[antlr-interest] skiping the rest of a line

Scott Amort jsamort at sympatico.ca
Mon Feb 6 13:57:59 PST 2006


Jason Wood wrote:
> Newbie question
>
> I have the following line in a text file … ~Another Section. The ~A part
> is of interest but the rest is not, also it is not guaranteed that
> anything after the ~A will be present. So, I have created a rule to look
> for ~A. After the ~A is located I want to skip the rest of the line and
> proceed to the next line. How do I go about doing that?
>
> I tried the following and it works but this gives me a nondeterministic
> warning, which it understandable because matched everything but newline
> characters.
>
> IGNORE: ':'(~('\n'|'\r'))* ('\n'|'\r'('\n')?){$setType(Token.SKIP);
> newline();};
>
> J
>
>
>   
Hi Jason,

I'm pretty new at this too, but I'll give it a stab...

couldn't you just have this in your lexer:

ANOTHER_SECTION
: "~A" ((~('\n' | '\r'))*)! ('\n' | '\r' ('\n')?)!
;

It will match anything after ~A that is not a newline, and terminate the 
rule at a newline. The exclamation point prevents that portion from 
being included in the token, so all that gets passed on to the parser is 
the initial ~A.

Hope this helps!

Best,
Scott


More information about the antlr-interest mailing list