parse: add some more generic token parser functions
This commit is contained in:
@@ -126,6 +126,36 @@ bool parse_keyword(struct parse_ctx *ctx, enum token_keyword kw)
|
|||||||
return true;
|
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)
|
bool parse_int(struct parse_ctx *ctx, long long *out)
|
||||||
{
|
{
|
||||||
struct lex_token *tok = peek_token(ctx);
|
struct lex_token *tok = peek_token(ctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user