Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

NatalieParser is a zero-dependency, from-scratch, hand-written recursive descent parser for the Ruby Programming Language.

License

Notifications You must be signed in to change notification settings

natalie-lang/natalie_parser

Repository files navigation

Natalie Parser

NOT MAINTAINED: This parser has been archived in favor of Prism. Natalie now uses Prism instead.

Gem Version github build status MIT License

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.

To Do

  • 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 and 2i)
    • Non-ASCII identifiers
    • Pattern matching

Development

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)))

Running Tests

rake test

Copyright & License

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.

Note about Outside Sources

The file test/test_ruby_parser.rb is copyright Ryan Davis and is licensed MIT.

About

NatalieParser is a zero-dependency, from-scratch, hand-written recursive descent parser for the Ruby Programming Language.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published