aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-12-30 22:52:43 +0000
committerGinger Bill <bill@gingerbill.org>2016-12-30 22:52:43 +0000
commit0c6775ca14ced37ac58a03ccad4028e225bda7d6 (patch)
tree1d53d0bc67fb5287d609bba3c2e0933c70a9f0d6 /src/parser.c
parent6748f305db791e0b3db3fe567ea44ba96935c7d9 (diff)
Fix give expressions
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c54
1 files changed, 35 insertions, 19 deletions
diff --git a/src/parser.c b/src/parser.c
index 75e2c7d90..bfed77b0b 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1275,27 +1275,36 @@ void expect_semicolon(AstFile *f, AstNode *s) {
return;
}
- if (s != NULL && prev_token.pos.line != f->curr_token.pos.line) {
- switch (s->kind) {
- case AstNode_ProcDecl:
- return;
- case AstNode_GenericDecl:
- if (s->GenericDecl.close.kind == Token_CloseBrace) {
+ if (s != NULL) {
+ if (prev_token.pos.line != f->curr_token.pos.line) {
+ switch (s->kind) {
+ case AstNode_ProcDecl:
return;
- } else if (s->GenericDecl.token.kind == Token_type) {
+ case AstNode_GenericDecl:
+ if (s->GenericDecl.close.kind == Token_CloseBrace) {
+ return;
+ } else if (s->GenericDecl.token.kind == Token_type) {
+ if (f->prev_token.kind == Token_CloseBrace) {
+ return;
+ }
+ }
+ break;
+
+ case AstNode_TypeSpec:
if (f->prev_token.kind == Token_CloseBrace) {
return;
}
+ break;
}
- break;
-
- case AstNode_TypeSpec:
- if (f->prev_token.kind == Token_CloseBrace) {
- return;
+ } else {
+ switch (s->kind) {
+ case AstNode_GiveExpr:
+ if (f->curr_token.kind == Token_CloseBrace) {
+ return;
+ }
+ break;
}
- break;
}
-
syntax_error(prev_token, "Expected `;` after %.*s, got %.*s",
LIT(ast_node_strings[s->kind]), LIT(token_strings[prev_token.kind]));
} else {
@@ -2752,10 +2761,11 @@ AstNode *parse_return_stmt(AstFile *f) {
}
Token token = expect_token(f, Token_return);
- AstNodeArray results = make_ast_node_array(f);
-
+ AstNodeArray results;
if (f->curr_token.kind != Token_Semicolon && f->curr_token.kind != Token_CloseBrace) {
results = parse_rhs_expr_list(f);
+ } else {
+ results = make_ast_node_array(f);
}
expect_semicolon(f, results.e[0]);
@@ -2774,9 +2784,15 @@ AstNode *parse_give_stmt(AstFile *f) {
}
Token token = expect_token(f, Token_give);
- AstNodeArray results = parse_rhs_expr_list(f);
- expect_semicolon(f, results.e[0]);
- return make_expr_stmt(f, make_give_expr(f, token, results));
+ AstNodeArray results;
+ if (f->curr_token.kind != Token_Semicolon && f->curr_token.kind != Token_CloseBrace) {
+ results = parse_rhs_expr_list(f);
+ } else {
+ results = make_ast_node_array(f);
+ }
+ AstNode *ge = make_give_expr(f, token, results);
+ expect_semicolon(f, ge);
+ return make_expr_stmt(f, ge);
}
AstNode *parse_for_stmt(AstFile *f) {