convert binary and unary operators
[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 return ret
29
30 def insertDocstrings(self, data):
31 ret = ""
32 docstring_counter = 0
33 for line in data.split("\n"):
34 if("//DOCSTRING_PLACEHOLDER" in line):
35 ret += quote*3
36 ret += self.docstrings[docstring_counter]
37 ret += quote*3
38 ret += "\n"
39 docstring_counter += 1
40 else:
41 ret += "#"+line + "\n"
42 return ret