1#include "prism/extension.h"
14VALUE rb_cPrismLocation;
16VALUE rb_cPrismComment;
17VALUE rb_cPrismInlineComment;
18VALUE rb_cPrismEmbDocComment;
19VALUE rb_cPrismMagicComment;
20VALUE rb_cPrismParseError;
21VALUE rb_cPrismParseWarning;
23VALUE rb_cPrismParseResult;
24VALUE rb_cPrismLexResult;
25VALUE rb_cPrismParseLexResult;
26VALUE rb_cPrismStringQuery;
28VALUE rb_cPrismCurrentVersionError;
30VALUE rb_cPrismDebugEncoding;
32ID rb_id_option_command_line;
33ID rb_id_option_encoding;
34ID rb_id_option_filepath;
35ID rb_id_option_freeze;
36ID rb_id_option_frozen_string_literal;
38ID rb_id_option_main_script;
39ID rb_id_option_partial_script;
40ID rb_id_option_scopes;
41ID rb_id_option_version;
43ID rb_id_forwarding_positionals;
44ID rb_id_forwarding_keywords;
45ID rb_id_forwarding_block;
46ID rb_id_forwarding_all;
57check_string(
VALUE value) {
64 return RSTRING_PTR(value);
77 pm_string_constant_init(input, RSTRING_PTR(
string), RSTRING_LEN(
string));
101 for (
size_t scope_index = 0; scope_index < scopes_count; scope_index++) {
123 for (
size_t name_index = 0; name_index < names_count; name_index++) {
133 if (
id == rb_id_forwarding_positionals) {
135 }
else if (
id == rb_id_forwarding_keywords) {
137 }
else if (
id == rb_id_forwarding_block) {
139 }
else if (
id == rb_id_forwarding_all) {
142 rb_raise(rb_eArgError,
"invalid forwarding value: %" PRIsVALUE, name);
157 for (
size_t local_index = 0; local_index < locals_count; local_index++) {
168 const char *name = rb_id2name(
SYM2ID(local));
169 pm_string_constant_init(scope_local, name, strlen(name));
185 if (key_id == rb_id_option_filepath) {
187 }
else if (key_id == rb_id_option_encoding) {
195 }
else if (key_id == rb_id_option_line) {
197 }
else if (key_id == rb_id_option_frozen_string_literal) {
199 }
else if (key_id == rb_id_option_version) {
201 const char *version = check_string(value);
203 if (RSTRING_LEN(value) == 7 && strncmp(version,
"current", 7) == 0) {
204 const char *current_version = RSTRING_PTR(
rb_const_get(rb_cObject, rb_intern(
"RUBY_VERSION")));
209 rb_raise(rb_eArgError,
"invalid version: %" PRIsVALUE, value);
212 }
else if (key_id == rb_id_option_scopes) {
213 if (!
NIL_P(value)) build_options_scopes(options, value);
214 }
else if (key_id == rb_id_option_command_line) {
216 const char *
string = check_string(value);
217 uint8_t command_line = 0;
219 for (
size_t index = 0; index < strlen(
string); index++) {
220 switch (
string[index]) {
227 default: rb_raise(rb_eArgError,
"invalid command line flag: '%c'",
string[index]);
break;
233 }
else if (key_id == rb_id_option_main_script) {
235 }
else if (key_id == rb_id_option_partial_script) {
237 }
else if (key_id == rb_id_option_freeze) {
240 rb_raise(rb_eArgError,
"unknown keyword: %" PRIsVALUE, key);
261build_options(
VALUE argument) {
274 if (!
NIL_P(keywords)) {
279 rb_protect(build_options, (
VALUE) argument, &state);
287 if (!
NIL_P(filepath)) {
306 extract_options(options,
Qnil, keywords);
307 input_load_string(input,
string);
320 *encoded_filepath = rb_str_encode_ospath(filepath);
321 extract_options(options, *encoded_filepath, keywords);
333 int e = rb_w32_map_errno(GetLastError());
347 rb_raise(
rb_eRuntimeError,
"Unknown error (%d) initializing file: %s", result, source);
352#ifndef PRISM_EXCLUDE_SERIALIZATION
372 pm_serialize(&parser, node, &buffer);
375 pm_node_destroy(&parser, node);
393 string_options(argc, argv, &input, &options);
395#ifdef PRISM_BUILD_DEBUG
399 pm_string_constant_init(&input, dup, length);
402 VALUE value = dump_input(&input, &options);
405#ifdef PRISM_BUILD_DEBUG
427 VALUE encoded_filepath;
428 file_options(argc, argv, &input, &options, &encoded_filepath);
430 VALUE value = dump_input(&input, &options);
448rb_class_new_instance_freeze(
int argc,
const VALUE *argv,
VALUE klass,
bool freeze) {
458parser_location(
const pm_parser_t *parser,
VALUE source,
bool freeze,
const uint8_t *start,
size_t length) {
460 return rb_class_new_instance_freeze(3, argv, rb_cPrismLocation, freeze);
466#define PARSER_LOCATION_LOC(parser, source, freeze, loc) \
467 parser_location(parser, source, freeze, loc.start, (size_t) (loc.end - loc.start))
474 VALUE argv[] = { PARSER_LOCATION_LOC(parser, source, freeze, comment->
location) };
475 VALUE type = (comment->
type == PM_COMMENT_EMBDOC) ? rb_cPrismEmbDocComment : rb_cPrismInlineComment;
476 return rb_class_new_instance_freeze(1, argv,
type, freeze);
491 VALUE value = parser_comment(parser, source, freeze, comment);
506 VALUE argv[] = { key_loc, value_loc };
507 return rb_class_new_instance_freeze(2, argv, rb_cPrismMagicComment, freeze);
514parser_magic_comments(
const pm_parser_t *parser,
VALUE source,
bool freeze) {
527 return magic_comments;
539 return PARSER_LOCATION_LOC(parser, source, freeze, parser->
data_loc);
555 VALUE type =
ID2SYM(rb_intern(pm_diagnostic_id_human(error->diag_id)));
557 VALUE location = PARSER_LOCATION_LOC(parser, source, freeze, error->location);
560 switch (error->level) {
562 level =
ID2SYM(rb_intern(
"syntax"));
565 level =
ID2SYM(rb_intern(
"argument"));
568 level =
ID2SYM(rb_intern(
"load"));
574 VALUE argv[] = {
type, message, location, level };
575 VALUE value = rb_class_new_instance_freeze(4, argv, rb_cPrismParseError, freeze);
595 VALUE type =
ID2SYM(rb_intern(pm_diagnostic_id_human(warning->diag_id)));
597 VALUE location = PARSER_LOCATION_LOC(parser, source, freeze, warning->location);
600 switch (warning->level) {
602 level =
ID2SYM(rb_intern(
"default"));
605 level =
ID2SYM(rb_intern(
"verbose"));
611 VALUE argv[] = {
type, message, location, level };
612 VALUE value = rb_class_new_instance_freeze(4, argv, rb_cPrismParseWarning, freeze);
625 VALUE result_argv[] = {
627 parser_comments(parser, source, freeze),
628 parser_magic_comments(parser, source, freeze),
629 parser_data_loc(parser, source, freeze),
630 parser_errors(parser, encoding, source, freeze),
631 parser_warnings(parser, encoding, source, freeze),
635 return rb_class_new_instance_freeze(7, result_argv,
class, freeze);
663 VALUE value = pm_token_new(parser, token, parse_lex_data->encoding, parse_lex_data->source, parse_lex_data->freeze);
666 if (parse_lex_data->freeze) {
680parse_lex_encoding_changed_callback(
pm_parser_t *parser) {
682 parse_lex_data->encoding = rb_enc_find(parser->
encoding->
name);
688 VALUE tokens = parse_lex_data->tokens;
691 for (
long index = 0; index <
RARRAY_LEN(tokens); index++) {
698 rb_enc_associate(next_value, parse_lex_data->encoding);
701 VALUE next_token_argv[] = {
702 parse_lex_data->source,
711 if (parse_lex_data->freeze) {
739 .encoding = rb_utf8_encoding(),
740 .freeze = options->
freeze,
745 .
data = (
void *) data,
746 .callback = parse_lex_token,
757 rb_enc_associate(source_string, encoding);
773 rb_ary_push(value, pm_ast_new(&parser, node, parse_lex_data.encoding, source, options->
freeze));
776 result = parse_result_create(rb_cPrismParseLexResult, &parser, value, parse_lex_data.encoding, source, options->
freeze);
778 result = parse_result_create(rb_cPrismLexResult, &parser, parse_lex_data.tokens, parse_lex_data.encoding, source, options->
freeze);
781 pm_node_destroy(&parser, node);
798 string_options(argc, argv, &input, &options);
800 VALUE result = parse_lex_input(&input, &options,
false);
819 VALUE encoded_filepath;
820 file_options(argc, argv, &input, &options, &encoded_filepath);
822 VALUE value = parse_lex_input(&input, &options,
false);
844 VALUE source = pm_source_new(&parser, encoding, options->
freeze);
845 VALUE value = pm_ast_new(&parser, node, encoding, source, options->
freeze);
846 VALUE result = parse_result_create(rb_cPrismParseResult, &parser, value, encoding, source, options->
freeze);
852 pm_node_destroy(&parser, node);
904 string_options(argc, argv, &input, &options);
906#ifdef PRISM_BUILD_DEBUG
910 pm_string_constant_init(&input, dup, length);
913 VALUE value = parse_input(&input, &options);
915#ifdef PRISM_BUILD_DEBUG
932parse_file(
int argc,
VALUE *argv,
VALUE self) {
936 VALUE encoded_filepath;
937 file_options(argc, argv, &input, &options, &encoded_filepath);
939 VALUE value = parse_input(&input, &options);
955 pm_node_destroy(&parser, node);
972 string_options(argc, argv, &input, &options);
973 profile_input(&input, &options);
989profile_file(
int argc,
VALUE *argv,
VALUE self) {
993 VALUE encoded_filepath;
994 file_options(argc, argv, &input, &options, &encoded_filepath);
996 profile_input(&input, &options);
1004parse_stream_eof(
void *stream) {
1015parse_stream_fgets(
char *
string,
int size,
void *stream) {
1023 const char *cstr = RSTRING_PTR(line);
1024 long length = RSTRING_LEN(line);
1026 memcpy(
string, cstr, length);
1027 string[length] =
'\0';
1040parse_stream(
int argc,
VALUE *argv,
VALUE self) {
1046 extract_options(&options,
Qnil, keywords);
1051 pm_node_t *node =
pm_parse_stream(&parser, &buffer, (
void *) stream, parse_stream_fgets, parse_stream_eof, &options);
1054 VALUE source = pm_source_new(&parser, encoding, options.
freeze);
1055 VALUE value = pm_ast_new(&parser, node, encoding, source, options.
freeze);
1056 VALUE result = parse_result_create(rb_cPrismParseResult, &parser, value, encoding, source, options.
freeze);
1058 pm_node_destroy(&parser, node);
1076 VALUE source = pm_source_new(&parser, encoding, options->
freeze);
1077 VALUE comments = parser_comments(&parser, source, options->
freeze);
1079 pm_node_destroy(&parser, node);
1093parse_comments(
int argc,
VALUE *argv,
VALUE self) {
1096 string_options(argc, argv, &input, &options);
1098 VALUE result = parse_input_comments(&input, &options);
1113parse_file_comments(
int argc,
VALUE *argv,
VALUE self) {
1117 VALUE encoded_filepath;
1118 file_options(argc, argv, &input, &options, &encoded_filepath);
1120 VALUE value = parse_input_comments(&input, &options);
1142parse_lex(
int argc,
VALUE *argv,
VALUE self) {
1145 string_options(argc, argv, &input, &options);
1147 VALUE value = parse_lex_input(&input, &options,
true);
1169parse_lex_file(
int argc,
VALUE *argv,
VALUE self) {
1173 VALUE encoded_filepath;
1174 file_options(argc, argv, &input, &options, &encoded_filepath);
1176 VALUE value = parse_lex_input(&input, &options,
true);
1192 pm_node_destroy(&parser, node);
1208parse_success_p(
int argc,
VALUE *argv,
VALUE self) {
1211 string_options(argc, argv, &input, &options);
1213 VALUE result = parse_input_success_p(&input, &options);
1228parse_failure_p(
int argc,
VALUE *argv,
VALUE self) {
1240parse_file_success_p(
int argc,
VALUE *argv,
VALUE self) {
1244 VALUE encoded_filepath;
1245 file_options(argc, argv, &input, &options, &encoded_filepath);
1247 VALUE result = parse_input_success_p(&input, &options);
1262parse_file_failure_p(
int argc,
VALUE *argv,
VALUE self) {
1278 rb_raise(rb_eArgError,
"Invalid or non ascii-compatible encoding");
1297string_query_local_p(
VALUE self,
VALUE string) {
1298 const uint8_t *source = (
const uint8_t *) check_string(
string);
1299 return string_query(pm_string_query_local(source, RSTRING_LEN(
string), rb_enc_get(
string)->name));
1311string_query_constant_p(
VALUE self,
VALUE string) {
1312 const uint8_t *source = (
const uint8_t *) check_string(
string);
1313 return string_query(pm_string_query_constant(source, RSTRING_LEN(
string), rb_enc_get(
string)->name));
1323string_query_method_name_p(
VALUE self,
VALUE string) {
1324 const uint8_t *source = (
const uint8_t *) check_string(
string);
1325 return string_query(pm_string_query_method_name(source, RSTRING_LEN(
string), rb_enc_get(
string)->name));
1335RUBY_FUNC_EXPORTED
void
1339 if (strcmp(pm_version(), EXPECTED_PRISM_VERSION) != 0) {
1342 "The prism library version (%s) does not match the expected version (%s)",
1344 EXPECTED_PRISM_VERSION
1348#ifdef HAVE_RB_EXT_RACTOR_SAFE
1373 rb_cPrismCurrentVersionError =
rb_const_get(rb_cPrism, rb_intern(
"CurrentVersionError"));
1381 rb_id_option_frozen_string_literal =
rb_intern_const(
"frozen_string_literal");
1387 rb_id_source_for = rb_intern(
"for");
1388 rb_id_forwarding_positionals = rb_intern(
"*");
1389 rb_id_forwarding_keywords = rb_intern(
"**");
1390 rb_id_forwarding_block = rb_intern(
"&");
1391 rb_id_forwarding_all = rb_intern(
"...");
1415#ifndef PRISM_EXCLUDE_SERIALIZATION
1425 Init_prism_api_node();
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
@ PM_WARNING_LEVEL_DEFAULT
For warnings which should be emitted if $VERBOSE != nil.
@ PM_WARNING_LEVEL_VERBOSE
For warnings which should be emitted if $VERBOSE == true.
@ PM_ERROR_LEVEL_ARGUMENT
For errors that should raise an argument error.
@ PM_ERROR_LEVEL_LOAD
For errors that should raise a load error.
@ PM_ERROR_LEVEL_SYNTAX
For errors that should raise a syntax error.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
Defines a top-level module.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
#define T_STRING
Old name of RUBY_T_STRING.
#define xfree
Old name of ruby_xfree.
#define INT2FIX
Old name of RB_INT2FIX.
#define ID2SYM
Old name of RB_ID2SYM.
#define ULONG2NUM
Old name of RB_ULONG2NUM.
#define SYM2ID
Old name of RB_SYM2ID.
#define xmalloc
Old name of ruby_xmalloc.
#define LONG2FIX
Old name of RB_INT2FIX.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define Qtrue
Old name of RUBY_Qtrue.
#define NUM2INT
Old name of RB_NUM2INT.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_syserr_fail(int e, const char *mesg)
Raises appropriate exception that represents a C errno.
VALUE rb_eNoMemError
NoMemoryError exception.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given class.
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
VALUE rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
Identical to rb_enc_str_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_ary_replace(VALUE copy, VALUE orig)
Replaces the contents of the former object with the contents of the latter.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Identical to rb_ary_new_from_values(), except it expects exactly two parameters.
void rb_ext_ractor_safe(bool flag)
Asserts that the extension library that calls this function is aware of Ractor.
#define rb_str_new(str, len)
Allocates an instance of rb_cString.
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
VALUE rb_str_freeze(VALUE str)
This is the implementation of String#freeze.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_const_get(VALUE space, ID name)
Identical to rb_const_defined(), except it returns the actual defined value.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_hash_foreach(VALUE q, int_type *w, VALUE e)
Iteration over the given hash.
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding)
Set the encoding option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options)
Free the internal memory associated with the options.
PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options, bool partial_script)
Set the partial script option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script)
Set the main script option on the given options struct.
PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const char *version, size_t length)
Set the version option on the given options struct by parsing the given string.
PRISM_EXPORTED_FUNCTION bool pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count)
Create a new options scope struct.
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line)
Set the line option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_freeze_set(pm_options_t *options, bool freeze)
Set the freeze option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked)
Set the encoding_locked option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal)
Set the frozen string literal option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line)
Sets the command line option on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath)
Set the filepath option on the given options struct.
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count)
Allocate and zero out the scopes array on the given options struct.
PRISM_EXPORTED_FUNCTION void pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding)
Set the forwarding option on the given scope struct.
static const uint8_t PM_OPTIONS_COMMAND_LINE_E
A bit representing whether or not the command line -e option was set.
static const uint8_t PM_OPTIONS_COMMAND_LINE_L
A bit representing whether or not the command line -l option was set.
static const uint8_t PM_OPTIONS_COMMAND_LINE_A
A bit representing whether or not the command line -a option was set.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_NONE
The default value for parameters.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_ALL
When the scope is fowarding with the ... parameter.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_POSITIONALS
When the scope is fowarding with the * parameter.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_KEYWORDS
When the scope is fowarding with the ** parameter.
static const uint8_t PM_OPTIONS_COMMAND_LINE_N
A bit representing whether or not the command line -n option was set.
static const uint8_t PM_OPTIONS_COMMAND_LINE_X
A bit representing whether or not the command line -x option was set.
static const uint8_t PM_OPTIONS_SCOPE_FORWARDING_BLOCK
When the scope is fowarding with the & parameter.
static const uint8_t PM_OPTIONS_COMMAND_LINE_P
A bit representing whether or not the command line -p option was set.
void pm_buffer_free(pm_buffer_t *buffer)
Free the memory associated with the buffer.
bool pm_buffer_init(pm_buffer_t *buffer)
Initialize a pm_buffer_t with its default values.
size_t pm_buffer_length(const pm_buffer_t *buffer)
Return the length of the buffer.
char * pm_buffer_value(const pm_buffer_t *buffer)
Return the value of the buffer.
PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string)
Returns the length associated with the string.
PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string)
Returns the start pointer associated with the string.
PRISM_EXPORTED_FUNCTION void pm_string_free(pm_string_t *string)
Free the associated memory of the given string.
PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_file_init(pm_string_t *string, const char *filepath)
Read the file indicated by the filepath parameter into source and load its contents and size into the...
pm_string_init_result_t
Represents the result of calling pm_string_mapped_init or pm_string_file_init.
@ PM_STRING_INIT_SUCCESS
Indicates that the string was successfully initialized.
@ PM_STRING_INIT_ERROR_GENERIC
Indicates a generic error from a string_*_init function, where the type of error should be read from ...
@ PM_STRING_INIT_ERROR_DIRECTORY
Indicates that the file that was attempted to be opened was a directory.
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser)
Parse the Ruby source associated with the given parser and return the tree.
PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback(pm_parser_t *parser, pm_encoding_changed_callback_t callback)
Register a callback that will be called whenever prism changes the encoding it is using to parse base...
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser)
Free any memory associated with the given parser.
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse_stream(pm_parser_t *parser, pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *stream_fgets, pm_parse_stream_feof_t *stream_feof, const pm_options_t *options)
Parse a stream of Ruby source and return the tree.
PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm_options_t *options)
Initialize a parser with the given start and end pointers.
pm_string_query_t
Represents the results of a slice query.
@ PM_STRING_QUERY_TRUE
Returned if the result of the slice query is true.
@ PM_STRING_QUERY_ERROR
Returned if the encoding given to a slice query was invalid.
@ PM_STRING_QUERY_FALSE
Returned if the result of the slice query is false.
#define RARRAY_LEN
Just another name of rb_array_len.
#define errno
Ractor-aware version of errno.
#define RTEST
This is an old name of RB_TEST.
We need a struct here to pass through rb_protect and it has to be a single value.
This struct gets stored in the parser and passed in to the lex callback any time a new token is found...
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory.
This struct represents a diagnostic generated during parsing.
const char * name
The name of the encoding.
When you are lexing through a file, the lexer needs all of the information that the parser additional...
void * data
This opaque pointer is used to provide whatever information the user deemed necessary to the callback...
pm_list_node_t * head
A pointer to the head of the list.
size_t size
The size of the list.
const uint8_t * end
A pointer to the end location of the range in the source.
size_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.
This is the base structure that represents a node in the syntax tree.
A scope of locals surrounding the code that is being parsed.
pm_string_t * locals
The names of the locals in the scope.
The options that can be passed to the parser.
bool freeze
Whether or not the parser should freeze the nodes that it creates.
pm_options_scope_t * scopes
The scopes surrounding the code that is being parsed.
int32_t line
The line within the file that the parse starts on.
pm_string_t filepath
The name of the file that is currently being parsed.
This struct represents the overall parser.
pm_lex_state_t lex_state
The current state of the lexer.
const pm_encoding_t * encoding
The encoding functions for the current file is attached to the parser as it's parsing so that it can ...
pm_list_t magic_comment_list
The list of magic comments that have been found while parsing.
pm_lex_callback_t * lex_callback
This is an optional callback that can be attached to the parser that will be called whenever a new to...
pm_location_t data_loc
An optional location that represents the location of the END marker and the rest of the content of th...
const uint8_t * start
The pointer to the start of the source.
pm_list_t error_list
The list of errors that have been found while parsing.
pm_list_t warning_list
The list of warnings that have been found while parsing.
int32_t start_line
The line number at the start of the parse.
pm_list_t comment_list
The list of comments that have been found while parsing.
pm_newline_list_t newline_list
This is the list of newline offsets in the source file.
A generic string type that can have various ownership semantics.
This struct represents a token in the Ruby source.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.