[GH-ISSUE #115] Regex of HASDEPENDENCY in Dependency Parsing #99

Open
opened 2026-10-26 21:03:30 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @alex8937 on GitHub (Feb 1, 2024).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-Coder/issues/115

Could you share more details of regex used in Dependency Parsing for each language?

Originally created by @alex8937 on GitHub (Feb 1, 2024). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-Coder/issues/115 Could you share more details of regex used in Dependency Parsing for each language?
Author
Owner

@guoday commented on GitHub (Feb 7, 2024):

We design different regex patterns according to the grammar characteristics of different languages.

For examples, for c language, we use #inlcude to find dependency:

def extract_includes(file_content):
    includes = set()
    include_pattern = r'#include[ \t]+"([^"]+)"|#include[ \t]+<([^>]+)>'
    for match in re.finditer(include_pattern, file_content):
        include_path = match.group(1) or match.group(2)
        includes.add(include_path)
    return includes


def find_dependencies(file_paths, contents):
    extensions = [".c", ".h"]
    file_paths = [file_name for file_name in file_paths if any(file_name.endswith(ext) for ext in extensions)]
    dependencies = []
    for file_path_A in file_paths:
        content_A = contents[file_path_A]
        if not content_A.strip():
            continue

        includes_A = extract_includes(content_A)
        for file_path_B in file_paths:
            if file_path_A != file_path_B:
                file_name_B = os.path.basename(file_path_B)
                for include in includes_A:
                    if include == file_name_B or include.endswith("/" + file_name_B):
                        dependencies.append((file_path_B, file_path_A))
                        break

    return dependencies
<!-- gh-comment-id:1931570016 --> @guoday commented on GitHub (Feb 7, 2024): We design different regex patterns according to the grammar characteristics of different languages. For examples, for `c` language, we use `#inlcude` to find dependency: ``` def extract_includes(file_content): includes = set() include_pattern = r'#include[ \t]+"([^"]+)"|#include[ \t]+<([^>]+)>' for match in re.finditer(include_pattern, file_content): include_path = match.group(1) or match.group(2) includes.add(include_path) return includes def find_dependencies(file_paths, contents): extensions = [".c", ".h"] file_paths = [file_name for file_name in file_paths if any(file_name.endswith(ext) for ext in extensions)] dependencies = [] for file_path_A in file_paths: content_A = contents[file_path_A] if not content_A.strip(): continue includes_A = extract_includes(content_A) for file_path_B in file_paths: if file_path_A != file_path_B: file_name_B = os.path.basename(file_path_B) for include in includes_A: if include == file_name_B or include.endswith("/" + file_name_B): dependencies.append((file_path_B, file_path_A)) break return dependencies ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-Coder#99
No description provided.