From aca96263d8d395b1bf7fc61f04585d6da4c8a1fb Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 21:16:22 -0700 Subject: [PATCH] aider: Added comments to the regex pattern in `aider/coder.py` to make it clearer. # Context: USER: can you modify the code to add your earlier regex comments? ASSISTANT: Sure, I will add comments to the regex pattern in the `aider/coder.py` file to make it clearer. Here are the changes: ```python aider/coder.py <<<<<<< ORIGINAL pattern = re.compile( r"(^```\S*\s*)?^((?:[a-zA-Z]:\\|/)?(?:[\w\s.-]+[\\/])*\w+(\.[\w\s.-]+)*)\s+(^```\S*\s*)?^<<<<<<< ORIGINAL\n(.*?\n?)^=======\n(.*?)^>>>>>>> UPDATED", # noqa: E501 re.MULTILINE | re.DOTALL, ) ======= pattern = re.compile( # Optional: Matches the start of a code block (e.g., ```python) and any following whitespace r"(^```\S*\s*)?" # Matches the file path r"^((?:[a-zA-Z]:\\|/)?(?:[\w\s.-]+[\\/])*\w+(\.[\w\s.-]+)*)" # Optional: Matches the end of a code block (e.g., ```) and any following whitespace r"\s+(^```\S*\s*)?" # Matches the start of the ORIGINAL section and captures its content r"^<<<<<<< ORIGINAL\n(.*?\n?)" # Matches the separator between ORIGINAL and UPDATED sections and captures the UPDATED content r"^=======\n(.*?)" # Matches the end of the UPDATED section r"^>>>>>>> UPDATED", re.MULTILINE | re.DOTALL, ) >>>>>>> UPDATED ``` This should make the regex pattern more understandable. --- aider/coder.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/aider/coder.py b/aider/coder.py index f4f0a6e06..20784e3fe 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -344,7 +344,18 @@ class Coder: # self.console.print(md) pattern = re.compile( - r"(^```\S*\s*)?^((?:[a-zA-Z]:\\|/)?(?:[\w\s.-]+[\\/])*\w+(\.[\w\s.-]+)*)\s+(^```\S*\s*)?^<<<<<<< ORIGINAL\n(.*?\n?)^=======\n(.*?)^>>>>>>> UPDATED", # noqa: E501 + # Optional: Matches the start of a code block (e.g., ```python) and any following whitespace + r"(^```\S*\s*)?" + # Matches the file path + r"^((?:[a-zA-Z]:\\|/)?(?:[\w\s.-]+[\\/])*\w+(\.[\w\s.-]+)*)" + # Optional: Matches the end of a code block (e.g., ```) and any following whitespace + r"\s+(^```\S*\s*)?" + # Matches the start of the ORIGINAL section and captures its content + r"^<<<<<<< ORIGINAL\n(.*?\n?)" + # Matches the separator between ORIGINAL and UPDATED sections and captures the UPDATED content + r"^=======\n(.*?)" + # Matches the end of the UPDATED section + r"^>>>>>>> UPDATED", re.MULTILINE | re.DOTALL, )