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:
parent
667f894ec3
commit
6485f858ed
@ -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
|
||||
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user