mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Trim macro arg whitespace after line continuations
This commit is contained in:
@@ -2052,9 +2052,23 @@ static int yylex_RAW(void)
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
/* Trim left whitespace (stops at a block comment or line continuation) */
|
/* Trim left whitespace (stops at a block comment) */
|
||||||
while (isWhitespace(peek()))
|
for (;;) {
|
||||||
shiftChar();
|
c = peek();
|
||||||
|
if (isWhitespace(c)) {
|
||||||
|
shiftChar();
|
||||||
|
} else if (c == '\\') {
|
||||||
|
shiftChar();
|
||||||
|
c = peek();
|
||||||
|
// If not a line continuation, handle as a normal char
|
||||||
|
if (!isWhitespace(c) && c != '\n' && c != '\r')
|
||||||
|
goto backslash;
|
||||||
|
// Line continuations count as "whitespace"
|
||||||
|
readLineContinuation();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = peek();
|
c = peek();
|
||||||
@@ -2103,6 +2117,7 @@ static int yylex_RAW(void)
|
|||||||
shiftChar();
|
shiftChar();
|
||||||
c = peek();
|
c = peek();
|
||||||
|
|
||||||
|
backslash:
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case ',': /* Escapes only valid inside a macro arg */
|
case ',': /* Escapes only valid inside a macro arg */
|
||||||
case '(':
|
case '(':
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
\1: < 1>
|
\1: < 1>
|
||||||
\2: <2>
|
\2: <2>
|
||||||
|
|
||||||
'mac c,d':
|
'mac c,d':
|
||||||
\1: < c>
|
\1: <c>
|
||||||
\2: <d>
|
\2: <d>
|
||||||
|
|
||||||
'mac 1,2 + 2,3':
|
'mac 1,2 + 2,3':
|
||||||
|
|||||||
19
test/asm/trimmed-macro-args.asm
Normal file
19
test/asm/trimmed-macro-args.asm
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
MACRO print_all
|
||||||
|
REPT _NARG
|
||||||
|
PRINTLN "{d:_NARG}: \"\1\""
|
||||||
|
SHIFT
|
||||||
|
ENDR
|
||||||
|
ENDM
|
||||||
|
|
||||||
|
print_all a, \
|
||||||
|
b \
|
||||||
|
, c
|
||||||
|
|
||||||
|
DEF EMPTY equs ""
|
||||||
|
print_all a, \
|
||||||
|
{EMPTY} b \
|
||||||
|
{EMPTY}, c
|
||||||
|
|
||||||
|
print_all a, \
|
||||||
|
/* . */ b \
|
||||||
|
/* . */, c
|
||||||
0
test/asm/trimmed-macro-args.err
Normal file
0
test/asm/trimmed-macro-args.err
Normal file
9
test/asm/trimmed-macro-args.out
Normal file
9
test/asm/trimmed-macro-args.out
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
3: "a"
|
||||||
|
2: "b"
|
||||||
|
1: "c"
|
||||||
|
3: "a"
|
||||||
|
2: "b"
|
||||||
|
1: "c"
|
||||||
|
3: "a"
|
||||||
|
2: " b"
|
||||||
|
1: "c"
|
||||||
Reference in New Issue
Block a user