3
3
spark grammar differences over Python2 for Python 2.6.
4
4
"""
5
5
6
- from uncompyle6 .parser import PythonParserSingle
7
6
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
7
+
8
+ from uncompyle6 .parser import PythonParserSingle
8
9
from uncompyle6 .parsers .parse2 import Python2Parser
9
10
from uncompyle6 .parsers .reducecheck import (
10
11
except_handler ,
11
12
ifelsestmt2 ,
12
13
ifstmt2 ,
13
- tryexcept ,
14
14
tryelsestmt ,
15
+ tryexcept ,
15
16
)
16
17
17
18
@@ -64,8 +65,8 @@ def p_try_except26(self, args):
64
65
except_suite ::= c_stmts_opt jmp_abs come_from_pop
65
66
66
67
# This is what happens after a jump where
67
- # we start a new block. For reasons I don't fully
68
- # understand, there is also a value on the top of the stack
68
+ # we start a new block. For reasons that I don't fully
69
+ # understand, there is also a value on the top of the stack.
69
70
come_from_pop ::= COME_FROM POP_TOP
70
71
come_froms_pop ::= come_froms POP_TOP
71
72
"""
@@ -78,7 +79,7 @@ def p_try_except26(self, args):
78
79
def p_jumps26 (self , args ):
79
80
"""
80
81
81
- # The are the equivalents of Python 2.7+'s
82
+ # There are the equivalents of Python 2.7+'s
82
83
# POP_JUMP_IF_TRUE and POP_JUMP_IF_FALSE
83
84
jmp_true ::= JUMP_IF_TRUE POP_TOP
84
85
jmp_false ::= JUMP_IF_FALSE POP_TOP
@@ -106,8 +107,8 @@ def p_jumps26(self, args):
106
107
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD come_froms POP_TOP COME_FROM
107
108
108
109
# This is what happens after a jump where
109
- # we start a new block. For reasons I don't fully
110
- # understand, there is also a value on the top of the stack
110
+ # we start a new block. For reasons that I don't fully
111
+ # understand, there is also a value on the top of the stack.
111
112
come_froms_pop ::= come_froms POP_TOP
112
113
113
114
"""
@@ -394,7 +395,7 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
394
395
if ast [1 ] is None :
395
396
return False
396
397
397
- # For now, we won't let the 2nd 'expr' be a "if_exp_not"
398
+ # For now, we won't let the 2nd 'expr' be an "if_exp_not"
398
399
# However in < 2.6 where we don't have if/else expression it *can*
399
400
# be.
400
401
if self .version >= (2 , 6 ) and ast [2 ][0 ] == "if_exp_not" :
@@ -464,7 +465,7 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
464
465
ja_attr = ast [4 ].attr
465
466
return tokens [last ].offset != ja_attr
466
467
elif lhs == "try_except" :
467
- # We need to distingush try_except from tryelsestmt and we do that
468
+ # We need to distingush " try_except" from " tryelsestmt"; we do that
468
469
# by checking the jump before the END_FINALLY
469
470
# If we have:
470
471
# insn
@@ -490,7 +491,7 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
490
491
) or (tokens [last - 3 ] == "JUMP_FORWARD" and tokens [last - 3 ].attr != 2 )
491
492
elif lhs == "tryelsestmt" :
492
493
493
- # We need to distingush try_except from tryelsestmt and we do that
494
+ # We need to distinguish " try_except" from " tryelsestmt"; we do that
494
495
# by making sure that the jump before the except handler jumps to
495
496
# code somewhere before the end of the construct.
496
497
# This AST method is slower, but the token-only based approach
@@ -508,8 +509,8 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
508
509
return else_start >= last_offset
509
510
510
511
# The above test apparently isn't good enough, so we have additional
511
- # checks distinguish try_except from tryelsestmt and we do that
512
- # by checking the jump before the END_FINALLY
512
+ # checks distinguish " try_except" from " tryelsestmt". we do that
513
+ # by checking the jump before the " END_FINALLY".
513
514
# If we have:
514
515
# insn
515
516
# POP_TOP
@@ -546,7 +547,7 @@ class Python26ParserSingle(Python2Parser, PythonParserSingle):
546
547
# Check grammar
547
548
p = Python26Parser ()
548
549
p .check_grammar ()
549
- from xdis .version_info import PYTHON_VERSION_TRIPLE , IS_PYPY
550
+ from xdis .version_info import IS_PYPY , PYTHON_VERSION_TRIPLE
550
551
551
552
if PYTHON_VERSION_TRIPLE [:2 ] == (2 , 6 ):
552
553
lhs , rhs , tokens , right_recursive , dup_rhs = p .check_sets ()
0 commit comments