mirror of
https://github.com/hyprwm/hyprlang.git
synced 2025-05-12 13:20:36 +01:00
parser: change expression syntax to avoid bash clashes
changes from $() to {{}} to avoid clashing with bash syntax
This commit is contained in:
parent
a15e7ba78a
commit
a59e86a3da
3 changed files with 7 additions and 7 deletions
|
@ -644,9 +644,9 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
|||
|
||||
// parse expressions $(somevar + 2)
|
||||
// We only support single expressions for now
|
||||
while (RHS.contains("$(")) {
|
||||
const auto BEGIN_EXPR = RHS.find("$(");
|
||||
const auto END_EXPR = RHS.find(')', BEGIN_EXPR + 2);
|
||||
while (RHS.contains("{{")) {
|
||||
const auto BEGIN_EXPR = RHS.find("{{");
|
||||
const auto END_EXPR = RHS.find("}}", BEGIN_EXPR + 2);
|
||||
if (END_EXPR != std::string::npos) {
|
||||
// try to parse the expression
|
||||
const auto RESULT = impl->parseExpression(RHS.substr(BEGIN_EXPR + 2, END_EXPR - BEGIN_EXPR - 2));
|
||||
|
@ -655,7 +655,7 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
|||
return result;
|
||||
}
|
||||
|
||||
RHS = RHS.substr(0, BEGIN_EXPR) + std::format("{}", RESULT.value()) + RHS.substr(END_EXPR + 1);
|
||||
RHS = RHS.substr(0, BEGIN_EXPR) + std::format("{}", RESULT.value()) + RHS.substr(END_EXPR + 2);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ $MY_VAR = 1337
|
|||
$MY_VAR_2 = $MY_VAR
|
||||
testVar = $MY_VAR$MY_VAR_2
|
||||
|
||||
$EXPR_VAR = $(MY_VAR + 2)
|
||||
testExpr = $(EXPR_VAR - 4)
|
||||
$EXPR_VAR = {{MY_VAR + 2}}
|
||||
testExpr = {{EXPR_VAR - 4}}
|
||||
|
||||
testEnv = $SHELL
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
EXPECT(std::any_cast<const char*>(config.getConfigValue("testStringRecursive")), std::string{"dbc"});
|
||||
|
||||
// test dynamic exprs
|
||||
EXPECT(config.parseDynamic("testExpr = $(EXPR_VAR * 2)").error, false);
|
||||
EXPECT(config.parseDynamic("testExpr = {{EXPR_VAR * 2}}").error, false);
|
||||
EXPECT(std::any_cast<int64_t>(config.getConfigValue("testExpr")), 1339L * 2);
|
||||
|
||||
// test env variables
|
||||
|
|
Loading…
Reference in a new issue