1
- # Copyright (c) 2015-2022 Rocky Bernstein
1
+ # Copyright (c) 2015-2023 Rocky Bernstein
2
2
# Copyright (c) 2005 by Dan Pascu <[email protected] >
3
3
# Copyright (c) 2000-2002 by hartmut Goebel <[email protected] >
4
4
# Copyright (c) 1999 John Aycock
@@ -44,8 +44,8 @@ def nop_func(self, args):
44
44
45
45
46
46
class PythonParser (GenericASTBuilder ):
47
- def __init__ (self , SyntaxTree , start , debug ):
48
- super (PythonParser , self ).__init__ (SyntaxTree , start , debug )
47
+ def __init__ (self , syntax_tree_class , start , debug ):
48
+ super (PythonParser , self ).__init__ (syntax_tree_class , start , debug )
49
49
# FIXME: customize per python parser version
50
50
51
51
# These are the non-terminals we should collect into a list.
@@ -103,6 +103,7 @@ def __init__(self, SyntaxTree, start, debug):
103
103
)
104
104
# Instructions filled in from scanner
105
105
self .insts = []
106
+ self .version = tuple ()
106
107
107
108
def ast_first_offset (self , ast ):
108
109
if hasattr (ast , "offset" ):
@@ -151,9 +152,9 @@ def cleanup(self):
151
152
Remove recursive references to allow garbage
152
153
collector to collect this object.
153
154
"""
154
- for dict in (self .rule2func , self .rules , self .rule2name ):
155
- for i in list (dict .keys ()):
156
- dict [i ] = None
155
+ for rule_dict in (self .rule2func , self .rules , self .rule2name ):
156
+ for i in list (rule_dict .keys ()):
157
+ rule_dict [i ] = None
157
158
for i in dir (self ):
158
159
setattr (self , i , None )
159
160
@@ -164,11 +165,11 @@ def debug_reduce(self, rule, tokens, parent, last_token_pos):
164
165
165
166
def fix (c ):
166
167
s = str (c )
167
- last_token_pos = s .find ("_" )
168
- if last_token_pos == - 1 :
168
+ token_pos = s .find ("_" )
169
+ if token_pos == - 1 :
169
170
return s
170
171
else :
171
- return s [:last_token_pos ]
172
+ return s [:token_pos ]
172
173
173
174
prefix = ""
174
175
if parent and tokens :
@@ -267,13 +268,13 @@ def __ambiguity(self, children):
267
268
print (children )
268
269
return GenericASTBuilder .ambiguity (self , children )
269
270
270
- def resolve (self , list ):
271
- if len (list ) == 2 and "function_def" in list and "assign" in list :
271
+ def resolve (self , rule : list ):
272
+ if len (rule ) == 2 and "function_def" in rule and "assign" in rule :
272
273
return "function_def"
273
- if "grammar" in list and "expr" in list :
274
+ if "grammar" in rule and "expr" in rule :
274
275
return "expr"
275
- # print >> sys.stderr, 'resolve', str(list )
276
- return GenericASTBuilder .resolve (self , list )
276
+ # print >> sys.stderr, 'resolve', str(rule )
277
+ return GenericASTBuilder .resolve (self , rule )
277
278
278
279
###############################################
279
280
# Common Python 2 and Python 3 grammar rules #
@@ -667,7 +668,7 @@ def get_python_parser(
667
668
if compile_mode == "exec" :
668
669
p = parse10 .Python10Parser (debug_parser )
669
670
else :
670
- p = parse10 .Python01ParserSingle (debug_parser )
671
+ p = parse10 .Python10ParserSingle (debug_parser )
671
672
elif version == (1 , 1 ):
672
673
import uncompyle6 .parsers .parse11 as parse11
673
674
@@ -873,6 +874,7 @@ def python_parser(
873
874
:param showasm: Flag which determines whether the disassembled and
874
875
ingested code is written to sys.stdout or not.
875
876
:param parser_debug: dict containing debug flags for the spark parser.
877
+ :param is_pypy: True if we are running PyPY
876
878
877
879
:return: Abstract syntax tree representation of the code object.
878
880
"""
0 commit comments