3 * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
4 * Annotations / bugfixes: Alex Vaynberg <alv@andrew.cmu.edu>
9 type ext = (int * int) * (int * int) * string (* position *)
11 val show : ext -> string (* converts the data into human readable form *)
13 type 'a marked (* value with positional information *)
15 (* INTRODUCTION FUNCTIONS for type 'a marked *)
17 (* put together a value and positional information *)
18 val mark : 'a * ext -> 'a marked
20 (* put together a value and an option of positional information *)
21 val mark' : 'a * ext option -> 'a marked
23 (* mark the value with no positional information *)
24 val naked : 'a -> 'a marked
26 (* ELIMINATION FUNCTIONS for type a' marked *)
28 (* data: remove the markings *)
29 val data : 'a marked -> 'a
30 val kane : 'a marked -> 'a
32 (* ext: retrieve positional information from marked value*)
33 val ext : 'a marked -> ext option
39 * returns SOME of positional information unit that contains each one in the list
40 * NONE if such wrap is not possible (spans several files, etc.)
42 val wrap : ext option list -> ext option
44 (* map: make your function keep positional information *)
45 val map : ('a -> 'b) -> 'a marked -> 'b marked
46 (* map': similar to map, but f can now use positional information
47 * and preserve it at the same time
49 val map' : ('a marked -> 'b) -> 'a marked -> 'b marked
52 structure Mark :> MARK =
54 type ext = (int * int) * (int * int) * string
56 fun pos (row, 0) = Int.toString row
57 | pos (row, col) = Int.toString row ^ "." ^ Int.toString col
59 fun show (l, r, file) = file ^ ":" ^ pos l ^ "-" ^ pos r
61 type 'a marked = 'a * ext option
63 fun mark (d, e) = (d, SOME e)
64 fun mark' (d, e) = (d, e)
65 fun naked d = (d, NONE)
71 fun extmin ((l1, c1), (l2, c2)) =
72 if l1 < l2 then (l1, c1)
74 if l1 > l2 then (l2, c2)
75 else (l1, Int.min (c1, c2))
76 fun extmax ((l1, c1), (l2, c2)) =
77 if l1 > l2 then (l1, c1)
79 if l1 > l2 then (l2, c2)
80 else (l1, Int.min (c1, c2))
87 | SOME (el1, el2, elf) =>
90 if String.compare (ef, elf) = EQUAL then
91 SOME (extmin (e1, el1), extmax (e2, el2), ef)
93 | NONE => SOME (el1, el2, elf)))
96 fun map f (d, e) = (f d, e)
97 fun map' f (m as (d, e)) = (f m, e)