sometimes, when the necessary look ahead is small and is bounded,
syntactic predicates can be your friend.
see attached.
grammar LexerOnly;
@members {
private static final String [] x = new String[]{
"a8 b c = d e23 f",
"a1b2c3 = xyz",
"a1 2 b"
};
public static void main(String [] args) {
for( int i = 0; i < x.length; ++i ) {
try {
System.out.println("about to lex:`"+x[i]+"`");
LexerOnlyLexer lexer =
new LexerOnlyLexer(new ANTLRStringStream(x[i]));
int j = 1;
Token token = lexer.nextToken();
while( token.getType() != LexerOnlyLexer.EOF ) {
System.out.format("\%d: type = \%s, text = `\%s`\%n",
j,
tokenNames[token.getType()],
token.getText());
j++;
token = lexer.nextToken();
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
}
list_of_tokens : .+ EOF ; // dummy, this rule is never used by this test case...
NUMBER : DIGIT+ ;
NAME : ID ( (WS ID_HEAD)=> WS ID )* ;
EQU : '=' ;
WHITESPACE : WS { $channel = HIDDEN; };
fragment ID : ID_HEAD ID_TAIL* ;
fragment ID_HEAD : ALPHA ;
fragment ID_TAIL : ALPHA | DIGIT;
fragment ALPHA : ('a'..'z')|('A'..'Z') ;
fragment DIGIT : '0'..'9' ;
fragment WS : ' '+ ;
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
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.