diff --git a/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt b/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt index d69869c..88e9be5 100644 --- a/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt +++ b/parser/src/main/kotlin/gay/pizza/pork/parser/Parser.kt @@ -13,11 +13,11 @@ class Parser(source: PeekableSource, 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") } diff --git a/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkElementTypes.kt b/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkElementTypes.kt index 4806b39..8341c19 100644 --- a/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkElementTypes.kt +++ b/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkElementTypes.kt @@ -46,4 +46,6 @@ object PorkElementTypes { fun elementTypeFor(nodeType: NodeType): IElementType = nodeTypeToElementType[nodeType]!! + + val FailedToParse: IElementType = IElementType("FailedToParse", PorkLanguage) } diff --git a/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkParser.kt b/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkParser.kt index c7d9f5a..9a23cb5 100644 --- a/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkParser.kt +++ b/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PorkParser.kt @@ -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" + ) } diff --git a/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PsiBuilderMarkAttribution.kt b/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PsiBuilderMarkAttribution.kt index 49ee294..fc7a836 100644 --- a/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PsiBuilderMarkAttribution.kt +++ b/support/pork-idea/src/main/kotlin/gay/pizza/pork/idea/PsiBuilderMarkAttribution.kt @@ -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() } } }