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

BatchBuild: use parser combinators instead of pattern matching

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