1
1
using System ;
2
- using System . Linq ;
3
2
4
3
using RSML . Analyzer . Semantics ;
5
4
using RSML . Analyzer . Syntax ;
6
5
using RSML . Exceptions ;
6
+ using RSML . Performance . Value ;
7
7
using RSML . Toolchain . Compliance ;
8
8
9
9
10
- namespace RSML . Performance . Value
10
+ namespace RSML . Performance . Stateless
11
11
{
12
12
13
13
/// <summary>
@@ -29,19 +29,23 @@ public static class OptimizedValidator
29
29
public static void ValidateLine ( SyntaxLine line )
30
30
{
31
31
32
- if ( line . Length == 0 )
32
+ int len = line . Length ;
33
+
34
+ if ( len == 0 )
33
35
throw new InvalidRsmlSyntax ( "Empty token sequence." ) ;
34
36
35
- if ( line . Length != 1 && line [ line . Last ( ) ] . Kind == TokenKind . Eol )
37
+ if ( len != 1 && line [ line . Last ( ) ] . Kind == TokenKind . Eol )
36
38
line . Remove ( line . Last ( ) ) ; // removes last
37
39
40
+ len = line . Length ; // recalculate cuz it changed
41
+
38
42
switch ( line [ 0 ] . Kind )
39
43
{
40
44
41
45
case TokenKind . Eol or TokenKind . Eof :
42
46
return ; // we're done here
43
47
44
- case TokenKind . CommentSymbol when line . Length != 2 :
48
+ case TokenKind . CommentSymbol when len != 2 :
45
49
throw new InvalidRsmlSyntax (
46
50
"A comment must be 2 tokens long."
47
51
) ; // even if you have a comment with no text not even spaces, you'll have 2 tokens
@@ -55,7 +59,7 @@ public static void ValidateLine(SyntaxLine line)
55
59
case TokenKind . CommentSymbol :
56
60
return ;
57
61
58
- case TokenKind . SpecialActionSymbol when line . Length != 3 :
62
+ case TokenKind . SpecialActionSymbol when len != 3 :
59
63
throw new InvalidRsmlSyntax ( "A special action must be 3 tokens long." ) ; // even with no arg, you'll have 3 tokens
60
64
61
65
case TokenKind . SpecialActionSymbol when ! line [ 0 ] . Value . IsEquals ( "@" ) :
@@ -78,7 +82,7 @@ public static void ValidateLine(SyntaxLine line)
78
82
if ( ! line [ 0 ] . Value . IsEquals ( "!>" ) && ! line [ 0 ] . Value . IsEquals ( "->" ) )
79
83
throw new InvalidRsmlSyntax ( "Operator must be one of !> or ->." ) ;
80
84
81
- switch ( line . Length )
85
+ switch ( len )
82
86
{
83
87
84
88
case 2 :
@@ -94,15 +98,13 @@ public static void ValidateLine(SyntaxLine line)
94
98
line [ 2 ] . Kind != TokenKind . LogicPathValue )
95
99
throw new InvalidRsmlSyntax ( "A 3 token long logic path must be a *Operator + SystemName + LogicPathValue overload." ) ;
96
100
97
- string sysName1 = line [ 1 ] . Value . ToString ( ) ;
98
-
99
101
if ( ! line [ 1 ] . Value . IsEquals ( "any" ) && line [ 1 ] . Kind == TokenKind . WildcardKeyword )
100
102
throw new InvalidRsmlSyntax ( "A token of type WildcardKeyword must have a value of 'any'." ) ;
101
103
102
104
if ( ! line [ 1 ] . Value . IsEquals ( "defined" ) && line [ 1 ] . Kind == TokenKind . DefinedKeyword )
103
105
throw new InvalidRsmlSyntax ( "A token of type DefinedKeyword must have a value of 'defined'." ) ;
104
106
105
- if ( ! Validator . ValidSystems . Any ( s => sysName1 . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) &&
107
+ if ( ! line [ 1 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidSystems ) &&
106
108
line [ 1 ] . Kind == TokenKind . SystemName )
107
109
throw new InvalidRsmlSyntax ( "Invalid system name as of v2.0.0." ) ;
108
110
@@ -122,9 +124,6 @@ public static void ValidateLine(SyntaxLine line)
122
124
) ;
123
125
}
124
126
125
- string sysName2 = line [ 1 ] . Value . ToString ( ) ;
126
- string archName1 = line [ 2 ] . Value . ToString ( ) ;
127
-
128
127
if ( ! line [ 1 ] . Value . IsEquals ( "any" ) && line [ 1 ] . Kind == TokenKind . WildcardKeyword )
129
128
throw new InvalidRsmlSyntax ( "A token of type WildcardKeyword must have a value of 'any'." ) ;
130
129
@@ -137,12 +136,11 @@ public static void ValidateLine(SyntaxLine line)
137
136
if ( ! line [ 2 ] . Value . IsEquals ( "defined" ) && line [ 2 ] . Kind == TokenKind . DefinedKeyword )
138
137
throw new InvalidRsmlSyntax ( "A token of type DefinedKeyword must have a value of 'defined'." ) ;
139
138
140
- if ( ! Validator . ValidSystems . Any ( s => sysName2 . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) &&
141
- line [ 1 ] . Kind == TokenKind . SystemName )
139
+ if ( ! line [ 1 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidSystems ) && line [ 1 ] . Kind == TokenKind . SystemName )
142
140
throw new InvalidRsmlSyntax ( "Invalid system name as of v2.0.0." ) ;
143
141
144
- if ( ! Validator . ValidArchitectures . Any ( s => archName1 . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) &&
145
- line [ 2 ] . Kind == TokenKind . ArchitectureIdentifier )
142
+ // ReSharper disable once InvertIf
143
+ if ( ! line [ 2 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidArchitectures ) && line [ 2 ] . Kind == TokenKind . ArchitectureIdentifier )
146
144
throw new InvalidRsmlSyntax ( "Invalid architecture identifier as of v2.0.0." ) ;
147
145
148
146
return ;
@@ -164,10 +162,6 @@ public static void ValidateLine(SyntaxLine line)
164
162
) ;
165
163
}
166
164
167
- string sysName3 = line [ 1 ] . Value . ToString ( ) ;
168
- string major1 = line [ 2 ] . Value . ToString ( ) ;
169
- string archName2 = line [ 3 ] . Value . ToString ( ) ;
170
-
171
165
if ( ! line [ 1 ] . Value . IsEquals ( "any" ) && line [ 1 ] . Kind == TokenKind . WildcardKeyword )
172
166
throw new InvalidRsmlSyntax ( "A token of type WildcardKeyword must have a value of 'any'." ) ;
173
167
@@ -186,15 +180,13 @@ public static void ValidateLine(SyntaxLine line)
186
180
if ( ! line [ 3 ] . Value . IsEquals ( "defined" ) && line [ 3 ] . Kind == TokenKind . DefinedKeyword )
187
181
throw new InvalidRsmlSyntax ( "A token of type DefinedKeyword must have a value of 'defined'." ) ;
188
182
189
- if ( ! Validator . ValidSystems . Any ( s => sysName3 . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) &&
190
- line [ 1 ] . Kind == TokenKind . SystemName )
191
- throw new InvalidRsmlSyntax ( $ "Invalid system name ({ sysName3 } ) as of v2.0.0.") ;
183
+ if ( ! line [ 1 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidSystems ) && line [ 1 ] . Kind == TokenKind . SystemName )
184
+ throw new InvalidRsmlSyntax ( "Invalid system name as of v2.0.0." ) ;
192
185
193
- if ( ! Validator . ValidArchitectures . Any ( s => archName2 . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) &&
194
- line [ 3 ] . Kind == TokenKind . ArchitectureIdentifier )
186
+ if ( ! line [ 3 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidArchitectures ) && line [ 3 ] . Kind == TokenKind . ArchitectureIdentifier )
195
187
throw new InvalidRsmlSyntax ( "Invalid architecture identifier as of v2.0.0." ) ;
196
188
197
- if ( ! Int32 . TryParse ( major1 , out _ ) && line [ 2 ] . Kind == TokenKind . MajorVersionId )
189
+ if ( ! Int32 . TryParse ( line [ 2 ] . Value , out _ ) && line [ 2 ] . Kind == TokenKind . MajorVersionId )
198
190
throw new InvalidRsmlSyntax ( "The major version must be a valid integer" ) ;
199
191
200
192
return ;
@@ -222,11 +214,6 @@ public static void ValidateLine(SyntaxLine line)
222
214
) ;
223
215
}
224
216
225
- string sysName4 = line [ 1 ] . Value . ToString ( ) ;
226
- string comp = line [ 2 ] . Value . ToString ( ) ;
227
- string major2 = line [ 3 ] . Value . ToString ( ) ;
228
- string archName3 = line [ 4 ] . Value . ToString ( ) ;
229
-
230
217
if ( ! line [ 1 ] . Value . IsEquals ( "any" ) && line [ 1 ] . Kind == TokenKind . WildcardKeyword )
231
218
throw new InvalidRsmlSyntax ( "A token of type WildcardKeyword must have a value of 'any'." ) ;
232
219
@@ -239,18 +226,16 @@ public static void ValidateLine(SyntaxLine line)
239
226
if ( ! line [ 4 ] . Value . IsEquals ( "defined" ) && line [ 4 ] . Kind == TokenKind . DefinedKeyword )
240
227
throw new InvalidRsmlSyntax ( "A token of type DefinedKeyword must have a value of 'defined'." ) ;
241
228
242
- if ( ! Validator . ValidSystems . Any ( s => sysName4 . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) &&
243
- line [ 1 ] . Kind == TokenKind . SystemName )
229
+ if ( ! line [ 1 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidSystems ) && line [ 1 ] . Kind == TokenKind . SystemName )
244
230
throw new InvalidRsmlSyntax ( "Invalid system name as of v2.0.0." ) ;
245
231
246
- if ( ! Validator . ValidArchitectures . Any ( s => archName3 . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) &&
247
- line [ 1 ] . Kind == TokenKind . ArchitectureIdentifier )
232
+ if ( ! line [ 4 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidArchitectures ) && line [ 4 ] . Kind == TokenKind . ArchitectureIdentifier )
248
233
throw new InvalidRsmlSyntax ( "Invalid architecture identifier as of v2.0.0." ) ;
249
234
250
- if ( ! Validator . ValidComparators . Any ( s => comp . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) )
235
+ if ( ! line [ 2 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidComparators ) )
251
236
throw new InvalidRsmlSyntax ( "Invalid comparator." ) ;
252
237
253
- if ( ! Int32 . TryParse ( major2 , out _ ) )
238
+ if ( ! Int32 . TryParse ( line [ 3 ] . Value , out _ ) )
254
239
throw new InvalidRsmlSyntax ( "The major version must be a valid integer. Wildcards are not compatible with comparators." ) ;
255
240
256
241
return ;
0 commit comments