aboutsummaryrefslogtreecommitdiff
path: root/Data/ConfigManager/Parser.hs
diff options
context:
space:
mode:
authorJoris2016-03-16 21:09:44 +0100
committerJoris2016-03-16 22:09:54 +0100
commitc6c01d7c248bca1078285c4afeaa25493e9974b3 (patch)
tree7b060664b16ffcae25cb62089dfbeed5a0b7c69a /Data/ConfigManager/Parser.hs
parentf2dc23683ceae93135223713e4ca7fa3a12edbea (diff)
Add import expression
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