/
plang.py
47 lines (39 loc) · 1.14 KB
/
plang.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
import os
import sys
import rply.parser
import edn
import pground
from ptypes import *
def readinput():
result = []
while True:
s = os.read(0, 1)
result.append(s)
if s == '':
if len(result) > 1:
break
raise SystemExit
return "".join(result)
def entry_point(argv):
input_data = readinput()
env = Env(pground.GROUND)
try:
input_parsed = edn.loads("(do %s)" % input_data)
print Cc(input_parsed, identity, env, None).run().to_str()
# catching two exceptions here makes pypy fail with a weird error
except rply.parser.ParsingError as error:
pos = error.getsourcepos()
print "Error reading code at line: %d column: %d" % (pos.lineno, pos.colno)
return -1
except rply.errors.LexingError as error:
pos = error.getsourcepos()
print "Error reading code at line: %d column: %d" % (pos.lineno, pos.colno)
return -1
except PError as error:
print error.to_str()
return -1
return 0
def target(*args):
return entry_point, None
if __name__ == "__main__":
entry_point(sys.argv)