snippet-0.1.0.0: src/Snippet/Region.hs
-- |
--
-- Module : Snippet.Region
-- Copyright : (c) 2026 Patrick Brisbin
-- License : AGPL-3
-- Maintainer : pbrisbin@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Snippet.Region
( Region (..)
-- * Single-line helpers
, lineRegion
, lineRegionFrom
, lineRegionFromTo
) where
import Prelude
data Region = Region
{ startLine :: Int
, endLine :: Maybe Int
-- ^ Defaults to 'startLine' if missing
, startColumn :: Maybe Int
-- ^ Defaults to @1@ if missing
, endColumn :: Maybe Int
-- ^ If missing, the entire last line is considered focused
--
-- This follows section 3.30.8 @endColumn@ property of sarif-v2.0
-- specification, because it's just reasonable behavior:
--
-- @
-- If endColumn is absent, it SHALL default to a value one greater than the
-- column number of the last character on the line
-- @
}
deriving stock (Eq, Show)
lineRegion :: Int -> Region
lineRegion startLine =
Region
{ startLine
, endLine = Nothing
, startColumn = Nothing
, endColumn = Nothing
}
lineRegionFrom :: Int -> Int -> Region
lineRegionFrom startLine sc =
Region
{ startLine
, endLine = Nothing
, startColumn = Just sc
, endColumn = Nothing
}
lineRegionFromTo :: Int -> Int -> Int -> Region
lineRegionFromTo startLine sc ec =
Region
{ startLine
, endLine = Nothing
, startColumn = Just sc
, endColumn = Just ec
}