mirror of
https://github.com/hyprwm/hyprlang.git
synced 2026-05-04 23:17:58 +02:00
Remove escaped chars, skip escaped {{ from expressions.
This commit is contained in:
parent
557241780c
commit
6cdd04cb86
1 changed files with 23 additions and 1 deletions
|
|
@ -645,7 +645,20 @@ 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("{{");
|
||||
auto firstUnescaped = RHS.find("{{");
|
||||
//keep searching until the escape char is not found.
|
||||
while(RHS.at(firstUnescaped - 1) == '\\'){
|
||||
firstUnescaped = RHS.find("{{", firstUnescaped + 1);
|
||||
//escape if the next match is never found
|
||||
if(firstUnescaped == std::string::npos)
|
||||
break;
|
||||
}
|
||||
//real match was never found.
|
||||
if(firstUnescaped == std::string::npos){
|
||||
break;
|
||||
}
|
||||
const auto BEGIN_EXPR = firstUnescaped;
|
||||
// }} doesnt need escaping. it would be valid if escaped anyways.
|
||||
const auto END_EXPR = RHS.find("}}", BEGIN_EXPR + 2);
|
||||
if (END_EXPR != std::string::npos) {
|
||||
// try to parse the expression
|
||||
|
|
@ -669,6 +682,15 @@ CParseResult CConfig::parseLine(std::string line, bool dynamic) {
|
|||
}
|
||||
}
|
||||
|
||||
// Removing escape chars. -- in the future, maybe map all the chars that can be escaped.
|
||||
// Right now only expression parsing has escapeable chars
|
||||
for(long i = 0; i < (long)RHS.length()-(long)1; i++){
|
||||
if(RHS.at(i) == '\\' && (RHS.at(i+1) == '{' || RHS.at(i+1) == '}')){
|
||||
RHS.erase(i--, 1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (ISVARIABLE)
|
||||
return parseVariable(LHS, RHS, dynamic);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue