add expr to match to matchh

This commit is contained in:
Scott Richmond 2024-05-18 17:01:12 -04:00
parent b5d23b26ec
commit 32cf7d6cc4

View File

@ -228,7 +228,7 @@
(array/push data curr)
(def interpolated (map scan-interpolations data))
(advance parser)
(def ast {:type :interpolated :data interpolated :token origin})
(def ast @{:type :interpolated :data interpolated :token origin})
(if (some is-error? interpolated)
(do
(def err {:type :error :msg "bad interpolated string" :data ast :token origin})
@ -620,19 +620,23 @@
(defn- matchh [parser]
(def origin (current parser))
(def ast {:type :match :data @[] :token origin})
(var to-match nil)
(def clauses @[])
(expect parser :match)
(advance parser)
(try
(do
(simple parser)
(set to-match (simple parser))
(expect parser :with) (advance parser)
(def open-brace (current parser))
(expect parser :lbrace) (advance parser)
(accept-many parser :newline)
(while (not (check parser :rbrace))
(when (check parser :eof) (error {:type :error :token origin :data ast :msg "unclosed brace"}))
(array/push (ast :data) (match-clause parser)))
(when (check parser :eof)
(error {:type :error :token open-brace :msg "unclosed brace"}))
(array/push clauses (match-clause parser)))
(advance parser)
ast)
{:type :match :data [to-match clauses] :token origin})
([err] err)))
# {pattern} = {nonbinding} {terminators}
@ -1090,15 +1094,15 @@
)
# (do
(comment
(do
# (comment
(def source `
loop (1, 2) with (x, y) -> :bar
"{bar}{quux}"
`)
(def scanned (s/scan source))
(print "\n***NEW PARSE***\n")
(def a-parser (new-parser scanned))
(def parsed (toplevel a-parser))
(def parsed (interpolated a-parser))
# (print (pp-ast parsed))
(pp scanned)