add easy patterns, start work on string interpolation

This commit is contained in:
Scott Richmond 2024-05-08 17:31:47 -04:00
parent 736f1024c3
commit 3466b075af

View File

@ -324,6 +324,14 @@
(advance parser) (advance parser)
{:type :word :data (origin :lexeme) :token origin}) {:type :word :data (origin :lexeme) :token origin})
(defn- tuple-pattern [parser])
(defn- list-pattern [parser])
(defn- dict-pattern [parser])
(defn- string-pattern [parser])
(defrec pattern [parser] (defrec pattern [parser]
(case (-> parser current type) (case (-> parser current type)
:nil (nill parser) :nil (nill parser)
@ -331,11 +339,15 @@
:false (bool parser) :false (bool parser)
:keyword (kw parser) :keyword (kw parser)
:number (number parser) :number (number parser)
:string (str parser)
:word (word-pattern parser) :word (word-pattern parser)
:placeholder (placeholder parser) :placeholder (placeholder parser)
:lparen (tuple-pattern parser)
) :lbracket (list-pattern parser)
) :startdict (dict-pattern parser)
:interpolated (string-pattern parser)
(panic parser "expected pattern")
))
### conditional forms ### conditional forms
# if {simple} then {nonbinding} else {nonbinding} # if {simple} then {nonbinding} else {nonbinding}
@ -539,18 +551,12 @@
(import ./scanner :as s) (import ./scanner :as s)
(do (do
#(comment #(comment
(def source `when { (def source `"{foo}"`)
a -> b
foo -> bar quux
-> baz
c -> d
}
`)
(def scanned (s/scan source)) (def scanned (s/scan source))
(def a-parser (new-parser scanned)) # (def a-parser (new-parser scanned))
(def parsed (whenn a-parser)) # (def parsed (whenn a-parser))
(-> parsed) # (-> parsed)
# (map (fn [t] (t :type)) (scanned :tokens)) (map (fn [t] (t :type)) (scanned :tokens))
) )