module Data.Rewriting.Pos (
Pos,
above,
below,
parallelTo,
leftOf,
rightOf,
) where
import Data.Rewriting.Utils
import Data.List
type Pos = [Int]
above :: Pos -> Pos -> Bool
above :: Pos -> Pos -> Bool
above = Pos -> Pos -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf
below :: Pos -> Pos -> Bool
below :: Pos -> Pos -> Bool
below = (Pos -> Pos -> Bool) -> Pos -> Pos -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Pos -> Pos -> Bool
above
parallelTo :: Pos -> Pos -> Bool
parallelTo :: Pos -> Pos -> Bool
parallelTo Pos
p Pos
q = Bool -> Bool
not (Pos -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Pos
p') Bool -> Bool -> Bool
&& Bool -> Bool
not (Pos -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Pos
q') where
(Pos
p', Pos
q') = Pos -> Pos -> (Pos, Pos)
forall a. Ord a => [a] -> [a] -> ([a], [a])
dropCommonPrefix Pos
p Pos
q
leftOf :: Pos -> Pos -> Bool
leftOf :: Pos -> Pos -> Bool
leftOf Pos
p Pos
q = Bool -> Bool
not (Pos -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Pos
p') Bool -> Bool -> Bool
&& Bool -> Bool
not (Pos -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Pos
q') Bool -> Bool -> Bool
&& Pos -> Int
forall a. HasCallStack => [a] -> a
head Pos
p' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Pos -> Int
forall a. HasCallStack => [a] -> a
head Pos
q' where
(Pos
p', Pos
q') = Pos -> Pos -> (Pos, Pos)
forall a. Ord a => [a] -> [a] -> ([a], [a])
dropCommonPrefix Pos
p Pos
q
rightOf :: Pos -> Pos -> Bool
rightOf :: Pos -> Pos -> Bool
rightOf Pos
p Pos
q = Bool -> Bool
not (Pos -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Pos
p') Bool -> Bool -> Bool
&& Bool -> Bool
not (Pos -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Pos
q') Bool -> Bool -> Bool
&& Pos -> Int
forall a. HasCallStack => [a] -> a
head Pos
p' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Pos -> Int
forall a. HasCallStack => [a] -> a
head Pos
q' where
(Pos
p', Pos
q') = Pos -> Pos -> (Pos, Pos)
forall a. Ord a => [a] -> [a] -> ([a], [a])
dropCommonPrefix Pos
p Pos
q
parallelToRef :: Pos -> Pos -> Bool
parallelToRef :: Pos -> Pos -> Bool
parallelToRef Pos
p Pos
q = Bool -> Bool
not (Pos
p Pos -> Pos -> Bool
`above` Pos
q) Bool -> Bool -> Bool
&& Bool -> Bool
not (Pos
p Pos -> Pos -> Bool
`below` Pos
q)