aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/parser/json.lux
blob: 8dfa6a8d3396dd5937f4814feafd25617d34e1b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(.module:
  [library
   [lux #*
    ["$" documentation (#+ documentation:)]
    [data
     [text (#+ \n)
      ["%" format (#+ format)]]]
    [macro
     ["." template]]]]
  [\\library
   ["." /]])

(documentation: /.Parser
  "A JSON parser.")

(documentation: /.result
  (format "Executes the parser against a JSON object."
          \n "Verifies that all of the JSON was consumed by the parser.")
  [(result parser json)])

(documentation: /.any
  "Just returns the JSON input without applying any logic.")

(template [<name>]
  [(`` (documentation: <name>
         (format "Reads a JSON value as " (~~ (template.text [<name>])) ".")))]

  [/.null]
  [/.boolean]
  [/.number]
  [/.string]
  )

(template [<test> <check> <read>]
  [(`` (documentation: <test>
         (format "Asks whether a JSON value is a " (~~ (template.text [<read>])) ".")
         [(<test> test)]))
   (`` (documentation: <check>
         (format "Ensures a JSON value is a " (~~ (template.text [<read>])) ".")
         [(<check> test)]))]

  [/.boolean? /.boolean! ..boolean]
  [/.number?  /.number!  ..number]
  [/.string?  /.string!  ..string]
  )

(documentation: /.nullable
  "Enhances parser by adding NULL-handling."
  [(nullable parser)])

(documentation: /.array
  "Parses the contents of a JSON array."
  [(array parser)])

(documentation: /.object
  (format "Parses the contents of a JSON object."
          \n "Use this with the 'field' combinator.")
  [(object parser)])

(documentation: /.field
  (format "Parses a field inside a JSON object."
          \n "Use this inside the 'object' combinator.")
  [(field field_name parser)])

(documentation: /.dictionary
  "Parses a dictionary-like JSON object.")

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Parser
             ..result
             ..any

             ..null
             ..boolean
             ..number
             ..string
             
             ..boolean? ..boolean!
             ..number? ..number!
             ..string? ..string!
             
             ..nullable
             ..array
             ..object
             ..field
             ..dictionary
             ($.default /.unconsumed_input)
             ($.default /.empty_input)
             ($.default /.unexpected_value)
             ($.default /.value_mismatch)]
            []))