public override IScanner GetScanner(IVsTextLines buffer) { if (scanner == null) { this.scanner = new LineScanner(LanguageSet.Acquire(LanguageOption.Extended).Grammar); } return(this.scanner); }
public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req) { Debug.Print("ParseSource at ({0}:{1}), reason {2}", req.Line, req.Col, req.Reason); Source source = (Source)this.GetSource(req.FileName); if (source.GetLineCount() > 0) { switch (req.Reason) { case ParseReason.Check: SetLanguageOption(source); Parser parser = LanguageSet.Acquire(source.option).Parser; // This is where you perform your syntax highlighting. // Parse entire source as given in req.Text. // Store results in the AuthoringScope object. ParseTree tree; ParseTreeNode root; lock (lock_parser) { root = (tree = parser.Parse(req.Text, req.FileName)).Root; AstNode node = null; if (root != null) { if (req.FileName != "<Source>") { JoinUO.UOSL.Service.UOSLBase.ReCache(req.FileName, tree); } node = (AstNode)root.AstNode; } source.ParseResult = node; } // Used for brace matching. TokenStack braces = parser.Context.OpenBraces; foreach (Token brace in braces) { TextSpan openBrace = new TextSpan(); openBrace.iStartLine = brace.Location.Line; openBrace.iStartIndex = brace.Location.Column; openBrace.iEndLine = brace.Location.Line; openBrace.iEndIndex = openBrace.iStartIndex + brace.Length; TextSpan closeBrace = new TextSpan(); if (brace.OtherBrace != null) // Added check: this did not seem to be handled -=Derrick=- { closeBrace.iStartLine = brace.OtherBrace.Location.Line; closeBrace.iStartIndex = brace.OtherBrace.Location.Column; closeBrace.iEndLine = brace.OtherBrace.Location.Line; closeBrace.iEndIndex = closeBrace.iStartIndex + brace.OtherBrace.Length; if (source.Braces == null) { source.Braces = new List <TextSpan[]>(); } source.Braces.Add(new TextSpan[2] { openBrace, closeBrace }); } else // Added error message -=Derrick=- { req.Sink.AddError(req.FileName, string.Format("Unmatched opening brace '{0}'", brace.Text), openBrace, Severity.Error); } } if (parser.Context.CurrentParseTree.ParserMessages.Count > 0) { foreach (ParserMessage error in parser.Context.CurrentParseTree.ParserMessages) { TextSpan span = new TextSpan(); int line, col; if (!(error is ExternalErrorMessage) || ((ExternalErrorMessage)error).FilePath == parser.Context.CurrentParseTree.FileName) { source.GetLineIndexOfPosition(error.Span.Location.Position, out line, out col); span.iStartLine = line; span.iStartIndex = col; source.GetLineIndexOfPosition(error.Span.EndPosition, out line, out col); span.iEndLine = Math.Max(span.iStartLine, line); span.iEndIndex = Math.Max(span.iStartIndex, col); } else { span.iStartLine = error.Span.Location.Line; span.iStartIndex = error.Span.Location.Column; span.iEndLine = span.iStartLine; span.iEndIndex = span.iStartIndex; } Severity level = error.Level == ParserErrorLevel.Error ? Severity.Error : error.Level == ParserErrorLevel.Warning ? Severity.Warning : Severity.Hint; if (error is ExternalErrorMessage) { req.Sink.AddError(((ExternalErrorMessage)error).FilePath, error.Message, span, level); } else { req.Sink.AddError(req.FileName, error.Message, span, level); } } } break; case ParseReason.DisplayMemberList: // Parse the line specified in req.Line for the two // tokens just before req.Col to obtain the identifier // and the member connector symbol. // Examine existing parse tree for members of the identifer // and return a list of members in your version of the // Declarations class as stored in the AuthoringScope // object. break; case ParseReason.MethodTip: // Parse the line specified in req.Line for the token // just before req.Col to obtain the name of the method // being entered. // Examine the existing parse tree for all method signatures // with the same name and return a list of those signatures // in your version of the Methods class as stored in the // AuthoringScope object. break; case ParseReason.QuickInfo: break; case ParseReason.HighlightBraces: case ParseReason.MemberSelectAndHighlightBraces: case ParseReason.MatchBraces: if (source.Braces != null) { foreach (TextSpan[] brace in source.Braces) { if (brace.Length == 2) { req.Sink.MatchPair(brace[0], brace[1], 1); } else if (brace.Length >= 3) { req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1); } } } break; } } AuthoringScope _scope = null; ScopeDict.TryGetValue(source, out _scope); if (_scope == null) { _scope = ScopeDict[source] = new AuthoringScope(source, source.ParseResult); } else if (source.ParseResult != null) { _scope.LastParseResult = source.ParseResult; } return(_scope); }