Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Line
- data Column
- data Loc
- data Span
- data SpanOrLoc
- data Area
- loc :: Line -> Column -> Loc
- origin :: Loc
- spanFromTo :: Loc -> Loc -> Span
- spanFromToMay :: Loc -> Loc -> Maybe Span
- spanOrLocFromTo :: Loc -> Loc -> SpanOrLoc
- areaFromTo :: Loc -> Loc -> Area
- spanArea :: Span -> Area
- locLine :: Loc -> Line
- locColumn :: Loc -> Column
- spanStart :: Span -> Loc
- spanEnd :: Span -> Loc
- spanOrLocStart :: SpanOrLoc -> Loc
- spanOrLocEnd :: SpanOrLoc -> 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
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 # | |
Enum Line Source # | |
Num Line Source # | |
Read Line Source # | |
Real Line Source # | |
Defined in Data.Loc.Pos toRational :: Line -> Rational # | |
Show Line Source # | |
Eq Line Source # | |
Ord Line Source # | |
ToNat Line Source # | |
Instances
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 # | |
Enum Column Source # | |
Defined in Data.Loc.Pos | |
Num Column Source # | |
Read Column Source # | |
Real Column Source # | |
Defined in Data.Loc.Pos toRational :: Column -> Rational # | |
Show Column Source # | |
Eq Column Source # | |
Ord 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
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 # | |
Read Loc Source # | |
Show Loc Source # | |
Eq Loc Source # | |
Ord 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
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 # | |
Read Span Source # | |
Show Span Source # | |
Eq Span Source # | |
Ord Span Source # | |
A SpanOrLoc
consists of a start location and an end location.
The end location must be greater than or equal to the start location;
in other words, backwards spans are not permitted.
If the start and end location are the same, then the value is a SpanOrLoc
.
If they differ, then the value is a SpanOrLoc
.
Instances
Data SpanOrLoc Source # | |
Defined in Data.Loc.SpanOrLoc gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SpanOrLoc -> c SpanOrLoc # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SpanOrLoc # toConstr :: SpanOrLoc -> Constr # dataTypeOf :: SpanOrLoc -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SpanOrLoc) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SpanOrLoc) # gmapT :: (forall b. Data b => b -> b) -> SpanOrLoc -> SpanOrLoc # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SpanOrLoc -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SpanOrLoc -> r # gmapQ :: (forall d. Data d => d -> u) -> SpanOrLoc -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SpanOrLoc -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SpanOrLoc -> m SpanOrLoc # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SpanOrLoc -> m SpanOrLoc # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SpanOrLoc -> m SpanOrLoc # | |
Show SpanOrLoc Source # | |
Eq SpanOrLoc Source # | |
Ord SpanOrLoc Source # | |
Defined in Data.Loc.SpanOrLoc |
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
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 # | |
Monoid Area Source # | |
Semigroup Area Source # | |
Read Area Source # | |
Show Area Source # | |
Eq Area Source # | |
Ord 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
.
SpanOrLoc
Area
Deconstructing
Loc
Span
SpanOrLoc
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
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 # | |
Enum Pos Source # |
|
Num Pos Source # |
|
Read Pos Source # | |
Real Pos Source # | |
Defined in Data.Loc.Pos toRational :: Pos -> Rational # | |
Show Pos Source # | |
Eq Pos Source # | |
Ord Pos Source # | |
ToNat Pos Source # | |
List of length 1 or 2.
Instances
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 # | |
Functor OneToTwo Source # | |
Read a => Read (OneToTwo a) Source # | |
Show a => Show (OneToTwo a) Source # | |
Eq a => Eq (OneToTwo a) Source # | |
Ord a => Ord (OneToTwo a) Source # | |
List of length 0, 1, or 2.
Instances
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 # | |
Functor ZeroToTwo Source # | |
Read a => Read (ZeroToTwo a) Source # | |
Show a => Show (ZeroToTwo a) Source # | |
Eq a => Eq (ZeroToTwo a) Source # | |
Ord a => Ord (ZeroToTwo a) Source # | |
Defined in Data.Loc.List.ZeroToTwo |
data LocException Source #
Instances
Exception LocException Source # | |
Defined in Data.Loc.Exception | |
Show LocException Source # | |
Defined in Data.Loc.Exception showsPrec :: Int -> LocException -> ShowS # show :: LocException -> String # showList :: [LocException] -> ShowS # | |
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 # |