validate dict patterns, by validating pairs

This commit is contained in:
Scott Richmond 2024-05-19 20:18:39 -04:00
parent e767c319b1
commit d249ee0b21

View File

@ -144,9 +144,6 @@ Deferred until a later iteration of Ludus:
(set (status :last) nil) (set (status :last) nil)
validator) validator)
### XXX: to do
(defn- dict-pattern [validator])
(defn- word-pattern [validator] (defn- word-pattern [validator]
(def ast (validator :ast)) (def ast (validator :ast))
(def name (ast :data)) (def name (ast :data))
@ -210,6 +207,12 @@ Deferred until a later iteration of Ludus:
(set (ast :compiled) (peg/compile grammar)) (set (ast :compiled) (peg/compile grammar))
(set (ast :bindings) bindings)) (set (ast :bindings) bindings))
(defn- pair [validator]
(def ast (validator :ast))
(def [_ patt] (ast :data))
(set (validator :ast) patt)
(pattern validator))
(defn- pattern* [validator] (defn- pattern* [validator]
(print "PATTERN*") (print "PATTERN*")
(def ast (validator :ast)) (def ast (validator :ast))
@ -224,9 +227,11 @@ Deferred until a later iteration of Ludus:
:word (word-pattern validator) :word (word-pattern validator)
:list (simple-coll-pattern validator) :list (simple-coll-pattern validator)
:tuple (simple-coll-pattern validator) :tuple (simple-coll-pattern validator)
:dict (simple-coll-pattern validator)
:splat (splattern validator) :splat (splattern validator)
:typed (typed validator) :typed (typed validator)
:interpolated (str-pattern validator) :interpolated (str-pattern validator)
:pair (pair validator)
))) )))
(set pattern pattern*) (set pattern pattern*)
@ -633,16 +638,11 @@ Deferred until a later iteration of Ludus:
(import ./base :as b) (import ./base :as b)
# (do (do
(comment # (comment
(def source ` (def source `
fn foobar { let #{a, b} = #{:a 1}
(:foo, :bar) -> true b
(_, _) -> false
}
let bar = foobar (:foo, _)
bar (:bar, 2)
add ()
`) `)
(def scanned (s/scan source)) (def scanned (s/scan source))
(def parsed (p/parse scanned)) (def parsed (p/parse scanned))