metosin/malli

Implement `-parse-info` for sequence regexes

Open

#1230 aperta il 16 ott 2025

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Clojure (237 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (1724 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

  • :alt is like :or except any regex child makes it transforming
  • :cat is like :tuple except any regex child makes it transforming
  • leave all others as transforming

Relevant examples:

(let [s [:cat :keyword [:alt [:vector :any] [:+ :int]]]
      v [:k 1 2 3]
      roundtrip #(->> % (m/parse s) (m/unparse s))]
  (list v (roundtrip v)))
;; => ([:k 1 2 3] [:k [1 2 3]])

(def Hiccup ; (leaf node)
  [:cat :keyword [:? [:maybe [:map-of :keyword :any]]] [:* string?]])

(m/parse Hiccup [:div "edge" "case"])
;; => [:div nil ["edge" "case"]]

(let [v [:div "edge" "case"]]
  (= v (->> v (m/parse Hiccup) (m/unparse Hiccup))))
;; => false

(map (m/parser [:cat :int [:? [:maybe :int]] :int])
  [[1 2 3]
   [1 3]
   [1 nil 3]])
;; => ([1 2 3] [1 nil 3] [1 nil 3])

(m/parse [:cat :int [:cat :int]]
  [1 2])
;; => [1 [2]]

(m/parse [:and
          [:orn [:v vector?] [:l list?]]
          [:cat :keyword [:* :any]]]
  [:x])
;; => Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:203).
;;    :malli.core/and-schema-multiple-transforming-parsers

Extracted from: https://clojurians.slack.com/archives/CLDK6MFMK/p1760419966575209

Guida contributor