mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Fix lookahead of soft keywords in the PEG parser (GH-20436)
Automerge-Triggered-By: @gvanrossum
This commit is contained in:
parent
21fda91f8d
commit
404b23b85b
4 changed files with 31 additions and 2 deletions
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue