@@ -12,35 +12,14 @@ public class TextParser
1212 private const char DefaultNumberDecimalSeparator = '.' ;
1313 private static readonly char [ ] EscapeCharacters = { '\\ ' , 'a' , 'b' , 'f' , 'n' , 'r' , 't' , 'v' } ;
1414
15- // These aliases are supposed to simply the where clause and make it more human readable
16- private static readonly Dictionary < string , TokenId > PredefinedOperatorAliases = new ( StringComparer . OrdinalIgnoreCase )
17- {
18- { "eq" , TokenId . Equal } ,
19- { "equal" , TokenId . Equal } ,
20- { "ne" , TokenId . ExclamationEqual } ,
21- { "notequal" , TokenId . ExclamationEqual } ,
22- { "neq" , TokenId . ExclamationEqual } ,
23- { "lt" , TokenId . LessThan } ,
24- { "LessThan" , TokenId . LessThan } ,
25- { "le" , TokenId . LessThanEqual } ,
26- { "LessThanEqual" , TokenId . LessThanEqual } ,
27- { "gt" , TokenId . GreaterThan } ,
28- { "GreaterThan" , TokenId . GreaterThan } ,
29- { "ge" , TokenId . GreaterThanEqual } ,
30- { "GreaterThanEqual" , TokenId . GreaterThanEqual } ,
31- { "and" , TokenId . DoubleAmpersand } ,
32- { "AndAlso" , TokenId . DoubleAmpersand } ,
33- { "or" , TokenId . DoubleBar } ,
34- { "OrElse" , TokenId . DoubleBar } ,
35- { "not" , TokenId . Exclamation } ,
36- { "mod" , TokenId . Percent }
37- } ;
38-
3915 private readonly char _numberDecimalSeparator ;
4016 private readonly string _text ;
4117 private readonly int _textLen ;
4218 private readonly ParsingConfig _parsingConfig ;
4319
20+ // These aliases simplify the "Where"-clause and make it more human-readable.
21+ private readonly Dictionary < string , TokenId > _predefinedOperatorAliases ;
22+
4423 private int _textPos ;
4524 private char _ch ;
4625
@@ -58,6 +37,29 @@ public TextParser(ParsingConfig config, string text)
5837 {
5938 _parsingConfig = config ;
6039
40+ _predefinedOperatorAliases = new ( config . IsCaseSensitive ? StringComparer . Ordinal : StringComparer . OrdinalIgnoreCase )
41+ {
42+ { "eq" , TokenId . Equal } ,
43+ { "equal" , TokenId . Equal } ,
44+ { "ne" , TokenId . ExclamationEqual } ,
45+ { "notequal" , TokenId . ExclamationEqual } ,
46+ { "neq" , TokenId . ExclamationEqual } ,
47+ { "lt" , TokenId . LessThan } ,
48+ { "LessThan" , TokenId . LessThan } ,
49+ { "le" , TokenId . LessThanEqual } ,
50+ { "LessThanEqual" , TokenId . LessThanEqual } ,
51+ { "gt" , TokenId . GreaterThan } ,
52+ { "GreaterThan" , TokenId . GreaterThan } ,
53+ { "ge" , TokenId . GreaterThanEqual } ,
54+ { "GreaterThanEqual" , TokenId . GreaterThanEqual } ,
55+ { "and" , TokenId . DoubleAmpersand } ,
56+ { "AndAlso" , TokenId . DoubleAmpersand } ,
57+ { "or" , TokenId . DoubleBar } ,
58+ { "OrElse" , TokenId . DoubleBar } ,
59+ { "not" , TokenId . Exclamation } ,
60+ { "mod" , TokenId . Percent }
61+ } ;
62+
6163 _numberDecimalSeparator = config . NumberParseCulture ? . NumberFormat . NumberDecimalSeparator [ 0 ] ?? DefaultNumberDecimalSeparator ;
6264
6365 _text = text ;
@@ -529,14 +531,14 @@ private Exception ParseError(string format, params object[] args)
529531 return ParseError ( CurrentToken . Pos , format , args ) ;
530532 }
531533
532- private static Exception ParseError ( int pos , string format , params object [ ] args )
534+ private TokenId GetAliasedTokenId ( TokenId tokenId , string alias )
533535 {
534- return new ParseException ( string . Format ( CultureInfo . CurrentCulture , format , args ) , pos ) ;
536+ return tokenId == TokenId . Identifier && _predefinedOperatorAliases . TryGetValue ( alias , out TokenId id ) ? id : tokenId ;
535537 }
536538
537- private static TokenId GetAliasedTokenId ( TokenId tokenId , string alias )
539+ private static Exception ParseError ( int pos , string format , params object [ ] args )
538540 {
539- return tokenId == TokenId . Identifier && PredefinedOperatorAliases . TryGetValue ( alias , out TokenId id ) ? id : tokenId ;
541+ return new ParseException ( string . Format ( CultureInfo . CurrentCulture , format , args ) , pos ) ;
540542 }
541543
542544 private static bool IsHexChar ( char c )
0 commit comments