summaryrefslogtreecommitdiff
path: root/src/LispParser.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/LispParser.kt')
-rw-r--r--src/LispParser.kt15
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