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-darwinx86_64-unknown-linux-gnux86_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(debugorrelease,debugis the default value)
- run
make tests/runto run tests - run
make libruby_parser_cpp.a(ormake libruby_parser_cpp.libfor MSVC) to get a static library - run
make lib-ruby-parser.hppto get a header file
- Each directory has its own
build.mkfile 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 scriptsdirectory contains per-triplet additional configurations formakecodegendirectory is a Rust micro-library that does code generationbenchmarkdirectory contains a set of scripts to compare performance of Rust vs C++ vs Ripper