]> git.lizzy.rs Git - rust.git/commitdiff
Port indenter to python
authorRicho Healey <richo@psych0tik.net>
Thu, 15 Jan 2015 08:23:46 +0000 (00:23 -0800)
committerRicho Healey <richo@psych0tik.net>
Fri, 16 Jan 2015 16:49:54 +0000 (08:49 -0800)
src/etc/indenter

index 1a3a446533572d421959c7d3ec84b08ec91697cc..b3eed6a144342fd83bf64cc67d579a9c59009365 100755 (executable)
@@ -1,16 +1,19 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
+#!/usr/bin/env python
+import re
+import sys
 
-my $indent = 0;
-while (<>) {
-    if (/^rust: ~">>/) {
-        $indent += 1;
-    }
+indent = 0
+more_re = re.compile(r"^rust: ~\">>")
+less_re = re.compile(r"^rust: ~\"<<")
+while True:
+    line = sys.stdin.readline()
+    if not line:
+        break
 
-    printf "%03d  %s%s", $indent, ("  " x $indent), $_;
+    if more_re.match(line):
+        indent += 1
 
-    if (/^rust: ~"<</) {
-        $indent -= 1;
-    }
-}
+    print "%03d %s%s" % (indent, " " * indent, line.strip())
+
+    if less_re.match(line):
+        indent -= 1