All classes/methods are defined under lib_ruby_parser
namespace. API mostly mirrors Rust version.
Pre-compiled libraries and header files are available on Releases, supported platforms:
x86_64-apple-darwin
x86_64-unknown-linux-gnu
x86_64-pc-windows-msvc
// Configure parsing options
lib_ruby_parser::ParserOptions options(
/* 1. filename */
lib_ruby_parser::String::Copied("(eval)"),
/* 2. decoder */
lib_ruby_parser::MaybeDecoder(lib_ruby_parser::Decoder(nullptr)),
/* 3. token_rewriter */
lib_ruby_parser::MaybeTokenRewriter(lib_ruby_parser::TokenRewriter(nullptr)),
/* 4. record_tokens */
true);
// Setup input to parse
lib_ruby_parser::ByteList input = lib_ruby_parser::ByteList::Copied("2 + 3", 5);
lib_ruby_parser::ParserResult result = lib_ruby_parser::parse(
std::move(input),
std::move(options));
assert_eq(result.ast->tag, lib_ruby_parser::Node::Tag::SEND);
assert_eq(result.tokens.len, 4); // tINT tPLUS tINT EOF
assert_eq(result.comments.len, 0);
assert_eq(result.magic_comments.len, 0);
assert_byte_list(result.input.bytes, "2 + 3");
ParserResult
contains the following fields:
Node* ast
- potentually nullable AST, tagged enumTokenList tokens
- list of tokensDiagnosticList diagnostics
- list of diagnosticsCommentList comments
- list of commentsMagicCommentList magic_comments
- list of magic commentsDecodedInput input
- decoded input
All node classes fully match node structs of the original Rust implementation. You can check full documentation (nodes
module)
- Clone the repo
- Set environment variables:
TARGET
(e.g.export TARGET=x86_64-apple-darwin
, no default value)CXX
(e.g.g++
)BUILD_ENV
(debug
orrelease
,debug
is the default value)
- run
make tests/run
to run tests - run
make libruby_parser_cpp.a
(ormake libruby_parser_cpp.lib
for MSVC) to get a static library - run
make lib-ruby-parser.hpp
to get a header file
- Each directory has its own
build.mk
file that is included my the mainMakefile
- Rust parser with basic C++ bindings is located under
ruby-parser-cpp
. - Actual C++ bindings are located in
*.{hpp, cpp}
files in the root directory scripts
directory contains per-triplet additional configurations formake
codegen
directory is a Rust micro-library that does code generationbenchmark
directory contains a set of scripts to compare performance of Rust vs C++ vs Ripper