Skip to content

Commit

Permalink
Added support for escaped LF + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loumadev committed Nov 28, 2023
1 parent 40f45f6 commit 224e585
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/compiler/lexer/Lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ bool __Lexer_resolveEscapedChar(char ch, char *out) {
case '\\': *out = '\\'; break;
case '\'': *out = '\''; break;
case '"': *out = '"'; break;
case '\n': *out = '\n'; break;
default: return false;
}

Expand Down
11 changes: 11 additions & 0 deletions test/compiler/lexer/Lexer.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,17 @@ DESCRIBE(string_whitespace_escape, "String literals tokenization with escaped wh
EXPECT_EQUAL_INT(token->value.string->length, 2);
})

TEST_BEGIN("Line feed as escaped char") {
result = Lexer_tokenize(&lexer, "\"line1 \\\nline2\"");
EXPECT_TRUE(result.success);

token = (Token*)Array_get(lexer.tokens, 0);

EXPECT_TRUE(token->kind == TOKEN_STRING);
EXPECT_TRUE(String_equals(token->value.string, "line1 \nline2"));
EXPECT_EQUAL_INT(token->value.string->length, 12);
} TEST_END();


TEST("Single carriage return", {
result = Lexer_tokenize(&lexer, "\"\\r\"");
Expand Down

0 comments on commit 224e585

Please sign in to comment.