mirror of
https://github.com/gbdev/rgbds.git
synced 2026-05-08 19:09:36 +00:00
Fix some fixed-point literal lexing issues (#1914)
- No fractional digits are necessary after the decimal point, e.g. `42.` is valid instead of `42.0` - Error messages refer to "fixed-point" not "integer" constants - Test more carefully for lexing unrelated to underscores
This commit is contained in:
+8
-2
@@ -958,12 +958,17 @@ static uint32_t readFractionalPart(uint32_t integer) {
|
|||||||
READFRACTIONALPART_PRECISION,
|
READFRACTIONALPART_PRECISION,
|
||||||
READFRACTIONALPART_PRECISION_DIGITS,
|
READFRACTIONALPART_PRECISION_DIGITS,
|
||||||
} state = READFRACTIONALPART_DIGITS;
|
} state = READFRACTIONALPART_DIGITS;
|
||||||
bool nonDigit = true;
|
bool anyDigit = false;
|
||||||
|
bool nonDigit = false;
|
||||||
|
|
||||||
for (int c = peek();; c = nextChar()) {
|
for (int c = peek();; c = nextChar()) {
|
||||||
if (state == READFRACTIONALPART_DIGITS) {
|
if (state == READFRACTIONALPART_DIGITS) {
|
||||||
if (c == '_') {
|
if (c == '_') {
|
||||||
checkDigitSeparator(nonDigit);
|
if (nonDigit) {
|
||||||
|
error("Invalid fixed-point constant, '_' after another '_'");
|
||||||
|
} else if (!anyDigit) {
|
||||||
|
error("Invalid fixed-point constant, '_' after '.'");
|
||||||
|
}
|
||||||
nonDigit = true;
|
nonDigit = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -976,6 +981,7 @@ static uint32_t readFractionalPart(uint32_t integer) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
c -= '0';
|
c -= '0';
|
||||||
|
anyDigit = true;
|
||||||
nonDigit = false;
|
nonDigit = false;
|
||||||
|
|
||||||
if (divisor > (UINT32_MAX - c) / 10) {
|
if (divisor > (UINT32_MAX - c) / 10) {
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
; good
|
||||||
|
println 3.14
|
||||||
|
println 42.
|
||||||
|
println 12_34.56_78
|
||||||
|
println 12.34_q.5
|
||||||
|
println 1_2.3_4_q15
|
||||||
|
println 1.q2
|
||||||
|
|
||||||
|
; bad
|
||||||
|
println 12.34q0
|
||||||
|
println 12.34q_15
|
||||||
|
println 12.34q1_5
|
||||||
|
println 1_.2
|
||||||
|
println 1._2
|
||||||
|
println 1.2q
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
error: Invalid fixed-point constant, no significant digits after 'q'
|
||||||
|
at fixed-point-syntax.asm(10)
|
||||||
|
error: Invalid fixed-point constant, no significant digits after 'q'
|
||||||
|
at fixed-point-syntax.asm(11)
|
||||||
|
error: syntax error, unexpected symbol
|
||||||
|
at fixed-point-syntax.asm(11)
|
||||||
|
error: syntax error, unexpected symbol
|
||||||
|
at fixed-point-syntax.asm(12)
|
||||||
|
error: Invalid integer constant, trailing '_'
|
||||||
|
at fixed-point-syntax.asm(13)
|
||||||
|
error: Invalid fixed-point constant, '_' after '.'
|
||||||
|
at fixed-point-syntax.asm(14)
|
||||||
|
error: Invalid fixed-point constant, no significant digits after 'q'
|
||||||
|
at fixed-point-syntax.asm(15)
|
||||||
|
Assembly aborted with 7 errors
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
$323D7
|
||||||
|
$2A0000
|
||||||
|
$4D2915B
|
||||||
|
$18B
|
||||||
|
$62B85
|
||||||
|
$4
|
||||||
|
$C570A
|
||||||
|
$13333
|
||||||
|
$13333
|
||||||
|
$13333
|
||||||
@@ -30,3 +30,7 @@ println 123.456_
|
|||||||
; bad ('_' next to '.')
|
; bad ('_' next to '.')
|
||||||
println 1_.618
|
println 1_.618
|
||||||
println 2._718
|
println 2._718
|
||||||
|
|
||||||
|
; bad ('_' after 'q')
|
||||||
|
println 1q_2
|
||||||
|
println 1q2_3
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ error: Invalid integer constant, '_' after another '_'
|
|||||||
at invalid-underscore.asm(17)
|
at invalid-underscore.asm(17)
|
||||||
error: Invalid integer constant, '_' after another '_'
|
error: Invalid integer constant, '_' after another '_'
|
||||||
at invalid-underscore.asm(18)
|
at invalid-underscore.asm(18)
|
||||||
error: Invalid integer constant, '_' after another '_'
|
error: Invalid fixed-point constant, '_' after another '_'
|
||||||
at invalid-underscore.asm(19)
|
at invalid-underscore.asm(19)
|
||||||
error: Invalid integer constant, '_' after another '_'
|
error: Invalid fixed-point constant, '_' after another '_'
|
||||||
at invalid-underscore.asm(20)
|
at invalid-underscore.asm(20)
|
||||||
error: Invalid integer constant, trailing '_'
|
error: Invalid integer constant, trailing '_'
|
||||||
at invalid-underscore.asm(23)
|
at invalid-underscore.asm(23)
|
||||||
@@ -26,6 +26,10 @@ error: Invalid fixed-point constant, trailing '_'
|
|||||||
at invalid-underscore.asm(28)
|
at invalid-underscore.asm(28)
|
||||||
error: Invalid integer constant, trailing '_'
|
error: Invalid integer constant, trailing '_'
|
||||||
at invalid-underscore.asm(31)
|
at invalid-underscore.asm(31)
|
||||||
error: Invalid integer constant, '_' after another '_'
|
error: Invalid fixed-point constant, '_' after '.'
|
||||||
at invalid-underscore.asm(32)
|
at invalid-underscore.asm(32)
|
||||||
Assembly aborted with 15 errors
|
error: syntax error, unexpected symbol
|
||||||
|
at invalid-underscore.asm(35)
|
||||||
|
error: syntax error, unexpected symbol
|
||||||
|
at invalid-underscore.asm(36)
|
||||||
|
Assembly aborted with 17 errors
|
||||||
|
|||||||
Reference in New Issue
Block a user