Add degenerate.py, to strip out generated code and thus make the logic readable
authorNick Downing <downing.nick@gmail.com>
Sun, 1 Jul 2018 15:04:40 +0000 (01:04 +1000)
committerNick Downing <downing.nick@gmail.com>
Sun, 1 Jul 2018 15:04:40 +0000 (01:04 +1000)
degenerate.py [new file with mode: 0755]

diff --git a/degenerate.py b/degenerate.py
new file mode 100755 (executable)
index 0000000..96d362a
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+
+re_begin = re.compile(
+  '([\t ]*# GENERATE .*) BEGIN'
+)
+re_end = re.compile(
+  '([\t ]*# GENERATE END)'
+)
+
+line = sys.stdin.readline()
+while len(line):
+  match = re_begin.match(line)
+  if match is not None:
+    sys.stdout.write(match.group(1))
+    line = sys.stdin.readline()
+    while len(line):
+      match = re_end.match(line)
+      if match is not None:
+        sys.stdout.write(line[len(match.group(1)):])
+        break
+      line = sys.stdin.readline()
+  else:
+    sys.stdout.write(line)
+  line = sys.stdin.readline()