diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 07acb21d..210f266b 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -330,11 +330,9 @@ class Python2Parser(PythonParser): 'dict_comp_func', 0, customize) else: - kvlist_n = "kvlist_%s" % token.attr - self.add_unique_rules([ - (kvlist_n + " ::=" + ' kv3' * token.attr), - "dict ::= %s %s" % (opname, kvlist_n) - ], customize) + kvlist_n = ' kv3' * token.attr + rule = "dict ::= %s%s" % (opname, kvlist_n) + self.addRule(rule, nop_func) continue elif opname_base == 'BUILD_SLICE': slice_num = token.attr diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index da6cc835..2c1489b8 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -646,6 +646,8 @@ class Python3Parser(PythonParser): elif self.version >= 3.5: if opname != 'BUILD_MAP_WITH_CALL': if opname == 'BUILD_MAP_UNPACK': + # FIXME: start here + # rule = "%s ::= %s %s" % (kvlist_n, 'expr ' * (token.attr*2), opname) rule = kvlist_n + ' ::= ' + 'expr ' * (token.attr*2) self.add_unique_rule(rule, opname, token.attr, customize) rule = 'dict_entry ::= ' + 'expr ' * (token.attr*2) diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 5590ec44..bf4681e9 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1705,10 +1705,6 @@ class SourceWalker(GenericASTTraversal, object): kv_node = node[0] l = list(kv_node) length = len(l) - - # FIXME: Parser-speed improved grammars will have BUILD_MAP - # at the end. So in the future when everything is - # complete, we can do an "assert" instead of "if". if kv_node[-1].kind.startswith("BUILD_MAP"): length -= 1 i = 0 @@ -1784,13 +1780,20 @@ class SourceWalker(GenericASTTraversal, object): pass pass else: - # Python 2 style kvlist - assert node[-1].kind.startswith('kvlist') - kv_node = node[-1] # goto kvlist + # Python 2 style kvlist. Find beginning of kvlist. + if node[0].kind.startswith("BUILD_MAP"): + if len(node) > 1 and node[1].kind in ('kvlist', 'kvlist_n'): + kv_node = node[1] + else: + kv_node = node[1:] + else: + assert node[-1].kind.startswith('kvlist') + kv_node = node[-1] first_time = True for kv in kv_node: assert kv in ('kv', 'kv2', 'kv3') + # kv ::= DUP_TOP expr ROT_TWO expr STORE_SUBSCR # kv2 ::= DUP_TOP expr expr ROT_THREE STORE_SUBSCR # kv3 ::= expr expr STORE_MAP