do not create output files on error
[sv2nmigen.git] / pypreproc.py
1 import sys
2 quote = "\""
3
4
5 class Preprocessor:
6 def __init__(self):
7 self.docstrings = []
8
9 def removeComments(self, data):
10 # print(data)
11 ret = ""
12 in_docstring = False
13 docstring = ""
14 for line in data.split("\n"):
15 docstring_end = ("#docstring_end" in line)
16 if "#docstring_begin" in line:
17 ret += "//DOCSTRING_PLACEHOLDER\n"
18 in_docstring = True
19 docstring = ""
20 if(in_docstring == False):
21 ret += line + "\n"
22 else:
23 if(not docstring_end):
24 docstring += line + "\n"
25 if(docstring_end):
26 in_docstring = False
27 self.docstrings += [docstring]
28 print(docstring)
29 return ret
30
31 def insertDocstrings(self, data):
32 ret = ""
33 docstring_counter = 0
34 for line in data.split("\n"):
35 if("//DOCSTRING_PLACEHOLDER" in line):
36 ret += quote*3
37 ret += self.docstrings[docstring_counter]
38 ret += quote*3
39 ret += "\n"
40 docstring_counter += 1
41 else:
42 ret += "#"+line + "\n"
43 return ret