Skip to content

Commit 75a901b

Browse files
committed
Fix breakout level literal parsing
1 parent 754db66 commit 75a901b

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/DiagnosticsProvider.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,19 @@ public static function checkDiagnostics($node) {
9494
$breakoutLevel = $breakoutLevel->expression;
9595
}
9696

97-
if ($breakoutLevel instanceof Node\Expression\NumericLiteral) {
97+
if (
98+
$breakoutLevel instanceof Node\NumericLiteral
99+
&& $breakoutLevel->children->kind === TokenKind::IntegerLiteralToken
100+
) {
98101
$literalString = $breakoutLevel->getText();
99-
if (
100-
$breakoutLevel->children->kind === TokenKind::BinaryLiteralToken
101-
&& \bindec(\substr($literalString, 2)) > 0
102-
) {
103-
return null;
102+
$firstTwoChars = \substr($literalString, 0, 2);
103+
104+
if ($firstTwoChars === '0b' || $firstTwoChars === '0B') {
105+
if (\bindec(\substr($literalString, 2)) > 0) {
106+
return null;
107+
}
104108
}
105-
else if (
106-
\in_array($breakoutLevel->children->kind, [
107-
TokenKind::DecimalLiteralToken,
108-
TokenKind::HexadecimalLiteralToken,
109-
TokenKind::OctalLiteralToken,
110-
TokenKind::IntegerLiteralToken
111-
])
112-
&& \intval($literalString, 0) > 0
113-
) {
109+
else if (\intval($literalString, 0) > 0) {
114110
return null;
115111
}
116112
}
@@ -125,7 +121,7 @@ public static function checkDiagnostics($node) {
125121

126122
return new Diagnostic(
127123
DiagnosticKind::Error,
128-
"Expected positive integer literal.",
124+
"Positive integer literal expected.",
129125
$start,
130126
$end - $start
131127
);

0 commit comments

Comments
 (0)