[antlr-interest] Lexer question: Matchin everything up to a specifc token or EOF?

Thomas Brandon tbrandonau at gmail.com
Tue Jul 25 07:39:35 PDT 2006


On 7/26/06, Peter Palotas <peter.palotas at gmail.com> wrote:
> Hi,
>
> I want my lexer to macth any character up until a specific sequence of
> characters, say "<?", or EOF.
>
> Tried the rule:
>
> PCDATA
>     : ( options
>          { greedy=false; }
>          :  .
>          )* ("<?")?
>          ;
>
I think you want to check the lookahead rather than matching the end
token in your PCDATA rule. Something like (check syntax):
protected
PCDATA: ( { !('<' == LA(1) && '?' == LA(2)) }? .)+ ;

Then normal EOF handling should apply and "<?" would be handled by a
seperate lexer rule.
Tom.

>
> // Peter
>


More information about the antlr-interest mailing list