Add typed shorthand to dicts

This commit is contained in:
Scott Richmond 2023-05-31 11:37:39 -04:00
parent 6c38c43727
commit e27e5a4c1a
3 changed files with 9 additions and 6 deletions

View File

@ -47,7 +47,9 @@
(defp pair-pattern group weak-order [:keyword pattern])
(defp dict-pattern-term flat choice [pair-pattern :word splattern])
(defp typed group weak-order [:word (quiet :as) :keyword])
(defp dict-pattern-term flat choice [pair-pattern :word typed splattern])
(defp dict-pattern-entry weak-order [dict-pattern-term separators])
@ -65,8 +67,6 @@
(defp guard order-0 [(quiet :when) expression])
(defp typed group weak-order [:word (quiet :as) :keyword])
(defp pattern flat choice [literal
:ignored
:placeholder

View File

@ -139,6 +139,9 @@
:pair-pattern
(assoc map (-> data first :data first) (second data))
:typed
(assoc map (-> data first :data first keyword) member)
map ;;ignore splats
)))
@ -933,7 +936,7 @@
(do
(def source "
let #{:a a as :number} = #{:a 1}
let #{a as :number} = #{:a 1}
a
")

View File

@ -5,13 +5,13 @@
[ludus.scanner :as s]))
(def source
"spawn foo
"#{a as :number}
"
)
(def tokens (-> source s/scan :tokens))
(def result (p/apply-parser g/spawn tokens))
(def result (p/apply-parser g/dict-pattern tokens))
(-> result :data)