0 | module Libraries.Text.Bounded
19 | showPrec d (MkBounds sl sc el ec) =
20 | showCon d "MkBounds" (concat [showArg sl, showArg sc, showArg el, showArg ec])
23 | startBounds : Bounds -> (Int, Int)
24 | startBounds b = (b.startLine, b.startCol)
27 | endBounds : Bounds -> (Int, Int)
28 | endBounds b = (b.endLine, b.endCol)
31 | union : Bounds -> Bounds -> Bounds
33 | let (ur, uc) = min (startBounds b1) (startBounds b2)
34 | (lr, lc) = max (endBounds b1) (endBounds b2)
35 | in MkBounds ur uc lr lc
39 | (MkBounds sl sc el ec) == (MkBounds sl' sc' el' ec') =
46 | record WithBounds ty where
47 | constructor MkBounded
53 | start : WithBounds ty -> (Int, Int)
54 | start = startBounds . bounds
57 | end : WithBounds ty -> (Int, Int)
58 | end = endBounds . bounds
61 | Eq ty => Eq (WithBounds ty) where
62 | (MkBounded val ir bd) == (MkBounded val' ir' bd') =
63 | val == val' && ir == ir' && bd == bd'
66 | Show ty => Show (WithBounds ty) where
67 | showPrec d (MkBounded val ir bd) =
68 | showCon d "MkBounded" (concat [showArg ir, showArg val, showArg bd])
71 | Functor WithBounds where
72 | map f (MkBounded val ir bd) = MkBounded (f val) ir bd
75 | Foldable WithBounds where
76 | foldr c n b = c b.val n
79 | Traversable WithBounds where
80 | traverse f (MkBounded v a bd) = (\ v => MkBounded v a bd) <$> f v
83 | irrelevantBounds : ty -> WithBounds ty
84 | irrelevantBounds x = MkBounded x True (MkBounds (-
1) (-
1) (-
1) (-
1))
87 | removeIrrelevance : WithBounds ty -> WithBounds ty
88 | removeIrrelevance (MkBounded val ir bd) = MkBounded val True bd
91 | mergeBounds : WithBounds ty -> WithBounds ty' -> WithBounds ty'
92 | mergeBounds (MkBounded _ True _) (MkBounded val True _) = irrelevantBounds val
93 | mergeBounds (MkBounded _ True _) b2 = b2
94 | mergeBounds b1 (MkBounded val True _) = const val <$> b1
96 | MkBounded b2.val False (union (bounds b1) (bounds b2))
99 | joinBounds : WithBounds (WithBounds ty) -> WithBounds ty
100 | joinBounds b = mergeBounds b b.val