Changeset 2124
- Timestamp:
- Dec 1, 2012, 1:08:08 PM (11 years ago)
- Location:
- trunk/tools/vslol
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/vslol/CppKeywordClassifier.cs
r2123 r2124 31 31 { 32 32 [Import] 33 internal IClassificationTypeRegistryService m_type_registry = null; /* Set via MEF */33 internal IClassificationTypeRegistryService m_type_registry = null; 34 34 [Import] 35 35 internal IClassifierAggregatorService m_aggregator = null; … … 60 60 private IClassifier m_classifier; 61 61 62 private IClassificationType m_customclass_type, m_constant_type; 63 private Regex m_customclass_regex, m_constant_regex; 62 private IClassificationType m_types_type, m_constant_type; 63 private Regex m_types_regex, m_constant_regex; 64 65 private static const string[] m_all_types = 66 { 67 "auto|void|bool|int|unsigned|char|short|long|float|double"; 68 "class|struct|union|template|namespace|typename|typedef", 69 "const|static|extern|volatile|inline|explicit" 70 }; 71 72 private static const string[] m_cpp_types = 73 { 74 "u?int(8|16|32|64|ptr)_t", 75 "(wchar|size|ssize)_t", 76 "va_list", 77 }; 78 79 /* ldouble real half 80 "(f(16|128)||d|[ui](8|16||64)|r)(vec[234]|mat[234]|quat|cmplx)"; 81 */ 82 83 private static const string[] m_csharp_types = 84 { 85 "var|string", 86 "out|ref|internal|sealed|public|private|protected|override" 87 }; 88 89 private static const string[] m_lolfx_types = 90 { 91 "attribute|varying|uniform|in|out", 92 "int|uint", 93 "(|[dui])(vec|mat)[234]" 94 }; 95 96 private static const string[] m_all_constants = 97 { 98 "true|false" 99 }; 100 101 private static const string[] m_cpp_constants = 102 { 103 "NULL|nullptr", 104 "EXIT_SUCCESS|EXIT_FAILURE", 105 "M_(E|LOG(2|10)E|LN2|LN10|PI|PI_2|PI_4|1_PI|2_PI|2_SQRTPI|SQRT(2|1_2))", 106 "SIG(HUP|INT|QUIT|ILL|TRAP|ABRT|FPE|KILL|USR1|SEGV|USR2|PIPE|ALRM)", 107 "SIG(TERM|CHLD|CONT|STOP|TSTP|TTIN|TTOU)" 108 }; 109 110 private static const string[] m_csharp_constants = 111 { 112 "null", 113 }; 114 115 private static const string[] m_lolfx_constants = 116 { 117 "gl_Position|gl_FragColor", 118 }; 64 119 65 120 internal CppKeywordClassifier(IClassificationTypeRegistryService registry, … … 70 125 71 126 /* Regex for types and specifiers */ 72 m_customclass_type = registry.GetClassificationType("LolCustomClass"); 73 74 string tmp = @"\b("; 75 tmp += "void|bool|int|unsigned|char|short|long|float|double|ldouble|"; 76 tmp += "class|struct|union|template|const|static|extern|volatile|inline|namespace|"; 127 m_types_type = registry.GetClassificationType("LolAnyType"); 128 129 List<string> types_list = m_all_types.ToList(); 130 if (type.IsOfType("c/c++")) 131 types_list = types_list.Concat(m_cpp_types).ToList(); 132 if (type.IsOfType("csharp")) 133 types_list = types_list.Concat(m_csharp_types).ToList(); 77 134 if (type.IsOfType("lolfx")) 78 tmp += "attribute|varying|uniform|in|out|"; 135 types_list = types_list.Concat(m_lolfx_types).ToList(); 136 m_types_regex = 137 new Regex(@"\b(" + String.Join("|", types_list.ToArray()) + @")\b"); 138 139 /* Regex for constant words */ 140 m_constant_type = registry.GetClassificationType("LolAnyConstant"); 141 142 List<string> constants_list = m_all_constants.ToList(); 143 if (type.IsOfType("c/c++")) 144 constants_list = constants_list.Concat(m_cpp_constants).ToList(); 79 145 if (type.IsOfType("csharp")) 80 tmp += "var|out|ref|string|internal|sealed|public|private|protected|override|"; 81 if (!type.IsOfType("csharp")) 82 tmp += "(f(16|128)||d|[ui](8|16||64)|r)(vec[234]|mat[234]|quat|cmplx)|"; 83 if (type.IsOfType("c/c++")) 84 { 85 tmp += "u?int(8|16|32|64|ptr)_t|"; 86 tmp += "(wchar|size|ssize)_t|"; 87 tmp += "real|half|explicit|typename|typedef|auto|"; 88 } 89 tmp = tmp.Remove(tmp.Length - 1); 90 tmp += @")\b"; 91 m_customclass_regex = new Regex(tmp); 92 93 /* Regex for constant words */ 94 m_constant_type = registry.GetClassificationType("LolCppConstant"); 95 96 if (type.IsOfType("csharp")) 97 m_constant_regex = new Regex(@"\b(null|true|false)\b"); 98 else if (type.IsOfType("c/c++")) 99 m_constant_regex = new Regex(@"\b(NULL|nullptr|true|false|M_PI)\b"); 100 else if (type.IsOfType("lolfx")) 101 m_constant_regex = new Regex(@"\b(gl_Position|gl_FragColor)\b"); 102 else 103 m_constant_regex = new Regex(@"\b(NULL)\b"); 104 146 constants_list = constants_list.Concat(m_csharp_constants).ToList(); 147 if (type.IsOfType("lolfx")) 148 constants_list = constants_list.Concat(m_lolfx_constants).ToList(); 149 m_constant_regex = 150 new Regex(@"\b(" + String.Join("|", constants_list.ToArray()) + @")\b"); 105 151 } 106 152 … … 116 162 if (cs_class == "keyword" || cs_class == "identifier") 117 163 { 118 if (m_ customclass_regex.IsMatch(cs.Span.GetText()))164 if (m_types_regex.IsMatch(cs.Span.GetText())) 119 165 { 120 ret.Add(new ClassificationSpan(cs.Span, m_ customclass_type));166 ret.Add(new ClassificationSpan(cs.Span, m_types_type)); 121 167 continue; 122 168 } … … 202 248 internal sealed class LolCppTypeFormat : LolGenericFormat 203 249 { 204 public const string m_name = "Lol CustomClass";250 public const string m_name = "LolAnyType"; 205 251 public LolCppTypeFormat() 206 252 { … … 220 266 internal sealed class LolCppConstantFormat : LolGenericFormat 221 267 { 222 public const string m_name = "Lol CppConstant";268 public const string m_name = "LolAnyConstant"; 223 269 public LolCppConstantFormat() 224 270 { -
trunk/tools/vslol/LolFxLanguageService.cs
r2123 r2124 9 9 // 10 10 11 using System; 11 12 using System.Collections.Generic; 12 13 using System.Linq;
Note: See TracChangeset
for help on using the changeset viewer.