-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf4ppc.py
46 lines (40 loc) · 1.2 KB
/
f4ppc.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
from f4error import error
__author__ = 'hyst329'
used_modules = set()
ppc_path = ['library']
def preprocess(raw):
global used_modules
lines = raw.split('\n')
i = 0
try:
while 1:
l = lines[i]
p = l.find('#')
if p >= 0:
l = l[0:p]
if len(l) and l[0] == '@':
d = l[1:]
d = d.split(' ')
if d[0] == 'use':
mod = d[1]
if mod not in used_modules:
used_modules.add(mod)
for p in ppc_path:
path = p + "/" + mod.replace('.', '/') + '.f4'
if os.path.exists(path):
break
cont = open(path, 'r').read()
l = preprocess(cont)
else:
error('INVDIR', d[0])
l = ''
if isinstance(l, list):
lines[i:i + 1] = l
elif isinstance(l, str):
lines[i] = l
i += 1
except IndexError:
return lines
def to_string(lines):
return '\n'.join(lines)