Fix lookahead of soft keywords in the PEG parser (GH-20436)

Automerge-Triggered-By: @gvanrossum
This commit is contained in:
Pablo Galindo 2020-05-27 00:15:52 +01:00 committed by GitHub
parent 21fda91f8d
commit 404b23b85b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 2 deletions

View file

@ -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",