Skip to content

Commit

Permalink
Merge pull request #16 from Cirru/empty-line
Browse files Browse the repository at this point in the history
reduce extra empty line
  • Loading branch information
soyaine authored Feb 23, 2021
2 parents 2e579dc + 89a5e80 commit 691c113
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
restore-keys: |
${{ runner.os }}-clojars
- run: yarn && yarn build
- run: yarn && yarn test && yarn build
name: Build web assets

- name: Deploy to server
Expand Down
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.11"]
[cirru/writer "0.1.12"]
```

```clojure
Expand Down
228 changes: 159 additions & 69 deletions calcit.cirru

Large diffs are not rendered by default.

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

cond
a
, c
(d)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cirru-writer-clj",
"version": "0.1.11",
"version": "0.1.12",
"description": "Cirru writer in Clojure",
"main": "target/main.js",
"directories": {
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.1.11",
{:version "0.1.12",
:group-id "cirru",
:artifact-id "writer",
:skip-tag true,
Expand Down
24 changes: 15 additions & 9 deletions src/cirru_writer/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@

(defn generate-tree [expr insist-head? options level in-tail?]
(loop [acc "", exprs expr, head? true, prev-kind nil, bended? false]
(comment
do
(println "loop:" prev-kind head?)
(println " =>" (pr-str acc))
(println " =>" exprs)
(println " =>" head? insist-head?))
(if (empty? exprs)
acc
(let [cursor (first exprs)
Expand Down Expand Up @@ -101,9 +95,15 @@
next-level
false)))
(= kind :expr)
(str
(render-newline next-level)
(generate-tree cursor child-insist-head? options next-level false))
(let [content (generate-tree
cursor
child-insist-head?
options
next-level
false)]
(if (string/starts-with? content "\n")
content
(str (render-newline next-level) content)))
(= kind :boxed-expr)
(str
(if (contains? #{:leaf :simple-expr nil} prev-kind)
Expand All @@ -119,6 +119,12 @@
(and (= kind :leaf) (or (= prev-kind :expr) (= prev-kind :boxed-expr)))
(str (render-newline next-level) ", " child)
:else child)]
(comment
do
(println "loop:" prev-kind kind head? insist-head?)
(println " =>" (pr-str acc))
(println " =>" exprs)
(println " =>" (pr-str child)))
(recur
(if (empty? acc) result (str acc result))
(rest 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 @@ -17,6 +17,15 @@
(is (= (parse expected) data))
(is (= (write-code data) expected)))))

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

(deftest
cond-test
(let [data (read-string (slurp "examples/ast/cond.edn"))
Expand Down

0 comments on commit 691c113

Please sign in to comment.