File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed
src/main/java/org/truffleruby/parser Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -1043,25 +1043,20 @@ public RubyNode visitIntegerNode(Nodes.IntegerNode node) {
1043
1043
final int radix ;
1044
1044
final int offset ;
1045
1045
1046
- if (string . startsWith ( "0b" ) || string . startsWith ( "0B" )) {
1046
+ if (node . isBinary ( )) {
1047
1047
radix = 2 ;
1048
1048
offset = 2 ;
1049
- } else if (string . startsWith ( "0x" ) || string . startsWith ( "0X" )) {
1049
+ } else if (node . isHexadecimal ( )) {
1050
1050
radix = 16 ;
1051
1051
offset = 2 ;
1052
- } else if (string . startsWith ( "0d" ) || string . startsWith ( "0D" )) {
1052
+ } else if (node . isDecimal ( )) {
1053
1053
radix = 10 ;
1054
- offset = 2 ;
1055
- } else if (string .startsWith ("0o" ) || string .startsWith ("0O" )) {
1056
- radix = 8 ;
1057
- offset = 2 ;
1058
- } else if (string .startsWith ("0" ) && string .length () > 1 ) {
1059
- // check length to distinguish `0` from octal literal `0...`
1054
+ offset = (string .startsWith ("0d" ) || string .startsWith ("0D" )) ? 2 : 0 ;
1055
+ } else if (node .isOctal ()) {
1060
1056
radix = 8 ;
1061
- offset = 1 ;
1057
+ offset = ( string . startsWith ( "0o" ) || string . startsWith ( "0O" )) ? 2 : 1 ; // 0oXX, 0OXX, 0XX
1062
1058
} else {
1063
- radix = 10 ;
1064
- offset = 0 ;
1059
+ throw CompilerDirectives .shouldNotReachHere ();
1065
1060
}
1066
1061
1067
1062
final long value = Long .parseLong (string .substring (offset ), radix );
You can’t perform that action at this time.
0 commit comments