[antlr-interest] Match until "<@"
Terence Parr
parrt at jguru.com
Wed May 8 16:50:49 PDT 2002
On Wednesday, May 8, 2002, at 01:33 PM, praveen_c wrote:
> Hi all,
>
> Just wondering what is wrong with the following Lexer rule. I'm
> trying to match all characters until reach the combination "<@"
> including white space, new lines...everything.
>
> MULTI_LINE_TEXT: ( options { greedy=false; } : .)* (~("<@"));
>
> It gives me wierd errors. Is this the right way to specify when I
> want to have something matched until I see a combination. If you
> think there is a better way, please let me know.
What is the k value? Has to be 2 at least. Also, note that you have
asked it to match anything until it sees NOT <@. If you don't want
the <@ in this token, you have a problem that is hard for a lexer since
any token can follow MULTI_LINE_TEXT in principle. You should probably
use a semantic predicate that tells it how to break out:
MLT : ( {!(LA(1)=='<'&&LA(2)=='@')}? . ) ;
That will work, but I dislike syntax checks in semantic predicates.
Seems this "break out of the loop" issue came up before...might check
the archives.
Ter
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list