Skip to content

Commit

Permalink
Fix require bug
Browse files Browse the repository at this point in the history
Fix require bug
  • Loading branch information
bobbicodes authored Jul 4, 2023
2 parents 81e1d1a + 267ade4 commit a4e582d
Show file tree
Hide file tree
Showing 5 changed files with 369 additions and 351 deletions.
614 changes: 308 additions & 306 deletions dist/assets/index-13c5f3bf.js → dist/assets/index-a562dec2.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/lang-clojure-eval/assets/vite-4a748afd.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script type="module" crossorigin src="/lang-clojure-eval/assets/index-13c5f3bf.js"></script>
<script type="module" crossorigin src="/lang-clojure-eval/assets/index-a562dec2.js"></script>
<link rel="stylesheet" href="/lang-clojure-eval/assets/index-dcab846b.css">
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lang-clojure-eval",
"version": "0.0.21",
"version": "0.0.22",
"author": "Bobbi Towers <[email protected]>",
"description": "Lezer-based Clojure Codemirror 6 extension with live evaluation",
"main": "dist/index.cjs",
Expand Down
23 changes: 19 additions & 4 deletions src/lang_clojure_eval/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,33 @@
'lang-clojure-eval.integer
{'parseInt int/parse-int}}}))

(defn reqs [req-form]
(let [first-req (z/down req-form)]
(loop [z first-req result []]
(if-not (z/right z)
result
(recur (z/right z)
(conj result (z/sexpr (z/right z))))))))

(defn current-ns [source]
(z/sexpr (z/next (z/find-next-value (z/of-string source) z/next 'ns))))

(def last-req (atom ""))

(defn eval-string [source]
(let [reqs (str "(ns " (or (current-ns source) "lang-clojure-eval")
"(:require [lang-clojure-eval.character :as Character]
[lang-clojure-eval.integer :as Integer]))
(let [ns-name (z/next (z/find-next-value (z/of-string source) z/next 'ns))
req-form (z/right ns-name)
reqs (str "(ns " (or (current-ns source) "lang-clojure-eval")
"\n (:require [lang-clojure-eval.character :as Character]
[lang-clojure-eval.integer :as Integer] "
(apply str (interpose "\n" (reqs req-form))) "))
(defn int [x]
(if (.isInteger js/Number (js/parseInt x))
(js/parseInt x)
(.charCodeAt x 0)))")]
(when (or req-form
(and ns-name (nil? req-form))) (reset! last-req reqs))
(try (binding [*print-length* 100]
(with-out-str (pprint/pprint (sci/eval-string* context (str reqs source)))))
(with-out-str (pprint/pprint (sci/eval-string* context (str @last-req source)))))
(catch :default e
(with-out-str (error-handler source e))))))
Loading

0 comments on commit a4e582d

Please sign in to comment.