aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-03 15:48:50 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commita9df3e468a63d997dce6c9f14761757b8685f307 (patch)
treed16fca42b4633dfaa319ea18f35905eb6757e0ea /src
parent350a116e5a9a167b229cefae6e5927f604d7fa85 (diff)
Code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/parser.c44
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;
}