diff options
| author | Mel <mel@rnrd.eu> | 2025-06-12 17:14:12 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-06-12 17:14:12 +0200 |
| commit | 9676d1ca61b025af9e52506f8aec1f9c0792f51c (patch) | |
| tree | 1992a522d86019e87363c2b0de2ce37368d27789 /boot/lex.c | |
| parent | 8b655fe0f1d6589c9216a6244c067aec1d866be7 (diff) | |
| download | catskill-9676d1ca61b025af9e52506f8aec1f9c0792f51c.tar.zst catskill-9676d1ca61b025af9e52506f8aec1f9c0792f51c.zip | |
Parse most primitive types into tree
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/lex.c')
| -rw-r--r-- | boot/lex.c | 36 |
1 files changed, 36 insertions, 0 deletions
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: @@ -375,6 +381,32 @@ token_ends_statement(const struct Token* t) } 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) { return c >= from && c <= 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" |
