Spaces:
Sleeping
Sleeping
Download benchmark/patch_parser.py from Aaxelis/Repo-Searcher: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/Aaxelis/Repo-Searcher/resolve/main/benchmark/patch_parser.py
- Command line
-
hf download hf://spaces/Aaxelis/Repo-Searcher/benchmark/patch_parser.py
-
curl -L -o patch_parser.py https://huggingface.co/spaces/Aaxelis/Repo-Searcher/resolve/main/benchmark/patch_parser.py
1.55 kB
| import re | |
| def extract_java_files(patch: str) -> list[str]: | |
| files = set() | |
| for match in re.finditer( | |
| r"^diff --git a/(.*?\.java) b/(.*?\.java)", patch, re.MULTILINE | |
| ): | |
| files.add(match.group(2)) | |
| for match in re.finditer( | |
| r"^diff --git /dev/null b/(.*?\.java)", patch, re.MULTILINE | |
| ): | |
| files.add(match.group(1)) | |
| return sorted(files) | |
| def extract_methods_from_patch(patch: str) -> list[str]: | |
| methods = set() | |
| for match in re.finditer(r"^@@ .+? @@\s+.*?(\w+)\s*\(", patch, re.MULTILINE): | |
| method_name = match.group(1) | |
| if method_name not in ( | |
| "if", | |
| "for", | |
| "while", | |
| "switch", | |
| "catch", | |
| "class", | |
| "interface", | |
| "enum", | |
| "new", | |
| "return", | |
| ): | |
| methods.add(method_name) | |
| sig_pattern = re.compile( | |
| r"^[+]\s*(?:public|private|protected)?\s*(?:static\s+)?" | |
| r"(?:final\s+)?(?:synchronized\s+)?(?:abstract\s+)?" | |
| r"(?:<[^>]+>\s+)?" | |
| r"\w+(?:<[^>]*>)?(?:\[\])?\s+" | |
| r"(\w+)\s*\(", | |
| re.MULTILINE, | |
| ) | |
| for match in sig_pattern.finditer(patch): | |
| method_name = match.group(1) | |
| if method_name not in ( | |
| "if", | |
| "for", | |
| "while", | |
| "switch", | |
| "catch", | |
| "class", | |
| "interface", | |
| "enum", | |
| "new", | |
| "return", | |
| ): | |
| methods.add(method_name) | |
| return sorted(methods) | |