core: fix negating of ifs

This commit is contained in:
Vaxry 2025-07-25 21:24:08 +02:00
parent 235ce61cba
commit 13865735fe
Signed by: vaxry
GPG key ID: 665806380871D640
2 changed files with 11 additions and 7 deletions

View file

@ -535,11 +535,6 @@ std::optional<std::string> CConfigImpl::parseComment(const std::string& comment)
break; break;
} }
if (args[i] == "!") {
negated = true;
continue;
}
if (args[i] == "endif") { if (args[i] == "endif") {
if (!currentFlags.inAnIfBlock) if (!currentFlags.inAnIfBlock)
return "stray endif"; return "stray endif";
@ -557,12 +552,17 @@ std::optional<std::string> CConfigImpl::parseComment(const std::string& comment)
if (currentFlags.inAnIfBlock) if (currentFlags.inAnIfBlock)
return "nested if statements are not allowed"; return "nested if statements are not allowed";
if (ifBlockVariable.starts_with("!")) {
negated = true;
ifBlockVariable = ifBlockVariable.substr(1);
}
currentFlags.inAnIfBlock = true; currentFlags.inAnIfBlock = true;
if (const auto VAR = getVariable(ifBlockVariable); VAR) if (const auto VAR = getVariable(ifBlockVariable); VAR)
currentFlags.ifBlockFailed = !VAR->truthy(); currentFlags.ifBlockFailed = negated ? VAR->truthy() : !VAR->truthy();
else else
currentFlags.ifBlockFailed = true; currentFlags.ifBlockFailed = !negated;
} }
return std::nullopt; return std::nullopt;

View file

@ -37,8 +37,12 @@ source = ./colors.conf
customType = abc customType = abc
# hyprlang if ! NONEXISTENT_VAR
testStringColon = ee:ee:ee testStringColon = ee:ee:ee
# hyprlang endif
# hyprlang noerror true # hyprlang noerror true
errorVariable = true errorVariable = true