Skip to content

Commit

Permalink
a fix to indentation related to comma syntax; bump 0.1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Mar 12, 2021
1 parent 691c113 commit 4f482e7
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 225 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Demo http://repo.cirru.org/writer.clj/
[![Clojars Project](https://img.shields.io/clojars/v/cirru/writer.svg)](https://clojars.org/cirru/writer)

```clojure
[cirru/writer "0.1.12"]
[cirru/writer "0.1.13"]
```

```clojure
Expand Down
439 changes: 247 additions & 192 deletions calcit.cirru

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/ast/nested-3.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[["c" ["d" ["e"] [["a"] "d" ["f"] ["g"]]]]]
5 changes: 5 additions & 0 deletions examples/cirru/nested-3.cirru
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

c $ d (e)
a
, d (f)
g
4 changes: 2 additions & 2 deletions examples/cirru/unfolding.cirru
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set
add 1 $
, x y
add 5 $
add 2
add 5 $
add 2

a
b (c d e) f
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cirru-writer-clj",
"version": "0.1.12",
"version": "0.1.13",
"description": "Cirru writer in Clojure",
"main": "target/main.js",
"directories": {
Expand Down Expand Up @@ -32,6 +32,6 @@
"shortid": "^2.2.16"
},
"devDependencies": {
"shadow-cljs": "^2.11.18"
"shadow-cljs": "^2.11.23"
}
}
2 changes: 1 addition & 1 deletion release.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:version "0.1.12",
{:version "0.1.13",
:group-id "cirru",
:artifact-id "writer",
:skip-tag true,
Expand Down
22 changes: 8 additions & 14 deletions src/cirru_writer/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

(defn render-newline [x] (str "\n" (render-spaces x)))

(defn generate-tree [expr insist-head? options level in-tail?]
(loop [acc "", exprs expr, head? true, prev-kind nil, bended? false]
(defn generate-tree [expr insist-head? options base-level in-tail?]
(loop [acc "", exprs expr, head? true, prev-kind nil, bended-size 0, level base-level]
(if (empty? exprs)
acc
(let [cursor (first exprs)
Expand All @@ -70,14 +70,7 @@
tail?
(if (empty? cursor)
"$"
(str
"$ "
(generate-tree
cursor
false
options
(if bended? next-level level)
tail?)))
(str "$ " (generate-tree cursor false options level tail?)))
(= kind :leaf) (generate-leaf cursor)
(and head? insist-head?) (generate-inline-expr cursor)
(= kind :simple-expr)
Expand Down Expand Up @@ -111,17 +104,17 @@
(render-newline next-level))
(generate-tree cursor child-insist-head? options next-level false))
:else (throw (js/Error. "Unknown")))
bended? (and (= kind :leaf) (or (= prev-kind :expr) (= prev-kind :boxed-expr)))
result (cond
tail? (str char-space child)
(and (= prev-kind :leaf) (= kind :leaf)) (str char-space child)
(and (= prev-kind :leaf) (= kind :simple-expr)) (str char-space child)
(and (= prev-kind :simple-expr) (= kind :leaf)) (str char-space child)
(and (= kind :leaf) (or (= prev-kind :expr) (= prev-kind :boxed-expr)))
(str (render-newline next-level) ", " child)
bended? (str (render-newline next-level) ", " child)
:else child)]
(comment
do
(println "loop:" prev-kind kind head? insist-head?)
(println "loop:" prev-kind kind head? insist-head? level bended-size)
(println " =>" (pr-str acc))
(println " =>" exprs)
(println " =>" (pr-str child)))
Expand All @@ -136,7 +129,8 @@
(if (contains? #{:leaf :simple-expr} prev-kind) :simple-expr :expr)
(if (= prev-kind :leaf) :simple-expr :expr)))
kind)
(or bended? (or (= kind :expr) (= kind :boxed-expr))))))))
(if bended? (inc bended-size) bended-size)
(if bended? next-level level))))))

(defn generate-statements [exprs options]
(->> exprs
Expand Down
9 changes: 9 additions & 0 deletions src/cirru_writer/test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@
(is (= (parse expected) data))
(is (= (write-code data) expected)))))

(deftest
nested-3-test
(let [data (read-string (slurp "examples/ast/nested-3.edn"))
expected (slurp "examples/cirru/nested-3.cirru")]
(testing
"writing case for nested-3"
(is (= (parse expected) data))
(is (= (write-code data) expected)))))

(deftest
parentheses-test
(let [data (read-string (slurp "examples/ast/parentheses.edn"))
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f482e7

Please sign in to comment.