<div dir="ltr"><div><div>I think you are right, this is probably the right track. A little more googling with permutation parsers gave me this, which is also about parsing iCal using parsec:<br><a href="http://stackoverflow.com/questions/3706172/haskell-parsec-and-unordered-properties">http://stackoverflow.com/questions/3706172/haskell-parsec-and-unordered-properties</a><br>
<br></div>I'll review all this and see if that solves the problem... Thank you!<br><br></div>Emmanuel<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Dec 25, 2012 at 3:28 AM, Brent Yorgey <span dir="ltr"><<a href="mailto:byorgey@seas.upenn.edu" target="_blank">byorgey@seas.upenn.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Emmanuel,<br>
<br>
Sounds like you want a permutation parser, perhaps? Check out<br>
<br>
<a href="http://hackage.haskell.org/packages/archive/parsec/latest/doc/html/Text-Parsec-Perm.html" target="_blank">http://hackage.haskell.org/packages/archive/parsec/latest/doc/html/Text-Parsec-Perm.html</a><br>
<br>
-Brent<br>
<div><div class="h5"><br>
On Tue, Dec 25, 2012 at 12:18:37AM +0100, Emmanuel Touzery wrote:<br>
> Hi,<br>
><br>
> I'm trying to parse ical files but the source material doesn't matter<br>
> much. First, I know there is an icalendar library on hackage, but I'm<br>
> trying to learn as well through this.<br>
><br>
> Now the format is really quite simple and actually I'm parsing it, it<br>
> works, but I don't like the code I'm writing, it feels wrong and I'm sure<br>
> there is a better way. Actually for now I'm parsing it to an array of<br>
> arrays, but I want to fill a proper "data" structure.<br>
><br>
> For my purpose the file contains a bunch of records like this:<br>
><br>
> BEGIN:VEVENT<br>
> DTSTART:20121218T103000Z<br>
> DTEND:20121218T120000Z<br>
> [..]<br>
> DESCRIPTION:<br>
> [..]<br>
> END:VEVENT<br>
><br>
> There are a bunch of records I don't care about and also I want to parse no<br>
> matter what is the order of directives (so, i want to parse also if DTEND<br>
> appears before DTSTART for instance, and so on).<br>
><br>
> That last part is my one problem. I can't do:<br>
><br>
> parseBegin<br>
> start <- parseStart<br>
> end <- parseEnd<br>
> skipRows<br>
> desc <- parseDesc<br>
> skipRows<br>
> end <- parseEnd<br>
> return Event { eventStart = start, eventEnd = end ...}<br>
><br>
> my current working code is:<br>
><br>
> parseEvent = do<br>
> parseBegin<br>
> contents <- many1 $ (try startDate)<br>
> <|> (try endDate)<br>
> <|> (try description)<br>
> <|> unknownCalendarInfo<br>
> parseEnd<br>
> return contents<br>
><br>
> But then contents of course returns an array, while I want to return only<br>
> one element here.<br>
><br>
> SOMEHOW what I would like is:<br>
><br>
> parseEvent = do<br>
> parseBegin<br>
> contents <- many1 $ (start <- T.try startDate)<br>
> <|> (end <- T.try endDate)<br>
> <|> (desc <- T.try description)<br>
> <|> unknownCalendarInfo<br>
> parseEnd<br>
> return Event { eventStart = start, eventEnd = end ...}<br>
><br>
> But obviously as far as Parsec is concerned startDate could occur several<br>
> times and also it's just not valid Haskell syntax.<br>
><br>
> So, any hint about this problem? Parsing multi-line records with Parsec,<br>
> when I don't know the order in which the lines will appear? I mean sure I<br>
> can convert my array to the proper data structure... I find which element<br>
> in the array contains the start date and then which contains the end<br>
> date... and build my data structure.. But I'm sure something much nicer can<br>
> be done... I just can't find how.<br>
><br>
> I see the author of iCalendar fixed the problem but I can't completely<br>
> understand his source, it's too many things at the same time for me, I need<br>
> to take this one step at a time.<br>
><br>
> Thank you!<br>
><br>
> Emmanuel<br>
<br>
</div></div>> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br>
<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>