1module PSCi.Module where
6import qualified Language.PureScript as P
8import System.FilePath (pathSeparator)
9import System.IO.UTF8 (readUTF8File)
12-- | The name of the PSCI support module
13supportModuleName :: P.ModuleName
14supportModuleName = P.ModuleName [P.ProperName "$PSCI", P.ProperName "Support"]
16-- | Support module, contains code to evaluate terms
17supportModule :: P.Module
19 case P.parseModulesFromFiles id [("", code)] of
20 Right [(_, P.Module ss cs _ ds exps)] -> P.Module ss cs supportModuleName ds exps
21 _ -> P.internalError "Support module could not be parsed"
28 , "import Control.Monad.Eff"
29 , "import Control.Monad.Eff.Console"
30 , "import Control.Monad.Eff.Unsafe"
32 , "class Eval a where"
33 , " eval :: a -> Eff (console :: CONSOLE) Unit"
35 , "instance evalShow :: (Show a) => Eval a where"
38 , "instance evalEff :: (Eval a) => Eval (Eff eff a) where"
39 , " eval x = unsafeInterleaveEff x >>= eval"
45-- Loads a file for use with imports.
47loadModule :: FilePath -> IO (Either String [P.Module])
48loadModule filename = do
49 content <- readUTF8File filename
50 return $ either (Left . P.prettyPrintMultipleErrors False) (Right . map snd) $ P.parseModulesFromFiles id [(filename, content)]
55loadAllModules :: [FilePath] -> IO (Either P.MultipleErrors [(FilePath, P.Module)])
56loadAllModules files = do
57 filesAndContent <- forM files $ \filename -> do
58 content <- readUTF8File filename
59 return (filename, content)
60 return $ P.parseModulesFromFiles id filesAndContent
64-- Makes a volatile module to execute the current expression.
66createTemporaryModule :: Bool -> PSCiState -> P.Expr -> P.Module
67createTemporaryModule exec PSCiState{psciImportedModules = imports, psciLetBindings = lets} val =
69 moduleName = P.ModuleName [P.ProperName "$PSCI"]
70 trace = P.Var (P.Qualified (Just supportModuleName) (P.Ident "eval"))
71 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
72 itDecl = P.ValueDeclaration (P.Ident "it") P.Public [] $ Right val
73 mainDecl = P.ValueDeclaration (P.Ident "$main") P.Public [] $ Right mainValue
74 decls = if exec then [itDecl, mainDecl] else [itDecl]
76 P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName ((importDecl `map` imports) ++ lets ++ decls) Nothing
80-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
82createTemporaryModuleForKind :: PSCiState -> P.Type -> P.Module
83createTemporaryModuleForKind PSCiState{psciImportedModules = imports, psciLetBindings = lets} typ =
85 moduleName = P.ModuleName [P.ProperName "$PSCI"]
86 itDecl = P.TypeSynonymDeclaration (P.ProperName "IT") [] typ
88 P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName ((importDecl `map` imports) ++ lets ++ [itDecl]) Nothing
91-- Makes a volatile module to execute the current imports.
93createTemporaryModuleForImports :: PSCiState -> P.Module
94createTemporaryModuleForImports PSCiState{psciImportedModules = imports} =
96 moduleName = P.ModuleName [P.ProperName "$PSCI"]
98 P.Module (P.internalModuleSourceSpan "<internal>") [] moduleName (importDecl `map` imports) Nothing
100importDecl :: ImportedModule -> P.Declaration
101importDecl (mn, declType, asQ) = P.ImportDeclaration mn declType asQ False
104indexFile = ".psci_modules" ++ pathSeparator : "index.js"
106modulesDir :: FilePath
107modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
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