From 581c50abbbd41611eeadf6c600fa726171dcdc7a Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Mon, 2 Sep 2024 23:40:20 +0200 Subject: [PATCH] expression: Allow for paren'd expressions --- flamingo/grammar/expr.h | 7 ++++++- hello_world.fl | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/flamingo/grammar/expr.h b/flamingo/grammar/expr.h index 717ebe7..4d160c0 100644 --- a/flamingo/grammar/expr.h +++ b/flamingo/grammar/expr.h @@ -27,11 +27,16 @@ static int parse_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t** val) { return parse_identifier(flamingo, child, val); } - // These expressions do have side-effects, so we need to parse them anyway. + // These expressions could have side-effects, so we need to parse them anyway. if (strcmp(type, "call") == 0) { return parse_call(flamingo, child, val); } + if (strcmp(type, "parenthesized_expression") == 0) { + TSNode const grandchild = ts_node_child_by_field_name(child, "expression", 10); + return parse_expr(flamingo, grandchild, val); + } + return error(flamingo, "unknown expression type: %s", type); } diff --git a/hello_world.fl b/hello_world.fl index 6271751..420e602 100644 --- a/hello_world.fl +++ b/hello_world.fl @@ -8,8 +8,8 @@ fn do_nothing(a: str, b: str) { do_nothing("test1", "test2") fn no_args(x: str) { - print "b4" - return x # TODO return none + print("b4") + return(x) # TODO return none print "a4" }