Skip to content

Commit

Permalink
dynamic: fix dynamic variables being blocked by flag keywords
Browse files Browse the repository at this point in the history
fixes #45
  • Loading branch information
vaxerski committed May 15, 2024
1 parent 0736782 commit 969cb07
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
if (!h.options.allowFlags && h.name != LHS)
continue;

if (h.options.allowFlags && !LHS.starts_with(h.name))
if (h.options.allowFlags && (!LHS.starts_with(h.name) || LHS.contains(':') /* avoid cases where a category is called the same as a handler */))
continue;

ret = h.func(LHS.c_str(), RHS.c_str());
Expand Down
2 changes: 1 addition & 1 deletion src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CConfigImpl {

Hyprlang::SConfigOptions configOptions;

void parseComment(const std::string& comment);
void parseComment(const std::string& comment);

struct {
bool noError = false;
Expand Down
4 changes: 4 additions & 0 deletions tests/config/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ specialAnonymous {
value = 3
}

flagsStuff {
value = 2
}

testCategory:testValueHex = 0xFFfFaAbB

$RECURSIVE1 = a
Expand Down
3 changes: 3 additions & 0 deletions tests/parse/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ int main(int argc, char** argv, char** envp) {
config.addConfigValue("testCategory:testColor1", (Hyprlang::INT)0);
config.addConfigValue("testCategory:testColor2", (Hyprlang::INT)0);
config.addConfigValue("testCategory:testColor3", (Hyprlang::INT)0);
config.addConfigValue("flagsStuff:value", (Hyprlang::INT)0);
config.addConfigValue("myColors:pink", (Hyprlang::INT)0);
config.addConfigValue("myColors:green", (Hyprlang::INT)0);
config.addConfigValue("myColors:random", (Hyprlang::INT)0);
Expand Down Expand Up @@ -170,6 +171,8 @@ int main(int argc, char** argv, char** envp) {
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testCategory:testValueHex")), (Hyprlang::INT)0xAABBCCDD);
EXPECT(config.parseDynamic("testStringColon", "1:3:3:7").error, false);
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringColon")), std::string{"1:3:3:7"});
EXPECT(config.parseDynamic("flagsStuff:value = 69").error, false);
EXPECT(std::any_cast<int64_t>(config.getConfigValue("flagsStuff:value")), (Hyprlang::INT)69);

// test dynamic special
config.addSpecialConfigValue("specialGeneric:one", "boom", (Hyprlang::INT)0);
Expand Down

0 comments on commit 969cb07

Please sign in to comment.