From dddb486d78e5eb8e4d7c5b4599dea71b0813473c Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 8 May 2016 18:15:07 -0400 Subject: [PATCH] DRY parse{2,3} code Add test for last bug. --- test/bytecode_3.2/11_if_while_bug.pyc | Bin 0 -> 452 bytes test/simple_source/looping/11_if_while_bug.py | 9 ++++++ uncompyle6/parser.py | 28 ++++++++++++++++++ uncompyle6/parsers/parse2.py | 24 --------------- uncompyle6/parsers/parse3.py | 23 -------------- 5 files changed, 37 insertions(+), 47 deletions(-) create mode 100644 test/bytecode_3.2/11_if_while_bug.pyc create mode 100644 test/simple_source/looping/11_if_while_bug.py diff --git a/test/bytecode_3.2/11_if_while_bug.pyc b/test/bytecode_3.2/11_if_while_bug.pyc new file mode 100644 index 0000000000000000000000000000000000000000..719b3b6b71d483fcc263d7bad385028af53dada2 GIT binary patch literal 452 zcmb78!Ab)$6nx1RQQ1;Fi5@)f$)!-}MMUu4%OV9Yt8UU7HtohugDb2z`%`|M^P*Ng z8uDHyGm|&5>F{v!p3f`#wFK}L$`8>L(Hqe%fS@9iV5$KcFFv`hQNBa#u?5uwY87=i zjKS1I?cJ9I24jx5l1}=B>V(>Y6&2q_HX_{lvXE5tl3z?;B|VL3zJ?q(97^s?S%UDH z;eQ(xWwG(s0&^~~?zIbhIPdM|8|seXryB|dhTg24)unGjTj|_3jWg?IJ|355Q9eH! zNDpCo?q0$H%%ykMY%nJ#q&!5VVkAz*nK%-&jN|_rf6^lQU*tZ sep: + while sep < p: + if p[sep:sep+1] != extsep: + return p[:sep], p[sep:] + altsep += 1 + return p, p[:0] diff --git a/uncompyle6/parser.py b/uncompyle6/parser.py index 801078e0..462f1251 100644 --- a/uncompyle6/parser.py +++ b/uncompyle6/parser.py @@ -182,6 +182,34 @@ class PythonParser(GenericASTBuilder): for_block POP_BLOCK else_suitel _come_from """ + def p_whilestmt(self, args): + """ + whilestmt ::= SETUP_LOOP + testexpr + l_stmts_opt JUMP_BACK + POP_BLOCK _come_from + + whilestmt ::= SETUP_LOOP + testexpr + return_stmts + POP_BLOCK COME_FROM + + while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM + while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM + while1stmt ::= SETUP_LOOP return_stmts COME_FROM + + while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM + whileelsestmt ::= SETUP_LOOP testexpr + l_stmts_opt JUMP_BACK + POP_BLOCK + else_suite COME_FROM + + whileelselaststmt ::= SETUP_LOOP testexpr + l_stmts_opt JUMP_BACK + POP_BLOCK + else_suitec COME_FROM + """ + def p_import20(self, args): ''' stmt ::= importstmt diff --git a/uncompyle6/parsers/parse2.py b/uncompyle6/parsers/parse2.py index 7f921558..dc8c0d40 100644 --- a/uncompyle6/parsers/parse2.py +++ b/uncompyle6/parsers/parse2.py @@ -318,30 +318,6 @@ class Python2Parser(PythonParser): POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY - whilestmt ::= SETUP_LOOP - testexpr - l_stmts_opt JUMP_BACK - POP_BLOCK COME_FROM - - whilestmt ::= SETUP_LOOP - testexpr - return_stmts - POP_BLOCK COME_FROM - - while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM - while1stmt ::= SETUP_LOOP return_stmts COME_FROM - while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK COME_FROM - - while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM - whileelsestmt ::= SETUP_LOOP testexpr - l_stmts_opt JUMP_BACK - POP_BLOCK - else_suite COME_FROM - - whileelselaststmt ::= SETUP_LOOP testexpr - l_stmts_opt JUMP_BACK - POP_BLOCK - else_suitec COME_FROM ''' def p_expr2(self, args): diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 8df27b34..59f5c78b 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -328,29 +328,6 @@ class Python3Parser(PythonParser): POP_BLOCK LOAD_CONST COME_FROM WITH_CLEANUP END_FINALLY - whilestmt ::= SETUP_LOOP - testexpr - l_stmts_opt JUMP_BACK - POP_BLOCK _come_from - - whilestmt ::= SETUP_LOOP - testexpr - return_stmts - POP_BLOCK COME_FROM - - while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM - while1stmt ::= SETUP_LOOP return_stmts COME_FROM - - while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM - whileelsestmt ::= SETUP_LOOP testexpr - l_stmts_opt JUMP_BACK - POP_BLOCK - else_suite COME_FROM - - whileelselaststmt ::= SETUP_LOOP testexpr - l_stmts_opt JUMP_BACK - POP_BLOCK - else_suitec COME_FROM ''' def p_genexpr3(self, args):