-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
30 lines (24 loc) · 819 Bytes
/
utils.py
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
from collections import defaultdict
from os import path
from glob import glob
def split_clauses(program):
in_parenthese = False
in_quote = False
pos = 0
program = program + " "
for i, c in enumerate(program):
if not in_quote and c == "(":
in_parenthese = True
elif in_parenthese and c == ")":
in_parenthese = False
elif not in_quote and c == '`':
in_quote = True
elif in_quote and c == '`':
in_quote = False
if c == "." and not program[i-1].isdigit() and not program[i+1].isdigit():
yield program[pos:i]
pos = i + 1
yield program[pos:]
def find_files(fn):
folder = path.dirname(path.abspath(__file__))
return glob(path.join(folder, "**/{}".format(fn)), recursive=True)