From 068d94497f6cfee8ad4234c8f5ec0ce1956efc28 Mon Sep 17 00:00:00 2001 From: ell1e Date: Sat, 11 Jan 2025 21:10:10 +0100 Subject: [PATCH] compiler: Add more handling for T_CHAR token type DCO-1.1-Signed-off-by: Ellie --- src/compiler/token/token.h64 | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/compiler/token/token.h64 b/src/compiler/token/token.h64 index eb16b40..01e9d9d 100644 --- a/src/compiler/token/token.h64 +++ b/src/compiler/token/token.h64 @@ -276,16 +276,27 @@ func parse_token_value(tok) { } elseif tok.kind == T_BIGNUM { throw new TypeError("Cannot return actual " "literal value for T_BIGNUM token.") - } elseif tok.kind == T_STR { - if tok.str.len == 0 or - not {"'", '"'}.has(tok.str[1]) { - # Invalid literal. Just return empty value. - return "" + } elseif tok.kind == T_STR or + tok.kind == T_CHAR { + var i = 2 + if tok.kind == T_CHAR { + if tok.str.len < 2 or + tok.str[1] != "c" or + not {"'", '"'}.has(tok.str[2]) { + # Invalid literal. Just return empty value. + return "" + } + i = 3 + } else { + if tok.str.len == 0 or + not {"'", '"'}.has(tok.str[1]) { + # Invalid literal. Just return empty value. + return "" + } } var toklen = tok.str.len var escaped = no var result = "" - var i = 2 while i <= toklen - 1 { if escaped { escaped = no