Greetings. I'd like to write a parser that takes some Haskell source code and seperates it into two piles - comments, and everything else. I have a parser that recognises single-line comments, and another that recognises multi-line comments. What I'd like to do is make a big parser that returns [Either String String], which all the comments in one side and all the rest in the other side. But I can't figure out how to construct such a parser... Any hints?
Andrew Coppin <andrewcoppin@btinternet.com> writes:
I have a parser that recognises single-line comments, and another that recognises multi-line comments. What I'd like to do is make a big parser that returns [Either String String], which all the comments in one side and all the rest in the other side. But I can't figure out how to construct such a parser... Any hints?
wholething = many comment comment = do fmap Left $ (linecomment `onFail` nestedcomment) `onFail` fmap Right $ noncomment
Malcolm Wallace wrote:
Andrew Coppin <andrewcoppin@btinternet.com> writes:
Any hints?
wholething = many comment
comment = do fmap Left $ (linecomment `onFail` nestedcomment) `onFail` fmap Right $ noncomment
Haskell: The language of truely scary people(tm) :-} Thanks, I'll give that a go...
participants (2)
-
Andrew Coppin -
Malcolm Wallace