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


C# Codegen.CodeGenerator类代码示例

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


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

示例1: GetTargetCharLiteralFromANTLRCharLiteral

 public override string GetTargetCharLiteralFromANTLRCharLiteral(
         CodeGenerator generator,
         string literal )
 {
     int c = Grammar.GetCharValueFromGrammarCharLiteral( literal );
     return ( (char)c ).ToString();
 }
开发者ID:bszafko,项目名称:antlrcs,代码行数:7,代码来源:PythonTarget.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: GetTargetStringLiteralFromANTLRStringLiteral

 /** Convert from an ANTLR string literal found in a grammar file to
 *  an equivalent string literal in the target language.  For Java, this
 *  is the translation 'a\n"' -> "a\n\"".  Expect single quotes
 *  around the incoming literal.  Just flip the quotes and replace
 *  double quotes with \"
 */
 public override string GetTargetStringLiteralFromANTLRStringLiteral( CodeGenerator generator,
                                                            string literal )
 {
     literal = literal.Replace( "\"", "\\\"" );
     StringBuilder buf = new StringBuilder( literal );
     buf[0] = '"';
     buf[literal.Length - 1] = '"';
     buf.Insert( 0, '@' );
     return buf.ToString();
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:16,代码来源:ObjCTarget.cs

示例5: GetTokenTypeAsTargetLabel

 /** If we have a label, prefix it with the recognizer's name */
 public override string GetTokenTypeAsTargetLabel( CodeGenerator generator, int ttype )
 {
     string name = generator.grammar.GetTokenDisplayName( ttype );
     // If name is a literal, return the token type instead
     if ( name[0] == '\'' )
     {
         return ttype.ToString();
     }
     return generator.grammar.name + Grammar.grammarTypeToFileNameSuffix[(int)generator.grammar.type] + "_" + name;
     //return super.getTokenTypeAsTargetLabel(generator, ttype);
     //return this.getTokenTextAndTypeAsTargetLabel(generator, null, ttype);
 }
开发者ID:bszafko,项目名称:antlrcs,代码行数:13,代码来源:ObjCTarget.cs

示例6: PerformGrammarAnalysis

        protected override void PerformGrammarAnalysis(CodeGenerator generator, Grammar grammar)
        {
            base.PerformGrammarAnalysis(generator, grammar);

            foreach (Rule rule in grammar.Rules)
                rule.ThrowsSpec.Add("RecognitionException");

            IEnumerable<Rule> delegatedRules = grammar.GetDelegatedRules();
            if (delegatedRules != null)
            {
                foreach (Rule rule in delegatedRules)
                    rule.ThrowsSpec.Add("RecognitionException");
            }
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:14,代码来源:JavaTarget.cs

示例7: GetTargetCharLiteralFromANTLRCharLiteral

        public override string GetTargetCharLiteralFromANTLRCharLiteral( CodeGenerator generator,
                                                                string literal )
        {
            StringBuilder buf = new StringBuilder( 10 );

            int c = Grammar.GetCharValueFromGrammarCharLiteral( literal );
            if ( c < Label.MIN_CHAR_VALUE )
            {
                buf.Append( "\\x{0000}" );
            }
            else if ( c < targetCharValueEscape.Length &&
                    targetCharValueEscape[c] != null )
            {
                buf.Append( targetCharValueEscape[c] );
            }
            else if ( ( c < 0x7F ) && !char.IsControl( (char)c ) )
            {
                // normal char
                buf.Append( (char)c );
            }
            else
            {
                // must be something unprintable...use \\uXXXX
                // turn on the bit above max "\\uFFFF" value so that we pad with zeros
                // then only take last 4 digits
                string hex = c.ToString( "X4" );
                buf.Append( "\\x{" );
                buf.Append( hex );
                buf.Append( "}" );
            }

            if ( buf.ToString().IndexOf( '\\' ) == -1 )
            {
                // no need for interpolation, use single quotes
                buf.Insert( 0, '\'' );
                buf.Append( '\'' );
            }
            else
            {
                // need string interpolation
                buf.Insert( 0, '\"' );
                buf.Append( '\"' );
            }

            return buf.ToString();
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:46,代码来源:Perl5Target.cs

示例8: GetTargetCharLiteralFromANTLRCharLiteral

        public override string GetTargetCharLiteralFromANTLRCharLiteral( CodeGenerator generator,
                                                               string literal )
        {
            if ( literal.StartsWith( "'\\u" ) )
            {
                literal = "0x" + literal.Substring( 3, 4 );
            }
            else
            {
                int c = literal[1]; // TJP
                if ( c < 32 || c > 127 )
                {
                    literal = "0x" + c.ToString( "x" );
                }
            }

            return literal;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:18,代码来源:ObjCTarget.cs

示例9: GetTokenTypeAsTargetLabel

        /** Target must be able to override the labels used for token types */
        public override string GetTokenTypeAsTargetLabel( CodeGenerator generator,
                            int ttype )
        {
            // use ints for predefined types;
            // <invalid> <EOR> <DOWN> <UP>
            if ( ttype >= 0 && ttype <= 3 )
            {
                return ttype.ToString();
            }

            string name = generator.grammar.GetTokenDisplayName( ttype );

            // If name is a literal, return the token type instead
            if ( name[0] == '\'' )
            {
                return ttype.ToString();
            }

            return name;
        }
开发者ID:bszafko,项目名称:antlrcs,代码行数:21,代码来源:PythonTarget.cs

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

示例11: TestSetAttrOfExpr

        public void TestSetAttrOfExpr()
        {
            string action = "%{foo($ID.text).getST()}.y = z;";
            string expecting = "(foo((ID1!=null?ID1.getText():null)).getST()).setAttribute(\"y\", z);";

            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,代码行数:35,代码来源:TestTemplates.cs

示例12: TestRewriteRuleAndRewriteModeRefRule

        public void TestRewriteRuleAndRewriteModeRefRule()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "tree grammar TP;\n" +
                "options {ASTLabelType=CommonTree; output=template; rewrite=true;}\n" +
                "a  : b+ -> {ick}\n" +
                "   | b b A -> {ick}\n" +
                "   ;\n" +
                "b  : B ;\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,代码行数:20,代码来源:TestRewriteTemplates.cs

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

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


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