mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 21:10:19 +00:00
This commit is contained in:
parent
fd6f0d76b2
commit
bf8ec59dc5
@ -28,6 +28,7 @@ typedef struct ExprVt {
|
|||||||
bool is_subscr; // SubscrExpr
|
bool is_subscr; // SubscrExpr
|
||||||
bool is_starred; // StarredExpr
|
bool is_starred; // StarredExpr
|
||||||
bool is_binary; // BinaryExpr
|
bool is_binary; // BinaryExpr
|
||||||
|
bool is_ternary; // TernaryExpr
|
||||||
void (*dtor)(Expr*);
|
void (*dtor)(Expr*);
|
||||||
} ExprVt;
|
} ExprVt;
|
||||||
|
|
||||||
@ -873,7 +874,11 @@ void TernaryExpr__emit_(Expr* self_, Ctx* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TernaryExpr* TernaryExpr__new(int line) {
|
TernaryExpr* TernaryExpr__new(int line) {
|
||||||
const static ExprVt Vt = {.dtor = TernaryExpr__dtor, .emit_ = TernaryExpr__emit_};
|
const static ExprVt Vt = {
|
||||||
|
.dtor = TernaryExpr__dtor,
|
||||||
|
.emit_ = TernaryExpr__emit_,
|
||||||
|
.is_ternary = true,
|
||||||
|
};
|
||||||
TernaryExpr* self = PK_MALLOC(sizeof(TernaryExpr));
|
TernaryExpr* self = PK_MALLOC(sizeof(TernaryExpr));
|
||||||
self->vt = &Vt;
|
self->vt = &Vt;
|
||||||
self->line = line;
|
self->line = line;
|
||||||
@ -1681,6 +1686,10 @@ static Error* exprTernary(Compiler* self) {
|
|||||||
e->cond = Ctx__s_popx(ctx());
|
e->cond = Ctx__s_popx(ctx());
|
||||||
e->true_expr = Ctx__s_popx(ctx());
|
e->true_expr = Ctx__s_popx(ctx());
|
||||||
Ctx__s_push(ctx(), (Expr*)e);
|
Ctx__s_push(ctx(), (Expr*)e);
|
||||||
|
|
||||||
|
if(e->cond->vt->is_ternary || e->false_expr->vt->is_ternary || e->true_expr->vt->is_ternary) {
|
||||||
|
return SyntaxError(self, "nested ternary expressions without `()` are ambiguous");
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user