diff options
author | Joris | 2016-03-18 09:50:39 +0100 |
---|---|---|
committer | Joris | 2016-03-18 09:50:39 +0100 |
commit | bf804f73ce3494be430054499c5ce18f232f68ca (patch) | |
tree | 6b89c204b9f997d6f6d4134cfaa72ecc6f2234f6 /Data/ConfigManager/Parser.hs | |
parent | 9c3c43835addc950c3af7fab8fd53e24e7e29ad9 (diff) |
Add optional imports
Diffstat (limited to 'Data/ConfigManager/Parser.hs')
-rw-r--r-- | Data/ConfigManager/Parser.hs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Data/ConfigManager/Parser.hs b/Data/ConfigManager/Parser.hs index 856ccfd..b49f586 100644 --- a/Data/ConfigManager/Parser.hs +++ b/Data/ConfigManager/Parser.hs @@ -10,7 +10,7 @@ import Data.Char (isSpace, isAlphaNum) import Text.ParserCombinators.Parsec -import Data.ConfigManager.Expr +import Data.ConfigManager.Types parseConfig :: Text -> Either Text [Expr] parseConfig input = @@ -22,7 +22,10 @@ exprsParser :: Parser [Expr] exprsParser = skip *> many (exprParser <* restOfLine <* skip) <* eof exprParser :: Parser Expr -exprParser = (try bindingParser) <|> (try importParser) +exprParser = + (try bindingParser) + <|> (try $ importParser "import" (Import Required)) + <|> (try $ importParser "importMaybe" (Import Optional)) bindingParser :: Parser Expr bindingParser = do @@ -33,14 +36,14 @@ bindingParser = do value <- valueParser return $ Binding name value -importParser :: Parser Expr -importParser = do - _ <- string "import" +importParser :: String -> (FilePath -> Expr) -> Parser Expr +importParser name exprFromPath = do + _ <- string name _ <- spaces _ <- char '"' path <- many (noneOf "\"") _ <- char '"' - return $ Import path + return $ exprFromPath path nameParser :: Parser Name nameParser = do |