ANTLR : How to replace all characters defined as space with actual space

Posted by Puneet Pawaia on Stack Overflow See other posts from Stack Overflow or by Puneet Pawaia
Published on 2010-12-24T13:29:55Z Indexed on 2010/12/24 18:54 UTC
Read the original article Hit count: 273

Filed under:

Hi All,

My ANTLR code is as follow :

LPARENTHESIS : ('('); 
RPARENTHESIS : (')'); 

fragment CHARACTER : ('a'..'z'|'0'..'9'|); 
fragment QUOTE     : ('"'); 
fragment WILDCARD  : ('*'); 
fragment SPACE     : (' '|'\n'|'\r'|'\t'|'\u000C'|';'|':'|','); 

WILD_STRING 
   : (CHARACTER)* 
     ( 
       ('?') 
       (CHARACTER)* 
     )+ 
   ; 
PREFIX_STRING 
   : (CHARACTER)+
     ( 
       ('*')  
     )+ 
   ; 
WS     : (SPACE) { $channel=HIDDEN; }; 
PHRASE : (QUOTE)(LPARENTHESIS)?(WORD)(WILDCARD)?(RPARENTHESIS)?((SPACE)+(LPARENTHESIS)?(WORD)(WILDCARD)?(RPARENTHESIS)?)*(SPACE)+(QUOTE); 
WORD   : (CHARACTER)+; 

What I would like to do is to replace all characters marked as space to be replaced with actual space character in the PHRASE. Also if possible, I would then like all continuous spaces to be represented by a single space.

Any help would be most appreciated. For some reason, I am finding it hard to understand ANTLR. Any good tutorials out there ?

© Stack Overflow or respective owner

Related posts about antlr3