diff options
Diffstat (limited to 'Parser/pegen.c')
-rw-r--r-- | Parser/pegen.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/Parser/pegen.c b/Parser/pegen.c index 2554273..68f0e32 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -782,7 +782,6 @@ _PyPegen_is_memoized(Parser *p, int type, void *pres) return 0; } - int _PyPegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p) { @@ -836,6 +835,28 @@ _PyPegen_expect_token(Parser *p, int type) return t; } +Token * +_PyPegen_expect_forced_token(Parser *p, int type, const char* expected) { + + if (p->error_indicator == 1) { + return NULL; + } + + if (p->mark == p->fill) { + if (_PyPegen_fill_token(p) < 0) { + p->error_indicator = 1; + return NULL; + } + } + Token *t = p->tokens[p->mark]; + if (t->type != type) { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(t, "expected '%s'", expected); + return NULL; + } + p->mark += 1; + return t; +} + expr_ty _PyPegen_expect_soft_keyword(Parser *p, const char *keyword) { |