fix(parser): allow space before function macro arguments (#933)

This commit is contained in:
mo
2026-07-26 22:38:11 +02:00
committed by GitHub
parent 0c66d1838e
commit 8686b42120
2 changed files with 24 additions and 2 deletions
@@ -541,10 +541,14 @@ bool DefinesStreamProxy::FindMacroForIdentifier(const std::string& input,
void DefinesStreamProxy::ExtractParametersFromMacroUsage( void DefinesStreamProxy::ExtractParametersFromMacroUsage(
const ParserLine& line, const unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos) const ParserLine& line, const unsigned& linePos, MacroParameterState& state, const std::string& input, unsigned& inputPos)
{ {
if (input[inputPos] != '(') auto parameterStart = inputPos;
while (parameterStart < input.size() && isspace(input[parameterStart]))
parameterStart++;
if (parameterStart >= input.size() || input[parameterStart] != '(')
return; return;
inputPos++; inputPos = parameterStart + 1u;
state.m_parameter_state = ParameterState::AFTER_OPEN; state.m_parameter_state = ParameterState::AFTER_OPEN;
state.m_parameters = std::vector<std::string>(); state.m_parameters = std::vector<std::string>();
state.m_current_parameter.clear(); state.m_current_parameter.clear();
@@ -839,6 +839,24 @@ namespace test::parsing::impl::defines_stream_proxy
REQUIRE(proxy.Eof()); REQUIRE(proxy.Eof());
} }
TEST_CASE("DefinesStreamProxy: Function macro call can have space before arguments", "[parsing][parsingstream]")
{
const std::vector<std::string> lines{
"#define CHOICE_X(itemIndex) itemIndex",
"CHOICE_X(2)",
"CHOICE_X (2)",
};
MockParserLineStream mockStream(lines);
DefinesStreamProxy proxy(&mockStream);
ExpectLine(&proxy, 1, "");
ExpectLine(&proxy, 2, "2");
ExpectLine(&proxy, 3, "2");
REQUIRE(proxy.Eof());
}
TEST_CASE("DefinesStreamProxy: Macro definition that has unclosed parameters throws an error", "[parsing][parsingstream]") TEST_CASE("DefinesStreamProxy: Macro definition that has unclosed parameters throws an error", "[parsing][parsingstream]")
{ {
const std::vector<std::string> lines{ const std::vector<std::string> lines{