Trim left space from macro args, even past block comments (#1831)

This commit is contained in:
Rangi
2025-09-19 13:44:18 -04:00
committed by GitHub
parent e0a6199f83
commit 67741ab428
3 changed files with 6 additions and 25 deletions

View File

@@ -1950,24 +1950,6 @@ static Token yylex_RAW() {
size_t parenDepth = 0; size_t parenDepth = 0;
int c; int c;
// Trim left spaces (stops at a block comment)
for (;;) {
c = peek();
if (isBlankSpace(c)) {
shiftChar();
} else if (c == '\\') {
c = nextChar();
// If not a line continuation, handle as a normal char
if (!isWhitespace(c)) {
goto backslash;
}
// Line continuations count as "space"
discardLineContinuation();
} else {
break;
}
}
for (;;) { for (;;) {
c = peek(); c = peek();
@@ -2029,7 +2011,6 @@ static Token yylex_RAW() {
case '\\': // Character escape case '\\': // Character escape
c = nextChar(); c = nextChar();
backslash:
switch (c) { switch (c) {
case ',': // Escapes only valid inside a macro arg case ',': // Escapes only valid inside a macro arg
case '(': case '(':
@@ -2084,9 +2065,9 @@ append:
} }
finish: // Can't `break` out of a nested `for`-`switch` finish: // Can't `break` out of a nested `for`-`switch`
// Trim right blank space // Trim left and right blank space
auto rightPos = std::find_if_not(str.rbegin(), str.rend(), isBlankSpace); str.erase(str.begin(), std::find_if_not(RANGE(str), isBlankSpace));
str.resize(rightPos.base() - str.begin()); str.erase(std::find_if_not(str.rbegin(), str.rend(), isBlankSpace).base(), str.end());
// Returning COMMAs to the parser would mean that two consecutive commas // Returning COMMAs to the parser would mean that two consecutive commas
// (i.e. an empty argument) need to return two different tokens (STRING // (i.e. an empty argument) need to return two different tokens (STRING

View File

@@ -1,7 +1,7 @@
'mac ': 'mac ':
'mac 1,2': 'mac 1,2':
\1: < 1> \1: <1>
\2: <2> \2: <2>
'mac c,d': 'mac c,d':

View File

@@ -5,5 +5,5 @@
2: "b" 2: "b"
1: "c" 1: "c"
3: "a" 3: "a"
2: " b" 2: "b"
1: "c" 1: "c"