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::string dump(int indent = 0) const override
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << indent_str(indent) << "Return\n";
|
oss << indent_str(indent) << "Return";
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
oss << value->dump(indent + 1);
|
oss << "\n"
|
||||||
|
<< value->dump(indent + 1);
|
||||||
}
|
}
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,9 +94,18 @@ stmt:
|
||||||
| KW_RETURN expr NEWLINE {
|
| KW_RETURN expr NEWLINE {
|
||||||
$$ = std::make_unique<Return>(std::move($2));
|
$$ = 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 {
|
| KW_WHILE expr COLON NEWLINE INDENT stmt_list DEDENT {
|
||||||
$$ = std::make_unique<While>(std::move($2), std::move($6));
|
$$ = 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:
|
expr:
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,3 @@ Module
|
||||||
Return
|
Return
|
||||||
Identifier(x)
|
Identifier(x)
|
||||||
Return
|
Return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
Module
|
Module
|
||||||
ClassDef(A)
|
ClassDef(A)
|
||||||
Pass
|
Pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue