Fix lookahead of soft keywords in the PEG parser · python/cpython@cba7301 · GitHub
Skip to content

Commit cba7301

Browse files
committed
Fix lookahead of soft keywords in the PEG parser
1 parent b45af1a commit cba7301

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

Lib/test/test_peg_generator/test_c_parser.py

Lines changed: 12 additions & 0 deletions

Parser/pegen/pegen.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,15 @@ _PyPegen_lookahead_with_name(int positive, expr_ty (func)(Parser *), Parser *p)
718718
return (res != NULL) == positive;
719719
}
720720

721+
int
722+
_PyPegen_lookahead_with_string(int positive, expr_ty (func)(Parser *, const char*), Parser *p, const char* arg)
723+
{
724+
int mark = p->mark;
725+
void *res = func(p, arg);
726+
p->mark = mark;
727+
return (res != NULL) == positive;
728+
}
729+
721730
int
722731
_PyPegen_lookahead_with_int(int positive, Token *(func)(Parser *, int), Parser *p, int arg)
723732
{

Parser/pegen/pegen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ int _PyPegen_is_memoized(Parser *p, int type, void *pres);
119119

120120
int _PyPegen_lookahead_with_name(int, expr_ty (func)(Parser *), Parser *);
121121
int _PyPegen_lookahead_with_int(int, Token *(func)(Parser *, int), Parser *, int);
122+
int _PyPegen_lookahead_with_string(int , expr_ty (func)(Parser *, const char*), Parser *, const char*);
122123
int _PyPegen_lookahead(int, void *(func)(Parser *), Parser *);
123124

124125
Token *_PyPegen_expect_token(Parser *p, int type);

Tools/peg_generator/pegen/c_generator.py

Lines changed: 9 additions & 2 deletions

0 commit comments

Comments
 (0)