aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/control/parser/json.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/documentation/lux/control/parser/json.lux94
1 files changed, 94 insertions, 0 deletions
diff --git a/stdlib/source/documentation/lux/control/parser/json.lux b/stdlib/source/documentation/lux/control/parser/json.lux
new file mode 100644
index 000000000..8dfa6a8d3
--- /dev/null
+++ b/stdlib/source/documentation/lux/control/parser/json.lux
@@ -0,0 +1,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)]
+ []))