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;
29VALUE rb_cPrismDebugEncoding;
31ID rb_id_option_command_line;
32ID rb_id_option_encoding;
33ID rb_id_option_filepath;
34ID rb_id_option_freeze;
35ID rb_id_option_frozen_string_literal;
37ID rb_id_option_main_script;
38ID rb_id_option_partial_script;
39ID rb_id_option_scopes;
40ID rb_id_option_version;
42ID rb_id_forwarding_positionals;
43ID rb_id_forwarding_keywords;
44ID rb_id_forwarding_block;
45ID rb_id_forwarding_all;
56check_string(
VALUE value) {
63 return RSTRING_PTR(value);
76 pm_string_constant_init(input, RSTRING_PTR(
string), RSTRING_LEN(
string));
95 if (!pm_options_scopes_init(options, scopes_count)) {
100 for (
size_t scope_index = 0; scope_index < scopes_count; scope_index++) {
101 VALUE scope = rb_ary_entry(scopes, scope_index);
122 for (
size_t name_index = 0; name_index < names_count; name_index++) {
123 VALUE name = rb_ary_entry(names, name_index);
132 if (
id == rb_id_forwarding_positionals) {
134 }
else if (
id == rb_id_forwarding_keywords) {
136 }
else if (
id == rb_id_forwarding_block) {
138 }
else if (
id == rb_id_forwarding_all) {
141 rb_raise(rb_eArgError,
"invalid forwarding value: %" PRIsVALUE, name);
151 if (!pm_options_scope_init(options_scope, locals_count)) {
156 for (
size_t local_index = 0; local_index < locals_count; local_index++) {
157 VALUE local = rb_ary_entry(locals, local_index);
167 const char *name = rb_id2name(
SYM2ID(local));
168 pm_string_constant_init(scope_local, name, strlen(name));
172 pm_options_scope_forwarding_set(options_scope, forwarding);
184 if (key_id == rb_id_option_filepath) {
185 if (!
NIL_P(value)) pm_options_filepath_set(options, check_string(value));
186 }
else if (key_id == rb_id_option_encoding) {
189 pm_options_encoding_locked_set(options,
true);
191 pm_options_encoding_set(options, rb_enc_name(rb_to_encoding(value)));
194 }
else if (key_id == rb_id_option_line) {
195 if (!
NIL_P(value)) pm_options_line_set(options,
NUM2INT(value));
196 }
else if (key_id == rb_id_option_frozen_string_literal) {
197 if (!
NIL_P(value)) pm_options_frozen_string_literal_set(options,
RTEST(value));
198 }
else if (key_id == rb_id_option_version) {
200 const char *version = check_string(value);
202 if (!pm_options_version_set(options, version, RSTRING_LEN(value))) {
203 rb_raise(rb_eArgError,
"invalid version: %" PRIsVALUE, value);
206 }
else if (key_id == rb_id_option_scopes) {
207 if (!
NIL_P(value)) build_options_scopes(options, value);
208 }
else if (key_id == rb_id_option_command_line) {
210 const char *
string = check_string(value);
211 uint8_t command_line = 0;
213 for (
size_t index = 0; index < strlen(
string); index++) {
214 switch (
string[index]) {
221 default: rb_raise(rb_eArgError,
"invalid command line flag: '%c'",
string[index]);
break;
225 pm_options_command_line_set(options, command_line);
227 }
else if (key_id == rb_id_option_main_script) {
228 if (!
NIL_P(value)) pm_options_main_script_set(options,
RTEST(value));
229 }
else if (key_id == rb_id_option_partial_script) {
230 if (!
NIL_P(value)) pm_options_partial_script_set(options,
RTEST(value));
231 }
else if (key_id == rb_id_option_freeze) {
232 if (!
NIL_P(value)) pm_options_freeze_set(options,
RTEST(value));
234 rb_raise(rb_eArgError,
"unknown keyword: %" PRIsVALUE, key);
255build_options(
VALUE argument) {
268 if (!
NIL_P(keywords)) {
273 rb_protect(build_options, (
VALUE) argument, &state);
276 pm_options_free(options);
281 if (!
NIL_P(filepath)) {
283 pm_options_free(options);
287 pm_options_filepath_set(options, RSTRING_PTR(filepath));
300 extract_options(options,
Qnil, keywords);
301 input_load_string(input,
string);
314 *encoded_filepath = rb_str_encode_ospath(filepath);
315 extract_options(options, *encoded_filepath, keywords);
317 const char *source = (
const char *) pm_string_source(&options->
filepath);
320 switch (result = pm_string_file_init(input, source)) {
324 pm_options_free(options);
327 int e = rb_w32_map_errno(GetLastError());
336 pm_options_free(options);
340 pm_options_free(options);
341 rb_raise(
rb_eRuntimeError,
"Unknown error (%d) initializing file: %s", result, source);
346#ifndef PRISM_EXCLUDE_SERIALIZATION
358 if (!pm_buffer_init(&buffer)) {
363 pm_parser_init(&parser, pm_string_source(input), pm_string_length(input), options);
365 pm_node_t *node = pm_parse(&parser);
366 pm_serialize(&parser, node, &buffer);
368 VALUE result =
rb_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer));
369 pm_node_destroy(&parser, node);
370 pm_buffer_free(&buffer);
371 pm_parser_free(&parser);
387 string_options(argc, argv, &input, &options);
389#ifdef PRISM_BUILD_DEBUG
390 size_t length = pm_string_length(&input);
392 memcpy(dup, pm_string_source(&input), length);
393 pm_string_constant_init(&input, dup, length);
396 VALUE value = dump_input(&input, &options);
399#ifdef PRISM_BUILD_DEBUG
403 pm_string_free(&input);
404 pm_options_free(&options);
421 VALUE encoded_filepath;
422 file_options(argc, argv, &input, &options, &encoded_filepath);
424 VALUE value = dump_input(&input, &options);
425 pm_string_free(&input);
426 pm_options_free(&options);
442rb_class_new_instance_freeze(
int argc,
const VALUE *argv,
VALUE klass,
bool freeze) {
452parser_location(
const pm_parser_t *parser,
VALUE source,
bool freeze,
const uint8_t *start,
size_t length) {
454 return rb_class_new_instance_freeze(3, argv, rb_cPrismLocation, freeze);
460#define PARSER_LOCATION_LOC(parser, source, freeze, loc) \
461 parser_location(parser, source, freeze, loc.start, (size_t) (loc.end - loc.start))
468 VALUE argv[] = { PARSER_LOCATION_LOC(parser, source, freeze, comment->
location) };
469 VALUE type = (comment->
type == PM_COMMENT_EMBDOC) ? rb_cPrismEmbDocComment : rb_cPrismInlineComment;
470 return rb_class_new_instance_freeze(1, argv,
type, freeze);
485 VALUE value = parser_comment(parser, source, freeze, comment);
486 rb_ary_push(comments, value);
500 VALUE argv[] = { key_loc, value_loc };
501 return rb_class_new_instance_freeze(2, argv, rb_cPrismMagicComment, freeze);
508parser_magic_comments(
const pm_parser_t *parser,
VALUE source,
bool freeze) {
517 rb_ary_push(magic_comments, value);
521 return magic_comments;
533 return PARSER_LOCATION_LOC(parser, source, freeze, parser->
data_loc);
541parser_errors(
const pm_parser_t *parser, rb_encoding *encoding,
VALUE source,
bool freeze) {
549 VALUE type =
ID2SYM(rb_intern(pm_diagnostic_id_human(error->diag_id)));
551 VALUE location = PARSER_LOCATION_LOC(parser, source, freeze, error->location);
554 switch (error->level) {
556 level =
ID2SYM(rb_intern(
"syntax"));
559 level =
ID2SYM(rb_intern(
"argument"));
562 level =
ID2SYM(rb_intern(
"load"));
568 VALUE argv[] = {
type, message, location, level };
569 VALUE value = rb_class_new_instance_freeze(4, argv, rb_cPrismParseError, freeze);
570 rb_ary_push(errors, value);
581parser_warnings(
const pm_parser_t *parser, rb_encoding *encoding,
VALUE source,
bool freeze) {
589 VALUE type =
ID2SYM(rb_intern(pm_diagnostic_id_human(warning->diag_id)));
591 VALUE location = PARSER_LOCATION_LOC(parser, source, freeze, warning->location);
594 switch (warning->level) {
596 level =
ID2SYM(rb_intern(
"default"));
599 level =
ID2SYM(rb_intern(
"verbose"));
605 VALUE argv[] = {
type, message, location, level };
606 VALUE value = rb_class_new_instance_freeze(4, argv, rb_cPrismParseWarning, freeze);
607 rb_ary_push(warnings, value);
619 VALUE result_argv[] = {
621 parser_comments(parser, source, freeze),
622 parser_magic_comments(parser, source, freeze),
623 parser_data_loc(parser, source, freeze),
624 parser_errors(parser, encoding, source, freeze),
625 parser_warnings(parser, encoding, source, freeze),
629 return rb_class_new_instance_freeze(7, result_argv,
class, freeze);
644 rb_encoding *encoding;
657 VALUE value = pm_token_new(parser, token, parse_lex_data->encoding, parse_lex_data->source, parse_lex_data->freeze);
660 if (parse_lex_data->freeze) {
665 rb_ary_push(parse_lex_data->tokens, yields);
674parse_lex_encoding_changed_callback(
pm_parser_t *parser) {
676 parse_lex_data->encoding = rb_enc_find(parser->
encoding->
name);
682 VALUE tokens = parse_lex_data->tokens;
685 for (
long index = 0; index <
RARRAY_LEN(tokens); index++) {
686 VALUE yields = rb_ary_entry(tokens, index);
687 VALUE token = rb_ary_entry(yields, 0);
692 rb_enc_associate(next_value, parse_lex_data->encoding);
695 VALUE next_token_argv[] = {
696 parse_lex_data->source,
703 VALUE next_yields = rb_assoc_new(next_token, rb_ary_entry(yields, 1));
705 if (parse_lex_data->freeze) {
710 rb_ary_push(next_tokens, next_yields);
713 rb_ary_replace(parse_lex_data->tokens, next_tokens);
723 pm_parser_init(&parser, pm_string_source(input), pm_string_length(input), options);
724 pm_parser_register_encoding_changed_callback(&parser, parse_lex_encoding_changed_callback);
726 VALUE source_string =
rb_str_new((
const char *) pm_string_source(input), pm_string_length(input));
734 .freeze = options->
freeze,
739 .data = (
void *) data,
740 .callback = parse_lex_token,
744 pm_node_t *node = pm_parse(&parser);
750 rb_encoding *encoding = rb_enc_find(parser.
encoding->
name);
751 rb_enc_associate(source_string, encoding);
766 VALUE value = rb_ary_new_capa(2);
767 rb_ary_push(value, pm_ast_new(&parser, node, parse_lex_data.encoding, source, options->
freeze));
768 rb_ary_push(value, parse_lex_data.tokens);
770 result = parse_result_create(rb_cPrismParseLexResult, &parser, value, parse_lex_data.encoding, source, options->
freeze);
772 result = parse_result_create(rb_cPrismLexResult, &parser, parse_lex_data.tokens, parse_lex_data.encoding, source, options->
freeze);
775 pm_node_destroy(&parser, node);
776 pm_parser_free(&parser);
792 string_options(argc, argv, &input, &options);
794 VALUE result = parse_lex_input(&input, &options,
false);
795 pm_string_free(&input);
796 pm_options_free(&options);
813 VALUE encoded_filepath;
814 file_options(argc, argv, &input, &options, &encoded_filepath);
816 VALUE value = parse_lex_input(&input, &options,
false);
817 pm_string_free(&input);
818 pm_options_free(&options);
833 pm_parser_init(&parser, pm_string_source(input), pm_string_length(input), options);
835 pm_node_t *node = pm_parse(&parser);
836 rb_encoding *encoding = rb_enc_find(parser.
encoding->
name);
838 VALUE source = pm_source_new(&parser, encoding, options->
freeze);
839 VALUE value = pm_ast_new(&parser, node, encoding, source, options->
freeze);
840 VALUE result = parse_result_create(rb_cPrismParseResult, &parser, value, encoding, source, options->
freeze);
846 pm_node_destroy(&parser, node);
847 pm_parser_free(&parser);
898 string_options(argc, argv, &input, &options);
900#ifdef PRISM_BUILD_DEBUG
901 size_t length = pm_string_length(&input);
903 memcpy(dup, pm_string_source(&input), length);
904 pm_string_constant_init(&input, dup, length);
907 VALUE value = parse_input(&input, &options);
909#ifdef PRISM_BUILD_DEBUG
913 pm_string_free(&input);
914 pm_options_free(&options);
926parse_file(
int argc,
VALUE *argv,
VALUE self) {
930 VALUE encoded_filepath;
931 file_options(argc, argv, &input, &options, &encoded_filepath);
933 VALUE value = parse_input(&input, &options);
934 pm_string_free(&input);
935 pm_options_free(&options);
946 pm_parser_init(&parser, pm_string_source(input), pm_string_length(input), options);
948 pm_node_t *node = pm_parse(&parser);
949 pm_node_destroy(&parser, node);
950 pm_parser_free(&parser);
966 string_options(argc, argv, &input, &options);
967 profile_input(&input, &options);
968 pm_string_free(&input);
969 pm_options_free(&options);
983profile_file(
int argc,
VALUE *argv,
VALUE self) {
987 VALUE encoded_filepath;
988 file_options(argc, argv, &input, &options, &encoded_filepath);
990 profile_input(&input, &options);
991 pm_string_free(&input);
992 pm_options_free(&options);
998parse_stream_eof(
void *stream) {
1009parse_stream_fgets(
char *
string,
int size,
void *stream) {
1017 const char *cstr = RSTRING_PTR(line);
1018 long length = RSTRING_LEN(line);
1020 memcpy(
string, cstr, length);
1021 string[length] =
'\0';
1034parse_stream(
int argc,
VALUE *argv,
VALUE self) {
1040 extract_options(&options,
Qnil, keywords);
1045 pm_node_t *node = pm_parse_stream(&parser, &buffer, (
void *) stream, parse_stream_fgets, parse_stream_eof, &options);
1046 rb_encoding *encoding = rb_enc_find(parser.
encoding->
name);
1048 VALUE source = pm_source_new(&parser, encoding, options.
freeze);
1049 VALUE value = pm_ast_new(&parser, node, encoding, source, options.
freeze);
1050 VALUE result = parse_result_create(rb_cPrismParseResult, &parser, value, encoding, source, options.
freeze);
1052 pm_node_destroy(&parser, node);
1053 pm_buffer_free(&buffer);
1054 pm_parser_free(&parser);
1065 pm_parser_init(&parser, pm_string_source(input), pm_string_length(input), options);
1067 pm_node_t *node = pm_parse(&parser);
1068 rb_encoding *encoding = rb_enc_find(parser.
encoding->
name);
1070 VALUE source = pm_source_new(&parser, encoding, options->
freeze);
1071 VALUE comments = parser_comments(&parser, source, options->
freeze);
1073 pm_node_destroy(&parser, node);
1074 pm_parser_free(&parser);
1087parse_comments(
int argc,
VALUE *argv,
VALUE self) {
1090 string_options(argc, argv, &input, &options);
1092 VALUE result = parse_input_comments(&input, &options);
1093 pm_string_free(&input);
1094 pm_options_free(&options);
1107parse_file_comments(
int argc,
VALUE *argv,
VALUE self) {
1111 VALUE encoded_filepath;
1112 file_options(argc, argv, &input, &options, &encoded_filepath);
1114 VALUE value = parse_input_comments(&input, &options);
1115 pm_string_free(&input);
1116 pm_options_free(&options);
1136parse_lex(
int argc,
VALUE *argv,
VALUE self) {
1139 string_options(argc, argv, &input, &options);
1141 VALUE value = parse_lex_input(&input, &options,
true);
1142 pm_string_free(&input);
1143 pm_options_free(&options);
1163parse_lex_file(
int argc,
VALUE *argv,
VALUE self) {
1167 VALUE encoded_filepath;
1168 file_options(argc, argv, &input, &options, &encoded_filepath);
1170 VALUE value = parse_lex_input(&input, &options,
true);
1171 pm_string_free(&input);
1172 pm_options_free(&options);
1183 pm_parser_init(&parser, pm_string_source(input), pm_string_length(input), options);
1185 pm_node_t *node = pm_parse(&parser);
1186 pm_node_destroy(&parser, node);
1189 pm_parser_free(&parser);
1202parse_success_p(
int argc,
VALUE *argv,
VALUE self) {
1205 string_options(argc, argv, &input, &options);
1207 VALUE result = parse_input_success_p(&input, &options);
1208 pm_string_free(&input);
1209 pm_options_free(&options);
1222parse_failure_p(
int argc,
VALUE *argv,
VALUE self) {
1234parse_file_success_p(
int argc,
VALUE *argv,
VALUE self) {
1238 VALUE encoded_filepath;
1239 file_options(argc, argv, &input, &options, &encoded_filepath);
1241 VALUE result = parse_input_success_p(&input, &options);
1242 pm_string_free(&input);
1243 pm_options_free(&options);
1256parse_file_failure_p(
int argc,
VALUE *argv,
VALUE self) {
1272 rb_raise(rb_eArgError,
"Invalid or non ascii-compatible encoding");
1291string_query_local_p(
VALUE self,
VALUE string) {
1292 const uint8_t *source = (
const uint8_t *) check_string(
string);
1293 return string_query(pm_string_query_local(source, RSTRING_LEN(
string), rb_enc_get(
string)->name));
1305string_query_constant_p(
VALUE self,
VALUE string) {
1306 const uint8_t *source = (
const uint8_t *) check_string(
string);
1307 return string_query(pm_string_query_constant(source, RSTRING_LEN(
string), rb_enc_get(
string)->name));
1317string_query_method_name_p(
VALUE self,
VALUE string) {
1318 const uint8_t *source = (
const uint8_t *) check_string(
string);
1319 return string_query(pm_string_query_method_name(source, RSTRING_LEN(
string), rb_enc_get(
string)->name));
1329RUBY_FUNC_EXPORTED
void
1333 if (strcmp(
pm_version(), EXPECTED_PRISM_VERSION) != 0) {
1336 "The prism library version (%s) does not match the expected version (%s)",
1338 EXPECTED_PRISM_VERSION
1342#ifdef HAVE_RB_EXT_RACTOR_SAFE
1373 rb_id_option_frozen_string_literal =
rb_intern_const(
"frozen_string_literal");
1379 rb_id_source_for = rb_intern(
"for");
1380 rb_id_forwarding_positionals = rb_intern(
"*");
1381 rb_id_forwarding_keywords = rb_intern(
"**");
1382 rb_id_forwarding_block = rb_intern(
"&");
1383 rb_id_forwarding_all = rb_intern(
"...");
1407#ifndef PRISM_EXCLUDE_SERIALIZATION
1417 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_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.
rb_encoding * rb_utf8_encoding(void)
Queries the encoding that represents UTF-8.
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_new(void)
Allocates a new, empty array.
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.
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_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().
void rb_define_const(VALUE klass, const char *name, VALUE val)
Defines a Ruby level constant under a namespace.
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_hash_foreach(VALUE q, int_type *w, VALUE e)
Iteration over the given hash.
struct pm_options_scope pm_options_scope_t
A scope of locals surrounding the code that is being parsed.
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.
struct pm_options pm_options_t
The options that can be passed to the parser.
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.
struct pm_parser pm_parser_t
The parser used to parse Ruby source.
struct pm_comment pm_comment_t
This is a node in the linked list of comments that we've found while parsing.
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.
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.
PRISM_EXPORTED_FUNCTION const char * pm_version(void)
The prism version and the serialization format.
#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...
struct pm_list_node * next
A pointer to the next node in the list.
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.
pm_string_t * locals
The names of the locals in the scope.
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.
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.