aboutsummaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
authorJoris2015-11-29 13:25:50 +0100
committerJoris2015-11-29 13:25:50 +0100
commitb0f00782ebc9ca6825a6c87b41e5c4888c009a65 (patch)
tree1a2b4e4288c183eb3c0a46a0837c148de6a57206 /src/Model
parent54d944eded3463f7d6a4dc506fc1885d0cac662d (diff)
Authorize comments on birthdates.csv
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 =