[antlr-interest] Exceptional question...:)
Hill, Robert
rhill03 at eds.com
Mon Jun 20 05:58:47 PDT 2005
That's the ticket Martin, cheers.
I think having the predicate in there narrowed my vision, and I didn't
want to remove it for some unknown reason.!
I've added the test after the match, and it works just fine.
Also about the ##, I didn't think about the cut and pasting of code, I
guess that depends on how many AST type statements you have in the rule
:)
Cheers anyway :)
/2ob
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org]
Sent: 20 June 2005 11:23
To: Robert Hill
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Exceptional question...:)
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