ANTLR V4 lexer lookahead question

161 views
Skip to first unread message

TR

unread,
May 3, 2015, 8:40:41 AM5/3/15
to antlr-di...@googlegroups.com
Hi,

I'm trying to write a grammar for an XML-like language, where we use << instead of < characters.
This is a partial snap of the lexer, where TEXT represents the text between (outside) tags:

OPEN  : '<<' ;
CLOSE : '>>' ;
TEXT  : ~[^<]+ ;

The definition for TEXT above is clearly wrong, because it will stop at the first occurrence of < even when one is not followed by another <.
I am looking for a way to define "capture everything until you encounter a <<" but don't include the << in the match. So something like this won't work either:

TEXT  : .*? '<<' ;

Is there a way to accomplish that in ANTLR4?

-- TR

Terence Parr

unread,
May 3, 2015, 11:48:45 AM5/3/15
to antlr-di...@googlegroups.com
On May 3, 2015, at 5:40 AM, TR <tzv...@gmail.com> wrote:

Hi,

I'm trying to write a grammar for an XML-like language, where we use << instead of < characters.
This is a partial snap of the lexer, where TEXT represents the text between (outside) tags:

OPEN  : '<<' ;
CLOSE : '>>' ;
TEXT  : ~[^<]+ ;

The definition for TEXT above is clearly wrong, because it will stop at the first occurrence of < even when one is not followed by another <.

hi. it should stop at << not <

Ter
I am looking for a way to define "capture everything until you encounter a <<" but don't include the << in the match. So something like this won't work either:

TEXT  : .*? '<<' ;

Is there a way to accomplish that in ANTLR4?

-- TR


--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages