-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdedup.py
More file actions
27 lines (25 loc) · 753 Bytes
/
dedup.py
File metadata and controls
27 lines (25 loc) · 753 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Remove duplicates and some bogons from extracted ABNF.
Use, copy and modify at your own risk."""
f = open("some.abnf","r")
fixed = []
for l in f.readlines():
l = ' '.join(l.split()) # canonical whitespace
# ignore blank lines
if l:
# heuristic: ignore raw $
if '$' in l and not ("'$'" in l) and not ('"$"' in l):
print("Warning - ignoring", l)
else:
# restore whitespace before continuation char
if l[0] == '/':
l = ' '+l
# keep line if not duplicate
if not l in fixed:
fixed.append(l)
f.close()
o = open("fixed.abnf","w")
for l in fixed:
o.write(l+"\n")
o.close()