devSpec:lex: Allow backslash escaping of strings
Now we can escape special characters without issue.
This commit is contained in:
@@ -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 */ }
|
||||||
|
|||||||
Reference in New Issue
Block a user