[antlr-interest] Whitespace question

Indhu Bharathi indhu.b at s7software.com
Fri Oct 9 10:20:28 PDT 2009

Try something like


r     :     lbl=searchTerm ({spaceFollows($lbl.stop)}?=> lbl=searchTerm)*



@members {

      public boolean spaceFollows(Token tkn) {

            return input.get(tkn.getTokenIndex()+1).getType()==WS;






Indhu Bharathi

 <http://www.s7software.com/> S7 Software Solutions




-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Reid Rivenburgh
Sent: Friday, October 09, 2009 9:55 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Whitespace question


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 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:




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:




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,



List: http://www.antlr.org/mailman/listinfo/antlr-interest


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091009/2d834fcc/attachment.html 

More information about the antlr-interest mailing list