[antlr-interest] Selective ignoring of whitespace
Ratul Bhadury
hola.ratul at gmail.com
Mon May 18 07:00:03 PDT 2009
Thanks for the tips guys.
I've made some progress but seeing one peculiarity which I would be grateful
if someone could explain.
Single line input like 'sec= sec, dfd dfdf' is accepted as I
intend, i.e sec & dfd dfdf are regarded as search_terms. However if I put
a space before the '=', the line cannot be parsed. I tried putted a WS*
element in the definition of keyword_field, and also tried putting it in
keyword_clause, but they made no difference.
Can someone explain to me why this is the case? Grammar is below.
Many thanks!
Ratul
-------------------------------------------
------------ THE GRAMAR --------
-------------------------------------------
grammar MopedSearch;
options
{
language=CSharp2;
}
/*------------------------------------------------------------------
* PARSER RULES
*------------------------------------------------------------------*/
clause returns [ SearchExpression searchExpr ]
: keyword_clause EOF
;
keyword_clause
: keyword_field EQ search_term_list
;
id_clause
: id_field EQ id_list
;
search_term_list : search_term (',' search_term)*
;
id_list : NUMBER (',' NUMBER)*;
keyword_field : 'sec'
| 'cp'
| 'our'
;
id_field : 't'
| 'p'
| 'c'
;
search_term : keyword_field
| KEYWORD
;
NUMBER : DIGIT+;
EQ : '=';
KEYWORD : CHAR(CHAR|' ')*;
fragment CHAR :
ALPHA_UC|ALPHA_LC|DIGIT|'$'|'£'|'&'|'^'|'%'|'('|')'|'['|']'|':'|';'|'*'|'<'|'>'|'/'|'\\'|'@'|'#'|'?'|'!'|'.';
fragment ALPHA_UC : 'A'..'Z';
fragment ALPHA_LC : 'a'..'z';
fragment DIGIT : '0'..'9';
WS : (' ' | '\t') {$channel=HIDDEN;}
;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090518/5c842450/attachment.html
More information about the antlr-interest
mailing list