Skip to content

Commit

Permalink
#99 aibolit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 15, 2020
1 parent 186d7e4 commit c6c90ec
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/main/java/org/xembly/Verbs.java
Expand Up @@ -62,32 +62,39 @@ final class Verbs {
* @return Collection of directives
*/
public Collection<Directive> directives() {
final ANTLRErrorListener errors = new BaseErrorListener() {
// @checkstyle ParameterNumberCheck (10 lines)
@Override
public void syntaxError(final Recognizer<?, ?> recognizer,
final Object symbol, final int line,
final int position, final String msg,
final RecognitionException error) {
throw new SyntaxException(Verbs.this.text, error);
}
};
final XemblyLexer lexer = new XemblyLexer(
CharStreams.fromString(this.text)
);
lexer.removeErrorListeners();
lexer.addErrorListener(errors);
lexer.addErrorListener(this.errors());
final XemblyParser parser =
new XemblyParser(
new CommonTokenStream(lexer)
);
parser.removeErrorListeners();
parser.addErrorListener(errors);
parser.addErrorListener(this.errors());
try {
return parser.directives().ret;
} catch (final ParsingException ex) {
throw new SyntaxException(this.text, ex);
}
}

/**
* Errors listener.
* @return Listener
*/
private ANTLRErrorListener errors() {
return new BaseErrorListener() {
// @checkstyle ParameterNumberCheck (10 lines)
@Override
public void syntaxError(final Recognizer<?, ?> recognizer,
final Object symbol, final int line,
final int position, final String msg,
final RecognitionException error) {
throw new SyntaxException(Verbs.this.text, error);
}
};
}

}

0 comments on commit c6c90ec

Please sign in to comment.