[Haskell-cafe] simple parsec question
S. Doaitse Swierstra
doaitse at swierstra.net
Tue Mar 5 10:34:14 CET 2013
Maybe this is something you do not even want to use a parser combinator library for. The package
http://hackage.haskell.org/packages/archive/list-grouping/0.1.1/doc/html/Data-List-Grouping.html
contains a function breakBefore, so you can write
main = do inp <- readFile ...
let result = map mkSection . breakBefore ((= ':').last)). lines $ inp
mkSection (l:ll) = Section (Top l) (Contents ll)
Doaitse
On Mar 3, 2013, at 16:44 , Immanuel Normann <immanuel.normann at googlemail.com> wrote:
> Hi,
>
> I am trying to parse a semi structured text with parsec that basically should identify sections. Each section starts with a headline and has an unstructured content - that's all. For instance, consider the following example text (inside the dashed lines):
>
> ---------------------------
>
> top 1:
>
> some text ... bla
>
> top 2:
>
> more text ... bla bla
>
>
> ---------------------------
>
> This should be parsed into a structure like this:
>
> [Section (Top 1) (Content "some text ... bla"), Section (Top 1) (Content "more text ... bla")]
>
> Say, I have a parser "headline", but the content after a headline could be anything that is different from what "headline" parses.
> How could the "section" parser making use of "headline" look like?
> My idea would be to use the "manyTill" combinator, but I don"t find an easy solution.
>
> Many thanks for any hint
>
> Immanuel
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list