diff --git a/src/config.cpp b/src/config.cpp index bfdffc1..dd4a0ce 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -519,14 +519,14 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) { return result; } - if (*LHS.begin() == '$') - return parseVariable(LHS, RHS, dynamic); + const bool ISVARIABLE = *LHS.begin() == '$'; // limit unwrapping iterations to 100. if exceeds, raise error for (size_t i = 0; i < 100; ++i) { bool anyMatch = false; for (auto& var : impl->variables) { - const auto LHSIT = LHS.find("$" + var.name); + // don't parse LHS variables if this is a variable... + const auto LHSIT = ISVARIABLE ? std::string::npos : LHS.find("$" + var.name); const auto RHSIT = RHS.find("$" + var.name); if (LHSIT != std::string::npos) @@ -551,6 +551,9 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) { } } + if (ISVARIABLE) + return parseVariable(LHS, RHS, dynamic); + bool found = false; for (auto& h : impl->handlers) { if (!h.options.allowFlags && h.name != LHS) diff --git a/tests/config/config.conf b/tests/config/config.conf index e0f564f..f08b8b7 100644 --- a/tests/config/config.conf +++ b/tests/config/config.conf @@ -67,6 +67,10 @@ specialAnonymous { testCategory:testValueHex = 0xFFfFaAbB +$RECURSIVE1 = a +$RECURSIVE2 = $RECURSIVE1b +testStringRecursive = $RECURSIVE2c + testStringQuotes = "Hello World!" #testDefault = 123 diff --git a/tests/parse/main.cpp b/tests/parse/main.cpp index ef7524f..ae2c4f8 100644 --- a/tests/parse/main.cpp +++ b/tests/parse/main.cpp @@ -89,6 +89,7 @@ int main(int argc, char** argv, char** envp) { config.addConfigValue("testEnv", ""); config.addConfigValue("testVar", (Hyprlang::INT)0); config.addConfigValue("testStringQuotes", ""); + config.addConfigValue("testStringRecursive", ""); config.addConfigValue("testCategory:testValueInt", (Hyprlang::INT)0); config.addConfigValue("testCategory:testValueHex", (Hyprlang::INT)0xA); config.addConfigValue("testCategory:nested1:testValueNest", (Hyprlang::INT)0); @@ -178,12 +179,16 @@ int main(int argc, char** argv, char** envp) { // test variables std::cout << " → Testing variables\n"; EXPECT(std::any_cast(config.getConfigValue("testVar")), 13371337); + EXPECT(std::any_cast(config.getConfigValue("testStringRecursive")), std::string{"abc"}); // test dynamic variables std::cout << " → Testing dynamic variables\n"; EXPECT(config.parseDynamic("$MY_VAR_2 = 420").error, false); EXPECT(std::any_cast(config.getConfigValue("testVar")), 1337420); + EXPECT(config.parseDynamic("$RECURSIVE1 = d").error, false); + EXPECT(std::any_cast(config.getConfigValue("testStringRecursive")), std::string{"dbc"}); + // test env variables std::cout << " → Testing env variables\n"; EXPECT(std::any_cast(config.getConfigValue("testEnv")), std::string{getenv("SHELL")});