Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rajasegar/ruby-ast-explorer
AST Explorer for ruby
https://github.com/rajasegar/ruby-ast-explorer
abstract-syntax-tree ast ast-explorer codemod parser ruby
Last synced: 16 days ago
JSON representation
AST Explorer for ruby
- Host: GitHub
- URL: https://github.com/rajasegar/ruby-ast-explorer
- Owner: rajasegar
- Created: 2019-08-07T02:13:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-01T21:33:37.000Z (over 1 year ago)
- Last Synced: 2024-10-10T16:30:57.205Z (29 days ago)
- Topics: abstract-syntax-tree, ast, ast-explorer, codemod, parser, ruby
- Language: JavaScript
- Homepage: https://ruby-ast-explorer.herokuapp.com/
- Size: 2.77 MB
- Stars: 15
- Watchers: 2
- Forks: 5
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-codemods - Ruby AST Explorer - AST Explorer for Ruby. (Ruby)
README
# ruby-ast-explorer
AST Explorer lets you to visualize your ruby code as AST(Abstract Syntax Trees).
This uses the [parser](https://github.com/whitequark/parser) gem to convert the source code into ASTs
and the [TreeWriter](https://www.rubydoc.info/github/whitequark/parser/Parser/TreeRewriter) class
of the gem to apply transformations on the AST nodes and convert them back to source code.We can take the transformation logic and put into a ruby file like `transform.rb` and use
the same to do large scale refactorings with your ruby code base using tools like [codeshift](https://github.com/rajasegar/codeshift) and [cybertron](https://github.com/rajasegar/cybertron).```sh
$ codeshift -t transform.rb app/models/**/*.rb
```## Export as gist
You can also export the source and transform code as gist to your Github account by clicking
the `Export as gist` button. But before that you need to sign in with Github and give permission to create gists for this app named ruby-ast-explorer.And with that you can directly use the transform from your gist.
```sh
$ codeshift -t https://gist.githubusercontent.com/[user]/.../transform.rb app/models/**/*.rb
```It has got four panes with the following content:
* Top-Left => Original Source Code
* Top-Right => AST in Tree and S-expressions formats
* Bottom-Left => Transform Class
* Bottom-Right => Output![screenshot](https://github.com/rajasegar/ruby-ast-explorer/blob/master/public/screenshot.png)
## Reference:
* https://whitequark.org/blog/2013/04/26/lets-play-with-ruby-code/
* https://blog.arkency.com/using-ruby-parser-and-ast-tree-to-find-deprecated-syntax/
* https://blog.arkency.com/rewriting-deprecated-apis-with-parser-gem/
* https://gist.github.com/jonatas/e70c874cbbd0cac5a9abd9f4a78fa816
* https://github.com/jonatas/fast
* http://www.zenspider.com/projects/ruby2ruby.html
* [Parsing Ruby](https://whitequark.org/blog/2012/10/02/parsing-ruby/)
* [awesome-ruby-ast](https://github.com/rajasegar/awesome-ruby-ast)Inspired by [AST Explorer](https://astexplorer.net) by [Felix Kling](https://github.com/fkling)
## Tools
* [parser gem](https://github.com/whitequark/parser)
* [CodeMirror](https://codemirror.net/)## Other related tools
* [Astrolabe](https://github.com/yujinakayama/astrolabe)
* [codeshift](https://github.com/rajasegar/codeshift)
* [cybertron](https://github.com/rajasegar/cybertron)