aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/parser/json.lux
blob: 89ab7f9f13522558aad6903a06abafc77a75f0f7 (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
(.require
 [library
  [lux (.except)
   ["$" documentation (.only documentation:)]
   [data
    [text (.only \n)
     ["%" \\format (.only format)]]]
   [meta
    [macro
     ["[0]" template]]]]]
 [\\library
  ["[0]" /]])

(documentation: (/.Parser it)
  "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.")

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

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

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

  [/.boolean? /.this_boolean ..boolean]
  [/.number?  /.this_number  ..number]
  [/.string?  /.this_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? ..this_boolean
             ..number? ..this_number
             ..string? ..this_string
             
             ..nullable
             ..array
             ..object
             ..field
             ..dictionary
             ($.default /.unconsumed_input)
             ($.default /.empty_input)
             ($.default /.unexpected_value)
             ($.default /.value_mismatch)]
            []))