mirror of
https://github.com/hyprwm/hyprlang.git
synced 2025-12-20 12:00:03 +01:00
core: fix negating of ifs
This commit is contained in:
parent
235ce61cba
commit
13865735fe
2 changed files with 11 additions and 7 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue