diff options
author | Joris | 2015-11-29 13:25:50 +0100 |
---|---|---|
committer | Joris | 2015-11-29 13:25:50 +0100 |
commit | b0f00782ebc9ca6825a6c87b41e5c4888c009a65 (patch) | |
tree | 1a2b4e4288c183eb3c0a46a0837c148de6a57206 /src/Model | |
parent | 54d944eded3463f7d6a4dc506fc1885d0cac662d (diff) |
Authorize comments on birthdates.csv
Diffstat (limited to 'src/Model')
-rw-r--r-- | src/Model/BirthdateParser.hs | 16 |
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 = |