Fix several bugs to get Python scanner/parser basically working, processes ../tests...
[pilex.git] / degenerate.py
1 #!/usr/bin/env python3
2
3 import re
4 import sys
5
6 re_begin = re.compile(
7   '([\t ]*# GENERATE .*) BEGIN'
8 )
9 re_end = re.compile(
10   '([\t ]*# GENERATE END)'
11 )
12
13 line = sys.stdin.readline()
14 while len(line):
15   match = re_begin.match(line)
16   if match is not None:
17     sys.stdout.write(match.group(1))
18     line = sys.stdin.readline()
19     while len(line):
20       match = re_end.match(line)
21       if match is not None:
22         sys.stdout.write(line[len(match.group(1)):])
23         break
24       line = sys.stdin.readline()
25   else:
26     sys.stdout.write(line)
27   line = sys.stdin.readline()