[antlr-interest] Whitespace question
Reid Rivenburgh
reid at lanl.gov
Fri Oct 9 09:24:35 PDT 2009
Hi. I've been using ANTLR (ANTLRWorks, actually, which is very nice) to
implement a project-specific search language, sort of like google's.
I've gotten it mostly working, though it's taken some time and
experimentation to understand the details. In my grammar, I've defined
a searchTerms parser rule, which is one or more searchTerm:
searchTerm+;
searchTerm matches a SEARCH_TERM token, which can be a number or word
(with some special characters like '*' allowed). The number is the
usual definition for a floating point number:
('-'|'+')?((DIGIT+)|(DIGIT*'.'DIGIT+));
which I hope is correct. (DIGIT is the fragment 0..9.) I'm also
sending whitespace to the HIDDEN channel, as is often recommended. It
seems like a side effect of this is that this input:
4.66.34
which isn't a valid number, gets parsed as two different terms: 4.66 and
.34. Is there some way to require whitespace between my search terms so
that input isn't allowed? When I was parsing words, this wasn't a
problem. I wouldn't be surprised if my design is a bit wrong still, and
that's what's put me in this position.
I can't post the entire grammar, unfortunately.
Thanks for any pointers,
Reid
More information about the antlr-interest
mailing list