diff --git a/janet/validate.janet b/janet/validate.janet index 5b6ae44..388949a 100644 --- a/janet/validate.janet +++ b/janet/validate.janet @@ -7,7 +7,7 @@ Tracking here, before I start writing this code, the kinds of validation we're h * [ ] ensure called keywords are only called w/ one arg * [ ] first-level property access with pkg, e.g. `Foo :bar`--bar must be on Foo - [ ] accept pkg-kws -* [ ] validate dict patterns +* [x] validate dict patterns * [x] compile string-patterns * [x] `loop` form arity checking * [x] arity checking of explicit named function calls @@ -372,6 +372,17 @@ Deferred until a later iteration of Ludus: {:node ast :msg "mismatched arity"})) validator) +(defn- kw-root [validator] + (def ast (validator :ast)) + (def data (ast :data)) + (def [_ args] data) + (when (not= :args (args :type)) + (break (array/push (validator :errors) + {:node args :msg "called keyword expects an argument"}))) + (when (not= 1 (length (args :data))) + (array/push (validator :errors) + {:node args :msg "called keywords take one argument"}))) + (defn- synthetic [validator] (def ast (validator :ast)) (def data (ast :data)) @@ -386,7 +397,8 @@ Deferred until a later iteration of Ludus: (print "stype " stype) (print "ltype " ltype) (when (= ftype :pkg-name) (pkg-root validator)) - (when (= ltype :args) (tail-call validator)) + (when (= ftype :keyword) (kw-root validator)) + # (when (= ltype :args) (tail-call validator)) (when (and (= ftype :word) (= stype :args)) (check-arity validator)) validator) @@ -638,11 +650,10 @@ Deferred until a later iteration of Ludus: (import ./base :as b) -(do -# (comment +# (do +(comment (def source ` -let #{a, b} = #{:a 1} -b +:foo (1, 2) `) (def scanned (s/scan source)) (def parsed (p/parse scanned))