public IEnumerable <ITagSpan <IErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans) { var alreadyReportedSyntaxErrors = new HashSet <string>(); foreach (var span in spans) { foreach (var token in _parser.GetTokensBetween(span.Start.Position, span.End.Position)) { var syntaxError = token as SyntaxErrorToken; if (syntaxError != null && alreadyReportedSyntaxErrors.Add(syntaxError.Exception.Message)) { yield return(CreateErrorTag(span, token, "syntax error", syntaxError.Exception.Message)); continue; } var anchor = token as Anchor; if (anchor != null && _anchors[anchor.Value] > 1) { yield return(CreateErrorTag(span, token, "syntax error", "Duplicate anchor")); continue; } var anchorAlias = token as AnchorAlias; if (anchorAlias != null && !_anchors.ContainsKey(anchorAlias.Value)) { yield return(CreateErrorTag(span, token, "syntax error", "Undefined anchor")); continue; } } } }
/// <summary> /// This method scans the given SnapshotSpan for potential matches for this classification. /// In this instance, it classifies everything and returns each span as a new ClassificationSpan. /// </summary> /// <param name="trackingSpan">The span currently being classified</param> /// <returns>A list of ClassificationSpans that represent spans identified to be of this classification</returns> public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span) { var classifications = new List <ClassificationSpan>(); var tokens = _parser.GetTokensBetween(span.Start.Position, span.End.Position); Type previousTokenType = null; foreach (var token in tokens) { IClassificationType classificationType = null; var currentTokenType = token.GetType(); if (currentTokenType == typeof(Anchor)) { classificationType = _anchor; } else if (currentTokenType == typeof(AnchorAlias)) { classificationType = _alias; } else if (currentTokenType == typeof(Scalar)) { classificationType = previousTokenType == typeof(Key) ? _key : _value; } else if (currentTokenType == typeof(Tag)) { classificationType = _tag; } else if (currentTokenType == typeof(TagDirective)) { classificationType = _directive; } else if (currentTokenType == typeof(VersionDirective)) { classificationType = _directive; } else if (currentTokenType == typeof(Comment)) { classificationType = _comment; } else if (currentTokenType == typeof(SyntaxErrorToken)) { //classificationType = null; } else if (token.End.Index > token.Start.Index) { classificationType = _symbol; } previousTokenType = currentTokenType; if (classificationType != null) { var start = Math.Max(token.Start.Index, span.Start.Position); var end = Math.Min(token.End.Index, span.End.Position + 1); classifications.Add( new ClassificationSpan( new SnapshotSpan( span.Snapshot, new Span(start, end - start) ), classificationType ) ); } } return(classifications); }