Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

syntax_tree-translator

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

syntax_tree-translator

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

SyntaxTree::Translator

Build Status Gem Version

Translate Syntax Tree syntax trees into other Ruby parser syntax trees.

Installation

Add this line to your application's Gemfile:

gem "syntax_tree-translator"

And then execute:

$ bundle install

Or install it yourself as:

$ gem install syntax_tree-translator

Usage

First, you need to get the source code that you'd like to translate into a syntax tree. Then you need to parse it using Syntax Tree's parse method, as in:

source = ARGF.read
program = SyntaxTree.parse(source)

From there, you now have a SyntaxTree::Program node representing the top of your syntax tree. You can translate that into another format by using one of the provided visitors. Each is detailed below.

parser

To translate into the whitequark/parser gem's syntax tree, instantiate a new source buffer, pass that along with the filename and line number into a new visitor, and call visit.

buffer = Parser::Source::Buffer.new("(string)")
buffer.source = source

visitor = SyntaxTree::Translator::Parser.new(buffer)
node = visitor.visit(program)

rubocop-ast

To translate into the rubocop/rubocop-ast gem's syntax tree (the one used internally by rubocop), you do pretty much the exact same thing as parser, except that it generates more specific node types with helper methods.

buffer = Parser::Source::Buffer.new("(string)")
buffer.source = source

visitor = SyntaxTree::Translator::RuboCop.new(buffer)
node = visitor.visit(program)

ruby_parser

To translate into the seattlerb/ruby_parser gem's syntax tree you instantiate a new visitor and pass it the program instance.

visitor = SyntaxTree::Translator::RubyParser.new
node = visitor.visit(program)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-syntax-tree/syntax_tree-translator.

License

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

FAQs

Package last updated on 20 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc