mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 21:00:56 +00:00
parser: fix integer literals
This commit is contained in:
parent
1b363dcf56
commit
f64a54fa06
@ -13,11 +13,11 @@ class Parser(source: PeekableSource<Token>, val attribution: NodeAttribution) {
|
||||
} else {
|
||||
val integer = it.text.toIntOrNull()
|
||||
if (integer != null) {
|
||||
IntegerLiteral(integer)
|
||||
return@expect IntegerLiteral(integer)
|
||||
}
|
||||
val long = it.text.toLongOrNull()
|
||||
if (long != null) {
|
||||
LongLiteral(long)
|
||||
return@expect LongLiteral(long)
|
||||
}
|
||||
throw ParseError("Illegal integer value")
|
||||
}
|
||||
|
@ -46,4 +46,6 @@ object PorkElementTypes {
|
||||
|
||||
fun elementTypeFor(nodeType: NodeType): IElementType =
|
||||
nodeTypeToElementType[nodeType]!!
|
||||
|
||||
val FailedToParse: IElementType = IElementType("FailedToParse", PorkLanguage)
|
||||
}
|
||||
|
@ -17,5 +17,7 @@ class PorkParser : PsiParser {
|
||||
return builder.treeBuilt
|
||||
}
|
||||
|
||||
class ExitParser(val error: String) : RuntimeException("Exit Parser: $error")
|
||||
class ExitParser(val error: String? = null) : RuntimeException(
|
||||
if (error == null) "Fast Exit" else "Exit Parser: $error"
|
||||
)
|
||||
}
|
||||
|
@ -17,16 +17,20 @@ class PsiBuilderMarkAttribution(val builder: PsiBuilder) : ParserNodeAttribution
|
||||
while (!builder.eof()) {
|
||||
builder.advanceLexer()
|
||||
}
|
||||
throw PorkParser.ExitParser(e.error)
|
||||
throw PorkParser.ExitParser()
|
||||
} catch (e: ParseError) {
|
||||
marker.error(e.error)
|
||||
while (!builder.eof()) {
|
||||
builder.advanceLexer()
|
||||
}
|
||||
marker.error(e.error)
|
||||
throw PorkParser.ExitParser(e.error)
|
||||
throw PorkParser.ExitParser()
|
||||
} catch (e: PorkParser.ExitParser) {
|
||||
marker.error(e.error)
|
||||
throw e
|
||||
if (e.error != null) {
|
||||
marker.error(e.error)
|
||||
} else {
|
||||
marker.done(PorkElementTypes.FailedToParse)
|
||||
}
|
||||
throw PorkParser.ExitParser()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user