diff options
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 |