2012-03-26 104 views
3

当使用StringTemplate的4.0.2以下对象结构:StringTemplate的-4:使用 '@' 作为自定义分隔符

ST st = new ST("@[email protected]", '@', '@'); 

产生异常:

1:8: '@' came as a complete surprise to me 
Exception in thread "main" org.stringtemplate.v4.compiler.STException 
    at org.stringtemplate.v4.compiler.Compiler.reportMessageAndThrowSTException(Compiler.java:213) 
    at org.stringtemplate.v4.compiler.Compiler.compile(Compiler.java:143) 
    at org.stringtemplate.v4.STGroup.compile(STGroup.java:427) 
    at org.stringtemplate.v4.ST.<init>(ST.java:142) 
    at org.stringtemplate.v4.ST.<init>(ST.java:136) 

是否有某种特殊的方式使用“@”字符作为自定义分隔符还是简单地不允许?

回答

3

@用于定义区域并且是保留的操作符。

+0

很高兴知道,谢谢Terence – 2012-04-09 20:48:27

+0

以'@'作为分隔符来调用构造函数时抛出异常可能是一个想法。我花了很长时间才发现这是它无法工作的原因。 – wvdz 2014-05-27 11:54:20

+0

好点。添加了一个问题https://github.com/antlr/stringtemplate4/issues/84 – 2014-05-27 16:49:58