@@ -48,37 +48,41 @@ class IntegerLiteral extends NumericLiteral, TIntegerLiteral {
4848}
4949
5050private int parseInteger ( Ruby:: Integer i ) {
51- exists ( string s , string values , string str |
52- s = i .getValue ( ) .toLowerCase ( ) and
53- (
51+ exists ( string s | s = i .getValue ( ) .toLowerCase ( ) .replaceAll ( "_" , "" ) |
52+ s .charAt ( 0 ) != "0" and
53+ result = s .toInt ( )
54+ or
55+ exists ( string str , string values , int shift |
5456 s .matches ( "0b%" ) and
5557 values = "01" and
56- str = s .suffix ( 2 )
58+ str = s .suffix ( 2 ) and
59+ shift = 1
5760 or
5861 s .matches ( "0x%" ) and
5962 values = "0123456789abcdef" and
60- str = s .suffix ( 2 )
63+ str = s .suffix ( 2 ) and
64+ shift = 4
6165 or
6266 s .charAt ( 0 ) = "0" and
6367 not s .charAt ( 1 ) = [ "b" , "x" , "o" ] and
6468 values = "01234567" and
65- str = s .suffix ( 1 )
69+ str = s .suffix ( 1 ) and
70+ shift = 3
6671 or
6772 s .matches ( "0o%" ) and
6873 values = "01234567" and
69- str = s .suffix ( 2 )
70- or
71- s .charAt ( 0 ) != "0" and values = "0123456789" and str = s
74+ str = s .suffix ( 2 ) and
75+ shift = 3
76+ |
77+ result =
78+ sum ( int index , string c , int v , int exp |
79+ c = str .charAt ( index ) and
80+ v = values .indexOf ( c .toLowerCase ( ) ) and
81+ exp = str .length ( ) - index - 1
82+ |
83+ v .bitShiftLeft ( ( str .length ( ) - index - 1 ) * shift )
84+ )
7285 )
73- |
74- result =
75- sum ( int index , string c , int v , int exp |
76- c = str .replaceAll ( "_" , "" ) .charAt ( index ) and
77- v = values .indexOf ( c .toLowerCase ( ) ) and
78- exp = str .replaceAll ( "_" , "" ) .length ( ) - index - 1
79- |
80- v * values .length ( ) .pow ( exp ) .floor ( )
81- )
8286 )
8387}
8488
0 commit comments