From 39457aa7e61fa1fd7157a9454ec1780ffc8c87be Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 12 May 2026 22:53:26 +0100 Subject: [PATCH] parse: add some more generic token parser functions --- bshell/parse/syntax/generic.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bshell/parse/syntax/generic.c b/bshell/parse/syntax/generic.c index 2eda2ef..27125d2 100644 --- a/bshell/parse/syntax/generic.c +++ b/bshell/parse/syntax/generic.c @@ -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);