1
{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving, FlexibleContexts #-}
2
DeriveDataTypeable, GeneralizedNewtypeDeriving,
3
DeriveFunctor, DeriveFoldable, DeriveTraversable,
3
6
{-| Abstract names should carry unique identifiers and stuff. Not right now though.
5
8
module Agda.Syntax.Abstract.Name where
7
10
import Control.Monad.State
8
import Data.Generics (Typeable, Data)
12
import Data.Foldable (Foldable)
13
import Data.Traversable (Traversable)
14
import Data.Typeable (Typeable)
10
16
import Data.Function
12
19
import Agda.Syntax.Position
13
20
import Agda.Syntax.Common
31
38
, nameBindingSite :: Range
32
39
, nameFixity :: Fixity'
34
deriving (Typeable, Data)
36
43
-- | Qualified names are non-empty lists of names. Equality on qualified names
37
44
-- are just equality on the last name, i.e. the module part is just
42
49
data QName = QName { qnameModule :: ModuleName
43
50
, qnameName :: Name
45
deriving (Typeable, Data)
54
-- | Something preceeded by a qualified name.
55
data QNamed a = QNamed
59
deriving (Typeable, Show, Functor, Foldable, Traversable)
47
61
-- | A module name is just a qualified name.
49
63
-- The 'SetRange' instance for module names sets all individual ranges
50
64
-- to the given one.
51
65
newtype ModuleName = MName { mnameToList :: [Name] }
52
deriving (Eq, Ord, Typeable, Data)
66
deriving (Eq, Ord, Typeable)
54
68
-- | Ambiguous qualified names. Used for overloaded constructors.
56
70
-- Invariant: All the names in the list must have the same concrete,
57
71
-- unqualified name.
58
72
newtype AmbiguousQName = AmbQ { unAmbQ :: [QName] }
59
deriving (Typeable, Data, HasRange, Show)
73
deriving (Typeable, HasRange, Show)
61
75
instance HasRange ModuleName where
62
76
getRange (MName []) = noRange
63
77
getRange (MName xs) = getRange xs
79
-- | A module is anonymous if the qualification path ends in an underscore.
80
isAnonymousModuleName :: ModuleName -> Bool
81
isAnonymousModuleName (MName []) = False
82
isAnonymousModuleName (MName ms) = C.isNoName $ nameConcrete $ last ms
65
84
-- | Sets the ranges of the individual names in the module name to
66
85
-- match those of the corresponding concrete names. If the concrete
67
86
-- names are fewer than the number of module name name parts, then the
68
87
-- initial name parts get the range 'noRange'.
89
-- @C.D.E \`withRangesOf\` [A, B]@ returns @C.D.E@ but with ranges set
72
92
-- * @C@: 'noRange'.
193
212
freshNoName_ :: (MonadState s m, HasFresh NameId s) => m Name
194
213
freshNoName_ = freshNoName noRange
215
-- | Get the next version of the concrete name. For instance, @nextName "x" = "x₁"@.
196
216
-- The name must not be a 'NoName'.
197
217
nextName :: Name -> Name
198
218
nextName x = x { nameConcrete = C.Name noRange $ nextSuf ps }