mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
cmGeneratorExpression: Fix parser for adjacent colon and comma
Update ParseGeneratorExpression to allow correct parsing of adjacent colon and comma separators in either order. Fixes: #27324
This commit is contained in:
@@ -115,31 +115,9 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
|
||||
emptyParamTermination = true;
|
||||
}
|
||||
|
||||
while (this->it != this->Tokens.end() &&
|
||||
this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator) {
|
||||
commaTokens.push_back(this->it);
|
||||
parameters.resize(parameters.size() + 1);
|
||||
assert(this->it != this->Tokens.end());
|
||||
++this->it;
|
||||
if (this->it == this->Tokens.end()) {
|
||||
emptyParamTermination = true;
|
||||
}
|
||||
}
|
||||
while (this->it != this->Tokens.end() &&
|
||||
this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator) {
|
||||
extendText(*(parameters.end() - 1), this->it);
|
||||
assert(this->it != this->Tokens.end());
|
||||
++this->it;
|
||||
}
|
||||
while (this->it != this->Tokens.end() &&
|
||||
this->it->TokenType != cmGeneratorExpressionToken::EndExpression) {
|
||||
this->ParseContent(*(parameters.end() - 1));
|
||||
if (this->it == this->Tokens.end()) {
|
||||
break;
|
||||
}
|
||||
while (this->it != this->Tokens.end() &&
|
||||
this->it->TokenType ==
|
||||
cmGeneratorExpressionToken::CommaSeparator) {
|
||||
auto handleCommaOrColon = [this, &commaTokens, ¶meters,
|
||||
&emptyParamTermination]() -> void {
|
||||
if (this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator) {
|
||||
commaTokens.push_back(this->it);
|
||||
parameters.resize(parameters.size() + 1);
|
||||
assert(this->it != this->Tokens.end());
|
||||
@@ -147,14 +125,32 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
|
||||
if (this->it == this->Tokens.end()) {
|
||||
emptyParamTermination = true;
|
||||
}
|
||||
}
|
||||
while (this->it != this->Tokens.end() &&
|
||||
this->it->TokenType ==
|
||||
cmGeneratorExpressionToken::ColonSeparator) {
|
||||
} else if (this->it->TokenType ==
|
||||
cmGeneratorExpressionToken::ColonSeparator) {
|
||||
extendText(*(parameters.end() - 1), this->it);
|
||||
assert(this->it != this->Tokens.end());
|
||||
++this->it;
|
||||
}
|
||||
};
|
||||
|
||||
while (
|
||||
this->it != this->Tokens.end() &&
|
||||
(this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator ||
|
||||
this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator)) {
|
||||
handleCommaOrColon();
|
||||
}
|
||||
while (this->it != this->Tokens.end() &&
|
||||
this->it->TokenType != cmGeneratorExpressionToken::EndExpression) {
|
||||
this->ParseContent(*(parameters.end() - 1));
|
||||
if (this->it == this->Tokens.end()) {
|
||||
break;
|
||||
}
|
||||
while (
|
||||
this->it != this->Tokens.end() &&
|
||||
(this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator ||
|
||||
this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator)) {
|
||||
handleCommaOrColon();
|
||||
}
|
||||
}
|
||||
if (this->it != this->Tokens.end() &&
|
||||
this->it->TokenType == cmGeneratorExpressionToken::EndExpression) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
file(READ "${RunCMake_TEST_BINARY_DIR}/LIST-edgecases.txt" content)
|
||||
|
||||
set(expected "a;b;c:;d\na;b;c;:d")
|
||||
if(NOT content STREQUAL expected)
|
||||
set(RunCMake_TEST_FAILED "actual content:\n [[${content}]]\nbut expected:\n [[${expected}]]")
|
||||
endif()
|
||||
3
Tests/RunCMake/GeneratorExpression/LIST-edgecases.cmake
Normal file
3
Tests/RunCMake/GeneratorExpression/LIST-edgecases.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
set(ls1 "$<LIST:APPEND,a,b,c:,d>")
|
||||
set(ls2 "$<LIST:APPEND,a,b,c,:d>")
|
||||
file(GENERATE OUTPUT LIST-edgecases.txt CONTENT ${ls1}\n${ls2})
|
||||
@@ -56,6 +56,7 @@ run_cmake(FILTER-empty)
|
||||
run_cmake(FILTER-InvalidOperator)
|
||||
run_cmake(FILTER-Exclude)
|
||||
run_cmake(FILTER-Include)
|
||||
run_cmake(LIST-edgecases)
|
||||
|
||||
function(run_cmake_build test)
|
||||
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
|
||||
|
||||
Reference in New Issue
Block a user