summaryrefslogtreecommitdiffstats
path: root/Tools/peg_generator
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-05-26 23:15:52 (GMT)
committerGitHub <noreply@github.com>2020-05-26 23:15:52 (GMT)
commit404b23b85b17c84e022779f31fc89cb0ed0d37e8 (patch)
treefea9aca0072a7f5f06a5af49b36b434185d7e76c /Tools/peg_generator
parent21fda91f8da96406e6a912f7c312424209c19bef (diff)
downloadcpython-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.py11
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",