本文整理汇总了C#中Antlr4.StringTemplate.TemplateGroupFile类的典型用法代码示例。如果您正苦于以下问题:C# TemplateGroupFile类的具体用法?C# TemplateGroupFile怎么用?C# TemplateGroupFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TemplateGroupFile类属于Antlr4.StringTemplate命名空间,在下文中一共展示了TemplateGroupFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestImportDir
public void TestImportDir()
{
/*
dir1
g.stg has a() that imports dir2 with absolute path
dir2
a.st
b.st
*/
string dir1 = Path.Combine(tmpdir, "dir1");
string dir2 = Path.Combine(tmpdir, "dir2");
string gstr =
"import \"" + dir2 + "\"\n" +
"a() ::= <<dir1 a>>\n";
writeFile(dir1, "g.stg", gstr);
string a = "a() ::= <<dir2 a>>\n";
string b = "b() ::= <<dir2 b>>\n";
writeFile(dir2, "a.st", a);
writeFile(dir2, "b.st", b);
TemplateGroup group = new TemplateGroupFile(Path.Combine(dir1, "g.stg"));
Template st = group.GetInstanceOf("b"); // visible only if import worked
string expected = "dir2 b";
string result = st.Render();
Assert.AreEqual(expected, result);
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:27,代码来源:TestImports.cs
示例2: TestAlias
public void TestAlias()
{
string dir = tmpdir;
string groupFile =
"a() ::= \"bar\"\n" +
"b ::= a\n";
writeFile(dir, "group.stg", groupFile);
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "group.stg"));
Template st = group.GetInstanceOf("b");
string expected = "bar";
string result = st.Render();
Assert.AreEqual(expected, result);
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:13,代码来源:TestGroups.cs
示例3: TestDefaultValueBehaviorEmptyTemplate
public void TestDefaultValueBehaviorEmptyTemplate()
{
string templates =
"t(a={}) ::= <<\n" +
"<a><if(a)>+<else>-<endif>\n" +
">>\n";
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(tmpdir + Path.DirectorySeparatorChar + "t.stg");
Template st = group.GetInstanceOf("t");
string expected = "+";
string result = st.Render();
Assert.AreEqual(expected, result);
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:14,代码来源:TestGroupSyntax.cs
示例4: ProcessTemplate
private static void ProcessTemplate([NotNull] string templateFile, Model.Model model)
{
if (templateFile == null) throw new ArgumentNullException("templateFile");
Template template = new TemplateGroupFile(templateFile)
.GetInstanceOf(MAIN_TEMPLATE_NAME);
if (template == null)
throw new ArgumentException(string.Format("Template {0} not found", MAIN_TEMPLATE_NAME));
template.Add(MODEL_VAR, model);
File.WriteAllText(BuildTargetFileName(templateFile), template.Render());
}
开发者ID:jeromerg,项目名称:NDocUtil,代码行数:14,代码来源:NGitVersion.cs
示例5: TestCantDefineEmbeddedRegionAgain
public void TestCantDefineEmbeddedRegionAgain()
{
string dir = tmpdir;
string g = "a() ::= <<[<@r>foo<@end>]>>\n" +
"@a.r() ::= <<bar>>\n"; // error; dup
writeFile(dir, "g.stg", g);
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg"));
ErrorBuffer errors = new ErrorBuffer();
group.Listener = errors;
group.Load();
string expected = "g.stg 2:3: the explicit definition of region /a.r hides an embedded definition in the same group" + newline;
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:15,代码来源:TestRegions.cs
示例6: TestFortranLineWrap
public void TestFortranLineWrap()
{
string templates =
"Function(args) ::= << FUNCTION line( <args; wrap=\"\\n c\", separator=\",\"> )>>" + newline;
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
Template a = group.GetInstanceOf("Function");
a.Add("args",
new string[] { "a", "b", "c", "d", "e", "f" });
string expecting =
" FUNCTION line( a,b,c,d," + Environment.NewLine +
" ce,f )";
Assert.AreEqual(expecting, a.Render(30));
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:15,代码来源:TestLineWrap.cs
示例7: TestArg
public void TestArg()
{
string templates =
"foo(a,) ::= << >>\n";
writeFile(tmpdir, "t.stg", templates);
TemplateGroupFile group;
ITemplateErrorListener errors = new ErrorBuffer();
group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
group.Load(); // force load
string expected = "t.stg 1:6: missing ID at ')'" + newline;
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
开发者ID:antlr,项目名称:antlrcs,代码行数:15,代码来源:TestGroupSyntaxErrors.cs
示例8: TestAliasWithArgs
public void TestAliasWithArgs()
{
string dir = tmpdir;
string groupFile =
"a(x,y) ::= \"<x><y>\"\n" +
"b ::= a\n";
writeFile(dir, "group.stg", groupFile);
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "group.stg"));
Template st = group.GetInstanceOf("b");
st.Add("x", 1);
st.Add("y", 2);
string expected = "12";
string result = st.Render();
Assert.AreEqual(expected, result);
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:15,代码来源:TestGroups.cs
示例9: TestAnonymousTemplateInRegion
public void TestAnonymousTemplateInRegion()
{
string dir = tmpdir;
string g = "a() ::= <<[<@r()>]>>\n" +
"@a.r() ::= <<\n"+
"<[\"foo\"]:{x|<x>}>\n"+
">>\n";
writeFile(dir, "g.stg", g);
TemplateGroup group = new TemplateGroupFile(Path.Combine(dir, "g.stg"));
Template st = group.GetInstanceOf("a");
string expected = "[foo]";
string result = st.Render();
Assert.AreEqual(expected, result);
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:15,代码来源:TestRegions.cs
示例10: TestDefaultArgument
public void TestDefaultArgument()
{
string templates =
"method(name) ::= <<" + newline +
"$stat(name)$" + newline +
">>" + newline +
"stat(name,value=\"99\") ::= \"x=$value$; // $name$\"" + newline
;
writeFile(tmpdir, "group.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "group.stg"), '$', '$');
Template b = group.GetInstanceOf("method");
b.Add("name", "foo");
string expecting = "x=99; // foo";
string result = b.Render();
Assert.AreEqual(expecting, result);
}
开发者ID:jamilgeor,项目名称:antlrcs,代码行数:16,代码来源:TestDollarDelimiters.cs
示例11: TestIndirectCallWithPassThru
public void TestIndirectCallWithPassThru()
{
// pass-through for dynamic template invocation is not supported by the
// bytecode representation
writeFile(tmpdir, "t.stg",
"t1(x) ::= \"<x>\"\n" +
"main(x=\"hello\",t=\"t1\") ::= <<\n" +
"<(t)(...)>\n" +
">>");
TemplateGroup group = new TemplateGroupFile(tmpdir + "/t.stg");
ErrorBuffer errors = new ErrorBuffer();
group.Listener = errors;
Template st = group.GetInstanceOf("main");
Assert.AreEqual("t.stg 2:34: mismatched input '...' expecting RPAREN" + newline, errors.ToString());
Assert.IsNull(st);
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:16,代码来源:TestIndirectionAndEarlyEval.cs
示例12: TestInstanceofRenderer
public void TestInstanceofRenderer()
{
string templates =
"numberThing(x,y,z) ::= \"numbers: <x>, <y>; <z>\"\n";
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.RegisterRenderer(typeof(int), new NumberRenderer());
group.RegisterRenderer(typeof(double), new NumberRenderer());
Template st = group.GetInstanceOf("numberThing");
st.Add("x", -2100);
st.Add("y", 3.14159);
st.Add("z", "hi");
string expecting = "numbers: -2100, 3.14159; hi";
string result = st.Render();
Assert.AreEqual(expecting, result);
}
开发者ID:antlr,项目名称:antlrcs,代码行数:16,代码来源:TestRenderers.cs
示例13: TestEarlyEvalInIfExpr
public void TestEarlyEvalInIfExpr()
{
string templates = "main(x) ::= << <if((x))>foo<else>bar<endif> >>";
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(tmpdir + "/t.stg");
Template st = group.GetInstanceOf("main");
string s = st.Render();
Assert.AreEqual(" bar ", s);
st.Add("x", "true");
s = st.Render();
Assert.AreEqual(" foo ", s);
}
开发者ID:antlr,项目名称:antlrcs,代码行数:16,代码来源:TestEarlyEvaluation.cs
示例14: TestAttribute
public void TestAttribute()
{
string templates =
"t(x) ::= << <x> >>" + Environment.NewLine;
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
Template st = group.GetInstanceOf("t");
List<InterpEvent> events = st.GetEvents();
string expected =
"[IndentEvent{self=/t(x), expr=' <x>', source=[0..4), output=[0..1)}," +
" EvalExprEvent{self=/t(x), expr='<x>', source=[1..4), output=[0..0)}," +
" EvalExprEvent{self=/t(x), expr=' ', source=[4..5), output=[0..1)}," +
" EvalTemplateEvent{self=/t(x), output=[0..1)}]";
string result = events.ToListString();
Assert.AreEqual(expected, result);
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:17,代码来源:TestDebugEvents.cs
示例15: TestAccessDictionaryFromAnonymousTemplate
public void TestAccessDictionaryFromAnonymousTemplate()
{
string dir = tmpdir;
string g =
"a() ::= <<[<[\"foo\",\"a\"]:{x|<if(values.(x))><x><endif>}>]>>\n" +
"values ::= [\n" +
" \"a\":false,\n" +
" default:true\n" +
"]\n";
writeFile(dir, "g.stg", g);
TemplateGroup group = new TemplateGroupFile(Path.Combine(dir, "g.stg"));
Template st = group.GetInstanceOf("a");
string expected = "[foo]";
string result = st.Render();
Assert.AreEqual(expected, result);
}
开发者ID:antlr,项目名称:antlrcs,代码行数:17,代码来源:TestDictionaries.cs
示例16: TestHiddenPropertyNotError
public void TestHiddenPropertyNotError()
{
ErrorBuffer errors = new ErrorBuffer();
string templates =
"t(u) ::= \"<u.name>\"" + Environment.NewLine;
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
Template st = group.GetInstanceOf("t");
st.Add("u", new UserHiddenName("parrt"));
st.Render();
string expected = "";
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:17,代码来源:TestInterptimeErrors.cs
示例17: TestLocaleWithNumberRenderer
public void TestLocaleWithNumberRenderer()
{
//string templates = "foo(x,y) ::= << <x; format=\"%,d\"> <y; format=\"%,2.3f\"> >>\n";
string templates = "foo(x,y) ::= << <x; format=\"{0:#,#}\"> <y; format=\"{0:0.000}\"> >>\n";
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.RegisterRenderer(typeof(int), new NumberRenderer());
group.RegisterRenderer(typeof(double), new NumberRenderer());
Template st = group.GetInstanceOf("foo");
st.Add("x", -2100);
st.Add("y", 3.14159);
// Polish uses ' ' (ASCII 160) for ',' and ',' for '.'
string expecting = " -2 100 3,142 "; // Ê
string result = st.Render(new CultureInfo("pl"));
Assert.AreEqual(expecting, result);
}
开发者ID:antlr,项目名称:antlrcs,代码行数:17,代码来源:TestRenderers.cs
示例18: TestIndentBeyondLineWidth
public void TestIndentBeyondLineWidth()
{
string templates =
"duh(chars) ::= << <chars; wrap=\"\\n\"\\>>>" + newline;
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
Template a = group.GetInstanceOf("duh");
a.Add("chars", new string[] { "a", "b", "c", "d", "e" });
//
string expecting =
" a" + Environment.NewLine +
" b" + Environment.NewLine +
" c" + Environment.NewLine +
" d" + Environment.NewLine +
" e";
Assert.AreEqual(expecting, a.Render(2));
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:18,代码来源:TestLineWrap.cs
示例19: TestDefineRegionInSubgroup
public void TestDefineRegionInSubgroup()
{
string dir = tmpdir;
string g1 = "a() ::= <<[<@r()>]>>\n";
writeFile(dir, "g1.stg", g1);
string g2 = "@a.r() ::= <%\n" +
" foo\n\n\n" +
"%>\n";
writeFile(dir, "g2.stg", g2);
TemplateGroup group1 = new TemplateGroupFile(Path.Combine(dir, "g1.stg"));
TemplateGroup group2 = new TemplateGroupFile(Path.Combine(dir, "g2.stg"));
group2.ImportTemplates(group1); // define r in g2
Template st = group2.GetInstanceOf("a");
string expected = "[foo]";
string result = st.Render();
Assert.AreEqual(expected, result);
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:18,代码来源:TestNoNewlineTemplates.cs
示例20: ProcessTemplate
private static void ProcessTemplate(string templateFile, Model.Model model)
{
string targetFile = BuildTargetFileName(templateFile);
Console.WriteLine("\ttemplate: " + templateFile);
try
{
Template template = new TemplateGroupFile(templateFile)
.GetInstanceOf(MAIN_TEMPLATE_NAME);
template.Add(MODEL_VAR, model);
File.WriteAllText(targetFile, template.Render());
}
finally
{
Console.WriteLine("\toutput: " + targetFile);
}
}
开发者ID:jrgcubano,项目名称:NAsync,代码行数:19,代码来源:NGitVersion.cs
注:本文中的Antlr4.StringTemplate.TemplateGroupFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论