Skip to content

AppThreat/ruby_ast_gen

Repository files navigation

RubyAstGen

A Ruby parser than dumps the AST as JSON output. Uses both the parser gem and prism gem, thus supports parsing Ruby version 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, and 4.0 syntax with backwards-compatible AST formats.

Usage

The release uses JRuby to enable an effective standalone version. Using jruby, one can run

jruby -S bundle install
jruby -S bundle exec exe/ruby_ast_gen

If using the JAR file, instead you can run

curl 'https://repo1.maven.org/maven2/org/jruby/jruby-complete/9.4.8.0/jruby-complete-9.4.8.0.jar' \
    --output jruby.jar
java -jar jruby.jar \
    -S gem install bundler --install-dir vendor/bundle/jruby/3.1.0
java -jar jruby.jar -s vendor/bundle/jruby/3.1.0/bin/bundle install
java -jar jruby.jar -S vendor/bundle/jruby/3.1.0/bin/bundle exec exe/ruby_ast_gen

The commands are as follows:

usage: ruby_ast_gen [options]
    -i, --input    The input file or directory
    -o, --output   The output directory
    -e, --exclude  The exclusion regex
    -l, --log      The logging level
    --parser-info  Print parser/runtime capability information
    --version      Print the version
    --help         Print usage

To inspect which parser backend will be used in the current runtime, run:

exe/ruby_ast_gen --parser-info

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

The test suite includes a syntax fixture corpus under spec/fixtures/syntax and JSON shape contract specs. Add small fixtures there when supporting new Ruby syntax; use a leading # min_ruby: x.y.z comment for syntax that only parses on newer runtimes.

To install this gem onto your local machine, run bundle exec rake install. To package, run rake build.

License

The gem is available as open source under the terms of the MIT License.

About

A Ruby AST generator tool

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors