I am following this tutorial for implementing Parser Combinators (a la parsec) in Haskell. I implemented everything of the NanoParsec mentioned throught this post.
For some hours now, I am struggeling to implement
-- try p. If p fails continue without consuming anything try :: Parser a -> Parser a try p = ... -- Parser for everything, until the character-sequence stop appears. -- If stop does not appear at all: fail untilStop :: String -> Parser String untilStop stop = ...
My best attempt to implement
untilStop looks like somewhat like this and does not quite work
untilStop :: String -> Parser String untilStop (c : cs) = do s <- some $ satisfy (/= d) string (c : cs) <|> do i <- item untilStop (d : ds) -- maybe use msum from MonadPlus to combine?
I could not figure out how to combine
i and the recursive call without failing everthing because of
string are not getting everything together.
I think once I have
untilStop should be straightforward. Can someone point me in the right direction or implement it (
try) for me?
Right now I am still learning about Monads, Applicative and related stuff so trying to understand the sourcecode of parsec was impossible for me.