Correct long-literals for Python 2.7

This commit is contained in:
rocky
2022-10-16 19:33:51 -04:00
parent bb9b9fb4b3
commit 5b3ea47bac
8 changed files with 26 additions and 11 deletions

View File

@@ -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 = []

View File

@@ -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
"""

View File

@@ -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,

View File

@@ -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,

View File

@@ -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]