Recognize wide character literal

For now, L'' is equivalent to ''.
This commit is contained in:
Rui Ueyama 2020-07-20 19:24:56 +09:00
parent ab4f1e1e19
commit 7746e4ee0b
2 changed files with 13 additions and 3 deletions

View File

@ -95,6 +95,9 @@ int main() {
of(char), \
"sizeof(char)");
ASSERT(4, sizeof(L'\0'));
ASSERT(97, L'a');
printf("OK\n");
return 0;
}

View File

@ -246,8 +246,8 @@ static Token *read_string_literal(char *start) {
return tok;
}
static Token *read_char_literal(char *start) {
char *p = start + 1;
static Token *read_char_literal(char *start, char *quote) {
char *p = quote + 1;
if (*p == '\0')
error_at(start, "unclosed char literal");
@ -452,11 +452,18 @@ Token *tokenize(File *file) {
// Character literal
if (*p == '\'') {
cur = cur->next = read_char_literal(p);
cur = cur->next = read_char_literal(p, p);
p += cur->len;
continue;
}
// Wide character literal
if (startswith(p, "L'")) {
cur = cur->next = read_char_literal(p, p + 1);
p = cur->loc + cur->len;
continue;
}
// Identifier or keyword
if (is_ident1(*p)) {
char *start = p;