From cde12cde03c0321a218020643ed4a8665e0dc963 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 14 Dec 2017 05:25:46 -0500 Subject: [PATCH] Try removing more singleton rules --- __pkginfo__.py | 2 +- uncompyle6/parser.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/__pkginfo__.py b/__pkginfo__.py index 13301699..68dcbb82 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -39,7 +39,7 @@ entry_points = { 'pydisassemble=uncompyle6.bin.pydisassemble:main', ]} ftp_url = None -install_requires = ['spark-parser >= 1.8.4, < 1.9.0', +install_requires = ['spark-parser >= 1.8.5, < 1.9.0', 'xdis >= 3.6.2, < 3.7.0', 'six'] license = 'MIT' mailing_list = 'python-debugger@googlegroups.com' diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index e3188c80..f5f371d5 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -46,6 +46,15 @@ class PythonParser(GenericASTBuilder): ] self.collect = frozenset(nt_list) + # ??? Do we need a debug option to skip eliding singleton reductions? + # Time will tell if it if useful in debugging + + # FIXME: optional_nt is a misnomer. It's really about there being a + # singleton reduction that we can simplify. It also happens to be optional + # in its other derivation + self.optional_nt |= frozenset(['come_froms', 'suite_stmts', 'l_stmts_opt', + 'c_stmts_opt']) + # Reduce singleton reductions in these nonterminals: # FIXME: would love to do expr, sstmts, stmts and # so on but that would require major changes to the @@ -180,11 +189,19 @@ class PythonParser(GenericASTBuilder): # stmts -> stmts stmt -> stmts stmt -> ... # stmms -> stmt stmt ... # - rv = args[0] + if not hasattr(args[0], 'append'): + # Was in self.optional_nt as a single item, but we find we have + # more than one now... + rv = GenericASTBuilder.nonterminal(self, nt, [args[0]]) + else: + rv = args[0] + pass rv.append(args[1]) elif n == 1 and args[0] in self.singleton: rv = GenericASTBuilder.nonterminal(self, nt, args[0]) del args[0] # save memory + elif n == 1 and nt in self.optional_nt: + rv = args[0] else: rv = GenericASTBuilder.nonterminal(self, nt, args) return rv