I am trying to test some subrules in my parser, to check variants. The rule I am checking is an expression rule
expression: expression PLUS expression # plusExpression
| expression IS NOT? NULL # nullExpression
| columnIdentifier # columnExpression
| literal # literalExpression
;
In the generated the parse, the method signature is:
public final ExpressionContext expression(int _p) throws RecognitionException {
I'm having trouble figuring out what value to pass as the _p argument.
When I check calls to the expression method in the parser, I see 0 being passed. However, when I try to call parser.expression(0) directly, I get a null pointer exception.
What is the recommended way to call this subrule to enable unit testing?
As reference, here is the code for the unit test rig I am trying to write:
private Expression parseExpression( String expressionString ) {
DataProcessorLexer lexer = new DataProcessorLexer( new ANTLRInputStream( expressionString ) );
DataProcessorParser parser = new DataProcessorParser( new CommonTokenStream( lexer ) );
parser.removeErrorListeners();
parser.addErrorListener( new DiagnosticErrorListener() );
// Perform the Parse
ParseTree tree = parser.expression(0);
ParseTreeWalker walker = new ParseTreeWalker();
statementWalker = new StatementWalker();
walker.walk( statementWalker, tree );
return statementWalker.getExpressionValue( tree );
}