Thanks so much Michael :)

That worked perfectly. I wouldn't yet know if its the best approach or not,
but it works as I want it to, so I'm more than satisfied! I'll read up more
on syntactic predicates.

If it helps others, this is what Michael proposed...

grammar Space;

@members {

  public static void main(String[] args) throws Exception {
       SpaceLexer lex = new SpaceLexer(new ANTLRStringStream("sec  =  fooz,
foo z foofooz"));
       CommonTokenStream tokens = new CommonTokenStream(lex);

       SpaceParser parser = new SpaceParser(tokens);

       try {
           parser.clause();
       } catch (RecognitionException e)  {
           e.printStackTrace();
       }
   }

}



clause  : keyword_clause EOF;

keyword_clause
   :
     keyword_field { System.out.println($keyword_field.text);} EQ
search_term_list
   ;

keyword_field:  KEYWORD_SEC | KEYWORD_CP ;

search_term_list    :    search_term (',' search_term)* ;

search_term: KEYWORD {System.out.println($KEYWORD.text);} ;

fragment KEYWORD_SEC: 'sec';
fragment KEYWORD_CP: 'cp';
fragment KEYWORD: CHAR (CHAR | ' ')* ;


ALL_KEYWORD:
           ( (KEYWORD_SEC WS* EQ) => KEYWORD_SEC { $type = KEYWORD_SEC; }
           | (KEYWORD_CP WS* EQ) => KEYWORD_CP { $type = KEYWORD_CP; }
           | (KEYWORD) => KEYWORD { $type = KEYWORD; }
           )
           ;

EQ            : '=';
 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;}
       ;

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to