本文整理汇总了C#中Antlr4.StringTemplate.TemplateGroupFile.ImportTemplates方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateGroupFile.ImportTemplates方法的具体用法?C# TemplateGroupFile.ImportTemplates怎么用?C# TemplateGroupFile.ImportTemplates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr4.StringTemplate.TemplateGroupFile
的用法示例。
在下文中一共展示了TemplateGroupFile.ImportTemplates方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: TestImportTemplateInGroupFileFromGroupFile
public void TestImportTemplateInGroupFileFromGroupFile()
{
string dir = tmpdir;
string groupFile =
"a() ::= \"g1 a\"\n" +
"b() ::= \"<c()>\"\n";
writeFile(dir, Path.Combine("x", "group.stg"), groupFile);
groupFile =
"b() ::= \"g2 b\"\n" +
"c() ::= \"g2 c\"\n";
writeFile(dir, Path.Combine("y", "group.stg"), groupFile);
TemplateGroup group1 = new TemplateGroupFile(Path.Combine(dir, "x", "group.stg"));
TemplateGroup group2 = new TemplateGroupFile(Path.Combine(dir, "y", "group.stg"));
group1.ImportTemplates(group2);
Template st = group1.GetInstanceOf("b");
string expected = "g2 c";
string result = st.Render();
Assert.AreEqual(expected, result);
}
示例3: TestMissingSuperTemplate
public void TestMissingSuperTemplate()
{
ErrorBuffer errors = new ErrorBuffer();
string templates =
"t() ::= \"<super.t()>\"" + Environment.NewLine;
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
string templates2 =
"u() ::= \"blech\"" + Environment.NewLine;
writeFile(tmpdir, "t2.stg", templates2);
TemplateGroup group2 = new TemplateGroupFile(Path.Combine(tmpdir, "t2.stg"));
group.ImportTemplates(group2);
Template st = group.GetInstanceOf("t");
st.Render();
string expected = "context [/t] 1:1 no such template: super.t" + newline;
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
示例4: TestSuperRegionRefMissingOk
public void TestSuperRegionRefMissingOk()
{
string dir = tmpdir;
string g =
"a() ::= \"X<@r()>Y\"" +
"@a.r() ::= \"foo\"" + newline;
writeFile(dir, "g.stg", g);
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg"));
string sub =
"@a.r() ::= \"A<@super.q()>B\"" + newline; // allow this; trap at runtime
ITemplateErrorListener errors = new ErrorBuffer();
group.Listener = errors;
writeFile(dir, "sub.stg", sub);
TemplateGroupFile subGroup = new TemplateGroupFile(dir + "/sub.stg");
subGroup.ImportTemplates(group);
Template st = subGroup.GetInstanceOf("a");
string result = st.Render();
string expecting = "XABY";
Assert.AreEqual(expecting, result);
}
示例5: TestRegionOverrideStripsNewlines
public void TestRegionOverrideStripsNewlines()
{
string dir = tmpdir;
string g =
"a() ::= \"X<@r()>Y\"" +
"@a.r() ::= <<\n" +
"foo\n" +
">>\n";
writeFile(dir, "g.stg", g);
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg"));
string sub = "@a.r() ::= \"A<@super.r()>B\"" + newline;
writeFile(dir, "sub.stg", sub);
TemplateGroupFile subGroup = new TemplateGroupFile(Path.Combine(dir, "sub.stg"));
subGroup.ImportTemplates(group);
Template st = subGroup.GetInstanceOf("a");
string result = st.Render();
string expecting = "XAfooBY";
Assert.AreEqual(expecting, result);
}
示例6: TestRegionOverrideRefSuperRegion3Levels
public void TestRegionOverrideRefSuperRegion3Levels()
{
string dir = tmpdir;
string g =
"a() ::= \"X<@r()>Y\"" +
"@a.r() ::= \"foo\"" + newline;
writeFile(dir, "g.stg", g);
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg"));
string sub =
"@a.r() ::= \"<@super.r()>2\"" + newline;
writeFile(dir, "sub.stg", sub);
TemplateGroupFile subGroup = new TemplateGroupFile(dir + "/sub.stg");
subGroup.ImportTemplates(group);
string subsub =
"@a.r() ::= \"<@super.r()>3\"" + newline;
writeFile(dir, "subsub.stg", subsub);
TemplateGroupFile subSubGroup = new TemplateGroupFile(dir + "/subsub.stg");
subSubGroup.ImportTemplates(subGroup);
Template st = subSubGroup.GetInstanceOf("a");
string result = st.Render();
string expecting = "Xfoo23Y";
Assert.AreEqual(expecting, result);
}
示例7: TestRegionOverrideRefSuperImplicitRegion
public void TestRegionOverrideRefSuperImplicitRegion()
{
string dir = tmpdir;
string g =
"a() ::= \"X<@r>foo<@end>Y\"" + newline;
writeFile(dir, "g.stg", g);
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "g.stg"));
string sub =
"@a.r() ::= \"A<@super.r()>\"" + newline;
writeFile(dir, "sub.stg", sub);
TemplateGroupFile subGroup = new TemplateGroupFile(dir + "/sub.stg");
subGroup.ImportTemplates(group);
Template st = subGroup.GetInstanceOf("a");
string result = st.Render();
string expecting = "XAfooY";
Assert.AreEqual(expecting, result);
}
示例8: TestDefineRegionInSubgroup2
public void TestDefineRegionInSubgroup2()
{
string dir = tmpdir;
string g1 = "a() ::= <<[<@r()>]>>\n";
writeFile(dir, "g1.stg", g1);
string g2 = "@a.r() ::= <<foo>>>\n";
writeFile(dir, "g2.stg", g2);
TemplateGroup group1 = new TemplateGroupFile(Path.Combine(dir, "g1.stg"));
TemplateGroup group2 = new TemplateGroupFile(Path.Combine(dir, "g2.stg"));
group1.ImportTemplates(group2); // opposite of previous; g1 imports g2
Template st = group1.GetInstanceOf("a");
string expected = "[]"; // @a.r implicitly defined in g1; can't see g2's
string result = st.Render();
Assert.AreEqual(expected, result);
}