tuple
This commit is contained in:
parent
d294daa307
commit
140d01eac4
3 changed files with 28 additions and 2 deletions
|
|
@ -190,4 +190,24 @@ struct Dict : Expr
|
||||||
}
|
}
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Tuple : Expr
|
||||||
|
{
|
||||||
|
std::vector<ptr<Expr>> elements;
|
||||||
|
|
||||||
|
Tuple(std::vector<ptr<Expr>> elems)
|
||||||
|
: elements(std::move(elems)) {}
|
||||||
|
|
||||||
|
std::string dump(int indent = 0) const override
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << indent_str(indent) << "Tuple";
|
||||||
|
for (const auto &elem : elements)
|
||||||
|
{
|
||||||
|
oss << "\n"
|
||||||
|
<< elem->dump(indent + 1);
|
||||||
|
}
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -57,6 +57,7 @@
|
||||||
%type <std::unique_ptr<Slice>> slice
|
%type <std::unique_ptr<Slice>> slice
|
||||||
%type <std::unique_ptr<Stmt>> stmt
|
%type <std::unique_ptr<Stmt>> stmt
|
||||||
%type <std::vector<std::unique_ptr<Expr>>> args
|
%type <std::vector<std::unique_ptr<Expr>>> args
|
||||||
|
%type <std::vector<std::unique_ptr<Expr>>> tuple
|
||||||
%type <std::vector<std::unique_ptr<Stmt>>> stmt_list
|
%type <std::vector<std::unique_ptr<Stmt>>> stmt_list
|
||||||
%type <std::vector<std::string>> params
|
%type <std::vector<std::string>> params
|
||||||
|
|
||||||
|
|
@ -110,6 +111,7 @@ expr:
|
||||||
| expr L_PAREN args R_PAREN { $$ = std::make_unique<Call>(std::move($1), std::move($3));}
|
| expr L_PAREN args R_PAREN { $$ = std::make_unique<Call>(std::move($1), std::move($3));}
|
||||||
| expr DOT IDENTIFIER { $$ = std::make_unique<Attribute>(std::move($1), $3);}
|
| expr DOT IDENTIFIER { $$ = std::make_unique<Attribute>(std::move($1), $3);}
|
||||||
| L_BRACKET args R_BRACKET { $$ = std::make_unique<List>(std::move($2));}
|
| L_BRACKET args R_BRACKET { $$ = std::make_unique<List>(std::move($2));}
|
||||||
|
| L_PAREN tuple R_PAREN { $$ = std::make_unique<Tuple>(std::move($2));}
|
||||||
| MINUS expr { $$ = std::make_unique<UnaryOpExpr>(UnaryOperator(UnaryOperator::NEG), std::move($2));}
|
| MINUS expr { $$ = std::make_unique<UnaryOpExpr>(UnaryOperator(UnaryOperator::NEG), std::move($2));}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -131,6 +133,11 @@ args:
|
||||||
| args COMMA expr { $1.push_back(std::move($3)); $$ = std::move($1); }
|
| args COMMA expr { $1.push_back(std::move($3)); $$ = std::move($1); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
tuple:
|
||||||
|
expr { $$ = std::vector<std::unique_ptr<Expr>>();
|
||||||
|
$$.push_back(std::move($1)); }
|
||||||
|
| tuple COMMA expr { $1.push_back(std::move($3)); $$ = std::move($1); }
|
||||||
|
|
||||||
params:
|
params:
|
||||||
{ $$ = std::vector<std::string>();}
|
{ $$ = std::vector<std::string>();}
|
||||||
| IDENTIFIER { $$ = std::vector<std::string>(); $$.push_back($1); }
|
| IDENTIFIER { $$ = std::vector<std::string>(); $$.push_back($1); }
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,4 @@ Module
|
||||||
Tuple
|
Tuple
|
||||||
Number(1)
|
Number(1)
|
||||||
Number(2)
|
Number(2)
|
||||||
Number(3)
|
Number(3)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue