Skip to content

Commit de3ea99

Browse files
committed
Port indenter to python
1 parent 68372ae commit de3ea99

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/etc/indenter

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
#!/usr/bin/perl
2-
use strict;
3-
use warnings;
1+
#!/usr/bin/env python
2+
import re
3+
import sys
44

5-
my $indent = 0;
6-
while (<>) {
7-
if (/^rust: ~">>/) {
8-
$indent += 1;
9-
}
5+
indent = 0
6+
more_re = re.compile(r"^rust: ~\">>")
7+
less_re = re.compile(r"^rust: ~\"<<")
8+
while True:
9+
line = sys.stdin.readline()
10+
if not line:
11+
break
1012

11-
printf "%03d %s%s", $indent, (" " x $indent), $_;
13+
if more_re.match(line):
14+
indent += 1
1215

13-
if (/^rust: ~"<</) {
14-
$indent -= 1;
15-
}
16-
}
16+
print "%03d %s%s" % (indent, " " * indent, line.strip())
17+
18+
if less_re.match(line):
19+
indent -= 1

0 commit comments

Comments
 (0)