diff options
Diffstat (limited to 'boot/parse.c')
| -rw-r--r-- | boot/parse.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/boot/parse.c b/boot/parse.c index 07b6e58..1c42352 100644 --- a/boot/parse.c +++ b/boot/parse.c @@ -439,14 +439,31 @@ parser_expression_postfix(struct Parser* p, struct Parser_Error* error) { struct Expression* expression = CHECK(parser_expression_member(p, error)); - switch (parser_peek(p).kind) { + struct Token token = parser_peek(p); + switch (token.kind) { case TOKEN_ROUND_OPEN: return parser_expression_postfix_call(p, expression, error); case TOKEN_SQUARE_OPEN: return parser_expression_postfix_subscript(p, expression, error); - default: - return expression; + default:; + } + + enum Increment_Decrement_Operation inc_dec_op = + increment_decrement_operation_from_token(&token); + if (inc_dec_op) { + parser_next(p); + struct Expression_Increment_Decrement inc_dec = { + .prefix = false, + .subject = expression, + .operation = inc_dec_op, + }; + + struct Span span = span_merge(expression->span, token.span); + union Expression_Value value = { .increment_decrement = inc_dec }; + return expression_new(EXPRESSION_INCREMENT_DECREMENT, value, span, token.location); } + + return expression; } struct Expression* @@ -463,6 +480,22 @@ parser_expression_unary_operation(struct Parser* p, struct Parser_Error* error) return expression_new(EXPRESSION_UNARY_OPERATION, value, span, token.location); } + enum Increment_Decrement_Operation inc_dec_op = + increment_decrement_operation_from_token(&token); + if (inc_dec_op) { + parser_next(p); + struct Expression* subject = CHECK(parser_expression_unary_operation(p, error)); + struct Expression_Increment_Decrement inc_dec = { + .prefix = true, + .subject = subject, + .operation = inc_dec_op, + }; + + struct Span span = span_merge(token.span, inc_dec.subject->span); + union Expression_Value value = { .increment_decrement = inc_dec }; + return expression_new(EXPRESSION_INCREMENT_DECREMENT, value, span, token.location); + } + return parser_expression_postfix(p, error); } |
