parsley icon indicating copy to clipboard operation
parsley copied to clipboard

UnionMatcher doesn't add possible matches when throwing on ambiguity

Open hugoduncan opened this issue 12 years ago • 4 comments

When the UnionMatcher throws due to ambiguous match, the possible matches are not added to the exception, which makes it harder than necessary to debug parsers for this case.

hugoduncan avatar May 31 '12 16:05 hugoduncan

Hugo how is the error message in the brand new Parsley v0.9.0 -- not great I expect.

On Thu, May 31, 2012 at 6:31 PM, Hugo Duncan < [email protected]

wrote:

When the UnionMatcher throws due to ambiguous match, the possible matches are not added to the exception, which makes it harder than necessary to debug parsers for this case.


Reply to this email directly or view it on GitHub: https://github.com/cgrand/parsley/issues/3

Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (en)

cgrand avatar May 31 '12 17:05 cgrand

Looks like I get:

nth not supported on this type: Boolean
(def ambiguous-parser
  (parser
   :expr #{#"Abc" #"Ade"}))
(clojure.pprint/pprint (ambiguous-parser "A"))

Edit: Not sure what I was testing above...

hugoduncan avatar May 31 '12 17:05 hugoduncan

0.9.0 reports the matcher functions that give ambiguous matches - is this what you intended?

I was expecting to see something like (pr-str (filter identity (map #(% s eof) matchers)))

hugoduncan avatar May 31 '12 20:05 hugoduncan

I reverted my modification and push a 0.9.1 out of the door (I should never commit in a hurry, even if I have to get off the train :-))

I don't know how to make the message more informative without more widespread changes: a successful matcher returns: the number of characters matched and the (usually) numerical id of the original matcher which are not that helpful when you have two conflicting regexes. Am I overlooking something there?

cgrand avatar Jun 01 '12 12:06 cgrand