Skip to content

Commit

Permalink
Strip leading comments from recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
eval committed Feb 15, 2024
1 parent 6dd43e2 commit 7bca698
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/eval/deps_try/recipe.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
[edamame.core :as e]
[eval.deps-try.util :as util]))

(defn- strip-leading-comments
"(strip-leading-comments \";; Use this recipe like so,,,\n(ns recipe.hello)\")
;; => \"(ns recipe.hello)\"
"
[s]
(let [[comments _] (string/split s #"\(ns" 2)]
(subs s (count (str comments)))))

(defn -parse [s]
(let [[ns-form {:keys [end-row]}] ((juxt identity meta) (e/parse-string s {:quote true}))
docstring (when (> (count ns-form) 2)
Expand All @@ -27,7 +35,7 @@
[slurpable]
(let [contents (-> slurpable slurp string/trim)]
(merge {:location (str slurpable)}
(-parse contents))))
(-parse (strip-leading-comments contents)))))


(defn- recipe-arg-dispatch [arg]
Expand Down Expand Up @@ -95,6 +103,7 @@
((requiring-resolve 'clojure.pprint/pprint) {:deps-try.manifest/recipes recipes}))))

(comment

(def recipes (fs/path (fs/cwd) "recipes"))

(fs/relativize (str recipes) (first (fs/glob recipes "**/*.clj")))
Expand All @@ -112,7 +121,8 @@
(slurp "README.md")
(slurp "/Users/gert/projects/deps-try/deps-try/recipes/next_jdbc_postgresql.clj")
(parse-recipe-string
"(ns my.namespace
";; some comment
(ns my.namespace
{:clj-kondo/config '{:linters {:unresolved-symbol {:level :off}}}})")

(parse-recipe-string
Expand Down

0 comments on commit 7bca698

Please sign in to comment.