-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
52 lines (46 loc) · 1.8 KB
/
Copy pathutils.py
File metadata and controls
52 lines (46 loc) · 1.8 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import re
class EchiumTree:
def __init__(self, data):
self.raw_data = data
self.root = ''
self.variables = {'':1}
self.contents = {}
self.commands = {}
self.output = ''
def parse(self):
''' populates contents and variables '''
# first let's find variables
variables = re.findall(r'var +(\w+) += +(\d+) *;',self.raw_data)
for var in variables:
self.variables[var[0]] = int(var[1])
contents = re.findall(r"content +(\w+) += +'(.+)'",self.raw_data)
for cont in contents:
file_id = cont[0]
file_name = cont[1]
file_handle = open('src/'+file_name)
self.contents[file_id]=file_handle.read()
render_box = re.compile(r"render +{(.*)}",
flags=re.DOTALL).search(self.raw_data)[1]
self.root = render_box
raw_commands = re.findall(r"(@\w+\*(\w*);)",render_box)
actual_commands = {}
for com in raw_commands:
content_name = com[0]
content_repeat_variable = com[1]
repeat = self.variables[content_repeat_variable]
actual_commands[content_name] = repeat
self.commands = actual_commands
return True
def render(self):
''' compiles the output string '''
ready_content = {}
for com_id,com_rep in self.commands.items():
content_id = re.search(r"@(\w+)*\w*",com_id)[1]
content_content = self.contents[content_id]
repeat = com_rep
ready_content[com_id] = content_content*repeat
# beginning compilation
self.output = self.root
for token,content in ready_content.items():
self.output = self.output.replace(token,content)
return self.output