You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
NT: load_attr -> attribute to match AST
This commit is contained in:
@@ -32,7 +32,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
super(PythonParser, self).__init__(AST, start, debug)
|
super(PythonParser, self).__init__(AST, start, debug)
|
||||||
# FIXME: customize per python parser version
|
# FIXME: customize per python parser version
|
||||||
nt_list = [
|
nt_list = [
|
||||||
'stmts', 'except_stmts', '_stmts', 'load_attrs',
|
'stmts', 'except_stmts', '_stmts', 'attributes',
|
||||||
'exprlist', 'kvlist', 'kwargs', 'come_froms', '_come_froms',
|
'exprlist', 'kvlist', 'kwargs', 'come_froms', '_come_froms',
|
||||||
'importlist',
|
'importlist',
|
||||||
# Python < 3
|
# Python < 3
|
||||||
@@ -388,7 +388,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
importlist ::= alias
|
importlist ::= alias
|
||||||
alias ::= IMPORT_NAME store
|
alias ::= IMPORT_NAME store
|
||||||
alias ::= IMPORT_FROM store
|
alias ::= IMPORT_FROM store
|
||||||
alias ::= IMPORT_NAME load_attrs store
|
alias ::= IMPORT_NAME attributes store
|
||||||
|
|
||||||
import ::= LOAD_CONST LOAD_CONST alias
|
import ::= LOAD_CONST LOAD_CONST alias
|
||||||
import_from_star ::= LOAD_CONST LOAD_CONST IMPORT_NAME IMPORT_STAR
|
import_from_star ::= LOAD_CONST LOAD_CONST IMPORT_NAME IMPORT_STAR
|
||||||
@@ -398,7 +398,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
imports_cont ::= import_cont+
|
imports_cont ::= import_cont+
|
||||||
import_cont ::= LOAD_CONST LOAD_CONST alias
|
import_cont ::= LOAD_CONST LOAD_CONST alias
|
||||||
|
|
||||||
load_attrs ::= LOAD_ATTR+
|
attributes ::= LOAD_ATTR+
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def p_list_comprehension(self, args):
|
def p_list_comprehension(self, args):
|
||||||
@@ -433,7 +433,7 @@ class PythonParser(GenericASTBuilder):
|
|||||||
expr ::= LOAD_CONST
|
expr ::= LOAD_CONST
|
||||||
expr ::= LOAD_GLOBAL
|
expr ::= LOAD_GLOBAL
|
||||||
expr ::= LOAD_DEREF
|
expr ::= LOAD_DEREF
|
||||||
expr ::= load_attr
|
expr ::= attribute
|
||||||
expr ::= binary_expr
|
expr ::= binary_expr
|
||||||
expr ::= list
|
expr ::= list
|
||||||
expr ::= compare
|
expr ::= compare
|
||||||
@@ -471,8 +471,8 @@ class PythonParser(GenericASTBuilder):
|
|||||||
|
|
||||||
subscript ::= expr expr BINARY_SUBSCR
|
subscript ::= expr expr BINARY_SUBSCR
|
||||||
|
|
||||||
load_attr ::= expr LOAD_ATTR
|
attribute ::= expr LOAD_ATTR
|
||||||
get_iter ::= expr GET_ITER
|
get_iter ::= expr GET_ITER
|
||||||
|
|
||||||
yield ::= expr YIELD_VALUE
|
yield ::= expr YIELD_VALUE
|
||||||
|
|
||||||
|
@@ -367,7 +367,7 @@ class Python2Parser(PythonParser):
|
|||||||
continue
|
continue
|
||||||
elif opname == 'LOOKUP_METHOD':
|
elif opname == 'LOOKUP_METHOD':
|
||||||
# A PyPy speciality - DRY with parse3
|
# A PyPy speciality - DRY with parse3
|
||||||
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",
|
self.add_unique_rule("attribute ::= expr LOOKUP_METHOD",
|
||||||
opname, v, customize)
|
opname, v, customize)
|
||||||
continue
|
continue
|
||||||
elif opname_base == 'MAKE_FUNCTION':
|
elif opname_base == 'MAKE_FUNCTION':
|
||||||
|
@@ -48,9 +48,7 @@ class Python23Parser(Python24Parser):
|
|||||||
expr ::= and2
|
expr ::= and2
|
||||||
and2 ::= _jump jmp_false COME_FROM expr COME_FROM
|
and2 ::= _jump jmp_false COME_FROM expr COME_FROM
|
||||||
|
|
||||||
alias ::= IMPORT_NAME load_attrs store
|
alias ::= IMPORT_NAME attributes store
|
||||||
load_attrs ::= LOAD_ATTR+
|
|
||||||
|
|
||||||
conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM
|
conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@@ -595,7 +595,7 @@ class Python3Parser(PythonParser):
|
|||||||
mklambda ::= {pos_arg}^n LOAD_LAMBDA [LOAD_CONST] MAKE_FUNCTION_n
|
mklambda ::= {pos_arg}^n LOAD_LAMBDA [LOAD_CONST] MAKE_FUNCTION_n
|
||||||
|
|
||||||
For PYPY:
|
For PYPY:
|
||||||
load_attr ::= expr LOOKUP_METHOD
|
attribute ::= expr LOOKUP_METHOD
|
||||||
call ::= expr CALL_METHOD
|
call ::= expr CALL_METHOD
|
||||||
"""
|
"""
|
||||||
is_pypy = False
|
is_pypy = False
|
||||||
@@ -796,7 +796,7 @@ class Python3Parser(PythonParser):
|
|||||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||||
elif opname == 'LOOKUP_METHOD':
|
elif opname == 'LOOKUP_METHOD':
|
||||||
# A PyPy speciality - DRY with parse2
|
# A PyPy speciality - DRY with parse2
|
||||||
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",
|
self.add_unique_rule("attribute ::= expr LOOKUP_METHOD",
|
||||||
opname, token.attr, customize)
|
opname, token.attr, customize)
|
||||||
continue
|
continue
|
||||||
elif opname.startswith('MAKE_CLOSURE'):
|
elif opname.startswith('MAKE_CLOSURE'):
|
||||||
|
@@ -125,7 +125,7 @@ TABLE_DIRECT = {
|
|||||||
(1, 100), (2, 100) ),
|
(1, 100), (2, 100) ),
|
||||||
|
|
||||||
'IMPORT_FROM': ( '%{pattr}', ),
|
'IMPORT_FROM': ( '%{pattr}', ),
|
||||||
'load_attr': ( '%c.%[1]{pattr}',
|
'attribute': ( '%c.%[1]{pattr}',
|
||||||
(0, 'expr')),
|
(0, 'expr')),
|
||||||
'LOAD_FAST': ( '%{pattr}', ),
|
'LOAD_FAST': ( '%{pattr}', ),
|
||||||
'LOAD_NAME': ( '%{pattr}', ),
|
'LOAD_NAME': ( '%{pattr}', ),
|
||||||
@@ -155,7 +155,7 @@ TABLE_DIRECT = {
|
|||||||
'unpack_w_parens': ( '(%C%,)', (1, maxint, ', ') ),
|
'unpack_w_parens': ( '(%C%,)', (1, maxint, ', ') ),
|
||||||
|
|
||||||
# This nonterminal we create on the fly in semantic routines
|
# This nonterminal we create on the fly in semantic routines
|
||||||
'load_attr_w_parens': ( '(%c).%[1]{pattr}',
|
'attribute_w_parens': ( '(%c).%[1]{pattr}',
|
||||||
(0, 'expr')),
|
(0, 'expr')),
|
||||||
|
|
||||||
'unpack_list': ( '[%C]',
|
'unpack_list': ( '[%C]',
|
||||||
@@ -312,7 +312,7 @@ PRECEDENCE = {
|
|||||||
'list_comp': 0,
|
'list_comp': 0,
|
||||||
'generator_exp': 0,
|
'generator_exp': 0,
|
||||||
|
|
||||||
'load_attr': 2,
|
'attribute': 2,
|
||||||
'subscript': 2,
|
'subscript': 2,
|
||||||
'subscript2': 2,
|
'subscript2': 2,
|
||||||
'slice0': 2,
|
'slice0': 2,
|
||||||
|
@@ -1878,10 +1878,10 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
n_unpack_w_parens = n_unpack
|
n_unpack_w_parens = n_unpack
|
||||||
|
|
||||||
def n_load_attr(self, node):
|
def n_attribute(self, node):
|
||||||
if (node[0] == 'LOAD_CONST' or
|
if (node[0] == 'LOAD_CONST' or
|
||||||
node[0] == 'expr' and node[0][0] == 'LOAD_CONST'):
|
node[0] == 'expr' and node[0][0] == 'LOAD_CONST'):
|
||||||
node.kind = 'load_attr_w_parens'
|
node.kind = 'attribute_w_parens'
|
||||||
self.default(node)
|
self.default(node)
|
||||||
|
|
||||||
def n_assign(self, node):
|
def n_assign(self, node):
|
||||||
|
Reference in New Issue
Block a user