11using System ;
2- using System . Linq ;
32
43using RSML . Analyzer . Semantics ;
54using RSML . Analyzer . Syntax ;
65using RSML . Exceptions ;
6+ using RSML . Performance . Value ;
77using RSML . Toolchain . Compliance ;
88
99
10- namespace RSML . Performance . Value
10+ namespace RSML . Performance . Stateless
1111{
1212
1313 /// <summary>
@@ -29,19 +29,23 @@ public static class OptimizedValidator
2929 public static void ValidateLine ( SyntaxLine line )
3030 {
3131
32- if ( line . Length == 0 )
32+ int len = line . Length ;
33+
34+ if ( len == 0 )
3335 throw new InvalidRsmlSyntax ( "Empty token sequence." ) ;
3436
35- if ( line . Length != 1 && line [ line . Last ( ) ] . Kind == TokenKind . Eol )
37+ if ( len != 1 && line [ line . Last ( ) ] . Kind == TokenKind . Eol )
3638 line . Remove ( line . Last ( ) ) ; // removes last
3739
40+ len = line . Length ; // recalculate cuz it changed
41+
3842 switch ( line [ 0 ] . Kind )
3943 {
4044
4145 case TokenKind . Eol or TokenKind . Eof :
4246 return ; // we're done here
4347
44- case TokenKind . CommentSymbol when line . Length != 2 :
48+ case TokenKind . CommentSymbol when len != 2 :
4549 throw new InvalidRsmlSyntax (
4650 "A comment must be 2 tokens long."
4751 ) ; // 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)
5559 case TokenKind . CommentSymbol :
5660 return ;
5761
58- case TokenKind . SpecialActionSymbol when line . Length != 3 :
62+ case TokenKind . SpecialActionSymbol when len != 3 :
5963 throw new InvalidRsmlSyntax ( "A special action must be 3 tokens long." ) ; // even with no arg, you'll have 3 tokens
6064
6165 case TokenKind . SpecialActionSymbol when ! line [ 0 ] . Value . IsEquals ( "@" ) :
@@ -78,7 +82,7 @@ public static void ValidateLine(SyntaxLine line)
7882 if ( ! line [ 0 ] . Value . IsEquals ( "!>" ) && ! line [ 0 ] . Value . IsEquals ( "->" ) )
7983 throw new InvalidRsmlSyntax ( "Operator must be one of !> or ->." ) ;
8084
81- switch ( line . Length )
85+ switch ( len )
8286 {
8387
8488 case 2 :
@@ -94,15 +98,13 @@ public static void ValidateLine(SyntaxLine line)
9498 line [ 2 ] . Kind != TokenKind . LogicPathValue )
9599 throw new InvalidRsmlSyntax ( "A 3 token long logic path must be a *Operator + SystemName + LogicPathValue overload." ) ;
96100
97- string sysName1 = line [ 1 ] . Value . ToString ( ) ;
98-
99101 if ( ! line [ 1 ] . Value . IsEquals ( "any" ) && line [ 1 ] . Kind == TokenKind . WildcardKeyword )
100102 throw new InvalidRsmlSyntax ( "A token of type WildcardKeyword must have a value of 'any'." ) ;
101103
102104 if ( ! line [ 1 ] . Value . IsEquals ( "defined" ) && line [ 1 ] . Kind == TokenKind . DefinedKeyword )
103105 throw new InvalidRsmlSyntax ( "A token of type DefinedKeyword must have a value of 'defined'." ) ;
104106
105- if ( ! Validator . ValidSystems . Any ( s => sysName1 . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) &&
107+ if ( ! line [ 1 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidSystems ) &&
106108 line [ 1 ] . Kind == TokenKind . SystemName )
107109 throw new InvalidRsmlSyntax ( "Invalid system name as of v2.0.0." ) ;
108110
@@ -122,9 +124,6 @@ public static void ValidateLine(SyntaxLine line)
122124 ) ;
123125 }
124126
125- string sysName2 = line [ 1 ] . Value . ToString ( ) ;
126- string archName1 = line [ 2 ] . Value . ToString ( ) ;
127-
128127 if ( ! line [ 1 ] . Value . IsEquals ( "any" ) && line [ 1 ] . Kind == TokenKind . WildcardKeyword )
129128 throw new InvalidRsmlSyntax ( "A token of type WildcardKeyword must have a value of 'any'." ) ;
130129
@@ -137,12 +136,11 @@ public static void ValidateLine(SyntaxLine line)
137136 if ( ! line [ 2 ] . Value . IsEquals ( "defined" ) && line [ 2 ] . Kind == TokenKind . DefinedKeyword )
138137 throw new InvalidRsmlSyntax ( "A token of type DefinedKeyword must have a value of 'defined'." ) ;
139138
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 )
142140 throw new InvalidRsmlSyntax ( "Invalid system name as of v2.0.0." ) ;
143141
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 )
146144 throw new InvalidRsmlSyntax ( "Invalid architecture identifier as of v2.0.0." ) ;
147145
148146 return ;
@@ -164,10 +162,6 @@ public static void ValidateLine(SyntaxLine line)
164162 ) ;
165163 }
166164
167- string sysName3 = line [ 1 ] . Value . ToString ( ) ;
168- string major1 = line [ 2 ] . Value . ToString ( ) ;
169- string archName2 = line [ 3 ] . Value . ToString ( ) ;
170-
171165 if ( ! line [ 1 ] . Value . IsEquals ( "any" ) && line [ 1 ] . Kind == TokenKind . WildcardKeyword )
172166 throw new InvalidRsmlSyntax ( "A token of type WildcardKeyword must have a value of 'any'." ) ;
173167
@@ -186,15 +180,13 @@ public static void ValidateLine(SyntaxLine line)
186180 if ( ! line [ 3 ] . Value . IsEquals ( "defined" ) && line [ 3 ] . Kind == TokenKind . DefinedKeyword )
187181 throw new InvalidRsmlSyntax ( "A token of type DefinedKeyword must have a value of 'defined'." ) ;
188182
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." ) ;
192185
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 )
195187 throw new InvalidRsmlSyntax ( "Invalid architecture identifier as of v2.0.0." ) ;
196188
197- if ( ! Int32 . TryParse ( major1 , out _ ) && line [ 2 ] . Kind == TokenKind . MajorVersionId )
189+ if ( ! Int32 . TryParse ( line [ 2 ] . Value , out _ ) && line [ 2 ] . Kind == TokenKind . MajorVersionId )
198190 throw new InvalidRsmlSyntax ( "The major version must be a valid integer" ) ;
199191
200192 return ;
@@ -222,11 +214,6 @@ public static void ValidateLine(SyntaxLine line)
222214 ) ;
223215 }
224216
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-
230217 if ( ! line [ 1 ] . Value . IsEquals ( "any" ) && line [ 1 ] . Kind == TokenKind . WildcardKeyword )
231218 throw new InvalidRsmlSyntax ( "A token of type WildcardKeyword must have a value of 'any'." ) ;
232219
@@ -239,18 +226,16 @@ public static void ValidateLine(SyntaxLine line)
239226 if ( ! line [ 4 ] . Value . IsEquals ( "defined" ) && line [ 4 ] . Kind == TokenKind . DefinedKeyword )
240227 throw new InvalidRsmlSyntax ( "A token of type DefinedKeyword must have a value of 'defined'." ) ;
241228
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 )
244230 throw new InvalidRsmlSyntax ( "Invalid system name as of v2.0.0." ) ;
245231
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 )
248233 throw new InvalidRsmlSyntax ( "Invalid architecture identifier as of v2.0.0." ) ;
249234
250- if ( ! Validator . ValidComparators . Any ( s => comp . Equals ( s , StringComparison . OrdinalIgnoreCase ) ) )
235+ if ( ! line [ 2 ] . Value . IsAsciiEqualsIgnoreCase ( Validator . ValidComparators ) )
251236 throw new InvalidRsmlSyntax ( "Invalid comparator." ) ;
252237
253- if ( ! Int32 . TryParse ( major2 , out _ ) )
238+ if ( ! Int32 . TryParse ( line [ 3 ] . Value , out _ ) )
254239 throw new InvalidRsmlSyntax ( "The major version must be a valid integer. Wildcards are not compatible with comparators." ) ;
255240
256241 return ;
0 commit comments