internal static CrawlSyntaxTree ParseTree(CrawlParser.Translation_unitContext context, string name)
        {
            TranslationUnitNode node = ParseTreeParser.ParseTranslationUnit(context);

            node.OwningTree.CompilationUnitName = name;

            return(node.OwningTree);
        }
 internal static void WriteParseTrees(TextWriter output, CrawlCompilerConfiguration configuration)
 {
     foreach (string inputfile in configuration.Files)
     {
         output.WriteLine("Parsing file {0}", inputfile);
         CrawlParser.Translation_unitContext tu = ParseFile(File.OpenRead(inputfile));
         //foreach (string line in Utils.MakeIndents(tu.ToStringTree(CrawlParser.ruleNames)).Split('\n'))
         //{
         //    output.WriteLine(line);
         //}
         output.WriteLine(Utils.MakeIndents(tu.ToStringTree(CrawlParser.ruleNames)));
     }
 }
        public static ParseTreeData ReadFileToPt(string path, SideeffectHelper helper)
        {
            ICharStream  charStream  = new AntlrFileStream(path, Encoding.UTF8);
            CrawlLexer   tokenSource = new CrawlLexer(charStream);
            ITokenStream tokenStream = new CommonTokenStream(tokenSource);

            CompilationMessageErrorListner cm = new CompilationMessageErrorListner(helper.CompilationMessages, path);

            CrawlParser parser = new CrawlParser(tokenStream);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(cm);

            CrawlParser.Translation_unitContext translationUnit = parser.translation_unit();

            return(new ParseTreeData(tokenStream, translationUnit, path));
        }
        public static CrawlSyntaxTree ReadFile(string filename)
        {
            ICharStream  charStream  = new AntlrFileStream(filename, Encoding.UTF8);
            CrawlLexer   tokenSource = new CrawlLexer(charStream);
            ITokenStream tokenStream = new CommonTokenStream(tokenSource);
            CrawlParser  parser      = new CrawlParser(tokenStream);


            //The translation_unit is the top rule in our grammar.
            //Asking the parser to match that from the token stream leaves us at the top of the parse tree.
            CrawlParser.Translation_unitContext rootContext = parser.translation_unit();


            TranslationUnitNode node = ParseTreeParser.ParseTranslationUnit(rootContext);

            node.OwningTree.CompilationUnitName = filename;

            return(node.OwningTree);
        }
        public static TranslationUnitNode ParseTranslationUnit(CrawlParser.Translation_unitContext translationUnit)
        {
            CrawlParser.Import_directivesContext imports =
                (CrawlParser.Import_directivesContext)translationUnit.GetChild(0);

            CrawlParser.Namespace_declarationContext nameSpace =
                (CrawlParser.Namespace_declarationContext)translationUnit.GetChild(1);

            CrawlParser.StatementsContext statements =
                (CrawlParser.StatementsContext)translationUnit.GetChild(2);


            IEnumerable <ImportNode> importNodes = ParseImports(imports);

            //Add the "No namespace" namespace
            importNodes = importNodes.Concat(CrawlSyntaxNode.Import(Interval.Invalid, "").AsSingleIEnumerable());
            NamespaceNode namespaceNode = ParseNamespace(nameSpace);   //Forts�t herfra.
            BlockNode     rootBlock     = ParseBlockNode(statements);


            return(CrawlSyntaxNode.TranslationUnit(translationUnit.SourceInterval, null, importNodes, namespaceNode, rootBlock));
        }
Exemple #6
0
 public ParseTreeData(ITokenStream tokenStream, CrawlParser.Translation_unitContext parseTree, string filename)
 {
     TokenStream = tokenStream;
     ParseTree   = parseTree;
     Filename    = filename;
 }