comparison src/source_print.sml @ 8:a455a9f85cc3

Parsing basic expressions
author Adam Chlipala <adamc@hcoop.net>
date Sat, 26 Jan 2008 17:10:26 -0500
parents 5c3cc348e9e6
children d89477f07c1e
comparison
equal deleted inserted replaced
7:2ce5bf227d01 8:a455a9f85cc3
89 89
90 | CVar s => string s 90 | CVar s => string s
91 | CApp (c1, c2) => parenIf par (box [p_con c1, 91 | CApp (c1, c2) => parenIf par (box [p_con c1,
92 space, 92 space,
93 p_con' true c2]) 93 p_con' true c2])
94 | CAbs (e, x, k, c) => parenIf par (box [string "fn", 94 | CAbs (x, k, c) => parenIf par (box [string "fn",
95 space, 95 space,
96 string x, 96 string x,
97 space, 97 space,
98 p_explicitness e, 98 string "::",
99 space, 99 space,
100 p_kind k, 100 p_kind k,
101 space, 101 space,
102 string "=>", 102 string "=>",
103 space, 103 space,
104 p_con c]) 104 p_con c])
105 105
106 | CName s => box [string "#", string s] 106 | CName s => box [string "#", string s]
107 107
108 | CRecord xcs => box [string "[", 108 | CRecord xcs => box [string "[",
109 p_list (fn (x, c) => 109 p_list (fn (x, c) =>
119 space, 119 space,
120 p_con c2]) 120 p_con c2])
121 121
122 and p_con c = p_con' false c 122 and p_con c = p_con' false c
123 123
124 fun p_exp' par (e, _) =
125 case e of
126 EAnnot (e, t) => box [string "(",
127 p_exp e,
128 space,
129 string ":",
130 space,
131 p_con t,
132 string ")"]
133
134 | EVar s => string s
135 | EApp (e1, e2) => parenIf par (box [p_exp e1,
136 space,
137 p_exp' true e2])
138 | EAbs (x, NONE, e) => parenIf par (box [string "fn",
139 space,
140 string x,
141 space,
142 string "=>",
143 space,
144 p_exp e])
145 | EAbs (x, SOME t, e) => parenIf par (box [string "fn",
146 space,
147 string x,
148 space,
149 string ":",
150 space,
151 p_con t,
152 space,
153 string "=>",
154 space,
155 p_exp e])
156 | ECApp (e, c) => parenIf par (box [p_exp e,
157 space,
158 string "[",
159 p_con c,
160 string "]"])
161 | ECAbs (exp, x, k, e) => parenIf par (box [string "fn",
162 space,
163 string x,
164 space,
165 p_explicitness exp,
166 space,
167 p_kind k,
168 space,
169 string "=>",
170 space,
171 p_exp e])
172
173 and p_exp e = p_exp' false e
174
124 fun p_decl ((d, _) : decl) = 175 fun p_decl ((d, _) : decl) =
125 case d of 176 case d of
126 DCon (x, NONE, c) => box [string "con", 177 DCon (x, NONE, c) => box [string "con",
127 space, 178 space,
128 string x, 179 string x,
139 p_kind k, 190 p_kind k,
140 space, 191 space,
141 string "=", 192 string "=",
142 space, 193 space,
143 p_con c] 194 p_con c]
195 | DVal (x, NONE, e) => box [string "val",
196 space,
197 string x,
198 space,
199 string "=",
200 space,
201 p_exp e]
202 | DVal (x, SOME t, e) => box [string "val",
203 space,
204 string x,
205 space,
206 string ":",
207 space,
208 p_con t,
209 space,
210 string "=",
211 space,
212 p_exp e]
144 213
145 val p_file = p_list_sep newline p_decl 214 val p_file = p_list_sep newline p_decl
146 215
147 end 216 end