diff options
| author | Mel <mel@rnrd.eu> | 2025-06-14 00:14:58 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-06-14 00:14:58 +0200 |
| commit | 4a49045f77b5be5d82e84c6e3e57721686ec5a0a (patch) | |
| tree | 3143861a9a6d66e6acbe8c7273aaa0bbc0e486bc /boot/tree.c | |
| parent | 3e7acb02962b05db8cf83e5b6b082ac368c8c88e (diff) | |
| download | catskill-4a49045f77b5be5d82e84c6e3e57721686ec5a0a.tar.zst catskill-4a49045f77b5be5d82e84c6e3e57721686ec5a0a.zip | |
Disambiguate variable declaration and call/array access syntax with `var` + `let`
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/tree.c')
| -rw-r--r-- | boot/tree.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/boot/tree.c b/boot/tree.c index 449f4e6..dff0858 100644 --- a/boot/tree.c +++ b/boot/tree.c @@ -912,8 +912,30 @@ struct Statement_Value_Expression struct Expression* inner; }; +enum Statement_Declaration_Kind +{ + STATEMENT_DECLARATION_NONE, + STATEMENT_DECLARATION_VARIABLE, + STATEMENT_DECLARATION_CONSTANT, +}; + +enum Statement_Declaration_Kind +statement_declaration_kind_from_token(const struct Token* token) +{ + switch (token->kind) { + case TOKEN_WORD_VAR: + return STATEMENT_DECLARATION_VARIABLE; + case TOKEN_WORD_LET: + return STATEMENT_DECLARATION_CONSTANT; + + default: + return STATEMENT_DECLARATION_NONE; + } +} + struct Statement_Value_Declaration { + enum Statement_Declaration_Kind kind; struct String_Array names; struct Expression* initializer; struct Type_Node* type; @@ -1042,6 +1064,11 @@ statement_print(const struct Statement* statement) } case STATEMENT_DECLARATION: { printf("(declaration "); + if (statement->value.declaration.kind == STATEMENT_DECLARATION_VARIABLE) + printf("variable "); + else if (statement->value.declaration.kind == STATEMENT_DECLARATION_CONSTANT) + printf("constant "); + STRING_ARRAY_FOR_EACH(i, name, statement->value.declaration.names) { printf("%s ", name.data); |
