-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspongecasql.py
51 lines (36 loc) · 1.34 KB
/
spongecasql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
if __name__ == '__main__':
filename = sys.argv[-1]
with open(filename) as input_file:
input_code = input_file.read()
output_code = ""
is_string = False
is_inline_comment = False
is_multiline_comment = False
upper = False
prev_char = ""
for char in input_code:
is_comment = is_inline_comment or is_multiline_comment
is_special = is_comment or is_string
two_char = prev_char + char
if char == '\'' and not is_comment:
is_string = not is_string
elif two_char == '--' or char == "#" and not is_special:
is_inline_comment = True
elif two_char == '/*' and not is_special:
is_multiline_comment = True
elif char == '\n' and is_inline_comment:
is_inline_comment = False
elif two_char == '*/' and is_multiline_comment:
is_multiline_comment = False
if not is_special:
if upper:
output_code += char.upper()
else:
output_code += char.lower()
upper = not upper
else:
output_code += char
prev_char = char
with open('sPoNgeCaSeD_' + filename, 'w') as output_file:
output_file.write(output_code)