You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Merge pull request #465 from rocky/chained-compare-rename
Chained compare rename
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# In Python 3.3+ this uses grammar rule
|
# In Python 3.3+ this uses grammar rule
|
||||||
# compare_chained2 ::= expr COMPARE_OP RETURN_VALUE
|
# compare_chained_right ::= expr COMPARE_OP RETURN_VALUE
|
||||||
# In Python 3.6 uses this uses grammar rule
|
# In Python 3.6 uses this uses grammar rule
|
||||||
# compare_chained2 ::= expr COMPARE_OP come_froms JUMP_FORWARD
|
# compare_chained_right ::= expr COMPARE_OP come_froms JUMP_FORWARD
|
||||||
|
|
||||||
# Seen in Python 3.3 ipaddress.py
|
# Seen in Python 3.3 ipaddress.py
|
||||||
|
|
||||||
|
@@ -597,9 +597,10 @@ class PythonParser(GenericASTBuilder):
|
|||||||
compare ::= compare_single
|
compare ::= compare_single
|
||||||
compare_single ::= expr expr COMPARE_OP
|
compare_single ::= expr expr COMPARE_OP
|
||||||
|
|
||||||
# A compare_chained is two comparisions like x <= y <= z
|
# A compare_chained is two comparisions, as in: x <= y <= z
|
||||||
compare_chained ::= expr compare_chained1 ROT_TWO POP_TOP _come_froms
|
compare_chained ::= expr compared_chained_middle ROT_TWO POP_TOP
|
||||||
compare_chained2 ::= expr COMPARE_OP JUMP_FORWARD
|
_come_froms
|
||||||
|
compare_chained_right ::= expr COMPARE_OP JUMP_FORWARD
|
||||||
|
|
||||||
# Non-null kvlist items are broken out in the indiviual grammars
|
# Non-null kvlist items are broken out in the indiviual grammars
|
||||||
kvlist ::=
|
kvlist ::=
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2017-2022 Rocky Bernstein
|
# Copyright (c) 2017-2023 Rocky Bernstein
|
||||||
"""
|
"""
|
||||||
spark grammar differences over Python2 for Python 2.6.
|
spark grammar differences over Python2 for Python 2.6.
|
||||||
"""
|
"""
|
||||||
@@ -307,21 +307,22 @@ class Python26Parser(Python2Parser):
|
|||||||
|
|
||||||
and ::= expr JUMP_IF_FALSE POP_TOP expr JUMP_IF_FALSE POP_TOP
|
and ::= expr JUMP_IF_FALSE POP_TOP expr JUMP_IF_FALSE POP_TOP
|
||||||
|
|
||||||
# compare_chained is like x <= y <= z
|
# A "compare_chained" is two comparisions like x <= y <= z
|
||||||
compare_chained ::= expr compare_chained1 ROT_TWO COME_FROM POP_TOP _come_froms
|
compare_chained ::= expr compared_chained_middle ROT_TWO
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
COME_FROM POP_TOP _come_froms
|
||||||
jmp_false compare_chained1 _come_froms
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
jmp_false compared_chained_middle _come_froms
|
||||||
jmp_false compare_chained2 _come_froms
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
|
jmp_false compare_chained_right _come_froms
|
||||||
|
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
jmp_false_then compare_chained1 _come_froms
|
jmp_false_then compared_chained_middle _come_froms
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
jmp_false_then compare_chained2 _come_froms
|
jmp_false_then compare_chained_right _come_froms
|
||||||
|
|
||||||
compare_chained2 ::= expr COMPARE_OP return_expr_lambda
|
compare_chained_right ::= expr COMPARE_OP return_expr_lambda
|
||||||
compare_chained2 ::= expr COMPARE_OP RETURN_END_IF_LAMBDA
|
compare_chained_right ::= expr COMPARE_OP RETURN_END_IF_LAMBDA
|
||||||
compare_chained2 ::= expr COMPARE_OP RETURN_END_IF COME_FROM
|
compare_chained_right ::= expr COMPARE_OP RETURN_END_IF COME_FROM
|
||||||
|
|
||||||
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
|
return_if_lambda ::= RETURN_END_IF_LAMBDA POP_TOP
|
||||||
stmt ::= if_exp_lambda
|
stmt ::= if_exp_lambda
|
||||||
@@ -565,7 +566,7 @@ if __name__ == "__main__":
|
|||||||
remain_tokens = set(tokens) - opcode_set
|
remain_tokens = set(tokens) - opcode_set
|
||||||
import re
|
import re
|
||||||
|
|
||||||
remain_tokens = set([re.sub("_\d+$", "", t) for t in remain_tokens])
|
remain_tokens = set([re.sub(r"_\d+$", "", t) for t in remain_tokens])
|
||||||
remain_tokens = set([re.sub("_CONT$", "", t) for t in remain_tokens])
|
remain_tokens = set([re.sub("_CONT$", "", t) for t in remain_tokens])
|
||||||
remain_tokens = set(remain_tokens) - opcode_set
|
remain_tokens = set(remain_tokens) - opcode_set
|
||||||
print(remain_tokens)
|
print(remain_tokens)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2016-2020, 2022 Rocky Bernstein
|
# Copyright (c) 2016-2020, 2023 Rocky Bernstein
|
||||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||||
# Copyright (c) 2000-2002 by hartmut Goebel <hartmut@goebel.noris.de>
|
# Copyright (c) 2000-2002 by hartmut Goebel <hartmut@goebel.noris.de>
|
||||||
|
|
||||||
@@ -115,17 +115,18 @@ class Python27Parser(Python2Parser):
|
|||||||
or ::= expr_jitop expr COME_FROM
|
or ::= expr_jitop expr COME_FROM
|
||||||
and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM
|
and ::= expr JUMP_IF_FALSE_OR_POP expr COME_FROM
|
||||||
|
|
||||||
# compare_chained{1,2} is used exclusively in chained_compare
|
# compare_chained{middle,2} is used exclusively in chained_compare
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
compare_chained1 COME_FROM
|
JUMP_IF_FALSE_OR_POP compared_chained_middle
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
COME_FROM
|
||||||
compare_chained2 COME_FROM
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
|
JUMP_IF_FALSE_OR_POP compare_chained_right COME_FROM
|
||||||
|
|
||||||
return_lambda ::= RETURN_VALUE
|
return_lambda ::= RETURN_VALUE
|
||||||
return_lambda ::= RETURN_VALUE_LAMBDA
|
return_lambda ::= RETURN_VALUE_LAMBDA
|
||||||
|
|
||||||
compare_chained2 ::= expr COMPARE_OP return_lambda
|
compare_chained_right ::= expr COMPARE_OP return_lambda
|
||||||
compare_chained2 ::= expr COMPARE_OP return_lambda
|
compare_chained_right ::= expr COMPARE_OP return_lambda
|
||||||
|
|
||||||
# if_exp_true are for conditions which always evaluate true
|
# if_exp_true are for conditions which always evaluate true
|
||||||
# There is dead or non-optional remnants of the condition code though,
|
# There is dead or non-optional remnants of the condition code though,
|
||||||
@@ -177,11 +178,13 @@ class Python27Parser(Python2Parser):
|
|||||||
while1stmt ::= SETUP_LOOP returns pb_come_from
|
while1stmt ::= SETUP_LOOP returns pb_come_from
|
||||||
while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM
|
while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM
|
||||||
|
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK _come_froms
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
|
||||||
|
_come_froms
|
||||||
|
|
||||||
# Should this be JUMP_BACK+ ?
|
# Should this be JUMP_BACK+ ?
|
||||||
# JUMP_BACK should all be to the same location
|
# JUMP_BACK should all be to the same location
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK JUMP_BACK POP_BLOCK _come_froms
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK
|
||||||
|
JUMP_BACK POP_BLOCK _come_froms
|
||||||
|
|
||||||
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK
|
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK
|
||||||
else_suitel COME_FROM
|
else_suitel COME_FROM
|
||||||
|
@@ -346,14 +346,15 @@ class Python3Parser(PythonParser):
|
|||||||
# FIXME: Common with 2.7
|
# FIXME: Common with 2.7
|
||||||
ret_and ::= expr JUMP_IF_FALSE_OR_POP return_expr_or_cond COME_FROM
|
ret_and ::= expr JUMP_IF_FALSE_OR_POP return_expr_or_cond COME_FROM
|
||||||
ret_or ::= expr JUMP_IF_TRUE_OR_POP return_expr_or_cond COME_FROM
|
ret_or ::= expr JUMP_IF_TRUE_OR_POP return_expr_or_cond COME_FROM
|
||||||
if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM return_expr_or_cond
|
if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF COME_FROM
|
||||||
|
return_expr_or_cond
|
||||||
|
|
||||||
|
|
||||||
# compare_chained1 is used exclusively in chained_compare
|
# compared_chained_middle is used exclusively in chained_compare
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
||||||
compare_chained1 COME_FROM
|
compared_chained_middle COME_FROM
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
||||||
compare_chained2 COME_FROM
|
compare_chained_right COME_FROM
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_stmt3(self, args):
|
def p_stmt3(self, args):
|
||||||
@@ -419,24 +420,24 @@ class Python3Parser(PythonParser):
|
|||||||
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
|
|
||||||
forelsestmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suite
|
forelsestmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
||||||
COME_FROM_LOOP
|
else_suite COME_FROM_LOOP
|
||||||
|
|
||||||
forelselaststmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitec
|
forelselaststmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
||||||
COME_FROM_LOOP
|
else_suitec COME_FROM_LOOP
|
||||||
|
|
||||||
forelselaststmtl ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitel
|
forelselaststmtl ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
||||||
COME_FROM_LOOP
|
else_suitel COME_FROM_LOOP
|
||||||
|
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK
|
||||||
COME_FROM_LOOP
|
POP_BLOCK COME_FROM_LOOP
|
||||||
|
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK JUMP_BACK
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
|
||||||
COME_FROM_LOOP
|
JUMP_BACK COME_FROM_LOOP
|
||||||
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
|
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
|
||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
|
|
||||||
whilestmt ::= SETUP_LOOP testexpr returns POP_BLOCK
|
whilestmt ::= SETUP_LOOP testexpr returns POP_BLOCK
|
||||||
COME_FROM_LOOP
|
COME_FROM_LOOP
|
||||||
|
|
||||||
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK
|
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK
|
||||||
|
@@ -14,13 +14,14 @@ class Python30Parser(Python31Parser):
|
|||||||
|
|
||||||
pt_bp ::= POP_TOP POP_BLOCK
|
pt_bp ::= POP_TOP POP_BLOCK
|
||||||
|
|
||||||
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1 COME_FROM POP_TOP
|
assert ::= assert_expr jmp_true LOAD_ASSERT RAISE_VARARGS_1
|
||||||
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1 RAISE_VARARGS_1
|
COME_FROM POP_TOP
|
||||||
come_froms
|
assert2 ::= assert_expr jmp_true LOAD_ASSERT expr CALL_FUNCTION_1
|
||||||
|
RAISE_VARARGS_1 come_froms
|
||||||
call_stmt ::= expr _come_froms POP_TOP
|
call_stmt ::= expr _come_froms POP_TOP
|
||||||
|
|
||||||
return_if_lambda ::= RETURN_END_IF_LAMBDA COME_FROM POP_TOP
|
return_if_lambda ::= RETURN_END_IF_LAMBDA COME_FROM POP_TOP
|
||||||
compare_chained2 ::= expr COMPARE_OP RETURN_END_IF_LAMBDA
|
compare_chained_right ::= expr COMPARE_OP RETURN_END_IF_LAMBDA
|
||||||
|
|
||||||
# FIXME: combine with parse3.2
|
# FIXME: combine with parse3.2
|
||||||
whileTruestmt ::= SETUP_LOOP l_stmts_opt
|
whileTruestmt ::= SETUP_LOOP l_stmts_opt
|
||||||
@@ -205,12 +206,12 @@ class Python30Parser(Python31Parser):
|
|||||||
come_froms POP_TOP POP_BLOCK COME_FROM_LOOP
|
come_froms POP_TOP POP_BLOCK COME_FROM_LOOP
|
||||||
|
|
||||||
|
|
||||||
# compare_chained is like x <= y <= z
|
# A "compare_chained" is two comparisions like x <= y <= z
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
jmp_false compare_chained1 _come_froms
|
jmp_false compared_chained_middle _come_froms
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
jmp_false compare_chained2 _come_froms
|
jmp_false compare_chained_right _come_froms
|
||||||
compare_chained2 ::= expr COMPARE_OP RETURN_END_IF
|
compare_chained_right ::= expr COMPARE_OP RETURN_END_IF
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@@ -270,10 +271,11 @@ class Python30Parser(Python31Parser):
|
|||||||
jmp_true ::= JUMP_IF_TRUE_OR_POP POP_TOP
|
jmp_true ::= JUMP_IF_TRUE_OR_POP POP_TOP
|
||||||
jmp_true ::= POP_JUMP_IF_TRUE
|
jmp_true ::= POP_JUMP_IF_TRUE
|
||||||
|
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
compare_chained1 COME_FROM
|
JUMP_IF_FALSE_OR_POP compared_chained_middle
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
COME_FROM
|
||||||
compare_chained2 COME_FROM
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP
|
||||||
|
JUMP_IF_FALSE_OR_POP compare_chained_right COME_FROM
|
||||||
ret_or ::= expr JUMP_IF_TRUE_OR_POP return_expr_or_cond COME_FROM
|
ret_or ::= expr JUMP_IF_TRUE_OR_POP return_expr_or_cond COME_FROM
|
||||||
ret_and ::= expr JUMP_IF_FALSE_OR_POP return_expr_or_cond COME_FROM
|
ret_and ::= expr JUMP_IF_FALSE_OR_POP return_expr_or_cond COME_FROM
|
||||||
if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF
|
if_exp_ret ::= expr POP_JUMP_IF_FALSE expr RETURN_END_IF
|
||||||
|
@@ -25,10 +25,9 @@ class Python32Parser(Python3Parser):
|
|||||||
"""
|
"""
|
||||||
if_exp ::= expr jmp_false expr jump_forward_else expr COME_FROM
|
if_exp ::= expr jmp_false expr jump_forward_else expr COME_FROM
|
||||||
|
|
||||||
# compare_chained2 is used in a "chained_compare": x <= y <= z
|
# compare_chained_right is used in a "chained_compare": x <= y <= z
|
||||||
# used exclusively in compare_chained
|
compare_chained_right ::= expr COMPARE_OP RETURN_VALUE
|
||||||
compare_chained2 ::= expr COMPARE_OP RETURN_VALUE
|
compare_chained_right ::= expr COMPARE_OP RETURN_VALUE_LAMBDA
|
||||||
compare_chained2 ::= expr COMPARE_OP RETURN_VALUE_LAMBDA
|
|
||||||
|
|
||||||
# Python < 3.5 no POP BLOCK
|
# Python < 3.5 no POP BLOCK
|
||||||
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP
|
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP
|
||||||
|
@@ -190,7 +190,7 @@ class Python36Parser(Python35Parser):
|
|||||||
tryfinally_return_stmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST
|
tryfinally_return_stmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST
|
||||||
COME_FROM_FINALLY
|
COME_FROM_FINALLY
|
||||||
|
|
||||||
compare_chained2 ::= expr COMPARE_OP come_froms JUMP_FORWARD
|
compare_chained_right ::= expr COMPARE_OP come_froms JUMP_FORWARD
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Some of this is duplicated from parse37. Eventually we'll probably rebase from
|
# Some of this is duplicated from parse37. Eventually we'll probably rebase from
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2017-2020, 2022 Rocky Bernstein
|
# Copyright (c) 2017-2020, 2022-2023 Rocky Bernstein
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@@ -130,7 +130,8 @@ class Python37Parser(Python37BaseParser):
|
|||||||
stmt ::= return
|
stmt ::= return
|
||||||
return ::= return_expr RETURN_VALUE
|
return ::= return_expr RETURN_VALUE
|
||||||
|
|
||||||
# "returns" nonterminal is a sequence of statements that ends in a RETURN statement.
|
# "returns" nonterminal is a sequence of statements that ends in a
|
||||||
|
# RETURN statement.
|
||||||
# In later Python versions with jump optimization, this can cause JUMPs
|
# In later Python versions with jump optimization, this can cause JUMPs
|
||||||
# that would normally appear to be omitted.
|
# that would normally appear to be omitted.
|
||||||
|
|
||||||
@@ -221,8 +222,8 @@ class Python37Parser(Python37BaseParser):
|
|||||||
compare_single ::= expr expr COMPARE_OP
|
compare_single ::= expr expr COMPARE_OP
|
||||||
|
|
||||||
# A compare_chained is two comparisions like x <= y <= z
|
# A compare_chained is two comparisions like x <= y <= z
|
||||||
compare_chained ::= expr compare_chained1 ROT_TWO POP_TOP _come_froms
|
compare_chained ::= expr compared_chained_middle ROT_TWO POP_TOP _come_froms
|
||||||
compare_chained2 ::= expr COMPARE_OP JUMP_FORWARD
|
compare_chained_right ::= expr COMPARE_OP JUMP_FORWARD
|
||||||
|
|
||||||
# Non-null kvlist items are broken out in the indiviual grammars
|
# Non-null kvlist items are broken out in the indiviual grammars
|
||||||
kvlist ::=
|
kvlist ::=
|
||||||
@@ -439,10 +440,10 @@ class Python37Parser(Python37BaseParser):
|
|||||||
"""
|
"""
|
||||||
if_exp::= expr jmp_false expr jump_forward_else expr COME_FROM
|
if_exp::= expr jmp_false expr jump_forward_else expr COME_FROM
|
||||||
|
|
||||||
# compare_chained2 is used in a "chained_compare": x <= y <= z
|
# compare_chained_right is used in a "chained_compare": x <= y <= z
|
||||||
# used exclusively in compare_chained
|
# used exclusively in compare_chained
|
||||||
compare_chained2 ::= expr COMPARE_OP RETURN_VALUE
|
compare_chained_right ::= expr COMPARE_OP RETURN_VALUE
|
||||||
compare_chained2 ::= expr COMPARE_OP RETURN_VALUE_LAMBDA
|
compare_chained_right ::= expr COMPARE_OP RETURN_VALUE_LAMBDA
|
||||||
|
|
||||||
# Python < 3.5 no POP BLOCK
|
# Python < 3.5 no POP BLOCK
|
||||||
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP
|
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK COME_FROM_LOOP
|
||||||
@@ -625,41 +626,41 @@ class Python37Parser(Python37BaseParser):
|
|||||||
compare_chained ::= compare_chained37
|
compare_chained ::= compare_chained37
|
||||||
compare_chained ::= compare_chained37_false
|
compare_chained ::= compare_chained37_false
|
||||||
|
|
||||||
compare_chained37 ::= expr compare_chained1a_37
|
compare_chained37 ::= expr compared_chained_middlea_37
|
||||||
compare_chained37 ::= expr compare_chained1c_37
|
compare_chained37 ::= expr compared_chained_middlec_37
|
||||||
|
|
||||||
compare_chained37_false ::= expr compare_chained1_false_37
|
compare_chained37_false ::= expr compared_chained_middle_false_37
|
||||||
compare_chained37_false ::= expr compare_chained1b_false_37
|
compare_chained37_false ::= expr compared_chained_middleb_false_37
|
||||||
compare_chained37_false ::= expr compare_chained2_false_37
|
compare_chained37_false ::= expr compare_chained_right_false_37
|
||||||
|
|
||||||
compare_chained1a_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
compared_chained_middlea_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
||||||
compare_chained1a_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
compared_chained_middlea_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
||||||
compare_chained2a_37 COME_FROM POP_TOP COME_FROM
|
compare_chained_righta_37 COME_FROM POP_TOP COME_FROM
|
||||||
compare_chained1b_false_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
compared_chained_middleb_false_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
||||||
compare_chained2b_false_37 POP_TOP _jump COME_FROM
|
compare_chained_rightb_false_37 POP_TOP _jump COME_FROM
|
||||||
|
|
||||||
compare_chained1c_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
compared_chained_middlec_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
||||||
compare_chained2a_37 POP_TOP
|
compare_chained_righta_37 POP_TOP
|
||||||
|
|
||||||
compare_chained1_false_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
compared_chained_middle_false_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
||||||
compare_chained2c_37 POP_TOP JUMP_FORWARD COME_FROM
|
compare_chained_rightc_37 POP_TOP JUMP_FORWARD COME_FROM
|
||||||
compare_chained1_false_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
compared_chained_middle_false_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
||||||
compare_chained2b_false_37 POP_TOP _jump COME_FROM
|
compare_chained_rightb_false_37 POP_TOP _jump COME_FROM
|
||||||
|
|
||||||
compare_chained2_false_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
compare_chained_right_false_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
||||||
compare_chained2a_false_37 POP_TOP JUMP_BACK COME_FROM
|
compare_chained_righta_false_37 POP_TOP JUMP_BACK COME_FROM
|
||||||
|
|
||||||
compare_chained2a_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_TRUE JUMP_FORWARD
|
compare_chained_righta_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_TRUE JUMP_FORWARD
|
||||||
compare_chained2a_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_TRUE JUMP_BACK
|
compare_chained_righta_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_TRUE JUMP_BACK
|
||||||
compare_chained2a_false_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_FALSE jf_cfs
|
compare_chained_righta_false_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_FALSE jf_cfs
|
||||||
|
|
||||||
compare_chained2b_false_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_FALSE JUMP_FORWARD COME_FROM
|
compare_chained_rightb_false_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_FALSE JUMP_FORWARD COME_FROM
|
||||||
compare_chained2b_false_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_FALSE JUMP_FORWARD
|
compare_chained_rightb_false_37 ::= expr COMPARE_OP come_from_opt POP_JUMP_IF_FALSE JUMP_FORWARD
|
||||||
|
|
||||||
compare_chained2c_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP come_from_opt POP_JUMP_IF_FALSE
|
compare_chained_rightc_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP come_from_opt POP_JUMP_IF_FALSE
|
||||||
compare_chained2a_false_37 ELSE
|
compare_chained_righta_false_37 ELSE
|
||||||
compare_chained2c_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP come_from_opt POP_JUMP_IF_FALSE
|
compare_chained_rightc_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP come_from_opt POP_JUMP_IF_FALSE
|
||||||
compare_chained2a_false_37
|
compare_chained_righta_false_37
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_37_conditionals(self, args):
|
def p_37_conditionals(self, args):
|
||||||
@@ -667,11 +668,13 @@ class Python37Parser(Python37BaseParser):
|
|||||||
expr ::= if_exp37
|
expr ::= if_exp37
|
||||||
if_exp37 ::= expr expr jf_cfs expr COME_FROM
|
if_exp37 ::= expr expr jf_cfs expr COME_FROM
|
||||||
jf_cfs ::= JUMP_FORWARD _come_froms
|
jf_cfs ::= JUMP_FORWARD _come_froms
|
||||||
ifelsestmt ::= testexpr c_stmts_opt jf_cfs else_suite opt_come_from_except
|
ifelsestmt ::= testexpr c_stmts_opt jf_cfs else_suite
|
||||||
|
opt_come_from_except
|
||||||
|
|
||||||
# This is probably more realistically an "ifstmt" (with a null else)
|
# This is probably more realistically an "ifstmt" (with a null else)
|
||||||
# see _cmp() of python3.8/distutils/__pycache__/version.cpython-38.opt-1.pyc
|
# see _cmp() of python3.8/distutils/__pycache__/version.cpython-38.opt-1.pyc
|
||||||
ifelsestmt ::= testexpr stmts jf_cfs else_suite_opt opt_come_from_except
|
ifelsestmt ::= testexpr stmts jf_cfs else_suite_opt
|
||||||
|
opt_come_from_except
|
||||||
|
|
||||||
|
|
||||||
expr_pjit ::= expr POP_JUMP_IF_TRUE
|
expr_pjit ::= expr POP_JUMP_IF_TRUE
|
||||||
@@ -694,7 +697,8 @@ class Python37Parser(Python37BaseParser):
|
|||||||
expr ::= if_exp_37a
|
expr ::= if_exp_37a
|
||||||
expr ::= if_exp_37b
|
expr ::= if_exp_37b
|
||||||
if_exp_37a ::= and_not expr JUMP_FORWARD come_froms expr COME_FROM
|
if_exp_37a ::= and_not expr JUMP_FORWARD come_froms expr COME_FROM
|
||||||
if_exp_37b ::= expr jmp_false expr POP_JUMP_IF_FALSE jump_forward_else expr
|
if_exp_37b ::= expr jmp_false expr POP_JUMP_IF_FALSE
|
||||||
|
jump_forward_else expr
|
||||||
jmp_false_cf ::= POP_JUMP_IF_FALSE COME_FROM
|
jmp_false_cf ::= POP_JUMP_IF_FALSE COME_FROM
|
||||||
comp_if ::= or jmp_false_cf comp_iter
|
comp_if ::= or jmp_false_cf comp_iter
|
||||||
"""
|
"""
|
||||||
@@ -1014,11 +1018,11 @@ class Python37Parser(Python37BaseParser):
|
|||||||
and ::= expr jmp_false expr COME_FROM
|
and ::= expr jmp_false expr COME_FROM
|
||||||
or ::= expr_jt expr COME_FROM
|
or ::= expr_jt expr COME_FROM
|
||||||
|
|
||||||
# compare_chained1 is used exclusively in chained_compare
|
# compared_chained_middle is used exclusively in chained_compare
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
||||||
compare_chained1 COME_FROM
|
compared_chained_middle COME_FROM
|
||||||
compare_chained1 ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
compared_chained_middle ::= expr DUP_TOP ROT_THREE COMPARE_OP JUMP_IF_FALSE_OR_POP
|
||||||
compare_chained2 COME_FROM
|
compare_chained_right COME_FROM
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_stmt3(self, args):
|
def p_stmt3(self, args):
|
||||||
@@ -1205,7 +1209,7 @@ class Python37Parser(Python37BaseParser):
|
|||||||
tryfinally_return_stmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST
|
tryfinally_return_stmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST
|
||||||
COME_FROM_FINALLY
|
COME_FROM_FINALLY
|
||||||
|
|
||||||
compare_chained2 ::= expr COMPARE_OP come_froms JUMP_FORWARD
|
compare_chained_right ::= expr COMPARE_OP come_froms JUMP_FORWARD
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_37_misc(self, args):
|
def p_37_misc(self, args):
|
||||||
|
@@ -338,8 +338,8 @@ TABLE_DIRECT = {
|
|||||||
"if_exp_not_lambda": ("%p if not %c else %c", (2, "expr", 27), 0, 4),
|
"if_exp_not_lambda": ("%p if not %c else %c", (2, "expr", 27), 0, 4),
|
||||||
"compare_single": ('%p %[-1]{pattr.replace("-", " ")} %p', (0, 19), (1, 19)),
|
"compare_single": ('%p %[-1]{pattr.replace("-", " ")} %p', (0, 19), (1, 19)),
|
||||||
"compare_chained": ("%p %p", (0, 29), (1, 30)),
|
"compare_chained": ("%p %p", (0, 29), (1, 30)),
|
||||||
"compare_chained1": ('%[3]{pattr.replace("-", " ")} %p %p', (0, 19), (-2, 19)),
|
"compared_chained_middle": ('%[3]{pattr.replace("-", " ")} %p %p', (0, 19), (-2, 19)),
|
||||||
"compare_chained2": ('%[1]{pattr.replace("-", " ")} %p', (0, 19)),
|
"compare_chained_right": ('%[1]{pattr.replace("-", " ")} %p', (0, 19)),
|
||||||
# "classdef": (), # handled by n_classdef()
|
# "classdef": (), # handled by n_classdef()
|
||||||
# A custom rule in n_function def distinguishes whether to call this or
|
# A custom rule in n_function def distinguishes whether to call this or
|
||||||
# function_def_async
|
# function_def_async
|
||||||
|
@@ -99,44 +99,44 @@ def customize_for_version37(self, version):
|
|||||||
"await_stmt": ("%|%c\n", 0),
|
"await_stmt": ("%|%c\n", 0),
|
||||||
"c_async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 3),
|
"c_async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 3),
|
||||||
"call_ex": ("%c(%p)", (0, "expr"), (1, 100)),
|
"call_ex": ("%c(%p)", (0, "expr"), (1, 100)),
|
||||||
"compare_chained1a_37": (
|
"compared_chained_middlea_37": (
|
||||||
' %[3]{pattr.replace("-", " ")} %p %p',
|
' %[3]{pattr.replace("-", " ")} %p %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
(-4, PRECEDENCE["compare"] - 1),
|
(-4, PRECEDENCE["compare"] - 1),
|
||||||
),
|
),
|
||||||
"compare_chained1_false_37": (
|
"compared_chained_middle_false_37": (
|
||||||
' %[3]{pattr.replace("-", " ")} %p %p',
|
' %[3]{pattr.replace("-", " ")} %p %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
(-4, PRECEDENCE["compare"] - 1),
|
(-4, PRECEDENCE["compare"] - 1),
|
||||||
),
|
),
|
||||||
"compare_chained2_false_37": (
|
"compare_chained_right_false_37": (
|
||||||
' %[3]{pattr.replace("-", " ")} %p %p',
|
' %[3]{pattr.replace("-", " ")} %p %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
(-5, PRECEDENCE["compare"] - 1),
|
(-5, PRECEDENCE["compare"] - 1),
|
||||||
),
|
),
|
||||||
"compare_chained1b_false_37": (
|
"compared_chained_middleb_false_37": (
|
||||||
' %[3]{pattr.replace("-", " ")} %p %p',
|
' %[3]{pattr.replace("-", " ")} %p %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
(-4, PRECEDENCE["compare"] - 1),
|
(-4, PRECEDENCE["compare"] - 1),
|
||||||
),
|
),
|
||||||
"compare_chained1c_37": (
|
"compared_chained_middlec_37": (
|
||||||
' %[3]{pattr.replace("-", " ")} %p %p',
|
' %[3]{pattr.replace("-", " ")} %p %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
(-2, PRECEDENCE["compare"] - 1),
|
(-2, PRECEDENCE["compare"] - 1),
|
||||||
),
|
),
|
||||||
"compare_chained2a_37": (
|
"compare_chained_righta_37": (
|
||||||
'%[1]{pattr.replace("-", " ")} %p',
|
'%[1]{pattr.replace("-", " ")} %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
),
|
),
|
||||||
"compare_chained2b_false_37": (
|
"compare_chained_rightb_false_37": (
|
||||||
'%[1]{pattr.replace("-", " ")} %p',
|
'%[1]{pattr.replace("-", " ")} %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
),
|
),
|
||||||
"compare_chained2a_false_37": (
|
"compare_chained_righta_false_37": (
|
||||||
'%[1]{pattr.replace("-", " ")} %p',
|
'%[1]{pattr.replace("-", " ")} %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
),
|
),
|
||||||
"compare_chained2c_37": (
|
"compare_chained_rightc_37": (
|
||||||
'%[3]{pattr.replace("-", " ")} %p %p',
|
'%[3]{pattr.replace("-", " ")} %p %p',
|
||||||
(0, PRECEDENCE["compare"] - 1),
|
(0, PRECEDENCE["compare"] - 1),
|
||||||
(6, PRECEDENCE["compare"] - 1),
|
(6, PRECEDENCE["compare"] - 1),
|
||||||
@@ -461,12 +461,12 @@ def customize_for_version37(self, version):
|
|||||||
compare_chained37 = node[0]
|
compare_chained37 = node[0]
|
||||||
if (
|
if (
|
||||||
compare_chained37 == "compare_chained37"
|
compare_chained37 == "compare_chained37"
|
||||||
and compare_chained37[1] == "compare_chained1b_37"
|
and compare_chained37[1] == "compared_chained_middleb_37"
|
||||||
):
|
):
|
||||||
compare_chained1b_37 = compare_chained37[1]
|
compared_chained_middleb_37 = compare_chained37[1]
|
||||||
if (
|
if (
|
||||||
len(compare_chained1b_37) > 2
|
len(compared_chained_middleb_37) > 2
|
||||||
and compare_chained1b_37[-2] == "JUMP_FORWARD"
|
and compared_chained_middleb_37[-2] == "JUMP_FORWARD"
|
||||||
):
|
):
|
||||||
node.kind = "testfalse"
|
node.kind = "testfalse"
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user