public void Start(CancellationToken cancellationToken) { try { Logger.Trace($"Starting ParseTaskID {_taskId} on thread {Thread.CurrentThread.ManagedThreadId}."); var tokenStream = RewriteAndPreprocess(cancellationToken); cancellationToken.ThrowIfCancellationRequested(); // temporal coupling... comments must be acquired before we walk the parse tree for declarations // otherwise none of the annotations get associated to their respective Declaration var commentListener = new CommentListener(); var annotationListener = new AnnotationListener(new VBAParserAnnotationFactory(), _module); var stopwatch = Stopwatch.StartNew(); var codePaneParseResults = ParseInternal(_module.ComponentName, tokenStream, new IParseTreeListener[] { commentListener, annotationListener }); stopwatch.Stop(); cancellationToken.ThrowIfCancellationRequested(); var comments = QualifyAndUnionComments(_module, commentListener.Comments, commentListener.RemComments); cancellationToken.ThrowIfCancellationRequested(); var attributesPassParseResults = RunAttributesPass(cancellationToken); var rewriter = new MemberAttributesRewriter(_exporter, _module.Component.CodeModule, new TokenStreamRewriter(attributesPassParseResults.tokenStream ?? tokenStream)); var completedHandler = ParseCompleted; if (completedHandler != null && !cancellationToken.IsCancellationRequested) { completedHandler.Invoke(this, new ParseCompletionArgs { ParseTree = codePaneParseResults.tree, AttributesTree = attributesPassParseResults.tree, Tokens = codePaneParseResults.tokenStream, AttributesRewriter = rewriter, Attributes = attributesPassParseResults.attributes, Comments = comments, Annotations = annotationListener.Annotations }); } } catch (COMException exception) { Logger.Error(exception, $"COM Exception thrown in thread {Thread.CurrentThread.ManagedThreadId} while parsing module {_module.ComponentName}, ParseTaskID {_taskId}."); var failedHandler = ParseFailure; failedHandler?.Invoke(this, new ParseFailureArgs { Cause = exception }); } catch (PreprocessorSyntaxErrorException syntaxErrorException) { var parsePassText = syntaxErrorException.ParsePass == ParsePass.CodePanePass ? "code pane" : "exported"; Logger.Error($"Syntax error while preprocessing; offending token '{syntaxErrorException.OffendingSymbol.Text}' at line {syntaxErrorException.LineNumber}, column {syntaxErrorException.Position} in the {parsePassText} version of module {_module.ComponentName}."); Logger.Debug(syntaxErrorException, $"SyntaxErrorException thrown in thread {Thread.CurrentThread.ManagedThreadId}, ParseTaskID {_taskId}."); ReportException(syntaxErrorException); } catch (ParsePassSyntaxErrorException syntaxErrorException) { var parsePassText = syntaxErrorException.ParsePass == ParsePass.CodePanePass ? "code pane" : "exported"; Logger.Error($"Syntax error; offending token '{syntaxErrorException.OffendingSymbol.Text}' at line {syntaxErrorException.LineNumber}, column {syntaxErrorException.Position} in the {parsePassText} version of module {_module.ComponentName}."); Logger.Debug(syntaxErrorException, $"SyntaxErrorException thrown in thread {Thread.CurrentThread.ManagedThreadId}, ParseTaskID {_taskId}."); ReportException(syntaxErrorException); } catch (SyntaxErrorException syntaxErrorException) { Logger.Error($"Syntax error; offending token '{syntaxErrorException.OffendingSymbol.Text}' at line {syntaxErrorException.LineNumber}, column {syntaxErrorException.Position} in module {_module.ComponentName}."); Logger.Debug(syntaxErrorException, $"SyntaxErrorException thrown in thread {Thread.CurrentThread.ManagedThreadId}, ParseTaskID {_taskId}."); ReportException(syntaxErrorException); } catch (OperationCanceledException exception) { //We report this, so that the calling code knows that the operation actually has been cancelled. ReportException(exception); } catch (Exception exception) { Logger.Error(exception, $" Unexpected exception thrown in thread {Thread.CurrentThread.ManagedThreadId} while parsing module {_module.ComponentName}, ParseTaskID {_taskId}."); ReportException(exception); } }
public void Start(CancellationToken token) { try { Logger.Trace($"Starting ParseTaskID {_taskId} on thread {Thread.CurrentThread.ManagedThreadId}."); var tokenStream = RewriteAndPreprocess(token); token.ThrowIfCancellationRequested(); IParseTree attributesTree; IDictionary <Tuple <string, DeclarationType>, Attributes> attributes; var attributesTokenStream = RunAttributesPass(token, out attributesTree, out attributes); var rewriter = new MemberAttributesRewriter(_exporter, _component.CodeModule, new TokenStreamRewriter(attributesTokenStream ?? tokenStream)); // temporal coupling... comments must be acquired before we walk the parse tree for declarations // otherwise none of the annotations get associated to their respective Declaration var commentListener = new CommentListener(); var annotationListener = new AnnotationListener(new VBAParserAnnotationFactory(), _qualifiedName); var stopwatch = Stopwatch.StartNew(); ITokenStream stream; var tree = ParseInternal(_component.Name, tokenStream, new IParseTreeListener[] { commentListener, annotationListener }, out stream); stopwatch.Stop(); token.ThrowIfCancellationRequested(); var comments = QualifyAndUnionComments(_qualifiedName, commentListener.Comments, commentListener.RemComments); token.ThrowIfCancellationRequested(); var completedHandler = ParseCompleted; if (completedHandler != null && !token.IsCancellationRequested) { completedHandler.Invoke(this, new ParseCompletionArgs { ParseTree = tree, AttributesTree = attributesTree, Tokens = stream, AttributesRewriter = rewriter, Attributes = attributes, Comments = comments, Annotations = annotationListener.Annotations }); } } catch (COMException exception) { Logger.Error(exception, $"Exception thrown in thread {Thread.CurrentThread.ManagedThreadId} while parsing module {_qualifiedName.Name}, ParseTaskID {_taskId}."); var failedHandler = ParseFailure; failedHandler?.Invoke(this, new ParseFailureArgs { Cause = exception }); } catch (SyntaxErrorException exception) { Logger.Warn($"Syntax error; offending token '{exception.OffendingSymbol.Text}' at line {exception.LineNumber}, column {exception.Position} in module {_qualifiedName}."); Logger.Error(exception, $"Exception thrown in thread {Thread.CurrentThread.ManagedThreadId}, ParseTaskID {_taskId}."); var failedHandler = ParseFailure; failedHandler?.Invoke(this, new ParseFailureArgs { Cause = exception }); } catch (OperationCanceledException exception) { //We return this, so that the calling code knows that the operation actually has been cancelled. var failedHandler = ParseFailure; failedHandler?.Invoke(this, new ParseFailureArgs { Cause = exception }); } catch (Exception exception) { Logger.Error(exception, $"Exception thrown in thread {Thread.CurrentThread.ManagedThreadId} while parsing module {_qualifiedName.Name}, ParseTaskID {_taskId}."); var failedHandler = ParseFailure; failedHandler?.Invoke(this, new ParseFailureArgs { Cause = exception }); } }