Skip to content

Commit 6319d33

Browse files
committed
Python 3.1 compile bug. DRY Python 3.x rules ...
via inheritance
1 parent abb61a4 commit 6319d33

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

uncompyle6/parsers/parse3.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,9 @@ def p_expr3(self, args):
360360
# Python 3.4+
361361
expr ::= LOAD_CLASSDEREF
362362
363+
binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR
363364
# Python3 drops slice0..slice3
364365
365-
# In Python 2, DUP_TOP_TWO is DUP_TOPX_2
366-
binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR
367366
'''
368367

369368
@staticmethod
@@ -672,34 +671,33 @@ def add_custom_rules(self, tokens, customize):
672671
return
673672

674673

675-
class Python31Parser(Python3Parser):
676-
677-
def p_31(self, args):
674+
class Python33Parser(Python3Parser):
675+
def p_33(self, args):
678676
"""
679677
# Store locals is only in Python 3.0 to 3.3
680678
stmt ::= store_locals
681679
store_locals ::= LOAD_FAST STORE_LOCALS
680+
681+
# Python 3.3 adds yield from.
682+
expr ::= yield_from
683+
yield_from ::= expr expr YIELD_FROM
682684
"""
683685

684686
class Python32Parser(Python3Parser):
685-
686-
def p_32(self, args):
687+
def p_32on(self, args):
687688
"""
688-
# Store locals is only in Python 3.0 to 3.3
689+
# In Python 3.2+, DUP_TOPX is DUP_TOP_TWO
690+
binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR
689691
stmt ::= store_locals
690692
store_locals ::= LOAD_FAST STORE_LOCALS
691693
"""
694+
pass
692695

693-
class Python33Parser(Python3Parser):
694-
def p_33(self, args):
695-
"""
696-
# Store locals is only in Python 3.0 to 3.3
697-
stmt ::= store_locals
698-
store_locals ::= LOAD_FAST STORE_LOCALS
696+
class Python31Parser(Python32Parser):
699697

700-
# Python 3.3 adds yield from.
701-
expr ::= yield_from
702-
yield_from ::= expr expr YIELD_FROM
698+
def p_31(self, args):
699+
"""
700+
binary_subscr2 ::= expr expr DUP_TOPX BINARY_SUBSCR
703701
"""
704702

705703
class Python3ParserSingle(Python3Parser, PythonParserSingle):

uncompyle6/parsers/parse34.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) 2016 Rocky Bernstein
22
"""
3-
spark grammar differences over Python3 for Python 3.4.2.
3+
spark grammar differences over Python 3.2 for Python 3.4
44
"""
55

66
from uncompyle6.parser import PythonParserSingle

uncompyle6/parsers/parse35.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Copyright (c) 2016 Rocky Bernstein
22
"""
3-
spark grammar differences over Python3 for Python 3.5.
3+
spark grammar differences over Python 3.2 for Python 3.5.
44
"""
55
from __future__ import print_function
66

77
from uncompyle6.parser import PythonParserSingle
88
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
9-
from uncompyle6.parsers.parse3 import Python3Parser
9+
from uncompyle6.parsers.parse3 import Python32Parser
1010

11-
class Python35Parser(Python3Parser):
11+
class Python35Parser(Python32Parser):
1212

1313
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
1414
super(Python35Parser, self).__init__(debug_parser)

0 commit comments

Comments
 (0)