[antlr-interest] Are ANTLR grammars space sensitive?
Terence Parr
parrt at cs.usfca.edu
Wed Apr 9 11:59:55 PDT 2008
Howdy...yeah, the action parser "sucks" at the moment...sorry. careful
of spaces in args, actions.
Ter
On Apr 9, 2008, at 9:26 AM, Edson Tirelli wrote:
>
> All,
>
> While playing with ANTLR during the weekend in my quest for
> learning AST/Tree grammars I found an odd situation. The following
> rule generates compilation errors:
>
> key_sentence
> @init {
> String text = "";
> }
> : variable_definition
> | cb=key_chunk { text = $cb.text; }
> -> ^(VT_LITERAL[ $cb.start, text ] )
> ;
>
> Errors are:
>
> [13:15:53] /tmp/antlrworks/DSLMapParser.java:1313: illegal start of
> expression
> [13:15:53] root_1 =
> (Object)adaptor.becomeRoot(adaptor.create(VT_LITERAL, ,
> ((Token)cb.start), text ), root_1);
> [13
> :
> 15
> :
> 53
> ] ^
> [13:15:53] /tmp/antlrworks/DSLMapParser.java:1313: ')' expected
> [13:15:53] root_1 =
> (Object)adaptor.becomeRoot(adaptor.create(VT_LITERAL, ,
> ((Token)cb.start), text ), root_1);
> [13
> :
> 15
> :
> 53
> ] ^
> [13:15:53] 2 errors
>
> Removing the spaces from inside the [], fixes the problem:
>
> -> ^(VT_LITERAL[$cb.start, text] )
>
> Is this known behavior? bug? I found no reference about it.
>
> Also, on a related question, as you can see in the rule, I'm
> using a dummy "text" variable to capture the text matched by the
> "key_chunk" rule. That is because simply writing:
>
> -> ^(VT_LITERAL[$cb.start, $cb.text] )
>
> Also generate compilation errors:
>
> [13:23:12] /tmp/antlrworks/DSLMapParser.java:1313: illegal start of
> expression
> [13:23:12] root_1 =
> (Object)adaptor.becomeRoot(adaptor.create(VT_LITERAL,
> ((Token)cb.start), , input.toString(cb.start,cb.stop)), root_1);
> [13
> :
> 23
> :
> 12
> ] ^
> [13:23:12] /tmp/antlrworks/DSLMapParser.java:1313: ')' expected
> [13:23:12] root_1 =
> (Object)adaptor.becomeRoot(adaptor.create(VT_LITERAL,
> ((Token)cb.start), , input.toString(cb.start,cb.stop)), root_1);
> [13
> :
> 23
> :
> 12
> ] ^
> [13:23:12] 2 errors
>
>
> Any idea if it is possible to avoid creating the dummy variable?
> I just prefer to keep the grammar as clean as possible...
>
> Thanks
> Edson
>
> --
> Edson Tirelli
> JBoss Drools Core Development
> Office: +55 11 3529-6000
> Mobile: +55 11 9287-5646
> JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080409/00e4a49d/attachment.html
More information about the antlr-interest
mailing list