all repos — xyw @ 838b748a55d21c0e1aa1e65df684c316d274839d

A minimal virtual machine and assembler for terminals.

Added support for basic escape characters in strings.
h3rald h3rald@h3rald.com
Fri, 05 Dec 2025 07:30:21 +0100
commit

838b748a55d21c0e1aa1e65df684c316d274839d

parent

2525f5d8a1d82fb2fc6789a7237f111013a9abf2

1 files changed, 47 insertions(+), 0 deletions(-)

jump to
M xywasm.cxywasm.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) {