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 
==========================================




      

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/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
-~----------~----~----~----~------~----~------~--~---

Reply via email to