1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Names
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
12-- Data types for names
14-----------------------------------------------------------------------------
16{-# LANGUAGE DeriveDataTypeable #-}
18module Language.PureScript.Names where
22import Data.Function (on)
25-- The type of a foreign import
29 -- A regular foreign import
33 -- A foreign import which contains inline Javascript as a string literal
37 -- A type class dictionary member accessor import, generated during desugaring of type class declarations
39 | TypeClassAccessorImport deriving (Show, Eq, Data, Typeable)
46 -- A value introduced as a binding in a module
52 | Extern ForeignImportType
54 -- A local name introduced using a lambda abstraction, variable introduction or binder
62 -- A type class dictionary, generated during desugaring of type class declarations
64 | TypeInstanceDictionaryValue
66 -- A type instance member, generated during desugaring of type class declarations
68 | TypeInstanceMember deriving (Show, Eq, Data, Typeable)
71-- Names for value identifiers
75 -- An alphanumeric identifier
79 -- A symbolic name for an infix operator
85 | Escaped String deriving (Data, Typeable)
87instance Show Ident where
89 show (Op op) = '(':op ++ ")"
92instance Eq Ident where
93 Ident s1 == Ident s2 = s1 == s2
94 Op s1 == Op s2 = s1 == s2
95 Escaped s1 == Escaped s2 = s1 == s2
96 Ident s1 == Escaped s2 = s1 == s2
97 Escaped s1 == Ident s2 = s1 == s2
100instance Ord Ident where
101 compare = compare `on` show
104-- Proper names, i.e. capitalized names for e.g. module names, type//data constructors.
106newtype ProperName = ProperName { runProperName :: String } deriving (Eq, Ord, Data, Typeable)
108instance Show ProperName where
114data ModuleName = ModuleName [ProperName] deriving (Eq, Ord, Data, Typeable)
116runModuleName :: ModuleName -> String
117runModuleName (ModuleName pns) = intercalate "." (runProperName `map` pns)
119moduleNameFromString :: String -> ModuleName
120moduleNameFromString = ModuleName . splitProperNames
122 splitProperNames s = case dropWhile (== '.') s of
124 s' -> ProperName w : splitProperNames s''
125 where (w, s'') = break (== '.') s'
127instance Show ModuleName where
131-- A qualified name, i.e. a name with an optional module name
133data Qualified a = Qualified (Maybe ModuleName) a deriving (Eq, Ord, Data, Typeable)
135instance (Show a) => Show (Qualified a) where
136 show (Qualified Nothing a) = show a
137 show (Qualified (Just name) a) = show name ++ "." ++ show a
140-- Provide a default module name, if a name is unqualified
142qualify :: ModuleName -> Qualified a -> (ModuleName, a)
143qualify m (Qualified Nothing a) = (m, a)
144qualify _ (Qualified (Just m) a) = (m, a)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list