parser: change expression syntax to avoid bash clashes

changes from $() to {{}} to avoid clashing with bash syntax
This commit is contained in:
Vaxry 2025-05-07 23:03:03 +01:00
parent a15e7ba78a
commit a59e86a3da
No known key found for this signature in database
GPG key ID: 665806380871D640
3 changed files with 7 additions and 7 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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