Creating a parser combinator library to parse JSON
Prev: alt | Contents | Next: Skipping whitespace |
fromjson
is the entry point into the JSON parser library. It takes a string, parses it as a JSON value, and converts it to an Arc value:
(def fromjson (s) (iflet (p r) (json-value (coerce s 'cons)) (do (if p (err "Unexpected characters after JSON value" (coerce p 'string))) r) (err:string "not a JSON value: " s)))
arc> (fromjson "true") t
If the string isn’t a valid JSON value (if the match fails), it raises an error:
arc> (fromjson "fable") not a JSON value: fable
Prev: alt | Contents | Next: Skipping whitespace |
Questions? Comments? Email me andrew.wilcox [at] gmail.com