Skip to content

Add instance Ord for Field, FieldLine, SectionArg and Name #9387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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