You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
3.8 "for" block ...
pysource: Tag older semantics for blocks with "expr" and "for_block"
This commit is contained in:
@@ -747,6 +747,12 @@ def get_python_parser(
|
|||||||
p = parse37.Python37Parser(debug_parser)
|
p = parse37.Python37Parser(debug_parser)
|
||||||
else:
|
else:
|
||||||
p = parse37.Python37ParserSingle(debug_parser)
|
p = parse37.Python37ParserSingle(debug_parser)
|
||||||
|
elif version == 3.8:
|
||||||
|
import uncompyle6.parsers.parse38 as parse38
|
||||||
|
if compile_mode == 'exec':
|
||||||
|
p = parse38.Python38Parser(debug_parser)
|
||||||
|
else:
|
||||||
|
p = parse38.Python38ParserSingle(debug_parser)
|
||||||
else:
|
else:
|
||||||
if compile_mode == 'exec':
|
if compile_mode == 'exec':
|
||||||
p = parse3.Python3Parser(debug_parser)
|
p = parse3.Python3Parser(debug_parser)
|
||||||
|
@@ -25,7 +25,10 @@ class Python38Parser(Python37Parser):
|
|||||||
|
|
||||||
def p_38misc(self, args):
|
def p_38misc(self, args):
|
||||||
"""
|
"""
|
||||||
for ::= expr get_iter store for_block JUMP_BACK
|
stmt ::= for38
|
||||||
|
for38 ::= expr get_iter store for_block JUMP_BACK
|
||||||
|
for38 ::= expr for_iter store for_block JUMP_BACK
|
||||||
|
|
||||||
forelsestmt ::= expr for_iter store for_block POP_BLOCK else_suite
|
forelsestmt ::= expr for_iter store for_block POP_BLOCK else_suite
|
||||||
forelselaststmt ::= expr for_iter store for_block POP_BLOCK else_suitec
|
forelselaststmt ::= expr for_iter store for_block POP_BLOCK else_suitec
|
||||||
forelselaststmtl ::= expr for_iter store for_block POP_BLOCK else_suitel
|
forelselaststmtl ::= expr for_iter store for_block POP_BLOCK else_suitel
|
||||||
@@ -40,6 +43,7 @@ class Python38Parser(Python37Parser):
|
|||||||
while1elsestmt ::= l_stmts JUMP_BACK
|
while1elsestmt ::= l_stmts JUMP_BACK
|
||||||
whileTruestmt ::= l_stmts_opt JUMP_BACK NOP
|
whileTruestmt ::= l_stmts_opt JUMP_BACK NOP
|
||||||
whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK NOP
|
whileTruestmt ::= l_stmts_opt JUMP_BACK POP_BLOCK NOP
|
||||||
|
for_block ::= l_stmts_opt _come_from_loops JUMP_BACK
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
|
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
|
||||||
@@ -47,7 +51,6 @@ class Python38Parser(Python37Parser):
|
|||||||
self.customized = {}
|
self.customized = {}
|
||||||
|
|
||||||
def customize_grammar_rules(self, tokens, customize):
|
def customize_grammar_rules(self, tokens, customize):
|
||||||
from trepan.api import debug; debug()
|
|
||||||
self.remove_rules("""
|
self.remove_rules("""
|
||||||
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
|
||||||
forelsestmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suite
|
forelsestmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suite
|
||||||
|
@@ -276,13 +276,25 @@ TABLE_DIRECT = {
|
|||||||
'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, -2 ),
|
'while1elsestmt': ( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n\n', 1, -2 ),
|
||||||
'whileelsestmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 2, -2 ),
|
'whileelsestmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n', 1, 2, -2 ),
|
||||||
'whileelselaststmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-', 1, 2, -2 ),
|
'whileelselaststmt': ( '%|while %c:\n%+%c%-%|else:\n%+%c%-', 1, 2, -2 ),
|
||||||
'for': ( '%|for %c in %c:\n%+%c%-\n\n', (3, 'store'), 1, 4 ),
|
'for': ( '%|for %c in %c:\n%+%c%-\n\n',
|
||||||
|
(3, 'store'),
|
||||||
|
(1, 'expr'),
|
||||||
|
(4, 'for_block') ),
|
||||||
'forelsestmt': (
|
'forelsestmt': (
|
||||||
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n', (3, 'store'), 1, 4, -2 ),
|
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n',
|
||||||
|
(3, 'store'),
|
||||||
|
(1, 'expr'),
|
||||||
|
(4, 'for_block'), -2 ),
|
||||||
'forelselaststmt': (
|
'forelselaststmt': (
|
||||||
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-', (3, 'store'), 1, 4, -2 ),
|
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-',
|
||||||
|
(3, 'store'),
|
||||||
|
(1, 'expr'),
|
||||||
|
(4, 'for_block'), -2 ),
|
||||||
'forelselaststmtl': (
|
'forelselaststmtl': (
|
||||||
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n', (3, 'store'), 1, 4, -2 ),
|
'%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n',
|
||||||
|
(3, 'store'),
|
||||||
|
(1, 'expr'),
|
||||||
|
(4, 'for_block'), -2 ),
|
||||||
'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ),
|
'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ),
|
||||||
'tryelsestmt': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-\n\n', 1, 3, 4 ),
|
'tryelsestmt': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-\n\n', 1, 3, 4 ),
|
||||||
'tryelsestmtc': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 1, 3, 4 ),
|
'tryelsestmtc': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 1, 3, 4 ),
|
||||||
|
@@ -908,6 +908,10 @@ def customize_for_version3(self, version):
|
|||||||
self.n_return_closure = return_closure
|
self.n_return_closure = return_closure
|
||||||
|
|
||||||
if version >= 3.7:
|
if version >= 3.7:
|
||||||
|
########################
|
||||||
|
# Python 3.7+ Additions
|
||||||
|
#######################
|
||||||
|
|
||||||
PRECEDENCE['attribute37'] = 2
|
PRECEDENCE['attribute37'] = 2
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'attribute37': ( '%c.%[1]{pattr}', 0 ),
|
'attribute37': ( '%c.%[1]{pattr}', 0 ),
|
||||||
@@ -928,7 +932,19 @@ def customize_for_version3(self, version):
|
|||||||
'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
|
'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
|
||||||
|
|
||||||
})
|
})
|
||||||
|
if version >= 3.8:
|
||||||
|
########################
|
||||||
|
# Python 3.8+ Additions
|
||||||
|
#######################
|
||||||
|
TABLE_DIRECT.update({
|
||||||
|
'for38': ( '%|for %c in %c:\n%+%c%-\n\n',
|
||||||
|
(2, 'store'),
|
||||||
|
(0, 'expr'),
|
||||||
|
(3, 'for_block') ),
|
||||||
|
})
|
||||||
|
pass
|
||||||
pass
|
pass
|
||||||
|
|
||||||
pass # version >= 3.6
|
pass # version >= 3.6
|
||||||
pass # version >= 3.4
|
pass # version >= 3.4
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user