futhark
Safe HaskellNone
LanguageGHC2021

Futhark.Profile.SourceRange

Synopsis

Documentation

data SourceRange Source #

I chose this representation over Loc from srcLoc because it guarantees the presence of a range. Loc is essentially a 'Maybe (Pos, Pos)', because of the NoLoc constructor. I cannot even imagine dealing with cross-file ranges anyway.

Constructors

SourceRange 

Fields

  • startPos :: !Pos
     
  • endLine :: !Int

    invariant: at least a big as start.line

  • endColumn :: !Int

    invariant: at least as big as start.col, unless the range spans multiple lines

startLineCol :: SourceRange -> (Int, Int) Source #

Extract start line and column

endLineCol :: SourceRange -> (Int, Int) Source #

Extract end line and column

filter123 :: (a -> Bool) -> OneTwoThree a -> Maybe (OneTwoThree a) Source #

mergeSemigroup :: Semigroup s => (SourceRange, s) -> (SourceRange, s) -> OneTwoThree (SourceRange, s) Source #

Assumes that the ranges overlap

parse :: Text -> Either Text SourceRange Source #

Parse a source range, respect the invariants noted in the definition and print the MegaParsec errorbundle into a Text.

>>> parse "example.fut:1:1-5"
Right (SourceRange {start = Pos "example.fut" 1 1 (-1), endLine = 1, endColumn = 5})
>>> parse "directory/example.fut:15:12-17:1"
Right (SourceRange {start = Pos "directory/example.fut" 15 12 (-1), endLine = 17, endColumn = 1})