[antlr-interest] Exceptional question...:)
Martin Probst
mail at martin-probst.com
Mon Jun 20 03:23:15 PDT 2005
Hi,
just match the characters and throw the exception afterwards:
>
> Element
>
> Options { defaultErrorHandler = false; }
>
> :
>
> ty:type nn:ID (ID! | HYPHEN!) cnt:element_count (INT | HYPHEN)
> string_size[#ty.getText()]
>
> (INT | HYPHEN) ({bIgnoreExtraneousEOLChars}? (options
> {greedy=false;}:~CR!)* CR!
(INT | HYPHEN) ( (options {greedy=false;}:~CR!
{ if (!bIngoreExtraneouseEOLChars) throw ...; } )* CR!
> ## = #([TOK_COMMENT,t]);
>
> #comment = #([TOK_COMMENT,t]);
>
> #comment = #(#[TOK_COMMENT,t]);
You can also write ## = #(#[TOK_COMMENT],#t); ;-)
I think it's just some liberation from the syntax, the idea is that you
don't have to write all those # chars if you're in an AST construction
statement anyways. About the ##/#comment: most people seem to prefer ##
as it's shorter and also doesn't break if you move the code or rename
the parser rule.
Regards,
Martin
More information about the antlr-interest
mailing list