/// <summary> /// Gets the classifications from <see cref="VisualCobraTokenizer"/>. /// </summary> /// <param name="span">The span to get classifications from.</param> /// <param name="tokenizer">The tokenizer to use.</param> /// <returns>A list of <see cref="ClassificationSpan"/> objects representing the classifications /// in <paramref name="span"/>.</returns> private static List <ClassificationSpan> GetClassificationsFromCobraTokenizer( SnapshotSpan span, Tokenizer tokenizer) { // TODO Tried parallelising, but I'm not sure it's safe in combination with "previous". var classifications = new List <ClassificationSpan>(); IToken previous = null; foreach (IToken tok in tokenizer.AllTokens()) { if (tok.IsKeyword) { AddSpanToClassifications(span, classifications, tok, _cobraKeywordClassificationType); } else { switch (tok.Which) { case "STRING_SINGLE": case "STRING_DOUBLE": case "CHAR": case "CHAR_LIT_SINGLE": AddSpanToClassifications(span, classifications, tok, _cobraStringClassificationType); break; case "ID": // Note "CLASS" is the class keyword, not "a class" if (IsClass(tok)) { AddSpanToClassifications(span, classifications, tok, _cobraClassClassificationType); } break; case "QUESTION": if (IsClass(previous)) { // add another char to cover the ? on the end of a nillable class AddSpanToClassifications(span, classifications, tok, _cobraClassClassificationType); } break; case "COMMENT": AddSpanToClassifications(span, classifications, tok, _cobraCommentClassificationType); break; } previous = tok; } } return(classifications); }
/// <summary> /// Gets the classifications from <see cref="VisualCobraTokenizer"/>. /// </summary> /// <param name="span">The span to get classifications from.</param> /// <param name="tokenizer">The tokenizer to use.</param> /// <returns>A list of <see cref="ClassificationSpan"/> objects representing the classifications /// in <paramref name="span"/>.</returns> private static List<ClassificationSpan> GetClassificationsFromCobraTokenizer( SnapshotSpan span, Tokenizer tokenizer) { // TODO Tried parallelising, but I'm not sure it's safe in combination with "previous". var classifications = new List<ClassificationSpan>(); IToken previous = null; foreach (IToken tok in tokenizer.AllTokens()) { if (tok.IsKeyword) { AddSpanToClassifications(span, classifications, tok, _cobraKeywordClassificationType); } else { switch (tok.Which) { case "STRING_SINGLE": case "STRING_DOUBLE": case "CHAR": case "CHAR_LIT_SINGLE": AddSpanToClassifications(span, classifications, tok, _cobraStringClassificationType); break; case "ID": // Note "CLASS" is the class keyword, not "a class" if (IsClass(tok)) { AddSpanToClassifications(span, classifications, tok, _cobraClassClassificationType); } break; case "QUESTION": if (IsClass(previous)) { // add another char to cover the ? on the end of a nillable class AddSpanToClassifications(span, classifications, tok, _cobraClassClassificationType); } break; case "COMMENT": AddSpanToClassifications(span, classifications, tok, _cobraCommentClassificationType); break; } previous = tok; } } return classifications; }