-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasture_orthography.py
74 lines (58 loc) · 1.93 KB
/
pasture_orthography.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
line_delimiter = ";"
line_escape = "/"
assignment = "=>"
application = " "
delayed_application = ","
argument = "$"
prior = "%"
comment_single = "#"
comment_begin = "#-"
comment_end = "-#"
brace_delimiter = "|"
brace_key = "'"
def verbose_string(exp, internal = False):
if exp is None: return "None"
if exp == []: return ""
if exp[0] == "assignment":
assert len(exp) == 3
return string(exp[1])+" "+assignment+" "+string(exp[2])
if exp[0] == "application":
assert len(exp) == 3
return "("+string(exp[1])+application+string(exp[2])+")"
if exp[0] == "argument":
if len(exp) == 2: return argument+string(exp[1])
elif len(exp) == 1: return eval(exp[0])
else: raise
assert len(exp) == 1
return exp[0]
# internal specifies whether this call is internal to the method
# (and thus whether to return contextual information )
# caution specifies whether
def string(exp, internal = False, first_arg = True):
#print(exp)
re = ""
if exp is None: re = "None"
elif exp == []: re = ""
elif exp[0] == "assignment":
assert len(exp) == 3, "Syntax Error: assignment operator needs two arguments"
re = string(exp[1], True)+" "+assignment+" "+string(exp[2], True)
elif exp[0] == "application":
assert len(exp) == 3, "Syntax Error: application operator needs two arguments"
re = None
if type(exp[1]) is list and exp[1][0] == "application" and not first_arg:
# if you add parens, you can pretend you are the first arg again
re = "("+string(exp[1], True, True)+")"
else: re = string(exp[1], True, first_arg)
if type(exp[2]) is list and exp[2][0] == "application":
re += delayed_application
else: re += application
return re + string(exp[2], True, False)
elif exp[0] == "argument":
if len(exp) == 2: re = argument+string(exp[1], True)
elif len(exp) == 1: re = eval(exp[0])
else: raise
else:
assert len(exp) == 1
re = exp[0]
if internal: return re#, {"applicative": False})
return re