@@ -809,94 +809,12 @@ Expression ParseIntegerLiteral()
809
809
_textParser . ValidateToken ( TokenId . IntegerLiteral ) ;
810
810
811
811
string text = _textParser . CurrentToken . Text ;
812
- string qualifier = null ;
813
- char last = text [ text . Length - 1 ] ;
814
- bool isHexadecimal = text . StartsWith ( text [ 0 ] == '-' ? "-0x" : "0x" , StringComparison . OrdinalIgnoreCase ) ;
815
- char [ ] qualifierLetters = isHexadecimal
816
- ? new [ ] { 'U' , 'u' , 'L' , 'l' }
817
- : new [ ] { 'U' , 'u' , 'L' , 'l' , 'F' , 'f' , 'D' , 'd' , 'M' , 'm' } ;
818
812
819
- if ( qualifierLetters . Contains ( last ) )
820
- {
821
- int pos = text . Length - 1 , count = 0 ;
822
- while ( qualifierLetters . Contains ( text [ pos ] ) )
823
- {
824
- ++ count ;
825
- -- pos ;
826
- }
827
- qualifier = text . Substring ( text . Length - count , count ) ;
828
- text = text . Substring ( 0 , text . Length - count ) ;
829
- }
830
-
831
- if ( text [ 0 ] != '-' )
832
- {
833
- if ( isHexadecimal )
834
- {
835
- text = text . Substring ( 2 ) ;
836
- }
837
-
838
- if ( ! ulong . TryParse ( text , isHexadecimal ? NumberStyles . HexNumber : NumberStyles . Integer , _parsingConfig . NumberParseCulture , out ulong value ) )
839
- {
840
- throw ParseError ( Res . InvalidIntegerLiteral , text ) ;
841
- }
842
-
843
- _textParser . NextToken ( ) ;
844
- if ( ! string . IsNullOrEmpty ( qualifier ) )
845
- {
846
- if ( qualifier == "U" || qualifier == "u" ) return ConstantExpressionHelper . CreateLiteral ( ( uint ) value , text ) ;
847
- if ( qualifier == "L" || qualifier == "l" ) return ConstantExpressionHelper . CreateLiteral ( ( long ) value , text ) ;
848
-
849
- // in case of UL, just return
850
- return ConstantExpressionHelper . CreateLiteral ( value , text ) ;
851
- }
813
+ var tokenPosition = _textParser . CurrentToken . Pos ;
852
814
853
- // if (value <= (int)short.MaxValue) return ConstantExpressionHelper.CreateLiteral((short)value, text);
854
- if ( value <= int . MaxValue ) return ConstantExpressionHelper . CreateLiteral ( ( int ) value , text ) ;
855
- if ( value <= uint . MaxValue ) return ConstantExpressionHelper . CreateLiteral ( ( uint ) value , text ) ;
856
- if ( value <= long . MaxValue ) return ConstantExpressionHelper . CreateLiteral ( ( long ) value , text ) ;
857
-
858
- return ConstantExpressionHelper . CreateLiteral ( value , text ) ;
859
- }
860
- else
861
- {
862
- if ( isHexadecimal )
863
- {
864
- text = text . Substring ( 3 ) ;
865
- }
866
-
867
- if ( ! long . TryParse ( text , isHexadecimal ? NumberStyles . HexNumber : NumberStyles . Integer , _parsingConfig . NumberParseCulture , out long value ) )
868
- {
869
- throw ParseError ( Res . InvalidIntegerLiteral , text ) ;
870
- }
871
-
872
- if ( isHexadecimal )
873
- {
874
- value = - value ;
875
- }
876
-
877
- _textParser . NextToken ( ) ;
878
- if ( ! string . IsNullOrEmpty ( qualifier ) )
879
- {
880
- if ( qualifier == "L" || qualifier == "l" )
881
- {
882
- return ConstantExpressionHelper . CreateLiteral ( value , text ) ;
883
- }
884
-
885
- if ( qualifier == "F" || qualifier == "f" || qualifier == "D" || qualifier == "d" || qualifier == "M" || qualifier == "m" )
886
- {
887
- return ParseRealLiteral ( text , qualifier [ 0 ] , false ) ;
888
- }
889
-
890
- throw ParseError ( Res . MinusCannotBeAppliedToUnsignedInteger ) ;
891
- }
892
-
893
- if ( value <= int . MaxValue )
894
- {
895
- return ConstantExpressionHelper . CreateLiteral ( ( int ) value , text ) ;
896
- }
897
-
898
- return ConstantExpressionHelper . CreateLiteral ( value , text ) ;
899
- }
815
+ var constantExpression = _numberParser . ParseIntegerLiteral ( tokenPosition , text ) ;
816
+ _textParser . NextToken ( ) ;
817
+ return constantExpression ;
900
818
}
901
819
902
820
Expression ParseRealLiteral ( )
@@ -907,40 +825,7 @@ Expression ParseRealLiteral()
907
825
908
826
_textParser . NextToken ( ) ;
909
827
910
- return ParseRealLiteral ( text , text [ text . Length - 1 ] , true ) ;
911
- }
912
-
913
- Expression ParseRealLiteral ( string text , char qualifier , bool stripQualifier )
914
- {
915
- object o ;
916
- switch ( qualifier )
917
- {
918
- case 'f' :
919
- case 'F' :
920
- o = _numberParser . ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( float ) ) ;
921
- break ;
922
-
923
- case 'm' :
924
- case 'M' :
925
- o = _numberParser . ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( decimal ) ) ;
926
- break ;
927
-
928
- case 'd' :
929
- case 'D' :
930
- o = _numberParser . ParseNumber ( stripQualifier ? text . Substring ( 0 , text . Length - 1 ) : text , typeof ( double ) ) ;
931
- break ;
932
-
933
- default :
934
- o = _numberParser . ParseNumber ( text , typeof ( double ) ) ;
935
- break ;
936
- }
937
-
938
- if ( o != null )
939
- {
940
- return ConstantExpressionHelper . CreateLiteral ( o , text ) ;
941
- }
942
-
943
- throw ParseError ( Res . InvalidRealLiteral , text ) ;
828
+ return _numberParser . ParseRealLiteral ( text , text [ text . Length - 1 ] , true ) ;
944
829
}
945
830
946
831
Expression ParseParenExpression ( )
0 commit comments