]
[(def: #export ( test)
- {#;doc (code;text ($_ text/compose "Asks whether a JSON value is a " "."))}
+ {#.doc (code.text ($_ text/compose "Asks whether a JSON value is a " "."))}
(-> (Reader Bool))
- (do p;Monad
+ (do p.Monad
[head any]
(case head
( value)
@@ -257,9 +257,9 @@
(fail ($_ text/compose "JSON value is not " ".")))))
(def: #export ( test)
- {#;doc (code;text ($_ text/compose "Ensures a JSON value is a " "."))}
+ {#.doc (code.text ($_ text/compose "Ensures a JSON value is a " "."))}
(-> (Reader Unit))
- (do p;Monad
+ (do p.Monad
[head any]
(case head
( value)
@@ -271,30 +271,30 @@
_
(fail ($_ text/compose "JSON value is not a " ".")))))]
- [boolean? boolean! Bool bool;Eq (:: bool;Codec encode) #Boolean "boolean" id]
- [number? number! Frac number;Eq (:: number;Codec encode) #Number "number" id]
- [string? string! Text text;Eq text;encode #String "string" id]
+ [boolean? boolean! Bool bool.Eq (:: bool.Codec encode) #Boolean "boolean" id]
+ [number? number! Frac number.Eq (:: number.Codec encode) #Number "number" id]
+ [string? string! Text text.Eq text.encode #String "string" id]
)
(def: #export (nullable parser)
(All [a] (-> (Reader a) (Reader (Maybe a))))
- (p;alt null
+ (p.alt null
parser))
(def: #export (array parser)
- {#;doc "Parses a JSON array, assuming that every element can be parsed the same way."}
+ {#.doc "Parses a JSON array, assuming that every element can be parsed the same way."}
(All [a] (-> (Reader a) (Reader a)))
- (do p;Monad
+ (do p.Monad
[head any]
(case head
(#Array values)
- (case (p;run (sequence;to-list values) parser)
- (#e;Error error)
+ (case (p.run (sequence.to-list values) parser)
+ (#e.Error error)
(fail error)
- (#e;Success [remainder output])
+ (#e.Success [remainder output])
(case remainder
- #;Nil
+ #.Nil
(wrap output)
_
@@ -304,46 +304,46 @@
(fail "JSON value is not an array."))))
(def: #export (object parser)
- {#;doc "Parses a JSON object, assuming that every element can be parsed the same way."}
+ {#.doc "Parses a JSON object, assuming that every element can be parsed the same way."}
(All [a] (-> (Reader a) (Reader (Dict Text a))))
- (do p;Monad
+ (do p.Monad
[head any]
(case head
(#Object object)
- (case (do e;Monad
+ (case (do e.Monad
[]
- (|> (dict;entries object)
- (monad;map @ (function [[key val]]
+ (|> (dict.entries object)
+ (monad.map @ (function [[key val]]
(do @
[val (run val parser)]
(wrap [key val]))))
- (:: @ map (dict;from-list text;Hash))))
- (#e;Success table)
+ (:: @ map (dict.from-list text.Hash))))
+ (#e.Success table)
(wrap table)
- (#e;Error error)
+ (#e.Error error)
(fail error))
_
(fail "JSON value is not an array."))))
(def: #export (field field-name parser)
- {#;doc "Parses a field inside a JSON object."}
+ {#.doc "Parses a field inside a JSON object."}
(All [a] (-> Text (Reader a) (Reader a)))
- (do p;Monad
+ (do p.Monad
[head any]
(case head
(#Object object)
- (case (dict;get field-name object)
- (#;Some value)
+ (case (dict.get field-name object)
+ (#.Some value)
(case (run value parser)
- (#e;Success output)
+ (#e.Success output)
(function [tail]
- (#e;Success [(#;Cons (#Object (dict;remove field-name object))
+ (#e.Success [(#.Cons (#Object (dict.remove field-name object))
tail)
output]))
- (#e;Error error)
+ (#e.Error error)
(fail error))
_
@@ -360,23 +360,23 @@
(do-template [ ]
[(def: (-> Text) )]
- [show-boolean Boolean (:: bool;Codec encode)]
- [show-number Number (:: number;Codec encode)]
- [show-string String text;encode])
+ [show-boolean Boolean (:: bool.Codec encode)]
+ [show-number Number (:: number.Codec encode)]
+ [show-string String text.encode])
(def: (show-array show-json elems)
(-> (-> JSON Text) (-> Array Text))
($_ text/compose "["
- (|> elems (sequence/map show-json) sequence;to-list (text;join-with ","))
+ (|> elems (sequence/map show-json) sequence.to-list (text.join-with ","))
"]"))
(def: (show-object show-json object)
(-> (-> JSON Text) (-> Object Text))
($_ text/compose "{"
(|> object
- dict;entries
+ dict.entries
(list/map (function [[key value]] ($_ text/compose (show-string key) ":" (show-json value))))
- (text;join-with ","))
+ (text.join-with ","))
"}"))
(def: (show-json json)
@@ -394,24 +394,24 @@
))
(def: space~
- (l;Lexer Text)
- (l;some l;space))
+ (l.Lexer Text)
+ (l.some l.space))
(def: data-sep
- (l;Lexer [Text Unit Text])
- ($_ p;seq space~ (l;this ",") space~))
+ (l.Lexer [Text Unit Text])
+ ($_ p.seq space~ (l.this ",") space~))
(def: null~
- (l;Lexer Null)
- (do p;Monad
- [_ (l;this "null")]
+ (l.Lexer Null)
+ (do p.Monad
+ [_ (l.this "null")]
(wrap [])))
(do-template [ ]
[(def:
- (l;Lexer Boolean)
- (do p;Monad
- [_ (l;this )]
+ (l.Lexer Boolean)
+ (do p.Monad
+ [_ (l.this )]
(wrap )))]
[t~ "true" true]
@@ -419,49 +419,49 @@
)
(def: boolean~
- (l;Lexer Boolean)
- (p;either t~ f~))
+ (l.Lexer Boolean)
+ (p.either t~ f~))
(def: number~
- (l;Lexer Number)
- (do p;Monad
- [signed? (l;this? "-")
- digits (l;many l;decimal)
- decimals (p;default "0"
+ (l.Lexer Number)
+ (do p.Monad
+ [signed? (l.this? "-")
+ digits (l.many l.decimal)
+ decimals (p.default "0"
(do @
- [_ (l;this ".")]
- (l;many l;decimal)))
- exp (p;default ""
+ [_ (l.this ".")]
+ (l.many l.decimal)))
+ exp (p.default ""
(do @
- [mark (l;one-of "eE")
- signed?' (l;this? "-")
- offset (l;many l;decimal)]
+ [mark (l.one-of "eE")
+ signed?' (l.this? "-")
+ offset (l.many l.decimal)]
(wrap ($_ text/compose mark (if signed?' "-" "") offset))))]
(case (frac/decode ($_ text/compose (if signed? "-" "") digits "." decimals exp))
- (#e;Error message)
- (p;fail message)
+ (#e.Error message)
+ (p.fail message)
- (#e;Success value)
+ (#e.Success value)
(wrap value))))
(def: escaped~
- (l;Lexer Text)
- ($_ p;either
- (p;after (l;this "\\t") (parser/wrap "\t"))
- (p;after (l;this "\\b") (parser/wrap "\b"))
- (p;after (l;this "\\n") (parser/wrap "\n"))
- (p;after (l;this "\\r") (parser/wrap "\r"))
- (p;after (l;this "\\f") (parser/wrap "\f"))
- (p;after (l;this "\\\"") (parser/wrap "\""))
- (p;after (l;this "\\\\") (parser/wrap "\\"))))
+ (l.Lexer Text)
+ ($_ p.either
+ (p.after (l.this "\\t") (parser/wrap "\t"))
+ (p.after (l.this "\\b") (parser/wrap "\b"))
+ (p.after (l.this "\\n") (parser/wrap "\n"))
+ (p.after (l.this "\\r") (parser/wrap "\r"))
+ (p.after (l.this "\\f") (parser/wrap "\f"))
+ (p.after (l.this "\\\"") (parser/wrap "\""))
+ (p.after (l.this "\\\\") (parser/wrap "\\"))))
(def: string~
- (l;Lexer String)
- (<| (l;enclosed ["\"" "\""])
+ (l.Lexer String)
+ (<| (l.enclosed ["\"" "\""])
(loop [_ []])
- (do p;Monad
- [chars (l;some (l;none-of "\\\""))
- stop l;peek])
+ (do p.Monad
+ [chars (l.some (l.none-of "\\\""))
+ stop l.peek])
(if (text/= "\\" stop)
(do @
[escaped escaped~
@@ -470,34 +470,34 @@
(wrap chars))))
(def: (kv~ json~)
- (-> (-> Unit (l;Lexer JSON)) (l;Lexer [String JSON]))
- (do p;Monad
+ (-> (-> Unit (l.Lexer JSON)) (l.Lexer [String JSON]))
+ (do p.Monad
[key string~
_ space~
- _ (l;this ":")
+ _ (l.this ":")
_ space~
value (json~ [])]
(wrap [key value])))
(do-template [ ]
[(def: ( json~)
- (-> (-> Unit (l;Lexer JSON)) (l;Lexer ))
- (do p;Monad
- [_ (l;this )
+ (-> (-> Unit (l.Lexer JSON)) (l.Lexer ))
+ (do p.Monad
+ [_ (l.this )
_ space~
- elems (p;sep-by data-sep )
+ elems (p.sep-by data-sep )
_ space~
- _ (l;this )]
+ _ (l.this )]
(wrap ( elems))))]
- [array~ Array "[" "]" (json~ []) sequence;from-list]
- [object~ Object "{" "}" (kv~ json~) (dict;from-list text;Hash)]
+ [array~ Array "[" "]" (json~ []) sequence.from-list]
+ [object~ Object "{" "}" (kv~ json~) (dict.from-list text.Hash)]
)
(def: (json~' _)
- (-> Unit (l;Lexer JSON))
- ($_ p;alt null~ boolean~ number~ string~ (array~ json~') (object~ json~')))
+ (-> Unit (l.Lexer JSON))
+ ($_ p.alt null~ boolean~ number~ string~ (array~ json~') (object~ json~')))
(struct: #export _ (Codec Text JSON)
(def: encode show-json)
- (def: decode (function [input] (l;run input (json~' [])))))
+ (def: decode (function [input] (l.run input (json~' [])))))
--
cgit v1.2.3