@@ -45,13 +45,13 @@ public static T[] GetAttributesOfType<T>(this Enum enumVal) where T : Attribute
45
45
46
46
public delegate ( List < string > modes , bool isModePopper , string pushTarget ) ModesForLexemeGetter < IN > (
47
47
KeyValuePair < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > attribute )
48
- where IN : struct ;
48
+ where IN : struct , Enum ;
49
49
50
50
public static class LexerBuilder
51
51
{
52
52
53
53
public static Dictionary < IN , ( List < LexemeAttribute > , List < LexemeLabelAttribute > ) > GetLexemesWithReflection < IN > ( BuildResult < ILexer < IN > > result , string lang )
54
- where IN : struct
54
+ where IN : struct , Enum
55
55
{
56
56
var attributes = new Dictionary < IN , ( List < LexemeAttribute > , List < LexemeLabelAttribute > ) > ( ) ;
57
57
@@ -101,7 +101,7 @@ public static class LexerBuilder
101
101
102
102
public static BuildResult < ILexer < IN > > BuildLexer < IN > (
103
103
Action < IN , LexemeAttribute , GenericLexer < IN > > extensionBuilder = null ,
104
- LexerPostProcess < IN > lexerPostProcess = null ) where IN : struct
104
+ LexerPostProcess < IN > lexerPostProcess = null ) where IN : struct , Enum
105
105
{
106
106
return BuildLexer < IN > ( new BuildResult < ILexer < IN > > ( ) , extensionBuilder , lexerPostProcess : lexerPostProcess ) ;
107
107
}
@@ -115,7 +115,7 @@ public static BuildResult<ILexer<IN>> BuildLexer<IN>(BuildResult<ILexer<IN>> res
115
115
Dictionary < IN , List < CommentAttribute > > comments = null ,
116
116
Func < KeyValuePair < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > , ( List < string > modes , bool isModePopper , string pushTarget ) > modesGetter = null ,
117
117
Func < List < ( IN tokenId , Func < Token < IN > , Token < IN > > callback ) > > callbacksGetter = null )
118
- where IN : struct
118
+ where IN : struct , Enum
119
119
{
120
120
attributes = attributes ?? GetLexemesWithReflection < IN > ( result , lang ) ;
121
121
lexerAttribute = lexerAttribute ?? typeof ( IN ) . GetCustomAttribute < LexerAttribute > ( ) ;
@@ -143,7 +143,7 @@ public static BuildResult<ILexer<IN>> BuildLexer<IN>(BuildResult<ILexer<IN>> res
143
143
return result ;
144
144
}
145
145
146
- private static List < Token < IN > > LabelTokens < IN > ( string lang , List < Token < IN > > tokens , Dictionary < IN , Dictionary < string , string > > labels ) where IN : struct
146
+ private static List < Token < IN > > LabelTokens < IN > ( string lang , List < Token < IN > > tokens , Dictionary < IN , Dictionary < string , string > > labels ) where IN : struct , Enum
147
147
{
148
148
List < Token < IN > > labeledTokens ;
149
149
labeledTokens = tokens . Select ( token =>
@@ -175,7 +175,7 @@ private static BuildResult<ILexer<IN>> Build<IN>(
175
175
string lang = null ,
176
176
IList < string > explicitTokens = null , Dictionary < IN , List < CommentAttribute > > comments = null ,
177
177
Func < KeyValuePair < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > , ( List < string >
178
- modes , bool isModePopper , string pushTarget ) > modesGetter = null , Func < List < ( IN tokenId , Func < Token < IN > , Token < IN > > callback ) > > callbacksGetter = null ) where IN : struct
178
+ modes , bool isModePopper , string pushTarget ) > modesGetter = null , Func < List < ( IN tokenId , Func < Token < IN > , Token < IN > > callback ) > > callbacksGetter = null ) where IN : struct , Enum
179
179
{
180
180
var hasRegexLexemes = IsRegexLexer < IN > ( attributes ) ;
181
181
var hasGenericLexemes = IsGenericLexer < IN > ( attributes ) ;
@@ -214,7 +214,7 @@ private static BuildResult<ILexer<IN>> Build<IN>(
214
214
215
215
private static BuildResult < ILexer < IN > > SetLabels < IN > (
216
216
Dictionary < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > attributes ,
217
- BuildResult < ILexer < IN > > result ) where IN : struct
217
+ BuildResult < ILexer < IN > > result ) where IN : struct , Enum
218
218
{
219
219
if ( result . IsOk && result . Result != null )
220
220
{
@@ -269,7 +269,7 @@ private static bool IsGenericLexer<IN>(Dictionary<IN, (List<LexemeAttribute> lex
269
269
private static BuildResult < ILexer < IN > > BuildRegexLexer < IN> (
270
270
Dictionary < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > attributes ,
271
271
string lang ,
272
- BuildResult < ILexer < IN > > result ) where IN : struct
272
+ BuildResult < ILexer < IN > > result ) where IN : struct, Enum
273
273
{
274
274
var lexer = new Lexer<IN>()
275
275
{
@@ -314,7 +314,7 @@ private static BuildResult<ILexer<IN>> BuildRegexLexer<IN>(
314
314
315
315
316
316
private static Dictionary < string , IDictionary < IN , List < LexemeAttribute > > > GetSubLexers < IN > (
317
- IDictionary < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > attributes , Func < KeyValuePair < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > , ( List < string > modes , bool isModePopper , string pushTarget ) > modesGetter = null ) where IN : struct
317
+ IDictionary < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > attributes , Func < KeyValuePair < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > , ( List < string > modes , bool isModePopper , string pushTarget ) > modesGetter = null ) where IN : struct , Enum
318
318
{
319
319
if ( modesGetter == null )
320
320
{
@@ -354,7 +354,7 @@ private static Dictionary<string, IDictionary<IN, List<LexemeAttribute>>> GetSub
354
354
return subLexers ;
355
355
}
356
356
357
- private static ( List < string > modes , bool isModePopper , string pushTarget ) GetModesForLexeme < IN > ( KeyValuePair < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > attribute ) where IN : struct
357
+ private static ( List < string > modes , bool isModePopper , string pushTarget ) GetModesForLexeme < IN > ( KeyValuePair < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > attribute ) where IN : struct , Enum
358
358
{
359
359
( List < string > modes , bool isModePopper , string pushTarget ) result = ( new List < string > ( ) , false , null ) ;
360
360
if ( attribute . Key is Enum enumValue )
@@ -403,7 +403,7 @@ private static (List<string> modes,bool isModePopper, string pushTarget) GetMode
403
403
404
404
private static ( GenericLexer < IN > . Config , GenericToken [ ] ) GetConfigAndGenericTokens < IN > (
405
405
IDictionary < IN , List < LexemeAttribute > > attributes , LexerAttribute lexerAttribute = null )
406
- where IN : struct
406
+ where IN : struct , Enum
407
407
{
408
408
var config = new GenericLexer < IN > . Config ( ) ;
409
409
if ( lexerAttribute != null )
@@ -460,7 +460,7 @@ private static IEnumerable<char[]> ParseIdentifierPattern(string pattern)
460
460
}
461
461
462
462
private static NodeCallback < GenericToken > GetCallbackSingle < IN > ( IN token , int channel )
463
- where IN : struct
463
+ where IN : struct , Enum
464
464
{
465
465
NodeCallback < GenericToken > callback = match =>
466
466
{
@@ -474,7 +474,7 @@ private static NodeCallback<GenericToken> GetCallbackSingle<IN>(IN token, int ch
474
474
}
475
475
476
476
private static NodeCallback < GenericToken > GetCallbackMulti < IN > ( IN token , int channel )
477
- where IN : struct
477
+ where IN : struct , Enum
478
478
{
479
479
NodeCallback < GenericToken > callbackMulti = match =>
480
480
{
@@ -494,7 +494,7 @@ public static BuildResult<ILexer<IN>> BuildGenericSubLexers<IN>(
494
494
IList < string > explicitTokens = null , LexerAttribute lexerAttribute = null ,
495
495
Dictionary < IN , List < CommentAttribute > > comments = null ,
496
496
Func < KeyValuePair < IN , ( List < LexemeAttribute > lexemes , List < LexemeLabelAttribute > labels ) > , ( List < string >
497
- modes , bool isModePopper , string pushTarget ) > modesGetter = null , Func < List < ( IN tokenId , Func < Token < IN > , Token < IN > > callback ) > > callbacksGetter = null ) where IN : struct
497
+ modes , bool isModePopper , string pushTarget ) > modesGetter = null , Func < List < ( IN tokenId , Func < Token < IN > , Token < IN > > callback ) > > callbacksGetter = null ) where IN : struct , Enum
498
498
{
499
499
GenericLexer < IN > genLexer = null ;
500
500
var subLexers = GetSubLexers ( attributes , modesGetter ) ;
@@ -534,7 +534,7 @@ public static BuildResult<ILexer<IN>> BuildGenericSubLexers<IN>(
534
534
private static BuildResult < ILexer < IN > > BuildGenericLexer < IN > ( IDictionary < IN , List < LexemeAttribute > > attributes ,
535
535
Action < IN , LexemeAttribute , GenericLexer < IN > > extensionBuilder , BuildResult < ILexer < IN > > result , string lang ,
536
536
LexerAttribute lexerAttribute = null , Dictionary < IN , List < CommentAttribute > > comments = null ,
537
- IList < string > explicitTokens = null ) where IN : struct
537
+ IList < string > explicitTokens = null ) where IN : struct , Enum
538
538
{
539
539
result = CheckStringAndCharTokens < IN > ( attributes , result , lang ) ;
540
540
var ( config , tokens ) = GetConfigAndGenericTokens < IN > ( attributes , lexerAttribute ) ;
@@ -783,7 +783,7 @@ private static (string delimiter, string escape, bool doEscape) GetDelimiters(Le
783
783
784
784
private static BuildResult < ILexer < IN > > CheckStringAndCharTokens < IN > (
785
785
IDictionary < IN , List < LexemeAttribute > > attributes , BuildResult < ILexer < IN > > result , string lang )
786
- where IN : struct
786
+ where IN : struct , Enum
787
787
{
788
788
var allLexemes = attributes . Values . SelectMany < List < LexemeAttribute > , LexemeAttribute > ( a => a ) ;
789
789
@@ -809,7 +809,7 @@ private static BuildResult<ILexer<IN>> CheckStringAndCharTokens<IN>(
809
809
810
810
811
811
private static Dictionary < IN , List < CommentAttribute > > GetCommentsAttribute < IN > ( BuildResult < ILexer < IN > > result ,
812
- string lang ) where IN : struct
812
+ string lang ) where IN : struct , Enum
813
813
{
814
814
var attributes = new Dictionary < IN , List < CommentAttribute > > ( ) ;
815
815
@@ -861,7 +861,7 @@ private static Dictionary<IN, List<CommentAttribute>> GetCommentsAttribute<IN>(B
861
861
}
862
862
863
863
private static void AddExtensions < IN > ( Dictionary < IN , LexemeAttribute > extensions ,
864
- Action < IN , LexemeAttribute , GenericLexer < IN > > extensionBuilder , GenericLexer < IN > lexer ) where IN : struct
864
+ Action < IN , LexemeAttribute , GenericLexer < IN > > extensionBuilder , GenericLexer < IN > lexer ) where IN : struct , Enum
865
865
{
866
866
if ( extensionBuilder != null )
867
867
{
0 commit comments