blob: 15ee7a498f38c96ba864b79d85854b2b704c37a6 (
plain)
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
|
""" yaml parser """
__license__ = 'GPL-3.0-only'
import yaml
from .types import Variable, Function, Struct
from .header import Header
def read(path: str, hdr: Header):
with open(path, mode='r', encoding='utf-8') as stream:
data = yaml.safe_load(stream)
for item, info in data['variables'].items():
hdr.variables.append(Variable(item, data=info))
for item, info in data['functions'].items():
hdr.functions.append(Function(item, data=info))
for struct in data['structs']:
name = struct.pop('name')
members = []
for item, info in struct.items():
match info['type']:
case 'fn_ptr':
members.append(Function(item, data=info))
case _:
members.append(Variable(item, data=info))
hdr.structs.append(Struct(name, members))
|