-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparendebugger
More file actions
executable file
·31 lines (28 loc) · 860 Bytes
/
parendebugger
File metadata and controls
executable file
·31 lines (28 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
import fileinput
import re
# Author: David McClosky
# Homepage: http://zorglish.org
# Code: http://github.com/dmcc
depth = 0
sentence_count = 0
for line in fileinput.input():
for token in re.split(r'([\(\)])', line):
token = token.strip()
if not token:
continue
if depth == 0:
print("--- Sentence %d --- " % sentence_count)
sentence_count += 1
if token == '(':
print("{}{}".format('. ' * depth, token))
depth += 1
elif token == ')':
depth -= 1
print("{}{}".format('. ' * depth, token))
if depth < 0:
raise ValueError("Too many )s")
else:
print("{}{}".format('. ' * depth, token))
if depth != 0:
raise ValueError("Not enough )s -- depth wasn't 0 at end.")