aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/parser.c b/src/parser.c
index 81f0a92..e63814f 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -70,7 +70,7 @@ static CHECK_RESULT int parser_parse_lhs(Parser *self, LhsExpr **result) {
}
/*
-FUNC_DECL = '(' PARAM* ')' '{' BODY* '}'
+CLOSURE = '(' PARAM* ')' '{' BODY* '}'
*/
static CHECK_RESULT int parser_parse_function_decl(Parser *self, FunctionDecl **func_decl) {
bool result;
@@ -101,7 +101,7 @@ static CHECK_RESULT int parser_parse_function_decl(Parser *self, FunctionDecl **
}
/*
-FUNC_CALL = IDENTIFIER '(' ARGS* ')'
+FUNC_CALL = IDENTIFIER '(' RHS* ')'
*/
static CHECK_RESULT int parser_parse_function_call(Parser *self, FunctionCall **func_call) {
bool result;
@@ -127,6 +127,7 @@ IMPORT = IMPORT_SYMBOL
*/
static CHECK_RESULT int parser_parse_import(Parser *self, Import **import) {
bool result;
+ *import = NULL;
return_if_error(tokenizer_consume_if(&self->tokenizer, TOK_IMPORT, &result));
if(!result)
@@ -138,20 +139,25 @@ static CHECK_RESULT int parser_parse_import(Parser *self, Import **import) {
}
/*
-RHS = FUNC_DECL | FUNC_CALL | IMPORT
+RHS = CLOSURE | FUNC_CALL | IMPORT
*/
static CHECK_RESULT int parser_parse_rhs(Parser *self, Ast *rhs_expr) {
FunctionDecl *func_decl;
FunctionCall *func_call;
Import *import;
+ /* bool result;*/
- return_if_error(parser_parse_function_decl(self, &func_decl));
- if(func_decl) {
- rhs_expr->type = AST_FUNCTION_DECL;
- rhs_expr->value.func_decl = func_decl;
+/*
+ return_if_error(tokenizer_consume_if(&self->tokenizer, TOK_STRING, &result));
+ if(result) {
+ String *string;
+ return_if_error(scoped_allocator_alloc(self->allocator, sizeof(String), (void**)&string));
+ string_init(string, self->tokenizer.value.string);
+ rhs_expr->type = AST_STRING;
+ rhs_expr->value.string = func_call;
return PARSER_OK;
}
-
+*/
return_if_error(parser_parse_function_call(self, &func_call));
if(func_call) {
rhs_expr->type = AST_FUNCTION_CALL;
@@ -159,6 +165,13 @@ static CHECK_RESULT int parser_parse_rhs(Parser *self, Ast *rhs_expr) {
return PARSER_OK;
}
+ return_if_error(parser_parse_function_decl(self, &func_decl));
+ if(func_decl) {
+ rhs_expr->type = AST_FUNCTION_DECL;
+ rhs_expr->value.func_decl = func_decl;
+ return PARSER_OK;
+ }
+
return_if_error(parser_parse_import(self, &import));
if(import) {
rhs_expr->type = AST_IMPORT;