@@ -14,14 +14,18 @@ namespace Spedit.UI.Components
14
14
{
15
15
public class AeonEditorHighlighting : IHighlightingDefinition
16
16
{
17
+ public AeonEditorHighlighting ( IEnumerable < HighlightingColor > namedHighlightingColors )
18
+ {
19
+ NamedHighlightingColors = namedHighlightingColors ;
20
+ }
21
+
17
22
public string Name => "SM" ;
18
23
19
24
public HighlightingRuleSet MainRuleSet
20
25
{
21
26
get
22
27
{
23
- var commentMarkerSet = new HighlightingRuleSet ( ) ;
24
- commentMarkerSet . Name = "CommentMarkerSet" ;
28
+ var commentMarkerSet = new HighlightingRuleSet { Name = "CommentMarkerSet" } ;
25
29
commentMarkerSet . Rules . Add ( new HighlightingRule
26
30
{
27
31
Regex = RegexKeywordsHelper . GetRegexFromKeywords ( new [ ]
@@ -197,41 +201,28 @@ public HighlightingRuleSet MainRuleSet
197
201
if ( def . MethodsStrings . Length > 0 )
198
202
rs . Rules . Add ( new HighlightingRule //Methods
199
203
{
200
- Regex = RegexKeywordsHelper . GetRegexFromKeywords ( def . MethodsStrings , true ) ,
204
+ Regex = RegexKeywordsHelper . GetRegexFromKeywords2 ( def . MethodsStrings ) ,
201
205
Color = new HighlightingColor
202
206
{ Foreground = new SimpleHighlightingBrush ( Program . OptionsObject . SH_Methods ) }
203
207
} ) ;
204
208
205
- // TODO: Methodmaps are not implements in this way, but I couldnt find where they are defined
206
- if ( def . EnumStructStrings . Length > 0 )
207
- {
208
- rs . Rules . Add ( new HighlightingRule //Methods
209
- {
210
- Regex = RegexKeywordsHelper . GetRegexFromKeywords ( def . EnumStructStrings , true ) ,
211
- Color = new HighlightingColor
212
- { Foreground = new SimpleHighlightingBrush ( Program . OptionsObject . SH_Types ) }
213
- } ) ;
214
- }
215
-
216
209
if ( def . StructFieldStrings . Length > 0 )
217
- {
218
210
rs . Rules . Add ( new HighlightingRule //Methods
219
211
{
220
- Regex = RegexKeywordsHelper . GetRegexFromKeywords ( def . StructFieldStrings , true ) ,
212
+ Regex = RegexKeywordsHelper . GetRegexFromKeywords2 (
213
+ def . StructFieldStrings . Select ( e => e ) . ToArray ( ) ) ,
221
214
Color = new HighlightingColor
222
215
{ Foreground = new SimpleHighlightingBrush ( Program . OptionsObject . SH_Methods ) }
223
216
} ) ;
224
- }
225
-
217
+
226
218
if ( def . StructMethodStrings . Length > 0 )
227
- {
228
219
rs . Rules . Add ( new HighlightingRule //Methods
229
220
{
230
- Regex = RegexKeywordsHelper . GetRegexFromKeywords ( def . StructMethodStrings , true ) ,
221
+ Regex = RegexKeywordsHelper . GetRegexFromKeywords2 (
222
+ def . StructMethodStrings . Select ( e => e ) . ToArray ( ) ) ,
231
223
Color = new HighlightingColor
232
224
{ Foreground = new SimpleHighlightingBrush ( Program . OptionsObject . SH_Methods ) }
233
225
} ) ;
234
- }
235
226
236
227
rs . Rules . Add ( new HighlightingRule //unknown function calls
237
228
{
@@ -256,14 +247,13 @@ public HighlightingColor GetNamedColor(string name)
256
247
return null ;
257
248
}
258
249
259
- public IEnumerable < HighlightingColor > NamedHighlightingColors { get ; set ; }
250
+ public IEnumerable < HighlightingColor > NamedHighlightingColors { get ; }
260
251
261
252
public IDictionary < string , string > Properties
262
253
{
263
254
get
264
255
{
265
- var propertiesDictionary = new Dictionary < string , string > ( ) ;
266
- propertiesDictionary . Add ( "DocCommentMarker" , "///" ) ;
256
+ var propertiesDictionary = new Dictionary < string , string > { { "DocCommentMarker" , "///" } } ;
267
257
return propertiesDictionary ;
268
258
}
269
259
}
@@ -286,6 +276,7 @@ public SimpleHighlightingBrush(Color color) : this(new SolidColorBrush(color))
286
276
287
277
private SimpleHighlightingBrush ( SerializationInfo info , StreamingContext context )
288
278
{
279
+ // ReSharper disable once PossibleNullReferenceException
289
280
brush = new SolidColorBrush ( ( Color ) ColorConverter . ConvertFromString ( info . GetString ( "color" ) ) ) ;
290
281
brush . Freeze ( ) ;
291
282
}
@@ -307,8 +298,7 @@ public override string ToString()
307
298
308
299
public override bool Equals ( object obj )
309
300
{
310
- var other = obj as SimpleHighlightingBrush ;
311
- if ( other == null )
301
+ if ( ! ( obj is SimpleHighlightingBrush other ) )
312
302
return false ;
313
303
return brush . Color . Equals ( other . brush . Color ) ;
314
304
}
@@ -327,20 +317,10 @@ public static Regex GetRegexFromKeywords(string[] keywords, bool ForceAtomicRege
327
317
328
318
if ( keywords . Length == 0 ) return new Regex ( "SPEdit_Error" ) ; //hehe
329
319
330
- var UseAtomicRegex = true ;
331
- for ( var j = 0 ; j < keywords . Length ; ++ j )
332
- if ( ! char . IsLetterOrDigit ( keywords [ j ] [ 0 ] ) ||
333
- ! char . IsLetterOrDigit ( keywords [ j ] [ keywords [ j ] . Length - 1 ] ) )
334
- {
335
- UseAtomicRegex = false ;
336
- break ;
337
- }
320
+ var UseAtomicRegex = keywords . All ( t => char . IsLetterOrDigit ( t [ 0 ] ) && char . IsLetterOrDigit ( t [ t . Length - 1 ] ) ) ;
338
321
339
322
var regexBuilder = new StringBuilder ( ) ;
340
- if ( UseAtomicRegex )
341
- regexBuilder . Append ( @"\b(?>" ) ;
342
- else
343
- regexBuilder . Append ( @"(" ) ;
323
+ regexBuilder . Append ( UseAtomicRegex ? @"\b(?>" : @"(" ) ;
344
324
345
325
var orderedKeyWords = new List < string > ( keywords ) ;
346
326
var i = 0 ;
@@ -361,24 +341,33 @@ public static Regex GetRegexFromKeywords(string[] keywords, bool ForceAtomicRege
361
341
}
362
342
}
363
343
364
- if ( UseAtomicRegex )
365
- regexBuilder . Append ( @")\b" ) ;
366
- else
367
- regexBuilder . Append ( @")" ) ;
344
+ regexBuilder . Append ( UseAtomicRegex ? @")\b" : @")" ) ;
368
345
369
346
return new Regex ( regexBuilder . ToString ( ) , RegexOptions . CultureInvariant | RegexOptions . ExplicitCapture ) ;
370
347
}
371
348
372
- public static string [ ] ConvertToAtomicRegexAbleStringArray ( string [ ] keywords )
349
+ private static string [ ] ConvertToAtomicRegexAbleStringArray ( IReadOnlyList < string > keywords )
350
+ {
351
+ return keywords . Where ( t => t . Length > 0 )
352
+ . Where ( t => char . IsLetterOrDigit ( t [ 0 ] ) && char . IsLetterOrDigit ( t [ t . Length - 1 ] ) )
353
+ . ToArray ( ) ;
354
+ }
355
+
356
+ /// Use this for class like matches (methodmaps and enumstructs atm)
357
+ public static Regex GetRegexFromKeywords2 ( IEnumerable < string > keywords )
373
358
{
374
- var atomicRegexAbleList = new List < string > ( ) ;
375
- for ( var j = 0 ; j < keywords . Length ; ++ j )
376
- if ( keywords [ j ] . Length > 0 )
377
- if ( char . IsLetterOrDigit ( keywords [ j ] [ 0 ] ) &&
378
- char . IsLetterOrDigit ( keywords [ j ] [ keywords [ j ] . Length - 1 ] ) )
379
- atomicRegexAbleList . Add ( keywords [ j ] ) ;
380
-
381
- return atomicRegexAbleList . ToArray ( ) ;
359
+ var regexBuilder = new StringBuilder ( @"(?<=\b[^\s]+\.)(" ) ;
360
+ var i = 0 ;
361
+ foreach ( var keyword in keywords )
362
+ {
363
+ if ( i ++ > 0 )
364
+ regexBuilder . Append ( "|" ) ;
365
+
366
+ regexBuilder . Append ( keyword ) ;
367
+ }
368
+
369
+ regexBuilder . Append ( @")\b" ) ;
370
+ return new Regex ( regexBuilder . ToString ( ) , RegexOptions . CultureInvariant | RegexOptions . ExplicitCapture ) ;
382
371
}
383
372
}
384
373
}
0 commit comments