[antlr-interest] Real simple grammar - newbie help?!
James Crowley
james.crowley at gmail.com
Thu Feb 4 15:11:13 PST 2010
hey guys,
I've got a really simple grammar that I'm trying to get working, but failing
miserably at the moment. Would really appreciate some pointers on this...
root : (keyword|ignore)*;
keyword : KEYWORD;
ignore : IGNORE;
KEYWORD : ABBRV|WORD;
fragment WORD : ALPHA+;
fragment ALPHA : 'a'..'z'|'A'..'Z';
fragment ABBRV : WORD?('.'WORD);
IGNORE : .{ Skip(); };
With the following test input:
"some ASP.NET and .NET stuff. that work."
I'm wanting a tree that is just a list of keyword nodes,
"some", "ASP.NET", "and", ".NET", "stuff", "that", "work"
At the moment I get
"some", "ASP.NET", "and", ".NET", "stuff. that",
(for some reason "." appears within the last keyword, and it misses "work"
If I change the ABBRV clause to
fragment ABBRV : ('.'WORD);
then that works fine, but I get keyword (asp) and keyword (.net) -
seperately - but I need them as a single token. Any help you can give would
be much appreciated.
Many thanks
James
More information about the antlr-interest
mailing list