harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 450e8d7df17ee805e2a3c0d1cde84864b03e8c70
parent 56e3c4ea3d2096cce28bbda2ef626f1112f6c34d
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 22 Nov 2020 08:48:37 -0500

parse: add 'want' function

Diffstat:
Msrc/parse.c | 13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/parse.c b/src/parse.c @@ -46,6 +46,17 @@ synassert(bool cond, struct token *tok, ...) } static void +want(struct parser *par, enum lexical_token ltok, struct token *tok) +{ + struct token _tok = {0}; + lex(par->lex, tok ? tok : &_tok); + synassert(tok->token == ltok, tok ? tok : &_tok, ltok, T_EOF); + if (!tok) { + token_finish(&_tok); + } +} + +static void parse_identifier(struct parser *par, struct identifier *ident) { struct token tok = {0}; @@ -53,7 +64,7 @@ parse_identifier(struct parser *par, struct identifier *ident) trace(par, "identifier"); while (true) { - synassert(lex(par->lex, &tok) == T_NAME, &tok, T_NAME, T_EOF); + want(par, T_NAME, &tok); i->name = strdup(tok.name); token_finish(&tok);