-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathactionmap.sml
42 lines (36 loc) · 1.24 KB
/
actionmap.sml
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
(* $Id$
*
* Copyright (c) 2008 Timothy Bourke (University of NSW and NICTA)
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the "BSD License" which is distributed with the
* software in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the BSD
* License for more details.
*)
structure ActionMap : sig
include ORD_MAP
val actionInsert : ((Atom.atom * 'a) * 'a map) -> 'a map
end
=
let structure E = Expression
in struct
open ActionRedBlackMap
fun actionInsert ((chandir, v), m) = let
fun getTail (l, r) = (Atom.atom (Substring.string l), Substring.first r)
val s = Substring.full (Atom.toString chandir)
val l = Substring.size s
val (n, d) = if l = 0 then (chandir, NONE)
else getTail (Substring.splitAt (s, l-1))
in
case d of
SOME #"?" => insert' (((n, E.Input), v), m)
| SOME #"!" => insert' (((n, E.Output), v), m)
| _ => let val m' = insert' (((n, E.Input), v), m)
in insert' (((n, E.Output), v), m') end
end
end end