cpp-pd-code-simplify-interface 0.1.14__tar.gz → 0.1.15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/PKG-INFO +1 -1
- cpp_pd_code_simplify_interface-0.1.15/cpp_pd_code_simplify_interface/__main__.py +10 -0
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/cpp_pd_code_simplify_interface/main.py +57 -47
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/pyproject.toml +1 -1
- cpp_pd_code_simplify_interface-0.1.14/cpp_pd_code_simplify_interface/__main__.py +0 -4
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/README.md +0 -0
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/build_backend/cpp_pd_code_simplify_interface_build_backend.py +0 -0
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/cpp_pd_code_simplify_interface/__init__.py +0 -0
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/cpp_pd_code_simplify_interface/_worker.py +0 -0
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/cpp_pd_code_simplify_interface/data/include/pdcode_simplify/pdcode_simplify.hpp +0 -0
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/cpp_pd_code_simplify_interface/data/src/native_interface.cpp +0 -0
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/cpp_pd_code_simplify_interface/data/src/pdcode_simplify.cpp +0 -0
- {cpp_pd_code_simplify_interface-0.1.14 → cpp_pd_code_simplify_interface-0.1.15}/cpp_pd_code_simplify_interface/py.typed +0 -0
|
@@ -90,10 +90,7 @@ def normalize_pd_codes(pd_codes: PdManyInput) -> list[str]:
|
|
|
90
90
|
return [normalize_pd_code(pd_code) for pd_code in pd_codes]
|
|
91
91
|
|
|
92
92
|
|
|
93
|
-
def
|
|
94
|
-
line_start = text.rfind("\n", 0, block_start)
|
|
95
|
-
line_start = 0 if line_start == -1 else line_start + 1
|
|
96
|
-
before_block = text[line_start:block_start]
|
|
93
|
+
def _label_for_line_prefix(before_block: str, label_prefix: str, index: int) -> str:
|
|
97
94
|
if ":" in before_block:
|
|
98
95
|
line_label = before_block.split(":", 1)[0].strip()
|
|
99
96
|
if line_label:
|
|
@@ -104,56 +101,62 @@ def _label_for_block(text: str, block_start: int, label_prefix: str, index: int)
|
|
|
104
101
|
|
|
105
102
|
|
|
106
103
|
def _pd_file_jobs(path: str) -> list[tuple[str, str]]:
|
|
107
|
-
text = pathlib.Path(path).read_text(encoding="utf-8")
|
|
108
104
|
jobs: list[tuple[str, str]] = []
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
105
|
+
fallback_jobs: list[tuple[str, str]] = []
|
|
106
|
+
current_label: Optional[str] = None
|
|
107
|
+
current_block: list[str] = []
|
|
108
|
+
bracket_depth = 0
|
|
109
|
+
|
|
110
|
+
with pathlib.Path(path).open("r", encoding="utf-8") as input_file:
|
|
111
|
+
for line in input_file:
|
|
112
|
+
cleaned = line.strip()
|
|
113
|
+
if not jobs and not current_block and cleaned and not cleaned.startswith("#"):
|
|
114
|
+
label = path
|
|
115
|
+
payload = cleaned
|
|
116
|
+
if ":" in cleaned:
|
|
117
|
+
line_label, payload = cleaned.split(":", 1)
|
|
118
|
+
line_label = line_label.strip()
|
|
119
|
+
payload = payload.strip()
|
|
120
|
+
if line_label:
|
|
121
|
+
label = f"{path}:{line_label}"
|
|
122
|
+
elif fallback_jobs:
|
|
123
|
+
label = f"{path}#{len(fallback_jobs) + 1}"
|
|
124
|
+
fallback_jobs.append((label, payload))
|
|
125
|
+
|
|
126
|
+
cursor = 0
|
|
127
|
+
while cursor < len(line):
|
|
128
|
+
if current_block:
|
|
129
|
+
char = line[cursor]
|
|
130
|
+
current_block.append(char)
|
|
131
|
+
if char == "[":
|
|
132
|
+
bracket_depth += 1
|
|
133
|
+
elif char == "]":
|
|
134
|
+
bracket_depth -= 1
|
|
135
|
+
if bracket_depth == 0:
|
|
136
|
+
jobs.append((current_label or f"{path}#{len(jobs) + 1}", "".join(current_block)))
|
|
137
|
+
current_label = None
|
|
138
|
+
current_block = []
|
|
139
|
+
cursor += 1
|
|
140
|
+
continue
|
|
141
|
+
|
|
142
|
+
start = line.find("PD[", cursor)
|
|
143
|
+
if start == -1:
|
|
125
144
|
break
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
_label_for_block(text, start, path, index),
|
|
131
|
-
text[start : end + 1],
|
|
132
|
-
))
|
|
133
|
-
index += 1
|
|
134
|
-
position = end + 1
|
|
145
|
+
current_label = _label_for_line_prefix(line[:start], path, len(jobs))
|
|
146
|
+
current_block = ["PD["]
|
|
147
|
+
bracket_depth = 1
|
|
148
|
+
cursor = start + 3
|
|
135
149
|
|
|
136
150
|
if jobs:
|
|
151
|
+
if current_block:
|
|
152
|
+
jobs.append((f"{path}#{len(jobs) + 1}", "".join(current_block).strip()))
|
|
137
153
|
if len(jobs) == 1:
|
|
138
154
|
jobs[0] = (path, jobs[0][1])
|
|
139
155
|
return jobs
|
|
140
156
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
continue
|
|
145
|
-
label = path
|
|
146
|
-
payload = cleaned
|
|
147
|
-
if ":" in cleaned:
|
|
148
|
-
line_label, payload = cleaned.split(":", 1)
|
|
149
|
-
line_label = line_label.strip()
|
|
150
|
-
payload = payload.strip()
|
|
151
|
-
if line_label:
|
|
152
|
-
label = f"{path}:{line_label}"
|
|
153
|
-
elif jobs:
|
|
154
|
-
label = f"{path}#{len(jobs) + 1}"
|
|
155
|
-
jobs.append((label, payload))
|
|
156
|
-
return jobs
|
|
157
|
+
if current_block:
|
|
158
|
+
fallback_jobs.append((f"{path}#{len(fallback_jobs) + 1}", "".join(current_block).strip()))
|
|
159
|
+
return fallback_jobs
|
|
157
160
|
|
|
158
161
|
|
|
159
162
|
@contextlib.contextmanager
|
|
@@ -1033,7 +1036,14 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
|
1033
1036
|
|
|
1034
1037
|
exit_code = 0
|
|
1035
1038
|
if args.pd_file:
|
|
1036
|
-
|
|
1039
|
+
try:
|
|
1040
|
+
jobs = _pd_file_jobs(args.pd_file)
|
|
1041
|
+
except KeyboardInterrupt:
|
|
1042
|
+
print(json.dumps({"error": "interrupted by Ctrl+C"}, indent=2))
|
|
1043
|
+
return 130
|
|
1044
|
+
except Exception as exc:
|
|
1045
|
+
print(json.dumps({"error": str(exc)}, indent=2))
|
|
1046
|
+
return 2
|
|
1037
1047
|
batch_payload = []
|
|
1038
1048
|
show_labels = len(jobs) > 1
|
|
1039
1049
|
for label, line in jobs:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|