Skip to content

Commit

Permalink
Parse some more keyword types
Browse files Browse the repository at this point in the history
  • Loading branch information
N00byEdge committed Oct 8, 2023
1 parent 3b172b0 commit 6bcd56a
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions selfhost/tokenizer.n
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const TokenType = enum(u8) {
if_keyword,
inline_keyword,
loop_keyword,
//noreturn_keyword,
return_keyword,
//struct_keyword,
//switch_keyword,
Expand All @@ -40,10 +39,11 @@ const TokenType = enum(u8) {
while_keyword,
__keyword,

//bool_keyword,
//type_keyword,
//void_keyword,
//anyopaque_keyword,
bool_keyword,
type_keyword,
void_keyword,
noreturn_keyword,
anyopaque_keyword,

// Single- or multi-character tokens
@".",
Expand Down Expand Up @@ -220,10 +220,22 @@ fn init() void {
}
}.&;

token_handlers['a'] = fn(context: *TokenizationContext) void {
if(context.matches("anyopaque".&)) {
context.add_token_advance(.anyopaque_keyword, 9);
}
else {
ident_handler(context);
}
}.&;

token_handlers['b'] = fn(context: *TokenizationContext) void {
if(context.matches("break".&)) {
context.add_token_advance(.break_keyword, 5);
}
else if(context.matches("bool".&)) {
context.add_token_advance(.bool_keyword, 4);
}
else {
ident_handler(context);
}
Expand Down Expand Up @@ -283,6 +295,15 @@ fn init() void {
}
}.&;

token_handlers['n'] = fn(context: *TokenizationContext) void {
if(context.matches("noreturn".&)) {
context.add_token_advance(.noreturn_keyword, 8);
}
else {
ident_handler(context);
}
}.&;

token_handlers['r'] = fn(context: *TokenizationContext) void {
if(context.matches("return".&)) {
context.add_token_advance(.return_keyword, 6);
Expand All @@ -292,6 +313,15 @@ fn init() void {
}
}.&;

token_handlers['t'] = fn(context: *TokenizationContext) void {
if(context.matches("type".&)) {
context.add_token_advance(.type_keyword, 4);
}
else {
ident_handler(context);
}
}.&;

token_handlers['u'] = fn(context: *TokenizationContext) void {
if(context.matches("undefined".&)) {
context.add_token_advance(.undefined_keyword, 9);
Expand All @@ -308,6 +338,9 @@ fn init() void {
if(context.matches("var".&)) {
context.add_token_advance(.var_keyword, 3);
}
else if(context.matches("void".&)) {
context.add_token_advance(.void_keyword, 4);
}
else {
ident_handler(context);
}
Expand Down

0 comments on commit 6bcd56a

Please sign in to comment.