forked from Okimdone/DSL-Lion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lion.py
executable file
·54 lines (46 loc) · 1.44 KB
/
lion.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
47
48
49
50
51
52
#!ENV/bin/python
import readline
import textx as tx
import templateEngine as te
from textx.model import get_children
def save_code(pycode):
with open("pycode.py","w+") as pyfile:
pyfile.write(pycode)
try :
readline.read_history_file('.lion_history')
except FileNotFoundError:
open('.lion_history', 'w').close()
readline.set_history_length(1000)
mm = tx.metamodel_from_file('LION_META_MODEL.tx')
AllofCode = []
pycode = te.genDependenciesCode()
exec(pycode)
while(True):
temp = AllofCode.copy()
try :
c = input("lion> ")
while(True) :
if ';' in c:
break
c += input("... ")
temp.append(c)
m = mm.model_from_str('\n'.join(temp))
code = te.genCode(m.rules[-1])
exec(code)
pycode += code
AllofCode.append(c)
readline.write_history_file('.lion_history')
except EOFError :
print("\r bye :(")
save_code(pycode)
break
except KeyboardInterrupt:
print("\ntype exit() or EOF to quit!")
except FileNotFoundError as e:
print(f'''The file "{e.args[1].split("'")[1]}" does not exist!''')
except tx.exceptions.TextXSyntaxError as e:
print(f'''SyntaxError: name '{e.message.split("'")[-2]}' is not defined''')
except tx.exceptions.TextXSemanticError as e:
print(f'''SemanticError: '{e.message}' is not defined''')
except Exception as e:
print(e)