[antlr-interest] still dealing with ST

Warner Onstine warnero at gmail.com
Mon Aug 27 19:25:07 PDT 2007


On 8/27/07, Terence Parr <parrt at cs.usfca.edu> wrote:
> Hi.
>
> why the extra parens?
>
> variableName=(variableDecl|ID)
>
> That means result of a subrule not rule, which doesn't return
> anything (at least for now).
Ahh, ok.

What I'm trying to do is give developers this option:
def someVar = someValue
def someVar (from the earlier variableDecl)
someVar = someValue

I've changed this section to this:
variableAssignment
	:	atom '=' statementValue -> variable_assignment(var={$atom.st},
value={$statementValue.st})
	;

atom	: 	variableDecl 	-> variable_decl(variable={$variableDecl.st})
	|	ID		-> {new StringTemplate($ID.text)}
	;

statementValue
	:	selectStatement
	|	updateStatement	
	|	deleteStatement	
	|	ID		-> {new StringTemplate($ID.text)}
	;

(not sure what to do with the selectStatement, updateStatement, etc. yet. )

When I run my test (which I'm attaching) I get this NullPointerException:
java.lang.NullPointerException
	at ModelParser.variableDecl(ModelParser.java:667)
	at ModelParser.atom(ModelParser.java:780)
	at ModelParser.variableAssignment(ModelParser.java:709)
	at ModelParser.body(ModelParser.java:573)
	at ModelParser.method(ModelParser.java:460)
	at ModelParser.model(ModelParser.java:332)
	at ModelParser.prog(ModelParser.java:114)

I'm sure there are better ways to do what I want to do, just looking
for some pointers.

>
> Ter
> On Aug 27, 2007, at 4:29 PM, Warner Onstine wrote:
>
> > Ok, got around a few of my earlier issues and have started to create
> > my template and rules for rewriting things, but I'm stuck on (I think)
> > one of the last assignments. I will attach the grammar, but I want to
> > highlight the section I'm currently having an issue with.
> >
> >
> > variableAssignment
> >       :       variableName=(variableDecl|ID) '='
> > variableValue=(selectStatement|updateStatement|deleteStatement|ID) ->
> > variable_assignment(var={$variableName.st},
> > valueToAssign={$variableValue.st})
> >       ;
> >
> > No matter what I do the Java that is generated has issues here:
> >
> >             {
> >                 retval.st = templateLib.getInstanceOf
> > ("variable_assignment",
> >               new STAttrMap().put("var",
> > variableName.st).put("valueToAssign", variableValue.st));
> >
> >             }
> >
> > It keeps saying that variableName.st and variableValue.st cannot be
> > resolved. Further up in the file they are set to:
> >         Token variableName=null;
> >         Token variableValue=null;
> >
> > And I realize that I may doing something completely wrong here, but
> > what I'm trying to do is to pass off the rendered template (sorry if
> > the terminology is incorrect just stating it how I see it) to the
> > calling template function (variable_assignment in this case). the
> > variable_assignment function (in the STG file) shouldn't have to know
> > what kind of variable is getting assigned etc. to actually just spit
> > out the rendered text.
> >
> > Let me know if you want the generated Java file.
> >
> > -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
> > <Model.g>
>
>


-- 
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: 2002 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070827/e93b3e78/attachment-0002.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ModelTest.java
Type: application/octet-stream
Size: 1651 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20070827/e93b3e78/attachment-0003.obj 


More information about the antlr-interest mailing list