blob: 1e4051be810cfc897af86154bcbaf8b71c9a684c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
module BirthdateParser
( parseBirthdates
) where
import Control.Arrow (left)
import Data.Text (Text)
import qualified Data.Text as T
import Text.ParserCombinators.Parsec
import Birthdate
import Date
parseBirthdates :: Text -> Either Text [Birthdate]
parseBirthdates input =
left
(T.pack . show)
(parse birthdatesParser "" (T.unpack input))
birthdatesParser :: Parser [Birthdate]
birthdatesParser = many (many newline >> birthdateParser <* many newline)
birthdateParser :: Parser Birthdate
birthdateParser =
Birthdate <$>
dateParser <* spaces <* char ',' <*>
valueParser <* char ',' <*>
valueParser
valueParser :: Parser Text
valueParser = T.strip . T.pack <$> many (noneOf ",\n")
dateParser :: Parser Date
dateParser =
Date <$>
integerParser <* spaces <*>
monthParser <* spaces <*>
integerParser
integerParser :: Parser Int
integerParser = (read :: String -> Int) <$> many1 digit
monthParser :: Parser Int
monthParser =
(try $ string "Janvier" >> return 1)
<|> (try $ string "Février" >> return 2)
<|> (try $ string "Mars" >> return 3)
<|> (try $ string "Avril" >> return 4)
<|> (try $ string "Mai" >> return 5)
<|> (try $ string "Juin" >> return 6)
<|> (try $ string "Juillet" >> return 7)
<|> (try $ string "Août" >> return 8)
<|> (try $ string "Septembre" >> return 9)
<|> (try $ string "Octobre" >> return 10)
<|> (try $ string "Novembre" >> return 11)
<|> (try $ string "Décembre" >> return 12)
|