Revert "improve abstraction for AssocList, fix bug in optional else (#315)" (#320)

This reverts commit bf6bb800c4.
This commit is contained in:
Dave Abrahams
2021-03-01 12:26:56 -05:00
committed by GitHub
parent 8b3bb7c5e9
commit f5300a84e5
55 changed files with 7431 additions and 293 deletions
+26 -9
View File
@@ -115,11 +115,15 @@ void PrintStatement(Statement* s, int depth) {
}
switch (s->tag) {
case StatementKind::Match:
std::cout << "match (" << *s->u.match_stmt.exp << ") {";
std::cout << "match (";
PrintExp(s->u.match_stmt.exp);
std::cout << ") {";
if (depth < 0 || depth > 1) {
std::cout << std::endl;
for (auto& clause : *s->u.match_stmt.clauses) {
std::cout << "case " << *clause.first << " =>" << std::endl;
std::cout << "case ";
PrintExp(clause.first);
std::cout << " =>" << std::endl;
PrintStatement(clause.second, depth - 1);
std::cout << std::endl;
}
@@ -129,7 +133,9 @@ void PrintStatement(Statement* s, int depth) {
std::cout << "}";
break;
case StatementKind::While:
std::cout << "while (" << *s->u.while_stmt.cond << ")" << std::endl;
std::cout << "while (";
PrintExp(s->u.while_stmt.cond);
std::cout << ")" << std::endl;
PrintStatement(s->u.while_stmt.body, depth - 1);
break;
case StatementKind::Break:
@@ -139,23 +145,34 @@ void PrintStatement(Statement* s, int depth) {
std::cout << "continue;";
break;
case StatementKind::VariableDefinition:
std::cout << "var " << *s->u.variable_definition.pat << " = "
<< *s->u.variable_definition.init << ";";
std::cout << "var ";
PrintExp(s->u.variable_definition.pat);
std::cout << " = ";
PrintExp(s->u.variable_definition.init);
std::cout << ";";
break;
case StatementKind::ExpressionStatement:
std::cout << *s->u.exp << ";";
PrintExp(s->u.exp);
std::cout << ";";
break;
case StatementKind::Assign:
std::cout << *s->u.assign.lhs << " = " << *s->u.assign.rhs << ";";
PrintExp(s->u.assign.lhs);
std::cout << " = ";
PrintExp(s->u.assign.rhs);
std::cout << ";";
break;
case StatementKind::If:
std::cout << "if (" << *s->u.if_stmt.cond << ")" << std::endl;
std::cout << "if (";
PrintExp(s->u.if_stmt.cond);
std::cout << ")" << std::endl;
PrintStatement(s->u.if_stmt.then_stmt, depth - 1);
std::cout << std::endl << "else" << std::endl;
PrintStatement(s->u.if_stmt.else_stmt, depth - 1);
break;
case StatementKind::Return:
std::cout << "return " << *s->u.return_stmt << ";";
std::cout << "return ";
PrintExp(s->u.return_stmt);
std::cout << ";";
break;
case StatementKind::Sequence:
PrintStatement(s->u.sequence.stmt, depth);