aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parser.c31
-rw-r--r--src/tokenizer.c6
2 files changed, 33 insertions, 4 deletions
diff --git a/src/parser.c b/src/parser.c
index babb2d9..7588bda 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -266,18 +266,36 @@ int parser_parse_rhs_start(Parser *self, Ast *rhs_expr) {
}
/*
-BODY = (LHS '=' RHS_START) |
- RHS_START
+BODY = LHS ';' |
+ (LHS '=' RHS_START ';') |
+ (RHS_START ';')
+
+Note: Semicolon is not required for closures, structs and tables
*/
int parser_parse_body(Parser *self, Ast *ast) {
+ bool match;
LhsExpr *lhs_expr;
Ast rhs_expr;
rhs_expr = ast_none();
return_if_error(parser_parse_lhs(self, &lhs_expr));
- if(lhs_expr)
- return_if_error(tokenizer_accept(&self->tokenizer, TOK_EQUALS));
+ if(lhs_expr) {
+ return_if_error(tokenizer_consume_if(&self->tokenizer, TOK_EQUALS, &match));
+ if(match)
+ goto rhs;
+
+ return_if_error(tokenizer_consume_if(&self->tokenizer, TOK_SEMICOLON, &match));
+ if(!match) {
+ self->error = tokenizer_create_error(&self->tokenizer, "Expected '=' or ';'");
+ return PARSER_UNEXPECTED_TOKEN;
+ }
+
+ ast->type = AST_LHS;
+ ast->value.lhs_expr = lhs_expr;
+ return PARSER_OK;
+ }
+ rhs:
return_if_error(parser_parse_rhs_start(self, &rhs_expr));
if(lhs_expr) {
lhs_expr->rhs_expr = rhs_expr;
@@ -286,6 +304,11 @@ int parser_parse_body(Parser *self, Ast *ast) {
} else {
*ast = rhs_expr;
}
+
+ /* TODO: Check for struct and tables */
+ if(rhs_expr.type != AST_FUNCTION_DECL)
+ return_if_error(tokenizer_accept(&self->tokenizer, TOK_SEMICOLON));
+
return PARSER_OK;
}
diff --git a/src/tokenizer.c b/src/tokenizer.c
index b996354..afaeb8e 100644
--- a/src/tokenizer.c
+++ b/src/tokenizer.c
@@ -247,6 +247,9 @@ static CHECK_RESULT int __tokenizer_next(Tokenizer *self, Token *token) {
} else if(c == '}') {
++self->index;
*token = TOK_CLOSING_BRACE;
+ } else if(c == ';') {
+ ++self->index;
+ *token = TOK_SEMICOLON;
} else if(c == '@') {
const char *err_msg;
++self->index;
@@ -361,6 +364,9 @@ static BufferView tokenizer_expected_token_as_string(Token token) {
case TOK_DOT:
str = ".";
break;
+ case TOK_SEMICOLON:
+ str = ";";
+ break;
default:
str = "Unknown token";
break;