lib-ruby-parser (C bindings)
4.0.4+ruby-3.1.1
C bindings for lib-ruby-parser library
|
lib-ruby-parser
All structs, enums and functions are prefixed with LIB_RUBY_PARSER_
. API mostly mirrors Rust version.
Pre-compiled library and header file are available on Releases, supported platforms:
x86_64-apple-darwin
x86_64-unknown-linux-gnu
x86_64-pc-windows-msvc
x86_64-pc-windows-gnu
Parser input:
LIB_RUBY_PARSER_ByteList input
- source code you want to parseLIB_RUBY_PARSER_ParserOptions options
- options of parsing:buffer_name
- name of your source codedecoder
- decoder that is used if there's a magic comment with non-UTF-8 encodingrecord_token
specifies whether tokens should be recorded during parsingtoken_rewriter
- token rewriter, optional, called for each token after lexing but before shifting.Parser output:
LIB_RUBY_PARSER_ParserResult result
- all data that parser can output:LIB_RUBY_PARSER_Node *ast
- pointer to AST whereLIB_RUBY_PARSER_Node
that is a tagged union with tag
and as
fieldsLIB_RUBY_PARSER_Class
LIB_RUBY_PARSER_TokenList tokens
- a list of tokens (ptr
+ len
) whereLIB_RUBY_PARSER_Token
withint32_t token_type
- type of the token (e.g. LIB_RUBY_PARSER_tDEF
)LIB_RUBY_PARSER_Bytes token_value
- value of the tokenLIB_RUBY_PARSER_Loc loc
- location of the tokenint32_t lex_state_before
- state before token was lex-ed (useless unless you have a custom token rewriter)int32_t lex_state_after
- state after token was lex-ed (useless unless you have a custom token rewriter)LIB_RUBY_PARSER_DiagnosticList diagnostics
- a list of diagnostics (ptr
+ len
) whereLIB_RUBY_PARSER_Diagnostic
with fieldsLIB_RUBY_PARSER_ErrorLevel level
- level of the diagnostic (error or warning)LIB_RUBY_PARSER_DiagnosticMessage message
- message that is a tagged union with tag
and as
fields, every message type is represented by its own struct like LIB_RUBY_PARSER_UnterminatedList
LIB_RUBY_PARSER_Loc loc
- location of the diagnosticLIB_RUBY_PARSER_CommentList comments
- a list of comments (ptr
+ len
) whereLIB_RUBY_PARSER_Comment
with fieldsLIB_RUBY_PARSER_Loc location
- location of the commentLIB_RUBY_PARSER_CommentType kind
- kind of the comment (inline/document/unknown)LIB_RUBY_PARSER_MagicCommentList magic_comments
- a list of magic comments (ptr
+ len
) whereLIB_RUBY_PARSER_MagicComment
with fieldsLIB_RUBY_PARSER_MagicCommentKind kind
LIB_RUBY_PARSER_Loc key_l
LIB_RUBY_PARSER_Loc value_l
LIB_RUBY_PARSER_DecodedInput input
- decoded input, is different from initial input if it has encoding different from utf-8, with fields:LIB_RUBY_PARSER_String name
- initial name of the source codeLIB_RUBY_PARSER_SourceLineList lines
- parsed source linesLIB_RUBY_PARSER_ByteList bytes
- (maybe re-encoded) initial inputTARGET
(e.g. export TARGET=x86_64-apple-darwin
, no default value)CC
(e.g. gcc
)BUILD_ENV
(debug
or release
, debug
is the default value)make tests/run
to run testsmake libruby_parser_c.a
(or make libruby_parser_c.lib
for MSVC) to get a static librarymake lib-ruby-parser.h
to get a header filebuild.mk
file that is included my the main Makefile
ruby-parser-c
.*.{h, c}
files in the root directoryscripts
directory contains per-triplet additional configurations for make
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