Make (_) a parsing error

This commit is contained in:
Scott Richmond 2022-11-03 17:51:33 -04:00
parent e248be16cf
commit 1caddfacbc

View File

@ -139,19 +139,24 @@
(defn- contains-placeholder? [members]
(< 0 (count (filter #(= ::ast/placeholder (::ast/type %1)) members))))
(defn unary-placeholder? [tuple]
(and (:partial tuple) (= (:length tuple) 1)))
(defn- parse-fn-tuple [origin]
(loop [parser (accept-many #{::token/newline ::token/comma} (advance origin))
members []
current_member nil]
(let [curr (current parser)]
(case (token-type parser)
::token/rparen (let [ms (add-member members current_member)]
(assoc (advance parser) ::ast
{::ast/type ::ast/tuple
::token/rparen (let [ms (add-member members current_member)
ast {::ast/type ::ast/tuple
:length (count ms)
:members ms
:token (current origin)
:partial (contains-placeholder? ms)}))
:partial (contains-placeholder? ms)}]
(if (unary-placeholder? ast)
(panic parser "You may not use a placeholder in a tuple of length 1. You may only partially apply functions that take more than one argument.")
(assoc (advance parser) ::ast ast)))
(::token/comma ::token/newline)
(recur