aboutsummaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/BirthdateParser.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Model/BirthdateParser.hs b/src/Model/BirthdateParser.hs
index 8e8489b..9bed07a 100644
--- a/src/Model/BirthdateParser.hs
+++ b/src/Model/BirthdateParser.hs
@@ -8,8 +8,10 @@ import Control.Arrow (left)
import Data.Text (Text)
import qualified Data.Text as T
+import Data.Maybe (catMaybes)
import Text.ParserCombinators.Parsec
+import Text.Parsec.Char (endOfLine)
import Model.Birthdate
import Model.Date
@@ -32,7 +34,19 @@ validateBirthdates birthdates =
]
birthdatesParser :: Parser [Birthdate]
-birthdatesParser = many (many newline >> birthdateParser <* many newline)
+birthdatesParser = catMaybes <$> many lineParser
+
+lineParser :: Parser (Maybe Birthdate)
+lineParser =
+ (Just <$> birthdateParser <* endOfLine)
+ <|> (emptyLine >> return Nothing)
+ <|> (commentLine >> return Nothing)
+
+emptyLine :: Parser ()
+emptyLine = skipMany (char ' ') >> endOfLine >> return ()
+
+commentLine :: Parser Text
+commentLine = T.strip . T.pack <$> (spaces *> char '#' *> many (noneOf "\n") <* endOfLine)
birthdateParser :: Parser Birthdate
birthdateParser =