Fork me on GitHub
#malli
<
2021-12-27
>
ikitommi16:12:05

@nbtheduke bumped into that myself. Need to add proper support for the Keyword argument functions now also accept maps. Could you write an issue of that?

Noah Bogart16:12:49

Yep, I can open an issue for it

ikitommi17:12:44

is there a full spec for clojure destructuring?

ikitommi17:12:33

seems to be that need to add something like :every and the merge of :map and :map-of to get proper support for parsing Clojure syntax.

ikitommi17:12:23

naive 30min parser for extended Plumatic Schama defn syntax:

(m/parse
 Bind
 '[a :- :int
   [b :- :int [c :- :string :as d :- [:vector :any]] & e :as f]
   & {:keys [g h] :as i} :- [:map [:g :int] [:h :int]]])
;{:args [{:arg {:sym a}
;         :- :-
;         :schema :int}
;        {:arg {:vec {:elems [{:arg {:sym b}
;                              :- :-
;                              :schema :int}
;                             {:arg {:vec {:elems [{:arg {:sym c}
;                                                   :- :-
;                                                   :schema :string}]
;                                          :rest nil
;                                          :as {:as :as
;                                               :sym d
;                                               :schema {:- :-
;                                                        :schema [:vector :any]}}}}}]
;                     :rest {:amp & :form {:arg {:sym e}}}
;                     :as {:as :as
;                          :sym f
;                          :schema nil}}}}]
; :rest {:amp &
;        :arg {:arg {:map {:keys [g h] :as i}}
;              :- :-
;              :schema [:map [:g :int] [:h :int]]}}}

ikitommi17:12:43

(def Bind
  (m/schema
   [:schema
    {:registry
     {"Schema" any?
      "Amp" [:= '&]
      "As" [:= :as]
      "Local" [:and symbol? [:not "Amp"]]
      "Map" [:map
             [:keys {:optional true} [:vector ident?]]
             [:strs {:optional true} [:vector ident?]]
             [:syms {:optional true} [:vector ident?]]
             [:or {:optional true} [:map-of simple-symbol? any?]]
             [:as {:optional true} "Local"]
             [:- {:optional true} "Schema"]]
      "Vector" [:catn
                [:elems [:* "SchematizedArgument"]]
                [:rest [:? [:catn
                            [:amp "Amp"]
                            [:form "SchematizedArgument"]]]]
                [:as [:? [:catn
                          [:as "As"]
                          [:sym "Local"]
                          [:schema [:? [:catn
                                        [:- "Separator"]
                                        [:schema "Schema"]]]]]]]]
      "Argument" [:alt
                  [:catn [:sym "Local"]]
                  [:catn [:map "Map"]]
                  [:catn [:vec [:schema [:ref "Vector"]]]]]
      "Separator" [:= :-]
      "SchematizedArgument" [:alt
                             [:catn
                              [:arg "Argument"]]
                             [:catn
                              [:arg "Argument"]
                              [:- "Separator"]
                              [:schema "Schema"]]]
      "Bind" [:catn
              [:args [:* "SchematizedArgument"]]
              [:rest [:? [:catn
                          [:amp "Amp"]
                          [:arg "SchematizedArgument"]]]]]}}
    "Bind"]))