Skip to content

Commit

Permalink
Merge pull request #9387 from haskell/ord-for-fields
Browse files Browse the repository at this point in the history
Add instance Ord for Field, FieldLine, SectionArg and Name
  • Loading branch information
mergify[bot] authored Nov 6, 2023
2 parents 2fca50b + af0126c commit 15b5b05
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Cabal-syntax/src/Distribution/Fields/Field.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE StandaloneDeriving #-}

-- | Cabal-like file AST types: 'Field', 'Section' etc
--
Expand Down Expand Up @@ -51,6 +52,9 @@ data Field ann
| Section !(Name ann) [SectionArg ann] [Field ann]
deriving (Eq, Show, Functor, Foldable, Traversable)

-- | @since 3.12.0.0
deriving instance Ord ann => Ord (Field ann)

-- | Section of field name
fieldName :: Field ann -> Name ann
fieldName (Field n _) = n
Expand All @@ -73,6 +77,9 @@ fieldUniverse f@(Field _ _) = [f]
data FieldLine ann = FieldLine !ann !ByteString
deriving (Eq, Show, Functor, Foldable, Traversable)

-- | @since 3.12.0.0
deriving instance Ord ann => Ord (FieldLine ann)

-- | @since 3.0.0.0
fieldLineAnn :: FieldLine ann -> ann
fieldLineAnn (FieldLine ann _) = ann
Expand All @@ -91,6 +98,9 @@ data SectionArg ann
SecArgOther !ann !ByteString
deriving (Eq, Show, Functor, Foldable, Traversable)

-- | @since 3.12.0.0
deriving instance Ord ann => Ord (SectionArg ann)

-- | Extract annotation from 'SectionArg'.
sectionArgAnn :: SectionArg ann -> ann
sectionArgAnn (SecArgName ann _) = ann
Expand All @@ -109,6 +119,9 @@ type FieldName = ByteString
data Name ann = Name !ann !FieldName
deriving (Eq, Show, Functor, Foldable, Traversable)

-- | @since 3.12.0.0
deriving instance Ord ann => Ord (Name ann)

mkName :: ann -> FieldName -> Name ann
mkName ann bs = Name ann (B.map Char.toLower bs)

Expand Down

0 comments on commit 15b5b05

Please sign in to comment.