[antlr-interest] Lexer for a grammar similar to a template engine

Joan Pujol jo at joanpujol.cat
Sun Oct 11 14:41:44 PDT 2009


Hi Gavin,

When I looked at your grammar it seemed correct to me but I tested it
in ANTLRWorks and I can't see why it doesn't work.

If you test with input "Hello ${name} it gives me a lexer error: line
1:7 mismatched character '{' expecting set null

I've looked at generated code and I see that when the lexer enters at
mTEXT rule it only can exit (correctly) if it reaches the end of
input.
And I don't understand why. I suppose that is something with the new
ANTLR3 lexers, or that I've to refresh some parsing theory, but I'm
absolutely lost.

A lot of thanks in advance,




On Sun, Oct 11, 2009 at 10:48 PM, Joan Pujol <jo at joanpujol.cat> wrote:
> Thanks Gavin and Graham,
>
> Gavin:
> But when you say that you can further evaluate at parser level what do you mean?
> What do you say is use another lexer+parser to parse the STRINGs
> tokens, doesn't you? Because the expressions will be a lot more
> complex to be parsed without prior lexer separation of tokens.
>
> Graham:
> You're right, I've corrected what you say changing the AND but what I
> don't understand is why if I put an input of for example:
> 'Hello?  --> It works.
> But If I put "Hello ${" it enters in infinite recursion saying:
> line 1:5 rule OTHER failed predicate: {input.LA(1)!='$' ||
> input.LA(2)!='{'}? infinite times.
>
>
> Cheers,
>
> --
> Joan Jesús Pujol Espinar
> http://www.joanpujol.cat
> http://lujop.deviantart.com
>



-- 
Joan Jesús Pujol Espinar
http://www.joanpujol.cat
http://lujop.deviantart.com


More information about the antlr-interest mailing list