Skip to content

Commit

Permalink
Expr.Types: add NPos & NSourcePos
Browse files Browse the repository at this point in the history
These are to abstract over Megaparsec types which for `(<>)` use `+` but do not
provide monoid. Also abstracting over these types allows to implement new
positioning tht would work faster then current types.
  • Loading branch information
Anton-Latukha committed Jan 19, 2022
1 parent 9c971ed commit b24d1de
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Nix/Expr/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,38 @@ import Instances.TH.Lift () -- importing Lift Text for G

-- * utils

newtype NPos = NPos Pos
deriving
( Eq, Ord
, Read, Show
, Data, NFData
, Generic
)

instance Semigroup NPos where
(NPos x) <> (NPos y) = NPos (x <> y)

-- | Represents source positions.
-- Source line & column positions change intensively during parsing,
-- so they are declared strict to avoid memory leaks.
--
-- The data type is a reimplementation of 'Text.Megaparsec.Pos' 'SourcePos'.
data NSourcePos =
NSourcePos
{ -- | Name of source file
getSourceName :: Path,
-- | Line number
getSourceLine :: !NPos,
-- | Column number
getSourceColumn :: !NPos
}
deriving
( Eq, Ord
, Read, Show
, Data, NFData
, Generic
)

-- 2021-07-16: NOTE: Should replace @ParamSet@ List
-- | > Hashmap VarName -- type synonym
type AttrSet = HashMap VarName
Expand Down

0 comments on commit b24d1de

Please sign in to comment.