Ben Gillis schrieb:
> This is probably a known CSharp2 target compile issue, but googling the
> error message only turned up others with the same problem, no
> resolution/status. 
>  
> Questions: Will it be fixed?  best work-arounds?
>  
>  
> The compile error is: Invalid expression term ')'
>  
> Anytime I use a token in single quotes in an AST rewrite, I get the
> above.  For example,
>  
> someRule : 'KEYWORD' 'TOKEN' ->  ^(KEYWORD TOKEN);

Oh damn - I've overlooked the cause when reading the email the first
time. For posterity:

someRule : 'KEYWORD' 'TOKEN' ->  ^(KEYWORD TOKEN);

is wrong and should throw an appropriate analyzer error (is that an
ANTLR 2.7.7 problem?), because you are rewriting the wrong things. If
you use single quotes then they have to be included in the rewrite part,
too. ANTLR doesn't turn 'foo' into the token foo, but e.g. into
TOKEN_12. So you would write:

someRule : 'KEYWORD' 'TOKEN' ->  ^('KEYWORD' 'TOKEN');

But it is better to ignore the possibility of literals in the parser
anyway, as those cause problems anyway.
>  
> which produces an empty condition in a C# if statement:
>  
>     if ( )
>  
>  
> If I remove the single quotes, the error is resolved:
>  
> someRule : KEYWORD TOKEN ->  ^(KEYWORD TOKEN);

To make this rule work, you must have defined the token elsewhere. This
is the best available variant.

Johannes
>  
>  
> the newly gen'd code being:
>  
> if ( stream_KEYWORD.HasNext() )
>  
> Regards,
> Ben
>  
> 
> 
> ------------------------------------------------------------------------
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to