[antlr-interest] XPath - identifiers are keywords
bob mcwhirter
bob at werken.com
Tue Jul 2 15:35:20 PDT 2002
You might be interested at my first shot of XPath using antlr
http://code.werken.com/
Look for werken.xpath
Specifically, the lexer and parser are here:
http://code.werken.com/werken.xpath/src/com/werken/xpath/parser/
I managed to make it work, but there's certainly ugliness in
it. I ended up punting for version 2, by using a completely
hand-rolled lexer/parser combination:
http://jaxen.org/
-bob
On Tue, 2 Jul 2002, John Merrells wrote:
>
> This is probably simple, but I've failed to find an explicit answer
> in the documentation or the FAQ. I have a language (XPath) and
> it has some keywords that can also be identifiers. How do I set
> up my lexer rules for this? The identifier is called NCNAME and
> is defined thus:
>
> k=2;
>
> NCNAME
> : (LETTER|'_') (NCNAMECHAR)*
> ;
>
> protected
> NCNAMECHAR: LETTER|'0'..'9'|'.'|'-'|'_';
>
> protected
> LETTER: ('a'..'z'|'A'..'Z');
>
> The keyword is 'comment', and when it's a keyword it is always
> followed by '(' ')'. So I tried just adding...
>
> COMMENT: "comment()";
>
> But that's ambiguous, so I tried adding a lexer rule to disambiguate
> between them, but I either got that wrong, or it didn't work. Should
> I increase k to be length("comment()")? That seems like overkill.
> I'm sure there's something obvious that I'm missing here...
>
> John
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
--
Bob McWhirter bob at werken.com
The Werken Company http://werken.com/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list