mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 21:21:33 +00:00
parser: implement long literal and handle overflow
This commit is contained in:
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user