summaryrefslogtreecommitdiff
path: root/src/main/frege/buildclient/config/BuildConfig.fr
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/frege/buildclient/config/BuildConfig.fr')
-rw-r--r--src/main/frege/buildclient/config/BuildConfig.fr18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main/frege/buildclient/config/BuildConfig.fr b/src/main/frege/buildclient/config/BuildConfig.fr
index 89be3a7..603f1a8 100644
--- a/src/main/frege/buildclient/config/BuildConfig.fr
+++ b/src/main/frege/buildclient/config/BuildConfig.fr
@@ -42,7 +42,9 @@ expectString :: ASTValue -> Maybe String
expectString (ASTValue.ASTString str) = Just str
expectString _ = Nothing
-
+expectNumber :: ASTValue -> Maybe Int
+expectNumber (ASTValue.ASTNumber num) = Just num
+expectNumber _ = Nothing
data BuildSource = GitSource {upstream :: String, branch :: Maybe String}
@@ -52,8 +54,8 @@ findSource :: ASTDirective -> Either String BuildSource
findSource (ASTDirective _ [ASTWord "git"] block) = do
upstream <- getTypedArg "upstream" "git upstream directive" block expectString
return $ GitSource upstream (getArgDirective "branch" block >>= expectString)
-findSource (ASTDirective _ [ASTWord name] _) = Left ("Unknown source type " ++ name)
-findSource _ = Left "Please provide a source type"
+findSource (ASTDirective _ [ASTWord name] _) = fail ("Unknown source type " ++ name)
+findSource _ = fail "Please provide a source type"
data BuildSystem = GradleBuild { task::String, project :: Maybe String }
@@ -64,9 +66,12 @@ findBuildSystem :: ASTDirective -> Either String BuildSystem
findBuildSystem (ASTDirective _ [ASTWord "gradle"] block) = do
task <- getTypedArg "task" "gradle task" block expectString
return $ GradleBuild task $ (getArgDirective "project" block >>= expectString)
+findBuildSystem _ = fail "Please provide a build system"
parseBuildConfig :: [ASTDirective] -> Either String BuildConfig
parseBuildConfig directives = do
+ version <- getTypedArg "schema" "schema" directives expectNumber
+ when (version != 1) $ fail "Invalid schema version. Needs to be 1"
modid <- getTypedArg "modid" "modid" directives expectString
label <- getTypedArg "label" "label" directives expectString
description <- getTypedArg "description" "description" directives expectString
@@ -75,6 +80,13 @@ parseBuildConfig directives = do
build <- findDirective "build" directives <?> "Please provide a build block" >>= findBuildSystem
return $ BuildConfig modid label description author (getArgDirective "webpresence" directives >>= expectString) source build
+parseBuildConfigStr :: String -> Either String BuildConfig
+parseBuildConfigStr str = reportErr tokens >> (runParser parseFile tokens) >>= parseBuildConfig
+ where reportErr (Token.ERROR position msg:_) = fail ("Error at position " ++ (show position) ++ ": " ++ msg)
+ reportErr (_:as) = reportErr as
+ reportErr _ = return ()
+ tokens = lexer str
+
data BuildConfig = BuildConfig
{ modid :: String
, label :: String