called keywords take only a single argument

This commit is contained in:
Scott Richmond 2024-05-20 17:43:57 -04:00
parent 1120f21df2
commit 94adf5e9d5

View File

@ -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 * [ ] ensure called keywords are only called w/ one arg
* [ ] first-level property access with pkg, e.g. `Foo :bar`--bar must be on Foo * [ ] first-level property access with pkg, e.g. `Foo :bar`--bar must be on Foo
- [ ] accept pkg-kws - [ ] accept pkg-kws
* [ ] validate dict patterns * [x] validate dict patterns
* [x] compile string-patterns * [x] compile string-patterns
* [x] `loop` form arity checking * [x] `loop` form arity checking
* [x] arity checking of explicit named function calls * [x] arity checking of explicit named function calls
@ -372,6 +372,17 @@ Deferred until a later iteration of Ludus:
{:node ast :msg "mismatched arity"})) {:node ast :msg "mismatched arity"}))
validator) 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] (defn- synthetic [validator]
(def ast (validator :ast)) (def ast (validator :ast))
(def data (ast :data)) (def data (ast :data))
@ -386,7 +397,8 @@ Deferred until a later iteration of Ludus:
(print "stype " stype) (print "stype " stype)
(print "ltype " ltype) (print "ltype " ltype)
(when (= ftype :pkg-name) (pkg-root validator)) (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)) (when (and (= ftype :word) (= stype :args))
(check-arity validator)) (check-arity validator))
validator) validator)
@ -638,11 +650,10 @@ Deferred until a later iteration of Ludus:
(import ./base :as b) (import ./base :as b)
(do # (do
# (comment (comment
(def source ` (def source `
let #{a, b} = #{:a 1} :foo (1, 2)
b
`) `)
(def scanned (s/scan source)) (def scanned (s/scan source))
(def parsed (p/parse scanned)) (def parsed (p/parse scanned))