-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
transformGrammar.py
52 lines (44 loc) · 1.36 KB
/
transformGrammar.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
52
import sys, os, re, shutil
from glob import glob
from pathlib import Path
def main(argv):
fixLexer("parser/PlSqlLexer.g4")
fixParser("parser/PlSqlParser.g4")
def fixLexer(file_path):
print("Altering " + file_path)
if not os.path.exists(file_path):
print(f"Could not find file: {file_path}")
sys.exit(1)
parts = os.path.split(file_path)
file_name = parts[-1]
shutil.move(file_path, file_path + ".bak")
input_file = open(file_path + ".bak",'r')
output_file = open(file_path, 'w')
for x in input_file:
if 'self.' in x:
x = x.replace('self.', 'this.')
output_file.write(x)
output_file.flush()
print("Writing ...")
input_file.close()
output_file.close()
def fixParser(file_path):
print("Altering " + file_path)
if not os.path.exists(file_path):
print(f"Could not find file: {file_path}")
sys.exit(1)
parts = os.path.split(file_path)
file_name = parts[-1]
shutil.move(file_path, file_path + ".bak")
input_file = open(file_path + ".bak",'r')
output_file = open(file_path, 'w')
for x in input_file:
if 'self.' in x:
x = x.replace('self.', 'p.')
output_file.write(x)
output_file.flush()
print("Writing ...")
input_file.close()
output_file.close()
if __name__ == '__main__':
main(sys.argv)