8 def __init__ (self,input,output=None):
12 # left part is non-greedy
13 comment = re.compile("(.*?)--.*")
14 spaces = re.compile("^\s+(\S.*)")
15 view = re.compile("(?i)\s*create\s+(or\s+replace)?\s+view.*")
19 outfile = open(self.output, "a")
22 with open(self.input) as feed:
23 contents = feed.read()
24 parts = contents.split(";")
26 # normalize: remove comments, linebreaks, trailing spaces..
27 lines = part.split('\n')
31 match = Schema.comment.match(line)
34 out_lines.append(line)
36 out_line = " ".join(out_lines)
37 # remove trailing spaces
38 match = Schema.spaces.match(out_line)
40 out_line = match.group(1)
41 match = Schema.view.match(out_line)
43 outfile.write("{};\n".format(out_line))
44 if outfile != sys.stdout:
47 if __name__ == '__main__':
48 if len(sys.argv) not in [2, 3]:
49 print('Usage:', sys.argv[0], 'input [output]')
56 Schema(input, output).parse()