-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathfix_indentation_bug.py
45 lines (37 loc) · 1.08 KB
/
fix_indentation_bug.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
"""
This module fix the Python indentation
for ANTLR generated codes
"""
import os
import sys
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
filename = input("Enter parser script's filename (Leave empty to automatically find in the current directory): ")
if filename == "":
current_dir_filemames = os.listdir(".")
for name in current_dir_filemames:
if name.endswith("Parser.py"):
filename = name
break
if filename == "":
print("Couldn't find any parser in this directory.\nAborting.")
exit()
else:
print("Fixing " + filename + ".")
print("Reading...")
file = open(filename, "r")
lines = file.readlines()
file.close()
print("Processing...")
for i in range(len(lines)):
space_count = 0
while space_count < len(lines[i]) and lines[i][space_count] == ' ':
space_count += 1
if space_count > 10 and space_count % 4 == 2:
lines[i] = lines[i][10:]
print("Writing...")
file = open(filename, "w")
file.writelines(lines)
file.close()
print("Done.")