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
31 (* ext: retrieve positional information from marked value*)
32 val ext : 'a marked -> ext option
38 * returns SOME of positional information unit that contains each one in the list
39 * NONE if such wrap is not possible (spans several files, etc.)
41 val wrap : ext option list -> ext option
43 (* map: make your function keep positional information *)
44 val map : ('a -> 'b) -> 'a marked -> 'b marked
45 (* map': similar to map, but f can now use positional information
46 * and preserve it at the same time
48 val map' : ('a marked -> 'b) -> 'a marked -> 'b marked
51 structure Mark :> MARK =
53 type ext = (int * int) * (int * int) * string
55 fun pos (row, 0) = Int.toString row
56 | pos (row, col) = Int.toString row ^ "." ^ Int.toString col
58 fun show (l, r, file) = file ^ ":" ^ pos l ^ "-" ^ pos r
60 type 'a marked = 'a * ext option
62 fun mark (d, e) = (d, SOME e)
63 fun mark' (d, e) = (d, e)
64 fun naked d = (d, NONE)
69 fun extmin ((l1, c1), (l2, c2)) =
70 if l1 < l2 then (l1, c1)
72 if l1 > l2 then (l2, c2)
73 else (l1, Int.min (c1, c2))
74 fun extmax ((l1, c1), (l2, c2)) =
75 if l1 > l2 then (l1, c1)
77 if l1 > l2 then (l2, c2)
78 else (l1, Int.min (c1, c2))
85 | SOME (el1, el2, elf) =>
88 if String.compare (ef, elf) = EQUAL then
89 SOME (extmin (e1, el1), extmax (e2, el2), ef)
91 | NONE => SOME (el1, el2, elf)))
94 fun map f (d, e) = (f d, e)
95 fun map' f (m as (d, e)) = (f m, e)