[antlr-interest] Grammar handling of whitespaces
Jim Idle
jimi at temporal-wave.com
Thu Feb 7 07:59:23 PST 2008
Use a semantic (probably gated is what is needed) predicate to look at
the previous off channel token. If it is a whitespace, then disallow the
following rule, issue an error or whatever it is you need:
{( (TokenStream)input ).get( input.index()-1 ).getType() != WS }?=>
optionalrule. The get() call does not skip off channel tokens.
Jim
> -----Original Message-----
> From: Shawn Poulson [mailto:spoulson3 at yahoo.com]
> Sent: Thursday, February 07, 2008 5:19 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Grammar handling of whitespaces
>
> Hello all,
>
> I've had success so far with generating my grammar for my C# target,
> with help from several individuals here. One of the tips I've used is
> to use a lexer rule to skip whitespaces using a rule like:
>
> WS : (' '|'\r'|'\t'|'\n') { $channel=HIDDEN; }
>
> This is very helpful for most parser rules, so I don't have to
> explicitly put whitespaces throughout my parser rules. But, there are
> times where I don't want whitespaces between certain elements. Is
> there a way to handle this?
>
> Thanks.
>
> ---
> Shawn Poulson
> spoulson at explodingcoder.com
More information about the antlr-interest
mailing list