0

STGroupからを構築しようとして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

私はいくつかの関連する質問といくつかの実験への答えで1つの手続き上の解決策を見つけました:

    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 に答える