Commit 3fac4b90 authored by Jurrien Stutterheim's avatar Jurrien Stutterheim

Split CPM into separate modules

parent 34910221
definition module AbsSyn
from FilePath import :: FilePath
/**
* Datatypes
*/
:: CpmAction
= Project FilePath ProjectAction
| Module String ModuleAction
| Environment EnvironmentAction
| CpmHelp
:: ProjectAction
= CreateProject
| ShowProject
| BuildProject Bool FilePath
| ProjectPath PathAction
//| SetProjectRoot String TODO: Not yet supported by PmProject
| SetTarget String
| SetExec String
| ProjectHelp
:: PathAction
= AddPathAction String
| RemovePathAction Int
| ListPathsAction
| MovePathAction Int PathDirection
| PathHelp
:: PathDirection
= PathUp
| PathDown
| PathTop
| PathBottom
:: ModuleAction
= CreateModule ModuleType
| ModuleHelp
:: ModuleType
= ApplicationModule
| LibraryModule
:: EnvironmentAction
= ShowEnvironment
implementation module AbsSyn
This diff is collapsed.
definition module CpmLogic
from AbsSyn import :: CpmAction
/**
* Execute a general CPM action
*/
doCpmAction :: String String .CpmAction *World -> .World
This diff is collapsed.
definition module Parser
from AbsSyn import :: CpmAction
startParse :: [.Char] -> CpmAction
implementation module Parser
/**
* CPM imports
*/
import AbsSyn
/**
* CleanIDE imports
*/
import PmEnvironment
/**
* Clean Platform imports
*/
import List, Maybe, ParserCombinators
/**
* Clean libraries imports
*/
import StdFunc, StdTuple
/**
* Parse one or more non-whitespace characters
*/
pNotSpace :: CParser Char [Char] a
pNotSpace = sp (<+> (satisfy (not o isWhite)))
/**
* Top-level parser for CPM commands
*/
pCpm :: CParser Char CpmAction a
pCpm = pProject <|> pModule <!> (yield CpmHelp)
/**
* Wrapper around the token parser that converts a Clean string to a list of
* charactersm for easier parsing
*/
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)
<!> (pHelp ProjectHelp)
/**
* Parser for all path-related actions
*/
pPathAction :: CParser Char ProjectAction a
pPathAction = pPathAction <@ ProjectPath
where pPathAction = (spstrtok "add" &> pNotSpace <@ AddPathAction o toString)
<|> (spstrtok "remove" &> sp nat <@ RemovePathAction)
<|> (spstrtok "list" <@ const ListPathsAction)
<|> (spstrtok "move" &> pPathDirection)
<!> (pHelp PathHelp)
pPathDirection = sp nat <&> \i -> pConstCtr dirOpts <@ MovePathAction i
dirOpts = [("up", PathUp), ("down", PathDown), ("top", PathTop), ("bottom", PathBottom)]
/**
* Parser for constant mappings between text and constructors
*/
pConstCtr :: [(String, c)] -> CParser Char c a
pConstCtr xs = choice (map (\(s, d) -> (spstrtok s <@ const d)) xs)
/**
* Parser to toggle the --force flag
*/
pForce :: CParser Char Bool a
pForce = (spstrtok "--force" <@ const True) <!> (yield False)
/**
* Parser for the argument to specify where the IDEEnvs file is
*/
pIDEEnvs :: CParser Char String a
pIDEEnvs = (spstrtok "--envs" &> (<?> (spsymbol '=')) &> pNotSpace <@ toString)
<!> (yield EnvsFileName)
/**
* Parser for module-related actions
*/
pModule :: CParser Char CpmAction a
pModule = spstrtok "module" &> (pModuleWithName <!> yield (Module "" ModuleHelp))
where pModuleWithName = pNotSpace <&> \mn -> pModuleAction <@ Module (toString mn)
pModuleAction = (spstrtok "create" &> pModuleType <@ CreateModule)
<!> (pHelp ModuleHelp)
pModuleType = (spstrtok "application" <@ const ApplicationModule)
<!> (yield LibraryModule)
/**
* Parser for the help command
*/
pHelp :: c -> CParser Char c a
pHelp c = (spstrtok "help" <@ const c) <|> (yield c)
/**
* Parse the a list of characters to get the action to be executed. If parsing
* fails, CpmHelp is returned as default action so help may be displayed.
*/
startParse :: [.Char] -> CpmAction
startParse args = maybe CpmHelp snd (find (null o fst) (begin pCpm args))
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