本文整理汇总了C#中Antlr.StringTemplate.StringTemplateGroup类的典型用法代码示例。如果您正苦于以下问题:C# Antlr.StringTemplate.StringTemplateGroup类的具体用法?C# Antlr.StringTemplate.StringTemplateGroup怎么用?C# Antlr.StringTemplate.StringTemplateGroup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Antlr.StringTemplate.StringTemplateGroup类属于命名空间,在下文中一共展示了Antlr.StringTemplate.StringTemplateGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetUp
public void SetUp()
{
group = new StringTemplateGroup(new System.IO.StringReader(gString));
/*
// warm up the on-the-fly compiler
for (int i=1; i<=2*N; i++) {
testBaselineLiteral();
testSingleLocalAttributeReference();
testApplyTemplateToList();
}
*/
}
示例2: Main
public static void Main(string[] args)
{
StringTemplateGroup group = new StringTemplateGroup("dummy");
StringTemplate bold = group.DefineTemplate("bold", "<b>$attr$</b>");
StringTemplate banner = group.DefineTemplate("banner", "the banner");
StringTemplate st = new StringTemplate(group,
"<html>\n" +
"$banner(a=b)$" +
"<p><b>$name$:$email$</b>" +
"$if(member)$<i>$fontTag$member</font></i>$endif$");
st.SetAttribute("name", "Terence");
st.SetAttribute("name", "Tom");
st.SetAttribute("email", "[email protected]");
st.SetAttribute("templateAttr", bold);
StringTemplateTreeView frame =
new StringTemplateTreeView("StringTemplateTreeView Example", st);
Application.Run(frame);
}
示例3: 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);
}
示例4: Initialize
public void Initialize()
{
config = STViewEngineConfiguration.GetConfig(ConfigConstants.ELEMENT_stview_sectionname);
StringTemplateGroup componentGroup = new ViewComponentStringTemplateGroup(
ConfigConstants.STGROUP_NAME_PREFIX + "_components",
config.TemplateLexerType);
StringTemplateGroup helpersSTGroup = new BasicStringTemplateGroup(
ConfigConstants.STGROUP_NAME_PREFIX + "_helpersST",
new EmbeddedResourceTemplateLoader(this.GetType().Assembly, ConfigConstants.HELPER_RESOURCE_NAMESPACE, false),
config.TemplateLexerType);
helpersSTGroup.SuperGroup = componentGroup;
templateGroup = new BasicStringTemplateGroup(
ConfigConstants.STGROUP_NAME_PREFIX,
new FileSystemTemplateLoader(ViewSourceLoader.ViewRootDir, false),
config.TemplateLexerType);
templateGroup.SuperGroup = helpersSTGroup;
if (config.TemplateWriterTypeName != null)
{
componentGroup.SetTemplateWriterType(config.TemplateWriterType);
helpersSTGroup.SetTemplateWriterType(config.TemplateWriterType);
templateGroup.SetTemplateWriterType(config.TemplateWriterType);
}
IEnumerator globalRenderersEnumerator = config.GetGlobalAttributeRenderers();
while (globalRenderersEnumerator.MoveNext())
{
RendererInfo renderInfo = (RendererInfo)globalRenderersEnumerator.Current;
componentGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
helpersSTGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
templateGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
}
}
示例5: testEmbeddedMultiLineIF
public virtual void testEmbeddedMultiLineIF()
{
StringTemplateGroup group = new StringTemplateGroup("test");
StringTemplate main = new StringTemplate(group, "$sub$");
StringTemplate sub = new StringTemplate(
group, ""
+ "begin" + NL
+ "$if(foo)$" + NL
+ "$foo$" + NL
+ "$else$" + NL
+ "blort" + NL
+ "$endif$" + NL
);
sub.SetAttribute("foo", "stuff");
main.SetAttribute("sub", sub);
string expecting = "begin" + NL
+ "stuff";
Assert.AreEqual(expecting, main.ToString());
main = new StringTemplate(group, "$sub$");
sub = sub.GetInstanceOf();
main.SetAttribute("sub", sub);
expecting = "begin" + NL
+ "blort";
Assert.AreEqual(expecting, main.ToString());
}
示例6: 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);
}
示例7: testIFTemplate
public virtual void testIFTemplate()
{
StringTemplateGroup group = new StringTemplateGroup("dummy", ".", typeof(AngleBracketTemplateLexer));
StringTemplate t = new StringTemplate(group, "SELECT <column> FROM PERSON " + "<if(cond)>WHERE ID=<id><endif>;");
t.SetAttribute("column", "name");
t.SetAttribute("cond", "true");
t.SetAttribute("id", "231");
Assert.AreEqual(t.ToString(), "SELECT name FROM PERSON WHERE ID=231;");
}
示例8: testIFCondWithParensDollarDelimsTemplate
public virtual void testIFCondWithParensDollarDelimsTemplate()
{
StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
StringTemplate t = new StringTemplate(group, "$if(map.(type))$$type$ $prop$=$map.(type)$;$endif$");
Hashtable map = new Hashtable();
map["int"] = "0";
t.SetAttribute("map", map);
t.SetAttribute("prop", "x");
t.SetAttribute("type", "int");
Assert.AreEqual("int x=0;", t.ToString());
}
示例9: testGroupSatisfiesSingleInterface
public virtual void testGroupSatisfiesSingleInterface()
{
// this also tests the group loader
IStringTemplateErrorListener errors = new ErrorBuffer();
StringTemplateGroup.RegisterGroupLoader(new CommonGroupLoader(errors, TEMPDIR));
string groupIStr = ""
+ "interface testI;" + NL
+ "t();" + NL
+ "bold(item);" + NL
+ "optional duh(a,b,c);" + NL;
WriteFile(TEMPDIR, "testI.sti", groupIStr);
string templates = ""
+ "group testG implements testI;" + NL
+ "t() ::= <<foo>>" + NL
+ "bold(item) ::= <<foo>>" + NL
+ "duh(a,b,c) ::= <<foo>>" + NL;
WriteFile(TEMPDIR, "testG.stg", templates);
file1 = new StreamReader(Path.Combine(TEMPDIR, "testG.stg"));
StringTemplateGroup group = new StringTemplateGroup(file1, errors);
string expecting = ""; // should be no errors
Assert.AreEqual(expecting, errors.ToString());
}
示例10: testGroupExtendsSuperGroup
public virtual void testGroupExtendsSuperGroup()
{
// this also tests the group loader
IStringTemplateErrorListener errors = new ErrorBuffer();
StringTemplateGroup.RegisterGroupLoader(
new CommonGroupLoader(errors, TEMPDIR)
);
string superGroup = ""
+ "group superG;" + NL
+ "bold(item) ::= <<*<item>*>>;\n" + NL;
WriteFile(TEMPDIR, "superG.stg", superGroup);
string templates = ""
+ "group testG : superG;" + NL
+ "main(x) ::= <<$bold(x)$>>" + NL;
WriteFile(TEMPDIR, "testG.stg", templates);
file1 = new StreamReader(Path.Combine(TEMPDIR, "testG.stg"));
StringTemplateGroup group = new StringTemplateGroup(file1, typeof(DefaultTemplateLexer), errors);
StringTemplate st = group.GetInstanceOf("main");
st.SetAttribute("x", "foo");
string expecting = "*foo*";
Assert.AreEqual(expecting, st.ToString());
}
示例11: testComplicatedSeparatorExpr
public virtual void testComplicatedSeparatorExpr()
{
StringTemplateGroup group = new StringTemplateGroup("test");
StringTemplate bold = group.DefineTemplate("bulletSeparator", "</li>$foo$<li>");
// make separator a complicated expression with args passed to included template
StringTemplate t = new StringTemplate(
group, @"<ul>$name; separator=bulletSeparator(foo="" "")+"" ""$</ul>"
);
t.SetAttribute("name", "Ter");
t.SetAttribute("name", "Tom");
t.SetAttribute("name", "Mel");
//System.out.println(t);
string expecting = "<ul>Ter</li> <li> Tom</li> <li> Mel</ul>";
Assert.AreEqual(expecting, t.ToString());
}
示例12: testComplicatedInheritance
public void testComplicatedInheritance()
{
// in super: decls invokes labels
// in sub: overridden decls which calls super.decls
// overridden labels
// Bug: didn't see the overridden labels. In other words,
// the overridden decls called super which called labels, but
// didn't get the subgroup overridden labels--it calls the
// one in the superclass. Ouput was "DL" not "DSL"; didn't
// invoke sub's labels().
string basetemplates = ""
+ "group base;" + NL
+ "decls() ::= \"D<labels()>\"" + NL
+ "labels() ::= \"L\"" + NL
;
StringTemplateGroup @base = new StringTemplateGroup(
new StringReader(basetemplates),
typeof(AngleBracketTemplateLexer));
string subtemplates = ""
+ "group sub;" + NL
+ "decls() ::= \"<super.decls()>\"" + NL
+ "labels() ::= \"SL\"" + NL
;
StringTemplateGroup sub = new StringTemplateGroup(
new StringReader(subtemplates),
typeof(AngleBracketTemplateLexer));
sub.SuperGroup = @base;
StringTemplate st = sub.GetInstanceOf("decls");
string expecting = "DSL";
string result = st.ToString();
Assert.AreEqual(expecting, result);
}
示例13: TestFirstThenRestTwiceOnIEnumeratorResultsInNoOutputFor2ndRef
public virtual void TestFirstThenRestTwiceOnIEnumeratorResultsInNoOutputFor2ndRef()
{
string templates = ""
+ "group TestIEnum ;" + NL
+ "FirstThenRest(Arg) ::=<<" + NL
+ "Iteration 1: " + NL
+ "FIRST: $first(Arg):{X=$it$ # }$" + NL
+ "REST : $rest(Arg):{X=$it$ # }$" + NL
+ "-------------" + NL
+ "Iteration 2: " + NL
+ "FIRST: $first(Arg):{X=$it$ # }$" + NL
+ "REST : $rest(Arg):{X=$it$ # }$" + NL
+ "-------------" + NL
+ ">>"
;
StringTemplateGroup group = new StringTemplateGroup(
new StringReader(templates),
typeof(DefaultTemplateLexer));
StringTemplate actionST = group.GetInstanceOf("FirstThenRest");
int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
actionST.SetAttribute("Arg", myIntArray.GetEnumerator());
string expected = ""
+ "Iteration 1: " + NL
+ "FIRST: X=1 # " + NL
+ "REST : X=2 # X=3 # X=4 # X=5 # " + NL
+ "-------------" + NL
+ "Iteration 2: " + NL
+ "FIRST: X=1 # " + NL
+ "REST : X=2 # X=3 # X=4 # X=5 # " + NL
+ "-------------" + NL
;
string actual = actionST.ToString();
Assert.AreEqual(expected, actual,
"IEnumerators have side-effects. Can't just Reset() and reuse because it may be \"deliberately positioned\".");
}
示例14: TestMultipleRefsToIEnumeratorGivesEmptyOutput
public virtual void TestMultipleRefsToIEnumeratorGivesEmptyOutput()
{
string templates = ""
+ "group TestIEnum ;" + NL
+ "Action(Arg) ::=<<" + NL
+ "Ref 1: " + NL
+ " $Arg:{X=$it$ # }$" + NL
+ "Ref 2: " + NL
+ " $Arg:{X=$it$ # }$" + NL
+ ">>"
;
StringTemplateGroup group = new StringTemplateGroup(
new StringReader(templates),
typeof(DefaultTemplateLexer));
StringTemplate actionST = group.GetInstanceOf("Action");
int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
actionST.SetAttribute("Arg", myIntArray.GetEnumerator());
string expected = ""
+ "Ref 1: " + NL
+ " X=1 # X=2 # X=3 # X=4 # X=5 # " + NL
+ "Ref 2: " + NL
+ " X=1 # X=2 # X=3 # X=4 # X=5 # " + NL
;
string actual = actionST.ToString();
Assert.AreEqual(expected, actual,
"IEnumerators have side-effects. Can't just Reset() and reuse because it may be \"deliberately positioned\".");
}
示例15: TestIfTestingDoesNotAdvanceIEnumeratorPosition2
public virtual void TestIfTestingDoesNotAdvanceIEnumeratorPosition2()
{
string templates = ""
+ "group TestIEnum ;" + NL
+ "ActionWithIfTest(Arg) ::=<<" + NL
+ "$if( Arg )$" + NL
+ "$Arg:{X=$it$ # }$" + NL
+ "$endif$" + NL
+ ">>" + NL
+ "ActionWithoutIfTest(Arg) ::=<<" + NL
+ "$Arg:{X=$it$ # }$" + NL
+ ">>"
;
StringTemplateGroup group = new StringTemplateGroup(
new StringReader(templates),
typeof(DefaultTemplateLexer));
StringTemplate actionWithIfTestST = group.GetInstanceOf("ActionWithIfTest");
StringTemplate actionWithoutIfTestST = group.GetInstanceOf("ActionWithoutIfTest");
int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
actionWithIfTestST.SetAttribute("Arg", myIntArray.GetEnumerator());
actionWithoutIfTestST.SetAttribute("Arg", myIntArray.GetEnumerator());
string resultWithIfTestST = actionWithIfTestST.ToString();
string resultWithoutIfTestST = actionWithoutIfTestST.ToString();
Assert.AreEqual(resultWithIfTestST, resultWithoutIfTestST);
}