Skip to content

Commit

Permalink
parser: added is_keyword() for token kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdberg committed Jan 22, 2025
1 parent 7632696 commit de003b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion parser/c2_parser.c2
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,13 @@ fn void Parser.parseFullTypeIdentifier(Parser* p, TypeRefHolder* ref) {
}

fn void Parser.dump_token(Parser* p, const Token* tok) @(unused) {
if (tok.kind >= Kind.KW_bool && tok.kind <= Kind.KW_while) {
if (is_keyword(tok.kind)) {
printf("%s%12s%s %6d %s",
color.Green, kind2str(tok.kind), color.Normal, tok.loc, p.sm.loc2str(tok.loc));
} else {
printf("%12s %6d %s ", kind2str(tok.kind), tok.loc, p.sm.loc2str(tok.loc));
}

switch (tok.kind) {
case Identifier:
printf(" %s%s%s", color.Cyan, p.pool.idx2str(tok.text_idx), color.Normal);
Expand Down
4 changes: 4 additions & 0 deletions parser/token.c2
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public type Kind enum u8 {
Error,
}

public fn bool is_keyword(Kind k) {
return k >= Kind.KW_bool && k <= Kind.KW_while;
}

// NOTE: keep in sync with TokenKind
const char*[] token_names = {
[Kind.None] = "none",
Expand Down

0 comments on commit de003b9

Please sign in to comment.