diff --git a/src/config.cpp b/src/config.cpp index 560fd8f..f2a2fc7 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -536,9 +536,9 @@ std::optional CConfigImpl::parseComment(const std::string& comment) } if (args[i] == "endif") { - if (!currentFlags.inAnIfBlock) + if (currentFlags.ifDatas.empty()) return "stray endif"; - currentFlags.inAnIfBlock = false; + currentFlags.ifDatas.pop_back(); break; } @@ -549,20 +549,19 @@ std::optional CConfigImpl::parseComment(const std::string& comment) } if (!ifBlockVariable.empty()) { - if (currentFlags.inAnIfBlock) - return "nested if statements are not allowed"; - if (ifBlockVariable.starts_with("!")) { negated = true; ifBlockVariable = ifBlockVariable.substr(1); } - currentFlags.inAnIfBlock = true; + CConfigImpl::SIfBlockData newIfData; if (const auto VAR = getVariable(ifBlockVariable); VAR) - currentFlags.ifBlockFailed = negated ? VAR->truthy() : !VAR->truthy(); + newIfData.failed = negated ? VAR->truthy() : !VAR->truthy(); else - currentFlags.ifBlockFailed = !negated; + newIfData.failed = !negated; + + currentFlags.ifDatas.emplace_back(newIfData); } return std::nullopt; @@ -632,7 +631,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) { return result; } - if (impl->currentFlags.inAnIfBlock && impl->currentFlags.ifBlockFailed) + if (!impl->currentFlags.ifDatas.empty() && impl->currentFlags.ifDatas.back().failed) return result; size_t lastHashPos = 0; diff --git a/src/config.hpp b/src/config.hpp index 63d9840..d68482c 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -103,9 +103,13 @@ class CConfigImpl { std::expected parseExpression(const std::string& s); SVariable* getVariable(const std::string& name); + struct SIfBlockData { + bool failed = false; + }; + struct { - bool noError = false; - bool inAnIfBlock = false; - bool ifBlockFailed = false; + bool noError = false; + + std::vector ifDatas; } currentFlags; }; diff --git a/tests/config/config.conf b/tests/config/config.conf index e3c372f..54e71bf 100644 --- a/tests/config/config.conf +++ b/tests/config/config.conf @@ -39,10 +39,20 @@ customType = abc # hyprlang if !NONEXISTENT_VAR +# hyprlang if !NONEXISTENT_VAR_2 + testStringColon = ee:ee:ee # hyprlang endif +# hyprlang if NONEXISTENT_VAR + +testStringColon = ee:ee:ee:22 + +# hyprlang endif + +# hyprlang endif + # hyprlang noerror true errorVariable = true