cgrand / parsley

a DSL for creating total and truly incremental parsers in Clojure
200 stars 24 forks source link

UnionMatcher doesn't add possible matches when throwing on ambiguity #3

Open hugoduncan opened 12 years ago

hugoduncan commented 12 years ago

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.

cgrand commented 12 years ago

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 < reply@reply.github.com

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)

hugoduncan commented 12 years ago

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 commented 12 years ago

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)))

cgrand commented 12 years ago

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?