This is a parser for the Ruby programming language, written in C++. It was extracted from the Natalie project.
You can use this library directly from a C/C++ project, or you can build it as a Ruby gem and use it from Ruby itself.
We are currently targeting Ruby 3.0 syntax, but that will probably change over time, depending on what things we want to support and what kind of help we get from the community.
NOTE: This project is still very new and there are certainly bugs. See the list below for things we already know about, but expect there are more we don't know about yet. We don't recommend you use this in production applications.
- Parse the Natalie compiler and standard library
- Pass (mostly) the RubyParser test suite
- Support different source encodings
- Support more of the Ruby 3.0 syntax
- "Endless" method definition (
def foo = bar
) - Argument forwarding (
...
) - Numbered block parameters (
_1
,_2
, etc.) - Rational and Complex literals (
1r
and2i
) - Non-ASCII identifiers
- Pattern matching
- "Endless" method definition (
You'll need:
- gcc or clang
- ruby-dev (dev headers)
- ccache (optional)
- compiledb (optional)
rake
ruby -I lib:ext -r natalie_parser -e "p NatalieParser.parse('1 + 2')"
# => s(:block, s(:call, s(:lit, 1), :+, s(:lit, 2)))
rake test
Natalie is copyright 2022, Tim Morgan and contributors. Natalie is licensed
under the MIT License; see the LICENSE
file in this directory for the full text.
The file test/test_ruby_parser.rb
is copyright Ryan Davis and is licensed MIT.