From c3eab65e3f107f7acdc0c0354770f9b8fbd92c4f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 23 Jun 2020 03:02:15 -0400 Subject: Bug fixes. --- stdlib/source/lux/data/format/json.lux | 101 ++++++++++++++++----------------- 1 file changed, 50 insertions(+), 51 deletions(-) (limited to 'stdlib/source/lux/data/format/json.lux') 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) + ["" text (#+ Parser)]]] [data ["." bit] ["." maybe] @@ -253,23 +252,23 @@ (def: space~ (Parser Text) - (l.some l.space)) + (.some .space)) (def: data-sep (Parser [Text Any Text]) - ($_ p.and space~ (l.this ",") space~)) + ($_ <>.and space~ (.this ",") space~)) (def: null~ (Parser Null) - (do p.monad - [_ (l.this "null")] + (do <>.monad + [_ (.this "null")] (wrap []))) (template [ ] [(def: (Parser Boolean) - (do p.monad - [_ (l.this )] + (do <>.monad + [_ (.this )] (wrap )))] [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? (.this "-")) + digits (.many .decimal) + decimals (<>.default "0" + (do @ + [_ (.this ".")] + (.many .decimal))) + exp (<>.default "" + (do @ + [mark (.one-of "eE") + signed?' (<>.parses? (.this "-")) + offset (.many .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 (.this "\t") + (<>@wrap text.tab)) + (<>.after (.this "\b") + (<>@wrap text.back-space)) + (<>.after (.this "\n") + (<>@wrap text.new-line)) + (<>.after (.this "\r") + (<>@wrap text.carriage-return)) + (<>.after (.this "\f") + (<>@wrap text.form-feed)) + (<>.after (.this (text@compose "\" text.double-quote)) + (<>@wrap text.double-quote)) + (<>.after (.this "\\") + (<>@wrap "\")))) (def: string~ (Parser String) - (<| (l.enclosed [text.double-quote text.double-quote]) + (<| (.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 (.some (.none-of (text@compose "\" text.double-quote))) + stop .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 ":") + _ (.this ":") _ space~ value (json~ [])] (wrap [key value]))) @@ -347,12 +346,12 @@ (template [ ] [(def: ( json~) (-> (-> Any (Parser JSON)) (Parser )) - (do p.monad - [_ (l.this ) + (do <>.monad + [_ (.this ) _ space~ - elems (p.sep-by data-sep ) + elems (<>.sep-by data-sep ) _ space~ - _ (l.this )] + _ (.this )] (wrap ( 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 (.run (json~' [])))) -- cgit v1.2.3