- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已成功使用StringTemplate 4在Visual Studio中进行了一些代码生成。我已经安装了StringTemplate和ANTLR的扩展,它们确实很棒。
在测试中,我可以弄清楚如何使用* .st4(StringTemplate)文件,但是如何使用* .stg(StringTemplateGroup)文件使我无所适从。它是可以嵌入到另一个StringTemplate中的定义的集合吗?如果是这样,那么从* .stg而不是* .st4生成的代码将是什么样?
最佳答案
StringTemplate组文件是存储在单个文件中的模板的集合。 GitHub上的ANTLR项目包含许多示例。例如Java.stg包含ANTLR 4的Java目标的所有代码生成模板。
您可以在StringTemplate C#项目本身的StringTemplateTests.cs文件中找到几个在C#中使用StringTemplate 3的示例。它不是最友好的文档,但确实包含涵盖了许多ST3功能的示例。这是使用StringTemplateGroup
的一个示例:
string templates =
"group dork;" + newline +
"" + newline +
"test(name) ::= <<" +
"<(name)()>" + newline +
">>" + newline +
"first() ::= \"the first\"" + newline +
"second() ::= \"the second\"" + newline
;
StringTemplateGroup group =
new StringTemplateGroup( new StringReader( templates ) );
StringTemplate f = group.GetInstanceOf( "test" );
f.SetAttribute( "name", "first" );
string expecting = "the first";
Assert.AreEqual( expecting, f.ToString() );
group dork;
test(name) ::= <<<(name)()>
>>
first() ::= "the first"
second() ::= "the second"
关于c# - StringTemplate与StringTemplateGroup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16472125/
我在 Java 中使用 StringTemplate 4.0.8。 在StringTemplate-4 documentation , 它说 Dictionary strings can also b
由于 return null; 之后的右花括号,以下 StringTemplate 给了我一个“无效字符 '}'”异常: $StatementList:{statement | public T $s
我正在尝试使用 StringTemplate 创建分层文档。 例如目录列表: \alpha \file1 \file2 \beta \file3 \gamma \file4
如何在 StringTemplate 部分中使用 $it$ 以外的变量名称? 最佳答案 什么是部分? 无论如何,如果模板有一个参数,ST 也会设置它的值 $a:t()$ 对于定义 t(v)::= "$
我有一张城市名称 map => 距原点的距离。 我想对这张 map 使用部分 map ,并创建类似这样的东西: city1: distance1 city2: distance2 city3: di
我正在使用 antlr-3.4-complete.jar,我相信它使用的是 StringTemplate 版本 3.2.1 我在树语法中有以下产品 functionCall : ^(FUNCCAL
我有一个像这样的类(class): public class Foo { private String s; } 我有一个所述对象的列表。我希望能够迭代此列表并打印出字符串属性 s。我有以下代
我正在使用 StringTemplate 自动生成配置文件,如果用户没有定义某些变量,则会出现错误。 StringTemplate 将用空字符串替换 undefined variable (我的意思是
我正在使用基于 Stringtemplate4 (ST) 的 ExcelExplorer 处理 Excel 文件。 这些文件包含几个带有日期的列。 默认情况下,日期按照“MM/dd/yy”日期格式呈现
这个问题已经有答案了: Why StringTemplate could be slow? (3 个回答) 已关闭 7 年前。 StringTemplate insert = new StringTe
我正在使用 StringTemplate 生成源代码,我需要呈现一个语句列表,我希望除最后一个之外的所有语句都用“;\n”分隔,但将最后一个语句格式化为包含在“返回项;\n”中我可以在模板中实现此目的
我想知道 StringTemplate 是否有/支持数字递增。 情况是: 输入:是一个具有“isKey() 和 getName() ” getter 的对象数组。 输出应该是( i=0; IF !ob
我想在 StringTemplate 中使用类似的东西 - 调用在执行渲染的应用程序中定义的函数,这可能吗? $renderArticle(article,width,padding)$ 我可以只
我正在为某些模板使用模板引擎 StringTemplate(显然)。 我想要的是能够将我的模板存储在单独的文件中,当然我可以使用简单的 .txt 文件并将它们读入 String 中,看起来有点像这样
我有这样的目录结构: Templates/ ├── Foo/ │ ├── Foo.st ├── Signature.st 这是 Foo.st 的样子: Som
假设我有一个模板 "{man} likes to do {do}" 我创建引擎 ST engine = new ST(template, '{', '}'); do 设置为 sports 且模型中没
我的 .stg 文件中有两个模板,它们都适用于多值 HashMap。 HashMap 被用作注入(inject)对象。 我需要那些可以多次注入(inject)的 HashMap 实例。 我的问题是,当
我在 C# 中使用 StringTemplate 并遵循代码从我的应用程序的子目录加载模板。 StringTemplateGroup group = new StringTemplateGroup("
假设我有要在 stringTemplate 中迭代的对象列表。对象看起来像这样: 公开课 a1 { private String name; private String value; private
在 StringTemplate 中,是否有一种内置的方法可以将字符串呈现为大写,例如像这样: my_template(component) ::= >> ... 还是我必须为此目的使用自定义渲染器
我是一名优秀的程序员,十分优秀!