<2.5 grammar customizations for imports and loops

This commit is contained in:
rocky
2016-07-08 17:26:14 -04:00
parent 62e60817f6
commit 61535a010d
3 changed files with 19 additions and 6 deletions

View File

@@ -37,7 +37,7 @@ entry_points={
]}
ftp_url = None
install_requires = ['spark-parser >= 1.4.0',
'xdis >= 1.1.5']
'xdis >= 1.1.6']
license = 'MIT'
mailing_list = 'python-debugger@googlegroups.com'
modname = 'uncompyle6'

View File

@@ -15,8 +15,18 @@ class Python24Parser(Python25Parser):
def p_misc24(self, args):
'''
# 2.5+ has two LOAD_CONSTs, one for the number '.'s in a relative import
importstmt ::= LOAD_CONST filler import_as
importfrom ::= LOAD_CONST filler IMPORT_NAME importlist2 POP_TOP
# keep positions similar to simplify semantic actions
importstmt ::= filler LOAD_CONST import_as
importfrom ::= filler LOAD_CONST IMPORT_NAME importlist2 POP_TOP
importmultiple ::= filler LOAD_CONST import_as imports_cont
import_cont ::= filler LOAD_CONST import_as_cont
# Python 2.5+ omits POP_TOP POP_BLOCK
while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_TOP POP_BLOCK COME_FROM
call_stmt ::= yield
'''
class Python24ParserSingle(Python25Parser, PythonParserSingle):

View File

@@ -330,9 +330,12 @@ class Scanner2(scan.Scanner):
j = self.prev[s]
while code[j] == self.opc.JA:
j = self.prev[j]
if code[j] == self.opc.LIST_APPEND: # list comprehension
stmts.remove(s)
continue
try:
if code[j] == self.opc.LIST_APPEND: # list comprehension
stmts.remove(s)
continue
except:
from trepan.api import debug; debug()
elif code[s] == self.opc.POP_TOP and code[self.prev[s]] == self.opc.ROT_TWO:
stmts.remove(s)
continue