-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from alexandrosraikos/2.0
2.0 Restructuring - This is an update on structure and semantics for the package. Objective logic was more closely followed to allow for further extension of the parsing capabilities.
- Loading branch information
Showing
5 changed files
with
241 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,5 +54,5 @@ | |
".npy", | ||
".npz", | ||
".ini", | ||
".inc" | ||
".inc", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# --------- | ||
# This source file is part of the Dependency Extractor python open source package. | ||
# Copyright (c) 2021, Alexandros Raikos tou Konstantinou. | ||
# | ||
# Licensed under the MIT License. | ||
# --------- | ||
# | ||
# Define supported languages with their corresponding compiled import regex. | ||
# ----- | ||
# NOTE: Strict suffix queries exclude local and relative imports. | ||
# NOTE: These expressions were formulated with the help of https://regex101.com. | ||
|
||
import re | ||
from typing import List | ||
|
||
|
||
class ProgrammingLanguage: | ||
def __init__(self, name, extensions, expressions): | ||
self.name: str = name | ||
self.extensions: List[str] = extensions | ||
self.expressions = expressions | ||
|
||
|
||
supported_languages = [ | ||
ProgrammingLanguage( | ||
"C++", | ||
extensions=[".cpp", ".hpp"], | ||
expressions={ | ||
"dependencies": { | ||
"regular": re.compile( | ||
r"#include [<\"](?P<dependency>[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\"\\|,.<>\/?]+)[\">]" | ||
), | ||
"strict": re.compile( | ||
r"#include [<\"](?P<dependency>[^.][a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\"\\|,.<>\/?]+[^.hpp][^.h])[\">]" | ||
), | ||
} | ||
}, | ||
), | ||
ProgrammingLanguage( | ||
"C", | ||
extensions=[".c", ".h"], | ||
expressions={ | ||
"dependencies": { | ||
"regular": re.compile( | ||
r"#include [<\"](?P<dependency>[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\"\\|,.<>\/?]+)[\">]" | ||
), | ||
"strict": re.compile( | ||
r"#include [<\"](?P<dependency>[^.][a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':\"\\|,.<>\/?]+[^.hpp][^.h])[\">]" | ||
), | ||
} | ||
}, | ||
), | ||
# TODO: #1 Needs improvement (it only reads last dependency in list + strict mode.) | ||
ProgrammingLanguage( | ||
"Go", | ||
extensions=[".go"], | ||
expressions={ | ||
"dependencies": { | ||
"regular": re.compile( | ||
r"import \(\n(?:\t\"(?P<dependency>[a-zA-Z0-9!@#$%^&*()_+\-\[\]{};':\"\\.\/?]+)\"[\n]+)+\)" | ||
) | ||
} | ||
}, | ||
), | ||
ProgrammingLanguage( | ||
"Java", | ||
extensions=[".java"], | ||
expressions={ | ||
"dependencies": { | ||
"regular": re.compile( | ||
r"import (?P<dependency>[a-zA-Z0-9!@#$%^&*_+\-\[\]{};':\"\\.\/?]+);" | ||
) | ||
} | ||
}, | ||
), | ||
ProgrammingLanguage( | ||
"Python", | ||
extensions=[".py", ".pyi"], | ||
expressions={ | ||
"dependencies": { | ||
"regular": re.compile( | ||
r"^(?:[ ]|)+(?:import|from) (?P<dependency>[^_][a-zA-Z0-9!@#$%^&*()_+\-\[\]{}.;':\"\\\/?]+)" | ||
), | ||
"strict": re.compile( | ||
r"^(?:[ ]|)+(?:import|from) (?P<dependency>[^_.][a-zA-Z0-9!@#$%^&*()_+\-\[\]{};':\"\\\/?]+)" | ||
), | ||
} | ||
}, | ||
), | ||
] |
Oops, something went wrong.