Parsec: No newline after last line and 'many'

Daan Leijen daan@cs.uu.nl
Mon, 8 Apr 2002 13:36:36 +0200


Hi Till,

My guess is that you want to break up a text file into
a list of lines with Parsec. (ie. "lines" functionality).
A text file consists of non-newline characters seperated by
newline characters:

> import Parsec
>
> plines :: Parser [String]
> plines  = (many (noneOf "\n")) `sepBy` newline

You don't need any "try" or "manyTill" here. It seems to 
work on my system but I haven't tested it exhaustively.

> TestLine> parseTest linep ("hi\nTill")
> ["hi","Till"]
> 
> TestLine> parseTest linep ("hi\nTill\n")
> ["hi","Till",""]
> 
> TestLine> parseTest linep ("hi\n\nTill\n")
> ["hi","","Till",""]

I hope this helps, 
All the best,
    Daan.


----- Original Message ----- 
From: "Till Doerges" <till@doerges.net>
To: <haskell@haskell.org>
Sent: Sunday, April 07, 2002 11:04 PM
Subject: Re: Parsec: No newline after last line and 'many'


> On Sun, Apr 07, 2002 at 07:44:42PM +0200, Till Doerges wrote:
> 
> > Eventually I want to be able to use my parser 'linep' with 'many' on
> > no matter which text-files.
> 
> 'manyTill linep eof' and is what I wanted (looking at my first name, I
> should have gotten that one earlier... ;-)
> 
> Bye -- Till
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell
> 
>