phrase icon indicating copy to clipboard operation
phrase copied to clipboard

phrasing error in recursive s/cat

Open ioRekz opened this issue 6 years ago • 3 comments

I think this is as much a question on spec that it is on phrase but I need the right :problem in order to display the message I want.

Here is a gist https://gist.github.com/ioRekz/5b9ae3f1b424eaf1a6256e082d1ad904

I'm close to achieve what I want but the last bit at the bottom is preventing me to achieve the goals

ioRekz avatar Jan 22 '18 10:01 ioRekz

I see your point. Please give me some time to work through your gist.

alexanderkiel avatar Jan 25 '18 08:01 alexanderkiel

@alexanderkiel did you have any chance to think about this ? I am facing the same problem. Thanks!

marco-m avatar Jul 11 '18 16:07 marco-m

I suppose that this is an equivalent minimal example:

(s/def ::hiccup-exp
    (s/spec
      (s/cat
        :tag #{:div}
        :attrs (s/? map?)
        :content (s/* (s/alt :exp ::hiccup-exp :text string?)))))

(s/explain-data ::hiccup-exp [:div "a"])
;;=> nil

(s/explain-data ::hiccup-exp [:a "a"])
;;=> ... :pred #{:div} ...

(s/explain-data ::hiccup-exp [:div [:a "a"]])
;;=> ... :reason "Extra input", :pred (clojure.spec.alpha/cat ...

I have no idea why spec works this way. Phrase depends on "nice" pred's in spec problems. I'll leave the issue open and would be happy if someone could debug spec in for this example.

alexanderkiel avatar Jul 16 '18 17:07 alexanderkiel