forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cwrap_parser.py
27 lines (24 loc) · 854 Bytes
/
cwrap_parser.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
import yaml
try:
# use faster C loader if available
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
# follows similar logic to cwrap, ignores !inc, and just looks for [[]]
def parse(filename):
with open(filename, 'r') as file:
declaration_lines = []
declarations = []
in_declaration = False
for line in file.readlines():
line = line.rstrip()
if line == '[[':
declaration_lines = []
in_declaration = True
elif line == ']]':
in_declaration = False
declaration = yaml.load('\n'.join(declaration_lines), Loader=Loader)
declarations.append(declaration)
elif in_declaration:
declaration_lines.append(line)
return declarations