mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-12-22 01:49:49 +01:00
parent
a685493fdb
commit
a2f3942114
3 changed files with 15 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -67,6 +67,10 @@ specialAnonymous {
|
|||
|
||||
testCategory:testValueHex = 0xFFfFaAbB
|
||||
|
||||
$RECURSIVE1 = a
|
||||
$RECURSIVE2 = $RECURSIVE1b
|
||||
testStringRecursive = $RECURSIVE2c
|
||||
|
||||
testStringQuotes = "Hello World!"
|
||||
#testDefault = 123
|
||||
|
||||
|
|
|
@ -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<int64_t>(config.getConfigValue("testVar")), 13371337);
|
||||
EXPECT(std::any_cast<const char*>(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<int64_t>(config.getConfigValue("testVar")), 1337420);
|
||||
|
||||
EXPECT(config.parseDynamic("$RECURSIVE1 = d").error, false);
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringRecursive")), std::string{"dbc"});
|
||||
|
||||
// test env variables
|
||||
std::cout << " → Testing env variables\n";
|
||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testEnv")), std::string{getenv("SHELL")});
|
||||
|
|
Loading…
Reference in a new issue