summaryrefslogtreecommitdiff
path: root/src/lexer.c
diff options
context:
space:
mode:
authorCarlos Maniero <carlos@maniero.me>2023-05-03 23:17:50 -0300
committerJohnny Richard <johnny@johnnyrichard.com>2023-05-04 21:47:51 +0200
commite2e0ed950bb147ebca3b9ac879268feeb185e20b (patch)
treed6888d4468d75a9d4498f20976b66a3d4bd8575a /src/lexer.c
parent8655b77d57ace45d4d040ef297cf172f3c12f4bd (diff)
parser: Introduce statement keywords
This commit introduces a few changes in pipalang syntax. Now, both functions and variables requires keywords to be defined. before: main(): i32 { a: i32 = 2; return a; } now: fn main(): i32 { let a: i32 = 2; return a; } Signed-off-by: Carlos Maniero <carlos@maniero.me> Reviewed-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/lexer.c')
-rw-r--r--src/lexer.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 3f6948a..56e24af 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -97,10 +97,18 @@ lexer_tokenize_name(lexer_t *lexer, token_t *token)
static void
lexer_token_process_keyword(token_t *token)
{
+ if (string_view_eq(string_view_from_str("let"), token->value)) {
+ token->kind = TOKEN_KEYWORD_LET;
+ return;
+ }
if (string_view_eq(string_view_from_str("return"), token->value)) {
token->kind = TOKEN_KEYWORD_RETURN;
return;
}
+ if (string_view_eq(string_view_from_str("fn"), token->value)) {
+ token->kind = TOKEN_KEYWORD_FN;
+ return;
+ }
}
void
@@ -318,6 +326,10 @@ token_kind_to_str(token_kind_t kind)
return "=";
case TOKEN_KEYWORD_RETURN:
return "return";
+ case TOKEN_KEYWORD_FN:
+ return "fn";
+ case TOKEN_KEYWORD_LET:
+ return "let";
case TOKEN_EOF:
return "TOKEN_EOF";
case TOKEN_UNKNOWN: