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


C# Grammar.ImportTokenVocabulary方法代码示例

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


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

示例1: Process


//.........这里部分代码省略.........

                    if (Report)
                    {
                        GrammarReport2 greport = new GrammarReport2(rootGrammar);
                        Console.WriteLine(greport.ToString());
                    }

                    if ( Profile )
                    {
                        GrammarReport report = new GrammarReport(rootGrammar);
                        Stats.WriteReport( GrammarReport.GRAMMAR_STATS_FILENAME,
                                          report.ToNotifyString() );
                    }

                    // now handle the lexer if one was created for a merged spec
                    string lexerGrammarStr = rootGrammar.GetLexerGrammar();
                    //[email protected]("lexer grammar:\n"+lexerGrammarStr);
                    if ( rootGrammar.type == GrammarType.Combined && lexerGrammarStr != null )
                    {
                        lexerGrammarFileName = rootGrammar.ImplicitlyGeneratedLexerFileName;
                        try
                        {
                            TextWriter w = GetOutputFile( rootGrammar, lexerGrammarFileName );
                            w.Write( lexerGrammarStr );
                            w.Close();
                        }
                        catch (IOException)
                        {
                            // emit different error message when creating the implicit lexer fails
                            // due to write permission error
                            exceptionWhenWritingLexerFile = true;
                            throw;
                        }
                        try
                        {
                            StringReader sr = new StringReader( lexerGrammarStr );
                            Grammar lexerGrammar = new Grammar(this);
                            lexerGrammar.composite.WatchNFAConversion = internalOption_watchNFAConversion;
                            lexerGrammar.implicitLexer = true;
                            if ( TestMode )
                                lexerGrammar.DefaultRuleModifier = "public";
                            FileInfo lexerGrammarFullFile = new FileInfo( System.IO.Path.Combine( GetFileDirectory( lexerGrammarFileName ), lexerGrammarFileName ) );
                            lexerGrammar.FileName = lexerGrammarFullFile.ToString();

                            lexerGrammar.ImportTokenVocabulary( rootGrammar );
                            lexerGrammar.ParseAndBuildAST( sr );

                            sr.Close();

                            lexerGrammar.composite.AssignTokenTypes();
                            lexerGrammar.AddRulesForSyntacticPredicates();
                            lexerGrammar.composite.DefineGrammarSymbols();
                            lexerGrammar.composite.CreateNFAs();

                            GenerateRecognizer( lexerGrammar );
                        }
                        finally
                        {
                            // make sure we clean up
                            if ( deleteTempLexer )
                            {
                                System.IO.DirectoryInfo outputDir = GetOutputDirectory( lexerGrammarFileName );
                                FileInfo outputFile = new FileInfo( System.IO.Path.Combine( outputDir.FullName, lexerGrammarFileName ) );
                                outputFile.Delete();
                            }
                        }
                    }
                }
                catch ( IOException e )
                {
                    if ( exceptionWhenWritingLexerFile )
                    {
                        ErrorManager.Error( ErrorManager.MSG_CANNOT_WRITE_FILE, e );
                    }
                    else
                    {
                        ErrorManager.Error( ErrorManager.MSG_CANNOT_OPEN_FILE,
                                           grammarFileName, e );
                    }
                }
                catch ( Exception e )
                {
                    ErrorManager.Error( ErrorManager.MSG_INTERNAL_ERROR, grammarFileName, e );
                }
            #if false
                finally
                {
                    Console.Out.WriteLine( "creates=" + Interval.creates );
                    Console.Out.WriteLine( "hits=" + Interval.hits );
                    Console.Out.WriteLine( "misses=" + Interval.misses );
                    Console.Out.WriteLine( "outOfRange=" + Interval.outOfRange );
                }
            #endif
            }

            if (_showTimer)
            {
                Console.WriteLine("Total parse time: {0}ms", timer.ElapsedMilliseconds);
            }
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:101,代码来源:AntlrTool.cs

示例2: TestArgsOnTokenInLexerRuleOfCombined

        public void TestArgsOnTokenInLexerRuleOfCombined()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "a : R;\n" +
                "R : 'z' ID[32] ;\n" +
                "ID : 'a';\n" );

            string lexerGrammarStr = g.GetLexerGrammar();
            System.IO.StringReader sr = new System.IO.StringReader( lexerGrammarStr );
            Grammar lexerGrammar = new Grammar();
            lexerGrammar.FileName = "<internally-generated-lexer>";
            lexerGrammar.ImportTokenVocabulary( g );
            lexerGrammar.ParseAndBuildAST( sr );
            lexerGrammar.DefineGrammarSymbols();
            lexerGrammar.CheckNameSpaceAndActions();
            sr.Close();

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

            int expectedMsgID = ErrorManager.MSG_RULE_HAS_NO_ARGS;
            object expectedArg = "ID";
            object expectedArg2 = null;
            GrammarSemanticsMessage expectedMessage =
                new GrammarSemanticsMessage( expectedMsgID, lexerGrammar, null, expectedArg, expectedArg2 );
            checkError( equeue, expectedMessage );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:33,代码来源:TestAttributes.cs


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