Solved commit bug

This commit is contained in:
Kevin Veen-Birkenbach 2023-09-14 18:18:27 +02:00
parent 1fbf43bfeb
commit 632334f574

26
scan.py
View File

@ -15,31 +15,31 @@ class CodeProcessor:
"""Remove comments based on file type.""" """Remove comments based on file type."""
comment_patterns = { comment_patterns = {
CodeProcessor.PYTHON: [ CodeProcessor.PYTHON: [
(r'^\s*#.*\n?', ''), (r'\s*#.*', '',0),
(r'\"\"\"(.*?)\"\"\"', ''), (r'\"\"\"(.*?)\"\"\"', '', re.DOTALL),
(r"\'\'\'(.*?)\'\'\'", '') (r"\'\'\'(.*?)\'\'\'", '', re.DOTALL)
], ],
CodeProcessor.JS: [ CodeProcessor.JS: [
(r'\s*//.*', ''), (r'\s*//.*', '',0),
(r'/\*.*?\*/', '') (r'/\*.*?\*/', '',0)
], ],
CodeProcessor.C: [ CodeProcessor.C: [
(r'\s*//.*', ''), (r'\s*//.*', '',0),
(r'/\*.*?\*/', '') (r'/\*.*?\*/', '',0)
], ],
CodeProcessor.CPP: [ CodeProcessor.CPP: [
(r'\s*//.*', ''), (r'\s*//.*', '',0),
(r'/\*.*?\*/', '') (r'/\*.*?\*/', '',0)
], ],
CodeProcessor.H: [ CodeProcessor.H: [
(r'\s*//.*', ''), (r'\s*//.*', '',0),
(r'/\*.*?\*/', '') (r'/\*.*?\*/', '',0)
] ]
} }
patterns = comment_patterns.get(file_type, []) patterns = comment_patterns.get(file_type, [])
for pattern, repl in patterns: for pattern, repl, flags in patterns:
content = re.sub(pattern, repl, content, flags=re.DOTALL) content = re.sub(pattern, repl, content, flags=flags)
return content.strip() return content.strip()
@staticmethod @staticmethod