Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/borkdude/analyze-reify
Analyze occurrences of reify in Clojure code. Implemented using tree-sitter-clojure and Rust.
https://github.com/borkdude/analyze-reify
clojure rust tree-sitter
Last synced: 4 months ago
JSON representation
Analyze occurrences of reify in Clojure code. Implemented using tree-sitter-clojure and Rust.
- Host: GitHub
- URL: https://github.com/borkdude/analyze-reify
- Owner: borkdude
- License: mit
- Created: 2020-03-10T16:16:32.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-20T10:39:48.000Z (almost 5 years ago)
- Last Synced: 2024-10-04T13:41:10.975Z (4 months ago)
- Topics: clojure, rust, tree-sitter
- Language: Rust
- Homepage:
- Size: 29.3 KB
- Stars: 17
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# analyze-reify
This project analyzes [Clojure](http://clojure.org/) code for occurrences of
`reify` and lists the reified interfaces and protocols. It is implemented using
[tree-sitter-clojure](https://github.com/sogaiu/tree-sitter-clojure) and
[Rust](https://www.rust-lang.org/).## Rationale
This is more a proof of concept than a public facing tool, although it does
solve a real problem for me. I wanted to know the most popular reified
interfaces so I could decide if it made sense supporting `reify` in
[babashka](https://github.com/borkdude/babashka/). Also I am curious about both
[Rust](https://www.rust-lang.org/) and
[tree-sitter](https://github.com/tree-sitter/) so this seemed like a nice
oppurtunity to combine the two.## Results
For simple analyses like this it seems a tree-sitter based approach is
feasible. Performance is better than parsing Clojure code into reified data
structures. For comparison, walking over the ASTs in `clojure/core.clj` takes
only around 50ms whereas in a tools.reader based solution it takes around
200ms. This is by no means a scientific benchmark. More research needed.```
Processed 829 files in 731ms. 😎
```## Build
Clone the repo including the submodule:
```
$ git clone https://github.com/borkdude/analyze-reify --recursive
$ cd analyze-reify
```Then build the `tree-sitter-clojure` source. Note: this script
requires `npm`.```
$ script/tree-sitter-clojure
```Then build with the Rust build tool `cargo`:
```
$ cargo build --release
```or install the tool on to your system:
```
$ cargo install --path .
```## Usage
Provide one or multiple paths (files, directories or .jar files) to
`analyze-reify`. It will scan for `.clj` files and analyze them.```
$ analyze-reify ~/git/clojure
clojure.core.protocols/CollReduce
clojure.core.ArrayManager
clojure.lang.IDeref
...Processed 160 files in 111ms. 😎
```To get a sorted frequency list, you can combine this tool with
[babashka](https://github.com/borkdude/babashka/):```
$ analyze-reify ~/git/clojure | bb -io '(->> *input* frequencies (sort-by second >))'
Processed 160 files in 101ms. 😎
[clojure.core.protocols/CollReduce 4]
[clojure.lang.IDeref 4]
[clojure.core.ArrayManager 2]
[java.util.List 2]
[java.util.Iterator 2]
[Elusive 2]
[java.util.ListIterator 2]
[Object 1]
[clojure.lang.ISeq 1]
[clojure.lang.IReduceInit 1]
[clojure.test_clojure.protocols.examples.ExampleInterface 1]
```## Thanks
Thanks to [sogaiu](https://github.com/sogaiu/) for taking the time to implement
[tree-sitter-clojure](https://github.com/sogaiu/tree-sitter-clojure).## License
Copyright © 2020 Michiel Borkent
Distributed under the MIT License. See LICENSE.