Closed mister-walter closed 1 year ago
Thank you for the suggestion.
I decided against recording the start position of every failed parse for performance reasons.
Maybe something can be done for the innermost failed rule. I'll think about it and report back.
Just a heads up - after playing around I discovered I can get this information already by digging into the second level result-detail of the error. This contains a list of the results for the sequence rule, including other successful parses that happened before the failed parse. From this I can get the position of the sequence's "start" character, and I can check that it was parsed successfully.
(esrap::result-detail (esrap::result-detail (esrap:esrap-parse-error-context (handler-case (parse 'numlist "(1, 2, 3") (error (c) c)))))
=>
(#<ESRAP::SUCCESSFUL-PARSE "(" @1> #<ESRAP::SUCCESSFUL-PARSE NATURAL @2>
#<ESRAP::SUCCESSFUL-PARSE # @8> #<ESRAP::FAILED-PARSE ")" @8>)
Not sure how possible this is, but it would be helpful to be able to get the position at which a failed parse rule began. For example, given the rules:
the following line invokes an error:
In this case, it's easy to see where the problem lies because it's all one line, and there's no nesting. However, in cases where the list spans multiple lines, it's often more useful to see the start of the offending list.
I poked around a little bit but couldn't see any built-in way to get this information (the start position of the rule that ended up failing).