From bb7adb6ddc72c8fba6c868b396dbb31e53224ee9 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 22 Dec 2016 00:35:56 -0400 Subject: - Fixed a bug when parsing JSON numbers. --- stdlib/source/lux/data/format/json.lux | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'stdlib/source') 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 - [?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) -- cgit v1.2.3