forked from ground/ground
Compare commits
3 Commits
e2a037befc
...
a4eba4ae47
Author | SHA1 | Date | |
---|---|---|---|
a4eba4ae47 | |||
872392c1c5 | |||
2e1e2e727b |
33
src/main.cpp
33
src/main.cpp
@@ -2098,6 +2098,37 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
return retLiteral;
|
||||
}
|
||||
|
||||
string interpretEscapeSequences(string input) {
|
||||
string output;
|
||||
for (size_t i = 0; i < input.length(); ++i) {
|
||||
if (input[i] == '\\' && i + 1 < input.length()) {
|
||||
char next = input[i + 1];
|
||||
switch (next) {
|
||||
case 'n': output += '\n'; break;
|
||||
case 't': output += '\t'; break;
|
||||
case 'r': output += '\r'; break;
|
||||
case 'b': output += '\b'; break;
|
||||
case 'f': output += '\f'; break;
|
||||
case 'a': output += '\a'; break;
|
||||
case 'v': output += '\v'; break;
|
||||
case '\\': output += '\\'; break;
|
||||
case '\'': output += '\''; break;
|
||||
case '\"': output += '\"'; break;
|
||||
case '0': output += '\0'; break;
|
||||
default:
|
||||
output += '\\';
|
||||
output += next;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
} else {
|
||||
output += input[i];
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
lexer function
|
||||
This function takes a string (the user's program) and splits it into smaller chunks
|
||||
@@ -2297,7 +2328,7 @@ vector<Instruction> parser(vector<vector<string>> in) {
|
||||
case Types::String:
|
||||
{
|
||||
Literal newLiteral;
|
||||
string str = i.substr(1, i.size() - 2);
|
||||
string str = interpretEscapeSequences(i.substr(1, i.size() - 2));
|
||||
newLiteral.val = str;
|
||||
newInst.args.push_back(newLiteral);
|
||||
}
|
||||
|
Reference in New Issue
Block a user