• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Grammars.ActionTranslator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Antlr3.Grammars.ActionTranslator的典型用法代码示例。如果您正苦于以下问题:C# ActionTranslator类的具体用法?C# ActionTranslator怎么用?C# ActionTranslator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ActionTranslator类属于Antlr3.Grammars命名空间,在下文中一共展示了ActionTranslator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestMessageStringificationIsConsistent

        public void TestMessageStringificationIsConsistent()
        {
            string action = "$other.tree = null;";
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar a;\n" +
                "options { output = AST;}" +
                "otherrule\n" +
                "    : 'y' ;" +
                "rule\n" +
                "    : other=otherrule {" + action + "}\n" +
                "    ;" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator,
                                                                        "rule",
                                                                        new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string rawTranslation =
                translator.Translate();

            int expectedMsgID = ErrorManager.MSG_WRITE_TO_READONLY_ATTR;
            object expectedArg = "other";
            object expectedArg2 = "tree";
            GrammarSemanticsMessage expectedMessage =
                new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
            string expectedMessageString = expectedMessage.ToString();
            Assert.AreEqual( expectedMessageString, expectedMessage.ToString() );
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:31,代码来源:TestMessages.cs


示例2: TestReuseExistingListLabelWithImplicitTokenLabel

        public void TestReuseExistingListLabelWithImplicitTokenLabel()
        {
            string action = "$ID.text;";
            string expecting = "(x!=null?x.getText():null);";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "a : x+=ID {" + action + "} ;" +
                "ID : 'a';\n" );
            AntlrTool antlr = newTool();
            antlr.SetOutputDirectory( null ); // write to /dev/null
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer();

            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:24,代码来源:TestAttributes.cs


示例3: TestTemplateConstructorNoArgs

        public void TestTemplateConstructorNoArgs()
        {
            string action = "x = %foo();";
            string expecting = "x = templateLib.getInstanceOf(\"foo\");";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "options {\n" +
                "    output=template;\n" +
                "}\n" +
                "\n" +
                "a : ID {" + action + "}\n" +
                "  ;\n" +
                "\n" +
                "ID : 'a';\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator =
                new ActionTranslator( generator,
                                            "a",
                                            new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string rawTranslation =
                translator.Translate();
            StringTemplateGroup templates =
                new StringTemplateGroup();
            StringTemplate actionST = new StringTemplate( templates, rawTranslation );
            string found = actionST.Render();

            assertNoErrors( equeue );

            Assert.AreEqual( expecting, found );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:36,代码来源:TestTemplates.cs


示例4: TestFullyQualifiedRefToCurrentRuleParameter

        public void TestFullyQualifiedRefToCurrentRuleParameter()
        {
            string action = "$a.i;";
            string expecting = "i;";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "a[int i]: {" + action + "}\n" +
                "  ;\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:22,代码来源:TestAttributes.cs


示例5: TestEscapedLessThanInAction

 public void TestEscapedLessThanInAction()
 {
     Grammar g = new Grammar();
     AntlrTool antlr = newTool();
     CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
     string action = "i<3; '<xmltag>'";
     ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                  new CommonToken( ANTLRParser.ACTION, action ), 0 );
     string expecting = action;
     string rawTranslation =
         translator.Translate();
     StringTemplateGroup templates =
         new StringTemplateGroup();
     StringTemplate actionST = new StringTemplate( templates, "<action>" );
     actionST.SetAttribute( "action", rawTranslation );
     string found = actionST.Render();
     Assert.AreEqual( expecting, found );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:18,代码来源:TestAttributes.cs


示例6: TestDynamicRuleScopeRefInSubrule

        public void TestDynamicRuleScopeRefInSubrule()
        {
            string action = "$a::n;";
            string expecting = "((a_scope)a_stack.peek()).n;";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "a\n" +
                "scope {\n" +
                "  float n;\n" +
                "} : b ;\n" +
                "b : {" + action + "}\n" +
                "  ;\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "b",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:26,代码来源:TestAttributes.cs


示例7: Test0IndexedGlobalScope

        public void Test0IndexedGlobalScope()
        {
            string action = "$Symbols[0]::names.add($id.text);";
            string expecting =
                "((Symbols_scope)Symbols_stack.elementAt(0)).names.add((id!=null?id.getText():null));";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "scope Symbols {\n" +
                "  int n;\n" +
                "  List names;\n" +
                "}\n" +
                "a scope Symbols; : (id=ID ';' {" + action + "} )+\n" +
                "  ;\n" +
                "ID : 'a';\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:28,代码来源:TestAttributes.cs


示例8: TestComplicatedSingleArgParsing

        public void TestComplicatedSingleArgParsing()
        {
            string action = "(*a).foo(21,33,\",\")";
            string expecting = "(*a).foo(21,33,\",\")";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );

            // now check in actual grammar.
            Grammar g = new Grammar(
                "parser grammar t;\n" +
                "a[User u, int i]\n" +
                "        : A a[" + action + "] B\n" +
                "        ;" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string rawTranslation = translator.Translate();
            Assert.AreEqual( expecting, rawTranslation );

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:25,代码来源:TestAttributes.cs


示例9: TestStringArgParsing

        public void TestStringArgParsing()
        {
            string action = "34, '{', \"it's<\", '\"', \"\\\"\", 19";
            string expecting = "34, '{', \"it's<\", '\"', \"\\\"\", 19";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );

            // now check in actual grammar.
            Grammar g = new Grammar(
                "parser grammar t;\n" +
                "a[User u, int i]\n" +
                "        : A a[" + action + "] B\n" +
                "        ;" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string rawTranslation = translator.Translate();
            Assert.AreEqual( expecting, rawTranslation );

            //IList<String> expectArgs = new List<String>() {
            //    {add("34");}
            //    {add("'{'");}
            //    {add("\"it's<\"");}
            //    {add("'\"'");}
            //    {add("\"\\\"\"");} // that's "\""
            //    {add("19");}
            //};
            IList<string> expectArgs = new List<string>( new string[]
            {
                "34",
                "'{'",
                "\"it's<\"",
                "'\"'",
                "\"\\\"\"", // that's "\""
                "19"
            } );

            List<string> actualArgs = CodeGenerator.GetListOfArgumentsFromAction( action, ',' );
            //Assert.AreEqual( "args mismatch", expectArgs, actualArgs );
            Assert.IsTrue(expectArgs.SequenceEqual(actualArgs), "args mismatch");

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:47,代码来源:TestAttributes.cs


示例10: TestSimplePlusEqualLabel

        public void TestSimplePlusEqualLabel()
        {
            string action = "$ids.size();"; // must be qualified
            string expecting = "list_ids.size();";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "parser grammar t;\n" +
                "a : ids+=ID ( COMMA ids+=ID {" + action + "})* ;\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator =
                new ActionTranslator( generator,
                                          "a",
                                          new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:23,代码来源:TestAttributes.cs


示例11: TestSharedGlobalScope

        public void TestSharedGlobalScope()
        {
            string action = "$Symbols::x;";
            string expecting = "((Symbols_scope)Symbols_stack.peek()).x;";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "scope Symbols {\n" +
                "  String x;\n" +
                "}\n" +
                "a\n" +
                "scope { int y; }\n" +
                "scope Symbols;\n" +
                " : b {" + action + "}\n" +
                " ;\n" +
                "b : ID {$Symbols::x=$ID.text} ;\n" +
                "ID : 'a';\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:30,代码来源:TestAttributes.cs


示例12: TestSettingLexerRulePropertyRefs

        public void TestSettingLexerRulePropertyRefs()
        {
            string action = "$text $type=1 $line=1 $pos=1 $channel=1 $index";
            string expecting = "getText() _type=1 state.tokenStartLine=1 state.tokenStartCharPositionInLine=1 _channel=1 -1";
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "R : 'r' {" + action + "};\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator =
                new ActionTranslator( generator,
                                          "R",
                                          new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:22,代码来源:TestAttributes.cs


示例13: TestScopeAndAttributeWithUnderscore

        public void TestScopeAndAttributeWithUnderscore()
        {
            string action = "$foo_bar::a_b;";
            string expecting = "((foo_bar_scope)foo_bar_stack.peek()).a_b;";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "scope foo_bar {\n" +
                "  int a_b;\n" +
                "}\n" +
                "a scope foo_bar; : (ID {" + action + "} )+\n" +
                "  ;\n" +
                "ID : 'a';\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual( expecting, found );

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:26,代码来源:TestAttributes.cs


示例14: TestRuleScopeOutsideRule

        public void TestRuleScopeOutsideRule()
        {
            string action = "public void foo() {$a::name;}";
            string expecting = "public void foo() {((a_scope)a_stack.peek()).name;}";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "@members {" + action + "}\n" +
                "a\n" +
                "scope { String name; }\n" +
                "  : {foo();}\n" +
                "  ;\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator,
                                                                         null,
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 0 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:26,代码来源:TestAttributes.cs


示例15: TestRuleRefWithDynamicScope

        public void TestRuleRefWithDynamicScope()
        {
            string action = "$field::x = $field.st;";
            string expecting = "((field_scope)field_stack.peek()).x = retval.st;";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar a;\n" +
                "field\n" +
                "scope { StringTemplate x; }\n" +
                "    :   'y' {" + action + "}\n" +
                "    ;\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator,
                                                                         "field",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:25,代码来源:TestAttributes.cs


示例16: TestAssignToOwnRulenameAttr

        public void TestAssignToOwnRulenameAttr()
        {
            string action = "$rule.tree = null;";
            string expecting = "retval.tree = null;";
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar a;\n" +
                "rule\n" +
                "    : 'y' {" + action + "}\n" +
                "    ;" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator,
                                                                         "rule",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:23,代码来源:TestAttributes.cs


示例17: TestComplicatedArgParsingWithTranslation

        public void TestComplicatedArgParsingWithTranslation()
        {
            string action = "x, $A.text+\"3242\", (*$A).foo(21,33), 3.2+1, '\\n', " +
                            "\"a,oo\\nick\", {bl, \"fdkj\"eck}";
            string expecting = "x, (A1!=null?A1.getText():null)+\"3242\", (*A1).foo(21,33), 3.2+1, '\\n', \"a,oo\\nick\", {bl, \"fdkj\"eck}";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );

            // now check in actual grammar.
            Grammar g = new Grammar(
                "parser grammar t;\n" +
                "a[User u, int i]\n" +
                "        : A a[" + action + "] B\n" +
                "        ;" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:26,代码来源:TestAttributes.cs


示例18: TestTokenLabelFromMultipleAlts

        public void TestTokenLabelFromMultipleAlts()
        {
            string action = "$ID.text;"; // must be qualified
            string action2 = "$INT.text;"; // must be qualified
            string expecting = "(ID1!=null?ID1.getText():null);";
            string expecting2 = "(INT2!=null?INT2.getText():null);";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "a : ID {" + action + "}\n" +
                "  | INT {" + action2 + "}\n" +
                "  ;\n" +
                "ID : 'a';\n" +
                "INT : '0';\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
            translator = new ActionTranslator( generator,
                                                   "a",
                                                   new CommonToken( ANTLRParser.ACTION, action2 ), 2 );
            found = translator.Translate();
            Assert.AreEqual( expecting2, found );

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:34,代码来源:TestAttributes.cs


示例19: TestDoNotTranslateAttributeCompare

 public void TestDoNotTranslateAttributeCompare()
 {
     string action = "$a.line == $b.line";
     string expecting = "(a!=null?a.getLine():0) == (b!=null?b.getLine():0)";
     ErrorQueue equeue = new ErrorQueue();
     ErrorManager.SetErrorListener( equeue );
     Grammar g = new Grammar(
             "lexer grammar a;\n" +
             "RULE:\n" +
             "     a=ID b=ID {" + action + "}" +
             "    ;\n" +
             "ID : 'id';"
     );
     AntlrTool antlr = newTool();
     CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
     g.CodeGenerator = generator;
     generator.GenRecognizer();
     ActionTranslator translator = new ActionTranslator( generator,
                                                                  "RULE",
                                                                  new CommonToken( ANTLRParser.ACTION, action ), 1 );
     string found = translator.Translate();
     Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
     Assert.AreEqual( expecting, found );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:24,代码来源:TestAttributes.cs


示例20: TestTokenLabels

        public void TestTokenLabels()
        {
            string action = "$id; $f; $id.text; $id.getText(); $id.dork " +
                            "$id.type; $id.line; $id.pos; " +
                            "$id.channel; $id.index;";
            string expecting = "id; f; (id!=null?id.getText():null); id.getText(); id.dork (id!=null?id.getType():0); (id!=null?id.getLine():0); (id!=null?id.getCharPositionInLine():0); (id!=null?id.getChannel():0); (id!=null?id.getTokenIndex():0);";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "parser grammar t;\n" +
                "a : id=ID f=FLOAT {" + action + "}\n" +
                "  ;" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator, "a",
                                                                         new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string found = translator.Translate();
            Assert.AreEqual(expecting, found);

            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:24,代码来源:TestAttributes.cs



注:本文中的Antlr3.Grammars.ActionTranslator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ST.StringTemplateGroup类代码示例发布时间:2022-05-24
下一篇:
C# Tree.RewriteRuleTokenStream类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap