[antlr-interest] Q: Peek at token without consumeing
Jim Idle
jimi at temporal-wave.com
Tue May 24 09:15:34 PDT 2011
This is the same specification as JavaFX - just download the source code
for the JavaFX compiler and steal my solution from there. It is easy
enough but just takes a little thinking about and some code. You will not
get it right with syntactic predicates though.
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Gustaf Johansson
> Sent: Sunday, May 22, 2011 10:07 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Q: Peek at token without consumeing
>
> Hi,
>
> I have a tricky problem that i cant seem to get right.
>
> I have a static semantics rule which says " ';' is optional if
> preceding statement ends with '}' or the statement is last in list"
> Basically meaning either have LA(-1) == '}' or LA(1) == '}' or we
> should expect a ';'.
>
> This rule is used in many places throughout the grammar so a generic
> approach would be best.
>
> I would like this case to produce good error messages since missing ';'
> is quite common.
> Can i use a "standard" rule and mark it somehow to not consume a token
> if it shouldnt (like the below example)?
>
> end:
> : ';'
> | '}' { doNotConsume() }
> | ( LA(-1) == '}' ) { doNotConsume() } ;
>
> BR Gustaf
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
More information about the antlr-interest
mailing list