diff --git a/src/compiler.h b/src/compiler.h index cf158895..b78bf1c4 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -301,6 +301,9 @@ class Compiler { EXPR_TUPLE(); // () is just for change precedence match_newlines_repl(); consume(TK(")")); + if(ctx()->s_expr.top()->is_tuple()) return; + Expr_ g = make_expr(ctx()->s_expr.popx()); + ctx()->s_expr.push(std::move(g)); } template diff --git a/src/expr.h b/src/expr.h index b56264cc..b942d960 100644 --- a/src/expr.h +++ b/src/expr.h @@ -24,6 +24,7 @@ struct Expr{ virtual bool is_attrib() const { return false; } virtual bool is_compare() const { return false; } virtual int star_level() const { return 0; } + virtual bool is_tuple() const { return false; } bool is_starred() const { return star_level() > 0; } // for OP_DELETE_XXX @@ -445,6 +446,7 @@ struct SetExpr: SequenceExpr{ struct TupleExpr: SequenceExpr{ using SequenceExpr::SequenceExpr; std::string str() const override { return "Tuple()"; } + bool is_tuple() const override { return true; } Opcode opcode() const override { for(auto& e: items) if(e->is_starred()) return OP_BUILD_TUPLE_UNPACK; return OP_BUILD_TUPLE; @@ -734,6 +736,17 @@ struct CallExpr: Expr{ } }; +struct GroupedExpr: Expr{ + Expr_ a; + std::string str() const override { return "Grouped()"; } + + GroupedExpr(Expr_&& a): a(std::move(a)) {} + + void emit(CodeEmitContext* ctx) override{ + a->emit(ctx); + } +}; + struct BinaryExpr: Expr{ TokenIndex op; Expr_ lhs; diff --git a/tests/31_cmp.py b/tests/31_cmp.py index 8a3a7649..d6cbeffd 100644 --- a/tests/31_cmp.py +++ b/tests/31_cmp.py @@ -13,4 +13,7 @@ assert 1<1+1<3<2+2<5 a = [1,2,3] assert a[0] < a[1] < a[2] assert a[0]+1 == a[1] < a[2] -assert a[0]+1 == a[1] < a[2]+1 < 5 \ No newline at end of file +assert a[0]+1 == a[1] < a[2]+1 < 5 + +assert (4>3<2) == False +# assert ((4>3)<2) == True \ No newline at end of file