aboutsummaryrefslogtreecommitdiff
path: root/Data/ConfigManager/Parser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Data/ConfigManager/Parser.hs')
-rw-r--r--Data/ConfigManager/Parser.hs30
1 files changed, 20 insertions, 10 deletions
diff --git a/Data/ConfigManager/Parser.hs b/Data/ConfigManager/Parser.hs
index e2329b6..856ccfd 100644
--- a/Data/ConfigManager/Parser.hs
+++ b/Data/ConfigManager/Parser.hs
@@ -6,31 +6,41 @@ module Data.ConfigManager.Parser
import Data.Text (Text)
import qualified Data.Text as T
-import qualified Data.HashMap.Strict as M
import Data.Char (isSpace, isAlphaNum)
import Text.ParserCombinators.Parsec
-import Data.ConfigManager.Config (Config(..))
-import Data.ConfigManager.Types
+import Data.ConfigManager.Expr
-parseConfig :: Text -> Either Text Config
+parseConfig :: Text -> Either Text [Expr]
parseConfig input =
- case parse bindingsParser "" (T.unpack (T.concat [input, "\n"])) of
- Right bindings -> Right . Config . M.fromList $ bindings
+ case parse exprsParser "" (T.unpack (T.concat [input, "\n"])) of
+ Right exprs -> Right exprs
Left parserError -> Left . T.pack . show $ parserError
-bindingsParser :: Parser [Binding]
-bindingsParser = skip *> many (bindingParser <* restOfLine <* skip) <* eof
+exprsParser :: Parser [Expr]
+exprsParser = skip *> many (exprParser <* restOfLine <* skip) <* eof
-bindingParser :: Parser Binding
+exprParser :: Parser Expr
+exprParser = (try bindingParser) <|> (try importParser)
+
+bindingParser :: Parser Expr
bindingParser = do
name <- nameParser
_ <- spaces
_ <- char '='
_ <- spaces
value <- valueParser
- return (name, value)
+ return $ Binding name value
+
+importParser :: Parser Expr
+importParser = do
+ _ <- string "import"
+ _ <- spaces
+ _ <- char '"'
+ path <- many (noneOf "\"")
+ _ <- char '"'
+ return $ Import path
nameParser :: Parser Name
nameParser = do