diff options
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | src/Model/BirthdateParser.hs | 16 |
2 files changed, 21 insertions, 4 deletions
@@ -10,11 +10,14 @@ Usage Create birthdates.csv which stores birthdates: ``` -23 Oct 1982, Katie, Clarke +# Family 30 Jan 1955, Henry, Brown 08 May 1980, Alexander, Khan + +# Friends 02 Aug 1976, Violet, Koval 02 Aug 1976, Jude, Martinez +23 Oct 1982, Katie, Clarke … ``` @@ -48,5 +51,5 @@ is an example notification with 3 birthdays today and 2 birthdays next week: ### Mail body “Today, Katie Clarke is 19 years old, Henry Brown is 34 years old and Alexander -Khan is 22 years old. Next week, Violet Koval will be 65 years old and Jude -Martinez will be 12 years old.” +Khan is 22 years old. Next week, Violet Koval will be 65 years old on thirsday +and Jude Martinez will be 12 years old on friday.” 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 = |