validate with passed context; don't die on builtin functions
This commit is contained in:
parent
608ab4ab67
commit
a06014270f
|
@ -5,7 +5,6 @@
|
|||
Tracking here, before I start writing this code, the kinds of validation we're hoping to accomplish:
|
||||
|
||||
* [ ] ensure called keywords are only called w/ one arg
|
||||
* [ ] validate `with` forms
|
||||
* [ ] first-level property access with pkg, e.g. `Foo :bar`--bar must be on Foo
|
||||
- [ ] accept pkg-kws
|
||||
* [ ] validate dict patterns
|
||||
|
@ -20,9 +19,10 @@ Tracking here, before I start writing this code, the kinds of validation we're h
|
|||
* [x] recur not called outside of `loop` forms
|
||||
* [x] splats come at the end of list, tuple, and dict patterns
|
||||
|
||||
Imports are for a later iteration of Ludus:
|
||||
Deferred until a later iteration of Ludus:
|
||||
* [ ] no circular imports DEFERRED
|
||||
* [ ] correct imports DEFERRED
|
||||
* [ ] validate `with` forms
|
||||
)
|
||||
|
||||
(try (os/cd "janet") ([_] nil))
|
||||
|
@ -344,6 +344,7 @@ Imports are for a later iteration of Ludus:
|
|||
(def fn-word (first data))
|
||||
(def the-fn (resolve-name ctx (fn-word :data)))
|
||||
(when (not the-fn) (break validator))
|
||||
(when (= :function (type the-fn)) (break validator))
|
||||
(print "fn name: " (the-fn :name))
|
||||
(def arities (the-fn :arities))
|
||||
(print "arities: ")
|
||||
|
@ -620,16 +621,24 @@ Imports are for a later iteration of Ludus:
|
|||
|
||||
(set validate validate*)
|
||||
|
||||
(defn valid [ast]
|
||||
(defn valid [ast &opt ctx]
|
||||
(default ctx @{})
|
||||
(def validator (new-validator ast))
|
||||
(def base-ctx @{:^parent ctx})
|
||||
(set (validator :ctx) ctx)
|
||||
(validate validator))
|
||||
|
||||
# (do
|
||||
(comment
|
||||
(defn foo [] :foo)
|
||||
(def base {
|
||||
"foo" foo
|
||||
})
|
||||
|
||||
(do
|
||||
# (comment
|
||||
(def source `
|
||||
let "{foo}" = "bar"
|
||||
foo ()
|
||||
`)
|
||||
(def scanned (s/scan source))
|
||||
(def parsed (p/parse scanned))
|
||||
(valid parsed)
|
||||
(valid parsed base)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user