-
Notifications
You must be signed in to change notification settings - Fork 4
/
importer.py
31 lines (25 loc) · 1.03 KB
/
importer.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
30
31
from box.parser import Parser
from box.generator import Generator
import os
class Importer:
def __init__(self, path):
# Path to directory containing function graphs to import
self.path = os.path.abspath(path)
# { "FunctionName": <Generator>, ... }
self.function_declarations = {}
# List of (Parser, Generator) objects,
# one for each function graph .box file
self.parser_generators = self._parse_box_files()
print(self.function_declarations)
def _parse_box_files(self):
# Result is a list of tuples [(parser, generator), ...]
result = []
for file in os.listdir(self.path):
if file.endswith(".box"):
path = os.path.join(self.path, file)
parser = Parser(path)
generator = Generator(parser)
code = generator.to_python([])
result.append((parser, generator))
self.function_declarations[generator.function_name] = generator
return result