Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Parsec, comma sperated list with special last element
(Nathan H?sken)
----------------------------------------------------------------------
Message: 1
Date: Mon, 17 Dec 2012 11:28:22 +0100
From: Nathan H?sken <[email protected]>
Subject: Re: [Haskell-beginners] Parsec, comma sperated list with
special last element
To: Karl Voelker <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 12/17/2012 07:45 AM, Karl Voelker wrote:
(...)
>
> Using endBy is not the problem. There are many different solutions:
>
> 1. Factor out the common prefix of cell and lastCell, and restructure the
> file parser to avoid committing to either cell or lastCell until the next
> input symbol is one which definitively identifies which alternative the
> parser is looking at.
>
> 2. Replace cell and lastCell with a single parser that matches either one.
> Parse out a list of cellOrLastCell results and then do some post-processing
> to treat the last one specially.
>
> 3. Use the "try" combinator. You apply this combinator to a parser, and get
> back a parser which consumes no input if it fails. When using this
> combinator, you should consider whether this will have an unacceptable
> impact on the performance of your parser. (Performance is one of the
> reasons Parsec does not just backtrack automatically.)
Ok, I would choose 3 because performance is not the issue and it seems
to be the most simple.
Still ... I can not do it with "endBy", can I? Do it so:
file = do
res <- many $ try (do {c <- cell; char ','; return c})
l <- lastCell
eof
return res
cell = many1 (noneOf ",")
lastCell = many1 (noneOf "\n")
works. But I wonder if I also could have used a clearer combinator from
parsec.
Regards,
Nathan
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 54, Issue 24
*****************************************