Changeset 2122 for trunk/tools/vslol/CppKeywordClassifier.cs
- Timestamp:
- Nov 30, 2012, 1:51:53 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/vslol/CppKeywordClassifier.cs
r2121 r2122 21 21 [Import] 22 22 internal IClassificationTypeRegistryService m_type_registry = null; /* Set via MEF */ 23 23 [Import] 24 internal IClassifierAggregatorService m_aggregator = null; 24 25 [Import] 25 26 internal IClassificationFormatMapService m_format_map = null; 26 27 28 internal static bool m_inprogress = false; 29 27 30 public IClassifier GetClassifier(ITextBuffer buffer) 28 31 { 32 /* Avoid infinite recursion */ 33 if (m_inprogress) 34 return null; 35 29 36 LolGenericFormat.SetRegistry(m_type_registry, m_format_map); 30 37 31 return buffer.Properties.GetOrCreateSingletonProperty<CppKeywordClassifier>(delegate { return new CppKeywordClassifier(m_type_registry, buffer.ContentType); }); 38 try 39 { 40 m_inprogress = true; 41 return buffer.Properties.GetOrCreateSingletonProperty<CppKeywordClassifier>(delegate { return new CppKeywordClassifier(m_type_registry, m_aggregator.GetClassifier(buffer), buffer.ContentType); }); 42 } 43 finally { m_inprogress = false; } 32 44 } 33 45 } … … 35 47 class CppKeywordClassifier : IClassifier 36 48 { 49 private IClassifier m_classifier; 50 37 51 private IClassificationType m_customclass_type; 38 private Regex m_ regex;52 private Regex m_customclass_regex; 39 53 40 54 internal CppKeywordClassifier(IClassificationTypeRegistryService registry, 55 IClassifier classifier, 41 56 IContentType type) 42 57 { 58 m_classifier = classifier; 59 43 60 m_customclass_type = registry.GetClassificationType("LolCustomClass"); 44 61 … … 57 74 tmp += "real|half|explicit|typename|typedef|"; 58 75 } 76 tmp = tmp.Remove(tmp.Length - 1); 59 77 tmp += @")\b"; 60 m_ regex = new Regex(tmp);78 m_customclass_regex = new Regex(tmp); 61 79 } 62 80 … … 65 83 List<ClassificationSpan> ret = new List<ClassificationSpan>(); 66 84 67 string tmp = span.GetText(); 68 var matches = m_regex.Matches(tmp); 69 foreach (Match m in matches) 85 foreach (ClassificationSpan cs in m_classifier.GetClassificationSpans(span)) 70 86 { 71 Span newspan = new Span(span.Start.Position + m.Index, m.Length); 72 SnapshotSpan newsnapshot = new SnapshotSpan(span.Snapshot, newspan); 73 ret.Add(new ClassificationSpan(newsnapshot, m_customclass_type)); 87 string cs_class = cs.ClassificationType.Classification.ToLower(); 88 89 /* Only apply our rules if we found a keyword or an identifier */ 90 if (cs_class == "keyword" || cs_class == "identifier") 91 { 92 if (m_customclass_regex.IsMatch(cs.Span.GetText())) 93 { 94 ret.Add(new ClassificationSpan(cs.Span, m_customclass_type)); 95 continue; 96 } 97 } 98 99 ret.Add(cs); 74 100 } 75 101
Note: See TracChangeset
for help on using the changeset viewer.