parser: implement long literal and handle overflow

This commit is contained in:
2023-09-12 00:25:13 -04:00
parent 7aa9d95221
commit 1b363dcf56
12 changed files with 55 additions and 2 deletions

View File

@ -11,7 +11,15 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
if (it.text.contains(".")) {
DoubleLiteral(it.text.toDouble())
} else {
IntegerLiteral(it.text.toInt())
val integer = it.text.toIntOrNull()
if (integer != null) {
IntegerLiteral(integer)
}
val long = it.text.toLongOrNull()
if (long != null) {
LongLiteral(long)
}
throw ParseError("Illegal integer value")
}
}
}

View File

@ -70,6 +70,10 @@ class Printer(buffer: StringBuilder) : NodeVisitor<Unit> {
append("]")
}
override fun visitLongLiteral(node: LongLiteral) {
append(node.value.toString())
}
override fun visitNative(node: Native) {
append("native ")
visit(node.form)