[antlr-interest] testing subrules and noviable alt upon eof

Ana Nelson nelson.ana at gmail.com
Wed Jun 4 07:55:07 PDT 2008


I use Ruby's Test::Unit via JRuby so I can do unit tests against actual
compiled grammars. I personally find it almost impossible to write grammars
without tests, and while I have nothing against gUnit I do like that I am
able to test against the "real thing". Also, all features of ANTLR are
automatically supported.

http://dev.agent.ie/svn/antlr/jruby-examples/

Maybe it's possible to write some java wrapping and use a generic java unit
testing framework? Or you could give jruby a whirl. :-)

If you want, if you can send me your complete grammar and some examples,
I'll run it through for you. It won't take long.



2008/6/4 Felix Dorner <felix_do at web.de>:

> Hi,
>
> I am aware of gunit, but since it doesnt support custom AST nodes, I won't
> use it.
>
> My toplevel rule is:
>
> body : statement* EOF
>
> When I try to test subrules (expressions, see below) against input
> snippets, in all cases I get NoViableAlts when the EOF token is encountered.
> For most inputs all input is consumed before the Exception (e.g. "3+4"
> "call()" "variable"), and for all cases that end with ".anIdentifier" it
> doesnt even consume this part. Now I dont know if this is unavoidable, or if
> something is wrong with my grammar. The problem occurs in the
> "selectorSequence" rule:
>
> expression     : setModifierExpr
>   ;
>
> setModifierExpr   : conditionalExpression (setModifier^
> conditionalExpression)*;
>
> conditionalExpression
>   : condAndExpr (OR^ condAndExpr)*;
>  condAndExpr
>   : relationalExpression (AND^ relationalExpression)*;
>
> relationalExpression
>   : additiveExpression (relationalOp^ additiveExpression)*;
>
> additiveExpression
>   : multExpr ((PLUS|MINUS)^ multExpr)*;
>
> multExpr
>   : prefixExpression ((MULT|DIV)^ prefixExpression)*;
> prefixExpression
>   : prefixOp prefixExpression -> ^(PRE prefixOp prefixExpression)
>   | '(' qualifiedName ')' selectorExpression -> ^(CAST qualifiedName
> selectorExpression)
>   | selectorExpression
>   ;
>
> selectorExpression
>   : (primaryExpression -> primaryExpression)
>     (selectorSequence -> ^(DOT primaryExpression selectorSequence))?
>   ;
>
>
> selectorSequence
>   : ('.' ID -> ID) (selectorSequence -> ^(DOT ID selectorSequence))?
>   | ('.' ID arguments -> ^(CALL ID arguments))
>     (selectorSequence -> ^(DOT ^(CALL ID arguments) selectorSequence))?
>   ;
>
> arguments
>   : '('expressionList? ')'  -> ^(ARGS expressionList?);
>
> primaryExpression
>
>   : (ID -> ID) (arguments -> ^(CALL ID arguments))?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080604/86f6567c/attachment.html 


More information about the antlr-interest mailing list