diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/control/parser/json.lux | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/stdlib/source/library/lux/control/parser/json.lux b/stdlib/source/library/lux/control/parser/json.lux index 2e9935480..cc20f6512 100644 --- a/stdlib/source/library/lux/control/parser/json.lux +++ b/stdlib/source/library/lux/control/parser/json.lux @@ -23,7 +23,7 @@ ["." // ("#\." functor)]) (type: #export (Parser a) - {#.doc "JSON parser."} + {#.doc "A JSON parser."} (//.Parser (List JSON) a)) (exception: #export (unconsumed_input {input (List JSON)}) @@ -33,6 +33,8 @@ (exception: #export empty_input) (def: #export (run parser json) + {#.doc (doc "Executes the parser against a JSON object." + "Verifies that all of the JSON was consumed by the parser.")} (All [a] (-> (Parser a) JSON (Try a))) (case (//.run parser (list json)) (#try.Success [remainder output]) @@ -41,7 +43,7 @@ (#try.Success output) _ - (exception.throw ..unconsumed_input remainder)) + (exception.except ..unconsumed_input remainder)) (#try.Failure error) (#try.Failure error))) @@ -52,7 +54,7 @@ (<| (function (_ inputs)) (case inputs #.Nil - (exception.throw ..empty_input []) + (exception.except ..empty_input []) (#.Cons head tail) (#try.Success [tail head])))) @@ -69,7 +71,7 @@ [head ..any] (case head (<tag> value) - (wrap value) + (in value) _ (//.failure (exception.construct ..unexpected_value [head])))))] @@ -93,7 +95,7 @@ [head ..any] (case head (<tag> value) - (wrap (\ <equivalence> = test value)) + (in (\ <equivalence> = test value)) _ (//.failure (exception.construct ..unexpected_value [head]))))) @@ -106,7 +108,7 @@ (case head (<tag> value) (if (\ <equivalence> = test value) - (wrap []) + (in []) (//.failure (exception.construct ..value_mismatch [(<tag> test) (<tag> value)]))) _ @@ -118,12 +120,13 @@ ) (def: #export (nullable parser) + {#.doc (doc "Enhances parser by adding NULL-handling.")} (All [a] (-> (Parser a) (Parser (Maybe a)))) (//.or ..null parser)) (def: #export (array parser) - {#.doc "Parses a JSON array."} + {#.doc "Parses the contents of a JSON array."} (All [a] (-> (Parser a) (Parser a))) (do //.monad [head ..any] @@ -136,7 +139,7 @@ (#try.Success [remainder output]) (case remainder #.Nil - (wrap output) + (in output) _ (//.failure (exception.construct ..unconsumed_input remainder)))) @@ -145,7 +148,8 @@ (//.failure (exception.construct ..unexpected_value [head]))))) (def: #export (object parser) - {#.doc "Parses a JSON object. Use this with the 'field' combinator."} + {#.doc (doc "Parses the contents of a JSON object." + "Use this with the 'field' combinator.")} (All [a] (-> (Parser a) (Parser a))) (do //.monad [head ..any] @@ -163,7 +167,7 @@ (#try.Success [remainder output]) (case remainder #.Nil - (wrap output) + (in output) _ (//.failure (exception.construct ..unconsumed_input remainder)))) @@ -172,7 +176,8 @@ (//.failure (exception.construct ..unexpected_value [head]))))) (def: #export (field field_name parser) - {#.doc "Parses a field inside a JSON object. Use this inside the 'object' combinator."} + {#.doc (doc "Parses a field inside a JSON object." + "Use this inside the 'object' combinator.")} (All [a] (-> Text (Parser a) (Parser a))) (function (recur inputs) (case inputs @@ -183,20 +188,20 @@ (#try.Success [inputs' output]) (#try.Success [inputs'' _]) - (exception.throw ..unconsumed_input inputs'') + (exception.except ..unconsumed_input inputs'') (#try.Failure error) (#try.Failure error)) (do try.monad [[inputs'' output] (recur inputs')] - (wrap [(list& (#/.String key) value inputs'') - output]))) + (in [(list& (#/.String key) value inputs'') + output]))) #.Nil - (exception.throw ..empty_input []) + (exception.except ..empty_input []) _ - (exception.throw ..unconsumed_input inputs)))) + (exception.except ..unconsumed_input inputs)))) (def: #export dictionary {#.doc "Parses a dictionary-like JSON object."} |