[stringtemplate-interest] How to call a template from another when using formal args
Zenaan Harkness
zen at freedbms.net
Fri Apr 3 15:27:53 PDT 2009
> I have looked at the simple_group_example tutorial in the wiki and the
> test cases but I haven't found an example that could show me how to
> Define a template that calls another one with formal arguments.
Somewhere there are a bunch of test cases - look in the src for a test/
directory. There should be many test cases for various features.
> The code below does not even parse.
> It tries to define a "zero" template that takes one single arg and
> that calls "equals" which takes 2 args by setting the second one to a
> fixed value 0.
"equals" sounds suspiciously like a reserved word. It may not be, but
check to ensure that you're not using reserved words as template names.
You will find a page on the wiki.
> String templates = "group test; "
> + "equals(a, b) ::= <<$a$ = $b$>>"
> + "zero(a) ::= <<$equals($a$,0)$>>";
Single line templates may have to use quote (") characters instead of
double angle-brackets. With double-angle brackets you may need
a space after the first pair, and a space before the last pair.
Sorry for being so indefinite, I haven't been using ST for 9 months or
so - a bit rusty I am.
> StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), DefaultTemplateLexer.class);
I think DefaultTemplateLexer is for quote grouping (").
You might need AngleBracketLexer.
> action parse error in group test line 1; template context is [zero]
> line 1:1: unexpected token: equals
Looks like you're using a reserved word.
Good luck
Zen
--
Homepage: www.SoulSound.net -- Free Australia: www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.
More information about the stringtemplate-interest
mailing list