loc-0.2.0.0: Line and column positions and ranges in text files
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Loc.Area

Synopsis

Documentation

data Area Source #

A set of non-overlapping, non-abutting Spans

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

Instances details
Monoid Area Source # 
Instance details

Defined in Data.Loc.Area

Methods

mempty :: Area #

mappend :: Area -> Area -> Area #

mconcat :: [Area] -> Area #

Semigroup Area Source #

<> = +

Instance details

Defined in Data.Loc.Area

Methods

(<>) :: Area -> Area -> Area #

sconcat :: NonEmpty Area -> Area #

stimes :: Integral b => b -> Area -> Area #

Read Area Source #

readPrec = areaReadPrec

Instance details

Defined in Data.Loc.Area

Show Area Source #

showsPrec = areaShowsPrec

Instance details

Defined in Data.Loc.Area

Methods

showsPrec :: Int -> Area -> ShowS #

show :: Area -> String #

showList :: [Area] -> ShowS #

Eq Area Source # 
Instance details

Defined in Data.Loc.Area

Methods

(==) :: Area -> Area -> Bool #

(/=) :: Area -> Area -> Bool #

Ord Area Source # 
Instance details

Defined in Data.Loc.Area

Methods

compare :: Area -> Area -> Ordering #

(<) :: Area -> Area -> Bool #

(<=) :: Area -> Area -> Bool #

(>) :: Area -> Area -> Bool #

(>=) :: Area -> Area -> Bool #

max :: Area -> Area -> Area #

min :: Area -> Area -> Area #

Constructing

fromTo Source #

Arguments

:: Loc

Start

-> Loc

End

-> Area 

Construct a contiguous Area consisting of a single Span specified by two Locs

The lesser loc will be the start, and the greater loc will be the end. If the two locs are equal, the area will be empty.

spanArea :: Span -> Area Source #

Construct an Area consisting of a single Span

>>> spanArea (read "4:5-6:3")
[4:5-6:3]

Combining

(+) :: Area -> Area -> Area Source #

The union of two Areas

Spans that overlap or abut will be merged in the result.

>>> read "[1:1-1:2]" + mempty
[1:1-1:2]
>>> read "[1:1-1:2]" + read "[1:2-1:3]"
[1:1-1:3]
>>> read "[1:1-1:2]" + read "[1:1-3:1]"
[1:1-3:1]
>>> read "[1:1-1:2]" + read "[1:1-11:1]"
[1:1-11:1]
>>> read "[1:1-3:1,6:1-6:2]" + read "[1:1-6:1]"
[1:1-6:2]
>>> read "[1:1-3:1]" + read "[5:1-6:2]"
[1:1-3:1,5:1-6:2]

(-) :: Area -> Area -> Area Source #

The difference between two Areas

a - b contains what is covered by a and not covered by b.

addSpan :: Span -> Area -> Area Source #

addSpan s a is the union of Area a and Span s

>>> addSpan (read "1:1-6:1") (read "[1:1-3:1,6:1-6:2]")
[1:1-6:2]

Querying

firstSpan :: Area -> Maybe Span Source #

The first contiguous Span in the Area, or Nothing if the area is empty

>>> firstSpan mempty
Nothing
>>> firstSpan (read "[3:4-7:2]")
Just 3:4-7:2
>>> firstSpan (read "[3:4-7:2,15:6-17:9]")
Just 3:4-7:2

lastSpan :: Area -> Maybe Span Source #

The last contiguous Span in the Area, or Nothing if the area is empty

>>> lastSpan mempty
Nothing
>>> lastSpan (read "[3:4-7:2]")
Just 3:4-7:2
>>> lastSpan (read "[3:4-7:2,15:6-17:9]")
Just 15:6-17:9

start :: Area -> Maybe Loc Source #

The Loc at which the Area starts, or Nothing if the Area is empty

>>> start mempty
Nothing
>>> start (read "[3:4-7:2]")
Just 3:4
>>> start (read "[3:4-7:2,15:6-17:9]")
Just 3:4

end :: Area -> Maybe Loc Source #

The Loc at which the Area ends, or Nothing if the Area is empty

>>> end mempty
Nothing
>>> end (read "[3:4-7:2]")
Just 7:2
>>> end (read "[3:4-7:2,15:6-17:9]")
Just 17:9

areaSpan :: Area -> Maybe Span Source #

A Span from start to end, or Nothing if the Area is empty

>>> areaSpan mempty
Nothing
>>> areaSpan (read "[3:4-7:2]")
Just 3:4-7:2
>>> areaSpan (read "[3:4-7:2,15:6-17:9]")
Just 3:4-17:9

spansAsc :: Area -> [Span] Source #

A list of the Spans that constitute an Area, sorted in ascending order

>>> spansAsc mempty
[]
>>> spansAsc (read "[3:4-7:2,15:6-17:9]")
[3:4-7:2,15:6-17:9]

spanCount :: Area -> Natural Source #

>>> spanCount mempty
0
>>> spanCount (read "[3:4-7:2]")
1
>>> spanCount (read "[3:4-7:2,15:6-17:9]")
2

Show and Read

areaReadPrec :: ReadPrec Area Source #

>>> readPrec_to_S areaReadPrec minPrec "[]"
[([],"")]
>>> readPrec_to_S areaReadPrec minPrec "[3:2-5:5,8:3-11:4]"
[([3:2-5:5,8:3-11:4],"")]
>>> readPrec_to_S areaReadPrec minPrec "[3:2-5:5,11:4-8:3]"
[([3:2-5:5,8:3-11:4],"")]
>>> readPrec_to_S areaReadPrec minPrec "[3:2-5:5,8:3-8:3]"
[]