@@ -16,6 +16,7 @@ public class NumberParser
16
16
private static readonly char [ ] Qualifiers = { 'U' , 'u' , 'L' , 'l' , 'F' , 'f' , 'D' , 'd' , 'M' , 'm' } ;
17
17
private static readonly char [ ] QualifiersHex = { 'U' , 'u' , 'L' , 'l' } ;
18
18
private static readonly string [ ] QualifiersReal = { "F" , "f" , "D" , "d" , "M" , "m" } ;
19
+ private ConstantExpressionHelper _constantExpressionHelper ;
19
20
20
21
private readonly CultureInfo _culture ;
21
22
@@ -26,6 +27,7 @@ public class NumberParser
26
27
public NumberParser ( ParsingConfig ? config )
27
28
{
28
29
_culture = config ? . NumberParseCulture ?? CultureInfo . InvariantCulture ;
30
+ _constantExpressionHelper = new ConstantExpressionHelper ( config ?? ParsingConfig . Default ) ;
29
31
}
30
32
31
33
/// <summary>
@@ -77,38 +79,38 @@ public Expression ParseIntegerLiteral(int tokenPosition, string text)
77
79
{
78
80
if ( qualifier == "U" || qualifier == "u" )
79
81
{
80
- return ConstantExpressionHelper . CreateLiteral ( ( uint ) unsignedValue , text ) ;
82
+ return _constantExpressionHelper . CreateLiteral ( ( uint ) unsignedValue , text ) ;
81
83
}
82
84
83
85
if ( qualifier == "L" || qualifier == "l" )
84
86
{
85
- return ConstantExpressionHelper . CreateLiteral ( ( long ) unsignedValue , text ) ;
87
+ return _constantExpressionHelper . CreateLiteral ( ( long ) unsignedValue , text ) ;
86
88
}
87
89
88
90
if ( QualifiersReal . Contains ( qualifier ) )
89
91
{
90
92
return ParseRealLiteral ( text , qualifier [ 0 ] , false ) ;
91
93
}
92
94
93
- return ConstantExpressionHelper . CreateLiteral ( unsignedValue , text ) ;
95
+ return _constantExpressionHelper . CreateLiteral ( unsignedValue , text ) ;
94
96
}
95
97
96
98
if ( unsignedValue <= int . MaxValue )
97
99
{
98
- return ConstantExpressionHelper . CreateLiteral ( ( int ) unsignedValue , text ) ;
100
+ return _constantExpressionHelper . CreateLiteral ( ( int ) unsignedValue , text ) ;
99
101
}
100
102
101
103
if ( unsignedValue <= uint . MaxValue )
102
104
{
103
- return ConstantExpressionHelper . CreateLiteral ( ( uint ) unsignedValue , text ) ;
105
+ return _constantExpressionHelper . CreateLiteral ( ( uint ) unsignedValue , text ) ;
104
106
}
105
107
106
108
if ( unsignedValue <= long . MaxValue )
107
109
{
108
- return ConstantExpressionHelper . CreateLiteral ( ( long ) unsignedValue , text ) ;
110
+ return _constantExpressionHelper . CreateLiteral ( ( long ) unsignedValue , text ) ;
109
111
}
110
112
111
- return ConstantExpressionHelper . CreateLiteral ( unsignedValue , text ) ;
113
+ return _constantExpressionHelper . CreateLiteral ( unsignedValue , text ) ;
112
114
}
113
115
114
116
if ( isHexadecimal || isBinary )
@@ -135,7 +137,7 @@ public Expression ParseIntegerLiteral(int tokenPosition, string text)
135
137
{
136
138
if ( qualifier == "L" || qualifier == "l" )
137
139
{
138
- return ConstantExpressionHelper . CreateLiteral ( value , text ) ;
140
+ return _constantExpressionHelper . CreateLiteral ( value , text ) ;
139
141
}
140
142
141
143
if ( QualifiersReal . Contains ( qualifier ) )
@@ -148,10 +150,10 @@ public Expression ParseIntegerLiteral(int tokenPosition, string text)
148
150
149
151
if ( value <= int . MaxValue )
150
152
{
151
- return ConstantExpressionHelper . CreateLiteral ( ( int ) value , text ) ;
153
+ return _constantExpressionHelper . CreateLiteral ( ( int ) value , text ) ;
152
154
}
153
155
154
- return ConstantExpressionHelper . CreateLiteral ( value , text ) ;
156
+ return _constantExpressionHelper . CreateLiteral ( value , text ) ;
155
157
}
156
158
157
159
/// <summary>
@@ -163,18 +165,18 @@ public Expression ParseRealLiteral(string text, char qualifier, bool stripQualif
163
165
{
164
166
case 'f' :
165
167
case 'F' :
166
- return ConstantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( float ) ) ! , text ) ;
168
+ return _constantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( float ) ) ! , text ) ;
167
169
168
170
case 'm' :
169
171
case 'M' :
170
- return ConstantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( decimal ) ) ! , text ) ;
172
+ return _constantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( decimal ) ) ! , text ) ;
171
173
172
174
case 'd' :
173
175
case 'D' :
174
- return ConstantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( double ) ) ! , text ) ;
176
+ return _constantExpressionHelper . CreateLiteral ( ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( double ) ) ! , text ) ;
175
177
176
178
default :
177
- return ConstantExpressionHelper . CreateLiteral ( ParseNumber ( text , typeof ( double ) ) ! , text ) ;
179
+ return _constantExpressionHelper . CreateLiteral ( ParseNumber ( text , typeof ( double ) ) ! , text ) ;
178
180
}
179
181
}
180
182
@@ -285,12 +287,12 @@ private Expression ParseAsBinary(int tokenPosition, string text, bool isNegative
285
287
{
286
288
if ( RegexBinary32 . IsMatch ( text ) )
287
289
{
288
- return ConstantExpressionHelper . CreateLiteral ( ( isNegative ? - 1 : 1 ) * Convert . ToInt32 ( text , 2 ) , text ) ;
290
+ return _constantExpressionHelper . CreateLiteral ( ( isNegative ? - 1 : 1 ) * Convert . ToInt32 ( text , 2 ) , text ) ;
289
291
}
290
292
291
293
if ( RegexBinary64 . IsMatch ( text ) )
292
294
{
293
- return ConstantExpressionHelper . CreateLiteral ( ( isNegative ? - 1 : 1 ) * Convert . ToInt64 ( text , 2 ) , text ) ;
295
+ return _constantExpressionHelper . CreateLiteral ( ( isNegative ? - 1 : 1 ) * Convert . ToInt64 ( text , 2 ) , text ) ;
294
296
}
295
297
296
298
throw new ParseException ( string . Format ( _culture , Res . InvalidBinaryIntegerLiteral , text ) , tokenPosition ) ;
0 commit comments