[antlr-interest] scoped variable not being passed
Warner Onstine
warnero at gmail.com
Wed Aug 29 13:34:42 PDT 2007
Ok, next to last question (I have one nagging grammar generation
question left, but want to get this one fixed before I pose it). I
have a prog scope variable (prog is one of the first matches which
I'll show below), I want to reference this variable in a later match
but it isn't being passed along and I'm not sure what I need to do to
get it to pass correctly.
Here's where it is declared:
prog
scope {
List methods;
List imports;
String className;
}
@init {
$prog::methods = new ArrayList();
$prog::imports = new ArrayList();
$prog::className = new String();
}
: packageDecl importsDecl? model ->
prog(packageName={$packageDecl.st}, imports={$prog::imports},
className={$prog::className}, methods={$prog::methods})
;
The variable I want to reference is $prog::className and I want to
reference it in my later statements (which I think are under the
method scope), here is where the method scope is declared later.
method
scope {
List localVars;
}
@init {
$method::localVars = new ArrayList();
}
: returnType=type? name=ID '(' p=parameter? ')' '{' methodBody=body? '}'
-> method(returnType={returnType != null ? $returnType.st : new
String("void")},
name={$name.text},
param={p != null ? $p.st : new String("")},
body={methodBody != null ? $method::localVars : null})
;
And I want to use the className variable here:
criteriaBlock
: '{' ID_EQUALS '(' ID ')' '}' -> id_eq(id={$ID.text},
model={$prog::className})
;
Again, I've attached the grammar for reference.
-warner
--
Warner Onstine - Programmer/Author
New book on Tapestry 4!
Tapestry 101 available at
http://sourcebeat.com/books/tapestrylive.html
warner at warneronstine.com
http://warneronstine.com/blog
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Model.g
Type: application/octet-stream
Size: 2966 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070829/8337a210/attachment.obj
More information about the antlr-interest
mailing list