typelevel/cats-parse

Backtracking with context

Opened this issue · 1 comments

Hi everyone. So i am having this list of parsers in my parser for each case it could possibly have (there is also a recursive parser above which uses this list of parsers for each next node and a lot of simple parsers inside each):

parser1.withContext("parser 1").backtrack | 
  parser2.withContext("parser 2").backtrack |
  parser3.withContext("parser 3")

The problem is - i never getting any context except of "parser 3". I wonder if there is some trick to get output like:

Left(Error(4,NonEmptyList(
  WithContext(parser 2, 
    WithContext(parser 3,EndOfString(4,27))
  )
)))

Can you make a PR with a test with a minimal example that you expect to pass so we can look at something concrete?

I think you should get contexts from all 3 if you fail to parse. Glancing at the code again, that should be what happens.

Can you show a more complete failure (with code, input, and error message)?