[antlr-interest] scoped variable not being passed

Warner Onstine warnero at gmail.com
Mon Sep 3 10:37:38 PDT 2007


Never did hear from anyone on this issue, is this doable? I've tried a
couple of different things I thought might work but yielded the same
result.

-warner

On 8/29/07, Warner Onstine <warnero at gmail.com> wrote:
> 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
>
>


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


More information about the antlr-interest mailing list