diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-05-26 23:15:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-26 23:15:52 (GMT) |
commit | 404b23b85b17c84e022779f31fc89cb0ed0d37e8 (patch) | |
tree | fea9aca0072a7f5f06a5af49b36b434185d7e76c /Tools/peg_generator | |
parent | 21fda91f8da96406e6a912f7c312424209c19bef (diff) | |
download | cpython-404b23b85b17c84e022779f31fc89cb0ed0d37e8.zip cpython-404b23b85b17c84e022779f31fc89cb0ed0d37e8.tar.gz cpython-404b23b85b17c84e022779f31fc89cb0ed0d37e8.tar.bz2 |
Fix lookahead of soft keywords in the PEG parser (GH-20436)
Automerge-Triggered-By: @gvanrossum
Diffstat (limited to 'Tools/peg_generator')
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 885ff05..ce1d6bb 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -58,7 +58,8 @@ class NodeTypes(Enum): STRING_TOKEN = 2 GENERIC_TOKEN = 3 KEYWORD = 4 - CUT_OPERATOR = 5 + SOFT_KEYWORD = 5 + CUT_OPERATOR = 6 BASE_NODETYPES = { @@ -123,7 +124,7 @@ class CCallMakerVisitor(GrammarVisitor): function="_PyPegen_expect_soft_keyword", arguments=["p", value], return_type="expr_ty", - nodetype=NodeTypes.NAME_TOKEN, + nodetype=NodeTypes.SOFT_KEYWORD, comment=f"soft_keyword='{value}'", ) @@ -217,6 +218,12 @@ class CCallMakerVisitor(GrammarVisitor): arguments=[positive, call.function, *call.arguments], return_type="int", ) + elif call.nodetype == NodeTypes.SOFT_KEYWORD: + return FunctionCall( + function=f"_PyPegen_lookahead_with_string", + arguments=[positive, call.function, *call.arguments], + return_type="int", + ) elif call.nodetype in {NodeTypes.GENERIC_TOKEN, NodeTypes.KEYWORD}: return FunctionCall( function=f"_PyPegen_lookahead_with_int", |