Skip to content

Commit 7e56220

Browse files
committed
better rm comments??
1 parent 8ee06e7 commit 7e56220

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

parse.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
def remove_comments(code: str) -> str:
1+
import re
2+
3+
def remove_comments(input_string):
4+
# Regular expression pattern to match /* ... */ style comments
5+
pattern = r'/\*.*?\*/'
6+
cleaned_string = re.sub(pattern, '', input_string, flags=re.DOTALL)
7+
8+
# Remove single-line comments (//) by splitting lines and keeping only non-comment parts
9+
lines = cleaned_string.split('\n')
10+
filtered_lines = []
11+
for line in lines:
12+
line = line.split('//')[0] # Remove everything after // in the line
13+
filtered_lines.append(line.strip())
14+
15+
return ''.join(filtered_lines)
16+
17+
def _remove_comments_old(code: str) -> str:
218
lines = code.splitlines()
319
no_comm = ''
420
in_comment = False

0 commit comments

Comments
 (0)