diff options
author | nea <nea@nea.moe> | 2023-08-09 17:05:46 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-08-09 17:05:46 +0200 |
commit | f3600dacea3e38cd541bf57076f8a7141987e10b (patch) | |
tree | c22645458e388a39a8d3a1e77cb261b4b69c1db2 /src/LispParser.kt | |
parent | b530d6360308ac1f68cf2508fa5bd4a085a8bec0 (diff) | |
download | nealisp-f3600dacea3e38cd541bf57076f8a7141987e10b.tar.gz nealisp-f3600dacea3e38cd541bf57076f8a7141987e10b.tar.bz2 nealisp-f3600dacea3e38cd541bf57076f8a7141987e10b.zip |
Add addition
Diffstat (limited to 'src/LispParser.kt')
-rw-r--r-- | src/LispParser.kt | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/LispParser.kt b/src/LispParser.kt index 1117397..e005c2d 100644 --- a/src/LispParser.kt +++ b/src/LispParser.kt @@ -49,6 +49,9 @@ class LispParser private constructor(filename: String, string: String) { if (paren == "\"") { return parseString() } + if (paren in digits) { + return parseNumber() + } if (paren == ":") { return parseAtom() } @@ -56,6 +59,18 @@ class LispParser private constructor(filename: String, string: String) { return LispAst.Reference(racer.span(start), ident) } + fun parseNumber(): LispAst.NumberLiteral { + val start = racer.idx + racer.pushState() + val number = racer.consumeWhile { it.last().let { it in digits || it == '.' } } + val double = number.toDoubleOrNull() + if (double == null) { + racer.popState() + racer.error("Could not parse number") + } + racer.discardState() + return LispAst.NumberLiteral(racer.span(start), double) + } fun parseAtom(): LispAst.Atom { val start = racer.idx |