Expression ParseExpression(string expression)
        {
            Expression expr = SpecialConstructs(expression);

            if (expr == null)
            {
                using (NR.IParser p = NR.ParserFactory.CreateParser(language, new System.IO.StringReader(expression))) {
                    expr = p.ParseExpression();
                }
            }
            return(expr);
        }
 public CompilationUnit ParseCurrentMemberAsCompilationUnit(string fileContent)
 {
     System.IO.TextReader content = ExtractCurrentMethod(fileContent);
     if (content != null)
     {
         NR.IParser p = NR.ParserFactory.CreateParser(language, content);
         p.Parse();
         return(p.CompilationUnit);
     }
     else
     {
         return(null);
     }
 }
 NR.IParser ParseFile(string fileContent)
 {
     NR.IParser parser = NR.ParserFactory.CreateParser(language, new StringReader(fileContent));
     parser.Parse();
     if (parser.Errors.Count > 0)
     {
         ShowSourceCodeErrors(parser.Errors.ErrorOutput);
         parser.Dispose();
         return(null);
     }
     else
     {
         return(parser);
     }
 }
 protected virtual Dictionary <PossibleTypeReference, object> FindPossibleTypeReferences(string fileContent)
 {
     NR.IParser parser = ParseFile(fileContent);
     if (parser == null)
     {
         return(null);
     }
     else
     {
         FindPossibleTypeReferencesVisitor visitor = new FindPossibleTypeReferencesVisitor();
         parser.CompilationUnit.AcceptVisitor(visitor, null);
         parser.Dispose();
         return(visitor.list);
     }
 }
        public override string CreateNewFileLikeExisting(string existingFileContent, string codeForNewType)
        {
            NR.IParser parser = ParseFile(existingFileContent);
            if (parser == null)
            {
                return(null);
            }
            RemoveTypesVisitor visitor = new RemoveTypesVisitor();

            parser.CompilationUnit.AcceptVisitor(visitor, null);
            List <NR.ISpecial> comments = new List <NR.ISpecial>();

            foreach (NR.ISpecial c in parser.Lexer.SpecialTracker.CurrentSpecials)
            {
                if (c.StartPosition.Y <= visitor.includeCommentsUpToLine ||
                    c.StartPosition.Y > visitor.includeCommentsAfterLine)
                {
                    comments.Add(c);
                }
            }
            IOutputAstVisitor outputVisitor = (language == NR.SupportedLanguage.CSharp) ? new CSharpOutputVisitor() : (IOutputAstVisitor) new VBNetOutputVisitor();

            using (SpecialNodesInserter.Install(comments, outputVisitor)) {
                parser.CompilationUnit.AcceptVisitor(outputVisitor, null);
            }
            string expectedText;

            if (language == NR.SupportedLanguage.CSharp)
            {
                expectedText = "using " + RemoveTypesVisitor.DummyIdentifier + ";";
            }
            else
            {
                expectedText = "Imports " + RemoveTypesVisitor.DummyIdentifier;
            }
            using (StringWriter w = new StringWriter()) {
                using (StringReader r1 = new StringReader(outputVisitor.Text)) {
                    string line;
                    while ((line = r1.ReadLine()) != null)
                    {
                        string trimLine = line.TrimStart();
                        if (trimLine == expectedText)
                        {
                            string indentation = line.Substring(0, line.Length - trimLine.Length);
                            using (StringReader r2 = new StringReader(codeForNewType)) {
                                while ((line = r2.ReadLine()) != null)
                                {
                                    w.Write(indentation);
                                    w.WriteLine(line);
                                }
                            }
                        }
                        else
                        {
                            w.WriteLine(line);
                        }
                    }
                }
                if (visitor.firstType)
                {
                    w.WriteLine(codeForNewType);
                }
                return(w.ToString());
            }
        }