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


C# GrammarAST.SetUnknownTokenBoundaries方法代码示例

本文整理汇总了C#中Antlr3.Tool.GrammarAST.SetUnknownTokenBoundaries方法的典型用法代码示例。如果您正苦于以下问题:C# GrammarAST.SetUnknownTokenBoundaries方法的具体用法?C# GrammarAST.SetUnknownTokenBoundaries怎么用?C# GrammarAST.SetUnknownTokenBoundaries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Antlr3.Tool.GrammarAST的用法示例。


在下文中一共展示了GrammarAST.SetUnknownTokenBoundaries方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseAndBuildAST

        public virtual void ParseAndBuildAST( TextReader r )
        {
            // BUILD AST FROM GRAMMAR
            ANTLRLexer lexer = new ANTLRLexer( new Antlr.Runtime.ANTLRReaderStream( r ) );
            lexer.Filename = this.FileName;
            // use the rewrite engine because we want to buffer up all tokens
            // in case they have a merged lexer/parser, send lexer rules to
            // new grammar.
            //lexer.setTokenObjectClass( "antlr.TokenWithIndex" );
            tokenBuffer = new Antlr.Runtime.CommonTokenStream( lexer );
            //tokenBuffer = new TokenStreamRewriteEngine( lexer );
            //tokenBuffer.Discard( ANTLRParser.WS, ANTLRParser.ML_COMMENT, ANTLRParser.COMMENT, ANTLRParser.SL_COMMENT );
            //tokenBuffer.discard( ANTLRParser.WS );
            //tokenBuffer.discard( ANTLRParser.ML_COMMENT );
            //tokenBuffer.discard( ANTLRParser.COMMENT );
            //tokenBuffer.discard( ANTLRParser.SL_COMMENT );
            ANTLRParser parser = new ANTLRParser( tokenBuffer );
            parser.FileName = this.FileName;
            Antlr.Runtime.IAstRuleReturnScope<GrammarAST> result = null;
            try
            {
                result = parser.grammar_( this );
            }
            //catch ( TokenStreamException tse )
            //{
            //    ErrorManager.internalError( "unexpected stream error from parsing " + fileName, tse );
            //}
            catch ( RecognitionException re )
            {
                ErrorManager.InternalError( "unexpected parser recognition error from " + fileName, re );
            }

            DealWithTreeFilterMode(); // tree grammar and filter=true?

            if ( lexer.hasASTOperator && !BuildAST )
            {
                object value = GetOption( "output" );
                if ( value == null )
                {
                    ErrorManager.GrammarWarning( ErrorManager.MSG_REWRITE_OR_OP_WITH_NO_OUTPUT_OPTION,
                                                this, null );
                    SetOption( "output", "AST", null );
                }
                else
                {
                    ErrorManager.GrammarError( ErrorManager.MSG_AST_OP_WITH_NON_AST_OUTPUT_OPTION,
                                              this, null, value );
                }
            }

            grammarTree = result.Tree;
            if (grammarTree != null && AntlrTool.internalOption_PrintGrammarTree)
                Console.WriteLine("grammar tree: " + grammarTree.ToStringTree());

            grammarTree.SetUnknownTokenBoundaries();

            FileName = lexer.Filename; // the lexer #src might change name
            if ( grammarTree.FindFirstType( ANTLRParser.RULE ) == null )
            {
                ErrorManager.Error( ErrorManager.MSG_NO_RULES, FileName );
            }
        }
开发者ID:jamilgeor,项目名称:antlrcs,代码行数:62,代码来源:Grammar.cs


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