Guest User

Untitled

a guest
Apr 21st, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. -- 7
  2. data CalendarProp = Prodid String | Version deriving (Show, Eq)
  3. data Calendar = Calendar CalendarProp CalendarProp [Event] deriving (Show, Eq)
  4. data Event = Event [EventProp] deriving (Show, Eq)
  5. data EventProp = Dtstamp DateTime | Dtstart DateTime | Uid String | Dtend DateTime | Description String | Summary String | Location String deriving (Show, Eq)
  6.  
  7. -- 8
  8. pEndLine = token "\n"
  9. pString = greedy (satisfy (/='\n'))
  10. pDtstamp = token "DTSTAMP:" *> (Dtstamp <$> parseDateTime) <* pEndLine
  11. pDtstart = token "DTSTART:" *> (Dtstart <$> parseDateTime) <* pEndLine
  12. pDtend = token "DTEND:" *> (Dtend <$> parseDateTime) <* pEndLine
  13. pUid = token "UID:" *> (Uid <$> pString) <* pEndLine
  14. pDescription = token "DESCRIPTION:" *> (Description <$> pString) <* pEndLine
  15. pSummary = token "SUMMARY:" *> (Summary <$> pString) <* pEndLine
  16. pLocation = token "LOCATION:"*> (Location <$> pString) <* pEndLine
  17. pProdid = token "PRODID:" *> (Prodid <$> pString) <* pEndLine
  18. pVersion = token "VERSION:" *> (Version <$ token "2.0") <* pEndLine
  19. pCalProp = pVersion <|> pProdid
  20. pEventProp :: Parser Char EventProp
  21. pEventProp = pDtstamp <|> pDtstart <|> pDtend <|> pUid <|> pDescription <|> pSummary <|> pLocation
  22. pEventProps :: Parser Char [EventProp]
  23. pEventProps = many pEventProp
  24.  
  25. pEventProps2 :: Parser Char Event
  26. pEventProps2 = Event <$> many pEventProp
  27. pEvent :: Parser Char Event
  28. pEvent = Event <$ token "BEGIN:VEVENT:\n" *> pEventProps <* token "END:VEVENT\n"
  29. pEvents = many pEvent
  30. pCalendar = Calendar <$> pCalProp <*> pCalProp <*> pEvents
  31.  
  32. parseCalendar :: Parser Char Calendar
  33. parseCalendar = token "BEGIN:VCALENDAR\n" *> pCalendar <* token "END:VCALENDAR\n"
  34.  
  35. eS = "BEGIN:VEVENT\nUID:19970610T172345Z-AF23B2@example.com\nDTSTAMP:19970610T172345Z\nDTSTART:19970714T170000Z\nDTEND:19970715T040000Z\nSUMMARY:Bastille Day Party\nEND:VEVENT\n"
  36. ePS2 = "BEGIN:VEVENT\nUID:19970610T172345Z-AF23B2@example.com\nDTSTAMP:19970610T172345Z\nDTSTART:19970714T170000Z\nDTEND:19970715T040000Z\nSUMMARY:Bastille Day Party\n"
  37. ePS = "UID:19970610T172345Z-AF23B2@example.com\nDTSTAMP:19970610T172345Z\nDTSTART:19970714T170000Z\nDTEND:19970715T040000Z\nSUMMARY:Bastille Day Party\n"
Add Comment
Please, Sign In to add comment