Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Line
- data Column
- data Loc
- data Span
- data Area
- loc :: Line -> Column -> Loc
- origin :: Loc
- spanFromTo :: Loc -> Loc -> Span
- spanFromToMay :: Loc -> Loc -> Maybe Span
- areaFromTo :: Loc -> Loc -> Area
- spanArea :: Span -> Area
- locLine :: Loc -> Line
- locColumn :: Loc -> Column
- spanStart :: Span -> Loc
- spanEnd :: Span -> Loc
- areaStart :: Area -> Maybe Loc
- areaEnd :: Area -> Maybe Loc
- areaSpansAsc :: Area -> [Span]
- spanUnion :: Span -> Span -> OneToTwo Span
- spanDifference :: Span -> Span -> ZeroToTwo Span
- areaUnion :: Area -> Area -> Area
- areaDifference :: Area -> Area -> Area
- data Pos
- data OneToTwo a
- data ZeroToTwo a
- class ToNat a where
- data LocException = EmptySpan
Concepts
Line
and Column
are positive integers representing line and column numbers.
The product of Line
and Column
is a Loc
, which represents a position
between characters in multiline text. The smallest loc is origin
: line 1,
column 1.
Here's a small piece of text for illustration:
1 2 12345678901234567890123456789 ┌───────────────────────────────┐ 1 │ I have my reasons, you │ 2 │ have yours. What's obvious │ 3 │ to me isn't to everyone else, │ 4 │ and vice versa. │ └───────────────────────────────┘
In this example, the word “obvious” starts at line 2, column 20, and it ends at
line 2, column 27. The Show
instance uses a shorthand notation denoting
these locs as 2:20
and 2:27
.
A Span
is a nonempty contiguous region of text between two locs; think of it
like a highlighted area in a simple text editor. In the above example, a span
that covers the word “obvious” starts at 2:20
and ends at 2:27
. The Show
instance describes this tersely as 2:20-2:27
.
Multiple non-overlapping regions form an Area
. You may also think of an
area like a span that can be empty or have “gaps”. In the example above, the
first three words “I have my”, and not the spaces between them, are covered by
the area [1:1-1:2,1:3-1:7,1:8-1:10]
.
Imports
Recommended import:
import Data.Loc.Types import qualified Data.Loc as Loc
Core types
Instances
Enum Line Source # | |
Eq Line Source # | |
Data Line Source # | |
Defined in Data.Loc.Pos gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Line -> c Line # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Line # dataTypeOf :: Line -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Line) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Line) # gmapT :: (forall b. Data b => b -> b) -> Line -> Line # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Line -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Line -> r # gmapQ :: (forall d. Data d => d -> u) -> Line -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Line -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Line -> m Line # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Line -> m Line # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Line -> m Line # | |
Num Line Source # | |
Ord Line Source # | |
Read Line Source # | |
Real Line Source # | |
Defined in Data.Loc.Pos toRational :: Line -> Rational # | |
Show Line Source # | |
ToNat Line Source # | |
Instances
Enum Column Source # | |
Defined in Data.Loc.Pos | |
Eq Column Source # | |
Data Column Source # | |
Defined in Data.Loc.Pos gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Column -> c Column # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Column # toConstr :: Column -> Constr # dataTypeOf :: Column -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Column) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Column) # gmapT :: (forall b. Data b => b -> b) -> Column -> Column # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Column -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Column -> r # gmapQ :: (forall d. Data d => d -> u) -> Column -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Column -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Column -> m Column # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Column -> m Column # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Column -> m Column # | |
Num Column Source # | |
Ord Column Source # | |
Read Column Source # | |
Real Column Source # | |
Defined in Data.Loc.Pos toRational :: Column -> Rational # | |
Show Column Source # | |
ToNat Column Source # | |
Stands for location. Consists of a Line
and a Column
. You can think of a
Loc
like a caret position in a text editor. Following the normal convention
for text editors and such, line and column numbers start with 1.
Instances
Eq Loc Source # | |
Data Loc Source # | |
Defined in Data.Loc.Loc gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Loc -> c Loc # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Loc # dataTypeOf :: Loc -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Loc) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Loc) # gmapT :: (forall b. Data b => b -> b) -> Loc -> Loc # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Loc -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Loc -> r # gmapQ :: (forall d. Data d => d -> u) -> Loc -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Loc -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Loc -> m Loc # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Loc -> m Loc # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Loc -> m Loc # | |
Ord Loc Source # | |
Read Loc Source # | |
Show Loc Source # | |
A Span
consists of a start location (start
) and an end location (end
).
The end location must be greater than the start location; in other words, empty
or backwards spans are not permitted.
Construct and combine spans using fromTo
, fromToMay
, +
, and -
.
Instances
Eq Span Source # | |
Data Span Source # | |
Defined in Data.Loc.Span gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Span -> c Span # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Span # dataTypeOf :: Span -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Span) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Span) # gmapT :: (forall b. Data b => b -> b) -> Span -> Span # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Span -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Span -> r # gmapQ :: (forall d. Data d => d -> u) -> Span -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Span -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Span -> m Span # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Span -> m Span # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Span -> m Span # | |
Ord Span Source # | |
Read Span Source # | |
Show Span Source # | |
A set of non-overlapping, non-abutting Span
s. You may also think of an Area
like a span that can be empty or have “gaps”.
Construct and combine areas using mempty
, spanArea
, fromTo
, +
, and -
.
Instances
Eq Area Source # | |
Data Area Source # | |
Defined in Data.Loc.Area gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Area -> c Area # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Area # dataTypeOf :: Area -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Area) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Area) # gmapT :: (forall b. Data b => b -> b) -> Area -> Area # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Area -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Area -> r # gmapQ :: (forall d. Data d => d -> u) -> Area -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Area -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Area -> m Area # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Area -> m Area # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Area -> m Area # | |
Ord Area Source # | |
Read Area Source # | |
Show Area Source # | |
Semigroup Area Source # | |
Monoid Area Source # | |
Constructing
Loc
Span
spanFromTo :: Loc -> Loc -> Span Source #
Attempt to construct a Span
from two Loc
s. The lesser loc will be the
start, and the greater loc will be the end. The two locs must not be equal,
or else this throws EmptySpan
.
The safe version of this function is spanFromToMay
.
This is an alias for fromTo
.
spanFromToMay :: Loc -> Loc -> Maybe Span Source #
Attempt to construct a Span
from two Loc
s. The lesser loc will be the
start, and the greater loc will be the end. If the two locs are equal,
the result is Nothing
, because a span cannot be empty.
This is the safe version of spanFromTo
, which throws an exception instead.
This is an alias for fromToMay
.
Area
Deconstructing
Loc
Span
Area
areaSpansAsc :: Area -> [Span] Source #
Combining
Span
spanDifference :: Span -> Span -> ZeroToTwo Span Source #
The difference between two Spans
s. a
contains what is covered by
-
ba
and not covered by b
.
This is an alias for -
.
Area
areaDifference :: Area -> Area -> Area Source #
The difference between two Area
s. a `
contains what is
covered by areaDifference
` ba
and not covered by b
.
This is an alias for -
.
Miscellaneous
Pos
stands for positive integer. You can also think of it as position,
because we use it to represent line and column numbers (Line
and Column
).
Pos
has instances of several of the standard numeric typeclasses, although
many of the operations throw Underflow
when non-positive values result.
Pos
does not have an Integral
instance, because there is no sensible
way to implement quotRem
.
Instances
Enum Pos Source # |
|
Eq Pos Source # | |
Data Pos Source # | |
Defined in Data.Loc.Pos gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Pos -> c Pos # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Pos # dataTypeOf :: Pos -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Pos) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pos) # gmapT :: (forall b. Data b => b -> b) -> Pos -> Pos # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pos -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pos -> r # gmapQ :: (forall d. Data d => d -> u) -> Pos -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Pos -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Pos -> m Pos # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Pos -> m Pos # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Pos -> m Pos # | |
Num Pos Source # |
|
Ord Pos Source # | |
Read Pos Source # | |
Real Pos Source # | |
Defined in Data.Loc.Pos toRational :: Pos -> Rational # | |
Show Pos Source # | |
ToNat Pos Source # | |
List of length 1 or 2.
Instances
Functor OneToTwo Source # | |
Foldable OneToTwo Source # | |
Defined in Data.Loc.List.OneToTwo fold :: Monoid m => OneToTwo m -> m # foldMap :: Monoid m => (a -> m) -> OneToTwo a -> m # foldMap' :: Monoid m => (a -> m) -> OneToTwo a -> m # foldr :: (a -> b -> b) -> b -> OneToTwo a -> b # foldr' :: (a -> b -> b) -> b -> OneToTwo a -> b # foldl :: (b -> a -> b) -> b -> OneToTwo a -> b # foldl' :: (b -> a -> b) -> b -> OneToTwo a -> b # foldr1 :: (a -> a -> a) -> OneToTwo a -> a # foldl1 :: (a -> a -> a) -> OneToTwo a -> a # elem :: Eq a => a -> OneToTwo a -> Bool # maximum :: Ord a => OneToTwo a -> a # minimum :: Ord a => OneToTwo a -> a # | |
Eq a => Eq (OneToTwo a) Source # | |
Ord a => Ord (OneToTwo a) Source # | |
Read a => Read (OneToTwo a) Source # | |
Show a => Show (OneToTwo a) Source # | |
List of length 0, 1, or 2.
Instances
Functor ZeroToTwo Source # | |
Foldable ZeroToTwo Source # | |
Defined in Data.Loc.List.ZeroToTwo fold :: Monoid m => ZeroToTwo m -> m # foldMap :: Monoid m => (a -> m) -> ZeroToTwo a -> m # foldMap' :: Monoid m => (a -> m) -> ZeroToTwo a -> m # foldr :: (a -> b -> b) -> b -> ZeroToTwo a -> b # foldr' :: (a -> b -> b) -> b -> ZeroToTwo a -> b # foldl :: (b -> a -> b) -> b -> ZeroToTwo a -> b # foldl' :: (b -> a -> b) -> b -> ZeroToTwo a -> b # foldr1 :: (a -> a -> a) -> ZeroToTwo a -> a # foldl1 :: (a -> a -> a) -> ZeroToTwo a -> a # toList :: ZeroToTwo a -> [a] # length :: ZeroToTwo a -> Int # elem :: Eq a => a -> ZeroToTwo a -> Bool # maximum :: Ord a => ZeroToTwo a -> a # minimum :: Ord a => ZeroToTwo a -> a # | |
Eq a => Eq (ZeroToTwo a) Source # | |
Ord a => Ord (ZeroToTwo a) Source # | |
Defined in Data.Loc.List.ZeroToTwo | |
Read a => Read (ZeroToTwo a) Source # | |
Show a => Show (ZeroToTwo a) Source # | |
data LocException Source #
Instances
Eq LocException Source # | |
Defined in Data.Loc.Exception (==) :: LocException -> LocException -> Bool # (/=) :: LocException -> LocException -> Bool # | |
Ord LocException Source # | |
Defined in Data.Loc.Exception compare :: LocException -> LocException -> Ordering # (<) :: LocException -> LocException -> Bool # (<=) :: LocException -> LocException -> Bool # (>) :: LocException -> LocException -> Bool # (>=) :: LocException -> LocException -> Bool # max :: LocException -> LocException -> LocException # min :: LocException -> LocException -> LocException # | |
Show LocException Source # | |
Defined in Data.Loc.Exception showsPrec :: Int -> LocException -> ShowS # show :: LocException -> String # showList :: [LocException] -> ShowS # | |
Exception LocException Source # | |
Defined in Data.Loc.Exception |