diff --git a/__pkginfo__.py b/__pkginfo__.py index 7b8c39be..643857cd 100644 --- a/__pkginfo__.py +++ b/__pkginfo__.py @@ -23,7 +23,7 @@ # Things that change more often go here. copyright = """ -Copyright (C) 2015-2019 Rocky Bernstein . +Copyright (C) 2015-2020 Rocky Bernstein . """ classifiers = ["Development Status :: 5 - Production/Stable", diff --git a/pytest/test_token.py b/pytest/test_token.py index e59bb925..e858aa92 100644 --- a/pytest/test_token.py +++ b/pytest/test_token.py @@ -5,7 +5,7 @@ from uncompyle6.scanners.tok import Token def test_token(): # Test token formatting of: LOAD_CONST None t = Token("LOAD_CONST", offset=0, attr=None, pattr=None, has_arg=True) - expect = " 0 LOAD_CONST None" + expect = " 0 LOAD_CONST None" # print(t.format()) assert t assert t.format() == expect @@ -17,7 +17,7 @@ def test_token(): # Make sure formatting of: LOAD_CONST False. We assume False is the 0th index # of co_consts. t = Token("LOAD_CONST", offset=1, attr=False, pattr=False, has_arg=True) - expect = " 1 LOAD_CONST False" + expect = " 1 LOAD_CONST False" assert t.format() == expect diff --git a/pytest/testdata/if-2.7.right b/pytest/testdata/if-2.7.right index 5746ad15..b285a037 100644 --- a/pytest/testdata/if-2.7.right +++ b/pytest/testdata/if-2.7.right @@ -1,12 +1,12 @@ # Python 2.7 # Embedded file name: simple_source/branching/05_if.py - 6 0 LOAD_NAME 0 'True' - 3 POP_JUMP_IF_FALSE 15 'to 15' + L. 6 0 LOAD_NAME 0 'True' + 3 POP_JUMP_IF_FALSE 15 'to 15' - 7 6 LOAD_NAME 1 'False' - 9 STORE_NAME 2 'b' - 12 JUMP_FORWARD 0 'to 15' - 15_0 COME_FROM 12 '12' - 15 LOAD_CONST None - 18 RETURN_VALUE + L. 7 6 LOAD_NAME 1 'False' + 9 STORE_NAME 2 'b' + 12 JUMP_FORWARD 0 'to 15' + 15_0 COME_FROM 12 '12' + 15 LOAD_CONST None + 18 RETURN_VALUE diff --git a/pytest/testdata/ifelse-2.7.right b/pytest/testdata/ifelse-2.7.right index de0679cd..f7a7d261 100644 --- a/pytest/testdata/ifelse-2.7.right +++ b/pytest/testdata/ifelse-2.7.right @@ -1,15 +1,15 @@ # Python 2.7 # Embedded file name: simple_source/branching/05_ifelse.py - 3 0 LOAD_NAME 0 'True' - 3 POP_JUMP_IF_FALSE 15 'to 15' + L. 3 0 LOAD_NAME 0 'True' + 3 POP_JUMP_IF_FALSE 15 'to 15' - 4 6 LOAD_CONST 1 - 9 STORE_NAME 1 'b' - 12 JUMP_FORWARD 6 'to 21' + L. 4 6 LOAD_CONST 1 + 9 STORE_NAME 1 'b' + 12 JUMP_FORWARD 6 'to 21' - 6 15 LOAD_CONST 2 - 18 STORE_NAME 2 'd' - 21_0 COME_FROM 12 '12' - 21 LOAD_CONST None - 24 RETURN_VALUE + L. 6 15 LOAD_CONST 2 + 18 STORE_NAME 2 'd' + 21_0 COME_FROM 12 '12' + 21 LOAD_CONST None + 24 RETURN_VALUE diff --git a/uncompyle6/scanners/tok.py b/uncompyle6/scanners/tok.py index 4742af3f..d7a0a9df 100644 --- a/uncompyle6/scanners/tok.py +++ b/uncompyle6/scanners/tok.py @@ -120,12 +120,19 @@ class Token: def __str__(self): return self.format(line_prefix="") - def format(self, line_prefix=""): - prefix = ( - "\n%s%4d " % (line_prefix, self.linestart) - if self.linestart - else (" " * (6 + len(line_prefix))) - ) + def format(self, line_prefix="", token_num=None): + if token_num is not None: + prefix = ( + "\n(%03d)%s L.%4d " % (token_num, line_prefix, self.linestart) + if self.linestart + else ("(%03d)%s" % (token_num, " " * (9 + len(line_prefix)))) + ) + else: + prefix = ( + "\n%s L.%4d " % (line_prefix, self.linestart) + if self.linestart + else (" " * (9 + len(line_prefix))) + ) offset_opname = "%8s %-17s" % (self.offset, self.kind) if not self.has_arg: diff --git a/uncompyle6/semantics/Makefile b/uncompyle6/semantics/Makefile deleted file mode 100644 index 97ae30ad..00000000 --- a/uncompyle6/semantics/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# Whatever it is you want to do, it should be forwarded to the -# to top-level irectories -PHONY=check all -all: check - -%: - $(MAKE) -C ../.. $@ diff --git a/uncompyle6/semantics/parser_error.py b/uncompyle6/semantics/parser_error.py index 1532ab64..6be97b21 100644 --- a/uncompyle6/semantics/parser_error.py +++ b/uncompyle6/semantics/parser_error.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 by Rocky Bernstein +# Copyright (c) 2018, 2020 by Rocky Bernstein # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -13,13 +13,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . import uncompyle6.parser as python_parser + + class ParserError(python_parser.ParserError): - def __init__(self, error, tokens): - self.error = error # previous exception + def __init__(self, error, tokens, debug): + self.error = error # previous exception self.tokens = tokens + self.debug = debug def __str__(self): - lines = ['--- This code section failed: ---'] - lines.extend([str(i) for i in self.tokens]) - lines.extend( ['', str(self.error)] ) - return '\n'.join(lines) + lines = ["--- This code section failed: ---"] + if self.debug: + lines.extend([t.format(token_num=i + 1) for i, t in enumerate(self.tokens)]) + else: + lines.extend([t.format() for t in self.tokens]) + lines.extend(["", str(self.error)]) + return "\n".join(lines) diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 14718ae8..0381f18f 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -2480,7 +2480,7 @@ class SourceWalker(GenericASTTraversal, object): ast = python_parser.parse(self.p, tokens, customize) self.p.insts = p_insts except (python_parser.ParserError, AssertionError) as e: - raise ParserError(e, tokens) + raise ParserError(e, tokens, self.p.debug['reduce']) checker(ast, False, self.ast_errors)