comparison src/source_print.sml @ 170:a158f8c5aa55

Parsing basic patterns
author Adam Chlipala <adamc@hcoop.net>
date Tue, 29 Jul 2008 16:38:15 -0400
parents 34ccd7d2bea8
children c7a6e6dbc318
comparison
equal deleted inserted replaced
169:2232ab355f66 170:a158f8c5aa55
160 and p_name (all as (c, _)) = 160 and p_name (all as (c, _)) =
161 case c of 161 case c of
162 CName s => string s 162 CName s => string s
163 | _ => p_con all 163 | _ => p_con all
164 164
165 fun p_pat' par (p, _) =
166 case p of
167 PWild => string "_"
168 | PVar s => string s
169 | PCon (ms, x, NONE) => p_list_sep (string ".") string (ms @ [x])
170 | PCon (ms, x, SOME p) => parenIf par (box [p_list_sep (string ".") string (ms @ [x]),
171 space,
172 p_pat' true p])
173
174 val p_pat = p_pat' false
175
165 fun p_exp' par (e, _) = 176 fun p_exp' par (e, _) =
166 case e of 177 case e of
167 EAnnot (e, t) => box [string "(", 178 EAnnot (e, t) => box [string "(",
168 p_exp e, 179 p_exp e,
169 space, 180 space,
237 string "--", 248 string "--",
238 space, 249 space,
239 p_con' true c]) 250 p_con' true c])
240 | EFold => string "fold" 251 | EFold => string "fold"
241 252
253 | ECase (e, pes) => parenIf par (box [string "case",
254 space,
255 p_exp' false e,
256 space,
257 string "of",
258 space,
259 p_list_sep (box [space, string "|", space])
260 (fn (p, e) => box [p_pat p,
261 space,
262 string "=>",
263 space,
264 p_exp e]) pes])
265
242 and p_exp e = p_exp' false e 266 and p_exp e = p_exp' false e
243 267
244 fun p_datatype (x, cons) = 268 fun p_datatype (x, cons) =
245 box [string "datatype", 269 box [string "datatype",
246 space, 270 space,