harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c41b2f8bbfe4bad1adc311cdfe566b3c94aadf11
parent e8edbc22bf9dffe9547d03b86582a4e30e5ff0ed
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Wed, 30 Dec 2020 15:28:24 -0500

parse: fix cast expressions

Specifically `foo: bar: baz`

Diffstat:
Msrc/parse.c | 14++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/parse.c b/src/parse.c @@ -1199,12 +1199,13 @@ parse_unary_expression(struct lexer *lexer) } static struct ast_expression * -parse_cast_expression(struct lexer *lexer) +parse_cast_expression(struct lexer *lexer, struct ast_expression *value) { trace(TR_PARSE, "cast"); - struct ast_expression *value = parse_unary_expression(lexer); + if (value == NULL) { + value = parse_unary_expression(lexer); + } enum cast_kind kind; - struct token tok; switch (lex(lexer, &tok)) { case T_COLON: @@ -1226,7 +1227,7 @@ parse_cast_expression(struct lexer *lexer) exp->cast.kind = kind; exp->cast.value = value; exp->cast.type = parse_type(lexer); - return exp; + return parse_cast_expression(lexer, exp); } static int @@ -1322,7 +1323,7 @@ parse_bin_expression(struct lexer *lexer, struct ast_expression *lvalue, int i) { trace(TR_PARSE, "bin-arithm"); if (!lvalue) { - lvalue = parse_cast_expression(lexer); + lvalue = parse_cast_expression(lexer, NULL); } struct token tok; @@ -1332,7 +1333,8 @@ parse_bin_expression(struct lexer *lexer, struct ast_expression *lvalue, int i) while ((j = precedence(tok.token)) >= i) { enum binarithm_operator op = binop_for_token(tok.token); - struct ast_expression *rvalue = parse_cast_expression(lexer); + struct ast_expression *rvalue = + parse_cast_expression(lexer, NULL); lex(lexer, &tok); int k;