Testing a rule with arguments

I am trying to test some subrules in my parser to check options. The rule I'm checking is an expression rule

expression: expression PLUS expression # plusExpression | expression IS NOT? NULL # nullExpression | columnIdentifier # columnExpression | literal # literalExpression ; 

In the generated analysis, the method signature:

 public final ExpressionContext expression(int _p) throws RecognitionException { 

I find it difficult to understand what value to pass as an argument to _p.

When I check the calls to the expression method in the parser, I see that 0 is 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 accessory to enable unit testing?

As a link, here is the code for installing unit test, which 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 ); } 
+4
source share

All Articles