Compare commits

...

2 Commits

Author SHA1 Message Date
blueloveTH
4df11f3c6f support empty tuple () 2024-12-18 19:29:39 +08:00
blueloveTH
a9a4ef6dda fix a utf8 bug 2024-12-18 18:52:11 +08:00
2 changed files with 23 additions and 7 deletions

View File

@ -98,7 +98,10 @@ void c11_sbuf__write_quoted(c11_sbuf* self, c11_sv sv, char quote) {
case '\r': c11_sbuf__write_cstrn(self, "\\r", 2); break;
case '\t': c11_sbuf__write_cstrn(self, "\\t", 2); break;
case '\b': c11_sbuf__write_cstrn(self, "\\b", 2); break;
default:
default: {
int u8bytes = c11__u8_header(c, true);
if(u8bytes <= 1) {
// not a valid utf8 char, or ascii
if(!isprint(c)) {
unsigned char uc = (unsigned char)c;
c11_sbuf__write_cstrn(self, "\\x", 2);
@ -107,6 +110,14 @@ void c11_sbuf__write_quoted(c11_sbuf* self, c11_sv sv, char quote) {
} else {
c11_sbuf__write_char(self, c);
}
} else {
for(int j = 0; j < u8bytes; j++) {
c11_sbuf__write_char(self, sv.data[i + j]);
}
i += u8bytes - 1;
}
break;
}
}
}
c11_sbuf__write_char(self, quote);

View File

@ -1722,6 +1722,11 @@ static Error* exprUnaryOp(Compiler* self) {
static Error* exprGroup(Compiler* self) {
Error* err;
int line = prev()->line;
if(match(TK_RPAREN)) {
// empty tuple
Ctx__s_push(ctx(), (Expr*)TupleExpr__new(line, 0));
return NULL;
}
match_newlines();
check(EXPR_TUPLE(self)); // () is just for change precedence
match_newlines();