diff --git a/user/tb/interp.c b/user/tb/interp.c index 4e28be1..92f7363 100644 --- a/user/tb/interp.c +++ b/user/tb/interp.c @@ -34,7 +34,33 @@ void tz_tokenize(Tokenizer *tz) { i++; size_t j = 0; while (i < len && tz->str[i] != '\'') { - str[j++] = tz->str[i++]; + if (tz->str[i] == '\\') { + if (i + 1 < len) { + i++; + char c; + switch (tz->str[i]) { + case 'n': c = '\n'; break; + case 't': c = '\t'; break; + case 'r': c = '\r'; break; + case '\\': c = '\\'; break; + case '\'': c = '\''; break; + case '"': c = '"'; break; + default: c = tz->str[i]; break; + } + if (j + 1 < TZ_MAX_TK) { + str[j++] = c; + } + } else { + if (j + 1 < TZ_MAX_TK) { + str[j++] = '\\'; + } + } + } else { + if (j + 1 < TZ_MAX_TK) { + str[j++] = tz->str[i]; + } + } + i++; } Token *tk = umalloc(sizeof(*tk)); tk->str = str; @@ -44,8 +70,11 @@ void tz_tokenize(Tokenizer *tz) { char *tkstr = umalloc(TZ_MAX_TK); string_memset(tkstr, 0, TZ_MAX_TK); size_t j = 0; - while (i < len && !string_chr_isspace(tz->str[i])) { - tkstr[j++] = tz->str[i++]; + while (i < len && !string_chr_isspace(tz->str[i]) && tz->str[i] != '\'') { + if (j + 1 < TZ_MAX_TK) { + tkstr[j++] = tz->str[i]; + } + i++; } Token *tk = umalloc(sizeof(*tk)); tk->str = tkstr;