From 9676d1ca61b025af9e52506f8aec1f9c0792f51c Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 12 Jun 2025 17:14:12 +0200 Subject: Parse most primitive types into tree Signed-off-by: Mel --- boot/lex.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'boot/lex.c') diff --git a/boot/lex.c b/boot/lex.c index 6b6badc..52760e9 100644 --- a/boot/lex.c +++ b/boot/lex.c @@ -98,6 +98,8 @@ enum Token_Kind TOKEN_WORD_RETURN, TOKEN_WORD_VAR, TOKEN_WORD_TYPE, + TOKEN_WORD_VARIANT, + TOKEN_WORD_CLASS, TOKEN_WORD_TRUE, TOKEN_WORD_FALSE, @@ -200,6 +202,10 @@ token_kind_to_string(enum Token_Kind kind) return "WORD_VAR"; case TOKEN_WORD_TYPE: return "WORD_TYPE"; + case TOKEN_WORD_VARIANT: + return "WORD_VARIANT"; + case TOKEN_WORD_CLASS: + return "WORD_CLASS"; case TOKEN_WORD_TRUE: return "WORD_TRUE"; case TOKEN_WORD_FALSE: @@ -374,6 +380,32 @@ token_ends_statement(const struct Token* t) return token_is(t, TOKEN_END_OF_FILE) || token_is(t, TOKEN_NEWLINE); } +bool +token_can_begin_type(const struct Token* t) +{ + switch (t->kind) { + // named type reference + case TOKEN_NAME: + + // keyword that introduces a type + case TOKEN_WORD_TYPE: + case TOKEN_WORD_VARIANT: + case TOKEN_WORD_CLASS: + case TOKEN_WORD_FUN: + + // arrays, tuples, maps and inline structures + case TOKEN_CURLY_OPEN: + case TOKEN_SQUARE_OPEN: + case TOKEN_ROUND_OPEN: + + // references + case TOKEN_AMPERSAND: + return true; + default: + return false; + } +} + bool ascii_in_range(ascii c, ascii from, ascii to) { @@ -763,6 +795,10 @@ lexer_word_from_name(struct Lexer* l, struct String word_or_name) return TOKEN_WORD_VAR; case 91700392: // "type" return TOKEN_WORD_TYPE; + case 3267162257: // "variant" + return TOKEN_WORD_VARIANT; + case 2938290531: // "class" + return TOKEN_WORD_CLASS; case 2588936279: // "true" return TOKEN_WORD_TRUE; case 1548710142: // "false" -- cgit 1.4.1