Exemplo n.º 1
0
        private void ParseStep()
        {
            string code = null;

            Invoke(new MethodInvoker(delegate
            {
                code = textEditorControl1.Text;
            }));
            TextReader        textReader = new StringReader(code);
            ICompilationUnit  newCompilationUnit;
            SupportedLanguage supportedLanguage;

            if (IsVisualBasic)
            {
                supportedLanguage = SupportedLanguage.VBNet;
            }
            else
            {
                supportedLanguage = SupportedLanguage.CSharp;
            }
            using (IParser p = ParserFactory.CreateParser(supportedLanguage, textReader))
            {
                // we only need to parse types and method definitions, no method bodies
                // so speed up the parser and make it more resistent to syntax
                // errors in methods
                p.ParseMethodBodies = false;
                p.Parse();
                newCompilationUnit = ConvertCompilationUnit(p.CompilationUnit);
            }
            // Remove information from lastCompilationUnit and add information from newCompilationUnit.
            myProjectContent.UpdateCompilationUnit(lastCompilationUnit, newCompilationUnit, DummyFileName);
            lastCompilationUnit = newCompilationUnit;
            parseInformation.SetCompilationUnit(newCompilationUnit);
        }
Exemplo n.º 2
0
        public void CreateParseInformation()
        {
            var parser = new CSharpBinding.Parser.TParser();
            var cu     = parser.Parse(pc, this.FileName, this.Document);

            ParserService.RegisterParseInformation(this.FileName, cu);
            pc.UpdateCompilationUnit(null, cu, this.FileName);
        }
Exemplo n.º 3
0
        public void CreateParseInformation()
        {
            ParserService.RegisterAvailableParsers(new ParserDescriptor(typeof(XamlParser), "XAML", new string[] { ".xaml" }));
            var parser = new XamlBinding.XamlParser();

            parser.LexerTags = new string[0];
            var cu = parser.Parse(pc, this.FileName, this.Document);

            ParserService.RegisterParseInformation(this.FileName, cu);
            pc.UpdateCompilationUnit(null, cu, this.FileName);
        }
        ICompilationUnit ParseCSharp(ICompilationUnit oldUnit, string fileContent)
        {
            ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser(ICSharpCode.NRefactory.SupportedLanguage.CSharp, new StringReader(fileContent));
            p.ParseMethodBodies = false;
            p.Parse();
            NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(pc, ICSharpCode.NRefactory.SupportedLanguage.CSharp);

            visitor.VisitCompilationUnit(p.CompilationUnit, null);
            Assert.AreEqual(0, p.Errors.Count, String.Format("Parse error preparing compilation unit: {0}", p.Errors.ErrorOutput));
            visitor.Cu.ErrorsDuringCompile = p.Errors.Count > 0;
            pc.UpdateCompilationUnit(oldUnit, visitor.Cu, null);

            return(visitor.Cu);
        }
Exemplo n.º 5
0
        public void mapSourceCode(string fileName)
        {
            "mapping file: {0}".format(fileName).debug();
            var parser = fileName.csharpAst();

            if (parsedCompilationUnits.ContainsKey(fileName))
            {
                parsedCompilationUnits[fileName] = parser.CompilationUnit;
            }
            else
            {
                parsedCompilationUnits.Add(fileName, parser.CompilationUnit);
            }
            var iCompilationUnit = setCurrentCompilationUnit(parser.CompilationUnit);

            myProjectContent.UpdateCompilationUnit(null, iCompilationUnit, fileName);
        }
Exemplo n.º 6
0
        public void parseSourceCode(string file, string code)
        {
            var text = textEditor.get_Text();

            //textEditor.set(")
            if (false == code.valid())
            {
                return;
            }

            if (false == mappedCompilationUnits.ContainsKey(file))
            {
                mappedCompilationUnits.Add(file, null);
            }

            var lastCompilationUnit = mappedCompilationUnits[file];

            var textReader = new StringReader(code);
            ICompilationUnit newCompilationUnit;
            var supportedLanguage = SupportedLanguage.CSharp;

            using (IParser p = ParserFactory.CreateParser(supportedLanguage, textReader))
            {
                // we only need to parse types and method definitions, no method bodies
                // so speed up the parser and make it more resistent to syntax
                // errors in methods
                p.ParseMethodBodies = false;
                p.Parse();
                newCompilationUnit = ConvertCompilationUnit(p.CompilationUnit);
            }
            // Remove information from lastCompilationUnit and add information from newCompilationUnit.
            myProjectContent.UpdateCompilationUnit(lastCompilationUnit, newCompilationUnit, DummyFileName);
            mappedCompilationUnits[file] = newCompilationUnit;
            //            lastCompilationUnit = newCompilationUnit;
            parseInformation.SetCompilationUnit(newCompilationUnit);

            try {
                //    if (file.exists())
                textEditor.Document.FoldingManager.UpdateFoldings(this.DummyFileName, parseInformation);
            } catch //(Exception ex)
            {
                //ex.log(ex);
            }
        }
        public void SetUpFixture()
        {
            string python =
                "import unittest\r\n" +
                "\r\n" +
                "class BaseTest(unittest.TestCase):\r\n" +
                "    def testSuccess(self):\r\n" +
                "        assert True\r\n" +
                "\r\n" +
                "class DerivedTest(BaseTest):\r\n" +
                "    pass\r\n" +
                "\r\n";

            projectContent = new DefaultProjectContent();
            PythonParser parser   = new PythonParser();
            string       fileName = @"C:\test.py";

            compilationUnit = parser.Parse(projectContent, fileName, python);
            projectContent.UpdateCompilationUnit(null, compilationUnit, fileName);
            if (compilationUnit.Classes.Count > 1)
            {
                c = compilationUnit.Classes[1];
            }
        }