本文整理汇总了C#中Antlr.StringTemplate.StringTemplateGroup.GetInstanceOf方法的典型用法代码示例。如果您正苦于以下问题:C# Antlr.StringTemplate.StringTemplateGroup.GetInstanceOf方法的具体用法?C# Antlr.StringTemplate.StringTemplateGroup.GetInstanceOf怎么用?C# Antlr.StringTemplate.StringTemplateGroup.GetInstanceOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr.StringTemplate.StringTemplateGroup
的用法示例。
在下文中一共展示了Antlr.StringTemplate.StringTemplateGroup.GetInstanceOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
// choose a skin or site "look" to present
string skin = "blue";
// allow overrides for language and skin from arguments on command line
string language = null;
if ( args.Length > 0 )
{
language = args[0];
}
if ( args.Length > 1)
{
if ( "blue".Equals(args[1]) || "red".Equals(args[1]) )
skin = args[1];
}
TryToSetRequestedLocale(language);
// load strings from a properties files like en.strings
ResourceManager resMgr = new ResourceManager("ST.Examples.i18n.Content.Strings", typeof(ResourceWrapper).Assembly);
ResourceWrapper strings = new ResourceWrapper(resMgr);
// get a template group rooted at appropriate skin
string absoluteSkinRootDirectoryName = Path.Combine(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName, skin);
StringTemplateGroup templates = new StringTemplateGroup("test", absoluteSkinRootDirectoryName);
// generate some pages; every page gets strings table to pull strings from
StringTemplate page1ST = templates.GetInstanceOf("page1");
page1ST.SetAttribute("strings", strings);
StringTemplate page2ST = templates.GetInstanceOf("page2");
page2ST.SetAttribute("strings", strings);
// render to text
Console.Out.WriteLine(page1ST);
Console.Out.WriteLine(page2ST);
}
示例2: testLineWrapForAnonTemplateComplicatedWrap
public void testLineWrapForAnonTemplateComplicatedWrap()
{
string templates = ""
+ "group test;" + NL
+ "top(s) ::= << <s>.>>" + "str(data) ::= <<!<data:{v|[<v>]}; wrap=\"!+\\n!\">!>>" + NL
;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates));
StringTemplate t = group.GetInstanceOf("top");
StringTemplate s = group.GetInstanceOf("str");
s.SetAttribute("data", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
t.SetAttribute("s", s);
string expecting = ""
+ " ![1][2]!+\n"
+ " ![3][4]!+\n"
+ " ![5][6]!+\n"
+ " ![7][8]!+\n"
+ " ![9]!.";
Assert.AreEqual(expecting, t.ToString(9));
}
示例3: testImplicitRegionRedefError
public void testImplicitRegionRedefError()
{
// cannot define an implicitly-defined template more than once
string templates = ""
+ "group test;" + NL
+ "a() ::= \"X<@r()>Y\"" + NL
+ "@a.r() ::= \"foo\"" + NL
+ "@a.r() ::= \"bar\"" + NL;
IStringTemplateErrorListener errors = new ErrorBuffer();
StringTemplateGroup group =
new StringTemplateGroup(new StringReader(templates), errors);
StringTemplate st = group.GetInstanceOf("a");
st.ToString();
string result = errors.ToString();
string expecting = "group test line 4: redefinition of template region: @a.r";
Assert.AreEqual(expecting, result);
}
示例4: testGroupFileFormat
public virtual void testGroupFileFormat()
{
string templates = ""
+ "group test;" + NL
+ @"t() ::= ""literal template""" + NL
+ @"bold(item) ::= ""<b>$item$</b>""" + NL
+ "duh() ::= <<" + NL
+ "xx" + NL
+ ">>" + NL;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(DefaultTemplateLexer));
string expecting = ""
+ "group test;" + NL
+ "bold(item) ::= <<<b>$item$</b>>>" + NL
+ "duh() ::= <<xx>>" + NL
+ "t() ::= <<literal template>>" + NL;
Assert.AreEqual(expecting, group.ToString());
StringTemplate a = group.GetInstanceOf("t");
expecting = "literal template";
Assert.AreEqual(expecting, a.ToString());
StringTemplate b = group.GetInstanceOf("bold");
b.SetAttribute("item", "dork");
expecting = "<b>dork</b>";
Assert.AreEqual(expecting, b.ToString());
}
示例5: testFormalArgumentAssignmentInApply
public virtual void testFormalArgumentAssignmentInApply()
{
string templates = ""
+ "group test;" + NL
+ @"page(name) ::= <<$name:bold(font=""Times"")$>>" + NL
+ @"bold(font) ::= ""<font face=$font$><b>$it$</b></font>""" + NL;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(DefaultTemplateLexer));
StringTemplate t = group.GetInstanceOf("page");
t.SetAttribute("name", "Ter");
string expecting = "<font face=Times><b>Ter</b></font>";
Assert.AreEqual(expecting, t.ToString());
}
示例6: testFindTemplateInCLASSPATH_Nope_JustRelativeToAssemblyLocation
public virtual void testFindTemplateInCLASSPATH_Nope_JustRelativeToAssemblyLocation()
{
// Look for templates in CLASSPATH as resources
StringTemplateGroup mgroup = new StringTemplateGroup("method stuff", typeof(AngleBracketTemplateLexer));
StringTemplate m = mgroup.GetInstanceOf("tests/method");
// "method.st" references body() so "body.st" will be loaded too
m.SetAttribute("visibility", "public");
m.SetAttribute("name", "foobar");
m.SetAttribute("returnType", "void");
m.SetAttribute("statements", "i=1;"); // body inherits these from method
m.SetAttribute("statements", "x=i;");
string expecting = "public void foobar() {" + NL
+ "\t// start of a body" + NL
+ "\ti=1;" + NL + "\tx=i;" + NL
+ "\t// end of a body" + NL
+ "}";
//.Replace(Environment.NewLine, "\n") below mitigates against failure due to line-ending differences
Assert.AreEqual(expecting, m.ToString().Replace(Environment.NewLine, "\n"));
}
示例7: testEmbeddedRegionRefWithNewlinesAngleBrackets
public void testEmbeddedRegionRefWithNewlinesAngleBrackets()
{
string templates = ""
+ "group test;" + NL
+ "a() ::= \"X<@r>" + NL
+ "blort" + NL
+ "<@end>" + NL
+ "Y\"" + NL;
StringTemplateGroup group =
new StringTemplateGroup(new StringReader(templates));
StringTemplate st = group.GetInstanceOf("a");
string result = st.ToString();
string expecting = "XblortY";
Assert.AreEqual(expecting, result);
}
示例8: testEmbeddedRegionRedefError
public void testEmbeddedRegionRedefError()
{
// cannot define an embedded template within group
string templates = ""
+ "group test;" + NL
+ "a() ::= \"X<@r>dork<@end>Y\""
+ "@a.r() ::= \"foo\"" + NL;
IStringTemplateErrorListener errors = new ErrorBuffer();
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), errors);
StringTemplate st = group.GetInstanceOf("a");
st.ToString();
string result = errors.ToString();
string expecting = "group test line 2: redefinition of template region: @a.r";
Assert.AreEqual(expecting, result);
}
示例9: testGroupTrailingSemiColon
public void testGroupTrailingSemiColon()
{
//try {
string templates =
"group test;" + NL +
"t1()::=\"R1\"; " + NL +
"t2() ::= \"R2\"" + NL
;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates));
StringTemplate st = group.GetInstanceOf("t1");
Assert.AreEqual("R1", st.ToString());
st = group.GetInstanceOf("t2");
Assert.AreEqual("R2", st.ToString());
Assert.Fail("A parse error should have been generated");
//} catch (ParseError??) {
//}
}
示例10: testLineWrapInNestedExpr
public void testLineWrapInNestedExpr()
{
string templates = ""
+ "group test;" + NL
+ "top(arrays) ::= <<Arrays: <arrays>done>>" + NL
+ "array(values) ::= <<int[] a = { <values; anchor, wrap=\"\\n\", separator=\",\"> };<\\n\\>>>" + NL
;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates));
StringTemplate top = group.GetInstanceOf("top");
StringTemplate a = group.GetInstanceOf("array");
a.SetAttribute("values",
new int[] {3,9,20,2,1,4,6,32,5,6,77,888,2,1,6,32,5,6,77,
4,9,20,2,1,4,63,9,20,2,1,4,6,32,5,6,77,6,32,5,6,77,
3,9,20,2,1,4,6,32,5,6,77,888,1,6,32,5});
top.SetAttribute("arrays", a);
top.SetAttribute("arrays", a); // add twice
string expecting = ""
+ "Arrays: int[] a = { 3,9,20,2,1,4,6,32,5,\n"
+ " 6,77,888,2,1,6,32,5,\n"
+ " 6,77,4,9,20,2,1,4,63,\n"
+ " 9,20,2,1,4,6,32,5,6,\n"
+ " 77,6,32,5,6,77,3,9,20,\n"
+ " 2,1,4,6,32,5,6,77,888,\n"
+ " 1,6,32,5 };\n"
+ "int[] a = { 3,9,20,2,1,4,6,32,5,6,77,888,\n"
+ " 2,1,6,32,5,6,77,4,9,20,2,1,4,\n"
+ " 63,9,20,2,1,4,6,32,5,6,77,6,\n"
+ " 32,5,6,77,3,9,20,2,1,4,6,32,\n"
+ " 5,6,77,888,1,6,32,5 };\n"
+ "done";
Assert.AreEqual(expecting, top.ToString(40));
}
示例11: testSingleValueWrap
public void testSingleValueWrap()
{
string templates = ""
+ "group test;" + NL
+ "m(args,body) ::= <<{ <body; anchor, wrap=\"\\n\"> }>>" + NL
;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates));
StringTemplate m = group.GetInstanceOf("m");
m.SetAttribute("body", "i=3;");
// make it wrap because of ") throws Ick { " literal
string expecting = ""
+ "{ \n"
+ " i=3; }";
Assert.AreEqual(expecting, m.ToString(2));
}
示例12: testLineDoesNotWrapDueToLiteral
public void testLineDoesNotWrapDueToLiteral()
{
string templates = ""
+ "group test;" + NL
+ "m(args,body) ::= <<public void foo(<args; wrap=\"\\n\",separator=\", \">) throws Ick { <body> }>>" + NL
;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates));
StringTemplate a = group.GetInstanceOf("m");
a.SetAttribute("args", new String[] { "a", "b", "c" });
a.SetAttribute("body", "i=3;");
// make it wrap because of ") throws Ick { " literal
int n = "public void foo(a, b, c".Length;
string expecting = "public void foo(a, b, c) throws Ick { i=3; }";
Assert.AreEqual(expecting, a.ToString(n));
}
示例13: testNestedWithIndentAndTrackStartOfExpr
public void testNestedWithIndentAndTrackStartOfExpr()
{
string templates = ""
+ "group test;" + NL
+ "top(d) ::= << <d>!>>" + NL
+ "duh(chars) ::= <<x: <chars; anchor, wrap=\"\\n\"\\>>>" + NL
;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates));
StringTemplate top = group.GetInstanceOf("top");
StringTemplate duh = group.GetInstanceOf("duh");
duh.SetAttribute("chars", new String[] { "a", "b", "c", "d", "e" });
top.SetAttribute("d", duh);
//
string expecting = ""
+ " x: ab\n"
+ " cd\n"
+ " e!";
Assert.AreEqual(expecting, top.ToString(7));
}
示例14: testNestedIndentedExpr
public void testNestedIndentedExpr()
{
string templates = ""
+ "group test;" + NL
+ "top(d) ::= << <d>!>>" + NL
+ "duh(chars) ::= << <chars; wrap=\"\\n\"\\>>>" + NL
;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates));
StringTemplate top = group.GetInstanceOf("top");
StringTemplate duh = group.GetInstanceOf("duh");
duh.SetAttribute("chars", new String[] { "a", "b", "c", "d", "e" });
top.SetAttribute("d", duh);
string expecting = ""
+ " ab\n"
+ " cd\n"
+ " e!";
// width=4 spaces + 2 char.
Assert.AreEqual(expecting, top.ToString(6));
}
示例15: testIndentBeyondLineWidth
public void testIndentBeyondLineWidth()
{
string templates = ""
+ "group test;" + NL
+ "duh(chars) ::= << <chars; wrap=\"\\n\"\\>>>" + NL
;
StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates));
StringTemplate a = group.GetInstanceOf("duh");
a.SetAttribute("chars", new String[] { "a", "b", "c", "d", "e" });
//
string expecting = ""
+ " a\n"
+ " b\n"
+ " c\n"
+ " d\n"
+ " e";
Assert.AreEqual(expecting, a.ToString(2));
}