diff options
-rw-r--r-- | stdlib/source/lux/data/format/json.lux | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 1b2c65f97..43b029f60 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -243,18 +243,25 @@ (def: number~ (Lexer Number) (do Monad<Lexer> - [?sign (: (Lexer (Maybe Text)) - (lexer;opt (lexer;text "-"))) + [?sign (: (Lexer Text) + (lexer;default "" + (lexer;text "-"))) digits (: (Lexer Text) (lexer;many' lexer;digit)) - ?decimals (: (Lexer (Maybe Text)) - (lexer;opt (do @ - [_ (lexer;text ".")] - (lexer;many' lexer;digit))))] + decimals (: (Lexer Text) + (lexer;default "0" + (do @ + [_ (lexer;text ".")] + (lexer;many' lexer;digit)))) + exp (: (Lexer Text) + (lexer;default "" + (do @ + [mark (lexer;either (lexer;text "e") (lexer;text "E")) + sign (lexer;default "" (lexer;text "-")) + offset (lexer;many' lexer;digit)] + (wrap (format mark sign offset)))))] (case (: (Error Real) - (Real/decode (format (default "" ?sign) - digits "." - (default "0" ?decimals)))) + (Real/decode (format ?sign digits "." decimals exp))) (#;Left message) (lexer;fail message) |