You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Isolate unmap_dict rule in 3.5
This commit is contained in:
@@ -4,7 +4,7 @@ spark grammar differences over Python 3.4 for Python 3.5.
|
|||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from uncompyle6.parser import PythonParserSingle
|
from uncompyle6.parser import PythonParserSingle, nop_func
|
||||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||||
from uncompyle6.parsers.parse34 import Python34Parser
|
from uncompyle6.parsers.parse34 import Python34Parser
|
||||||
|
|
||||||
@@ -33,15 +33,6 @@ class Python35Parser(Python34Parser):
|
|||||||
stmt ::= await_stmt
|
stmt ::= await_stmt
|
||||||
await_stmt ::= await_expr POP_TOP
|
await_stmt ::= await_expr POP_TOP
|
||||||
|
|
||||||
expr ::= unmap_dict
|
|
||||||
expr ::= unmapexpr
|
|
||||||
|
|
||||||
unmap_dict ::= dict_comp BUILD_MAP_UNPACK
|
|
||||||
|
|
||||||
unmap_dict ::= kv_lists BUILD_MAP_UNPACK
|
|
||||||
kv_lists ::= kv_list kv_lists
|
|
||||||
kv_lists ::= kv_list
|
|
||||||
|
|
||||||
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
# Python 3.5+ has WITH_CLEANUP_START/FINISH
|
||||||
|
|
||||||
withstmt ::= expr
|
withstmt ::= expr
|
||||||
@@ -128,7 +119,6 @@ class Python35Parser(Python34Parser):
|
|||||||
return_if_stmt ::= ret_expr RETURN_END_IF POP_BLOCK
|
return_if_stmt ::= ret_expr RETURN_END_IF POP_BLOCK
|
||||||
|
|
||||||
ifelsestmtc ::= testexpr c_stmts_opt JUMP_FORWARD else_suitec
|
ifelsestmtc ::= testexpr c_stmts_opt JUMP_FORWARD else_suitec
|
||||||
ifelsestmtc ::= testexpr c_stmts_opt jf_else else_suitec
|
|
||||||
|
|
||||||
# ifstmt ::= testexpr c_stmts_opt
|
# ifstmt ::= testexpr c_stmts_opt
|
||||||
|
|
||||||
@@ -149,17 +139,24 @@ class Python35Parser(Python34Parser):
|
|||||||
for i, token in enumerate(tokens):
|
for i, token in enumerate(tokens):
|
||||||
opname = token.kind
|
opname = token.kind
|
||||||
if opname == 'BUILD_MAP_UNPACK_WITH_CALL':
|
if opname == 'BUILD_MAP_UNPACK_WITH_CALL':
|
||||||
|
self.addRule("expr ::= unmapexpr", nop_func)
|
||||||
nargs = token.attr % 256
|
nargs = token.attr % 256
|
||||||
map_unpack_n = "map_unpack_%s" % nargs
|
map_unpack_n = "map_unpack_%s" % nargs
|
||||||
rule = map_unpack_n + ' ::= ' + 'expr ' * (nargs)
|
rule = map_unpack_n + ' ::= ' + 'expr ' * (nargs)
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.addRule(rule, nop_func)
|
||||||
rule = "unmapexpr ::= %s %s" % (map_unpack_n, opname)
|
rule = "unmapexpr ::= %s %s" % (map_unpack_n, opname)
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.addRule(rule, nop_func)
|
||||||
call_token = tokens[i+1]
|
call_token = tokens[i+1]
|
||||||
if self.version == 3.5:
|
if self.version == 3.5:
|
||||||
rule = 'call ::= expr unmapexpr ' + call_token.kind
|
rule = 'call ::= expr unmapexpr ' + call_token.kind
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.addRule(rule, nop_func)
|
||||||
pass
|
pass
|
||||||
|
elif opname == 'BUILD_MAP_UNPACK':
|
||||||
|
self.addRule("""
|
||||||
|
expr ::= unmap_dict
|
||||||
|
unmap_dict ::= dict_comp BUILD_MAP_UNPACK
|
||||||
|
""", nop_func)
|
||||||
|
|
||||||
pass
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user