[antlr-interest] Rematching AST Nodes
Courtney Falk
court at infiauto.com
Sat Apr 30 08:34:53 PDT 2011
I'm not certain this is a feasible strategy. Please let me know if
I'm working on something that's not possible.
I have a grammar, Alpha, that generates an AST as the first processing
stage. What I'm trying to do is use a tree grammar, Beta, that looks at
the AST nodes and attempts to match them against a second, different
lexical pattern.
The grammars might look like:
//-----
grammar Alpha
options { ASTLabelType=CommonTree; output=AST; }
tokens { ROOT; MATCH; DONTMATCH; }
root : subnodes+ -> ^(ROOT subnodes+);
subnodes : numbers | characters;
numbers : NUMBERS -> ^(DONTMATCH NUMBERS);
characters : CHARACTERS -> ^(MATCH CHARACTERS);
WHITESPACE : (' ' | '\r' | '\n' | '\t')+ { $channel = HIDDEN; }
NUMBERS : ('0'..'9')+;
CHARACTERS : ('a'..'z')+;
//-----
tree grammar Beta;
options { filter=true; tokenVocab=Alpha; }
root : ^(ROOT subnodes+);
subnode : numbers | characters;
numbers : ^(DONTMATCH NUMBERS) { System.out.println("Don't match"); };
characters : ^(MATCH rematch);
rematch : 'aaa' { System.out.println("Triple A"); }
//-----
I can't seem to find of way of making the "rematch" rule work.
Courtney Falk
court at infiauto.com
More information about the antlr-interest
mailing list