aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/format/json.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/format/json.lux101
1 files changed, 50 insertions, 51 deletions
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux
index e0975d02d..12e94a331 100644
--- a/stdlib/source/lux/data/format/json.lux
+++ b/stdlib/source/lux/data/format/json.lux
@@ -8,9 +8,8 @@
[control
pipe
["." try (#+ Try)]
- ["p" parser ("#@." monad)
- ["l" text (#+ Parser)]
- ["s" code]]]
+ ["<>" parser ("#@." monad)
+ ["<t>" text (#+ Parser)]]]
[data
["." bit]
["." maybe]
@@ -253,23 +252,23 @@
(def: space~
(Parser Text)
- (l.some l.space))
+ (<t>.some <t>.space))
(def: data-sep
(Parser [Text Any Text])
- ($_ p.and space~ (l.this ",") space~))
+ ($_ <>.and space~ (<t>.this ",") space~))
(def: null~
(Parser Null)
- (do p.monad
- [_ (l.this "null")]
+ (do <>.monad
+ [_ (<t>.this "null")]
(wrap [])))
(template [<name> <token> <value>]
[(def: <name>
(Parser Boolean)
- (do p.monad
- [_ (l.this <token>)]
+ (do <>.monad
+ [_ (<t>.this <token>)]
(wrap <value>)))]
[true~ "true" #1]
@@ -278,55 +277,55 @@
(def: boolean~
(Parser Boolean)
- (p.either true~ false~))
+ (<>.either true~ false~))
(def: number~
(Parser 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 ""
- (do @
- [mark (l.one-of "eE")
- signed?' (l.this? "-")
- offset (l.many l.decimal)]
- (wrap ($_ text@compose mark (if signed?' "-" "") offset))))]
+ (do {@ <>.monad}
+ [signed? (<>.parses? (<t>.this "-"))
+ digits (<t>.many <t>.decimal)
+ decimals (<>.default "0"
+ (do @
+ [_ (<t>.this ".")]
+ (<t>.many <t>.decimal)))
+ exp (<>.default ""
+ (do @
+ [mark (<t>.one-of "eE")
+ signed?' (<>.parses? (<t>.this "-"))
+ offset (<t>.many <t>.decimal)]
+ (wrap ($_ text@compose mark (if signed?' "-" "") offset))))]
(case (f@decode ($_ text@compose (if signed? "-" "") digits "." decimals exp))
(#try.Failure message)
- (p.fail message)
+ (<>.fail message)
(#try.Success value)
(wrap value))))
(def: escaped~
(Parser Text)
- ($_ p.either
- (p.after (l.this "\t")
- (p@wrap text.tab))
- (p.after (l.this "\b")
- (p@wrap text.back-space))
- (p.after (l.this "\n")
- (p@wrap text.new-line))
- (p.after (l.this "\r")
- (p@wrap text.carriage-return))
- (p.after (l.this "\f")
- (p@wrap text.form-feed))
- (p.after (l.this (text@compose "\" text.double-quote))
- (p@wrap text.double-quote))
- (p.after (l.this "\\")
- (p@wrap "\"))))
+ ($_ <>.either
+ (<>.after (<t>.this "\t")
+ (<>@wrap text.tab))
+ (<>.after (<t>.this "\b")
+ (<>@wrap text.back-space))
+ (<>.after (<t>.this "\n")
+ (<>@wrap text.new-line))
+ (<>.after (<t>.this "\r")
+ (<>@wrap text.carriage-return))
+ (<>.after (<t>.this "\f")
+ (<>@wrap text.form-feed))
+ (<>.after (<t>.this (text@compose "\" text.double-quote))
+ (<>@wrap text.double-quote))
+ (<>.after (<t>.this "\\")
+ (<>@wrap "\"))))
(def: string~
(Parser String)
- (<| (l.enclosed [text.double-quote text.double-quote])
+ (<| (<t>.enclosed [text.double-quote text.double-quote])
(loop [_ []])
- (do {@ p.monad}
- [chars (l.some (l.none-of (text@compose "\" text.double-quote)))
- stop l.peek])
+ (do {@ <>.monad}
+ [chars (<t>.some (<t>.none-of (text@compose "\" text.double-quote)))
+ stop <t>.peek])
(if (text@= "\" stop)
(do @
[escaped escaped~
@@ -336,10 +335,10 @@
(def: (kv~ json~)
(-> (-> Any (Parser JSON)) (Parser [String JSON]))
- (do p.monad
+ (do <>.monad
[key string~
_ space~
- _ (l.this ":")
+ _ (<t>.this ":")
_ space~
value (json~ [])]
(wrap [key value])))
@@ -347,12 +346,12 @@
(template [<name> <type> <open> <close> <elem-parser> <prep>]
[(def: (<name> json~)
(-> (-> Any (Parser JSON)) (Parser <type>))
- (do p.monad
- [_ (l.this <open>)
+ (do <>.monad
+ [_ (<t>.this <open>)
_ space~
- elems (p.sep-by data-sep <elem-parser>)
+ elems (<>.sep-by data-sep <elem-parser>)
_ space~
- _ (l.this <close>)]
+ _ (<t>.this <close>)]
(wrap (<prep> elems))))]
[array~ Array "[" "]" (json~ []) row.from-list]
@@ -361,10 +360,10 @@
(def: (json~' _)
(-> Any (Parser JSON))
- ($_ p.or null~ boolean~ number~ string~ (array~ json~') (object~ json~')))
+ ($_ <>.or null~ boolean~ number~ string~ (array~ json~') (object~ json~')))
(structure: #export codec
(Codec Text JSON)
(def: encode ..format)
- (def: decode (l.run (json~' []))))
+ (def: decode (<t>.run (json~' []))))