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] (defn- expect [parser type]
(if-not (check parser type) (expected parser type))) (if-not (check parser type) (expected parser type)))
(defn- expect-ret [parser type]
(try (expect parser type) ([e] e)))
# atoms # atoms
(defn- bool [parser] (defn- bool [parser]
(expect parser :bool) (expect parser :bool)
@ -261,6 +264,30 @@
(advance parser) (advance parser)
ast) 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 ### expressions
# four levels of expression complexity: # four levels of expression complexity:
@ -315,7 +342,7 @@
:word (word parser) :word (word parser)
# conditional forms # conditional forms
:if (unreachable) :if (iff parser)
:cond (unreachable) :cond (unreachable)
:match (unreachable) :match (unreachable)
:with (unreachable) :with (unreachable)