mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-12 13:09:05 +03:00
Search paths for (load ...) command.
This commit is contained in:
parent
13418bf900
commit
02cc5d4d51
@ -34,6 +34,7 @@ defaultProject = Project { projectTitle = "Untitled"
|
||||
, projectCarpDir = "./"
|
||||
, projectOutDir = "./out/"
|
||||
, projectPrompt = if os == "darwin" then "鲮 " else "> "
|
||||
, projectCarpSearchPaths = []
|
||||
}
|
||||
|
||||
completeKeywords :: Monad m => String -> String -> m [Completion]
|
||||
|
@ -399,13 +399,29 @@ executeCommand ctx@(Context env typeEnv pathStrings proj lastInput) cmd =
|
||||
return ctx
|
||||
|
||||
Load path ->
|
||||
do contents <- readFile path
|
||||
let files = projectFiles proj
|
||||
files' = if path `elem` files
|
||||
then files
|
||||
else path : files
|
||||
proj' = proj { projectFiles = files' }
|
||||
executeString (ctx { contextProj = proj' }) contents path
|
||||
do let carpDir = projectCarpDir proj
|
||||
fullSearchPaths =
|
||||
path :
|
||||
("./" ++ path) : -- the path from the current directory
|
||||
(map (++ "/" ++ path) (projectCarpSearchPaths proj)) ++ -- user defined search paths
|
||||
[carpDir ++ "/core/" ++ path]
|
||||
-- putStrLn ("Full search paths = " ++ show fullSearchPaths)
|
||||
existingPaths <- filterM doesPathExist fullSearchPaths
|
||||
case existingPaths of
|
||||
[] ->
|
||||
do putStrLnWithColor Red ("Invalid path " ++ path)
|
||||
return ctx
|
||||
firstPathFound : _ ->
|
||||
do --putStrLn ("Will load '" ++ firstPathFound ++ "'")
|
||||
performLoad firstPathFound
|
||||
where performLoad thePath =
|
||||
do contents <- readFile thePath
|
||||
let files = projectFiles proj
|
||||
files' = if thePath `elem` files
|
||||
then files
|
||||
else thePath : files
|
||||
proj' = proj { projectFiles = files' }
|
||||
executeString (ctx { contextProj = proj' }) contents thePath
|
||||
|
||||
Reload ->
|
||||
do let paths = projectFiles proj
|
||||
|
@ -509,13 +509,14 @@ data Project = Project { projectTitle :: String
|
||||
, projectCarpDir :: FilePath
|
||||
, projectOutDir :: FilePath
|
||||
, projectPrompt :: String
|
||||
, projectCarpSearchPaths :: [FilePath]
|
||||
}
|
||||
|
||||
projectFlags :: Project -> String
|
||||
projectFlags proj = joinWithSpace (projectCFlags proj ++ projectLibFlags proj)
|
||||
|
||||
instance Show Project where
|
||||
show (Project title incl cFlags libFlags srcFiles echoC carpDir outDir prompt) =
|
||||
show (Project title incl cFlags libFlags srcFiles echoC carpDir outDir prompt searchPaths) =
|
||||
unlines [ "Title: " ++ title
|
||||
, "Includes:\n " ++ joinWith "\n " (map show incl)
|
||||
, "Cflags:\n " ++ joinWith "\n " cFlags
|
||||
@ -525,6 +526,7 @@ instance Show Project where
|
||||
, "Output directory: " ++ outDir
|
||||
, "CARP_DIR: " ++ carpDir
|
||||
, "Prompt: " ++ prompt
|
||||
, "Search paths for (load ...) command:\n " ++ joinWith "\n " searchPaths
|
||||
]
|
||||
|
||||
-- | Represent the inclusion of a C header file, either like <string.h> or "string.h"
|
||||
|
Loading…
Reference in New Issue
Block a user