Added a few characters that can be escaped

This commit is contained in:
2023-01-31 12:37:18 +00:00
parent e265038547
commit fcd1cdf70b
4 changed files with 100 additions and 34 deletions

View File

@@ -171,12 +171,24 @@ static Toy_Token makeIntegerOrFloat(Toy_Lexer* lexer) {
}
static Toy_Token makeString(Toy_Lexer* lexer, char terminator) {
while (!isAtEnd(lexer) && peek(lexer) != terminator) {
while (!isAtEnd(lexer)) {
//skip escaped terminators
if (peek(lexer) == '\\' && peekNext(lexer) == terminator) {
advance(lexer);
advance(lexer);
continue;
}
//actually escape if you've hit the terminator
if (peek(lexer) == terminator) {
advance(lexer); //eat terminator
break;
}
//otherwise
advance(lexer);
}
advance(lexer); //eat terminator
if (isAtEnd(lexer)) {
return makeErrorToken(lexer, "Unterminated string");
}