From 56b2e17e30a5bf2205d7d45af809b0c5116d50eb Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 19 Mar 2018 06:01:39 -0400 Subject: [PATCH] Adjust 3.6 "while" loop grammar --- test/bytecode_3.6/05_while_and_if.pyc | Bin 0 -> 318 bytes test/simple_source/bug36/05_while_and_if.py | 13 +++++++++++++ uncompyle6/parsers/parse36.py | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/bytecode_3.6/05_while_and_if.pyc create mode 100644 test/simple_source/bug36/05_while_and_if.py diff --git a/test/bytecode_3.6/05_while_and_if.pyc b/test/bytecode_3.6/05_while_and_if.pyc new file mode 100644 index 0000000000000000000000000000000000000000..657842917976462dc92e60f042bb635950fdd322 GIT binary patch literal 318 zcmYjJ%}&B#5Zv9C+7RF_4?ygpVnXCZh|xPS;b78BLAI6#u=V?BKm#`~K8h#ar&mvX z1y1f)e>a)g$?WX(n$5a?I|LI1_<(;yqOSzHA;iG=3IQ;U!Lw$Pt;S>wZUp*TXgk<} z5-^_rZl;CxDkxm0xQ=wy{Gqfn>0nnm6FJnr?o7nk8?o`^erj@I&O%cE`y0k*M$ ggf2Sdl5)ivd06eg_AhlJx56E)QqGsruxc;`pASeqYXATM literal 0 HcmV?d00001 diff --git a/test/simple_source/bug36/05_while_and_if.py b/test/simple_source/bug36/05_while_and_if.py new file mode 100644 index 00000000..f07c0c5e --- /dev/null +++ b/test/simple_source/bug36/05_while_and_if.py @@ -0,0 +1,13 @@ +# From Python 3.6 getopt.py +# Bug showing that "while" can have several "COME_FROMS" before loop end +# NOTE: uncompyle6 still gets the "if"s wrong. +def getopt(args): + while args and args[0] and args[0] != '-': + if args[0] == '--': + break + if args[0]: + opts = 5 + else: + opts = 6 + + return opts diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 3a4587b5..0391833c 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -47,7 +47,7 @@ class Python36Parser(Python35Parser): come_from_loops ::= COME_FROM_LOOP* whilestmt ::= SETUP_LOOP testexpr l_stmts_opt - JUMP_BACK COME_FROM POP_BLOCK COME_FROM_LOOP + JUMP_BACK come_froms POP_BLOCK COME_FROM_LOOP # This might be valid in < 3.6 and ::= expr jmp_false expr