Skip to content

Instantly share code, notes, and snippets.

@MichaelDrogalis
Created September 9, 2016 17:54
Show Gist options
  • Save MichaelDrogalis/c66fc7c8db6367d9907caf200d5746fe to your computer and use it in GitHub Desktop.
Save MichaelDrogalis/c66fc7c8db6367d9907caf200d5746fe to your computer and use it in GitHub Desktop.
(s/def :flow/predicate
(s/or :and (s/cat :op (partial = :and) :exprs (s/+ :flow/predicate))
:or (s/cat :op (partial = :or) :exprs (s/+ :flow/predicate))
:not (s/cat :op (partial = :not) :exprs (s/cat :pred :flow/predicate))
:fn keyword?
:fn-and-args (s/cat :fn (λ [x]
(and (keyword? x)
(not (some #{x} #{:and :or :not}))))
:args (s/* keyword?))))
(s/conform :flow/predicate [:and [:f :x] [:or [:not [:g :a :b :c]] [:h :z]]])
;; =>
[:and
{:op :and,
:exprs
[[:fn-and-args {:fn :f, :args [:x]}]
[:or
{:op :or,
:exprs
[[:not
{:op :not,
:exprs {:pred [:fn-and-args {:fn :g, :args [:a :b :c]}]}}]
[:fn-and-args {:fn :h, :args [:z]}]]}]]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment