Commit 00a354d3 authored by Jurrien Stutterheim's avatar Jurrien Stutterheim

Switch to hierarchical module imports

Add "cpm make" command which builds all projects in the pwd
Fix path issues
Start implementing environment-related actions (currently not working)
Clean up
parent b8fb62d9
definition module AbsSyn
from FilePath import :: FilePath
from System.FilePath import :: FilePath
/**
* Datatypes
......@@ -9,6 +9,7 @@ from FilePath import :: FilePath
= Project FilePath ProjectAction
| Module String ModuleAction
| Environment EnvironmentAction
| CpmMake
| CpmHelp
:: ProjectAction
......@@ -16,7 +17,7 @@ from FilePath import :: FilePath
| ShowProject
| BuildProject Bool FilePath
| ProjectPath PathAction
//| SetProjectRoot String TODO: Not yet supported by PmProject
| SetRelativeRoot String
| SetTarget String
| SetExec String
| ProjectHelp
......@@ -29,10 +30,10 @@ from FilePath import :: FilePath
| PathHelp
:: PathDirection
= PathUp
| PathDown
| PathTop
| PathBottom
= MovePathUp
| MovePathDown
| MovePathTop
| MovePathBottom
:: ModuleAction
= CreateModule ModuleType
......@@ -43,4 +44,14 @@ from FilePath import :: FilePath
| LibraryModule
:: EnvironmentAction
= ShowEnvironment
= ListEnvironments
| ImportEnvironment FilePath
| RemoveEnvironment String
| ShowEnvironment String
| ExportEnvironment String
| CreateEnvironment String
| RenameEnvironment String String
| SetEnvironmentCompiler String String
| SetEnvironmentCodeGen String String
| EnvironmentHelp
// TODO: EnvironmentPaths, EnvironmentVersion, EnvironmentProcessor, Environment64BitProcessor
......@@ -54,12 +54,14 @@ import UtilIO
/**
* Clean Platform imports
*/
import CommandLine, Environment, Func, List, Text
import System.CommandLine, System.Environment, System.Directory
import Data.Error, Data.Func, Data.List
import Text
/**
* Clean libraries imports
*/
import StdFile, StdString
import StdFile, StdString, StdMisc
/**
* Start function which reads the program arguments, starts the parser and
......@@ -67,10 +69,13 @@ import StdFile, StdString
*/
Start :: *World -> *World
Start world
# (cmd, world) = getCommandLine world
(pwd, world) = accFiles GetFullApplicationPath world
(ch, world) = case getEnvironmentVariable "CLEAN_HOME" world of
(Just ch, world) -> (ch, world)
(_, world) -> (pwd, world)
= doCpmAction ch pwd (startParse (fromString $ mkCl cmd)) world
# (cmd, world) = getCommandLine world
(mpwd, world) = getCurrentDirectory world
(cpmd, world) = accFiles GetFullApplicationPath world
(ch, world) = case getEnvironmentVariable "CLEAN_HOME" world of
(Just ch, world) -> (ch, world)
(_, world) -> (cpmd, world)
= case mpwd of
Ok pwd -> doCpmAction ch pwd (startParse (fromString $ mkCl cmd)) world
Error e -> abort "Failed to read current directory"
where mkCl cmd = concat (intersperse " " (tl [fromString arg \\ arg <- cmd]))
......@@ -13,7 +13,12 @@ from PmProject import :: Project
/**
* Execute a general CPM action
*/
doCpmAction :: String String .CpmAction *World -> .World
doCpmAction :: String String !.CpmAction !*World -> .World
/**
* Find all project files in the current working directory and build them
*/
doMake :: String !String !*World -> .World
/**
* Execute project-specific actions
......@@ -28,25 +33,29 @@ doProjectPathAction :: .String .String Project .PathAction *World -> .World
/**
* Execute module-related actions
*/
doModuleAction :: .String .String .ModuleAction *World -> .World
doModuleAction :: .String !.String !.ModuleAction !*World -> .World
/**
* Turn a project name into a project filename
*/
mkProjectFile :: !String -> String
/**
* Modify a project
*/
withProject :: String String .(Project -> Project) *World -> .World
withProject :: !String !String .(Project -> Project) *World -> .World
/**
* Collect all project paths in a list with an index prefixed
*/
showPaths :: Project -> .[String]
showPaths :: !Project -> .[String]
/**
* Modify the list of paths in a project given a modification function which
* takes a strict list of project paths and returns a strict list of project
* paths.
*/
doModPaths :: String String Project .([!String!] -> [!String!]) *World -> .World
doModPaths :: !String !String !Project .([!String!] -> [!String!]) *World -> .World
/**
* Open a project file
......@@ -62,18 +71,18 @@ saveProject :: !FilePath !Project !FilePath !*World -> *World
* Remove an item from a strict list at a given index. Abort execution if the
* index is out of bounds.
*/
rmStrictListIdx :: Int u:[!.a!] -> v:[!.a!], [u <= v]
rmStrictListIdx :: !Int u:[!.a!] -> v:[!.a!], [u <= v]
/**
* Move a path at a given index up or down the list of paths. Abort execution
* if the index is out of bounds.
*/
moveStrictListIdx :: .Int .PathDirection .[!a!] -> .[!a!]
moveStrictListIdx :: !.Int .PathDirection .[!a!] -> .[!a!]
/**
* Show an error message
*/
error :: String *World -> .World
error :: !String !*World -> .World
/**
* Show a help message
......
This diff is collapsed.
......@@ -8,7 +8,7 @@ import AbsSyn
/**
* Clean Platform imports
*/
from ParserCombinators import :: Parser, :: CParser, :: ParsResult, :: AltCont, :: XorCont, :: SucCont
from Text.ParserCombinators import :: Parser, :: CParser, :: ParsResult, :: AltCont, :: XorCont, :: SucCont
/**
......
......@@ -13,7 +13,8 @@ import PmEnvironment
/**
* Clean Platform imports
*/
import List, Maybe, ParserCombinators
import Data.List, Data.Maybe
import Text.ParserCombinators
/**
* Clean libraries imports
......@@ -30,7 +31,13 @@ pNotSpace = sp (<+> (satisfy (not o isWhite)))
* Top-level parser for CPM commands
*/
pCpm :: CParser Char CpmAction a
pCpm = pProject <|> pModule <!> (yield CpmHelp)
pCpm = pMake <|> pProject <|> pModule <!> (yield CpmHelp)
/**
* Parse the make command
*/
pMake :: CParser Char CpmAction a
pMake = spstrtok "make" <@ const CpmMake
/**
* Wrapper around the token parser that converts a Clean string to a list of
......@@ -39,27 +46,37 @@ pCpm = pProject <|> pModule <!> (yield CpmHelp)
spstrtok :: (String -> CParser Char [Char] a)
spstrtok = sptoken o fromString
/**
* Parser for boolean values
*/ // TODO: REmove?
//pBool :: CParser Char Bool a
//pBool = pConstCtr [("true", True), ("True", True), ("false", False), ("False", False)]
/**
* Parser for the project commands
*/
pProject :: CParser Char CpmAction a
pProject = spstrtok "project" &> (pProjectWithName <!> yield (Project "" ProjectHelp))
where pProjectWithName = pNotSpace <&> \pn -> pProjectAction <@ Project (toString pn)
pProjectAction = (spstrtok "create" <@ const CreateProject)
<|> (spstrtok "show" <@ const ShowProject)
<|> (spstrtok "build" &> pForce <&> \f -> pIDEEnvs <@ BuildProject f)
<|> (spstrtok "path" &> pPathAction)
//<|> (spstrtok "projectroot" &> pNotSpace <@ SetProjectRoot o toString)
<|> (spstrtok "target" &> identifier <@ SetTarget o toString)
<|> (spstrtok "exec" &> identifier <@ SetExec o toString)
pProjectAction = (spstrtok "create" <@ const CreateProject)
<|> (spstrtok "show" <@ const ShowProject)
<|> (spstrtok "build" &> pForce <&> \f -> pIDEEnvs <@ BuildProject f)
<|> (spstrtok "path" &> pPathAction)
<|> (spstrtok "root" &> pNotSpace <@ SetRelativeRoot o toString)
<|> (spstrtok "target" &> identifier <@ SetTarget o toString)
<|> (spstrtok "exec" &> identifier <@ SetExec o toString)
<!> (pHelp ProjectHelp)
/**
* Parser for the environment commands
*/
pEnvironment :: CParser Char CpmAction a
pEnvironment = spstrtok "environment" &> pEnvironmentAction <@ Environment
where pEnvironmentAction = (spstrtok "list" <@ const ListEnvironments)
<|> (spstrtok "import" &> pNotSpace <@ ImportEnvironment o toString)
<|> (spstrtok "create" &> identifier <@ CreateEnvironment o toString)
<|> (spstrtok "remove" &> identifier <@ RemoveEnvironment o toString)
<|> (spstrtok "show" &> identifier <@ ShowEnvironment o toString)
<|> (spstrtok "export" &> identifier <@ ExportEnvironment o toString)
<|> (spstrtok "rename" &> identifier <&> \en -> identifier <@ RenameEnvironment (toString en) o toString)
<|> (spstrtok "setcompiler" &> identifier <&> \en -> identifier <@ SetEnvironmentCompiler (toString en) o toString)
<|> (spstrtok "setcodegen" &> identifier <&> \en -> identifier <@ SetEnvironmentCodeGen (toString en) o toString)
<!> (pHelp EnvironmentHelp)
/**
* Parser for all path-related actions
*/
......@@ -71,7 +88,8 @@ pPathAction = pPathAction <@ ProjectPath
<|> (spstrtok "move" &> pPathDirection)
<!> (pHelp PathHelp)
pPathDirection = sp nat <&> \i -> pConstCtr dirOpts <@ MovePathAction i
dirOpts = [("up", PathUp), ("down", PathDown), ("top", PathTop), ("bottom", PathBottom)]
dirOpts = [ ("up", MovePathUp), ("down", MovePathDown)
, ("top", MovePathTop), ("bottom", MovePathBottom)]
/**
* Parser for constant mappings between text and constructors
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment