<div dir="ltr"><div><div>Hi all,<br><br></div>I'm having trouble with a recursive parsec parser that keeps recursing on one type of end tag and terminates on another type of end tag. I'm sure I'm stuck on something silly, but here's what I have so far.<br><br></div>Git repo with stack/cabal project: <br><br><a href="https://github.com/codygman/megaparsectest/blob/master/library/Example.hs">https://github.com/codygman/megaparsectest/blob/master/library/Example.hs</a><br><br><br><div>Code I have so far (I deleted a few different approaches I tried because I thought they would clutter things up and make it harder to assist me with this issue):<br><br><br>{-# LANGUAGE QuasiQuotes #-}<br>-- | An example module.<br>module Example  where<br><br>import Text.Megaparsec<br>import Text.RawString.QQ<br>import Text.Megaparsec.String -- input stream is of the type ‘String’<br>import qualified Text.Megaparsec.Lexer as L<br>import Control.Monad (void, join)<br><br>ex :: String<br>ex = [r|<br>begin<br>field1 string<br>begin<br>  field11 int<br>  field12 string<br>end subsection; // optional<br>end;<br>|]<br><br>data Field = Field String String deriving Show<br>data Block = Fields [Field] | Block [Field] deriving Show<br><br>sc :: Parser ()<br>sc = L.space (void spaceChar) lineCmnt blockCmnt<br>  where lineCmnt  = L.skipLineComment "//"<br>        blockCmnt = L.skipBlockComment "/*" "*/"<br><br>field :: Parser Field<br>field =  dbg "field" $ do<br>  sc<br>  Field <$> someTill ((oneOf' (['a'..'z'] ++ ['0'..'9']))) spaceChar<br>        <*> some ((oneOf' (['a'..'z'] ++ ['0'..'9'])))<br><br>endEof = do<br>  sc *> string "end" *> char ';' *> sc *> eof<br>  pure ""<br><br>endIdent = do<br>  string "end" *> sc<br>  ident <- someTill ((oneOf' (['a'..'z'] ++ ['0'..'9']))) (char ';')<br>  sc *> eof<br>  pure ident<br><br>block = error "TODO implement"<br><br><br><br><br></div><div>-- Thanks,<br><br></div><div>-- Cody<br></div><div><br></div></div>