[antlr-interest] Tree grammars and references to attributes of the calling rule
Dominique de Waleffe
ddewaleffe at gmail.com
Thu Sep 18 07:00:41 PDT 2008
I am exploring the use of tree grammars...
I exepcted to be able to write something like the following:
tree grammar PipelineWalker;
options {
language = Java;
tokenVocab=Pipeline;
ASTLabelType=CommonTree;
}
@header{
// import Pipeline;
}
pipeline[Pipeline p]: ^(PIPE header body) ;
header : ^('pipeline' name) {
System.out.println($pipeline::p.getName());
$pipeline::p.setName($name.text);}
;
Where the intent is to get my 'Pipeline' object from the top level and
modifying it while going down the tree.
The problem is that the references I make to $pipeline::p in my header rule
seem to go untranslated into the generated code:
System.out.println($pipeline::p.getName());
$pipeline::p.setName((name5!=null?(input.getTokenStream().toString(
input.getTreeAdaptor().getTokenStartIndex(name5.start),
input.getTreeAdaptor().getTokenStopIndex(name5.start))):null));
Whereas if I write
pipeline[Pipeline p]: ^(PIPE header[p] body) ;
header[Pipeline p] : ^('pipeline' name) {
System.out.println($p.getName());
$p.setName($name.text);}
;
The translation seems to be better....
So is this a misunderstanding ? Or is this a bug ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080918/01544419/attachment.html
More information about the antlr-interest
mailing list