From 4a49045f77b5be5d82e84c6e3e57721686ec5a0a Mon Sep 17 00:00:00 2001 From: Mel Date: Sat, 14 Jun 2025 00:14:58 +0200 Subject: Disambiguate variable declaration and call/array access syntax with `var` + `let` Signed-off-by: Mel --- boot/lex.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'boot/lex.c') diff --git a/boot/lex.c b/boot/lex.c index 52760e9..f09e5e3 100644 --- a/boot/lex.c +++ b/boot/lex.c @@ -97,6 +97,7 @@ enum Token_Kind TOKEN_WORD_SWITCH, TOKEN_WORD_RETURN, TOKEN_WORD_VAR, + TOKEN_WORD_LET, TOKEN_WORD_TYPE, TOKEN_WORD_VARIANT, TOKEN_WORD_CLASS, @@ -200,6 +201,8 @@ token_kind_to_string(enum Token_Kind kind) return "WORD_RETURN"; case TOKEN_WORD_VAR: return "WORD_VAR"; + case TOKEN_WORD_LET: + return "WORD_LET"; case TOKEN_WORD_TYPE: return "WORD_TYPE"; case TOKEN_WORD_VARIANT: @@ -406,6 +409,12 @@ token_can_begin_type(const struct Token* t) } } +bool +token_can_begin_declaration(const struct Token* t) +{ + return token_is(t, TOKEN_WORD_VAR) || token_is(t, TOKEN_WORD_LET); +} + bool ascii_in_range(ascii c, ascii from, ascii to) { @@ -793,6 +802,8 @@ lexer_word_from_name(struct Lexer* l, struct String word_or_name) return TOKEN_WORD_RETURN; case 1662845996: // "var" return TOKEN_WORD_VAR; + case 860722406: + return TOKEN_WORD_LET; case 91700392: // "type" return TOKEN_WORD_TYPE; case 3267162257: // "variant" -- cgit 1.4.1