You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Correct long-literals for Python 2.7
This commit is contained in:
@@ -99,7 +99,7 @@ class PythonParser(GenericASTBuilder):
|
||||
# so on but that would require major changes to the
|
||||
# semantic actions
|
||||
self.singleton = frozenset(
|
||||
("str", "store", "_stmts", "suite_stmts_opt", "inplace_op")
|
||||
("str", "store", "_stmts", "suite_stmts_opt", "inplace_op", "add_value")
|
||||
)
|
||||
# Instructions filled in from scanner
|
||||
self.insts = []
|
||||
|
@@ -315,7 +315,9 @@ class Python2Parser(PythonParser):
|
||||
if opname in ("BUILD_CONST_LIST", "BUILD_CONST_SET"):
|
||||
rule = (
|
||||
"""
|
||||
add_consts ::= ADD_VALUE*
|
||||
add_consts ::= add_value+
|
||||
add_value ::= ADD_VALUE
|
||||
add_value ::= ADD_VALUE_VAR
|
||||
const_list ::= COLLECTION_START add_consts %s
|
||||
expr ::= const_list
|
||||
"""
|
||||
|
@@ -171,10 +171,14 @@ class Scanner(object):
|
||||
has_extended_arg=False,
|
||||
)
|
||||
)
|
||||
if tokens[j] == "LOAD_CONST":
|
||||
opname = "ADD_VALUE"
|
||||
else:
|
||||
opname = "ADD_VALUE_VAR"
|
||||
for j in range(collection_start, i):
|
||||
new_tokens.append(
|
||||
Token(
|
||||
opname="ADD_VALUE",
|
||||
opname=opname,
|
||||
attr=tokens[j].attr,
|
||||
pattr=tokens[j].pattr,
|
||||
offset=tokens[j].offset,
|
||||
|
@@ -25,7 +25,6 @@ from xdis import (
|
||||
)
|
||||
from uncompyle6.scanner import Code
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
from uncompyle6.parser import ParserError as ParserError2
|
||||
from uncompyle6.semantics.helper import (
|
||||
find_all_globals,
|
||||
find_globals_and_nonlocals,
|
||||
|
@@ -257,11 +257,14 @@ class NonterminalActions:
|
||||
sep = ", "
|
||||
else:
|
||||
for elem in flat_elems:
|
||||
assert elem.kind == "ADD_VALUE"
|
||||
try:
|
||||
if elem == "add_value":
|
||||
elem = elem[0]
|
||||
if elem == "ADD_VALUE":
|
||||
value = "%r" % elem.pattr
|
||||
except Exception:
|
||||
value = elem.pattr
|
||||
else:
|
||||
assert elem.kind == "ADD_VALUE_VAR"
|
||||
value = "%s" % elem.pattr
|
||||
|
||||
if elem.linestart is not None:
|
||||
if elem.linestart != self.line_number:
|
||||
next_indent = self.indent + INDENT_PER_LEVEL[:-1]
|
||||
|
Reference in New Issue
Block a user