1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Move Named & Ignored into Analysis.Name.

This commit is contained in:
Rob Rix 2019-12-18 10:51:02 -05:00
parent 667f894ec3
commit 6485f858ed
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7
2 changed files with 32 additions and 31 deletions

View File

@ -1,6 +1,12 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveTraversable, GeneralizedNewtypeDeriving #-}
module Analysis.Name
( Name(..)
, Named(..)
, named
, named'
, namedName
, namedValue
, Ignored(..)
) where
import Data.String (IsString)
@ -9,3 +15,27 @@ import Data.Text (Text)
-- | User-specified and -relevant names.
newtype Name = Name { unName :: Text }
deriving (Eq, IsString, Ord, Show)
-- | Annotates an @a@ with a 'Name'-provided name, which is ignored for '==' and 'compare'.
data Named a = Named (Ignored Name) a
deriving (Eq, Foldable, Functor, Ord, Show, Traversable)
named :: Name -> a -> Named a
named = Named . Ignored
named' :: Name -> Named Name
named' u = Named (Ignored u) u
namedName :: Named a -> Name
namedName (Named (Ignored n) _) = n
namedValue :: Named a -> a
namedValue (Named _ a) = a
newtype Ignored a = Ignored a
deriving (Foldable, Functor, Show, Traversable)
instance Eq (Ignored a) where _ == _ = True
instance Ord (Ignored a) where compare _ _ = EQ

View File

@ -1,12 +1,6 @@
{-# LANGUAGE DeriveGeneric, DeriveTraversable, GeneralizedNewtypeDeriving, LambdaCase, OverloadedLists #-}
module Core.Name
( Name (..)
, Named(..)
, named
, named'
, namedName
, namedValue
, Ignored(..)
( module Analysis.Name
, reservedNames
, isSimpleCharacter
, needsQuotation
@ -18,29 +12,6 @@ import Data.HashSet (HashSet)
import qualified Data.HashSet as HashSet
import Data.Text as Text (any, unpack)
-- | Annotates an @a@ with a 'Name'-provided name, which is ignored for '==' and 'compare'.
data Named a = Named (Ignored Name) a
deriving (Eq, Foldable, Functor, Ord, Show, Traversable)
named :: Name -> a -> Named a
named = Named . Ignored
named' :: Name -> Named Name
named' u = Named (Ignored u) u
namedName :: Named a -> Name
namedName (Named (Ignored n) _) = n
namedValue :: Named a -> a
namedValue (Named _ a) = a
newtype Ignored a = Ignored a
deriving (Foldable, Functor, Show, Traversable)
instance Eq (Ignored a) where _ == _ = True
instance Ord (Ignored a) where compare _ _ = EQ
reservedNames :: HashSet String
reservedNames = [ "#true", "#false", "if", "then", "else"
, "#unit", "load", "rec", "#record"]