Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Traverse and rewrite Clojure/ClojureScript/EDN from ClojureScript

License

NotificationsYou must be signed in to change notification settings

clj-commons/rewrite-cljs

Repository files navigation

🛑 for your consideration:

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.

Clojars Projectcljdoc badgeCircleCI

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

Quick start

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)))))

Limitations and ommissions

  • 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
  • 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!

Rationale

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.

Licenses

License for rewrite-cljs

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.

License for rewrite-clj

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

Stars

Watchers

Forks

Packages

No packages published

Contributors9

Languages


[8]ページ先頭

©2009-2025 Movatter.jp