mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
parser: major refinement of error handling
This commit is contained in:
@ -57,8 +57,8 @@ class PorkLexer : LexerBase() {
|
||||
try {
|
||||
val currentToken = tokenizer.next()
|
||||
currentTokenType = PorkElementTypes.elementTypeFor(currentToken.type)
|
||||
internalTokenStart = currentToken.start
|
||||
internalTokenEnd = currentToken.start + currentToken.text.length
|
||||
internalTokenStart = currentToken.sourceIndex.index
|
||||
internalTokenEnd = currentToken.sourceIndex.index + currentToken.text.length
|
||||
} catch (e: ProcessCanceledException) {
|
||||
throw e
|
||||
} catch (e: Throwable) {
|
||||
|
@ -29,12 +29,8 @@ class PsiBuilderMarkAttribution(val builder: PsiBuilder) : ParserNodeAttribution
|
||||
}
|
||||
throw PorkParser.ExitParser()
|
||||
} catch (e: PorkParser.ExitParser) {
|
||||
if (e.error != null) {
|
||||
marker.error(e.error)
|
||||
} else {
|
||||
marker.done(PorkElementTypes.FailedToParse)
|
||||
}
|
||||
throw PorkParser.ExitParser()
|
||||
marker.done(PorkElementTypes.FailedToParse)
|
||||
throw e
|
||||
}
|
||||
if (map[result] != null) {
|
||||
marker.drop()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package gay.pizza.pork.idea
|
||||
|
||||
import com.intellij.lang.PsiBuilder
|
||||
import gay.pizza.pork.parser.SourceIndex
|
||||
import gay.pizza.pork.parser.Token
|
||||
import gay.pizza.pork.parser.TokenSource
|
||||
import com.intellij.psi.TokenType as PsiTokenType
|
||||
@ -17,15 +18,15 @@ class PsiBuilderTokenSource(val builder: PsiBuilder) : TokenSource {
|
||||
|
||||
override fun peek(): Token {
|
||||
if (builder.eof()) {
|
||||
return Token.endOfFile(builder.currentOffset)
|
||||
return Token.endOfFile(SourceIndex.indexOnly(builder.currentOffset))
|
||||
}
|
||||
val elementType = builder.tokenType!!
|
||||
if (elementType == PsiTokenType.BAD_CHARACTER) {
|
||||
throw BadCharacterError("Invalid character.")
|
||||
throw BadCharacterError("Invalid character")
|
||||
}
|
||||
val tokenType = PorkElementTypes.tokenTypeFor(elementType) ?:
|
||||
throw RuntimeException("Lexing failure: ${elementType.debugName}")
|
||||
return Token(tokenType, builder.currentOffset, builder.tokenText!!)
|
||||
return Token(tokenType, SourceIndex.indexOnly(builder.currentOffset), builder.tokenText!!)
|
||||
}
|
||||
|
||||
class BadCharacterError(error: String) : RuntimeException(error)
|
||||
|
Reference in New Issue
Block a user