first draft if

This commit is contained in:
Scott Richmond 2024-05-08 13:22:49 -04:00
parent 05703a27fa
commit f3256f7d12

View File

@ -85,6 +85,9 @@
(defn- expect [parser type]
(if-not (check parser type) (expected parser type)))
(defn- expect-ret [parser type]
(try (expect parser type) ([e] e)))
# atoms
(defn- bool [parser]
(expect parser :bool)
@ -261,6 +264,30 @@
(advance parser)
ast)
### conditional forms
(defn- iff [parser]
(def ast {:type :if :data @[] :token (current parser)})
(advance parser) #consume the if
(update ast array/push :data (simple parser))
(when-let [err (expect-ret parser :then)] (update ast array/push :data err))
(update ast array/push :data (nonbinding parser))
(when-let [err (expect-ret parser :else)] (update ast array/push :data err))
(update ast array/push :data (nonbinding parser))
ast)
(defn- condd [parser])
(defn- match [parser])
### function forms
(defn- fnn [parser])
(defn- lambda [parser])
### compoound forms
(defn- block [parser])
(defn- doo [parser])
### expressions
# four levels of expression complexity:
@ -315,7 +342,7 @@
:word (word parser)
# conditional forms
:if (unreachable)
:if (iff parser)
:cond (unreachable)
:match (unreachable)
:with (unreachable)