Esprima (esprima.org) is an educational ECMAScript (also popularly known as JavaScript) parsing infrastructure for multipurpose analysis. It is also written in ECMAScript. This library wraps the Esprima JavaScript library for easy use within Ruby.
At the moment, esprima-rb only supports the Esprima parser / AST generator. If you'd like to add additional functionality, please send a pull request.
Install the gem as you would any other:
gem install esprima
Then, require it in your project:
require 'esprima'
Generate an AST abstract syntax tree by using the Esprima::Parser
class.
parser = Esprima::Parser.new
parser.parse("14 + 6;")
Here's the output for the example above:
{
:type => "Program",
:body => [{
:type => "ExpressionStatement",
:expression => {
:type => "BinaryExpression",
:operator => "+",
:left => {
:type => "Literal",
:value => 14
},
:right => {
:type => "Literal",
:value => 6
}
}
}]
}
No external requirements.
Run bundle exec rake
or bundle exec rspec
.
- Cameron C. Dutro: https://github.com/camertron
- The Esprima team including Ariya Hidayat: https://github.com/ariya
- esprima https://github.com/ariya/esprima
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0