[antlr-interest] Why does syntactic predicate not take effect?
Britta Kiera
nukiti at yahoo.de
Mon Nov 10 02:32:07 PST 2008
I'm replacing a handwritten config file parser by an ANTLR based implementation. The config files contain so called feature configurations which look like this:
plugins.navigation.GoTo Outline XRefs {}
where "plugins.navigation." is the feature path and "Goto Outline XRefs" is a sequence of three feature names. The braces contain some property definitions which are omitted here.
The lexer was supposed to generate a NAMES token for the feature name sequence. The definition below shows an approach that I tried to accomplish this. This approach didn't work. The lexer never generated a NAMES token although I tried
to enforce this using a syntactic predicate. I solved this problem in the parser but I'd like to understand why the
syntactic predicate does not take effect. Can somebody explain this to me?
Thank you,
Nukiti
================================= ANTLR lexer start ==========================================
lexer grammar SimpleLex;
options {
language = Java;
}
@header {
package test.antlr;
import java.io.StringReader;
}
@members {
public static void main(String args[]) throws Exception {
String input = " plugins.navigation.XRefs Outline GoTo {}";
CharStream cs = new ANTLRStringStream(input);
SimpleLex lex = new SimpleLex(cs);
Token t;
do {
String type;
t=lex.nextToken();
switch(t.getType()) {
case IDENT: type = "IDENT"; break;
case NAMES: type = "NAMES"; break;
case DOT : type = "DOT" ; break;
case WHITE: type = "WHITE"; break;
case LB : type = "LB" ; break;
case RB : type = "RB" ; break;
default : type = Integer.toString(t.getType()); break;
}
System.out.printf("Token: %6s(%2d) >%s<\n", type, t.getChannel(), t.getText());
}
while(t.getType() != -1);
}
}
IDENT
: (ID (WS ID)+)=> ID (WS ID)+ {$type = NAMES;}
| ID
;
WHITE
: WS { $channel = HIDDEN; }
;
NAMES:
;
LB : '{' ;
RB : '}' ;
DOT : '.' ;
fragment WS : (' '|'\r'|'\t'|'\u000C'|'\n')+;
fragment ID : LETTER (LETTER|DIGIT)*;
fragment DIGIT : '0'..'9';
fragment LETTER: 'A'..'Z' | 'a'..'z' | '_';
================================= ANTLR lexer end ==========================================
More information about the antlr-interest
mailing list