0

我正在尝试STGroup从 a构建 a,String但它抱怨无效字符和缺少模板:

    final String templates = "a(x) ::= <li>$x.fname$ $x.lname$</li>\n" +
                             "b(persons) ::= <ul>$persons:a()$</ul>\n";
    final STGroup grp = new STGroupString("mysource", templates, '$', '$');

这是它喷出的错误:

mysource 1:10: invalid character '<'
mysource 1:10: missing template at 'li'
mysource 1:12: invalid character '>'
mysource 1:13: invalid character '$'
mysource 1:10: garbled template definition starting at 'li'
mysource 1:14: garbled template definition starting at 'x'
mysource 1:21: invalid character '$'
mysource 1:23: invalid character '$'
mysource 1:16: garbled template definition starting at 'fname'
mysource 1:24: garbled template definition starting at 'x'
mysource 1:31: invalid character '$'
mysource 1:33: invalid character '<'
mysource 1:34: invalid character '/'
mysource 1:26: garbled template definition starting at 'lname'
mysource 1:36: invalid character '>'
mysource 1:34: garbled template definition starting at 'li'
mysource 2:16: invalid character '<'
mysource 2:16: missing template at 'ul'
mysource 2:18: invalid character '>'
mysource 2:19: invalid character '$'
mysource 2:16: garbled template definition starting at 'ul'
mysource 2:20: garbled template definition starting at 'persons'
mysource 2:31: invalid character '$'
mysource 2:33: invalid character '<'
mysource 2:34: invalid character '/'
mysource 2:36: invalid character '>'
mysource 2:34: missing '::=' at 'ul'
mysource 2:34: missing template at 'ul'
mysource 2:28: redefinition of template a
mysource 2:34: garbled template definition starting at 'ul'

我想使用$作为我的分隔符,能够呈现这些模板的正确格式是什么?

4

1 回答 1

0

我想出了一个程序解决方案,其中包含一些相关问题的答案和一些实验:

    STGroup grp = new STGroup('$', '$');
    final CompiledST templateA = grp.defineTemplate("a", "<li>$it.fname$ $it.lname$</li>");
    templateA.addArg(new FormalArgument("it"));
    final CompiledST templateB = grp.defineTemplate("b", "<ul>$list:a()$</ul>");
    templateB.addArg(new FormalArgument("list"));
于 2013-02-08T11:32:59.457 回答