Mercurial > feed
comparison src/ur/feed.ur @ 14:f641cfcd5153
Add gather pattern.
author | Karn Kallio <kkallio@eka> |
---|---|
date | Mon, 25 Jul 2011 20:55:09 -0430 |
parents | 7eea7ff1904c |
children | 7275f59cab61 |
comparison
equal
deleted
inserted
replaced
13:7eea7ff1904c | 14:f641cfcd5153 |
---|---|
239 None => None | 239 None => None |
240 | Some cstate => | 240 | Some cstate => |
241 case child.Finished cstate of | 241 case child.Finished cstate of |
242 None => None | 242 None => None |
243 | Some (cdata, _) => Some ((pdata, cdata), True)} | 243 | Some (cdata, _) => Some ((pdata, cdata), True)} |
244 | |
245 con gatherInternal (parent :: Type) (child :: Type) (data :: Type) = option (parent * bool * int * option child * list data) | |
246 | |
247 fun gather [parentI ::: Type] [parent ::: Type] [childI ::: Type] [child ::: Type] | |
248 (parent : pattern parentI parent) (child : pattern childI child) | |
249 : pattern (gatherInternal parentI childI child) (parent * list child) = | |
250 {Initial = None, | |
251 EnterTag = fn tinfo state => | |
252 case state of | |
253 None => | |
254 (case parent.EnterTag tinfo parent.Initial of | |
255 None => None | |
256 | Some pstate => Some (Some (pstate, False, 1, None, Nil))) | |
257 | Some (pstate, return, depth, cstate, clist) => | |
258 let | |
259 val cstate' = child.EnterTag tinfo (Option.get child.Initial cstate) | |
260 in | |
261 case child.Finished (Option.get child.Initial cstate') of | |
262 None => | |
263 Some (Some (pstate, return, depth+1, cstate', clist)) | |
264 | Some (cdata, _) => | |
265 Some (Some (pstate, return, depth+1, None, cdata :: clist)) | |
266 end, | |
267 ExitTag = fn state => | |
268 case state of | |
269 None => None | |
270 | Some (pstate, _, 1, cstate, clist) => | |
271 Some (Some (pstate, True, 1, cstate, clist)) | |
272 | Some (pstate, return, depth, cstate, clist) => | |
273 let | |
274 val cstate' = child.ExitTag (Option.get child.Initial cstate) | |
275 in | |
276 case child.Finished (Option.get child.Initial cstate') of | |
277 None => | |
278 Some (Some (pstate, return, depth-1, cstate', clist)) | |
279 | Some (cdata, _) => | |
280 Some (Some (pstate, return, depth-1, None, cdata :: clist)) | |
281 end, | |
282 Finished = fn state => | |
283 case state of | |
284 None => None | |
285 | Some (pstate, return, _, _, clist) => | |
286 case parent.Finished pstate of | |
287 None => None | |
288 | Some (pdata, _) => | |
289 if return then | |
290 Some ((pdata, List.rev clist), False) | |
291 else | |
292 None} | |
244 | 293 |
245 type document = string | 294 type document = string |
246 val show_document = _ | 295 val show_document = _ |
247 | 296 |
248 val fetch = FeedFfi.fetch | 297 val fetch = FeedFfi.fetch |