Refactor peeking at macro args to be like peeking at interpolations

This commit is contained in:
Rangi42
2025-07-20 11:21:44 -04:00
parent 68ffb01cac
commit 0eed237517

View File

@@ -816,22 +816,12 @@ static int peek() {
return c; return c;
} }
// If character is a macro arg char, do macro arg expansion
shiftChar(); shiftChar();
if (std::shared_ptr<std::string> str = readMacroArg(); str) {
std::shared_ptr<std::string> str = readMacroArg(); beginExpansion(str, std::nullopt);
// If the macro arg is invalid or an empty string, it cannot be expanded,
// so skip it and keep peeking.
if (!str || str->empty()) {
return peek(); // Tail recursion
} }
return peek(); // Tail recursion
beginExpansion(str, std::nullopt);
// Assuming macro args can't be recursive (I'll be damned if a way
// is found...), then we mark the entire macro arg as scanned.
lexerState->macroArgScanDistance += str->length();
return str->front();
} else if (c == '{' && !lexerState->disableInterpolation) { } else if (c == '{' && !lexerState->disableInterpolation) {
// If character is an open brace, do symbol interpolation // If character is an open brace, do symbol interpolation
shiftChar(); shiftChar();