checkParagraphs.py
1.05 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from enum import Enum
import sys
class State(Enum):
DEF = 0
NEWPAR = 1
ENDSEN = 2
ENDPAR = 3
def indent(l: str) -> int:
i = 0
while l[i] == '\t': i += 2
return i / 2
if __name__ == '__main__':
with open(sys.argv[1]) as i:
state = State.DEF
ab = ""
tokenAb = ""
abEnd = 0
for l in i:
if len(l) == 1:
if state == State.ENDSEN:
tokenAb = tokenAb.replace(chr(160), ' ')
ab = ab.replace(chr(160), ' ')
if ab.rstrip(' ') != tokenAb:
print("Mismatch in " + sys.argv[1] + ":\n" + tokenAb + "\n" + ab)
print([i for i in range(len(tokenAb)) if tokenAb[i] != ab[i]])
tokenAb = ""
abEnd = 0
state = State.ENDPAR
elif state != State.ENDPAR:
state = State.ENDSEN
elif indent(l) == 0:
if state == State.NEWPAR:
ab = l[:-2]
state = State.DEF
elif indent(l) == 1:
state = State.NEWPAR
elif indent(l) == 3:
split = l.split('; ')
beg = int(split[1])
length = int(split[2])
tokenAb += ' ' * (beg - abEnd)
tokenAb += split[3]
abEnd = beg + length
state = State.DEF