Commit ad3dc237 authored by Jurrien Stutterheim's avatar Jurrien Stutterheim
Browse files

BatchBuild: use parser combinators instead of pattern matching

parent 8f165e4d
module BatchBuild
import StdEnv
import StdListExtensions
import ArgEnv
import PmDriver
import PmProject
......@@ -8,39 +9,67 @@ import IdeState
from UtilIO import GetFullApplicationPath,GetLongPathName
import PmEnvironment, logfile, set_return_code
from Platform import application_path
import ParserCombinators
:: BBArgs =
{ force_rebuild :: Bool
, proj_path :: Maybe String
, env_path :: Maybe String }
Start :: *World -> *World
Start world
# commandline = getCommandLine
args = [arg \\ arg <-: commandline]
(path_ok,force_rebuild,proj_path)
= case args of
[_,prj]
-> (True,False,GetLongPathName prj)
[_,"--force",prj]
-> (True,True,GetLongPathName prj)
_
-> (False,False,"")
# (startup,world) = accFiles GetFullApplicationPath world
# envspath = application_path EnvsFileName
# (envs,world) = openEnvironments startup envspath world
// | not ok = wAbort ("Unable to read environments\n") world
| not path_ok = wAbort ("BatchBuild\nUse as: 'BatchBuild [--force] projectname.prj'\n") world
# ((proj,ok,err),world) = accFiles (ReadProjectFile proj_path startup) world
| not ok || err <> "" = wAbort ("BatchBuild failed while opening project: "+++.err+++."\n") world
# (ok,logfile,world) = openLogfile proj_path world
| not ok = wAbort ("BatchBuild failed while opening logfile.\n") world
# default_compiler_options = DefaultCompilerOptions
# iniGeneral = initGeneral True default_compiler_options startup proj_path proj envs logfile
# ps = {ls=iniGeneral,gst_world=world,gst_continue_or_stop=False}
# {ls,gst_world} = pinit force_rebuild ps
= finish gst_world
# commandline = getCommandLine
cl = intersperse " " (tl [arg \\ arg <-: commandline])
args = concat [fromString c \\ c <- cl]
{force_rebuild=force_rebuild, proj_path=proj_path, env_path=env_path} = startPBB args
# (startup,world) = accFiles GetFullApplicationPath world
# envspath = application_path EnvsFileName
# (envs,world) = openEnvironments startup envspath world // TODO: This is where we need to insert the .env file
| isNothing proj_path = wAbort ("BatchBuild\nUse as: 'BatchBuild [--force] projectname.prj [environment.env]'\n") world
# ((proj,ok,err),world) = accFiles (ReadProjectFile (fromJust proj_path) startup) world
| not ok || err <> "" = wAbort ("BatchBuild failed while opening project: "+++.err+++."\n") world
# (ok,logfile,world) = openLogfile (fromJust proj_path) world
| not ok = wAbort ("BatchBuild failed while opening logfile.\n") world
# default_compiler_options = DefaultCompilerOptions
# iniGeneral = initGeneral True default_compiler_options startup (fromJust proj_path) proj envs logfile
# ps = {ls=iniGeneral,gst_world=world,gst_continue_or_stop=False}
# {ls,gst_world} = pinit force_rebuild ps
= finish gst_world
concat :: [[.a]] -> [.a]
concat xss = foldr (++) [] xss
startPBB :: [.Char] -> BBArgs
startPBB args = case filter (\(xs, _) -> xs == []) (begin pBB args) of
[] -> {force_rebuild = False, proj_path = Nothing, env_path = Nothing }
[(_, as)] -> as
pBB :: CParser Char BBArgs BBArgs
pBB = pForce <&> \f -> pProj <&> \p -> pEnv <@ \e -> {force_rebuild = f, proj_path = p, env_path = e}
pForce :: CParser Char Bool BBArgs
pForce = (sptoken (fromString "--force") <@ const True) <!> yield False
pProj :: CParser Char (Maybe String) BBArgs
pProj = pFilename "prj"
pEnv :: CParser Char (Maybe String) BBArgs
pEnv = pFilename "env" <!> yield Nothing
pFilename :: String -> CParser Char (Maybe String) BBArgs
pFilename ext = sp pE
where pE = <*> (satisfy p) <&> \i -> symbol '.' &> token (fromString ext) <@ \e -> Just (toString i +++ toString ['.' : e])
p c = not (c == '.' || isWhite c)
pinit :: .Bool *GeneralSt -> *GeneralSt
pinit force_rebuild ps
= BringProjectUptoDate force_rebuild cleanup ps
where
cleanup exepath bool1 bool2 ps
= abortLog False "" ps
wAbort :: {#.Char} *World -> .World
wAbort message world
// # (console,world) = stdio world
// # console = console <<< message
......@@ -52,4 +81,5 @@ wAbort message world
//finish :: !*World -> String
//finish _ = ""
finish w = w
\ No newline at end of file
finish :: .a -> .a
finish w = w
Supports Markdown
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