mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Support comma in brackets and braces in preprocessor args
This commit is contained in:
parent
067f1a854e
commit
4ba33f03a0
@ -510,10 +510,10 @@ void DefinesStreamProxy::ContinueMacroParameters(const ParserLine& line, unsigne
|
||||
m_macro_parameter_state = ParameterState::AFTER_COMMA;
|
||||
}
|
||||
}
|
||||
else if (c == '(')
|
||||
else if (c == '(' || c == '[' || c == '{')
|
||||
{
|
||||
m_macro_parameter_state = ParameterState::AFTER_PARAM;
|
||||
m_macro_bracket_depth.push('(');
|
||||
m_macro_bracket_depth.push(c);
|
||||
m_current_macro_parameter << c;
|
||||
}
|
||||
else if (c == ')')
|
||||
@ -523,8 +523,8 @@ void DefinesStreamProxy::ContinueMacroParameters(const ParserLine& line, unsigne
|
||||
if (m_macro_bracket_depth.top() != '(')
|
||||
throw ParsingException(CreatePos(line, pos), "Unbalanced brackets in macro parameters");
|
||||
|
||||
m_macro_parameter_state = ParameterState::AFTER_PARAM;
|
||||
m_macro_bracket_depth.pop();
|
||||
m_macro_parameter_state = ParameterState::AFTER_PARAM;
|
||||
m_current_macro_parameter << c;
|
||||
}
|
||||
else if (m_macro_parameter_state == ParameterState::AFTER_COMMA)
|
||||
@ -537,6 +537,19 @@ void DefinesStreamProxy::ContinueMacroParameters(const ParserLine& line, unsigne
|
||||
m_macro_parameter_state = ParameterState::NOT_IN_PARAMETERS;
|
||||
}
|
||||
}
|
||||
else if (c == ']' || c == '}')
|
||||
{
|
||||
if (!m_macro_bracket_depth.empty())
|
||||
{
|
||||
const auto otherBracket = c == ']' ? '[' : '{';
|
||||
if (m_macro_bracket_depth.top() != otherBracket)
|
||||
throw ParsingException(CreatePos(line, pos), "Unbalanced brackets in macro parameters");
|
||||
m_macro_bracket_depth.pop();
|
||||
}
|
||||
|
||||
m_macro_parameter_state = ParameterState::AFTER_PARAM;
|
||||
m_current_macro_parameter << c;
|
||||
}
|
||||
else if (m_macro_parameter_state == ParameterState::AFTER_PARAM || !isspace(c))
|
||||
{
|
||||
m_macro_parameter_state = ParameterState::AFTER_PARAM;
|
||||
|
@ -729,6 +729,44 @@ namespace test::parsing::impl::defines_stream_proxy
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Ensure throws error on unclosed parenthesis in params", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
"#define someStuff(param1) Hello param1 World",
|
||||
"someStuff(A sentence with [brackets and a , character and stuff)",
|
||||
"someStuff(A sentence with {braces and a , character and stuff)",
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
DefinesStreamProxy proxy(&mockStream);
|
||||
|
||||
ExpectLine(&proxy, 1, "");
|
||||
ExpectErrorInLine(&proxy, 2, 64);
|
||||
ExpectErrorInLine(&proxy, 3, 62);
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Ensure throws error on parenthesis in params closed with wrong equivalent", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
"#define someStuff(param1) Hello param1 World",
|
||||
"someStuff(A sentence with (parenthesis and a , character] and stuff)",
|
||||
"someStuff(A sentence with [brackets and a , character} and stuff)",
|
||||
"someStuff(A sentence with {braces and a , character) and stuff)",
|
||||
};
|
||||
|
||||
MockParserLineStream mockStream(lines);
|
||||
DefinesStreamProxy proxy(&mockStream);
|
||||
|
||||
ExpectLine(&proxy, 1, "");
|
||||
ExpectErrorInLine(&proxy, 2, 57);
|
||||
ExpectErrorInLine(&proxy, 3, 54);
|
||||
ExpectErrorInLine(&proxy, 4, 52);
|
||||
|
||||
REQUIRE(proxy.Eof());
|
||||
}
|
||||
|
||||
TEST_CASE("DefinesStreamProxy: Ensure defines can go over multiple lines", "[parsing][parsingstream]")
|
||||
{
|
||||
const std::vector<std::string> lines{
|
||||
|
Loading…
x
Reference in New Issue
Block a user