ANTLR - Handle whitespace in identifier

35 views
Skip to first unread message

Yogesh Shetty

unread,
Dec 12, 2015, 5:44:14 PM12/12/15
to antlr-discussion
I am trying to build my custom search language and one of requirement is support for whitespace in identifier. 

For simplicity sake, i am sharing sample code and not the entire grammar 

Here are my sample search text 

LOB WHERE 
Line of Business WHERE 
Line of     Business WHERE 

As you can see in above search, first few words reflect search keyword followed by WHERE condition, i want to capture search keyword that can include whitespace. Sharing following sample grammar but doesn't seems to parse properly

sqlsyntax : identifierws 'WHERE';  
identifierws :  (WSID)+;
WSID: [a-zA-Z0-9 ] ;      // match identifiers with space
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines

Any help in this regard is appreciated.

This is what is happening when I try to parse Line of Business WHERE using above grammar rule. 

I get following error line 

1:0 no viable alternative at input 'Line' 

I get back LineofBusiness text but whitespace got trimmed, i want exact text Line of         Business, that is where I am struggling a bit.

Thanks in advance for your help

Jim Idle

unread,
Dec 13, 2015, 12:45:16 AM12/13/15
to antlr-discussion
Do t Zillow white space in identifiers. 





--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages