コード例 #1
0
ファイル: TestImports.cs プロジェクト: JSchofield/antlrcs
        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
0
        public static string Render(def.BiTemporal definition, string templateName)
        {
            var templateDI = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory;
            var templateFI = new FileInfo(Path.Combine(templateDI.FullName, templateDirectory, templateFilename));

            var stg      = new st.TemplateGroupFile(templateFI.FullName);
            var template = stg.GetInstanceOf(templateName);

            template.Add("def", definition);

            return(template.Render());
        }
コード例 #3
0
ファイル: TestScopes.cs プロジェクト: mahanteshck/antlrcs
        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;
        }
コード例 #4
0
        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();
        }
コード例 #5
0
ファイル: TestGroups.cs プロジェクト: mahanteshck/antlrcs
 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);
 }
コード例 #6
0
ファイル: TestVisualizer.cs プロジェクト: mahanteshck/antlrcs
        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();
        }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: TestGroups.cs プロジェクト: mahanteshck/antlrcs
 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);
 }
コード例 #9
0
ファイル: TestLineWrap.cs プロジェクト: mahanteshck/antlrcs
        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
0
ファイル: TestRegions.cs プロジェクト: JSchofield/antlrcs
        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);
        }
コード例 #11
0
ファイル: TestEarlyEvaluation.cs プロジェクト: antlr/antlrcs
        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
0
ファイル: TestRenderers.cs プロジェクト: antlr/antlrcs
 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
0
 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);
 }
コード例 #14
0
 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);
 }
コード例 #15
0
        public void TestAttribute()
        {
            string templates =
                "t(x) ::= << <x> >>" + Environment.NewLine;

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            Template st = group.GetInstanceOf("t");
            List<InterpEvent> events = st.GetEvents();
            string expected =
                "[IndentEvent{self=/t(x), expr=' <x>', source=[0..4), output=[0..1)}," +
                " EvalExprEvent{self=/t(x), expr='<x>', source=[1..4), output=[0..0)}," +
                " EvalExprEvent{self=/t(x), expr=' ', source=[4..5), output=[0..1)}," +
                " EvalTemplateEvent{self=/t(x), output=[0..1)}]";
            string result = events.ToListString();
            Assert.AreEqual(expected, result);
        }
コード例 #16
0
ファイル: TestRenderers.cs プロジェクト: antlr/antlrcs
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
ファイル: TestDictionaries.cs プロジェクト: antlr/antlrcs
        public void TestAccessDictionaryFromAnonymousTemplate()
        {
            string dir = tmpdir;
            string g =
                "a() ::= <<[<[\"foo\",\"a\"]:{x|<if(values.(x))><x><endif>}>]>>\n" +
                "values ::= [\n" +
                "    \"a\":false,\n" +
                "    default:true\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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
ファイル: TestLineWrap.cs プロジェクト: JSchofield/antlrcs
        public void TestIndentBeyondLineWidth()
        {
            string templates =
                    "duh(chars) ::= <<    <chars; wrap=\"\\n\"\\>>>" + newline;
            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));

            Template a = group.GetInstanceOf("duh");
            a.Add("chars", new string[] { "a", "b", "c", "d", "e" });
            //
            string expecting =
                "    a" + Environment.NewLine +
                "    b" + Environment.NewLine +
                "    c" + Environment.NewLine +
                "    d" + Environment.NewLine +
                "    e";
            Assert.AreEqual(expecting, a.Render(2));
        }
コード例 #21
0
ファイル: TestScopes.cs プロジェクト: mahanteshck/antlrcs
        public void TestArgWithSameNameAsEnclosing()
        {
            string templates =
                "t(x,y) ::= \"<u(x)>\"\n" +
                "u(y) ::= \"<x><y>\"";
            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("x", "x");
            st.Add("y", "y");
            string result = st.Render();

            string expectedError = "";
            Assert.AreEqual(expectedError, errors.ToString());

            string expected = "xx";
            Assert.AreEqual(expected, result);
            group.Listener = ErrorManager.DefaultErrorListener;
        }
コード例 #22
0
ファイル: TestEarlyEvaluation.cs プロジェクト: antlr/antlrcs
        public void TestEarlyEvalOfMapInIfExpr()
        {
            string templates =
                    "m ::= [\n" +
                    "	\"parrt\": \"value\",\n" +
                    "	default: \"other\"\n" +
                    "]\n" +
                    "main(x) ::= << p<x>t: <m.({p<x>t})>, <if(m.({p<x>t}))>if<else>else<endif> >>\n";
            writeFile(tmpdir, "t.stg", templates);

            TemplateGroup group = new TemplateGroupFile(tmpdir + "/t.stg");

            Template st = group.GetInstanceOf("main");

            st.Add("x", null);
            string s = st.Render();
            Assert.AreEqual(" pt: other, if ", s);

            st.Add("x", "arr");
            s = st.Render();
            Assert.AreEqual(" parrt: value, if ", s);
        }
コード例 #23
0
ファイル: TestImports.cs プロジェクト: antlr/antlrcs
        public void TestEmptyGroupImportGroupFileSameDir()
        {
            /*
            dir
                group1.stg		that imports group2.stg in same dir with just filename
                group2.stg		has c()
             */
            string dir = tmpdir;
            string groupFile =
                "import \"group2.stg\"\n";
            writeFile(dir, "group1.stg", groupFile);

            groupFile =
                "c() ::= \"g2 c\"\n";
            writeFile(dir, "group2.stg", groupFile);

            TemplateGroup group1 = new TemplateGroupFile(Path.Combine(dir, "group1.stg"));
            Template st = group1.GetInstanceOf("c"); // should see c()
            string expected = "g2 c";
            string result = st?.Render();
            Assert.AreEqual(expected, result);
        }
コード例 #24
0
ファイル: TestImports.cs プロジェクト: jamilgeor/antlrcs
        public void TestGroupFileInDirImportsAGroupDir()
        {
            /*
            dir
                g.stg has a() that imports subdir with relative path
                subdir
                    b.st
                    c.st
             */
            string dir = tmpdir;
            string gstr =
                "import \"subdir\"\n" + // finds subdir in dir
                "a() ::= \"a: <b()>\"\n";
            writeFile(dir, "g.stg", gstr);

            writeFile(dir, "subdir/b.st", "b() ::= \"b: <c()>\"\n");
            writeFile(dir, "subdir/c.st", "c() ::= <<subdir c>>\n");

            TemplateGroup group = new TemplateGroupFile(dir + "/g.stg");
            Template st = group.GetInstanceOf("a");
            string expected = "a: b: subdir c";
            string result = st.Render();
            Assert.AreEqual(expected, result);
        }
コード例 #25
0
ファイル: TestFunctions.cs プロジェクト: JSchofield/antlrcs
 public void TestReUseOfRestResult()
 {
     string templates =
         "a(names) ::= \"<b(rest(names))>\"" + newline +
         "b(x) ::= \"<x>, <x>\"" + newline
         ;
     writeFile(tmpdir, "t.stg", templates);
     TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
     Template e = group.GetInstanceOf("a");
     List<string> names = new List<string>();
     names.Add("Ter");
     names.Add("Tom");
     e.Add("names", names);
     string expecting = "Tom, Tom";
     Assert.AreEqual(expecting, e.Render());
 }
コード例 #26
0
ファイル: TestFunctions.cs プロジェクト: JSchofield/antlrcs
 public void TestReUseOfCat()
 {
     string templates =
         "a(mine,yours) ::= \"<b([mine,yours])>\"" + newline +
         "b(x) ::= \"<x>, <x>\"" + newline
         ;
     writeFile(tmpdir, "t.stg", templates);
     TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
     Template e = group.GetInstanceOf("a");
     List<string> mine = new List<string>();
     mine.Add("Ter");
     mine.Add("Tom");
     e.Add("mine", mine);
     List<string> yours = new List<string>();
     yours.Add("Foo");
     e.Add("yours", yours);
     string expecting = "TerTomFoo, TerTomFoo";
     Assert.AreEqual(expecting, e.Render());
 }
コード例 #27
0
ファイル: TestSyntaxErrors.cs プロジェクト: antlr/antlrcs
        public void TestIt()
        {
            string templates =
                "main() ::= <<" + newline +
                "<@r>a<@end>" + newline +
                "<@r()>" + newline +
                ">>";
            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            ErrorBuffer errors = new ErrorBuffer();
            group.Listener = errors;
            group.Load();
            Assert.AreEqual(0, errors.Errors.Count);

            Template template = group.GetInstanceOf("main");
            string expected =
                "a" + newline +
                "a";
            string result = template.Render();
            Assert.AreEqual(expected, result);
        }
コード例 #28
0
ファイル: TestLists.cs プロジェクト: mahanteshck/antlrcs
 public void TestListAsTemplateArgument()
 {
     string templates =
             "test(names,phones) ::= \"<foo([names,phones])>\"" + newline +
             "foo(items) ::= \"<items:{a | *<a>*}>\"" + newline
             ;
     writeFile(tmpdir, "t.stg", templates);
     TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
     Template e = group.GetInstanceOf("test");
     e.Add("names", "Ter");
     e.Add("names", "Tom");
     e.Add("phones", "1");
     e.Add("phones", "2");
     string expecting = "*Ter**Tom**1**2*";
     string result = e.Render();
     Assert.AreEqual(expecting, result);
 }
コード例 #29
0
ファイル: TestScopes.cs プロジェクト: mahanteshck/antlrcs
        public void TestMissingArg()
        {
            string templates =
                "t() ::= \"<u()>\"\n" +
                "u(z) ::= \"\"";
            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");
            string result = st.Render();

            string expectedError = "context [/t] 1:1 passed 0 arg(s) to template /u with 1 declared arg(s)" + newline;
            Assert.AreEqual(expectedError, errors.ToString());
        }
コード例 #30
0
ファイル: TestCoreBasics.cs プロジェクト: JSchofield/antlrcs
 public void TestMapWithExprAsTemplateName()
 {
     string templates =
         "d ::= [\"foo\":\"bold\"]\n" +
         "test(name) ::= \"<name:(d.foo)()>\"\n" +
         "bold(x) ::= <<*<x>*>>\n";
     writeFile(tmpdir, "t.stg", templates);
     TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
     Template st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     st.Add("name", "Tom");
     st.Add("name", "Sumana");
     string expected = "*Ter**Tom**Sumana*";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
コード例 #31
0
ファイル: TestScopes.cs プロジェクト: mahanteshck/antlrcs
        public void TestUnknownAttr()
        {
            string templates =
                "t() ::= \"<x>\"\n";
            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");
            string result = st.Render();

            string expectedError = "context [/t] 1:1 attribute x isn't defined" + newline;
            Assert.AreEqual(expectedError, errors.ToString());
        }