Correct 3.6 FUNCTION_EX handling, somewhat

Some Python 2.4 compatibility snuck in but I suppose that is not so bad
This commit is contained in:
rocky
2018-01-08 23:20:22 -05:00
parent 0692727605
commit 7883e00b44
6 changed files with 14 additions and 9 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,4 +1,4 @@
# Copyright (c) 2015-2017 Rocky Bernstein
# Copyright (c) 2015-2018 Rocky Bernstein
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
# Copyright (c) 1999 John Aycock
@@ -15,8 +15,6 @@ If we succeed in creating a parse tree, then we have a Python program
that a later phase can turn into a sequence of ASCII text.
"""
from __future__ import print_function
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
from uncompyle6.parsers.astnode import AST
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
@@ -523,7 +521,10 @@ class Python3Parser(PythonParser):
"""Python 3.3 added a an addtional LOAD_CONST before MAKE_FUNCTION and
this has an effect on many rules.
"""
new_rule = rule % (('LOAD_CONST ') * (1 if self.version >= 3.3 else 0))
if self.version >= 3.3:
new_rule = rule % (('LOAD_CONST ') * 1)
else:
new_rule = rule % (('LOAD_CONST ') * 0)
self.add_unique_rule(new_rule, opname, attr, customize)
def customize_grammar_rules(self, tokens, customize):
@@ -814,7 +815,10 @@ class Python3Parser(PythonParser):
args_pos, args_kw, annotate_args = token.attr
# FIXME: Fold test into add_make_function_rule
j = 1 if self.version < 3.3 else 2
if self.version < 3.3:
j = 1
else:
j = 2
if is_pypy or (i >= j and tokens[i-j] == 'LOAD_LAMBDA'):
rule_pat = ('mklambda ::= %sload_closure LOAD_LAMBDA %%s%s' %
('pos_arg '* args_pos, opname))

View File

@@ -158,8 +158,8 @@ class Python36Parser(Python35Parser):
elif opname == 'CALL_FUNCTION_EX':
self.addRule("""
expr ::= call_ex
unpack_list ::= list
call_ex ::= expr unpack_list CALL_FUNCTION_EX
starred ::= expr
call_ex ::= expr starred CALL_FUNCTION_EX
""", nop_func)
pass
else:

View File

@@ -533,8 +533,9 @@ class SourceWalker(GenericASTTraversal, object):
'fstring_single': ( "f'{%c%{conversion}}'", 0),
'fstring_multi': ( "f'%c'", 0),
'func_args36': ( "%c(**", 0),
'try_except36': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
'unpack_list': ( '*%c', (0, 'list') ),
'try_except36': ( '%|try:\n%+%c%-%c\n\n', 1, 2 ),
'unpack_list': ( '*%c', (0, 'list') ),
'starred': ( '*%c', (0, 'expr') ),
'call_ex' : (
'%c(%c)',
(0, 'expr'), 1),