mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
parser: ensure that the parse functions are always directly called by reworking whitespace
This commit is contained in:
@ -17,7 +17,7 @@ class PorkParser : PsiParser {
|
||||
return builder.treeBuilt
|
||||
}
|
||||
|
||||
class ExitParser(val error: String? = null) : RuntimeException(
|
||||
class ExitParser(error: String? = null) : RuntimeException(
|
||||
if (error == null) "Fast Exit" else "Exit Parser: $error"
|
||||
)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.intellij.lang.PsiBuilder
|
||||
import gay.pizza.pork.parser.SourceIndex
|
||||
import gay.pizza.pork.parser.Token
|
||||
import gay.pizza.pork.parser.TokenSource
|
||||
import gay.pizza.pork.parser.TokenType
|
||||
import com.intellij.psi.TokenType as PsiTokenType
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
@ -29,5 +30,18 @@ class PsiBuilderTokenSource(val builder: PsiBuilder) : TokenSource {
|
||||
return Token(tokenType, SourceIndex.indexOnly(builder.currentOffset), builder.tokenText!!)
|
||||
}
|
||||
|
||||
override fun peekTypeAhead(ahead: Int): TokenType {
|
||||
if (builder.eof()) {
|
||||
return TokenType.EndOfFile
|
||||
}
|
||||
val elementType = builder.lookAhead(ahead)
|
||||
if (elementType == null || elementType == PsiTokenType.BAD_CHARACTER) {
|
||||
return TokenType.EndOfFile
|
||||
}
|
||||
return PorkElementTypes.tokenTypeFor(elementType) ?: TokenType.EndOfFile
|
||||
}
|
||||
|
||||
override fun ignoringParserIgnoredTypes(): TokenSource = this
|
||||
|
||||
class BadCharacterError(error: String) : RuntimeException(error)
|
||||
}
|
||||
|
Reference in New Issue
Block a user