<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Tried this:<div class=""><br class=""></div><div class="">```hs</div><div class=""><div style="color: rgb(212, 190, 152); background-color: rgb(23, 24, 24); font-family: Menlo, Monaco, "Courier New", monospace; line-height: 18px; white-space: pre;" class=""><div class=""><span style="color: #d4bfa0;" class="">  findIt </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">do</span></div><div class=""><span style="color: #7e6b5f;" class="">    -- ignore leading whitespaces and an optional semicolon in between</span></div><div class=""><span style="color: #d4bfa0;" class="">    nbsc</span></div><div class=""><span style="color: #d4bfa0;" class="">    ii0 </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> getInput</span></div><div class=""><span style="color: #d4bfa0;" class="">    trace </span>(<span style="color: #97a2a7;" class="">"**about*to*match*semicolon*["</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #73a36c;" class="">T.</span><span style="color: #d4bfa0;" class="">unpack ii0 </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"]"</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> pure </span>()</div><div class=""><span style="color: #d4bfa0;" class="">    optionalSemicolon</span></div><div class=""><span style="color: #d4bfa0;" class="">    trace </span>(<span style="color: #97a2a7;" class="">"**after*semicolon*attempt**"</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> pure </span>()</div><div class=""><span style="color: #d4bfa0;" class="">    nbsc</span></div><div class=""><span style="color: #7e6b5f;" class="">    -- try get a doc comment block</span></div><div class=""><span style="color: #d4bfa0;" class="">    getIt </span><span style="color: #a3d349;" class="">>>=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">\</span><span style="color: #cc524b;" class="">case</span></div><div class=""><span style="color: #d4bfa0;" class=""></span></div></div></div><div class="">```</div><div class=""><br class=""></div><div class="">```console</div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">$ cabal run dcp < samples/basic.txt </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Up to date</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">**about*to*match*semicolon*[{##</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> # this is the module's doc comment</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #}</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""># this is regular line comment to be dropped in parsing</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{## </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> # this is the doc comment for  `doXXX()`</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #}</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">method doXXX() pass</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{#</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> # this is regular block comment to be dropped in parsing</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #}</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">{## </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> # this is the doc comment for  `doYYY()`</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> #}</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">method doYYY() pass</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">]</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">dcp: 10:1:</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">   |</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">10 | method doXXX() pass</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">   | ^</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">unexpected 'm'</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">expecting ';'</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">CallStack (from HasCallStack):</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">  error, called at src/Parser.hs:154:14 in main:Parser</span></div></div><div class="">```</div><div class=""><br class=""></div><div class="">So it seems the very first optionalSemicolon failed without consuming anything ...</div><div class=""><br class=""></div><div class="">And actually I totally have no clue how the content before `method doXXX` is consumed.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 2020-10-25, at 19:26, Jaro Reinders <<a href="mailto:jaro.reinders@gmail.com" class="">jaro.reinders@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I think the optionalSemicolon will consume the '{' of the first comment and then the 'getIt' will produce Nothing because the input doesn't start with '{##' anymore, and then it will go on like that until the optionalSemicolon consumes that 'm'.<br class=""><br class="">On 10/25/20 12:21 PM, YueCompl wrote:<br class=""><blockquote type="cite" class="">The rerun is guarded behind an optional `L.skipBlockCommentNested "{#" "#}"` got a `Just{}` result, and only after `getIt` got a `Nothing` result.<br class=""><blockquote type="cite" class="">On 2020-10-25, at 19:16, Jaro Reinders <<a href="mailto:jaro.reinders@gmail.com" class="">jaro.reinders@gmail.com</a>> wrote:<br class=""><br class="">But the 'findIt' parser will be rerun after every block comment right?<br class=""><br class="">On 10/25/20 12:10 PM, YueCompl wrote:<br class=""><blockquote type="cite" class="">Unlike `sc`, `nbsc` won't consume block comments, as it's defined as `L.space space1 (L.skipLineComment "#") empty`<br class=""><blockquote type="cite" class="">On 2020-10-25, at 19:07, Jaro Reinders <<a href="mailto:jaro.reinders@gmail.com" class="">jaro.reinders@gmail.com</a>> wrote:<br class=""><br class="">But in the basic.txt example, won't the first nbsc consume everything up to 'method doXXX() pass'. Then the semicolon parser consumes the 'm' character, and that will never backtrack. So that 'm' character is lost.<br class=""><br class="">On 10/25/20 12:00 PM, YueCompl wrote:<br class=""><blockquote type="cite" class="">During the parsing of doc comments, backtracking is off on purpose, as it won't consume syntactic contents, merely whitespaces (while doc comment is a special form of block comment), the desired result is `Nothing` or `Just docCmt` without backtracking of whitespaces.<br class=""><blockquote type="cite" class="">On 2020-10-25, at 18:53, Jaro Reinders <<a href="mailto:jaro.reinders@gmail.com" class="">jaro.reinders@gmail.com</a>> wrote:<br class=""><br class="">I think you have to insert a 'try' manually inside the optional, because megaparsec doesn't do backtracking by default.<br class=""><br class="">On 10/25/20 11:27 AM, YueCompl via Haskell-Cafe wrote:<br class=""><blockquote type="cite" class="">Dear Cafe,<br class="">I find myself unable to reason about an error that `optional` in a parser err out instead of return Nothing, I asked the question at StackOverflow, and would like to seek your help here as well.<br class=""><a href="https://stackoverflow.com/questions/64522568/why-optional-in-a-parser-can-err-out" class="">https://stackoverflow.com/questions/64522568/why-optional-in-a-parser-can-err-out</a> <<a href="https://stackoverflow.com/questions/64522568/why-optional-in-a-parser-can-err-out" class="">https://stackoverflow.com/questions/64522568/why-optional-in-a-parser-can-err-out</a>><br class=""><a href="https://github.com/complyue/dcp" class="">https://github.com/complyue/dcp</a> <<a href="https://github.com/complyue/dcp" class="">https://github.com/complyue/dcp</a>> is a minimum working example to reprod this error<br class="">$ cabal run dcp:dcp < samples/basic.txt<br class="">Up to date<br class="">dcp: 10:1:<br class="">    |<br class="">10 | method doXXX() pass<br class="">    | ^<br class="">unexpected 'm'<br class="">expecting ';'<br class="">CallStack (from HasCallStack):<br class="">   error, called at src/Parser.hs:149:14 in main:Parser<br class="">$<br class="">I believe it's optionalSemicolon causing the failure:<br class=""><a href="https://github.com/complyue/dcp/blob/1df7ad590d78d4fa9a017eb53f9f265e291bdfa7/src/Parser.hs#L50-L54" class="">https://github.com/complyue/dcp/blob/1df7ad590d78d4fa9a017eb53f9f265e291bdfa7/src/Parser.hs#L50-L54</a> <<a href="https://github.com/complyue/dcp/blob/1df7ad590d78d4fa9a017eb53f9f265e291bdfa7/src/Parser.hs#L50-L54" class="">https://github.com/complyue/dcp/blob/1df7ad590d78d4fa9a017eb53f9f265e291bdfa7/src/Parser.hs#L50-L54</a>><br class="">   findIt = do<br class="">     -- ignore leading whitespaces and an optional semicolon in between<br class="">     nbsc >> optionalSemicolon >> nbsc<br class="">     -- try get a doc comment block<br class="">     getIt >>= \case<br class="">And it's defined like this: <a href="https://github.com/complyue/dcp/blob/1df7ad590d78d4fa9a017eb53f9f265e291bdfa7/src/Parser.hs#L31-L32" class="">https://github.com/complyue/dcp/blob/1df7ad590d78d4fa9a017eb53f9f265e291bdfa7/src/Parser.hs#L31-L32</a> <<a href="https://github.com/complyue/dcp/blob/1df7ad590d78d4fa9a017eb53f9f265e291bdfa7/src/Parser.hs#L31-L32" class="">https://github.com/complyue/dcp/blob/1df7ad590d78d4fa9a017eb53f9f265e291bdfa7/src/Parser.hs#L31-L32</a>><br class="">optionalSemicolon :: Parser Bool<br class="">optionalSemicolon = fromMaybe False <$> optional (True <$ symbol ";")<br class="">I can't reason about why it can fail like this.<br class="">Best regards,<br class="">Compl<br class="">_______________________________________________<br class="">Haskell-Cafe mailing list<br class="">To (un)subscribe, modify options or view archives go to:<br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="">Only members subscribed via the mailman list are allowed to post.<br class=""></blockquote>_______________________________________________<br class="">Haskell-Cafe mailing list<br class="">To (un)subscribe, modify options or view archives go to:<br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="">Only members subscribed via the mailman list are allowed to post.<br class=""></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></div></div></blockquote></div><br class=""></div></body></html>