first draft if
This commit is contained in:
parent
05703a27fa
commit
f3256f7d12
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user