|
@@ -0,0 +1,50 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import sys
|
|
|
+import re
|
|
|
+
|
|
|
+def die(message):
|
|
|
+ sys.stderr.write(message + "\n")
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+if len(sys.argv) != 3:
|
|
|
+ die("Usage: python3 ./pythonize_constants.py input.cpp output.py")
|
|
|
+
|
|
|
+[filename_in, filename_out] = sys.argv[1:3]
|
|
|
+
|
|
|
+
|
|
|
+ignore = re.compile('^(#|namespace|})')
|
|
|
+comment = re.compile('^//(.*)')
|
|
|
+constant = re.compile('^[a-zA-Z].*?([a-zA-Z_0-9]+\\s*=.*);')
|
|
|
+
|
|
|
+with open(filename_in) as file_in, open(filename_out, "w") as file_out:
|
|
|
+ file_out.write("# This file is generated from " + filename_in + "\n" +
|
|
|
+ "# by the pythonize_constants.py script.\n" +
|
|
|
+ "# Do not edit, all changes will be lost.\n\n")
|
|
|
+ for line in file_in:
|
|
|
+ if ignore.match(line):
|
|
|
+ continue
|
|
|
+
|
|
|
+ line = comment.sub('#\\1', line)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ line = constant.sub('\\1', line)
|
|
|
+
|
|
|
+ file_out.write(line)
|