Antlr4.Tool.Grammar.ImportVocab C# (CSharp) Method

ImportVocab() public method

public ImportVocab ( Grammar importG ) : void
importG Grammar
return void
        public virtual void ImportVocab(Grammar importG)
        {
            foreach (string tokenName in importG.tokenNameToTypeMap.Keys)
            {
                DefineTokenName(tokenName, importG.tokenNameToTypeMap[tokenName]);
            }
            foreach (string tokenName in importG.stringLiteralToTypeMap.Keys)
            {
                DefineStringLiteral(tokenName, importG.stringLiteralToTypeMap[tokenName]);
            }
            foreach (KeyValuePair<string, int> channel in importG.channelNameToValueMap)
            {
                DefineChannelName(channel.Key, channel.Value);
            }
            //		this.tokenNameToTypeMap.putAll( importG.tokenNameToTypeMap );
            //		this.stringLiteralToTypeMap.putAll( importG.stringLiteralToTypeMap );
            int max = Math.Max(this.typeToTokenList.Count, importG.typeToTokenList.Count);
            Utils.SetSize(typeToTokenList, max);
            for (int ttype = 0; ttype < importG.typeToTokenList.Count; ttype++)
            {
                maxTokenType = Math.Max(maxTokenType, ttype);
                this.typeToTokenList[ttype] = importG.typeToTokenList[ttype];
            }

            max = Math.Max(this.channelValueToNameList.Count, importG.channelValueToNameList.Count);
            Utils.SetSize(channelValueToNameList, max);
            for (int channelValue = 0; channelValue < importG.channelValueToNameList.Count; channelValue++)
            {
                maxChannelType = Math.Max(maxChannelType, channelValue);
                this.channelValueToNameList[channelValue] = importG.channelValueToNameList[channelValue];
            }
        }

Usage Example

コード例 #1
0
ファイル: AntlrTool.cs プロジェクト: sharwell/antlr4cs
        /** To process a grammar, we load all of its imported grammars into
            subordinate grammar objects. Then we merge the imported rules
            into the root grammar. If a root grammar is a combined grammar,
            we have to extract the implicit lexer. Once all this is done, we
            process the lexer first, if present, and then the parser grammar
         */
        public virtual void Process(Grammar g, bool gencode)
        {
            g.LoadImportedGrammars();

            GrammarTransformPipeline transform = new GrammarTransformPipeline(g, this);
            transform.Process();

            LexerGrammar lexerg;
            GrammarRootAST lexerAST;
            if (g.ast != null && g.ast.grammarType == ANTLRParser.COMBINED &&
                 !g.ast.hasErrors)
            {
                lexerAST = transform.ExtractImplicitLexer(g); // alters g.ast
                if (lexerAST != null)
                {
                    if (grammarOptions != null)
                    {
                        lexerAST.cmdLineOptions = grammarOptions;
                    }

                    lexerg = new LexerGrammar(this, lexerAST);
                    lexerg.fileName = g.fileName;
                    lexerg.originalGrammar = g;
                    g.implicitLexer = lexerg;
                    lexerg.implicitLexerOwner = g;

                    int prevErrors = errMgr.GetNumErrors();
                    ProcessNonCombinedGrammar(lexerg, gencode);
                    if (errMgr.GetNumErrors() > prevErrors)
                    {
                        return;
                    }

                    //				System.out.println("lexer tokens="+lexerg.tokenNameToTypeMap);
                    //				System.out.println("lexer strings="+lexerg.stringLiteralToTypeMap);
                }
            }
            if (g.implicitLexer != null)
                g.ImportVocab(g.implicitLexer);
            //		System.out.println("tokens="+g.tokenNameToTypeMap);
            //		System.out.println("strings="+g.stringLiteralToTypeMap);
            ProcessNonCombinedGrammar(g, gencode);
        }