-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern.py
More file actions
49 lines (43 loc) · 1.07 KB
/
pattern.py
File metadata and controls
49 lines (43 loc) · 1.07 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
import re
# Patterns kept in their own file to avoid confusing the LLM when it tries to apply a diff to itself
code_block_pattern = re.compile(
r"(?:^([^\n`]+)\n)?^\s*```([^\n]*)\n"
r"(.*?^\s*>>>>>>> REPLACE)" # This lets us support internal triple-backticks
r"\s*\n^\s*```",
re.MULTILINE | re.DOTALL
)
search_block_pattern = re.compile(
r"^\s*<<<<<<< SEARCH\s*\n"
r"(.*?)(?:\r?\n)?" # Whitespace capture shouldn't be this crusty ;_;
r"^\s*=======\s*\n"
r"(.*?)(?:\r?\n)?"
r"^\s*>>>>>>> REPLACE",
re.MULTILINE | re.DOTALL
)
rewrite_block_pattern = re.compile(
r"^\s*<<<<<<< REWRITE\s*\n"
r"(.*?)(?:\r?\n)?"
r"^\s*>>>>>>> REPLACE",
re.MULTILINE | re.DOTALL
)
plan_block_pattern = re.compile(
r"^<<<<<<< PLAN\n"
r"Title:\s*(.*?)\n"
r"Prompt:\s*(.*?)"
r"^>>>>>>> END",
re.MULTILINE | re.DOTALL
)
diff_example = """```
dir/filename.ext
<<<<<<< SEARCH
exact original text
=======
new text
>>>>>>> REPLACE
```"""
rewrite_example = """```
dir/filename.ext
<<<<<<< REWRITE
new text
>>>>>>> REPLACE
```"""