当前位置: 首页>>代码示例>>C#>>正文


C# AntlrUnitTests.ErrorQueue类代码示例

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


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

示例1: 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

示例2: TestCannotHaveSpaceAfterDot

        public void TestCannotHaveSpaceAfterDot()
        {
            string action = "%x. y = z;";
            //String expecting = null;

            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

            int expectedMsgID = ErrorManager.MSG_INVALID_TEMPLATE_ACTION;
            object expectedArg = "%x.";
            GrammarSemanticsMessage expectedMessage =
                new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg );
            checkError( equeue, expectedMessage );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:28,代码来源:TestTemplates.cs

示例3: 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

示例4: TestBadGrammarOption

        public void TestBadGrammarOption()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue ); // unique listener per thread
            AntlrTool antlr = newTool();
            Grammar g = new Grammar( antlr,
                                    "grammar t;\n" +
                                    "options {foo=3; language=Java;}\n" +
                                    "a : 'a';\n" );

            object expectedArg = "foo";
            int expectedMsgID = ErrorManager.MSG_ILLEGAL_OPTION;
            GrammarSemanticsMessage expectedMessage =
                new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg );
            checkGrammarSemanticsError( equeue, expectedMessage );
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:16,代码来源:TestSymbolDefinitions.cs

示例5: Test3LevelImport

        public void Test3LevelImport()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            string slave =
                "parser grammar T;\n" +
                "a : T ;\n";
            mkdir( tmpdir );
            writeFile( tmpdir, "T.g", slave );
            string slave2 =
                "parser grammar S;\n" + // A, B, C token type order
                "import T;\n" +
                "a : S ;\n";
            mkdir( tmpdir );
            writeFile( tmpdir, "S.g", slave2 );

            string master =
                "grammar M;\n" +
                "import S;\n" +
                "a : M ;\n";
            writeFile( tmpdir, "M.g", master );
            AntlrTool antlr = newTool( new string[] { "-lib", tmpdir } );
            CompositeGrammar composite = new CompositeGrammar();
            Grammar g = new Grammar( antlr, tmpdir + "/M.g", composite );
            composite.SetDelegationRoot( g );
            g.ParseAndBuildAST();
            g.composite.AssignTokenTypes();
            g.composite.DefineGrammarSymbols();

            string expectedTokenIDToTypeMap = "[M=6, S=5, T=4]";
            string expectedStringLiteralToTypeMap = "{}";
            string expectedTypeToTokenList = "[T, S, M]";

            assertEquals( expectedTokenIDToTypeMap,
                         realElements( g.composite.tokenIDToTypeMap ).ToElementString() );
            assertEquals( expectedStringLiteralToTypeMap, g.composite.stringLiteralToTypeMap.ToElementString() );
            assertEquals( expectedTypeToTokenList,
                         realElements( g.composite.typeToTokenList ).ToElementString() );

            assertEquals( "unexpected errors: " + equeue, 0, equeue.errors.Count );

            bool ok =
                rawGenerateAndBuildRecognizer( "M.g", master, "MParser", null, false );
            bool expecting = true; // should be ok
            assertEquals( expecting, ok );
        }
开发者ID:bszafko,项目名称:antlrcs,代码行数:46,代码来源:TestCompositeGrammars.cs

示例6: TestRewriteRuleAndRewriteModeIgnoreActionsPredicates

        public void TestRewriteRuleAndRewriteModeIgnoreActionsPredicates()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "tree grammar TP;\n" +
                "options {ASTLabelType=CommonTree; output=template; rewrite=true;}\n" +
                "a: {action} {action2} x=A -> {ick}\n" +
                " | {pred1}? y+=B -> {ick}\n" +
                " | C {action} -> {ick}\n" +
                " | {pred2}?=> z+=D -> {ick}\n" +
                " | (E)=> ^(F G) -> {ick}\n" +
                " ;\n"
            );
            AntlrTool antlr = newTool();
            antlr.SetOutputDirectory( null ); // write to /dev/null
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer();

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

示例7: TestNoWildcardAsRootError

        public void TestNoWildcardAsRootError()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );

            string treeGrammar =
                "tree grammar TP;\n" +
                "options {output=AST;}\n" +
                "a : ^(. INT) \n" +
                "  ;\n";

            Grammar g = new Grammar( treeGrammar );
            AntlrTool antlr = newTool();
            antlr.SetOutputDirectory( null ); // write to /dev/null
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer();

            assertEquals( "unexpected errors: " + equeue, 1, equeue.errors.Count );

            int expectedMsgID = ErrorManager.MSG_WILDCARD_AS_ROOT;
            object expectedArg = null;
            RecognitionException expectedExc = null;
            GrammarSyntaxMessage expectedMessage =
                new GrammarSyntaxMessage( expectedMsgID, g, null, expectedArg, expectedExc );

            checkError( equeue, expectedMessage );
        }
开发者ID:bszafko,项目名称:antlrcs,代码行数:28,代码来源:TestTreeGrammarRewriteAST.cs

示例8: TestCStyleReturnInitValue

        public void TestCStyleReturnInitValue()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "a : r ;\n" +
                "r returns [int (*x)()=NULL] : 'a' ;\n" );
            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);

            Rule r = g.GetRule( "r" );
            AttributeScope retScope = r.ReturnScope;
            var parameters = retScope.Attributes;
            Assert.IsNotNull(parameters, "missing return action");
            Assert.AreEqual( 1, parameters.Count );
            string found = parameters.ElementAt( 0 ).ToString();
            string expecting = "int (*)() x=NULL";
            Assert.AreEqual( expecting, found );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:19,代码来源:TestAttributes.cs

示例9: TestNonGreedyLoopThatNeverLoops

        public void TestNonGreedyLoopThatNeverLoops()
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "DUH : (options {greedy=false;}:'x')+ ;" ); // loop never matched
            string expecting =
                ":s0=>2" + NewLine;

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

            checkDecision( g, 1, expecting, new int[] { 1 } );

            Assert.AreEqual(1, equeue.size(), "unexpected number of expected problems");
            Message msg = (Message)equeue.errors[0];
            Assert.IsTrue(msg is GrammarUnreachableAltsMessage, "warning must be an unreachable alt");
            GrammarUnreachableAltsMessage u = (GrammarUnreachableAltsMessage)msg;
            Assert.AreEqual( "[1]", u.alts.ToElementString() );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:19,代码来源:TestCharDFAConversion.cs

示例10: TestCharListLabelInLexer

        public void TestCharListLabelInLexer()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "R : x+='z' ;\n" );

            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            Assert.AreEqual(0, equeue.errors.Count, "unexpected errors: " + equeue);
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:14,代码来源:TestAttributes.cs

示例11: checkError

 //throws Exception
 protected void checkError( ErrorQueue equeue,
                           GrammarSemanticsMessage expectedMessage )
 {
     /*
     System.out.println(equeue.infos);
     System.out.println(equeue.warnings);
     System.out.println(equeue.errors);
     */
     Message foundMsg = null;
     for ( int i = 0; i < equeue.errors.Count; i++ )
     {
         Message m = (Message)equeue.errors[i];
         if ( m.msgID == expectedMessage.msgID )
         {
             foundMsg = m;
         }
     }
     Assert.IsTrue(equeue.errors.Count > 0, "no error; " + expectedMessage.msgID + " expected");
     Assert.IsTrue(equeue.errors.Count <= 1, "too many errors; " + equeue.errors);
     Assert.IsTrue(foundMsg != null, "couldn't find expected error: " + expectedMessage.msgID);
     Assert.IsTrue(foundMsg is GrammarSemanticsMessage, "error is not a GrammarSemanticsMessage");
     Assert.AreEqual( expectedMessage.arg, foundMsg.arg );
     Assert.AreEqual( expectedMessage.arg2, foundMsg.arg2 );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:25,代码来源:TestTemplates.cs

示例12: TestSetAttrOfExprInMembers

        public void TestSetAttrOfExprInMembers()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "options {\n" +
                "    output=template;\n" +
                "}\n" +
                "@members {\n" +
                "%code.instr = o;" + // must not get null ptr!
                "}\n" +
                "a : ID\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

            assertNoErrors( equeue );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:23,代码来源:TestTemplates.cs

示例13: 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

示例14: TestForwardRefRuleLabels

        public void TestForwardRefRuleLabels()
        {
            string action = "$r.x; $r.start; $r.stop; $r.tree; $a.x; $a.tree;";
            string expecting = "(r!=null?r.x:0); (r!=null?((Token)r.start):null); (r!=null?((Token)r.stop):null); (r!=null?((Object)r.tree):null); (r!=null?r.x:0); (r!=null?((Object)r.tree):null);";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "parser grammar t;\n" +
                "b : r=a {###" + action + "!!!}\n" +
                "  ;\n" +
                "a returns [int x]\n" +
                "  : ;\n" );
            AntlrTool antlr = newTool();
            antlr.SetOutputDirectory( null ); // write to /dev/null
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // codegen phase sets some vars we need

            StringTemplate codeST = generator.RecognizerST;
            string code = codeST.Render();
            int startIndex = code.IndexOf("###") + 3;
            int endIndex = code.IndexOf("!!!");
            string found = code.Substring(startIndex, endIndex - startIndex);
            Assert.AreEqual( expecting, found );

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

示例15: TestDynamicScopeRefOkEvenThoughRuleRefExists

        public void TestDynamicScopeRefOkEvenThoughRuleRefExists()
        {
            string action = "$b::n;";
            string expecting = "((b_scope)b_stack.peek()).n;";

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "s : b ;\n" +
                "b\n" +
                "scope {\n" +
                "  int n;\n" +
                "} : '(' b ')' {" + action + "}\n" + // refers to current invocation's 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


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