Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
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 Positive
- data OneToTwo a
- data ZeroToTwo a
- 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
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.
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 -
.
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
.
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 -
.
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
Instances
Enum Positive | |
Num Positive | |
Read Positive | |
Integral Positive | |
Defined in Integer.Positive.Unsafe | |
Real Positive | |
Defined in Integer.Positive.Unsafe toRational :: Positive -> Rational # | |
Show Positive | |
NFData Positive | |
Defined in Integer.Positive.Unsafe | |
Eq Positive | |
Ord Positive | |
Defined in Integer.Positive.Unsafe | |
Hashable Positive | |
Defined in Integer.Positive.Unsafe | |
BoundedBelow Positive | |
Defined in Integer.Positive.Unsafe |
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 # |