Skip to content

Commit

Permalink
Fix NPE when parsing lexer grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
uaraven committed Oct 26, 2020
1 parent 01f03d4 commit 8155b19
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
mainClassName = 'net.ninjacat.antlrscope.AppKt'

group 'net.ninjacat'
version '0.4.0'
version '0.4.1'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AntlrCompiler(grammar: String, text: String, private val javaCompiler: Jav
val runner = AntlrExecutor(text, packageName, grammarName, path.parent.resolve("classes"))
val results = runner.parse(errorListener)
tokens = results.tokens!!
tree = convertParseTree(results.tree!!, results.ruleNames)
tree = if (results.tree != null) convertParseTree(results.tree!!, results.ruleNames) else null
ruleNames = results.ruleNames

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class AntlrInterpreter(grammar: String, text: String): AntlrGrammarParser(gramma
val tokens = CommonTokenStream(lexEngine)
val parser = antlrGrammar!!.createParserInterpreter(tokens)
parser.addErrorListener(errorListener)
tree = convertParseTree(parser.parse(antlrGrammar!!.getRule(0).index), antlrGrammar?.ruleNames!!)
tree = if (tree != null) {
convertParseTree(parser.parse(antlrGrammar!!.getRule(0).index), antlrGrammar?.ruleNames!!)
} else {
null
}
errors.addAll(errorListener.errors)
} else {
val tokens = convertTokens(lexEngine, lexEngine.allTokens)
Expand Down

0 comments on commit 8155b19

Please sign in to comment.