Skip to content

Commit

Permalink
Clarify the possibility to use a default phraser
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkiel committed Jul 16, 2018
1 parent d85f7aa commit aaa3687
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/phrase/alpha.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@
"Takes a context and a clojure.spec problem and dispatches to a phraser.
Returns the phrasers return value or nil if none was found and no default
phraser is defined. Dispatches based on pred and via of the problem. See
phraser is defined. Dispatches based on :pred and :via of the problem. See
phraser macro for details."
[context problem]
(phrase* context (phrase-problem problem)))

(defn phrase-first
"Given a spec and a value x, phrases the first problem using context if any.
Returns nil if x is valid or no phraser was found. See phrase for details.
Use phrase directly if you want to phrase more than one problem."
Returns nil if x is valid or no phraser was found and no default phraser is
defined. See phrase for details. Use phrase directly if you want to phrase
more than one problem."
[context spec x]
(some->> (s/explain-data spec x)
::s/problems
Expand Down Expand Up @@ -174,8 +175,13 @@
:body (s/* any?)))

(defmacro defphraser
"Defines a phraser. Takes a predicate with possible capture symbols which have
to be also defined in the argument vector."
"Defines a phraser.
Takes a predicate with possible capture symbols which have to be also defined
in the argument vector.
Pred can be :default in order to define the default phraser which is used if
no other phraser matches."
{:arglists '([pred specifiers? [context-binding-form problem-binding-form
& capture-binding-forms] & body])}
[pred & more]
Expand Down

0 comments on commit aaa3687

Please sign in to comment.