[antlr-interest] xml grammar
Martin Probst
mail at martin-probst.com
Wed Nov 16 10:11:36 PST 2005
Hi,
> > state DEFAULT:
> > ELEMENT_START -> ELEMENT_STATE:
> > '<';
> > state ELEMENT_STATE:
> > QNAME -> ATTR_LIST_STATE:
> > ...;
>
> Well, yes, I've considered allowing you to specify a start rule for
> the lexer so you can do context-sensitive lexing. Pretty cool, eh?
> Only issue is, how do you call a random method in Java w/o function
> pointers? Reflection is SLOOOOW and not supported in all targets...
Can't you just have an "int state", DEFAULT = 1, ELEMENT_STATE = 2, etc.
and then switch over the state when lexing the next token? ->
ELEMENT_STATE then sets state to ELEMENT_STATE and your done - am I
missing something?
> > and so on. I guess it would be not so much work to implement that in
> > ANTLR, and it would be a really big improvement for people that
> > have to
> > implement stateful lexers. Do you have any ideas on this?
>
> Sure do! :) Use the start rule idea, but also you can simply invoke
> another lexer to handle everything for PCDATA or do it the other way:
> have a special lexer for inside the tag. Just call like an island
> grammar, right?
Well, I was thinking more general (read: my XQuery Grammar ;-)), not
about XML itself.
Martin
More information about the antlr-interest
mailing list