Skip to content

Commit

Permalink
add quoted cirru syntax; alpha release
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Sep 2, 2020
1 parent ffd70ef commit 3004a4b
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 222 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ do |short
do "|long text"
```

### Quoted Cirru format

For vectors of Cirru data, use `(with-meta [] :quoted-cirru)` to generate an embeded quoted syntax. For example:

```clojure
(write {:a 1, :b (with-meta ["def" "a" ["x" "y"] ["+" "x" "y"]] :quoted-cirru)})
```

generates:

```cirru
{} (:a 1)
:b $ quote
def a (x y) (+ x y)
```

### Workflow

Workflow https://github.com/mvc-works/calcit-workflow
Expand Down
276 changes: 257 additions & 19 deletions calcit.cirru

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cirru/edn",
"version": "0.0.9",
"version": "0.0.10-a1",
"description": "ClojureScript workflow using Calcit Editor",
"main": "index.js",
"scripts": {
Expand All @@ -21,7 +21,7 @@
"license": "MIT",
"devDependencies": {
"@cirru/parser.nim": "^0.0.5",
"shadow-cljs": "^2.8.99"
"shadow-cljs": "^2.11.1"
},
"dependencies": {
"feather-icons": "^4.28.0",
Expand Down
2 changes: 1 addition & 1 deletion release.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:version "0.0.9"
{:version "0.0.10-a1"
:group-id "cirru"
:artifact-id "edn"
:skip-tag true
Expand Down
16 changes: 7 additions & 9 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
:cache-blockers #{cumulo-util.build}
:dependencies [
[mvc-works/hsl "0.1.2"]
[mvc-works/shell-page "0.1.10"]
[respo "0.12.1"]
[respo/ui "0.3.14"]
[respo/alerts "0.5.1"]
[mvc-works/shell-page "0.1.15"]
[respo "0.13.3"]
[respo/ui "0.3.15"]
[respo/alerts "0.5.5"]
[respo/value "0.3.0"]
[respo/markdown "0.2.5"]
[respo/feather "0.1.1"]
[respo/reel "0.4.0"]
[respo/reel "0.4.2"]
[cirru/writer "0.1.7"]
[cirru/parser "0.2.5"]
[cirru/favored-edn "0.1.3"]
[cumulo/util "0.1.10"]
[cumulo/util "0.1.12"]
[medley "1.3.0"]
[appliedscience/js-interop "0.2.5"]
[applied-science/js-interop "0.2.7"]
[org.clojure/core.incubator "0.1.4"]
]
:open-file-command [
Expand All @@ -30,7 +30,6 @@
:modules {
:client {:init-fn cirru-edn.main/main!}
}
:devtools {:after-load cirru-edn.main/reload!}
:compiler-options {:infer-externs :auto}
:release {
:output-dir "dist/", :module-hash-names 8
Expand All @@ -39,7 +38,6 @@
}
:page {
:target :node-script, :output-to "target/page.js", :main cirru-edn.page/main!
:devtools {:after-load cirru-edn.page/main!}
}
}
}
2 changes: 1 addition & 1 deletion src/cirru_edn/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
:release-ui "http://cdn.tiye.me/favored-fonts/main-fonts.css",
:cdn-url "http://cdn.tiye.me/cirru-edn/",
:title "Cirru EDN",
:icon "http://cdn.tiye.me/logo/mvc-works.png",
:icon "http://cdn.tiye.me/logo/cirru.png",
:storage-key "cirru-edn"})
17 changes: 16 additions & 1 deletion src/cirru_edn/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
(ns cirru-edn.core
(:require [cirru-parser.core :as cirru-parser] [cirru-writer.core :as cirru-writer]))

(defn check-cirru-format [data]
(cond
(string? data) :ok
(vector? data) (doall (map check-cirru-format data))
:else (do (println "Invalid format for cirru:" data) (pr-str data))))

(def number-pattern (re-pattern #"-?[\d\.]+"))

(def symbol-pattern (re-pattern #"\w[\w\d_\/\-\?\>\<\.\:\=\+\*\!\$]+"))
Expand All @@ -26,6 +32,7 @@
(= "{}" (first xs))
(->> xs (rest) (map (fn [[k v]] [(cirru->edn k) (cirru->edn v)])) (into {}))
(= "do" (first xs)) (cirru->edn (get xs 1))
(= "quote" (first xs)) (get xs 1)
:else (do (js/console.warn "Unknown xs" xs) nil))
:else (do (js/console.warn "Unknown data" xs) (str xs))))

Expand All @@ -37,7 +44,10 @@
(keyword? data) (str data)
(map? data)
(vec (concat (list "{}") (map (fn [[k v]] [(edn->cirru k) (edn->cirru v)]) data)))
(vector? data) (vec (concat (list "[]") (map edn->cirru data)))
(vector? data)
(if (= :quoted-cirru (meta data))
(do (check-cirru-format data) ["quote" data])
(vec (concat (list "[]") (map edn->cirru data))))
(seq? data) (vec (concat (list "list") (map edn->cirru data)))
(set? data) (vec (concat (list "set") (map edn->cirru data)))
(nil? data) "nil"
Expand All @@ -54,3 +64,8 @@
(cirru-writer/write-code
[(if (coll? data) (edn->cirru data) ["do" (edn->cirru data)])]
{:inline? true}))

(defn user-scripts []
(println (write {:a 1, :b (with-meta ["def" "a" ["x" "y"] ["+" "x" "y"]] :quoted-cirru)}))
(println "will fail:" (write {:a 1, :b (with-meta ["a" "b" "c" {:a 1}] :quoted-cirru)}))
(println (pr-str (parse "{}\n :a $ quote $ def f (x y) (+ x y)\n"))))
4 changes: 3 additions & 1 deletion src/cirru_edn/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
(when (some? raw) (dispatch! :hydrate-storage (read-string raw))))
(println "App started."))

(defn reload! []
(defn ^:dev/after-load
reload!
[]
(clear-cache!)
(reset! *reel (refresh-reel @*reel schema/store updater))
(println "Code updated."))
Expand Down
4 changes: 2 additions & 2 deletions src/cirru_edn/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(merge
base-info
{:styles [(<< "http://~(get-ip!):8100/main.css") "/entry/main.css"],
:scripts ["/client.js"],
:scripts [{:src "/client.js"}],
:inline-styles []})))

(defn prod-page []
Expand All @@ -33,7 +33,7 @@
(merge
base-info
{:styles [(:release-ui config/site)],
:scripts (map #(-> % :output-name prefix-cdn) assets),
:scripts (map (fn [x] {:src (-> x :output-name prefix-cdn)}) assets),
:ssr "respo-ssr",
:inline-styles [(slurp "./entry/main.css")]}))))

Expand Down
Loading

0 comments on commit 3004a4b

Please sign in to comment.