Kaynağa Gözat

support empty tuple `()`

blueloveTH 1 yıl önce
ebeveyn
işleme
4df11f3c6f
1 değiştirilmiş dosya ile 5 ekleme ve 0 silme
  1. 5 0
      src/compiler/compiler.c

+ 5 - 0
src/compiler/compiler.c

@@ -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();