- Notifications
You must be signed in to change notification settings - Fork8
Traverse and rewrite Clojure/ClojureScript/EDN from ClojureScript
License
clj-commons/rewrite-cljs
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The functionality of rewrite-cljs (and much more) has been incorporated intorewrite-clj v1.
All further work on the ClojureScript version of rewrite-clj will continue in the rewrite-clj project.
No further work is currently planned for this project.
This library is a ClojureScript port ofrewrite-clj.It provides features to traverse and rewrite Clojure/ClojureScript/EDN documents in a whitespace and comment-aware manner replicatingthe behavior of its Clojure counterpart as closely as possible.
👋 Want to chat? Say hi onClojurians Slack in#rewrite-clj.
Created by @rundis in 2015, rewrite-cljs was originally used for Clojure/ClojureScript refactoring support inLight Table. In January of 2019, @rundis graciously transferred rewrite-cljs to clj-commons.
rewrite-cljs includes:
- An EDN parser
- An EDN aware zipper (using clojure.zip for ClojureScript)
- A customized cljs.reader (based onclojurescript-in-clojurescript that mimics more of clojure.tools.reader
Here's a little teaser on the sort of things you can do with the zipper features.
(nsrewrite-clj.zip-test (:require-macros [cemerick.cljs.test:refer (isdeftest )]) (:require [cemerick.cljs.test:as t] [rewrite-clj.zip:as z] [rewrite-clj.node:as n]))(deftestmanipulate-sexpr (let [sexpr" ^{:dynamic true} (+ 1 1 (+ 2 2) (reduce + [1 3 4]))" expected" ^{:dynamic true} (+ 1 1 (+ 2 2) (reduce + [6 7 [1 2]]))"] (is (= expected (-> sexpr z/of-string (z/find-tag-by-pos {:row4:col19}:vector) (z/replace [567]) (z/append-child [12]) z/down z/remove z/root-string)))))
- rewrite-cljs has fallen quite far behind rewrite-clj - with some love from the community, we can bring it up to date.
- There is no support for parsing files (duh)
- cljs.extended.reader which is used for reading edn/clojure/clojurescript, has lot of limitations. Please don't be surprisedwhen encountering errors during reading of perhaps legal but hopefully infrequently used language constructs.
- Some features in rewrite-clj are heavily based on macros, these features have been omitted for now
- Nice printing of nodes - Not implemented
- zip subedit support is not implemented (YET!)
- The reader captures positional metadata {:row :col :end-row :end-col} for all nodes. As long as you are only traversing the nodes you should be fine using the meta data and functions that depend on them (example zip/find-last-by-pos). However if you perform any form of rewriting the meta-data can't be trusted any longer. Not sure how to address that tbh. Pull requests are more than welcome!
Why a separate project? Why not incorporate ClojureScript support directly into rewrite-clj?
This might have not been terribly viable when this project was first created, but certainly is an option to consider today.
The MIT License (MIT)Copyright (c) 2015 Magnus RundbergetPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.The MIT License (MIT)Copyright (c) 2013-2015 Yannick SchererPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.About
Traverse and rewrite Clojure/ClojureScript/EDN from ClojureScript
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.