-
throws on parse
For a list of breaking changes see breaking changes.
Release workflow now creates a GitHub release
If you wish, you can read nitty gritty details on merging rewrite clj v0 and rewrite cljs. What follows is a summary of changes.
A new home under clj-commons. Thanks to @xsc, rewrite-clj will also retain its same maven coordinates on Clojars making for a seamless upgrade path for rewrite-clj v0 users.
Now supports ClojureScript, merging in rewrite-cljs specific functionality. Frustrations like not having namespace map support and differences from rewrite-clj, like whitespace parsing, should now be things of the past. Rewrite-cljs users migrating to rewrite-clj v1 are now at, and will remain at, feature parity with rewrite-clj.
Additions to the public API:
rewrite-clj.paredit
- carried over from rewrite-cljs, an API for structured editing of Clojure forms
rewrite-clj.zip
Exposes the following (accidentally?) omitted functions:
append-child*
insert-newline-left
insert-newline-right
insert-space-left
insert-space-right
subzip
Adds functions from rewrite-cljs
find-last-by-pos
- navigate to node at row/col
find-tag-by-pos
- navigate to node with tag at row/col
position-span
- returns start and end row/col for a form
remove-preserve-newline
- same as remove but preserves newlines
Adds namespaced element support functions
reapply-context
- reapplies (or removes) map qualifier node context from keywords and symbols
zipper creation functions now optionally accept an auto-resolve function to support sexpr on namespaced element nodes
Other additions
sexpr-able?
- return true if sexpr
is supported for current node
rewrite-clj.node
Additions:
keyword-node?
- returns true if form is a rewrite-clj keyword node
map-qualifier-node
- to create a namespaced map’s map qualifier node manually
map-context-apply
- apply map qualifier to keyword or symbol
map-context-clear
- remove map qualifier from keyword or symbol
node?
- returns true if a form is a rewrite-clj created node
sexpr-able?
- return true if sexpr
is supported for node
symbol-node?
- return true if node is a rewrite-clj symbol node
Updates:
sexpr
, sepxrs
and child-sexprs
- now optionally take an options argument to specify an auto-resolve function
Many updates to docs and docstrings
OS specific end of line variants in source now normalized consistently to \newline
#93
Postwalk on larger source file no longer throws StackOverflow #69
Postwalk now walks in post order #123
We now preserve newline at end of file #121
Support for garden style selectors #92
Correct and document prefix and suffix functions #91
Positional metadata added by the reader is elided on coercion #90
Can now read ##Inf
, ##-Inf
and ##Nan
#75
Ensure that all rewrite-clj nodes coerce to themselves
Strings now coerce to string nodes (instead of to token nodes) #126
Regexes now coerce to regex nodes #128
Regex node now:
Moved from potemkin import-vars to static template based version #98:
Avoids frustration/mysteries of dynamic import-vars for users and maintainers
Argument names now correct in API docs (some were gensymed previously)
Also turfed use of custom version of potemkin defprotocol+ in favor of plain old defprotocol. Perhaps I missed something, but I did not see the benefit of defprotocol+ for rewrite-clj v1.
Tests updated to hit public APIs #106
ClojureScript tests, in addition to being run under node, are now also run under chrome-headless, shadow-cljs, and for self-hosted ClojureScript, under planck.
Now testing rewrite-clj compiled under GraalVM native-image in two variants:
In a pure form where library and tests are compiled
Via sci where a sci exposed rewrite-clj is compiled, then tests are interpreted.
Now automatically testing rewrite-clj against popular libs #124
Now linting source with clj-kondo
Code coverage reports now generated for Clojure unit test run and sent to codecov.io
Can now preview for cljdoc locally via script/cljdoc_preview.clj
API diffs for rewrite-clj v1 vs rewrite-clj v0 vs rewrite-cljs can be generated by script/gen_api_diffs.clj
Contributors are acknowledged in README and updated via script/update_readme.clj
Doc code blocks are automatically tested via script/doc_tests.clj
#100
Some tooling and tech replaced:
All scripts are written in Clojure and run via Babashka or Clojure.
Switched from leiningen project.clj
to Clojure tools CLI deps.edn
Moved from CommonMark to AsciiDoc for docs
Moved from publishing docs locally via codox to publishing to cljdoc
Now using CommonMark in docstrings (they render nicely in cljdoc)
Moved from TravisCI to GitHub Actions where, in addition to Linux, we also test under macOS and Windows
Adopted kaocha for Clojure testing, stuck with doo for regular ClojureScript testing, and added support for ClojureScript watch testing with figwheel main.
Potemkin dynamic import-vars replaced with static code generation solution
Added GitHub issue templates
Fixed a generative test sporadic failure #88
Minimum Clojure version bumped from v1.5.1 to v1.9
Minimum ClojureScript version (from whatever is was for rewrite-cljs) bumped to v1.10
Minimum Java version bumped from v7 to v8
Keyword node field namespaced?
renamed to auto-resolved?
Now using ex-info
for explicitly raised exceptions
Rewrite-cljs positional support migrated to rewrite-clj’s positional support
Namespaced element support reworked
v1 changes do not affect node traversal of the namespaced map, number and order of children remain the same.
Namespace map prefix, is now stored in a namespaced map qualifier node.
Prior to v1, the prefix was parsed to a keyword-node.
Let’s look at what interesting node API functions will return for the prefix node in the following namespaced maps.
Assume we have parsed the example and traversed down to the prefix node.
For example via: (→ "#:prefix{:a 1}" z/of-string z/down z/node)
.
node API call | rewrite-clj | #:prefix{:a 1} | #::alias{:a 1} | #::{:a 1} |
---|---|---|---|---|
| v1 |
|
|
|
v0 |
| |||
| v1 |
| ||
v0 |
|
| ||
| v1 |
| ||
v0 |
|
| ||
| <read on below for discussion on sexpr> |
Namespaced element sexpr
support now relies on user specifiable auto-resolve function to resolve qualifiers
Unlike rewrite-clj v0, the default auto-resolve behaviour never consults *ns*
An sexpr for keyword node ::alias/foo
no longer returns :alias/foo
(this could be considered a bug fix, but if your code is expecting this, then you’ll need to make changes)
The following namespaced element sexpr
examples assume:
*ns*
is bound to user
namespace (important only for rewrite-clj v0):
We are using the default auto-resolve function for rewrite-clj v1
That you will refer to the User Guide for more detailed examples of v1 behaviour
source | sexpr rewrite-clj v1 | sexpr rewrite-clj v0 | sexpr rewrite-cljs |
---|---|---|---|
qualified keyword | no change | ||
current-ns qualified keyword |
|
|
|
ns-alias qualified keyword |
|
|
|
qualified map |
|
|
|
current-ns qualified map |
|
|
|
ns-alias qualified map |
|
|
|
Let’s dig into prefix and key sub-nodes of a namespaced map to explore v1 differences:
Description | rewrite-clj v1 | rewrite-clj v0 and rewrite-cljs |
---|---|---|
prefix (aka qualifier) | ||
qualified
|
|
|
current-ns qualified
|
|
|
ns-alias qualified
|
|
|
key | ||
qualified
|
|
|
current-ns qualified
|
|
|
ns-alias qualified
|
|
|
Potentially breaking
Some rewrite-cljs optimizations were dropped in favor of a single code base. If performance for rewrite-clj v1 for ClojureScript users is poor with today’s ClojureScript, we shall adapt.
Deleted unused rewrite-clj.node.indent
#116
Deleted redundant rewrite-clj.parser.util
as part of #93.
If you were using this internal namespace you can opt to switch to, the also internal, rewrite-clj.reader
namespace.
BREAKING: uses a dedicated node type for regular expressions. (see #49 – thanks @ChrisBlom!)
implement NodeCoercable
for nil
. (set #53 – thanks @jespera!)
fixes parsing of splicing reader conditionals #?@…
. (see #48)
fixes parsing of multi-line regular expressions. (see #51)
BREAKING: commas will no longer be parsed into :whitespace
nodes but
:comma
. (see #44 - thanks @arrdem!)
BREAKING: position
will throw exception if not used on rewrite-clj
custom zipper. (see #45)
BREAKING: drops testing against JDK6.
DEPRECATED:
append-space
in favour of insert-space-right
prepend-space
in favour of insert-space-left
append-newline
in favour of insert-newline-right
prepend-newline
in favour of insert-newline-left
fix insertion of nodes in the presense of existing whitespace. (see #33, #34 - thanks @eraserhd!)
edn
and edn*
now take a :track-position?
option that activates a custom
zipper implementation allowing position
to be called on. (see #41, #45 -
thanks @eraserhd!)
fix parsing of whitespace, e.g. <U+2028>
. (see #43)
fix serialization of `integer-node`s. (see #37 - thanks @eraserhd!)
adds insert-left*
and insert-right*
to facade.
generative tests. (see #41 - thanks @eraserhd!)
Development has branched off, using the 0.4.x
branch
upgrades dependencies.
fixes a compatibility issue when running 'benedekfazekas/mranderson' on a project with both 'rewrite-clj' and 'potemkin'.
switch to Clojure 1.8.0 as base Clojure dependency; mark as "provided".
switch to MIT License.
drop support for JDK6.
drop fast-zip
and potemkin
dependencies. (see #26)
fix handling of symbols with boundary character inside. (see #25)
fix handling of symbols with trailing quote, e.g. x'
. (see #24)
fix replace-children
for :uneval
nodes. (see #23)
add rewrite-clj.zip/postwalk
. (see #22)
allow parsing of aliased keywords, e.g. ::ns/foo
. (see #21)
fixes zipper creation over whitespace-/comment-only data. (see #20)
fixes parsing of empty comments. (see #19)
fixes parsing of comments that are at the end of a file without linebreak. (see #18)
upgrades dependencies.
add rewrite-clj.zip/child-sexprs
to public API.
fix parsing of backslash \\
character. (see #17)
fix :fn
nodes (were printable-only?
but should actually create an s-sexpression).
fix assert-sexpr-count
to not actually create the s-expressions.
fixes infinite loop when trying to read a character.
BREAKING rewrite-clj.zip.indent
no longer usable.
BREAKING node creation/edit has stricter preconditions (e.g. :meta
has to
contain exactly two non-whitespace forms).
BREAKING moved to a type/protocol based implementation of nodes.
fix radix support. (see #13)
fix handling of spaces between certain forms. (see #7)
add node constructor functions.
add child-sexprs
function.
fix assoc
on empty map. (see #16)
drop tests for Clojure 1.4.0.
fix behaviour of leftmost
.
upgrade to fast-zip 0.5.2.
fix behaviour of next
and end?
.
fix prewalk.
add row/column metadata.
add end?
.
allow access to children of quoted forms. (see #6)
fix children lookup for zipper (return nil
on missing children). (see #5)
add :uneval
element type (for #_form
elements).
fix estimate-length
for multi-line strings.
fix zipper creation from file.
upgrade dependencies.
fix file parser (UTF-8 characters were not parsed correctly, see #24@xsc/lein-ancient).
upgrade dependencies.
cleanup dependency chain.
upgrade dependencies.
Bugfix: parsing of a variety of keywords threw an exception.
Bugfix: :1.4
and others threw an exception.
added namespaced keywords.
added token type :newline
to handle linebreak characters.
rewrite-clj.zip/edn
wraps everything into [:forms …]
node, but the initial location
is the node passed to it.
new functions in rewrite-clj.zip.core
:
length
move-to-node
edit→>
, edit-node
subedit→
, subedit→>
, edit-children
leftmost?
, rightmost?
new functions in rewrite-clj.zip.edit
:
splice-or-remove
prefix
, suffix
(formerly rewrite-clj.zip.utils
)
rewrite-clj.zip.edit/remove
now handles whitespace appropriately.
indentation-aware modification functions in rewrite-clj.zip.indent
:
indent
indent-children
replace
edit
insert-left
insert-right
remove
splice
fast-zip utility functions in rewrite-clj.zip.utils
added more expressive error handling to parser.
added multi-line string handling (node type: :multi-line
)
new functions in rewrite-clj.printer
:
→string
estimate-length
new functions in rewrite-clj.zip
:
of-string
, of-file
print
, print-root
→string
, →root-string
append-space
, prepend-space
append-newline
, prepend-newline
right*
, left*
, … (delegating to fast-zip.core/right
, …)
new token type :forms
new functions in rewrite-clj.parser
:
parse-all
parse-string-all
parse-file-all
zipper utility functions in rewrite-clj.zip.utils
(able to handle multi-line strings):
prefix
suffix
Initial Release
Can you improve this documentation? These fine people already did:
lread & GitHub ActionsEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close