From b3d7e4aa4b646c082769b8305f179988a946493b Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 7 May 2017 20:10:14 -0400 Subject: - Added underscore separators ( _ ) for digits in the parser for the new compiler. --- new-luxc/source/luxc/parser.lux | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/new-luxc/source/luxc/parser.lux b/new-luxc/source/luxc/parser.lux index c9ba89b75..d76050860 100644 --- a/new-luxc/source/luxc/parser.lux +++ b/new-luxc/source/luxc/parser.lux @@ -206,6 +206,22 @@ ## These are very simple parsers that just cut chunks of text in ## specific shapes and then use decoders already present in the ## standard library to actually produce the values from the literals. +(def: rich-digit + (Lexer Char) + (l;either l;digit + (l;char #"_"))) + +(def: rich-digits + (Lexer Text) + (l;seq' (l/map char;as-text l;digit) + (l;some' rich-digit))) + +(def: (without-separators raw) + (-> (Lexer Text) (Lexer Text)) + (do Monad + [input raw] + (wrap (text;replace-all "_" "" input)))) + (do-template [ ] [(def: #export ( where) (-> Cursor (Lexer [Cursor Code])) @@ -224,25 +240,30 @@ bool;Codec] [parse-nat #;Nat - (l;seq' (l;text "+") (l;many' l;digit)) + (without-separators + (l;seq' (l;text "+") + rich-digits)) number;Codec] [parse-int #;Int - (l;seq' (l;default "" (l;text "-")) - (l;many' l;digit)) + (without-separators + (l;seq' (l;default "" (l;text "-")) + rich-digits)) number;Codec] [parse-real #;Real - ($_ l;seq' - (l;default "" (l;text "-")) - (l;many' l;digit) - (l;text ".") - (l;many' l;digit)) + (without-separators + ($_ l;seq' + (l;default "" (l;text "-")) + rich-digits + (l;text ".") + rich-digits)) number;Codec] [parse-deg #;Deg - (l;seq' (l;text ".") - (l;many' l;digit)) + (without-separators + (l;seq' (l;text ".") + rich-digits)) number;Codec] ) -- cgit v1.2.3