Skip to content

Commit 05e5e96

Browse files
committed
Adopt IntegerNode base flags (binary, octal etc)
1 parent b8977c6 commit 05e5e96

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/main/java/org/truffleruby/parser/YARPTranslator.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,25 +1043,20 @@ public RubyNode visitIntegerNode(Nodes.IntegerNode node) {
10431043
final int radix;
10441044
final int offset;
10451045

1046-
if (string.startsWith("0b") || string.startsWith("0B")) {
1046+
if (node.isBinary()) {
10471047
radix = 2;
10481048
offset = 2;
1049-
} else if (string.startsWith("0x") || string.startsWith("0X")) {
1049+
} else if (node.isHexadecimal()) {
10501050
radix = 16;
10511051
offset = 2;
1052-
} else if (string.startsWith("0d") || string.startsWith("0D")) {
1052+
} else if (node.isDecimal()) {
10531053
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()) {
10601056
radix = 8;
1061-
offset = 1;
1057+
offset = (string.startsWith("0o") || string.startsWith("0O")) ? 2 : 1; // 0oXX, 0OXX, 0XX
10621058
} else {
1063-
radix = 10;
1064-
offset = 0;
1059+
throw CompilerDirectives.shouldNotReachHere();
10651060
}
10661061

10671062
final long value = Long.parseLong(string.substring(offset), radix);

0 commit comments

Comments
 (0)