You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
More offsets captrued Add %b specifer
%b - associate text before specifier pysource.py: small doc correction
This commit is contained in:
@@ -36,6 +36,17 @@ The node will be associated with the text break, excluding the trailing newline.
|
|||||||
|
|
||||||
Note we assocate the accumulated text with the node normally, but we just don't
|
Note we assocate the accumulated text with the node normally, but we just don't
|
||||||
do it recursively which is where offsets are probably located.
|
do it recursively which is where offsets are probably located.
|
||||||
|
|
||||||
|
2. %b
|
||||||
|
-----
|
||||||
|
|
||||||
|
%b associates the text from the previous start node up to what we have now
|
||||||
|
|
||||||
|
For example in:
|
||||||
|
'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ),
|
||||||
|
|
||||||
|
The node position 0 will be associated with "import".
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# FIXME: DRY code with pysource
|
# FIXME: DRY code with pysource
|
||||||
@@ -82,8 +93,9 @@ TABLE_DIRECT_FRAGMENT = {
|
|||||||
'raise_stmt0': ( '%|%rraise\n', ),
|
'raise_stmt0': ( '%|%rraise\n', ),
|
||||||
'importstmt': ( '%|import %c%x\n', 2, (2, (0, 1)), ),
|
'importstmt': ( '%|import %c%x\n', 2, (2, (0, 1)), ),
|
||||||
'importfrom': ( '%|from %[2]{pattr}%x import %c\n', (2, (0, 1)), 3),
|
'importfrom': ( '%|from %[2]{pattr}%x import %c\n', (2, (0, 1)), 3),
|
||||||
|
'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ),
|
||||||
'list_for': (' for %c%x in %c%c', 2, (2,(1,)), 0, 3 ),
|
'list_for': (' for %c%x in %c%c', 2, (2,(1,)), 0, 3 ),
|
||||||
'forstmt': ( '%|for %c%x in %c:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4 ),
|
'forstmt': ( '%|for%b %c%x in %c:\n%+%c%-\n\n', 0, 3, (3, (2,)), 1, 4 ),
|
||||||
'forelsestmt': (
|
'forelsestmt': (
|
||||||
'%|for %c in %c%x:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
|
'%|for %c in %c%x:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
|
||||||
'forelselaststmt': (
|
'forelselaststmt': (
|
||||||
@@ -91,6 +103,10 @@ TABLE_DIRECT_FRAGMENT = {
|
|||||||
'forelselaststmtl': (
|
'forelselaststmtl': (
|
||||||
'%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
|
'%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
|
||||||
|
|
||||||
|
'whilestmt': ( '%|while%b %c:\n%+%c%-\n\n', 0, 1, 2 ),
|
||||||
|
'whileelsestmt': ( '%|while%b %c:\n%+%c%-%|else:\n%+%c%-\n\n', 0, 1, 2, -2 ),
|
||||||
|
'whileelselaststmt': ( '%|while%b %c:\n%+%c%-%|else:\n%+%c%-', 0, 1, 2, -2 ),
|
||||||
|
'forstmt': ( '%|for%b %c in %c:\n%+%c%-\n\n', 0, 3, 1, 4 ),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -215,7 +231,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for n in node:
|
for n in node:
|
||||||
self.set_pos_info(n, start, len(self.f.getvalue()))
|
self.set_pos_info_recurse(n, start, len(self.f.getvalue()))
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||||
@@ -1409,6 +1425,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
# print('======')
|
# print('======')
|
||||||
|
|
||||||
startnode_start = len(self.f.getvalue())
|
startnode_start = len(self.f.getvalue())
|
||||||
|
start = startnode_start
|
||||||
|
|
||||||
fmt = entry[0]
|
fmt = entry[0]
|
||||||
arg = 1
|
arg = 1
|
||||||
@@ -1444,6 +1461,10 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
elif typ == ',':
|
elif typ == ',':
|
||||||
if lastC == 1:
|
if lastC == 1:
|
||||||
self.write(',')
|
self.write(',')
|
||||||
|
elif typ == 'b':
|
||||||
|
finish = len(self.f.getvalue())
|
||||||
|
self.set_pos_info(node[entry[arg]], start, finish)
|
||||||
|
arg += 1
|
||||||
elif typ == 'c':
|
elif typ == 'c':
|
||||||
start = len(self.f.getvalue())
|
start = len(self.f.getvalue())
|
||||||
self.preorder(node[entry[arg]])
|
self.preorder(node[entry[arg]])
|
||||||
@@ -1534,9 +1555,6 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
|||||||
print(node)
|
print(node)
|
||||||
raise
|
raise
|
||||||
m = escape.search(fmt, i)
|
m = escape.search(fmt, i)
|
||||||
if hasattr(node, 'offset') and (self.name, node.offset) not in self.offsets:
|
|
||||||
print("Type %s of node %s has an offset %d" % (typ, node, node.offset))
|
|
||||||
pass
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.write(fmt[i:])
|
self.write(fmt[i:])
|
||||||
@@ -1804,7 +1822,7 @@ if __name__ == '__main__':
|
|||||||
return fn.__code__
|
return fn.__code__
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
[x for x in range(3) if x % 2 == 0]
|
import os, sys
|
||||||
|
|
||||||
def gcd(a, b):
|
def gcd(a, b):
|
||||||
if a > b:
|
if a > b:
|
||||||
|
@@ -362,7 +362,7 @@ TABLE_DIRECT = {
|
|||||||
# Python 2.5 Additions
|
# Python 2.5 Additions
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
# Import style for 2.5
|
# Import style for 2.5+
|
||||||
'importstmt': ( '%|import %c\n', 2),
|
'importstmt': ( '%|import %c\n', 2),
|
||||||
'importstar': ( '%|from %[2]{pattr} import *\n', ),
|
'importstar': ( '%|from %[2]{pattr} import *\n', ),
|
||||||
'importfrom': ( '%|from %[2]{pattr} import %c\n', 3 ),
|
'importfrom': ( '%|from %[2]{pattr} import %c\n', 3 ),
|
||||||
|
Reference in New Issue
Block a user