devSpec:lex: Allow backslash escaping of strings

Now we can escape special characters without issue.
This commit is contained in:
2025-01-15 08:21:18 -04:00
parent ead7d8ff5f
commit 76e465bd1d
+19 -3
View File
@@ -26,10 +26,26 @@
"(" { return LPAREN; } "(" { return LPAREN; }
")" { return RPAREN; } ")" { return RPAREN; }
[ \t]*"="[ \t]* { return EQUALS; } // Allow optional whitespace around equals [ \t]*"="[ \t]* { return EQUALS; } // Allow optional whitespace around equals
([^=\|\(\) \t\r\n]|\\[ \t])+ { (\\.|[^=\|\(\) \t\r\n])+ {
std::string token(yytext); std::string token(yytext);
token.erase(std::remove(token.begin(), token.end(), '\\'), token.end());
deviceSpecplval.str = strdup(token.c_str()); // Unescape logic for backslash, pipe
std::string unescaped;
unescaped.reserve(token.size());
for (size_t i = 0; i < token.size(); ++i)
{
if (token[i] == '\\' && i + 1 < token.size())
{
unescaped.push_back(token[++i]);
}
else
{
unescaped.push_back(token[i]);
}
}
deviceSpecplval.str = strdup(unescaped.c_str());
return STRING; return STRING;
} }
\r?\n { /* ignore newlines */ } \r?\n { /* ignore newlines */ }