Antlr3.AntlrTool.GetRootGrammar C# (CSharp) Method

GetRootGrammar() public method

public GetRootGrammar ( string grammarFileName ) : Grammar
grammarFileName string
return Grammar
        public virtual Grammar GetRootGrammar( string grammarFileName )
        {
            //StringTemplate.setLintMode(true);
            // grammars mentioned on command line are either roots or single grammars.
            // create the necessary composite in case it's got delegates; even
            // single grammar needs it to get token types.
            CompositeGrammar composite = new CompositeGrammar();
            Grammar grammar = new Grammar( this, grammarFileName, composite );
            if ( TestMode )
                grammar.DefaultRuleModifier = "public";
            composite.SetDelegationRoot( grammar );

            string f = null;

            if ( haveInputDir )
            {
                f = Path.Combine( inputDirectory, grammarFileName );
            }
            else
            {
                f = grammarFileName;
            }

            // Store the location of this grammar as if we import files, we can then
            // search for imports in the same location as the original grammar as well as in
            // the lib directory.
            //
            parentGrammarDirectory = Path.GetDirectoryName( f );

            if ( grammarFileName.LastIndexOfAny( new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar } ) == -1 )
            {
                grammarOutputDirectory = ".";
            }
            else
            {
                grammarOutputDirectory = grammarFileName.Substring( 0, grammarFileName.LastIndexOfAny( new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar } ) );
            }

            StringReader reader = new StringReader( System.IO.File.ReadAllText( f ) );
            grammar.ParseAndBuildAST( reader );
            composite.WatchNFAConversion = internalOption_watchNFAConversion;
            return grammar;
        }