accept newlines after arrows in fn clauses; make some asts mutable for validation

This commit is contained in:
Scott Richmond 2024-05-14 18:41:07 -04:00
parent 3225ea2472
commit ec43aa3c67

View File

@ -701,6 +701,7 @@
(print "parsed guard")
(expect parser :arrow) (advance parser)
(print "parsed arrow")
(accept-many parser :newline)
(def rhs (nonbinding parser))
(print "parsed rhs")
[[lhs guard rhs]]
@ -718,6 +719,7 @@
(advance parser)
(simple parser)))
(expect parser :arrow) (advance parser)
(accept-many parser :newline)
(def rhs (nonbinding parser))
(terminator parser)
[lhs guard rhs])
@ -745,7 +747,7 @@
(defn- lambda [parser]
(def origin (current parser))
(expect parser :fn) (advance parser)
{:type :fn :data (fn-simple parser) :token origin})
@{:type :fn :data (fn-simple parser) :token origin})
(defn- fnn [parser]
(if (= :lparen (-> parser peek type)) (break (lambda parser)))
@ -764,7 +766,7 @@
:lbrace (fn-clauses parser)
:lparen (fn-simple parser)
(panic parser (string "expected clause or clauses, got " (-> current parser type)))))
{:type :fn :name name :data data :token origin})
@{:type :fn :name name :data data :token origin})
([err] err)))
### compoound forms
@ -864,7 +866,7 @@
(expect parser :ns) (advance parser)
(def name (-> parser pkg-name (get :data)))
(def body (block parser))
{:type :ns :data body :name name :token origin})
@{:type :ns :data body :name name :token origin})
([err] err)))
(defn- importt [parser]
@ -895,7 +897,7 @@
:lparen (fn-simple parser)
:lbrace (fn-clauses parser)
))
{:type :loop :data [args clauses] :token origin})
@{:type :loop :data [args clauses] :token origin})
(defn- recur [parser]
(def origin (current parser))
@ -1091,7 +1093,7 @@
(do
#(comment
(def source `
pkg Foo {:bar nil}
loop (1, 2) with (x, y) -> :bar
`)
(def scanned (s/scan source))
(print "\n***NEW PARSE***\n")