示例#1
0
        public ParseTree Parse(TextFile sourceFile, out TimeSpan parserTimeSpan)
        {
            if (sourceFile.Data == null)
            {
                return(null);
            }

            try
            {
                var             stopwatch = Stopwatch.StartNew();
                var             parser    = new global::AspxParser.AspxParser(sourceFile.RelativePath);
                var             source    = new AspxSource(sourceFile.FullName, sourceFile.Data);
                AspxParseResult aspxTree  = parser.Parse(source);
                foreach (var error in aspxTree.ParseErrors)
                {
                    Logger.LogError(new ParsingException(sourceFile, message: error.Message)
                    {
                        TextSpan = error.Location.GetTextSpan()
                    });
                }
                var result = new AspxParseTree(aspxTree.RootNode);
                result.SourceFile = sourceFile;
                stopwatch.Stop();

                parserTimeSpan = stopwatch.Elapsed;

                return(result);
            }
            catch (Exception ex) when(!(ex is ThreadAbortException))
            {
                Logger.LogError(new ParsingException(sourceFile, ex));
                return(null);
            }
        }
示例#2
0
        public ParseTree Parse(SourceCodeFile sourceCodeFile)
        {
            ParseTree result = null;

            var filePath = Path.Combine(sourceCodeFile.RelativePath, sourceCodeFile.Name);

            if (sourceCodeFile.Code != null)
            {
                try
                {
                    var             parser   = new AspxParser.AspxParser(sourceCodeFile.RelativePath);
                    var             source   = new AspxSource(sourceCodeFile.FullPath, sourceCodeFile.Code);
                    AspxParseResult aspxTree = parser.Parse(source);
                    foreach (var error in aspxTree.ParseErrors)
                    {
                        Logger.LogError(new ParsingException(filePath, message: error.Message)
                        {
                            TextSpan = error.Location.GetTextSpan()
                        });
                    }
                    result = new AspxParseTree(aspxTree.RootNode);
                }
                catch (Exception ex)
                {
                    Logger.LogError(new ParsingException(filePath, ex));
                    result = new CSharpRoslynParseTree();
                }
            }
            else
            {
                result = new CSharpRoslynParseTree();
            }
            result.FileName = filePath;
            result.FileData = sourceCodeFile.Code;

            return(result);
        }