class def
This commit is contained in:
parent
5f560f079b
commit
878dfe74e0
4 changed files with 14 additions and 6 deletions
|
|
@ -49,10 +49,11 @@ struct Return : Stmt
|
|||
std::string dump(int indent = 0) const override
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << indent_str(indent) << "Return\n";
|
||||
oss << indent_str(indent) << "Return";
|
||||
if (value)
|
||||
{
|
||||
oss << value->dump(indent + 1);
|
||||
oss << "\n"
|
||||
<< value->dump(indent + 1);
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,9 +94,18 @@ stmt:
|
|||
| KW_RETURN expr NEWLINE {
|
||||
$$ = std::make_unique<Return>(std::move($2));
|
||||
}
|
||||
| KW_RETURN NEWLINE {
|
||||
$$ = std::make_unique<Return>(nullptr);
|
||||
}
|
||||
| KW_PASS NEWLINE {
|
||||
$$ = std::make_unique<Pass>();
|
||||
}
|
||||
| KW_WHILE expr COLON NEWLINE INDENT stmt_list DEDENT {
|
||||
$$ = std::make_unique<While>(std::move($2), std::move($6));
|
||||
}
|
||||
| KW_CLASS IDENTIFIER COLON NEWLINE INDENT stmt_list DEDENT {
|
||||
$$ = std::make_unique<ClassDef>(std::move($2), std::move($6));
|
||||
}
|
||||
;
|
||||
|
||||
expr:
|
||||
|
|
|
|||
|
|
@ -5,5 +5,4 @@ Module
|
|||
Identifier(x)
|
||||
Return
|
||||
Identifier(x)
|
||||
Return
|
||||
|
||||
Return
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
Module
|
||||
ClassDef(A)
|
||||
Pass
|
||||
|
||||
Pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue