aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/parser.lux41
1 files 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<Lexer>
+ [input raw]
+ (wrap (text;replace-all "_" "" input))))
+
(do-template [<name> <tag> <lexer> <codec>]
[(def: #export (<name> where)
(-> Cursor (Lexer [Cursor Code]))
@@ -224,25 +240,30 @@
bool;Codec<Text,Bool>]
[parse-nat #;Nat
- (l;seq' (l;text "+") (l;many' l;digit))
+ (without-separators
+ (l;seq' (l;text "+")
+ rich-digits))
number;Codec<Text,Nat>]
[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<Text,Int>]
[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<Text,Real>]
[parse-deg #;Deg
- (l;seq' (l;text ".")
- (l;many' l;digit))
+ (without-separators
+ (l;seq' (l;text ".")
+ rich-digits))
number;Codec<Text,Deg>]
)