Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Position information for syntax. Crucial for giving good error messages.
Synopsis
- type Position = Position' SrcFile
- type PositionWithoutFile = Position' ()
- data Position' a = Pn {}
- type SrcFile = Maybe RangeFile
- data RangeFile = RangeFile {
- rangeFilePath :: !AbsolutePath
- rangeFileName :: !(Maybe TopLevelModuleName)
- mkRangeFile :: AbsolutePath -> Maybe TopLevelModuleName -> RangeFile
- positionInvariant :: Position' a -> Bool
- startPos :: Maybe RangeFile -> Position
- movePos :: Position' a -> Char -> Position' a
- movePosByString :: Foldable t => Position' a -> t Char -> Position' a
- backupPos :: Position' a -> Position' a
- startPos' :: a -> Position' a
- type Interval = Interval' SrcFile
- type IntervalWithoutFile = Interval' ()
- data Interval' a = Interval {}
- intervalInvariant :: Ord a => Interval' a -> Bool
- posToInterval :: a -> PositionWithoutFile -> PositionWithoutFile -> Interval' a
- getIntervalFile :: Interval' a -> a
- iLength :: Interval' a -> Int32
- fuseIntervals :: Ord a => Interval' a -> Interval' a -> Interval' a
- setIntervalFile :: a -> Interval' b -> Interval' a
- type Range = Range' SrcFile
- data Range' a
- = NoRange
- | Range !a (Seq IntervalWithoutFile)
- rangeInvariant :: Ord a => Range' a -> Bool
- consecutiveAndSeparated :: Ord a => [Interval' a] -> Bool
- intervalsToRange :: a -> [IntervalWithoutFile] -> Range' a
- intervalToRange :: a -> IntervalWithoutFile -> Range' a
- rangeIntervals :: Range' a -> [IntervalWithoutFile]
- rangeFile :: Range -> SrcFile
- rangeModule' :: Range -> Maybe (Maybe TopLevelModuleName)
- rangeModule :: Range -> Maybe TopLevelModuleName
- rightMargin :: Range -> Range
- noRange :: Range' a
- posToRange :: Position' a -> Position' a -> Range' a
- posToRange' :: a -> PositionWithoutFile -> PositionWithoutFile -> Range' a
- rStart :: Range' a -> Maybe (Position' a)
- rStart' :: Range' a -> Maybe PositionWithoutFile
- rEnd :: Range' a -> Maybe (Position' a)
- rEnd' :: Range' a -> Maybe PositionWithoutFile
- rangeToInterval :: Range' a -> Maybe IntervalWithoutFile
- rangeToIntervalWithFile :: Range' a -> Maybe (Interval' a)
- continuous :: Range' a -> Range' a
- continuousPerLine :: Ord a => Range' a -> Range' a
- newtype PrintRange a = PrintRange a
- class HasRange a where
- class HasRange a => SetRange a where
- class KillRange a where
- killRange :: KillRangeT a
- type KillRangeT a = a -> a
- killRangeMap :: (KillRange k, KillRange v) => KillRangeT (Map k v)
- class KILLRANGE t b where
- killRangeN :: IsBase t ~ b => All KillRange (Domains t) => t -> t
- withRangeOf :: (SetRange t, HasRange u) => t -> u -> t
- fuseRange :: (HasRange u, HasRange t) => u -> t -> Range
- fuseRanges :: Ord a => Range' a -> Range' a -> Range' a
- beginningOf :: Range -> Range
- beginningOfFile :: Range -> Range
- interleaveRanges :: HasRange a => [a] -> [a] -> ([a], [(a, a)])
Positions
type PositionWithoutFile = Position' () Source #
Represents a point in the input.
If two positions have the same srcFile
and posPos
components,
then the final two components should be the same as well, but since
this can be hard to enforce the program should not rely too much on
the last two components; they are mainly there to improve error
messages for the user.
Note the invariant which positions have to satisfy: positionInvariant
.
Instances
Pretty PositionWithoutFile Source # | |
Defined in Agda.Syntax.Position pretty :: PositionWithoutFile -> Doc Source # prettyPrec :: Int -> PositionWithoutFile -> Doc Source # prettyList :: [PositionWithoutFile] -> Doc Source # | |
Foldable Position' Source # | |
Defined in Agda.Syntax.Position fold :: Monoid m => Position' m -> m foldMap :: Monoid m => (a -> m) -> Position' a -> m foldMap' :: Monoid m => (a -> m) -> Position' a -> m foldr :: (a -> b -> b) -> b -> Position' a -> b foldr' :: (a -> b -> b) -> b -> Position' a -> b foldl :: (b -> a -> b) -> b -> Position' a -> b foldl' :: (b -> a -> b) -> b -> Position' a -> b foldr1 :: (a -> a -> a) -> Position' a -> a foldl1 :: (a -> a -> a) -> Position' a -> a elem :: Eq a => a -> Position' a -> Bool maximum :: Ord a => Position' a -> a minimum :: Ord a => Position' a -> a | |
Traversable Position' Source # | |
Functor Position' Source # | |
NFData Position Source # | |
Defined in Agda.Syntax.Position | |
NFData PositionWithoutFile Source # | |
Defined in Agda.Syntax.Position rnf :: PositionWithoutFile -> () | |
EncodeTCM (Position' ()) Source # | |
Pretty a => Pretty (Position' (Maybe a)) Source # | |
EmbPrj a => EmbPrj (Position' a) Source # | |
Generic (Position' a) Source # | |
Read a => Read (Position' a) | |
Defined in Agda.Interaction.Base | |
Show a => Show (Position' a) Source # | |
Eq a => Eq (Position' a) Source # | |
Ord a => Ord (Position' a) Source # | |
ToJSON (Position' ()) Source # | |
Defined in Agda.Interaction.JSONTop | |
type Rep (Position' a) Source # | |
Defined in Agda.Syntax.Position type Rep (Position' a) = D1 ('MetaData "Position'" "Agda.Syntax.Position" "Agda-2.6.3.20230930-inplace" 'False) (C1 ('MetaCons "Pn" 'PrefixI 'True) ((S1 ('MetaSel ('Just "srcFile") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "posPos") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int32)) :*: (S1 ('MetaSel ('Just "posLine") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int32) :*: S1 ('MetaSel ('Just "posCol") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int32)))) |
RangeFile | |
|
Instances
mkRangeFile :: AbsolutePath -> Maybe TopLevelModuleName -> RangeFile Source #
A smart constructor for RangeFile
.
positionInvariant :: Position' a -> Bool Source #
startPos :: Maybe RangeFile -> Position Source #
The first position in a file: position 1, line 1, column 1.
movePos :: Position' a -> Char -> Position' a Source #
Advance the position by one character.
A newline character ('n'
) moves the position to the first
character in the next line. Any other character moves the
position to the next column.
movePosByString :: Foldable t => Position' a -> t Char -> Position' a Source #
Advance the position by a string.
movePosByString = foldl' movePos
backupPos :: Position' a -> Position' a Source #
Backup the position by one character.
Precondition: The character must not be 'n'
.
Intervals
type IntervalWithoutFile = Interval' () Source #
An interval. The iEnd
position is not included in the interval.
Note the invariant which intervals have to satisfy: intervalInvariant
.
Instances
Pretty IntervalWithoutFile Source # | |
Defined in Agda.Syntax.Position pretty :: IntervalWithoutFile -> Doc Source # prettyPrec :: Int -> IntervalWithoutFile -> Doc Source # prettyList :: [IntervalWithoutFile] -> Doc Source # | |
HasRange Interval Source # | |
Foldable Interval' Source # | |
Defined in Agda.Syntax.Position fold :: Monoid m => Interval' m -> m foldMap :: Monoid m => (a -> m) -> Interval' a -> m foldMap' :: Monoid m => (a -> m) -> Interval' a -> m foldr :: (a -> b -> b) -> b -> Interval' a -> b foldr' :: (a -> b -> b) -> b -> Interval' a -> b foldl :: (b -> a -> b) -> b -> Interval' a -> b foldl' :: (b -> a -> b) -> b -> Interval' a -> b foldr1 :: (a -> a -> a) -> Interval' a -> a foldl1 :: (a -> a -> a) -> Interval' a -> a elem :: Eq a => a -> Interval' a -> Bool maximum :: Ord a => Interval' a -> a minimum :: Ord a => Interval' a -> a | |
Traversable Interval' Source # | |
Functor Interval' Source # | |
NFData Interval Source # | |
Defined in Agda.Syntax.Position | |
NFData IntervalWithoutFile Source # | |
Defined in Agda.Syntax.Position rnf :: IntervalWithoutFile -> () | |
Pretty a => Pretty (Interval' (Maybe a)) Source # | |
EmbPrj a => EmbPrj (Interval' a) Source # | |
Generic (Interval' a) Source # | |
Read a => Read (Interval' a) | |
Defined in Agda.Interaction.Base | |
Show a => Show (Interval' a) Source # | |
Eq a => Eq (Interval' a) Source # | |
Ord a => Ord (Interval' a) Source # | |
type Rep (Interval' a) Source # | |
Defined in Agda.Syntax.Position type Rep (Interval' a) = D1 ('MetaData "Interval'" "Agda.Syntax.Position" "Agda-2.6.3.20230930-inplace" 'False) (C1 ('MetaCons "Interval" 'PrefixI 'True) (S1 ('MetaSel ('Just "iStart") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Position' a)) :*: S1 ('MetaSel ('Just "iEnd") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Position' a)))) |
intervalInvariant :: Ord a => Interval' a -> Bool Source #
posToInterval :: a -> PositionWithoutFile -> PositionWithoutFile -> Interval' a Source #
Converts a file name and two positions to an interval.
getIntervalFile :: Interval' a -> a Source #
Gets the srcFile
component of the interval. Because of the invariant,
they are both the same.
fuseIntervals :: Ord a => Interval' a -> Interval' a -> Interval' a Source #
Finds the least interval which covers the arguments.
Precondition: The intervals must point to the same file.
setIntervalFile :: a -> Interval' b -> Interval' a Source #
Sets the srcFile
components of the interval.
Ranges
A range is a file name, plus a sequence of intervals, assumed to point to the given file. The intervals should be consecutive and separated.
Note the invariant which ranges have to satisfy: rangeInvariant
.
NoRange | |
Range !a (Seq IntervalWithoutFile) |
Instances
EncodeTCM Range Source # | |
HasRange Range Source # | |
KillRange Range Source # | |
Defined in Agda.Syntax.Position | |
SetRange Range Source # | |
FreshName Range Source # | |
Defined in Agda.TypeChecking.Monad.Base freshName_ :: MonadFresh NameId m => Range -> m Name Source # | |
PrettyTCM Range Source # | |
Defined in Agda.TypeChecking.Pretty | |
EmbPrj Range Source # | Ranges are always deserialised as |
Subst Range Source # | |
Defined in Agda.TypeChecking.Substitute applySubst :: Substitution' (SubstArg Range) -> Range -> Range Source # | |
Foldable Range' Source # | |
Defined in Agda.Syntax.Position fold :: Monoid m => Range' m -> m foldMap :: Monoid m => (a -> m) -> Range' a -> m foldMap' :: Monoid m => (a -> m) -> Range' a -> m foldr :: (a -> b -> b) -> b -> Range' a -> b foldr' :: (a -> b -> b) -> b -> Range' a -> b foldl :: (b -> a -> b) -> b -> Range' a -> b foldl' :: (b -> a -> b) -> b -> Range' a -> b foldr1 :: (a -> a -> a) -> Range' a -> a foldl1 :: (a -> a -> a) -> Range' a -> a elem :: Eq a => a -> Range' a -> Bool maximum :: Ord a => Range' a -> a | |
Traversable Range' Source # | |
Functor Range' Source # | |
ToJSON Range Source # | |
Defined in Agda.Interaction.JSONTop | |
LensClosure MetaInfo Range Source # | |
Defined in Agda.TypeChecking.Monad.Base | |
LensClosure MetaVariable Range Source # | |
Defined in Agda.TypeChecking.Monad.Base | |
Pretty a => Pretty (Range' (Maybe a)) Source # | |
Null (Range' a) Source # | |
Eq a => Monoid (Range' a) Source # | |
Eq a => Semigroup (Range' a) Source # | |
Generic (Range' a) Source # | |
Read a => Read (Range' a) | Note that the grammar implemented by this instance does not necessarily match the current representation of ranges. |
Defined in Agda.Interaction.Base | |
Show a => Show (Range' a) Source # | |
NFData a => NFData (Range' a) Source # | |
Defined in Agda.Syntax.Position | |
Eq a => Eq (Range' a) Source # | |
Ord a => Ord (Range' a) Source # | |
FreshName (Range, String) Source # | |
Defined in Agda.TypeChecking.Monad.Base freshName_ :: MonadFresh NameId m => (Range, String) -> m Name Source # | |
type SubstArg Range Source # | |
Defined in Agda.TypeChecking.Substitute | |
type Rep (Range' a) Source # | |
Defined in Agda.Syntax.Position type Rep (Range' a) = D1 ('MetaData "Range'" "Agda.Syntax.Position" "Agda-2.6.3.20230930-inplace" 'False) (C1 ('MetaCons "NoRange" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Range" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Seq IntervalWithoutFile)))) |
rangeInvariant :: Ord a => Range' a -> Bool Source #
Range invariant.
consecutiveAndSeparated :: Ord a => [Interval' a] -> Bool Source #
Are the intervals consecutive and separated, do they all point to the same file, and do they satisfy the interval invariant?
intervalsToRange :: a -> [IntervalWithoutFile] -> Range' a Source #
Turns a file name plus a list of intervals into a range.
Precondition: consecutiveAndSeparated
.
intervalToRange :: a -> IntervalWithoutFile -> Range' a Source #
Converts a file name and an interval to a range.
rangeIntervals :: Range' a -> [IntervalWithoutFile] Source #
The intervals that make up the range. The intervals are
consecutive and separated (consecutiveAndSeparated
).
rangeModule' :: Range -> Maybe (Maybe TopLevelModuleName) Source #
The range's top-level module name, if any.
If there is no range, then Nothing
is returned. If there is a
range without a module name, then
is returned.Just
Nothing
rangeModule :: Range -> Maybe TopLevelModuleName Source #
The range's top-level module name, if any.
rightMargin :: Range -> Range Source #
Conflate a range to its right margin.
posToRange :: Position' a -> Position' a -> Range' a Source #
Converts two positions to a range.
Precondition: The positions have to point to the same file.
posToRange' :: a -> PositionWithoutFile -> PositionWithoutFile -> Range' a Source #
Converts a file name and two positions to a range.
rStart' :: Range' a -> Maybe PositionWithoutFile Source #
The initial position in the range, if any.
rEnd :: Range' a -> Maybe (Position' a) Source #
The position after the final position in the range, if any.
rEnd' :: Range' a -> Maybe PositionWithoutFile Source #
The position after the final position in the range, if any.
rangeToInterval :: Range' a -> Maybe IntervalWithoutFile Source #
Converts a range to an interval, if possible. Note that the information about the source file is lost.
rangeToIntervalWithFile :: Range' a -> Maybe (Interval' a) Source #
Converts a range to an interval, if possible.
continuous :: Range' a -> Range' a Source #
Returns the shortest continuous range containing the given one.
continuousPerLine :: Ord a => Range' a -> Range' a Source #
Removes gaps between intervals on the same line.
newtype PrintRange a Source #
Wrapper to indicate that range should be printed.
Instances
class HasRange a where Source #
Things that have a range are instances of this class.
Nothing
Instances
class HasRange a => SetRange a where Source #
If it is also possible to set the range, this is the class.
Nothing
Instances
class KillRange a where Source #
Killing the range of an object sets all range information to noRange
.
Nothing
killRange :: KillRangeT a Source #
default killRange :: (Functor f, KillRange b, f b ~ a) => KillRangeT a Source #
Instances
type KillRangeT a = a -> a Source #
killRangeMap :: (KillRange k, KillRange v) => KillRangeT (Map k v) Source #
Remove ranges in keys and values of a map.
class KILLRANGE t b where Source #
Instances
IsBase t ~ 'True => KILLRANGE t 'True Source # | |
Defined in Agda.Syntax.Position killRangeN :: t -> t Source # | |
KILLRANGE t (IsBase t) => KILLRANGE (a -> t) 'False Source # | |
Defined in Agda.Syntax.Position killRangeN :: (a -> t) -> a -> t Source # |
withRangeOf :: (SetRange t, HasRange u) => t -> u -> t Source #
x `withRangeOf` y
sets the range of x
to the range of y
.
fuseRange :: (HasRange u, HasRange t) => u -> t -> Range Source #
Precondition: The ranges must point to the same file (or be empty).
fuseRanges :: Ord a => Range' a -> Range' a -> Range' a Source #
fuseRanges r r'
unions the ranges r
and r'
.
Meaning it finds the least range r0
that covers r
and r'
.
Precondition: The ranges must point to the same file (or be empty).
beginningOf :: Range -> Range Source #
beginningOf r
is an empty range (a single, empty interval)
positioned at the beginning of r
. If r
does not have a
beginning, then noRange
is returned.
beginningOfFile :: Range -> Range Source #
beginningOfFile r
is an empty range (a single, empty interval)
at the beginning of r
's starting position's file. If there is no
such position, then an empty range is returned.
interleaveRanges :: HasRange a => [a] -> [a] -> ([a], [(a, a)]) Source #
Interleaves two streams of ranged elements
It will report the conflicts as a list of conflicting pairs. In case of conflict, the element with the earliest start position is placed first. In case of a tie, the element with the earliest ending position is placed first. If both tie, the element from the first list is placed first.