about summary refs log tree commit diff
path: root/boot/parse.c
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2025-06-03 01:46:34 +0200
committerMel <mel@rnrd.eu>2025-06-03 01:46:34 +0200
commitf4bcdb0373ac34349c6ecdb9a894c561e0cd419c (patch)
treeada9099eec92d0824b1943ff4ec453cc9682c2bd /boot/parse.c
parenta9b5fef2eb126500974a1cfe9ce4a8f7cc6e0490 (diff)
downloadcatskill-f4bcdb0373ac34349c6ecdb9a894c561e0cd419c.tar.zst
catskill-f4bcdb0373ac34349c6ecdb9a894c561e0cd419c.zip
Parse and lex ++, --, ** operators, with prefix and postfix handling
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/parse.c')
-rw-r--r--boot/parse.c39
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);
 }