1-----------------------------------------------------------------------------
4-- Copyright : (c) Phil Freeman 2014
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
12-- Type declarations and associated basic functions for PSCI.
14-----------------------------------------------------------------------------
18import qualified Data.Map as M
19import qualified Language.PureScript as P
21data PSCiOptions = PSCiOptions
22 { psciMultiLineMode :: Bool
23 , psciInputFile :: [FilePath]
24 , psciForeignInputFiles :: [FilePath]
25 , psciInputNodeFlags :: [String]
30-- Holds a list of imported modules, loaded files, and partial let bindings.
31-- The let bindings are partial,
32-- because it makes more sense to apply the binding to the final evaluated expression.
34data PSCiState = PSCiState
35 { psciImportedFilenames :: [FilePath]
36 , psciImportedModules :: [ImportedModule]
37 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
38 , psciForeignFiles :: M.Map P.ModuleName FilePath
39 , psciLetBindings :: [P.Declaration]
40 , psciNodeFlags :: [String]
43-- | All of the data that is contained by an ImportDeclaration in the AST.
46-- * A module name, the name of the module which is being imported
47-- * An ImportDeclarationType which specifies whether there is an explicit
48-- import list, a hiding list, or neither.
49-- * If the module is imported qualified, its qualified name in the importing
50-- module. Otherwise, Nothing.
52type ImportedModule = (P.ModuleName, P.ImportDeclarationType, Maybe P.ModuleName)
54psciImportedModuleNames :: PSCiState -> [P.ModuleName]
55psciImportedModuleNames (PSCiState{psciImportedModules = is}) =
56 map (\(mn, _, _) -> mn) is
58allImportsOf :: P.Module -> PSCiState -> [ImportedModule]
59allImportsOf m (PSCiState{psciImportedModules = is}) =
60 filter isImportOfThis is
62 name = P.getModuleName m
63 isImportOfThis (name', _, _) = name == name'
68-- Updates the state to have more imported modules.
70updateImportedFiles :: FilePath -> PSCiState -> PSCiState
71updateImportedFiles filename st = st { psciImportedFilenames = filename : psciImportedFilenames st }
74-- Updates the state to have more imported modules.
76updateImportedModules :: ImportedModule -> PSCiState -> PSCiState
77updateImportedModules im st = st { psciImportedModules = im : psciImportedModules st }
80-- Updates the state to have more loaded files.
82updateModules :: [(Either P.RebuildPolicy FilePath, P.Module)] -> PSCiState -> PSCiState
83updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modules }
86-- Updates the state to have more let bindings.
88updateLets :: [P.Declaration] -> PSCiState -> PSCiState
89updateLets ds st = st { psciLetBindings = psciLetBindings st ++ ds }
92-- Updates the state to have more let bindings.
94updateForeignFiles :: M.Map P.ModuleName FilePath -> PSCiState -> PSCiState
95updateForeignFiles fs st = st { psciForeignFiles = psciForeignFiles st `M.union` fs }
98-- Valid Meta-commands for PSCI
102 -- A purescript expression
106 -- Show the help (ie, list of directives)
110 -- Import a module from a loaded file
112 | Import ImportedModule
116 | BrowseModule P.ModuleName
118 -- Load a file for use with importing
122 -- Load a foreign module
124 | LoadForeign FilePath
130 -- Reset the state of the REPL
134 -- Add some declarations to the current evaluation context.
136 | Decls [P.Declaration]
138 -- Find the type of an expression
142 -- Find the kind of an expression
146 -- Shows information about the current state of the REPL
155-- | A list of all ReplQuery values.
156replQueries :: [ReplQuery]
157replQueries = [QueryLoaded, QueryImport]
159replQueryStrings :: [String]
160replQueryStrings = map showReplQuery replQueries
162showReplQuery :: ReplQuery -> String
163showReplQuery QueryLoaded = "loaded"
164showReplQuery QueryImport = "import"
166parseReplQuery :: String -> Maybe ReplQuery
167parseReplQuery "loaded" = Just QueryLoaded
168parseReplQuery "import" = Just QueryImport
169parseReplQuery _ = Nothing
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