aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/fwd/ast.h1
-rw-r--r--src/ast.c13
-rw-r--r--src/parser.y5
3 files changed, 18 insertions, 1 deletions
diff --git a/include/fwd/ast.h b/include/fwd/ast.h
index 1d784f1..f550647 100644
--- a/include/fwd/ast.h
+++ b/include/fwd/ast.h
@@ -699,6 +699,7 @@ int equiv_node_lists(struct ast *c1, struct ast *c2);
struct ast *reverse_ast_list(struct ast *root);
struct type *reverse_type_list(struct type *root);
+struct ast *filter_empty(struct ast *root);
void fix_closures(struct ast *root);
#define foreach_node(iter, nodes) \
diff --git a/src/ast.c b/src/ast.c
index a39cb94..d7d97e0 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -567,6 +567,19 @@ struct type *reverse_type_list(struct type *root)
return new_root;
}
+struct ast *filter_empty(struct ast *root)
+{
+ struct ast *ret = root;
+ while (root) {
+ if (root->n && root->n->k == AST_EMPTY)
+ root->n = root->n->n;
+
+ root = root->n;
+ }
+
+ return ret;
+}
+
void fix_closures(struct ast *root)
{
while (root) {
diff --git a/src/parser.y b/src/parser.y
index dad3210..6210a95 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -454,7 +454,10 @@ rev_statements
| statement
statements
- : rev_statements { $$ = reverse_ast_list($1); fix_closures($$); }
+ : rev_statements {
+ $$ = filter_empty(reverse_ast_list($1));
+ fix_closures($$);
+ }
opt_statements
: statements