mirror of
https://github.com/hyprwm/hyprlang.git
synced 2024-11-16 18:25:57 +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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*LHS.begin() == '$')
|
const bool ISVARIABLE = *LHS.begin() == '$';
|
||||||
return parseVariable(LHS, RHS, dynamic);
|
|
||||||
|
|
||||||
// limit unwrapping iterations to 100. if exceeds, raise error
|
// limit unwrapping iterations to 100. if exceeds, raise error
|
||||||
for (size_t i = 0; i < 100; ++i) {
|
for (size_t i = 0; i < 100; ++i) {
|
||||||
bool anyMatch = false;
|
bool anyMatch = false;
|
||||||
for (auto& var : impl->variables) {
|
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);
|
const auto RHSIT = RHS.find("$" + var.name);
|
||||||
|
|
||||||
if (LHSIT != std::string::npos)
|
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;
|
bool found = false;
|
||||||
for (auto& h : impl->handlers) {
|
for (auto& h : impl->handlers) {
|
||||||
if (!h.options.allowFlags && h.name != LHS)
|
if (!h.options.allowFlags && h.name != LHS)
|
||||||
|
|
|
@ -67,6 +67,10 @@ specialAnonymous {
|
||||||
|
|
||||||
testCategory:testValueHex = 0xFFfFaAbB
|
testCategory:testValueHex = 0xFFfFaAbB
|
||||||
|
|
||||||
|
$RECURSIVE1 = a
|
||||||
|
$RECURSIVE2 = $RECURSIVE1b
|
||||||
|
testStringRecursive = $RECURSIVE2c
|
||||||
|
|
||||||
testStringQuotes = "Hello World!"
|
testStringQuotes = "Hello World!"
|
||||||
#testDefault = 123
|
#testDefault = 123
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,7 @@ int main(int argc, char** argv, char** envp) {
|
||||||
config.addConfigValue("testEnv", "");
|
config.addConfigValue("testEnv", "");
|
||||||
config.addConfigValue("testVar", (Hyprlang::INT)0);
|
config.addConfigValue("testVar", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("testStringQuotes", "");
|
config.addConfigValue("testStringQuotes", "");
|
||||||
|
config.addConfigValue("testStringRecursive", "");
|
||||||
config.addConfigValue("testCategory:testValueInt", (Hyprlang::INT)0);
|
config.addConfigValue("testCategory:testValueInt", (Hyprlang::INT)0);
|
||||||
config.addConfigValue("testCategory:testValueHex", (Hyprlang::INT)0xA);
|
config.addConfigValue("testCategory:testValueHex", (Hyprlang::INT)0xA);
|
||||||
config.addConfigValue("testCategory:nested1:testValueNest", (Hyprlang::INT)0);
|
config.addConfigValue("testCategory:nested1:testValueNest", (Hyprlang::INT)0);
|
||||||
|
@ -178,12 +179,16 @@ int main(int argc, char** argv, char** envp) {
|
||||||
// test variables
|
// test variables
|
||||||
std::cout << " → Testing variables\n";
|
std::cout << " → Testing variables\n";
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testVar")), 13371337);
|
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
|
// test dynamic variables
|
||||||
std::cout << " → Testing dynamic variables\n";
|
std::cout << " → Testing dynamic variables\n";
|
||||||
EXPECT(config.parseDynamic("$MY_VAR_2 = 420").error, false);
|
EXPECT(config.parseDynamic("$MY_VAR_2 = 420").error, false);
|
||||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testVar")), 1337420);
|
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
|
// test env variables
|
||||||
std::cout << " → Testing env variables\n";
|
std::cout << " → Testing env variables\n";
|
||||||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testEnv")), std::string{getenv("SHELL")});
|
EXPECT(std::any_cast<const char*>(config.getConfigValue("testEnv")), std::string{getenv("SHELL")});
|
||||||
|
|
Loading…
Reference in a new issue