-- | A Safe Haskell-trusted re-export of the @srcloc@ package.
module Futhark.Util.Loc (module Data.Loc, contains) where

import Data.Loc

-- | Does the location of the given thing contain the given position?
-- The end of a 'Loc' is exclusive: it is the position just after the
-- last character.
contains :: (Located a) => a -> Pos -> Bool
contains :: forall a. Located a => a -> Pos -> Bool
contains a
a Pos
pos =
  case a -> Loc
forall a. Located a => a -> Loc
locOf a
a of
    Loc Pos
start Pos
end -> Pos
pos Pos -> Pos -> Bool
forall a. Ord a => a -> a -> Bool
>= Pos
start Bool -> Bool -> Bool
&& Pos
pos Pos -> Pos -> Bool
forall a. Ord a => a -> a -> Bool
< Pos
end
    Loc
NoLoc -> Bool
False