diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-02-26 14:59:58 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-02-26 15:55:36 -0700 |
commit | c8336ee48791f00378a35e463e2962f4c856beb2 (patch) | |
tree | c87668aa25febabe9c8d49846a1b6df962e8b4e0 /src/parser/grammar.pegjs | |
parent | e8e9ee18f29b2557fdc514c4322f5446484c4d58 (diff) | |
download | cps-interpreter-c8336ee48791f00378a35e463e2962f4c856beb2.tar.gz cps-interpreter-c8336ee48791f00378a35e463e2962f4c856beb2.zip |
format parser, add support for negative integers and return specifically
which type of number
Diffstat (limited to 'src/parser/grammar.pegjs')
-rw-r--r-- | src/parser/grammar.pegjs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/parser/grammar.pegjs b/src/parser/grammar.pegjs index 007bc1d..d267b58 100644 --- a/src/parser/grammar.pegjs +++ b/src/parser/grammar.pegjs @@ -269,6 +269,7 @@ ArithmeticOperation / "/" / "*" / "**" + / "%" BitOperation = ">>" @@ -285,17 +286,17 @@ ComparisonOperation / ">" / "<" -Integer = digits:[0-9]+ !"." { return parseInt(digits.join(''), 10); } +Integer = digits:("-"? [0-9]+) !"." { return { int: parseInt(digits.join(''), 10) }; } QuotedString = "'" content:[^']* "'" { return content.join(''); } / "\"" content:[^"]* "\"" { return content.join(''); } Real - = value:("-"? [0-9]+ "." [0-9]+) { - return parseFloat( + = value:("-"? [0-9]+ ("." [0-9]+)?) { + return { real: parseFloat( value.map(x => (Array.isArray(x) ? x.join('') : x)).join(''), - ); + ) }; } Literal |