本文整理汇总了C#中Antlr4.StringTemplate.TemplateGroupFile.Load方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateGroupFile.Load方法的具体用法?C# TemplateGroupFile.Load怎么用?C# TemplateGroupFile.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr4.StringTemplate.TemplateGroupFile
的用法示例。
在下文中一共展示了TemplateGroupFile.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: TestNamedArgsNotAllowInIndirectInclude
public void TestNamedArgsNotAllowInIndirectInclude()
{
string dir = tmpdir;
string groupFile =
"f(x,y) ::= \"<x><y>\"\n" +
"g(name) ::= \"<(name)(x={a},y={b})>\"";
//0123456789012345678901234567890
writeFile(dir, "group.stg", groupFile);
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(dir, "group.stg"));
ErrorBuffer errors = new ErrorBuffer();
group.Listener = errors;
group.Load();
// TODO: this could be more informative about the incorrect use of named arguments
string expected = "group.stg 2:22: '=' came as a complete surprise to me" + newline;
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
示例4: TestUnclosedTemplate
public void TestUnclosedTemplate()
{
string templates =
"foo() ::= {";
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:11: missing final '}' in {...} anonymous template" + newline +
"t.stg 1:10: no viable alternative at input '{'" + newline;
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
示例5: TestParen
public void TestParen()
{
string templates =
"foo( ::= << >>\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:5: no viable alternative at input '::='" + newline;
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
示例6: TestMissingImportString
public void TestMissingImportString()
{
string templates =
"import\n" +
"foo() ::= <<>>\n";
writeFile(tmpdir, "t.stg", templates);
ITemplateErrorListener errors = new ErrorBuffer();
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
group.Load(); // force load
string expected = "t.stg 2:0: mismatched input 'foo' expecting STRING" + newline +
"t.stg 2:3: missing EndOfFile at '('" + newline;
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
示例7: TestMap2
public void TestMap2()
{
string templates =
"d ::= [\"k\":]\n";
writeFile(tmpdir, "t.stg", templates);
TemplateGroupFile group;
ErrorBuffer errors = new ErrorBuffer();
group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
group.Load(); // force load
string expected = "[t.stg 1:11: missing value for key at ']']";
string result = errors.Errors.ToListString();
Assert.AreEqual(expected, result);
}
示例8: TestDefaultArgsOutOfOrder
public void TestDefaultArgsOutOfOrder()
{
string templates =
"foo(a={hi}, b) ::= << >>\n";
writeFile(tmpdir, "t.stg", templates);
TemplateGroupFile group;
ErrorBuffer errors = new ErrorBuffer();
group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
group.Load(); // force load
string expected =
"[t.stg 1:13: Optional parameters must appear after all required parameters]";
string result = errors.Errors.ToListString();
Assert.AreEqual(expected, result);
}
示例9: TestNestedDefaultValueTemplate
public void TestNestedDefaultValueTemplate()
{
string templates =
"t(a={x | <x:{y|<y>}>}) ::= \"ick\"" + Environment.NewLine;
writeFile(tmpdir, "t.stg", templates);
TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Load();
string expected =
"t(a={x | <x:{y|<y>}>}) ::= <<" + Environment.NewLine +
"ick" + Environment.NewLine +
">>" + Environment.NewLine;
string result = group.Show();
Assert.AreEqual(expected, result);
}
示例10: TestCantDefineEmbeddedRegionAgainInTemplate
public void TestCantDefineEmbeddedRegionAgainInTemplate()
{
string dir = tmpdir;
string g =
"a() ::= <<\n" +
"[\n" +
"<@r>foo<@end>\n" +
"<@r()>\n" +
"]\n" +
">>\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();
Assert.AreEqual(0, errors.Errors.Count);
Template template = group.GetInstanceOf("a");
string expected =
"[" + newline +
"foo" + newline +
"foo" + newline +
"]";
string result = template.Render();
Assert.AreEqual(expected, result);
}
示例11: TestMissingRegionName
public void TestMissingRegionName()
{
string dir = tmpdir;
string g = "@t.() ::= \"\"\n";
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 1:3: missing ID at '('" + newline;
string result = errors.ToString();
Assert.AreEqual(expected, result);
}
示例12: TestEmptyDictionary
public void TestEmptyDictionary()
{
string templates =
"d ::= []\n";
writeFile(tmpdir, "t.stg", templates);
TemplateGroupFile group = null;
ErrorBuffer errors = new ErrorBuffer();
group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
group.Load(); // force load
Assert.AreEqual(0, errors.Errors.Count);
}
示例13: TestDictEmptyDefaultValue
public void TestDictEmptyDefaultValue()
{
string templates =
"typeInit ::= [\"int\":\"0\", default:] " + newline +
"var(type,name) ::= \"<type> <name> = <typeInit.(type)>;\"" + newline
;
writeFile(tmpdir, "test.stg", templates);
ErrorBuffer errors = new ErrorBuffer();
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(tmpdir, "test.stg"));
group.Listener = errors;
group.Load();
string expected = "[test.stg 1:33: missing value for key at ']']";
string result = errors.Errors.ToListString();
Assert.AreEqual(expected, result);
}
示例14: TestUnloadingGroupFile
public void TestUnloadingGroupFile()
{
string dir = tmpdir;
string a =
"a(x) ::= <<foo>>\n" +
"b() ::= <<bar>>\n";
writeFile(dir, "a.stg", a);
TemplateGroup group = new TemplateGroupFile(dir + "/a.stg");
group.Load(); // force load
Template st = group.GetInstanceOf("a");
int originalHashCode = RuntimeHelpers.GetHashCode(st);
group.Unload(); // blast cache
st = group.GetInstanceOf("a");
int newHashCode = RuntimeHelpers.GetHashCode(st);
Assert.AreEqual(originalHashCode == newHashCode, false); // diff objects
string expected = "foo";
string result = st.Render();
Assert.AreEqual(expected, result);
st = group.GetInstanceOf("b");
expected = "bar";
result = st.Render();
Assert.AreEqual(expected, result);
}
示例15: TestValidButOutOfPlaceCharOnDifferentLine
public void TestValidButOutOfPlaceCharOnDifferentLine()
{
string templates =
"foo() ::= \"hi <\n" +
".> mom\"\n";
writeFile(tmpdir, "t.stg", templates);
ErrorBuffer errors = new ErrorBuffer();
TemplateGroupFile group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
group.Listener = errors;
group.Load(); // force load
string expected = "[t.stg 1:15: \\n in string, t.stg 1:14: doesn't look like an expression]";
string result = errors.Errors.ToListString();
Assert.AreEqual(expected, result);
}