Haskell Parse Paragraph and em element with Parsec?

This is a hack, but I think it does what you want: list = (:) text = many (try em (anyChar >>= return . List)) >>= return . (""++) .(++"") .

Concat (Each non-emphasised character is return as its own string. ) Here's how it works: At each char, first try to parse em This starts with two dashes. Since em can fail after consuming a single dash, as in "a-b", you need to prefix it with try If dashes are not allowed in the rest of the input, you don't need the try, but this is probably not the case.

Otherwise, consume anyChar. But this is of type Char not String so it has to be wrapped in a list This returns a list of single-character strings with emphasised sections interleaved. But you want a single string surrounded by p tags, so you first concat then add the start/end tags to the beginning/end.

Then you return that value There is probably a way to rewrite this whole parser so that instead of anyChar you consume input until you see two dashes. But I'm not sure how to write that off the top of my head, so instead you get this hack, which is probably a lot less efficient.

This is a hack, but I think it does what you want: list = (:) text = many (try em (anyChar >>= return . List)) >>= return . (""++) .(++"") .

Concat (Each non-emphasised character is return as its own string. ) Here's how it works: At each char, first try to parse em. This starts with two dashes.

Since em can fail after consuming a single dash, as in "a-b", you need to prefix it with try. If dashes are not allowed in the rest of the input, you don't need the try, but this is probably not the case. Otherwise, consume anyChar.

But this is of type Char, not String, so it has to be wrapped in a list. This returns a list of single-character strings with emphasised sections interleaved. But you want a single string surrounded by p tags, so you first concat, then add the start/end tags to the beginning/end.

Then you return that value. There is probably a way to rewrite this whole parser so that instead of anyChar you consume input until you see two dashes. But I'm not sure how to write that off the top of my head, so instead you get this hack, which is probably a lot less efficient.

Thanks! But when I try to parse, returns me an error: Undefined variable "list" – Martin Apr 25 '10 at 15:35 Oops. That's part of my personal utility library, and I forgot.

I added the definition. – Nathan Sanders Apr 25 '10 at 19:19 Thanks Nathan! , I still have the problem of get the element – Martin Apr 25 '10 at 21:12.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions