[antlr-interest] Can lexer rules return values?

Steve Bennett stevagewp at gmail.com
Sat Feb 16 01:22:45 PST 2008


On 2/16/08, Gavin Lambert <antlr at mirality.co.nz> wrote:
> IIRC, there was some discussion that they ought to be able to, but
> I don't think they can at the moment, no.

Maybe I was thinking of rule parameters.


> I think you can use scopes (though I also recall some discussion
> that scopes didn't work in the lexer, but I think that was for a
> much older version), or failing that, some member variables.

I'll try member vars.

> This is looking complicated enough (and with embedded whitespace
> to boot) that perhaps it ought to be in the parser instead.

My knowledge on such things is pretty limited, but I think I'm better
off with it in the lexer. I need to detect these embedded XML-ish
tags, then opaquely match everything through to the matching close
tag, and then farm the lot out to an external program. I don't want
any kind of AST for the tag or its contents, for example. However, I
guess I will end up with a massive token.

I'm a bit confused about what will happen if I use the parser instead:
I will get a sequence of basically meaningless tokens whose types I
will just ignore. Maybe it's ok.

Steve


More information about the antlr-interest mailing list