-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathresolver.py
More file actions
89 lines (72 loc) · 2.32 KB
/
Copy pathresolver.py
File metadata and controls
89 lines (72 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import re
def select(
text,
lines=None,
from_token=None,
to_token=None,
block=None,
inside_block=None,
lang=None,
):
selected_lines = []
if lines:
for line_range in lines.split(","):
range_match = re.match(r"(\d+)-(\d+)", line_range)
if range_match:
start = int(range_match.group(1))
end = int(range_match.group(2))
for i in range(start, end + 1):
selected_lines.append(i)
elif line_range.strip() != "":
selected_lines.append(int(line_range))
if block:
i = 0
delim_count = 0
for line in text.splitlines():
first_line_of_block = False
i = i + 1
if block in line and delim_count <= 0:
delim_count = 0
first_line_of_block = True
delim_count += line.count("{")
if delim_count > 0:
if not first_line_of_block:
delim_count += line.count("{")
selected_lines.append(i)
delim_count -= line.count("}")
if inside_block:
i = 0
delim_count = 0
for line in text.splitlines():
first_line_of_block = False
i = i + 1
if inside_block in line and delim_count <= 0:
delim_count = 0
first_line_of_block = True
delim_count += line.count("{")
delim_count -= line.count("}")
if delim_count > 0 and not first_line_of_block:
delim_count += line.count("{")
selected_lines.append(i)
if from_token and to_token:
i = 0
active = False
for line in text.splitlines():
i = i + 1
if not active and from_token in line:
active = True
if active:
selected_lines.append(i)
if active and to_token in line:
active = False
result = ""
source_lines = text.splitlines()
last_selected = 0
for i in sorted(selected_lines):
if i > (last_selected + 1) and last_selected != 0:
result += "\n⋯\n\n"
result += source_lines[i - 1] + "\n"
last_selected = i
if result == "":
return text
return result