Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get results from multiple cats? #11

Closed
ikitommi opened this issue Feb 15, 2020 · 4 comments
Closed

How to get results from multiple cats? #11

ikitommi opened this issue Feb 15, 2020 · 4 comments

Comments

@ikitommi
Copy link

ikitommi commented Feb 15, 2020

Tried to port a clojure.spec example into seqexp:

(s/def ::config (s/*
                  (s/cat :prop string?
                         :val  (s/alt :s string? :b boolean?))))
(s/conform ::config ["-server" "foo" "-verbose" true "-user" "joe"])
;;=> [{:prop "-server", :val [:s "foo"]}
;;    {:prop "-verbose", :val [:b true]}
;;    {:prop "-user", :val [:s "joe"]}]

First try:

(se/exec
  (se/*
    (se/as :opts
           (se/cat
             (se/as :prop string?)
             (se/as :val (se/| (se/as :s string?) (se/as :b boolean?))))))
  ["-server" "foo" "-verbose" true "-user" "joe"])
;{:rest (),
; :match ("-server" "foo" "-verbose" true "-user" "joe"),
; :opts ("-user" "joe"),
; :prop ("-user"),
; :val ("joe"),
; :s ("joe"),
; :b (true)}

Second try:

(se/exec-tree
  (se/*
    (se/as [:opts]
           (se/cat
             (se/as [:opts :prop] string?)
             (se/as [:opts :val] (se/| (se/as [:opts :val :s] string?) (se/as [:opts :val :b] boolean?))))))
  ["-server" "foo" "-verbose" true "-user" "joe"])
;{:rest (),
; :match [{:opts [{:prop [{:match ("-server")}],
;                  :val [{:s [{:match ("foo")}], :match ("foo")}],
;                  :match ("-server" "foo")}
;                 {:prop [{:match ("-verbose")}], :val [{:b [{:match (true)}], :match (true)}], :match ("-verbose" true)}
;                 {:prop [{:match ("-user")}], :val [{:s [{:match ("joe")}], :match ("joe")}], :match ("-user" "joe")}],
;          :match ("-server" "foo" "-verbose" true "-user" "joe")}]}

The second one seems to have all the information available, but one must do extra work on constructing the path vectors and parse the results with knowing the path vectors to get something like the clojure.spec version outputs. I'm I doing something wrong? Is there an easier way to exec any pattern and get something like the spec outputs?

@cgrand
Copy link
Owner

cgrand commented Feb 17, 2020

what's your intent? expose seqexp or wrap it behind something closer to spec?

@ikitommi
Copy link
Author

ikitommi commented Mar 6, 2020

hi. would like to have a regex-schemas in https://github.com/metosin/malli and using a proven library behind the scenes seems like a good idea. Would like to support same kind of destructuring that clojure.spec has.

@ikitommi
Copy link
Author

ikitommi commented Mar 6, 2020

Features looking for are:

  • fast validaton (true/false)
  • explain, for both errors and valid values, would retain the branch names like s/conform
  • maybe ~s/unform, to turn the values back from previous to actual values

btw, do you think seqexp would be a good option to use here?

@ikitommi
Copy link
Author

Malli has now it's own regex-engine, far less elegant, but does what is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants