Giter VIP home page Giter VIP logo

ruby-ast's Introduction

ruby-ast

Ruby to abstract syntax tree converter

Requirements

  • NodeJS 8.9.1+
  • Ruby 1.9+

Installation

npm install @buxlabs/ruby-ast

Why?

Some libraries like rollup or webpack can use assets in various formats to build applications. This tool should be able to convert Ruby code into an abstract syntax tree that can be consumed or converted by other tools, e.g. such that convert ruby to js, which in the end would let you use ruby in js apps.

How does it work?

This package uses Ripper which is a Ruby script parser from the standard library. The method Ripper.sexp is called in a child process via a tiny cli script and returns a json with an abstract syntax tree (a symbolic expression tree, called S-expression).

Examples

import { convert } from '@buxlabs/ruby-ast'
convert('puts "Hello world!"')
.then(result => {
  console.log(result) // [ 'program', [ [ 'command', [Array], [Array] ] ] ]
}) 

Status

Experimental, as most of Ripper methods are not locked. Not suggested for production use.

Instead of relying on a builtin parser it could also be a js lib without any dependencies but the maintenance cost is currently too high.

Todo

  • find good s-expression docs,
  • add more tests,
  • add benchmarks,
  • consider other execution approaches,
  • expose other Ripper methods

ruby-ast's People

Contributors

emilos avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.