[antlr-interest] Match the start and end of a line
Gokulakannan Somasundaram
gokul007 at gmail.com
Thu Dec 25 12:58:10 PST 2008
>
> grammar t;
>
> @lexer::members
> {
> boolean canStart = true;
> }
>
> tu
> : line+ EOF
> ;
>
> line
> : BOL STUFF* EOL
> ;
>
> BOL : { canStart }?=> { input.mark(); canStart = false; } . {
> input.rewind(); } ;
>
> EOL : '\r'? '\n' { canStart = true; } ;
>
> WS : (' ' | '\t')+ { $channel = HIDDEN; };
>
> STUFF
> : ('a'..'z'|'A'..'Z')+ ;
>
>
> I don't know the internals of ANTLR. But I think this approach incurs an
overhead of manipulating the 'canStart' for every line, even when i don't
need the condition. I think, if i follow an approach like this, it would
incur the overhead only necessary.
Suppose i need #include to always to be in the beginning of line
INCLUDE : '#include';
stmtInclude : INCLUDE { if ($INCLUDE.pos!=0) <<error>> };
Is my idea correct? Or does it have any disadvantage?
Thanks,
Gokul.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081226/c8ff84c0/attachment.html
More information about the antlr-interest
mailing list