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