Added support for basic escape characters in strings.
h3rald h3rald@h3rald.com
Fri, 05 Dec 2025 07:30:21 +0100
1 files changed,
47 insertions(+),
0 deletions(-)
jump to
M
xywasm.c
→
xywasm.c
@@ -814,6 +814,53 @@ }
} else if (in_string) { + if (c == '\\') + { + // Handle escape sequences + char next_char; + if (ctx->src == SRC_FILE) + { + if (fread(&next_char, 1, 1, ctx->fp) != 1) + { + token_error("Unterminated escape sequence in string literal"); + return TOKEN_END_INVALID; + } + } + else + { + if (!ctx->sp || *ctx->sp == '\0') + { + token_error("Unterminated escape sequence in string literal"); + return TOKEN_END_INVALID; + } + next_char = *ctx->sp++; + } + ctx->column++; + switch (next_char) + { + case 'n': + c = '\n'; + break; + case 't': + c = '\t'; + break; + case '"': + c = '"'; + break; + case 'r': + c = '\r'; + break; + case '\'': + c = '\''; + break; + case '\\': + c = '\\'; + break; + default: + token_error("Unknown escape sequence in string literal"); + return TOKEN_END_INVALID; + } + } ctx->column++; if (token_length > STRING_MAX_LENGTH) {