本文整理汇总了C#中Antlr4.StringTemplate.TemplateGroupFile.GetInstanceOf方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateGroupFile.GetInstanceOf方法的具体用法?C# TemplateGroupFile.GetInstanceOf怎么用?C# TemplateGroupFile.GetInstanceOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr4.StringTemplate.TemplateGroupFile
的用法示例。
在下文中一共展示了TemplateGroupFile.GetInstanceOf方法的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: TestIndexAttrVisibleLocallyOnly
public void TestIndexAttrVisibleLocallyOnly()
{
string templates =
"t(names) ::= \"<names:{n | <u(n)>}>\"\n" +
"u(x) ::= \"<i>:<x>\"";
ErrorBuffer errors = new ErrorBuffer();
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
Template st = group.GetInstanceOf("t");
st.Add("names", "Ter");
string result = st.Render();
group.GetInstanceOf("u").impl.Dump();
string expectedError = "t.stg 2:11: implicitly-defined attribute i not visible" + newline;
Assert.AreEqual(expectedError, errors.ToString());
string expected = ":Ter";
Assert.AreEqual(expected, result);
group.Listener = ErrorManager.DefaultErrorListener;
}
示例3: tryMyTemplate
public static string tryMyTemplate()
{
TemplateGroup stg = new TemplateGroupFile(@"C:\Users\Paulo\SkyDrive\Visual Studio 2013\Projects\DecafIde\DecafIde\CIL.stg");
Template fileTemplate = stg.GetInstanceOf("file");
Template structTemplate = stg.GetInstanceOf("struct");
structTemplate.Add("name", "name1");
structTemplate.Add("fields", "field1");
structTemplate.Add("fields", "field2");
fileTemplate.Add("defs", structTemplate.Render());
structTemplate = stg.GetInstanceOf("struct");
structTemplate.Add("name", "name2");
structTemplate.Add("fields", "field21");
structTemplate.Add("fields", "field22");
fileTemplate.Add("defs", structTemplate.Render());
return fileTemplate.Render();
}
示例4: 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);
}
示例5: SimpleVisualizerTest
public void SimpleVisualizerTest()
{
string templates =
"method(type,name,locals,args,stats) ::= <<\n" +
"public <type> <ick()> <name>(<args:{a| int <a>}; separator=\", \">) {\n" +
" <if(locals)>int locals[<locals>];<endif>\n" +
" <stats;separator=\"\\n\">\n" +
"}\n" +
">>\n" +
"assign(a,b) ::= \"<a> = <b>;\"\n" +
"return(x) ::= <<return <x>;>>\n" +
"paren(x) ::= \"(<x>)\"\n";
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.TrackCreationEvents = true;
Template st = group.GetInstanceOf("method");
st.impl.Dump();
st.Add("type", "float");
st.Add("name", "foo");
st.Add("locals", 3);
st.Add("args", new string[] { "x", "y", "z" });
Template s1 = group.GetInstanceOf("assign");
Template paren = group.GetInstanceOf("paren");
paren.Add("x", "x");
s1.Add("a", paren);
s1.Add("b", "y");
Template s2 = group.GetInstanceOf("assign");
s2.Add("a", "y");
s2.Add("b", "z");
Template s3 = group.GetInstanceOf("return");
s3.Add("x", "3.14159");
st.Add("stats", s1);
st.Add("stats", s2);
st.Add("stats", s3);
st.Visualize();
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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));
}
示例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: 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);
}
示例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: 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);
}
示例14: 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);
}
示例15: 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);
}