本文整理汇总了C#中Antlr4.StringTemplate.TemplateGroupFile类的典型用法代码示例。如果您正苦于以下问题:C# TemplateGroupFile类的具体用法?C# TemplateGroupFile怎么用?C# TemplateGroupFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TemplateGroupFile类属于Antlr4.StringTemplate命名空间,在下文中一共展示了TemplateGroupFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}