Handle Python 2.4 if true

This commit is contained in:
rocky
2018-08-12 02:24:13 -04:00
parent f14e1dd62f
commit c96e796ff5
3 changed files with 17 additions and 3 deletions

Binary file not shown.

View File

@@ -32,6 +32,11 @@ class Python24Parser(Python25Parser):
importmultiple ::= filler LOAD_CONST alias imports_cont importmultiple ::= filler LOAD_CONST alias imports_cont
import_cont ::= filler LOAD_CONST alias import_cont ::= filler LOAD_CONST alias
# Handle "if true else: ..." in Python 2.4
stmt ::= iftrue_stmt24
iftrue_stmt24 ::= _ifstmts_jump24 suite_stmts COME_FROM
_ifstmts_jump24 ::= c_stmts_opt JUMP_FORWARD POP_TOP
# Python 2.5+ omits POP_TOP POP_BLOCK # Python 2.5+ omits POP_TOP POP_BLOCK
while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_TOP POP_BLOCK COME_FROM while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_TOP POP_BLOCK COME_FROM
while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_TOP POP_BLOCK while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_TOP POP_BLOCK

View File

@@ -43,10 +43,19 @@ def customize_for_version(self, is_pypy, version):
'assert': ( '%|assert %c\n' , 0 ), 'assert': ( '%|assert %c\n' , 0 ),
'assert2': ( '%|assert %c, %c\n' , 0, 3 ), 'assert2': ( '%|assert %c, %c\n' , 0, 3 ),
'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ), 'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ),
'assign2': ( '%|%c, %c = %c, %c\n', 3, 4, 0, 1 ), 'assign2': ( '%|%c, %c = %c, %c\n',
'assign3': ( '%|%c, %c, %c = %c, %c, %c\n', 5, 6, 7, 0, 1, 2 ), 3, 4, 0, 1 ),
'assign3': ( '%|%c, %c, %c = %c, %c, %c\n',
5, 6, 7, 0, 1, 2 ),
}) })
if version < 3.0: if version < 3.0:
if version == 2.4:
def n_iftrue_stmt24(node):
self.template_engine(('%|%c', 0), node)
self.default(node)
self.prune()
self.n_iftrue_stmt24 = n_iftrue_stmt24
TABLE_R.update({ TABLE_R.update({
'STORE_SLICE+0': ( '%c[:]', 0 ), 'STORE_SLICE+0': ( '%c[:]', 0 ),
'STORE_SLICE+1': ( '%c[%p:]', 0, (1, -1) ), 'STORE_SLICE+1': ( '%c[%p:]', 0, (1, -1) ),
@@ -62,7 +71,7 @@ def customize_for_version(self, is_pypy, version):
}) })
# exec as a built-in statement is only in Python 2.x # exec as a built-in statement is only in Python 2.x
def n_exec_stmt(self, node): def n_exec_stmt(node):
""" """
exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT
exec_stmt ::= expr exprlist EXEC_STMT exec_stmt ::= expr exprlist EXEC_STMT