parse: add some more generic token parser functions

This commit is contained in:
2026-05-12 22:53:26 +01:00
parent 440561cb39
commit 39457aa7e6
+30
View File
@@ -126,6 +126,36 @@ bool parse_keyword(struct parse_ctx *ctx, enum token_keyword kw)
return true;
}
bool parse_word(struct parse_ctx *ctx, struct lex_token **out)
{
struct lex_token *tok = peek_token(ctx);
if (!tok) {
return false;
}
if (tok->tok_type != TOK_WORD) {
return false;
}
*out = claim_token(ctx);
return true;
}
bool parse_var(struct parse_ctx *ctx, struct lex_token **out)
{
struct lex_token *tok = peek_token(ctx);
if (!tok) {
return false;
}
if (tok->tok_type != TOK_VAR) {
return false;
}
*out = claim_token(ctx);
return true;
}
bool parse_int(struct parse_ctx *ctx, long long *out)
{
struct lex_token *tok = peek_token(ctx);