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, DeriveFunctor, GADTs #-}
18module Language.PureScript.Names where
22import Data.List.Split (splitOn)
23import qualified Data.Aeson as A
24import qualified Data.Text as T
27-- Names for value identifiers
31 -- An alphanumeric identifier
35 -- A symbolic name for an infix operator
37 | Op String deriving (Eq, Ord, Data, Typeable)
39runIdent :: Ident -> String
43instance Show Ident where
45 show (Op op) = '(':op ++ ")"
48-- Proper names, i.e. capitalized names for e.g. module names, type//data constructors.
50newtype ProperName = ProperName { runProperName :: String } deriving (Eq, Ord, Data, Typeable)
52instance Show ProperName where
58data ModuleName = ModuleName [ProperName] deriving (Eq, Ord, Data, Typeable)
60runModuleName :: ModuleName -> String
61runModuleName (ModuleName pns) = intercalate "." (runProperName `map` pns)
63moduleNameFromString :: String -> ModuleName
64moduleNameFromString = ModuleName . splitProperNames
66 splitProperNames s = case dropWhile (== '.') s of
68 s' -> ProperName w : splitProperNames s''
69 where (w, s'') = break (== '.') s'
71instance Show ModuleName where
75-- A qualified name, i.e. a name with an optional module name
77data Qualified a = Qualified (Maybe ModuleName) a deriving (Eq, Ord, Data, Typeable, Functor)
79instance (Show a) => Show (Qualified a) where
80 show (Qualified Nothing a) = show a
81 show (Qualified (Just name) a) = show name ++ "." ++ show a
83instance (a ~ ProperName) => A.ToJSON (Qualified a) where
84 toJSON = A.toJSON . show
86instance (a ~ ProperName) => A.FromJSON (Qualified a) where
88 A.withText "Qualified ProperName" $ \str ->
89 return $ case reverse (splitOn "." (T.unpack str)) of
90 [name] -> Qualified Nothing (ProperName name)
91 (name:rest) -> Qualified (Just (reconstructModuleName rest)) (ProperName name)
92 _ -> Qualified Nothing (ProperName "")
94 reconstructModuleName = moduleNameFromString . intercalate "." . reverse
98-- Provide a default module name, if a name is unqualified
100qualify :: ModuleName -> Qualified a -> (ModuleName, a)
101qualify m (Qualified Nothing a) = (m, a)
102qualify _ (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