[antlr-interest] Grammar handling of whitespaces

Shawn Poulson spoulson3 at yahoo.com
Thu Feb 7 08:28:37 PST 2008


--- Johannes Luber <jaluber at gmx.de> wrote:
> Erik Kratochvil schrieb:
> > First, make a new lexer lexer rule
> > ARROW : '=>';
> > and then use it in the parser rule arrow
> > arrow : ARROW ...whatever here...;
> 
> Well, the way he asks, he doesn't want to create a lexer rule for
> these 
> special situations. So your approach is probably the wrong one.

I will try both suggestions shortly, when I'm at my development PC. 
But, since it was asked, here's an example of what I'm trying to do. 
Throughout my grammars I'm working with things like my timespan_p
parsers. (You can tell I've worked with boost::spirit, no?)  The
timespan_p expects the form: "Td.h.m.s.fff", where 'T' is literal and
some of the elements are optional.  e.g. "T30" is 30 seconds, "T15:0"
indicates 15 minutes.

Currently, the parser will accept a whitespace between the 'T' and each
number elements.  e.g. "T 15 : 0" is equivalent to the previous
example.  This is not desired and, to me, considered poor form.

In boost::spirit, they utilize a directive "lexeme_d[]" that surrounds
parser references that are not processed by the skip parser (in this
case, the WS rule), thereby enforcing no whitespace inbetween.  e.g.
"lexeme_d[ 'T' >> int_p >> ':' >> int_p ]" is valid in spirit.  Maybe
ANTLR could use an equivalent directive?


---
Shawn Poulson
spoulson at explodingcoder.com


More information about the antlr-interest mailing list