[Haskell-beginners] Parsec, comma sperated list with special last element

Nathan Hüsken nathan.huesken at posteo.de
Tue Dec 18 09:58:45 CET 2012


I tried

file = do
  res <- endBy (try cell) (char ',')
  l   <- lastCell
  eof
  return res

cell = many1 (noneOf ",")
lastCell = many1 (noneOf "\n")

But that does not work because cell succeeds on the last cell.
I can replace the endBy by

many (try $ do {a <- cell; string ","; return a})

Nathan

On 12/18/2012 08:21 AM, Karl Voelker wrote:
> On Mon, Dec 17, 2012 at 2:28 AM, Nathan Hüsken <nathan.huesken at posteo.de>wrote:
> 
>> Still ... I can not do it with "endBy", can I?
>>
> 
> I think you can. What have you tried with endBy that didn't work?
> 
> -Karl
> 




More information about the Beginners mailing list