[stringtemplate-interest] stg file templates: Argument resolution bug?

Graham Wideman gwlist at grahamwideman.com
Tue May 26 18:14:57 PDT 2009


Hi folks:

I'm trying to puzzle out the conceptual logic behind argument passing and argument requirements-checking when using a string template group file, and calling one template from another.

The following cases seem to illustrate that stg's requirement for attributes to be declared as arguments is broken:

-----------------------------------
group test;

outer(arg1) ::= <<
arg1:  [ $arg1$ ]
inner: [ $inner("xxx")$ ]
>>

inner(argX) ::= <<
argX: [ $argX$ ]
argY: [ $argY$ ]
>>
-----------------------------------

Case 1: If my program invokes inner() directly, supplying an attribute for argX, then this runs, treating argY as though it's a null string, and does NOT report an error that there's an expression that references an argument that's not declared.

Case 2: If my program invokes outer(), supplying an attribute for arg1, this results in message:
"Error: no such attribute: argY in template context [outer inner]"

So, I think Case 2 shows the intended behavior, and Case 1 is a bug, as it violates this from the docs:

"When using a group file format to specify templates, you must specify the formal arguments for that template. If you try to access an attribute that is not formally defined in that template or an enclosing template, you will get a InvalidOperationException."

Comments?

-- Graham


More information about the stringtemplate-interest mailing list