Very first draft of import expression
This commit is contained in:
parent
5df9c71bcc
commit
3749d2ea50
|
@ -19,7 +19,7 @@
|
||||||
(recur word (::parent ctx))
|
(recur word (::parent ctx))
|
||||||
(throw (ex-info (str "Unbound name: " word) {}))))))
|
(throw (ex-info (str "Unbound name: " word) {}))))))
|
||||||
|
|
||||||
(declare interpret-ast match)
|
(declare interpret-ast match interpret)
|
||||||
|
|
||||||
(defn- match-tuple [pattern value ctx-atom]
|
(defn- match-tuple [pattern value ctx-atom]
|
||||||
(cond
|
(cond
|
||||||
|
@ -236,7 +236,7 @@
|
||||||
(let [members (:members ast)
|
(let [members (:members ast)
|
||||||
name (:name ast)]
|
name (:name ast)]
|
||||||
(if (contains? @ctx name)
|
(if (contains? @ctx name)
|
||||||
(throw (ex-info (str "ns name " name "is already bound") {}))
|
(throw (ex-info (str "ns name " name " is already bound") {}))
|
||||||
(let [ns (into
|
(let [ns (into
|
||||||
{::data/struct true ::data/type ::data/ns ::data/name name}
|
{::data/struct true ::data/type ::data/ns ::data/name name}
|
||||||
(map-values #(interpret-ast % ctx))
|
(map-values #(interpret-ast % ctx))
|
||||||
|
@ -245,6 +245,21 @@
|
||||||
(swap! ctx update-ctx {name ns})
|
(swap! ctx update-ctx {name ns})
|
||||||
ns)))))
|
ns)))))
|
||||||
|
|
||||||
|
(defn- interpret-import [ast ctx]
|
||||||
|
(let [path (:path ast)
|
||||||
|
name (:name ast)]
|
||||||
|
(if (contains? @ctx name)
|
||||||
|
(throw (ex-info (str "Name " name " is alrady bound") {}))
|
||||||
|
(let [result ;; TODO: add any error handling at all
|
||||||
|
(-> path
|
||||||
|
(slurp)
|
||||||
|
(scanner/scan)
|
||||||
|
(parser/parse)
|
||||||
|
(interpret))]
|
||||||
|
(swap! ctx update-ctx {name result})
|
||||||
|
result
|
||||||
|
))))
|
||||||
|
|
||||||
(defn interpret-ast [ast ctx]
|
(defn interpret-ast [ast ctx]
|
||||||
(case (::ast/type ast)
|
(case (::ast/type ast)
|
||||||
|
|
||||||
|
@ -270,6 +285,8 @@
|
||||||
|
|
||||||
::ast/ns (interpret-ns ast ctx)
|
::ast/ns (interpret-ns ast ctx)
|
||||||
|
|
||||||
|
::ast/import (interpret-import ast ctx)
|
||||||
|
|
||||||
::ast/block
|
::ast/block
|
||||||
(let [exprs (:exprs ast)
|
(let [exprs (:exprs ast)
|
||||||
inner (pop exprs)
|
inner (pop exprs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user