diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parser.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/parser.c b/src/parser.c index c94d416..a3bd330 100644 --- a/src/parser.c +++ b/src/parser.c @@ -370,12 +370,34 @@ int parser_parse_rhs_start(Parser *self, Ast *rhs_expr) { } /* -BODY = LHS ';' | - (LHS '=' RHS_START ';') | - (RHS_START ';') +BODY_SEMICOLON Note: Semicolon is not required for closures, structs and tables */ +static THROWABLE parser_parse_body_semicolon(Parser *self, Ast *expr) { + if(expr->type == AST_BINOP) { + bool match; + throw_if_error(tokenizer_consume_if(&self->tokenizer, TOK_SEMICOLON, &match)); + if(!match) { + /* TODO: Specify all the binop characters instead of "binop" which doesn't make sense for the user */ + self->error = tokenizer_create_error(&self->tokenizer, "Expected ';' or binop"); + throw(PARSER_UNEXPECTED_TOKEN); + } + return PARSER_OK; + } + + /* TODO: Check for struct and tables */ + if(expr->type != AST_FUNCTION_DECL) + throw_if_error(tokenizer_accept(&self->tokenizer, TOK_SEMICOLON)); + + return PARSER_OK; +} + +/* +BODY = LHS ';' | + (LHS '=' RHS_START BODY_SEMICOLON) | + (RHS_START BODY_SEMICOLON) +*/ int parser_parse_body(Parser *self, Ast *ast) { bool assignment; LhsExpr *lhs_expr; @@ -398,21 +420,7 @@ int parser_parse_body(Parser *self, Ast *ast) { *ast = rhs_expr; } - if(rhs_expr.type == AST_BINOP) { - bool match; - throw_if_error(tokenizer_consume_if(&self->tokenizer, TOK_SEMICOLON, &match)); - if(!match) { - /* TODO: Specify all the binop characters instead of "binop" which doesn't make sense for the user */ - self->error = tokenizer_create_error(&self->tokenizer, "Expected ';' or binop"); - return PARSER_UNEXPECTED_TOKEN; - } - return PARSER_OK; - } - - /* TODO: Check for struct and tables */ - if(rhs_expr.type != AST_FUNCTION_DECL) - throw_if_error(tokenizer_accept(&self->tokenizer, TOK_SEMICOLON)); - + try(parser_parse_body_semicolon(self, &rhs_expr)); return PARSER_OK; } |