From eb3528e580aa13a44a124d41828a778ab8ad51e7 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Thu, 8 Oct 2026 15:17:34 -0400 Subject: [PATCH] attach_comments Revisit how we attach comments, allowing consumers to do it in C. --- CHANGELOG.md | 3 + docs/relocation.md | 6 +- docs/serialization.md | 13 + ext/prism/extension.c | 124 ++- ext/prism/extension.h | 2 +- include/prism/comments.h | 12 + include/prism/internal/char.h | 6 + include/prism/internal/comments.h | 33 + include/prism/internal/node.h | 6 + include/prism/internal/options.h | 8 + include/prism/internal/parser.h | 13 + include/prism/options.h | 19 + include/prism/parser.h | 56 ++ .../org/ruby_lang/prism/ParsingOptions.java | 3 + javascript/src/parsePrism.js | 3 + lib/prism.rb | 34 +- lib/prism/ffi.rb | 5 +- lib/prism/lex_compat.rb | 8 +- lib/prism/parse_result.rb | 145 ++-- lib/prism/parse_result/comments.rb | 219 ----- lib/prism/relocation.rb | 98 --- lib/prism/translation/ruby_parser.rb | 57 +- prism.gemspec | 4 +- rakelib/typecheck.rake | 2 +- rbi/generated/prism.rbi | 68 +- rbi/generated/prism/lex_compat.rbi | 4 +- rbi/generated/prism/node.rbi | 624 +------------- rbi/generated/prism/parse_result.rbi | 89 +- rbi/generated/prism/parse_result/comments.rbi | 90 -- rbi/generated/prism/relocation.rbi | 59 -- rbi/generated/prism/serialize.rbi | 13 +- sample/prism/find_comments.rb | 35 +- sample/prism/multiplex_constants.rb | 2 +- sig/generated/prism.rbs | 34 +- sig/generated/prism/lex_compat.rbs | 4 +- sig/generated/prism/node.rbs | 795 +----------------- sig/generated/prism/parse_result.rbs | 97 +-- sig/generated/prism/parse_result/comments.rbs | 108 --- sig/generated/prism/relocation.rbs | 74 -- sig/generated/prism/serialize.rbs | 15 +- src/char.c | 15 + src/comments.c | 454 ++++++++++ src/options.c | 17 + src/parser.c | 47 ++ src/prism.c | 8 +- templates/ext/prism/api_node.c.erb | 4 +- templates/javascript/src/deserialize.js.erb | 10 + templates/lib/prism/node.rb.erb | 39 +- templates/lib/prism/serialize.rb.erb | 71 +- templates/src/serialize.c.erb | 31 + test/prism/api/freeze_test.rb | 13 +- test/prism/api/parse_test.rb | 9 + test/prism/result/attach_comments_test.rb | 262 ++++++ test/prism/result/comments_test.rb | 24 - test/prism/ruby/relocation_test.rb | 44 - test/prism/ruby/ruby_parser_test.rb | 10 + 56 files changed, 1553 insertions(+), 2495 deletions(-) delete mode 100644 lib/prism/parse_result/comments.rb delete mode 100644 rbi/generated/prism/parse_result/comments.rbi delete mode 100644 sig/generated/prism/parse_result/comments.rbs create mode 100644 src/comments.c create mode 100644 test/prism/result/attach_comments_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 04b89c426a..eb419ebb5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ Highlights of this release: * `BACKTICK` was split up into `BACKTICK` and `XSTRING_BACKTICK`. * `NEWLINE` was split up into `NEWLINE` and `NEWLINE_TERMINATOR`. * `WORDS_SEP` was split up into `WORDS_SEP` and `WORDS_SEP_IMPLICIT`. +- Comment attachment now happens during parsing with the `attach_comments` option instead of afterward with `ParseResult#attach_comments!`, which was removed. `Node#comments` now returns the comments attached to the node by that option. `Location#comments`, `Location#leading_comments`, `Location#trailing_comments`, `Node#leading_comments`, `Node#trailing_comments`, and the comment fields of `Prism::Relocation` were removed. +- Comments now live on the source. `Prism::Source#comments` returns them and `Result#comments` delegates to it, so `ParseResult.new`, `LexResult.new`, and `ParseLexResult.new` no longer take a `comments` argument. #### C/Rust Bindings - Most structs are now opaque (except for nodes) [#4015](https://github.com/ruby/prism/pull/4015) @@ -40,6 +42,7 @@ Highlights of this release: - `ForwardingSuperNode` now has `keyword_loc`. - Allow pattern matching with prism nodes to match on location slices, like `node in Prism::StringNode[content: "foo"]`. - `Prism.parse_file` and similar now accept anything responding to `to_path` (like `Pathname`) directly. +- `attach_comments` was added as a valid option. Each comment is attached to the node that ends latest on the comment's line before it, otherwise to the innermost node that contains it (or to that node's statements, if only whitespace and comments come between the comment and the statements), otherwise to the top-level statements. The attached comments are available through `Node#comments` and through `pm_node_comments_size` and `pm_node_comment` in the C API, as well as `pm_parser_comment_attachment`, `pm_parser_comment_ranges_size`, and `pm_parser_comment_range`, which expose the attachments grouped by node. When the option is set, the comments on the parse result are sorted by start offset. ### Removed - Removed `Prism::Pack`. diff --git a/docs/relocation.md b/docs/relocation.md index 0515f56247..34a267c95f 100644 --- a/docs/relocation.md +++ b/docs/relocation.md @@ -6,10 +6,10 @@ The `Relocation` module provides an API around this property. It allows you to " ## Getting started -To get started with the `Relocation` module, you would first instantiate a `Repository` object. You do this through a DSL that chains method calls for configuration. For example, if for every entry in the repository you want to store the start and end lines, the start and end code unit columns for in UTF-16, and the leading comments, you would: +To get started with the `Relocation` module, you would first instantiate a `Repository` object. You do this through a DSL that chains method calls for configuration. For example, if for every entry in the repository you want to store the start and end lines, and the start and end code unit columns for in UTF-16, you would: ```ruby -repository = Prism::Relocation.filepath("path/to/file").lines.code_unit_columns(Encoding::UTF_16).leading_comments +repository = Prism::Relocation.filepath("path/to/file").lines.code_unit_columns(Encoding::UTF_16) ``` Now that you have the repository, you can pass it into any of the `save*` APIs on nodes or locations to create entries in the repository that will be lazily reified. @@ -27,8 +27,6 @@ entry.end_line entry.start_code_units_column entry.end_code_units_column - -entry.leading_comments ``` Note that if you had configured other fields to be saved, you would be able to access them as well. The first time one of these fields is accessed, the repository will reify every entry it knows about and then clean itself up. In this way, you can effectively treat them as if you had kept around lightweight versions of `Prism::Node` or `Prism::Location` objects. diff --git a/docs/serialization.md b/docs/serialization.md index ad13b0a460..2ede928a02 100644 --- a/docs/serialization.md +++ b/docs/serialization.md @@ -44,6 +44,17 @@ The comment type is one of: | `1` | comment type | | location | the location in the source of this comment | +### comment attachment + +A comment attachment lists the comments owned by a single node. +Only nodes that own comments have an attachment, and there are none unless the `attach_comments` option was set. + +| # bytes | field | +| --- | --- | +| varuint | the node identifier of the node that owns the comments | +| varuint | number of comments owned by the node | +| varuint* | the index of each owned comment in the list of comments, ordered by start offset | + ### magic comment | # bytes | field | @@ -99,6 +110,8 @@ The header is structured like the following table: | varuint* | newline offsets | | varuint | number of comments | | comment* | comments | +| varuint | number of nodes with attached comments | +| comment attachment* | comment attachments | | varuint | number of magic comments | | magic comment* | magic comments | | location? | the optional location of the `__END__` keyword and its contents | diff --git a/ext/prism/extension.c b/ext/prism/extension.c index 62979873ed..8d24a99a7b 100644 --- a/ext/prism/extension.c +++ b/ext/prism/extension.c @@ -31,6 +31,7 @@ VALUE rb_cPrismCurrentVersionError; VALUE rb_cPrismDebugEncoding; +ID rb_id_option_attach_comments; ID rb_id_option_command_line; ID rb_id_option_encoding; ID rb_id_option_filepath; @@ -270,6 +271,8 @@ build_options_i(VALUE key, VALUE value, VALUE argument) { if (!NIL_P(value)) pm_options_partial_script_set(options, RTEST(value)); } else if (key_id == rb_id_option_freeze) { if (!NIL_P(value)) pm_options_freeze_set(options, RTEST(value)); + } else if (key_id == rb_id_option_attach_comments) { + if (!NIL_P(value)) pm_options_attach_comments_set(options, RTEST(value)); } else if (key_id == rb_id_option_raise_error) { if (!NIL_P(value)) { if (value == Qtrue) { @@ -624,27 +627,25 @@ typedef struct { VALUE comments; VALUE source; bool freeze; + long index; } parser_comments_each_data_t; static void parser_comments_each(const pm_comment_t *comment, void *data) { parser_comments_each_data_t *each_data = (parser_comments_each_data_t *) data; VALUE value = parser_comment(each_data->source, each_data->freeze, comment); - rb_ary_push(each_data->comments, value); + rb_ary_store(each_data->comments, each_data->index++, value); } /** - * Extract the comments out of the parser into an array. + * Extract the comments out of the parser into the given array, which was + * created before the source so that the source could hold it. */ -static VALUE -parser_comments(const pm_parser_t *parser, VALUE source, bool freeze) { - VALUE comments = rb_ary_new_capa(pm_parser_comments_size(parser)); - - parser_comments_each_data_t each_data = { comments, source, freeze }; +static void +parser_comments(const pm_parser_t *parser, VALUE comments, VALUE source, bool freeze) { + parser_comments_each_data_t each_data = { .comments = comments, .source = source, .freeze = freeze }; pm_parser_comments_each(parser, parser_comments_each, &each_data); - if (freeze) rb_obj_freeze(comments); - return comments; } /** @@ -803,6 +804,52 @@ parser_warnings(const pm_parser_t *parser, rb_encoding *encoding, VALUE source, return warnings; } +/** + * Create the arrays that hold the comments attached to each node, sized for the + * parser's comment attachments. They stay empty unless the attach_comments + * option was set. + */ +static void +parser_attachments_new(const pm_parser_t *parser, VALUE *attachments, VALUE *ranges) { + uint32_t ranges_size = pm_parser_comment_ranges_size(parser); + *attachments = rb_ary_new_capa(ranges_size == 0 ? 0 : (long) pm_parser_comments_size(parser)); + *ranges = rb_ary_new_capa(ranges_size == 0 ? 0 : (long) ranges_size + 1); +} + +/** + * Fill in the comments attached to each node. The attachments are the Comment + * objects in the order of the parser's comment attachments, which groups them + * by node in order of node id. The ranges are indexed by node id: for each node + * that owns comments, the index at which its comments begin is stored at its + * node id and the index at which they end is stored at the following node id. + */ +static void +parser_attachments(const pm_parser_t *parser, VALUE comments, VALUE attachments, VALUE ranges, bool freeze) { + uint32_t ranges_size = pm_parser_comment_ranges_size(parser); + + if (ranges_size > 0) { + long size = RARRAY_LEN(comments); + + for (long index = 0; index < size; index++) { + rb_ary_store(attachments, index, RARRAY_AREF(comments, pm_parser_comment_attachment(parser, (uint32_t) index))); + } + + for (uint32_t node_id = 0; node_id < ranges_size; node_id++) { + pm_comment_range_t range = pm_parser_comment_range(parser, node_id); + + if (range.length > 0) { + rb_ary_store(ranges, (long) node_id, LONG2FIX(range.index)); + rb_ary_store(ranges, (long) node_id + 1, LONG2FIX(range.index + range.length)); + } + } + } + + if (freeze) { + rb_obj_freeze(attachments); + rb_obj_freeze(ranges); + } +} + /** * Create a new parse result from the given parser, value, encoding, and source. */ @@ -810,7 +857,6 @@ static VALUE parse_result_create(VALUE class, const pm_parser_t *parser, VALUE value, rb_encoding *encoding, VALUE source, bool freeze) { VALUE result_argv[] = { value, - parser_comments(parser, source, freeze), parser_magic_comments(parser, source, freeze), parser_data_loc(parser, source, freeze), parser_errors(parser, encoding, source, freeze), @@ -819,7 +865,7 @@ parse_result_create(VALUE class, const pm_parser_t *parser, VALUE value, rb_enco source }; - return rb_class_new_instance_freeze(8, result_argv, class, freeze); + return rb_class_new_instance_freeze(7, result_argv, class, freeze); } /******************************************************************************/ @@ -908,7 +954,10 @@ parse_lex_input(const uint8_t *input, size_t input_length, const pm_options_t *o VALUE source_string = rb_str_new((const char *) input, input_length); VALUE offsets = rb_ary_new_capa(pm_parser_line_offsets(parser)->size); - VALUE source = rb_funcall(rb_cPrismSource, rb_id_source_for, 3, source_string, LONG2NUM(pm_parser_start_line(parser)), offsets); + VALUE comments = rb_ary_new(); + VALUE attachments = rb_ary_new(); + VALUE ranges = rb_ary_new(); + VALUE source = rb_funcall(rb_cPrismSource, rb_id_source_for, 6, source_string, LONG2NUM(pm_parser_start_line(parser)), offsets, comments, attachments, ranges); parse_lex_data_t parse_lex_data = { .source = source, @@ -941,6 +990,19 @@ parse_lex_input(const uint8_t *input, size_t input_length, const pm_options_t *o rb_obj_freeze(parse_lex_data.tokens); } + /* The comment lists were created along with the source before parsing, + * so they are grown to their final sizes now that those are known. */ + uint32_t ranges_size = pm_parser_comment_ranges_size(parser); + rb_ary_resize(comments, (long) pm_parser_comments_size(parser)); + + if (ranges_size > 0) { + rb_ary_resize(attachments, (long) pm_parser_comments_size(parser)); + rb_ary_resize(ranges, (long) ranges_size + 1); + } + + parser_comments(parser, comments, source, pm_options_freeze(options)); + parser_attachments(parser, comments, attachments, ranges, pm_options_freeze(options)); + if (return_nodes) { VALUE value = rb_ary_new_capa(2); rb_ary_push(value, pm_ast_new(parser, node, parse_lex_data.encoding, source, pm_options_freeze(options))); @@ -1018,13 +1080,16 @@ parse_input(const uint8_t *input, size_t input_length, const pm_options_t *optio rb_encoding *encoding = rb_enc_find(pm_parser_encoding_name(parser)); bool freeze = pm_options_freeze(options); - VALUE source = pm_source_new(parser, encoding, freeze); + VALUE comments = rb_ary_new_capa(pm_parser_comments_size(parser)); + VALUE attachments, ranges; + parser_attachments_new(parser, &attachments, &ranges); + + VALUE source = pm_source_new(parser, encoding, comments, attachments, ranges, freeze); + parser_comments(parser, comments, source, freeze); + parser_attachments(parser, comments, attachments, ranges, freeze); + VALUE value = pm_ast_new(parser, node, encoding, source, freeze); result = result_ok(parse_result_create(rb_cPrismParseResult, parser, value, encoding, source, freeze)); - - if (freeze) { - rb_obj_freeze(source); - } } pm_parser_free(parser); @@ -1041,6 +1106,9 @@ parse_input(const uint8_t *input, size_t input_length, const pm_options_t *optio * Parse the given string and return a ParseResult instance. The options that * are supported are: * + * * `attach_comments` - whether or not to attach each comment to the node that + * owns it. When set, the comments on the result are sorted by start + * offset. This should be a boolean or nil. * * `command_line` - either nil or a string of the various options that were * set on the command line. Valid values are combinations of "a", "l", * "n", "p", and "x". @@ -1298,8 +1366,16 @@ parse_stream(int argc, VALUE *argv, VALUE self) { if (result.type == RESULT_OK) { rb_encoding *encoding = rb_enc_find(pm_parser_encoding_name(parser)); - VALUE source = pm_source_new(parser, encoding, pm_options_freeze(options)); + VALUE comments = rb_ary_new_capa(pm_parser_comments_size(parser)); + VALUE attachments, ranges; + parser_attachments_new(parser, &attachments, &ranges); + + VALUE source = pm_source_new(parser, encoding, comments, attachments, ranges, pm_options_freeze(options)); + parser_comments(parser, comments, source, pm_options_freeze(options)); + parser_attachments(parser, comments, attachments, ranges, pm_options_freeze(options)); + VALUE value = pm_ast_new(parser, node, encoding, source, pm_options_freeze(options)); + result = result_ok(parse_result_create(rb_cPrismParseResult, parser, value, encoding, source, pm_options_freeze(options))); } @@ -1325,8 +1401,15 @@ parse_input_comments(const uint8_t *input, size_t input_length, const pm_options if (result.type == RESULT_OK) { rb_encoding *encoding = rb_enc_find(pm_parser_encoding_name(parser)); - VALUE source = pm_source_new(parser, encoding, pm_options_freeze(options)); - result = result_ok(parser_comments(parser, source, pm_options_freeze(options))); + VALUE comments = rb_ary_new_capa(pm_parser_comments_size(parser)); + VALUE attachments, ranges; + parser_attachments_new(parser, &attachments, &ranges); + + VALUE source = pm_source_new(parser, encoding, comments, attachments, ranges, pm_options_freeze(options)); + parser_comments(parser, comments, source, pm_options_freeze(options)); + parser_attachments(parser, comments, attachments, ranges, pm_options_freeze(options)); + + result = result_ok(comments); } pm_parser_free(parser); @@ -1630,6 +1713,7 @@ Init_prism(void) { /* Intern all of the IDs eagerly that we support so that we do not have to * do it every time we parse. */ + rb_id_option_attach_comments = rb_intern_const("attach_comments"); rb_id_option_command_line = rb_intern_const("command_line"); rb_id_option_encoding = rb_intern_const("encoding"); rb_id_option_filepath = rb_intern_const("filepath"); diff --git a/ext/prism/extension.h b/ext/prism/extension.h index d0cbc2ff53..7959cd8613 100644 --- a/ext/prism/extension.h +++ b/ext/prism/extension.h @@ -8,7 +8,7 @@ #include #include "prism.h" -VALUE pm_source_new(const pm_parser_t *parser, rb_encoding *encoding, bool freeze); +VALUE pm_source_new(const pm_parser_t *parser, rb_encoding *encoding, VALUE comments, VALUE comment_attachments, VALUE comment_ranges, bool freeze); VALUE pm_token_new(const pm_parser_t *parser, const pm_token_t *token, rb_encoding *encoding, VALUE source, bool freeze); VALUE pm_ast_new(const pm_parser_t *parser, const pm_node_t *node, rb_encoding *encoding, VALUE source, bool freeze); VALUE pm_integer_new(const pm_integer_t *integer); diff --git a/include/prism/comments.h b/include/prism/comments.h index 2270d53889..f368b4482a 100644 --- a/include/prism/comments.h +++ b/include/prism/comments.h @@ -23,6 +23,18 @@ typedef enum { /** An opaque pointer to a comment found while parsing. */ typedef struct pm_comment_t pm_comment_t; +/** + * The comments owned by a node, as a slice of the comment attachments of the + * parser that produced it. + */ +typedef struct { + /** The index of the first attachment owned by the node. */ + uint32_t index; + + /** The number of attachments owned by the node. */ + uint32_t length; +} pm_comment_range_t; + /** * Returns the location associated with the given comment. * diff --git a/include/prism/internal/char.h b/include/prism/internal/char.h index 9a58fba8c5..f7b09859b3 100644 --- a/include/prism/internal/char.h +++ b/include/prism/internal/char.h @@ -53,6 +53,12 @@ pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length) { */ size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length); +/* + * Returns the number of characters at the end of the string that are + * whitespace. Disallows searching past the given maximum number of characters. + */ +size_t pm_strrspn_whitespace(const uint8_t *string, ptrdiff_t length); + /* * Returns the number of characters at the start of the string that are * whitespace while also tracking the location of each newline. Disallows diff --git a/include/prism/internal/comments.h b/include/prism/internal/comments.h index bb3039a658..d546f566fc 100644 --- a/include/prism/internal/comments.h +++ b/include/prism/internal/comments.h @@ -2,9 +2,12 @@ #define PRISM_INTERNAL_COMMENTS_H #include "prism/comments.h" +#include "prism/parser.h" #include "prism/internal/list.h" +#include + /* A comment found while parsing. */ struct pm_comment_t { /* The embedded base node. */ @@ -17,4 +20,34 @@ struct pm_comment_t { pm_comment_type_t type; }; +/* + * The result of attaching comments to the nodes that own them. All of the + * arrays are allocated in the parser's metadata arena. + */ +typedef struct { + /* The comments found while parsing, sorted by start offset. */ + const pm_comment_t **comments; + + /* + * Indices into comments, grouped by owning node in order of node id and + * sorted by start offset within each group. A node's comments are not + * necessarily contiguous in comments, because a child can own a comment + * that falls between two comments owned by its parent. + */ + uint32_t *attachments; + + /* The slice of attachments for each node, indexed by node id. */ + pm_comment_range_t *ranges; + + /* The number of entries in ranges. */ + uint32_t ranges_size; +} pm_comment_attachments_t; + +/* + * Sort the parser's comment list in place by start offset, then assign every + * comment to the node that owns it. This is called after parsing when the + * attach_comments option is set. + */ +void pm_comments_attach(pm_parser_t *parser, const pm_node_t *root); + #endif diff --git a/include/prism/internal/node.h b/include/prism/internal/node.h index ca6d5616d7..3b24ea33f4 100644 --- a/include/prism/internal/node.h +++ b/include/prism/internal/node.h @@ -7,6 +7,12 @@ #include "prism/arena.h" +/* The offset of the start of the given location. */ +#define PM_LOCATION_START(location_) ((location_)->start) + +/* The offset just past the end of the given location. */ +#define PM_LOCATION_END(location_) ((location_)->start + (location_)->length) + /* * Slow path for pm_node_list_append: grow the list and append the node. * Do not call directly — use pm_node_list_append instead. diff --git a/include/prism/internal/options.h b/include/prism/internal/options.h index 4ac28808f4..7a8e72907e 100644 --- a/include/prism/internal/options.h +++ b/include/prism/internal/options.h @@ -147,6 +147,13 @@ struct pm_options_t { * between concurrency primitives. */ bool freeze; + + /* + * Whether or not the parser should attach comments to the nodes that own + * them after parsing. When this is set, the parser's comment list is + * sorted by start offset and every comment is assigned an owning node. + */ + bool attach_comments; }; /* Free the internal memory associated with the options. */ @@ -179,6 +186,7 @@ void pm_options_cleanup(pm_options_t *options); * | `1` | main script | * | `1` | partial script | * | `1` | freeze | + * | `1` | attach comments | * | `4` | the number of scopes | * | ... | the scopes | * diff --git a/include/prism/internal/parser.h b/include/prism/internal/parser.h index ad12d936cd..bac1164df9 100644 --- a/include/prism/internal/parser.h +++ b/include/prism/internal/parser.h @@ -4,6 +4,7 @@ #include "prism/compiler/accel.h" #include "prism/internal/arena.h" +#include "prism/internal/comments.h" #include "prism/internal/constant_pool.h" #include "prism/internal/encoding.h" #include "prism/internal/list.h" @@ -689,6 +690,12 @@ struct pm_parser_t { /* The list of comments that have been found while parsing. */ pm_list_t comment_list; + /* + * The attachments of comments to the nodes that own them, populated after + * parsing when the attach_comments option is set. + */ + pm_comment_attachments_t comment_attachments; + /* The list of magic comments that have been found while parsing. */ pm_list_t magic_comment_list; @@ -876,6 +883,12 @@ struct pm_parser_t { */ bool partial_script; + /* + * Whether or not comments should be attached to their owning nodes once + * parsing has finished. + */ + bool attach_comments; + /* Whether or not we're at the beginning of a command. */ bool command_start; diff --git a/include/prism/options.h b/include/prism/options.h index cf8a430bbc..44cf1640c1 100644 --- a/include/prism/options.h +++ b/include/prism/options.h @@ -249,6 +249,25 @@ PRISM_EXPORTED_FUNCTION bool pm_options_freeze(const pm_options_t *options) PRIS */ PRISM_EXPORTED_FUNCTION void pm_options_freeze_set(pm_options_t *options, bool freeze) PRISM_NONNULL(1); +/** + * Get the attach_comments option on the given options struct. + * + * @param options The options struct to get the attach_comments value from. + * @returns The attach_comments value. + */ +PRISM_EXPORTED_FUNCTION bool pm_options_attach_comments(const pm_options_t *options) PRISM_NONNULL(1); + +/** + * Set the attach_comments option on the given options struct. When this is + * set, the parser's comment list is sorted by start offset after parsing and + * every comment is assigned an owning node. Without it, comments are left in + * the order they were lexed and no nodes own any comments. + * + * @param options The options struct to set the attach_comments value on. + * @param attach_comments The attach_comments value to set. + */ +PRISM_EXPORTED_FUNCTION void pm_options_attach_comments_set(pm_options_t *options, bool attach_comments) PRISM_NONNULL(1); + /** * Get the raise_error option on the given options struct. * diff --git a/include/prism/parser.h b/include/prism/parser.h index 2c843ecf5e..12bfb8a8c0 100644 --- a/include/prism/parser.h +++ b/include/prism/parser.h @@ -223,6 +223,62 @@ typedef void (*pm_comment_callback_t)(const pm_comment_t *comment, void *data); */ PRISM_EXPORTED_FUNCTION void pm_parser_comments_each(const pm_parser_t *parser, pm_comment_callback_t callback, void *data) PRISM_NONNULL(1); +/** + * Returns the number of comments owned by the given node. This is 0 if the + * node owns no comments or if the attach_comments option was not set. + * + * @param parser the parser that produced the node + * @param node the node whose comments we want to count + * @returns the number of comments owned by the given node + */ +PRISM_EXPORTED_FUNCTION uint32_t pm_node_comments_size(const pm_parser_t *parser, const pm_node_t *node) PRISM_NONNULL(1, 2); + +/** + * Returns the comment at the given index among the comments owned by the given + * node, which are ordered by start offset. + * + * @param parser the parser that produced the node + * @param node the node whose comment we want to get + * @param index the index of the comment among those owned by the node + * @returns the comment at the given index, or NULL if the index is out of range + */ +PRISM_EXPORTED_FUNCTION const pm_comment_t * pm_node_comment(const pm_parser_t *parser, const pm_node_t *node, uint32_t index) PRISM_NONNULL(1, 2); + +/** + * Returns the index, among the comments associated with the given parser, of + * the comment at the given index among the comment attachments. The attachments + * are every comment, grouped by owning node in order of node id and ordered by + * start offset within each node, so there are as many attachments as there are + * comments when the attach_comments option is set. + * + * @param parser the parser whose comment attachments we want to read + * @param index the index of the attachment + * @returns the index of the comment, or UINT32_MAX if the index is out of range + * or the attach_comments option was not set + */ +PRISM_EXPORTED_FUNCTION uint32_t pm_parser_comment_attachment(const pm_parser_t *parser, uint32_t index) PRISM_NONNULL(1); + +/** + * Returns the number of node ids that have a comment range, which is one more + * than the largest id of a node that owns a comment, or 0 if the + * attach_comments option was not set or there are no comments. + * + * @param parser the parser whose comment ranges we want to count + * @returns the number of comment ranges + */ +PRISM_EXPORTED_FUNCTION uint32_t pm_parser_comment_ranges_size(const pm_parser_t *parser) PRISM_NONNULL(1); + +/** + * Returns the range of comment attachments owned by the node with the given id. + * + * @param parser the parser that produced the node + * @param node_id the id of the node + * @returns the range of attachments owned by the node, whose length is 0 if the + * node owns no comments, the node id is out of range, or the + * attach_comments option was not set + */ +PRISM_EXPORTED_FUNCTION pm_comment_range_t pm_parser_comment_range(const pm_parser_t *parser, uint32_t node_id) PRISM_NONNULL(1); + /** * Returns the number of magic comments associated with the given parser. * diff --git a/java/api/src/main/java/org/ruby_lang/prism/ParsingOptions.java b/java/api/src/main/java/org/ruby_lang/prism/ParsingOptions.java index c702e3c7b3..b5f484fd12 100644 --- a/java/api/src/main/java/org/ruby_lang/prism/ParsingOptions.java +++ b/java/api/src/main/java/org/ruby_lang/prism/ParsingOptions.java @@ -151,6 +151,9 @@ public static byte[] serialize(byte[] filepath, int line, byte[] encoding, boole // freeze output.write(0); + // attachComments + output.write(0); + // scopes // number of scopes diff --git a/javascript/src/parsePrism.js b/javascript/src/parsePrism.js index 1b350aa212..a424bf0d9c 100644 --- a/javascript/src/parsePrism.js +++ b/javascript/src/parsePrism.js @@ -161,6 +161,9 @@ function dumpOptions(options) { template.push("C"); values.push(0); + template.push("C"); + values.push(0); + template.push("L"); if (options.scopes) { const scopes = options.scopes; diff --git a/lib/prism.rb b/lib/prism.rb index bff555ffb3..e2918f52bf 100644 --- a/lib/prism.rb +++ b/lib/prism.rb @@ -103,23 +103,23 @@ def self.find(callable) # def gets: (?Integer integer) -> (String | nil) # end # - # def self.parse: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult - # def self.profile: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void - # def self.lex: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult - # def self.parse_lex: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult - # def self.dump: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String - # def self.parse_comments: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment] - # def self.parse_success?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool - # def self.parse_failure?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool - # def self.parse_stream: (_Stream stream, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult - # def self.parse_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult - # def self.profile_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void - # def self.lex_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult - # def self.parse_lex_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult - # def self.dump_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String - # def self.parse_file_comments: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment] - # def self.parse_file_success?: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool - # def self.parse_file_failure?: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool + # def self.parse: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult + # def self.profile: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void + # def self.lex: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult + # def self.parse_lex: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult + # def self.dump: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String + # def self.parse_comments: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment] + # def self.parse_success?: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool + # def self.parse_failure?: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool + # def self.parse_stream: (_Stream stream, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult + # def self.parse_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult + # def self.profile_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void + # def self.lex_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult + # def self.parse_lex_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult + # def self.dump_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String + # def self.parse_file_comments: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment] + # def self.parse_file_success?: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool + # def self.parse_file_failure?: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool end require_relative "prism/polyfill/byteindex" diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb index 6eb8231c2c..013f02ca8c 100644 --- a/lib/prism/ffi.rb +++ b/lib/prism/ffi.rb @@ -598,7 +598,7 @@ def version_string_to_number(version) # The set of options that are understood by the parsing APIs. Note that # raise_error is not listed here because it is deleted from the options # hash by raise_error_format_type before the options are dumped. - DUMP_OPTIONS_KEYS = [:command_line, :encoding, :filepath, :freeze, :frozen_string_literal, :line, :main_script, :partial_script, :scopes, :version].freeze + DUMP_OPTIONS_KEYS = [:attach_comments, :command_line, :encoding, :filepath, :freeze, :frozen_string_literal, :line, :main_script, :partial_script, :scopes, :version].freeze private_constant :DUMP_OPTIONS_KEYS # Convert the given options into a serialized options string. @@ -650,6 +650,9 @@ def dump_options(options) template << "C" values << (options.fetch(:freeze, false) ? 1 : 0) + template << "C" + values << (options.fetch(:attach_comments, false) ? 1 : 0) + template << "L" if (scopes = options[:scopes]) values << scopes.length diff --git a/lib/prism/lex_compat.rb b/lib/prism/lex_compat.rb index 8d4838651a..478d08db30 100644 --- a/lib/prism/lex_compat.rb +++ b/lib/prism/lex_compat.rb @@ -49,10 +49,10 @@ class Result < Prism::Result # Create a new lex compat result object with the given values. # - #: (Array[lex_compat_token] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize(value, comments, magic_comments, data_loc, errors, warnings, continuable, source) + #: (Array[lex_compat_token] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source) @value = value - super(comments, magic_comments, data_loc, errors, warnings, continuable, source) + super(magic_comments, data_loc, errors, warnings, continuable, source) end # Implement the hash pattern matching interface for Result. @@ -878,7 +878,7 @@ def result tokens = post_process_tokens(tokens, source, result.data_loc, bom, eof_token) - Result.new(tokens, result.comments, result.magic_comments, result.data_loc, result.errors, result.warnings, result.continuable?, source) + Result.new(tokens, result.magic_comments, result.data_loc, result.errors, result.warnings, result.continuable?, source) end private diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb index e9380d0f09..7c5bcdcccb 100644 --- a/lib/prism/parse_result.rb +++ b/lib/prism/parse_result.rb @@ -29,15 +29,20 @@ class Source # byte offset whenever a newline character is encountered. The first # element is always 0 to mark the first line. # - #: (String source, Integer start_line, Array[Integer] offsets) -> Source - def self.for(source, start_line, offsets) + # The comments, comment_attachments, and comment_ranges parameters are the + # lists described by the attributes of the same names. They are passed in + # empty when the source is created by the parser and filled in afterward, + # because the comments themselves refer to the source. + # + #: (String source, Integer start_line, Array[Integer] offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges) -> Source + def self.for(source, start_line, offsets, comments = [], comment_attachments = [], comment_ranges = []) if source.ascii_only? - ASCIISource.new(source, start_line, offsets) + ASCIISource.new(source, start_line, offsets, comments, comment_attachments, comment_ranges) elsif source.encoding == Encoding::BINARY source.force_encoding(Encoding::UTF_8) if source.valid_encoding? - new(source, start_line, offsets) + new(source, start_line, offsets, comments, comment_attachments, comment_ranges) else # This is an extremely niche use case where the file is marked as # binary, contains multi-byte characters, and those characters are not @@ -46,10 +51,10 @@ def self.for(source, start_line, offsets) # problems when asking for code units, but it appears to be the # cleanest solution at the moment. source.force_encoding(Encoding::BINARY) - ASCIISource.new(source, start_line, offsets) + ASCIISource.new(source, start_line, offsets, comments, comment_attachments, comment_ranges) end else - new(source, start_line, offsets) + new(source, start_line, offsets, comments, comment_attachments, comment_ranges) end end @@ -59,6 +64,22 @@ def self.for(source, start_line, offsets) # The line number where this source starts. attr_reader :start_line #: Integer + # The list of comments that were encountered during parsing. When the source + # is parsed with the attach_comments option, these are sorted by start + # offset. + attr_reader :comments #: Array[Comment] + + # The comments attached to nodes, grouped by node in order of node id. This + # is empty unless the source was parsed with the attach_comments option. + attr_reader :comment_attachments #: Array[Comment] + + # Indices into comment_attachments, indexed by node id. For each node that + # owns comments, the index at which its comments begin is stored at its node + # id and the index at which they end is stored at the following node id. The + # other entries are nil. This is empty unless the source was parsed with the + # attach_comments option. + attr_reader :comment_ranges #: Array[Integer?] + # The list of newline byte offsets in the source code. When initialized from # the C extension, this may be a packed binary string of uint32_t values # that is lazily unpacked on first access. @@ -74,11 +95,14 @@ def offsets # parameter can be either an Array of Integer byte offsets or a packed # binary string of uint32_t values (from the C extension). # - #: (String source, Integer start_line, Array[Integer] | String offsets) -> void - def initialize(source, start_line, offsets) + #: (String source, Integer start_line, Array[Integer] | String offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges) -> void + def initialize(source, start_line, offsets, comments = [], comment_attachments = [], comment_ranges = []) @source = source @start_line = start_line @offsets = offsets + @comments = comments + @comment_attachments = comment_attachments + @comment_ranges = comment_ranges end # Replace the value of start_line with the given value. @@ -95,6 +119,19 @@ def replace_offsets(offsets) @offsets = offsets end + # The comments attached to the node with the given id, ordered by start + # offset. Comments are only attached when the source is parsed with the + # attach_comments option. + # + #: (Integer node_id) -> Array[Comment] + def comments_for(node_id) + start = comment_ranges[node_id] + finish = comment_ranges[node_id + 1] + return [] if start.nil? || finish.nil? + + comment_attachments[start...finish] || [] + end + # Returns the encoding of the source code, which is set by parameters to the # parser or by the encoding magic comment. # @@ -222,6 +259,9 @@ def code_units_column(byte_offset, encoding) def deep_freeze source.freeze offsets.freeze + comments.freeze + comment_attachments.freeze + comment_ranges.freeze freeze end @@ -406,9 +446,6 @@ class Location # The length of this location in bytes. attr_reader :length #: Integer - # @rbs @leading_comments: Array[Comment]? - # @rbs @trailing_comments: Array[Comment]? - # Create a new location object with the given source, start byte offset, and # byte length. # @@ -417,50 +454,6 @@ def initialize(source, start_offset, length) @source = source @start_offset = start_offset @length = length - - # These are used to store comments that are associated with this location. - # They are initialized to `nil` to save on memory when there are no - # comments to be attached and/or the comment-related APIs are not used. - @leading_comments = nil - @trailing_comments = nil - end - - # These are the comments that are associated with this location that exist - # before the start of this location. - # - #: () -> Array[Comment] - def leading_comments - @leading_comments ||= [] - end - - # Attach a comment to the leading comments of this location. - # - #: (Comment comment) -> void - def leading_comment(comment) - leading_comments << comment - end - - # These are the comments that are associated with this location that exist - # after the end of this location. - # - #: () -> Array[Comment] - def trailing_comments - @trailing_comments ||= [] - end - - # Attach a comment to the trailing comments of this location. - # - #: (Comment comment) -> void - def trailing_comment(comment) - trailing_comments << comment - end - - # Returns all comments that are associated with this location (both leading - # and trailing comments). - # - #: () -> Array[Comment] - def comments - [*@leading_comments, *@trailing_comments] #: Array[Comment] end # Create a new location object with the given options. @@ -903,9 +896,6 @@ def inspect # :nodoc: # It contains the requested structure, any comments that were encounters, # and any errors that were encountered. class Result - # The list of comments that were encountered during parsing. - attr_reader :comments #: Array[Comment] - # The list of magic comments that were encountered during parsing. attr_reader :magic_comments #: Array[MagicComment] @@ -925,9 +915,8 @@ class Result # Create a new result object with the given values. # - #: (Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize(comments, magic_comments, data_loc, errors, warnings, continuable, source) - @comments = comments + #: (Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize(magic_comments, data_loc, errors, warnings, continuable, source) @magic_comments = magic_comments @data_loc = data_loc @errors = errors @@ -936,6 +925,13 @@ def initialize(comments, magic_comments, data_loc, errors, warnings, continuable @source = source end + # The list of comments that were encountered during parsing. + # + #: () -> Array[Comment] + def comments + source.comments + end + # Implement the hash pattern matching interface for Result. # #: (Array[Symbol]? keys) -> Hash[Symbol, untyped] @@ -1001,11 +997,9 @@ def code_units_cache(encoding) # This is a result specific to the `parse` and `parse_file` methods. class ParseResult < Result - autoload :Comments, "prism/parse_result/comments" autoload :Errors, "prism/parse_result/errors" autoload :Newlines, "prism/parse_result/newlines" - private_constant :Comments private_constant :Errors private_constant :Newlines @@ -1014,10 +1008,10 @@ class ParseResult < Result # Create a new parse result object with the given values. # - #: (ProgramNode value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize(value, comments, magic_comments, data_loc, errors, warnings, continuable, source) + #: (ProgramNode value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source) @value = value - super(comments, magic_comments, data_loc, errors, warnings, continuable, source) + super(magic_comments, data_loc, errors, warnings, continuable, source) end # Implement the hash pattern matching interface for ParseResult. @@ -1027,13 +1021,6 @@ def deconstruct_keys(keys) # :nodoc: super.merge!(value: value) end - # Attach the list of comments to their respective locations in the tree. - # - #: () -> void - def attach_comments! - Comments.new(self).attach! # steep:ignore - end - # Walk the tree and mark nodes that are on a new line, loosely emulating # the behavior of CRuby's `:line` tracepoint event. # @@ -1058,10 +1045,10 @@ class LexResult < Result # Create a new lex result object with the given values. # - #: (Array[Token] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize(value, comments, magic_comments, data_loc, errors, warnings, continuable, source) + #: (Array[Token] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source) @value = value - super(comments, magic_comments, data_loc, errors, warnings, continuable, source) + super(magic_comments, data_loc, errors, warnings, continuable, source) end # Implement the hash pattern matching interface for LexResult. @@ -1080,10 +1067,10 @@ class ParseLexResult < Result # Create a new parse lex result object with the given values. # - #: ([ProgramNode, Array[Token]] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize(value, comments, magic_comments, data_loc, errors, warnings, continuable, source) + #: ([ProgramNode, Array[Token]] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source) @value = value - super(comments, magic_comments, data_loc, errors, warnings, continuable, source) + super(magic_comments, data_loc, errors, warnings, continuable, source) end # Implement the hash pattern matching interface for ParseLexResult. diff --git a/lib/prism/parse_result/comments.rb b/lib/prism/parse_result/comments.rb deleted file mode 100644 index b5943496eb..0000000000 --- a/lib/prism/parse_result/comments.rb +++ /dev/null @@ -1,219 +0,0 @@ -# frozen_string_literal: true -# :markup: markdown -#-- -# rbs_inline: enabled - -module Prism - class ParseResult < Result - # When we've parsed the source, we have both the syntax tree and the list of - # comments that we found in the source. This class is responsible for - # walking the tree and finding the nearest location to attach each comment. - # - # It does this by first finding the nearest locations to each comment. - # Locations can either come from nodes directly or from location fields on - # nodes. For example, a `ClassNode` has an overall location encompassing the - # entire class, but it also has a location for the `class` keyword. - # - # Once the nearest locations are found, it determines which one to attach - # to. If it's a trailing comment (a comment on the same line as other source - # code), it will favor attaching to the nearest location that occurs before - # the comment. Otherwise it will favor attaching to the nearest location - # that is after the comment. - class Comments - # @rbs! - # # An internal interface for a target that comments can be attached - # # to. This is either going to be a NodeTarget or a CommentTarget. - # interface _CommentTarget - # def start_offset: () -> Integer - # def end_offset: () -> Integer - # def encloses?: (Comment) -> bool - # def leading_comment: (Comment) -> void - # def trailing_comment: (Comment) -> void - # end - - # A target for attaching comments that is based on a specific node's - # location. - class NodeTarget # :nodoc: - attr_reader :node #: node - - #: (node node) -> void - def initialize(node) - @node = node - end - - #: () -> Integer - def start_offset - node.start_offset - end - - #: () -> Integer - def end_offset - node.end_offset - end - - #: (Comment comment) -> bool - def encloses?(comment) - start_offset <= comment.location.start_offset && - comment.location.end_offset <= end_offset - end - - #: (Comment comment) -> void - def leading_comment(comment) - node.location.leading_comment(comment) - end - - #: (Comment comment) -> void - def trailing_comment(comment) - node.location.trailing_comment(comment) - end - end - - # A target for attaching comments that is based on a location field on a - # node. For example, the `end` token of a ClassNode. - class LocationTarget # :nodoc: - attr_reader :location #: Location - - #: (Location location) -> void - def initialize(location) - @location = location - end - - #: () -> Integer - def start_offset - location.start_offset - end - - #: () -> Integer - def end_offset - location.end_offset - end - - #: (Comment comment) -> bool - def encloses?(comment) - false - end - - #: (Comment comment) -> void - def leading_comment(comment) - location.leading_comment(comment) - end - - #: (Comment comment) -> void - def trailing_comment(comment) - location.trailing_comment(comment) - end - end - - # The parse result that we are attaching comments to. - attr_reader :parse_result #: ParseResult - - # Create a new Comments object that will attach comments to the given - # parse result. - # - #: (ParseResult parse_result) -> void - def initialize(parse_result) - @parse_result = parse_result - end - - # Attach the comments to their respective locations in the tree by - # mutating the parse result. - # - #: () -> void - def attach! - parse_result.comments.each do |comment| - preceding, enclosing, following = nearest_targets(parse_result.value, comment) - - if comment.trailing? - if preceding - preceding.trailing_comment(comment) - else - (following || enclosing || NodeTarget.new(parse_result.value)).leading_comment(comment) - end - else - # If a comment exists on its own line, prefer a leading comment. - if following - following.leading_comment(comment) - elsif preceding - preceding.trailing_comment(comment) - else - (enclosing || NodeTarget.new(parse_result.value)).leading_comment(comment) - end - end - end - end - - private - - # Responsible for finding the nearest targets to the given comment within - # the context of the given encapsulating node. - # - #: (node node, Comment comment) -> [_CommentTarget?, _CommentTarget?, _CommentTarget?] - def nearest_targets(node, comment) - comment_start = comment.location.start_offset - comment_end = comment.location.end_offset - - targets = [] #: Array[_CommentTarget] - node.comment_targets.map do |value| - case value - when StatementsNode - targets.concat(value.body.map { |node| NodeTarget.new(node) }) - when Node - targets << NodeTarget.new(value) - when Location - targets << LocationTarget.new(value) - end - end - - targets.sort_by!(&:start_offset) - preceding = nil #: _CommentTarget? - following = nil #: _CommentTarget? - - left = 0 - right = targets.length - - # This is a custom binary search that finds the nearest nodes to the - # given comment. When it finds a node that completely encapsulates the - # comment, it recurses downward into the tree. - while left < right - middle = (left + right) / 2 - target = targets[middle] - - target_start = target.start_offset - target_end = target.end_offset - - if target.encloses?(comment) - # @type var target: NodeTarget - # The comment is completely contained by this target. Abandon the - # binary search at this level. - return nearest_targets(target.node, comment) - end - - if target_end <= comment_start - # This target falls completely before the comment. Because we will - # never consider this target or any targets before it again, this - # target must be the closest preceding target we have encountered so - # far. - preceding = target - left = middle + 1 - next - end - - if comment_end <= target_start - # This target falls completely after the comment. Because we will - # never consider this target or any targets after it again, this - # target must be the closest following target we have encountered so - # far. - following = target - right = middle - next - end - - # This should only happen if there is a bug in this parser. - raise "Comment location overlaps with a target location" - end - - [preceding, NodeTarget.new(node), following] - end - end - end -end diff --git a/lib/prism/relocation.rb b/lib/prism/relocation.rb index fcf51f247d..37b60d004b 100644 --- a/lib/prism/relocation.rb +++ b/lib/prism/relocation.rb @@ -33,8 +33,6 @@ module Relocation # def end_character_column: () -> Integer # def cached_start_code_units_column: (_CodeUnitsCache cache) -> Integer # def cached_end_code_units_column: (_CodeUnitsCache cache) -> Integer - # def leading_comments: () -> Array[Comment] - # def trailing_comments: () -> Array[Comment] # end # # interface _Field @@ -170,27 +168,6 @@ def end_code_units_column fetch_value(:end_code_units_column) end - # Fetch the leading comments of the value. - # - #: () -> Array[CommentsField::Comment] - def leading_comments - fetch_value(:leading_comments) - end - - # Fetch the trailing comments of the value. - # - #: () -> Array[CommentsField::Comment] - def trailing_comments - fetch_value(:trailing_comments) - end - - # Fetch the leading and trailing comments of the value. - # - #: () -> Array[CommentsField::Comment] - def comments - [*leading_comments, *trailing_comments] - end - # Reify the values on this entry with the given values. This is an # internal-only API that is called from the repository when it is time to # reify the values. @@ -427,51 +404,6 @@ def cache end end - # An abstract field used as the parent class of the two comments fields. - class CommentsField - # An object that represents a slice of a comment. - class Comment - # The slice of the comment. - attr_reader :slice #: String - - # Initialize a new comment with the given slice. - # - #: (String slice) -> void - def initialize(slice) - @slice = slice - end - end - - private - - # Create comment objects from the given values. - # - #: (entry_value values) -> Array[Comment] - def comments(values) - values.map { |value| Comment.new(value.slice) } - end - end - - # A field representing the leading comments. - class LeadingCommentsField < CommentsField - # Fetches the leading comments of a value. - # - #: (_Value value) -> entry_values - def fields(value) - { leading_comments: comments(value.leading_comments) } - end - end - - # A field representing the trailing comments. - class TrailingCommentsField < CommentsField - # Fetches the trailing comments of a value. - # - #: (_Value value) -> entry_values - def fields(value) - { trailing_comments: comments(value.trailing_comments) } - end - end - # A repository is a configured collection of fields and a set of entries # that knows how to reparse a source and reify the values. class Repository @@ -567,30 +499,6 @@ def code_unit_columns(encoding) field(:code_unit_columns, CodeUnitColumnsField.new(self, encoding)) end - # Configure the leading comments field for this repository and return - # self. - # - #: () -> self - def leading_comments - field(:leading_comments, LeadingCommentsField.new) - end - - # Configure the trailing comments field for this repository and return - # self. - # - #: () -> self - def trailing_comments - field(:trailing_comments, TrailingCommentsField.new) - end - - # Configure both the leading and trailing comment fields for this - # repository and return self. - # - #: () -> self - def comments - leading_comments.trailing_comments - end - # This method is called from nodes and locations when they want to enter # themselves into the repository. It it internal-only and meant to be # called from the #save* APIs. @@ -610,12 +518,6 @@ def enter(node_id, field_name) # :nodoc: def reify! # :nodoc: result = source.result - # Attach the comments if they have been requested as part of the - # configuration of this repository. - if fields.key?(:leading_comments) || fields.key?(:trailing_comments) - result.attach_comments! - end - queue = [result.value] #: Array[Prism::node] while (node = queue.shift) @entries[node.node_id].each do |field_name, entry| diff --git a/lib/prism/translation/ruby_parser.rb b/lib/prism/translation/ruby_parser.rb index bcd42e089e..213464a771 100644 --- a/lib/prism/translation/ruby_parser.rb +++ b/lib/prism/translation/ruby_parser.rb @@ -35,11 +35,19 @@ class Compiler < ::Prism::Compiler # :nodoc: # pattern, so we need to track that state. attr_reader :in_pattern + # The list of comments from the parse result, sorted by start offset. + attr_reader :parse_comments + + # The source string being compiled. + attr_reader :source_string + # Initialize a new compiler with the given file name. - def initialize(file, in_def: false, in_pattern: false) + def initialize(file, in_def: false, in_pattern: false, parse_comments: [], source_string: "") @file = file @in_def = in_def @in_pattern = in_pattern + @parse_comments = parse_comments + @source_string = source_string end # alias foo bar @@ -1549,20 +1557,48 @@ def visit_yield_node(node) private - # Attach prism comments to the given sexp. + # Attach leading comments to the given sexp, mirroring ruby_parser's + # behavior: all comments preceding the class/module/def keyword are + # attached as long as no source code appears between the last comment + # and the keyword. Blank lines between comments are preserved. def attach_comments(sexp, node) - return unless node.comments - return if node.comments.empty? + node_start = node.location.start_offset + leading = [] + + parse_comments.each do |comment| + if comment.location.start_offset < node_start + leading << comment + end + end + + return if leading.empty? + + # Walk backwards and drop comments that have source code between + # them and the node (or between them and the next kept comment). + result = [] + boundary = node_start + + leading.reverse_each do |comment| + gap = source_string[comment.location.end_offset...boundary] + + if gap.match?(/\S/) + break + end + + result.unshift(comment) + boundary = comment.location.start_offset + end + + return if result.empty? - extra = node.location.start_line - node.comments.last.location.start_line - comments = node.comments.map(&:slice) - comments.concat([nil] * [0, extra].max) - sexp.comments = comments.join("\n") + # Build the comment string from the first comment through to the + # keyword, preserving blank lines (mirroring ruby_parser's lexer). + sexp.comments = source_string[result.first.location.start_offset...node_start].gsub(/^ +#/, "#").gsub(/^ +$/, "") end # Create a new compiler with the given options. def copy_compiler(in_def: self.in_def, in_pattern: self.in_pattern) - self.class.new(file, in_def: in_def, in_pattern: in_pattern) + self.class.new(file, in_def: in_def, in_pattern: in_pattern, parse_comments: parse_comments, source_string: source_string) end # Create a new Sexp object from the given prism node and arguments. @@ -1678,8 +1714,7 @@ def translate(result, filepath) raise ::RubyParser::SyntaxError, "#{filepath}:#{error.location.start_line} :: #{error.message}" end - result.attach_comments! - result.value.accept(self.class::Compiler.new(filepath)) + result.value.accept(self.class::Compiler.new(filepath, parse_comments: result.comments, source_string: result.source.source)) end end end diff --git a/prism.gemspec b/prism.gemspec index fc2c944d3b..db4b311ca3 100644 --- a/prism.gemspec +++ b/prism.gemspec @@ -122,7 +122,6 @@ Gem::Specification.new do |spec| "lib/prism/node_find.rb", "lib/prism/node.rb", "lib/prism/parse_result.rb", - "lib/prism/parse_result/comments.rb", "lib/prism/parse_result/errors.rb", "lib/prism/parse_result/newlines.rb", "lib/prism/pattern.rb", @@ -170,7 +169,6 @@ Gem::Specification.new do |spec| "rbi/generated/prism/string_query.rbi", "rbi/generated/prism/translation.rbi", "rbi/generated/prism/visitor.rbi", - "rbi/generated/prism/parse_result/comments.rbi", "rbi/generated/prism/parse_result/errors.rbi", "rbi/generated/prism/parse_result/newlines.rbi", "rbi/prism/translation/parser.rbi", @@ -197,13 +195,13 @@ Gem::Specification.new do |spec| "sig/generated/prism/string_query.rbs", "sig/generated/prism/translation.rbs", "sig/generated/prism/visitor.rbs", - "sig/generated/prism/parse_result/comments.rbs", "sig/generated/prism/parse_result/errors.rbs", "sig/generated/prism/parse_result/newlines.rbs", "sig/manifest.yaml", "src/arena.c", "src/buffer.c", "src/char.c", + "src/comments.c", "src/constant_pool.c", "src/diagnostic.c", "src/encoding.c", diff --git a/rakelib/typecheck.rake b/rakelib/typecheck.rake index 4eaf0974ce..1f74d707cf 100644 --- a/rakelib/typecheck.rake +++ b/rakelib/typecheck.rake @@ -2,7 +2,7 @@ namespace :typecheck do class RBICompiler - INODE = Set.new(%i[accept child_nodes comment_targets compact_child_nodes deconstruct each_child_node inspect type]) + INODE = Set.new(%i[accept child_nodes compact_child_nodes deconstruct each_child_node inspect type]) attr_reader :parent diff --git a/rbi/generated/prism.rbi b/rbi/generated/prism.rbi index 743358173d..078174b448 100644 --- a/rbi/generated/prism.rbi +++ b/rbi/generated/prism.rbi @@ -33,54 +33,54 @@ module Prism VERSION = T.let(nil, String) BACKEND = T.let(nil, Symbol) - sig { params(source: String, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseResult) } - def self.parse(source, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(source: String, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseResult) } + def self.parse(source, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(source: String, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).void } - def self.profile(source, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(source: String, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).void } + def self.profile(source, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(source: String, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(LexResult) } - def self.lex(source, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(source: String, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(LexResult) } + def self.lex(source, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(source: String, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseLexResult) } - def self.parse_lex(source, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(source: String, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseLexResult) } + def self.parse_lex(source, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(source: String, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(String) } - def self.dump(source, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(source: String, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(String) } + def self.dump(source, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(source: String, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Array[Comment]) } - def self.parse_comments(source, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(source: String, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Array[Comment]) } + def self.parse_comments(source, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(source: String, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Boolean) } - def self.parse_success?(source, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(source: String, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Boolean) } + def self.parse_success?(source, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(source: String, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Boolean) } - def self.parse_failure?(source, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(source: String, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Boolean) } + def self.parse_failure?(source, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(stream: ::T.untyped, filepath: String, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseResult) } - def self.parse_stream(stream, filepath: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(stream: ::T.untyped, filepath: String, attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseResult) } + def self.parse_stream(stream, filepath: T.unsafe(nil), attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(filepath: ::T.any(String, Pathname, IO), command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseResult) } - def self.parse_file(filepath, command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(filepath: ::T.any(String, Pathname, IO), attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseResult) } + def self.parse_file(filepath, attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(filepath: ::T.any(String, Pathname, IO), command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).void } - def self.profile_file(filepath, command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(filepath: ::T.any(String, Pathname, IO), attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).void } + def self.profile_file(filepath, attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(filepath: ::T.any(String, Pathname, IO), command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(LexResult) } - def self.lex_file(filepath, command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(filepath: ::T.any(String, Pathname, IO), attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(LexResult) } + def self.lex_file(filepath, attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(filepath: ::T.any(String, Pathname, IO), command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseLexResult) } - def self.parse_lex_file(filepath, command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(filepath: ::T.any(String, Pathname, IO), attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(ParseLexResult) } + def self.parse_lex_file(filepath, attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(filepath: ::T.any(String, Pathname, IO), command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(String) } - def self.dump_file(filepath, command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(filepath: ::T.any(String, Pathname, IO), attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(String) } + def self.dump_file(filepath, attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(filepath: ::T.any(String, Pathname, IO), command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Array[Comment]) } - def self.parse_file_comments(filepath, command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(filepath: ::T.any(String, Pathname, IO), attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Array[Comment]) } + def self.parse_file_comments(filepath, attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(filepath: ::T.any(String, Pathname, IO), command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Boolean) } - def self.parse_file_success?(filepath, command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(filepath: ::T.any(String, Pathname, IO), attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Boolean) } + def self.parse_file_success?(filepath, attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end - sig { params(filepath: ::T.any(String, Pathname, IO), command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Boolean) } - def self.parse_file_failure?(filepath, command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end + sig { params(filepath: ::T.any(String, Pathname, IO), attach_comments: T::Boolean, command_line: String, encoding: ::T.any(Encoding, FalseClass), freeze: T::Boolean, frozen_string_literal: T::Boolean, line: Integer, main_script: T::Boolean, partial_script: T::Boolean, raise_error: ::T.any(Symbol, TrueClass), scopes: T::Array[T::Array[Symbol]], version: String).returns(T::Boolean) } + def self.parse_file_failure?(filepath, attach_comments: T.unsafe(nil), command_line: T.unsafe(nil), encoding: T.unsafe(nil), freeze: T.unsafe(nil), frozen_string_literal: T.unsafe(nil), line: T.unsafe(nil), main_script: T.unsafe(nil), partial_script: T.unsafe(nil), raise_error: T.unsafe(nil), scopes: T.unsafe(nil), version: T.unsafe(nil)); end end diff --git a/rbi/generated/prism/lex_compat.rbi b/rbi/generated/prism/lex_compat.rbi index 4cce898471..7e7fe84920 100644 --- a/rbi/generated/prism/lex_compat.rbi +++ b/rbi/generated/prism/lex_compat.rbi @@ -44,8 +44,8 @@ module Prism attr_reader :value # Create a new lex compat result object with the given values. - sig { params(value: T::Array[[[Integer, Integer], Symbol, String, ::T.untyped]], comments: T::Array[Comment], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } - def initialize(value, comments, magic_comments, data_loc, errors, warnings, continuable, source); end + sig { params(value: T::Array[[[Integer, Integer], Symbol, String, ::T.untyped]], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } + def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source); end # Implement the hash pattern matching interface for Result. sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) } diff --git a/rbi/generated/prism/node.rbi b/rbi/generated/prism/node.rbi index 94c7d4f077..e1a3eaae17 100644 --- a/rbi/generated/prism/node.rbi +++ b/rbi/generated/prism/node.rbi @@ -94,15 +94,8 @@ module Prism sig { params(cache: ::T.untyped).returns(Integer) } def cached_end_code_units_column(cache); end - # Delegates to [`leading_comments`](rdoc-ref:Location#leading_comments) of the associated location object. - sig { returns(T::Array[Comment]) } - def leading_comments; end - - # Delegates to [`trailing_comments`](rdoc-ref:Location#trailing_comments) of the associated location object. - sig { returns(T::Array[Comment]) } - def trailing_comments; end - - # Delegates to [`comments`](rdoc-ref:Location#comments) of the associated location object. + # The comments attached to this node, ordered by start offset. Comments are + # only attached when the source is parsed with the attach_comments option. sig { returns(T::Array[Comment]) } def comments; end @@ -208,11 +201,6 @@ module Prism sig { abstract.returns(T::Array[Node]) } def compact_child_nodes; end - # Returns an array of child nodes and locations that could potentially have - # comments attached to them. - sig { abstract.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Returns a string representation of the node. sig { abstract.returns(String) } def inspect; end @@ -266,10 +254,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, new_name: ::T.any(GlobalVariableReadNode, BackReferenceReadNode, NumberedReferenceReadNode), old_name: ::T.any(GlobalVariableReadNode, BackReferenceReadNode, NumberedReferenceReadNode), keyword_loc: Location).returns(AliasGlobalVariableNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), new_name: T.unsafe(nil), old_name: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -351,10 +335,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, new_name: ::T.any(SymbolNode, InterpolatedSymbolNode), old_name: ::T.any(SymbolNode, InterpolatedSymbolNode), keyword_loc: Location).returns(AliasMethodNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), new_name: T.unsafe(nil), old_name: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -448,10 +428,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, left: Node, right: Node, operator_loc: Location).returns(AlternationPatternNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), left: T.unsafe(nil), right: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -533,10 +509,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, left: Node, right: Node, operator_loc: Location).returns(AndNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), left: T.unsafe(nil), right: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -624,10 +596,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, arguments: T::Array[Node]).returns(ArgumentsNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), arguments: T.unsafe(nil)); end @@ -706,10 +674,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, elements: T::Array[Node], opening_loc: ::T.nilable(Location), closing_loc: ::T.nilable(Location)).returns(ArrayNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), elements: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -817,10 +781,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, constant: ::T.nilable(::T.any(ConstantPathNode, ConstantReadNode)), requireds: T::Array[Node], rest: ::T.nilable(::T.any(ImplicitRestNode, SplatNode)), posts: T::Array[Node], opening_loc: ::T.nilable(Location), closing_loc: ::T.nilable(Location)).returns(ArrayPatternNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), constant: T.unsafe(nil), requireds: T.unsafe(nil), rest: T.unsafe(nil), posts: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -938,10 +898,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, key: Node, value: Node, operator_loc: ::T.nilable(Location)).returns(AssocNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), key: T.unsafe(nil), value: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -1032,10 +988,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, value: ::T.nilable(Node), operator_loc: Location).returns(AssocSplatNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), value: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -1110,10 +1062,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(BackReferenceReadNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -1175,10 +1123,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, begin_keyword_loc: ::T.nilable(Location), statements: ::T.nilable(StatementsNode), rescue_clause: ::T.nilable(RescueNode), else_clause: ::T.nilable(ElseNode), ensure_clause: ::T.nilable(EnsureNode), end_keyword_loc: ::T.nilable(Location)).returns(BeginNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), begin_keyword_loc: T.unsafe(nil), statements: T.unsafe(nil), rescue_clause: T.unsafe(nil), else_clause: T.unsafe(nil), ensure_clause: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -1290,10 +1234,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, expression: ::T.nilable(Node), operator_loc: Location).returns(BlockArgumentNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), expression: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -1368,10 +1308,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(BlockLocalVariableNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -1434,10 +1370,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, locals: T::Array[Symbol], parameters: ::T.nilable(::T.any(BlockParametersNode, NumberedParametersNode, ItParametersNode)), body: ::T.nilable(::T.any(StatementsNode, BeginNode)), opening_loc: Location, closing_loc: Location).returns(BlockNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), locals: T.unsafe(nil), parameters: T.unsafe(nil), body: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -1547,10 +1479,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: ::T.nilable(Symbol), name_loc: ::T.nilable(Location), operator_loc: Location).returns(BlockParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -1647,10 +1575,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, parameters: ::T.nilable(ParametersNode), locals: T::Array[BlockLocalVariableNode], opening_loc: ::T.nilable(Location), closing_loc: ::T.nilable(Location)).returns(BlockParametersNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), parameters: T.unsafe(nil), locals: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -1764,10 +1688,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, arguments: ::T.nilable(ArgumentsNode), keyword_loc: Location).returns(BreakNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), arguments: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -1842,10 +1762,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: ::T.nilable(Node), call_operator_loc: ::T.nilable(Location), message_loc: ::T.nilable(Location), read_name: Symbol, write_name: Symbol, operator_loc: Location, value: Node).returns(CallAndWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), call_operator_loc: T.unsafe(nil), message_loc: T.unsafe(nil), read_name: T.unsafe(nil), write_name: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -2004,10 +1920,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: ::T.nilable(Node), call_operator_loc: ::T.nilable(Location), name: Symbol, message_loc: ::T.nilable(Location), opening_loc: ::T.nilable(Location), arguments: ::T.nilable(ArgumentsNode), closing_loc: ::T.nilable(Location), equal_loc: ::T.nilable(Location), block: ::T.nilable(::T.any(BlockNode, BlockArgumentNode))).returns(CallNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), call_operator_loc: T.unsafe(nil), name: T.unsafe(nil), message_loc: T.unsafe(nil), opening_loc: T.unsafe(nil), arguments: T.unsafe(nil), closing_loc: T.unsafe(nil), equal_loc: T.unsafe(nil), block: T.unsafe(nil)); end @@ -2195,10 +2107,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: ::T.nilable(Node), call_operator_loc: ::T.nilable(Location), message_loc: ::T.nilable(Location), read_name: Symbol, write_name: Symbol, binary_operator: Symbol, binary_operator_loc: Location, value: Node).returns(CallOperatorWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), call_operator_loc: T.unsafe(nil), message_loc: T.unsafe(nil), read_name: T.unsafe(nil), write_name: T.unsafe(nil), binary_operator: T.unsafe(nil), binary_operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -2345,10 +2253,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: ::T.nilable(Node), call_operator_loc: ::T.nilable(Location), message_loc: ::T.nilable(Location), read_name: Symbol, write_name: Symbol, operator_loc: Location, value: Node).returns(CallOrWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), call_operator_loc: T.unsafe(nil), message_loc: T.unsafe(nil), read_name: T.unsafe(nil), write_name: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -2500,10 +2404,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: Node, call_operator_loc: Location, name: Symbol, message_loc: Location).returns(CallTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), call_operator_loc: T.unsafe(nil), name: T.unsafe(nil), message_loc: T.unsafe(nil)); end @@ -2617,10 +2517,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, value: Node, target: LocalVariableTargetNode, operator_loc: Location).returns(CapturePatternNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), value: T.unsafe(nil), target: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -2704,10 +2600,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, predicate: ::T.nilable(Node), conditions: T::Array[InNode], else_clause: ::T.nilable(ElseNode), case_keyword_loc: Location, end_keyword_loc: Location).returns(CaseMatchNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), predicate: T.unsafe(nil), conditions: T.unsafe(nil), else_clause: T.unsafe(nil), case_keyword_loc: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -2814,10 +2706,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, predicate: ::T.nilable(Node), conditions: T::Array[WhenNode], else_clause: ::T.nilable(ElseNode), case_keyword_loc: Location, end_keyword_loc: Location).returns(CaseNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), predicate: T.unsafe(nil), conditions: T.unsafe(nil), else_clause: T.unsafe(nil), case_keyword_loc: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -2922,10 +2810,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, locals: T::Array[Symbol], class_keyword_loc: Location, constant_path: ::T.any(ConstantReadNode, ConstantPathNode), inheritance_operator_loc: ::T.nilable(Location), superclass: ::T.nilable(Node), body: ::T.nilable(::T.any(StatementsNode, BeginNode)), end_keyword_loc: Location, name: Symbol).returns(ClassNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), locals: T.unsafe(nil), class_keyword_loc: T.unsafe(nil), constant_path: T.unsafe(nil), inheritance_operator_loc: T.unsafe(nil), superclass: T.unsafe(nil), body: T.unsafe(nil), end_keyword_loc: T.unsafe(nil), name: T.unsafe(nil)); end @@ -3053,10 +2937,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(ClassVariableAndWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -3150,10 +3030,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Node, binary_operator: Symbol).returns(ClassVariableOperatorWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), binary_operator_loc: T.unsafe(nil), value: T.unsafe(nil), binary_operator: T.unsafe(nil)); end @@ -3235,10 +3111,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(ClassVariableOrWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -3320,10 +3192,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(ClassVariableReadNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -3383,10 +3251,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(ClassVariableTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -3442,10 +3306,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, value: Node, operator_loc: Location).returns(ClassVariableWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), value: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -3543,10 +3403,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(ConstantAndWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -3628,10 +3484,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Node, binary_operator: Symbol).returns(ConstantOperatorWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), binary_operator_loc: T.unsafe(nil), value: T.unsafe(nil), binary_operator: T.unsafe(nil)); end @@ -3713,10 +3565,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(ConstantOrWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -3798,10 +3646,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, target: ConstantPathNode, operator_loc: Location, value: Node).returns(ConstantPathAndWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), target: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -3874,10 +3718,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, parent: ::T.nilable(Node), name: ::T.nilable(Symbol), delimiter_loc: Location, name_loc: Location).returns(ConstantPathNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), parent: T.unsafe(nil), name: T.unsafe(nil), delimiter_loc: T.unsafe(nil), name_loc: T.unsafe(nil)); end @@ -3980,10 +3820,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, target: ConstantPathNode, binary_operator_loc: Location, value: Node, binary_operator: Symbol).returns(ConstantPathOperatorWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), target: T.unsafe(nil), binary_operator_loc: T.unsafe(nil), value: T.unsafe(nil), binary_operator: T.unsafe(nil)); end @@ -4056,10 +3892,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, target: ConstantPathNode, operator_loc: Location, value: Node).returns(ConstantPathOrWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), target: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -4132,10 +3964,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, parent: ::T.nilable(Node), name: ::T.nilable(Symbol), delimiter_loc: Location, name_loc: Location).returns(ConstantPathTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), parent: T.unsafe(nil), name: T.unsafe(nil), delimiter_loc: T.unsafe(nil), name_loc: T.unsafe(nil)); end @@ -4223,10 +4051,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, target: ConstantPathNode, operator_loc: Location, value: Node).returns(ConstantPathWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), target: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -4311,10 +4135,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(ConstantReadNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -4374,10 +4194,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(ConstantTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -4433,10 +4249,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, value: Node, operator_loc: Location).returns(ConstantWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), value: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -4535,10 +4347,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, receiver: ::T.nilable(Node), parameters: ::T.nilable(ParametersNode), body: ::T.nilable(::T.any(StatementsNode, BeginNode)), locals: T::Array[Symbol], def_keyword_loc: Location, operator_loc: ::T.nilable(Location), lparen_loc: ::T.nilable(Location), rparen_loc: ::T.nilable(Location), equal_loc: ::T.nilable(Location), end_keyword_loc: ::T.nilable(Location)).returns(DefNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), receiver: T.unsafe(nil), parameters: T.unsafe(nil), body: T.unsafe(nil), locals: T.unsafe(nil), def_keyword_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), lparen_loc: T.unsafe(nil), rparen_loc: T.unsafe(nil), equal_loc: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -4697,10 +4505,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, lparen_loc: ::T.nilable(Location), value: Node, rparen_loc: ::T.nilable(Location), keyword_loc: Location).returns(DefinedNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), lparen_loc: T.unsafe(nil), value: T.unsafe(nil), rparen_loc: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -4795,10 +4599,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, else_keyword_loc: Location, statements: ::T.nilable(StatementsNode), end_keyword_loc: ::T.nilable(Location)).returns(ElseNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), else_keyword_loc: T.unsafe(nil), statements: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -4880,10 +4680,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: Location, statements: ::T.nilable(StatementsNode), closing_loc: Location).returns(EmbeddedStatementsNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), statements: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -4965,10 +4761,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, operator_loc: Location, variable: ::T.any(InstanceVariableReadNode, ClassVariableReadNode, GlobalVariableReadNode, BackReferenceReadNode, NumberedReferenceReadNode)).returns(EmbeddedVariableNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), operator_loc: T.unsafe(nil), variable: T.unsafe(nil)); end @@ -5041,10 +4833,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, ensure_keyword_loc: Location, statements: ::T.nilable(StatementsNode), end_keyword_loc: Location).returns(EnsureNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), ensure_keyword_loc: T.unsafe(nil), statements: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -5123,10 +4911,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, unexpected: ::T.nilable(Node)).returns(ErrorRecoveryNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), unexpected: T.unsafe(nil)); end @@ -5182,10 +4966,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(FalseNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -5246,10 +5026,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, constant: ::T.nilable(::T.any(ConstantPathNode, ConstantReadNode)), left: SplatNode, requireds: T::Array[Node], right: SplatNode, opening_loc: ::T.nilable(Location), closing_loc: ::T.nilable(Location)).returns(FindPatternNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), constant: T.unsafe(nil), left: T.unsafe(nil), requireds: T.unsafe(nil), right: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -5376,10 +5152,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, left: ::T.nilable(Node), right: ::T.nilable(Node), operator_loc: Location).returns(FlipFlopNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), left: T.unsafe(nil), right: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -5456,10 +5228,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, value: Float).returns(FloatNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), value: T.unsafe(nil)); end @@ -5515,10 +5283,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, index: ::T.any(LocalVariableTargetNode, InstanceVariableTargetNode, ClassVariableTargetNode, GlobalVariableTargetNode, ConstantTargetNode, ConstantPathTargetNode, CallTargetNode, IndexTargetNode, MultiTargetNode), collection: Node, statements: ::T.nilable(StatementsNode), for_keyword_loc: Location, in_keyword_loc: Location, do_keyword_loc: ::T.nilable(Location), end_keyword_loc: Location).returns(ForNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), index: T.unsafe(nil), collection: T.unsafe(nil), statements: T.unsafe(nil), for_keyword_loc: T.unsafe(nil), in_keyword_loc: T.unsafe(nil), do_keyword_loc: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -5659,10 +5423,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(ForwardingArgumentsNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -5715,10 +5475,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(ForwardingParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -5775,10 +5531,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, keyword_loc: Location, block: ::T.nilable(BlockNode)).returns(ForwardingSuperNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), keyword_loc: T.unsafe(nil), block: T.unsafe(nil)); end @@ -5851,10 +5603,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(GlobalVariableAndWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -5936,10 +5684,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Node, binary_operator: Symbol).returns(GlobalVariableOperatorWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), binary_operator_loc: T.unsafe(nil), value: T.unsafe(nil), binary_operator: T.unsafe(nil)); end @@ -6021,10 +5765,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(GlobalVariableOrWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -6106,10 +5846,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(GlobalVariableReadNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -6169,10 +5905,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(GlobalVariableTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -6228,10 +5960,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, value: Node, operator_loc: Location).returns(GlobalVariableWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), value: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -6329,10 +6057,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: Location, elements: T::Array[::T.any(AssocNode, AssocSplatNode)], closing_loc: Location).returns(HashNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), elements: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -6435,10 +6159,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, constant: ::T.nilable(::T.any(ConstantPathNode, ConstantReadNode)), elements: T::Array[AssocNode], rest: ::T.nilable(::T.any(AssocSplatNode, NoKeywordsParameterNode)), opening_loc: ::T.nilable(Location), closing_loc: ::T.nilable(Location)).returns(HashPatternNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), constant: T.unsafe(nil), elements: T.unsafe(nil), rest: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -6564,10 +6284,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, if_keyword_loc: ::T.nilable(Location), predicate: Node, then_keyword_loc: ::T.nilable(Location), statements: ::T.nilable(StatementsNode), subsequent: ::T.nilable(::T.any(ElseNode, IfNode)), end_keyword_loc: ::T.nilable(Location)).returns(IfNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), if_keyword_loc: T.unsafe(nil), predicate: T.unsafe(nil), then_keyword_loc: T.unsafe(nil), statements: T.unsafe(nil), subsequent: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -6716,10 +6432,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, numeric: ::T.any(FloatNode, IntegerNode, RationalNode)).returns(ImaginaryNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), numeric: T.unsafe(nil)); end @@ -6781,10 +6493,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, value: ::T.any(LocalVariableReadNode, CallNode, ConstantReadNode, LocalVariableTargetNode)).returns(ImplicitNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), value: T.unsafe(nil)); end @@ -6849,10 +6557,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(ImplicitRestNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -6904,10 +6608,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, pattern: Node, statements: ::T.nilable(StatementsNode), in_keyword_loc: Location, then_keyword_loc: ::T.nilable(Location)).returns(InNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), pattern: T.unsafe(nil), statements: T.unsafe(nil), in_keyword_loc: T.unsafe(nil), then_keyword_loc: T.unsafe(nil)); end @@ -6993,10 +6693,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: ::T.nilable(Node), call_operator_loc: ::T.nilable(Location), opening_loc: Location, arguments: ::T.nilable(ArgumentsNode), closing_loc: Location, block: ::T.nilable(BlockArgumentNode), operator_loc: Location, value: Node).returns(IndexAndWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), call_operator_loc: T.unsafe(nil), opening_loc: T.unsafe(nil), arguments: T.unsafe(nil), closing_loc: T.unsafe(nil), block: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -7132,10 +6828,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: ::T.nilable(Node), call_operator_loc: ::T.nilable(Location), opening_loc: Location, arguments: ::T.nilable(ArgumentsNode), closing_loc: Location, block: ::T.nilable(BlockArgumentNode), binary_operator: Symbol, binary_operator_loc: Location, value: Node).returns(IndexOperatorWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), call_operator_loc: T.unsafe(nil), opening_loc: T.unsafe(nil), arguments: T.unsafe(nil), closing_loc: T.unsafe(nil), block: T.unsafe(nil), binary_operator: T.unsafe(nil), binary_operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -7271,10 +6963,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: ::T.nilable(Node), call_operator_loc: ::T.nilable(Location), opening_loc: Location, arguments: ::T.nilable(ArgumentsNode), closing_loc: Location, block: ::T.nilable(BlockArgumentNode), operator_loc: Location, value: Node).returns(IndexOrWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), call_operator_loc: T.unsafe(nil), opening_loc: T.unsafe(nil), arguments: T.unsafe(nil), closing_loc: T.unsafe(nil), block: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -7418,10 +7106,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, receiver: Node, opening_loc: Location, arguments: ::T.nilable(ArgumentsNode), closing_loc: Location, block: ::T.nilable(BlockArgumentNode)).returns(IndexTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), receiver: T.unsafe(nil), opening_loc: T.unsafe(nil), arguments: T.unsafe(nil), closing_loc: T.unsafe(nil), block: T.unsafe(nil)); end @@ -7527,10 +7211,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(InstanceVariableAndWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -7612,10 +7292,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, binary_operator_loc: Location, value: Node, binary_operator: Symbol).returns(InstanceVariableOperatorWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), binary_operator_loc: T.unsafe(nil), value: T.unsafe(nil), binary_operator: T.unsafe(nil)); end @@ -7697,10 +7373,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(InstanceVariableOrWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -7782,10 +7454,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(InstanceVariableReadNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -7845,10 +7513,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(InstanceVariableTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -7904,10 +7568,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, value: Node, operator_loc: Location).returns(InstanceVariableWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), value: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -8005,10 +7665,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, value: Integer).returns(IntegerNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), value: T.unsafe(nil)); end @@ -8080,10 +7736,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: Location, parts: T::Array[::T.any(StringNode, EmbeddedStatementsNode, EmbeddedVariableNode)], closing_loc: Location).returns(InterpolatedMatchLastLineNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), parts: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -8209,10 +7861,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: Location, parts: T::Array[::T.any(StringNode, EmbeddedStatementsNode, EmbeddedVariableNode)], closing_loc: Location).returns(InterpolatedRegularExpressionNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), parts: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -8338,10 +7986,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: ::T.nilable(Location), parts: T::Array[::T.any(StringNode, EmbeddedStatementsNode, EmbeddedVariableNode, InterpolatedStringNode)], closing_loc: ::T.nilable(Location)).returns(InterpolatedStringNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), parts: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -8431,10 +8075,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: ::T.nilable(Location), parts: T::Array[::T.any(StringNode, EmbeddedStatementsNode, EmbeddedVariableNode)], closing_loc: ::T.nilable(Location)).returns(InterpolatedSymbolNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), parts: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -8516,10 +8156,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: Location, parts: T::Array[::T.any(StringNode, EmbeddedStatementsNode, EmbeddedVariableNode)], closing_loc: Location).returns(InterpolatedXStringNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), parts: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -8601,10 +8237,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(ItLocalVariableReadNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -8656,10 +8288,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(ItParametersNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -8711,10 +8339,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, elements: T::Array[::T.any(AssocNode, AssocSplatNode)]).returns(KeywordHashNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), elements: T.unsafe(nil)); end @@ -8775,10 +8399,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: ::T.nilable(Symbol), name_loc: ::T.nilable(Location), operator_loc: Location).returns(KeywordRestParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -8860,10 +8480,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, locals: T::Array[Symbol], operator_loc: Location, opening_loc: Location, closing_loc: Location, parameters: ::T.nilable(::T.any(BlockParametersNode, NumberedParametersNode, ItParametersNode)), body: ::T.nilable(::T.any(StatementsNode, BeginNode))).returns(LambdaNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), locals: T.unsafe(nil), operator_loc: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil), parameters: T.unsafe(nil), body: T.unsafe(nil)); end @@ -8966,10 +8582,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name_loc: Location, operator_loc: Location, value: Node, name: Symbol, depth: Integer).returns(LocalVariableAndWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil), name: T.unsafe(nil), depth: T.unsafe(nil)); end @@ -9055,10 +8667,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name_loc: Location, binary_operator_loc: Location, value: Node, name: Symbol, binary_operator: Symbol, depth: Integer).returns(LocalVariableOperatorWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name_loc: T.unsafe(nil), binary_operator_loc: T.unsafe(nil), value: T.unsafe(nil), name: T.unsafe(nil), binary_operator: T.unsafe(nil), depth: T.unsafe(nil)); end @@ -9144,10 +8752,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name_loc: Location, operator_loc: Location, value: Node, name: Symbol, depth: Integer).returns(LocalVariableOrWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil), name: T.unsafe(nil), depth: T.unsafe(nil)); end @@ -9233,10 +8837,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, depth: Integer).returns(LocalVariableReadNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), depth: T.unsafe(nil)); end @@ -9313,10 +8913,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, depth: Integer).returns(LocalVariableTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), depth: T.unsafe(nil)); end @@ -9376,10 +8972,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, depth: Integer, name_loc: Location, value: Node, operator_loc: Location).returns(LocalVariableWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), depth: T.unsafe(nil), name_loc: T.unsafe(nil), value: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -9491,10 +9083,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String).returns(MatchLastLineNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), content_loc: T.unsafe(nil), closing_loc: T.unsafe(nil), unescaped: T.unsafe(nil)); end @@ -9633,10 +9221,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, value: Node, pattern: Node, keyword_loc: Location).returns(MatchPredicateNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), value: T.unsafe(nil), pattern: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -9709,10 +9293,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, value: Node, pattern: Node, operator_loc: Location).returns(MatchRequiredNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), value: T.unsafe(nil), pattern: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -9833,10 +9413,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, call: CallNode, targets: T::Array[LocalVariableTargetNode]).returns(MatchWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), call: T.unsafe(nil), targets: T.unsafe(nil)); end @@ -9896,10 +9472,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, locals: T::Array[Symbol], module_keyword_loc: Location, constant_path: ::T.any(ConstantReadNode, ConstantPathNode), body: ::T.nilable(::T.any(StatementsNode, BeginNode)), end_keyword_loc: Location, name: Symbol).returns(ModuleNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), locals: T.unsafe(nil), module_keyword_loc: T.unsafe(nil), constant_path: T.unsafe(nil), body: T.unsafe(nil), end_keyword_loc: T.unsafe(nil), name: T.unsafe(nil)); end @@ -9998,10 +9570,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, lefts: T::Array[::T.any(LocalVariableTargetNode, InstanceVariableTargetNode, ClassVariableTargetNode, GlobalVariableTargetNode, ConstantTargetNode, ConstantPathTargetNode, CallTargetNode, IndexTargetNode, MultiTargetNode, RequiredParameterNode)], rest: ::T.nilable(::T.any(ImplicitRestNode, SplatNode)), rights: T::Array[::T.any(LocalVariableTargetNode, InstanceVariableTargetNode, ClassVariableTargetNode, GlobalVariableTargetNode, ConstantTargetNode, ConstantPathTargetNode, CallTargetNode, IndexTargetNode, MultiTargetNode, RequiredParameterNode)], lparen_loc: ::T.nilable(Location), rparen_loc: ::T.nilable(Location)).returns(MultiTargetNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), lefts: T.unsafe(nil), rest: T.unsafe(nil), rights: T.unsafe(nil), lparen_loc: T.unsafe(nil), rparen_loc: T.unsafe(nil)); end @@ -10121,10 +9689,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, lefts: T::Array[::T.any(LocalVariableTargetNode, InstanceVariableTargetNode, ClassVariableTargetNode, GlobalVariableTargetNode, ConstantTargetNode, ConstantPathTargetNode, CallTargetNode, IndexTargetNode, MultiTargetNode)], rest: ::T.nilable(::T.any(ImplicitRestNode, SplatNode)), rights: T::Array[::T.any(LocalVariableTargetNode, InstanceVariableTargetNode, ClassVariableTargetNode, GlobalVariableTargetNode, ConstantTargetNode, ConstantPathTargetNode, CallTargetNode, IndexTargetNode, MultiTargetNode)], lparen_loc: ::T.nilable(Location), rparen_loc: ::T.nilable(Location), operator_loc: Location, value: Node).returns(MultiWriteNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), lefts: T.unsafe(nil), rest: T.unsafe(nil), rights: T.unsafe(nil), lparen_loc: T.unsafe(nil), rparen_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -10267,10 +9831,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, arguments: ::T.nilable(ArgumentsNode), keyword_loc: Location).returns(NextNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), arguments: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -10339,10 +9899,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(NilNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -10395,10 +9951,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, operator_loc: Location, keyword_loc: Location).returns(NoBlockParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), operator_loc: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -10477,10 +10029,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, operator_loc: Location, keyword_loc: Location).returns(NoKeywordsParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), operator_loc: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -10558,10 +10106,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, maximum: Integer).returns(NumberedParametersNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), maximum: T.unsafe(nil)); end @@ -10617,10 +10161,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, number: Integer).returns(NumberedReferenceReadNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), number: T.unsafe(nil)); end @@ -10683,10 +10223,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, value: Node).returns(OptionalKeywordParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -10760,10 +10296,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location, operator_loc: Location, value: Node).returns(OptionalParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), value: T.unsafe(nil)); end @@ -10849,10 +10381,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, left: Node, right: Node, operator_loc: Location).returns(OrNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), left: T.unsafe(nil), right: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -10941,10 +10469,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, requireds: T::Array[::T.any(RequiredParameterNode, MultiTargetNode)], optionals: T::Array[OptionalParameterNode], rest: ::T.nilable(::T.any(RestParameterNode, ImplicitRestNode)), posts: T::Array[::T.any(RequiredParameterNode, MultiTargetNode)], keywords: T::Array[::T.any(RequiredKeywordParameterNode, OptionalKeywordParameterNode)], keyword_rest: ::T.nilable(::T.any(KeywordRestParameterNode, ForwardingParameterNode, NoKeywordsParameterNode)), block: ::T.nilable(::T.any(BlockParameterNode, NoBlockParameterNode))).returns(ParametersNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), requireds: T.unsafe(nil), optionals: T.unsafe(nil), rest: T.unsafe(nil), posts: T.unsafe(nil), keywords: T.unsafe(nil), keyword_rest: T.unsafe(nil), block: T.unsafe(nil)); end @@ -11024,10 +10548,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, body: ::T.nilable(Node), opening_loc: Location, closing_loc: Location).returns(ParenthesesNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), body: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -11113,10 +10633,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, expression: Node, operator_loc: Location, lparen_loc: Location, rparen_loc: Location).returns(PinnedExpressionNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), expression: T.unsafe(nil), operator_loc: T.unsafe(nil), lparen_loc: T.unsafe(nil), rparen_loc: T.unsafe(nil)); end @@ -11223,10 +10739,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, variable: ::T.any(LocalVariableReadNode, InstanceVariableReadNode, ClassVariableReadNode, GlobalVariableReadNode, BackReferenceReadNode, NumberedReferenceReadNode, ItLocalVariableReadNode), operator_loc: Location).returns(PinnedVariableNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), variable: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -11301,10 +10813,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, statements: ::T.nilable(StatementsNode), keyword_loc: Location, opening_loc: Location, closing_loc: Location).returns(PostExecutionNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), statements: T.unsafe(nil), keyword_loc: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -11399,10 +10907,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, statements: ::T.nilable(StatementsNode), keyword_loc: Location, opening_loc: Location, closing_loc: Location).returns(PreExecutionNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), statements: T.unsafe(nil), keyword_loc: T.unsafe(nil), opening_loc: T.unsafe(nil), closing_loc: T.unsafe(nil)); end @@ -11494,10 +10998,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, locals: T::Array[Symbol], statements: StatementsNode).returns(ProgramNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), locals: T.unsafe(nil), statements: T.unsafe(nil)); end @@ -11560,10 +11060,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, left: ::T.nilable(Node), right: ::T.nilable(Node), operator_loc: Location).returns(RangeNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), left: T.unsafe(nil), right: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -11653,10 +11149,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, numerator: Integer, denominator: Integer).returns(RationalNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), numerator: T.unsafe(nil), denominator: T.unsafe(nil)); end @@ -11736,10 +11228,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(RedoNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -11791,10 +11279,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String).returns(RegularExpressionNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), content_loc: T.unsafe(nil), closing_loc: T.unsafe(nil), unescaped: T.unsafe(nil)); end @@ -11934,10 +11418,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol, name_loc: Location).returns(RequiredKeywordParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil)); end @@ -12007,10 +11487,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: Symbol).returns(RequiredParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil)); end @@ -12070,10 +11546,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, expression: Node, keyword_loc: Location, rescue_expression: Node).returns(RescueModifierNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), expression: T.unsafe(nil), keyword_loc: T.unsafe(nil), rescue_expression: T.unsafe(nil)); end @@ -12151,10 +11623,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, keyword_loc: Location, exceptions: T::Array[Node], operator_loc: ::T.nilable(Location), reference: ::T.nilable(::T.any(LocalVariableTargetNode, InstanceVariableTargetNode, ClassVariableTargetNode, GlobalVariableTargetNode, ConstantTargetNode, ConstantPathTargetNode, CallTargetNode, IndexTargetNode)), then_keyword_loc: ::T.nilable(Location), statements: ::T.nilable(StatementsNode), subsequent: ::T.nilable(RescueNode)).returns(RescueNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), keyword_loc: T.unsafe(nil), exceptions: T.unsafe(nil), operator_loc: T.unsafe(nil), reference: T.unsafe(nil), then_keyword_loc: T.unsafe(nil), statements: T.unsafe(nil), subsequent: T.unsafe(nil)); end @@ -12262,10 +11730,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, name: ::T.nilable(Symbol), name_loc: ::T.nilable(Location), operator_loc: Location).returns(RestParameterNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), name: T.unsafe(nil), name_loc: T.unsafe(nil), operator_loc: T.unsafe(nil)); end @@ -12347,10 +11811,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(RetryNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -12402,10 +11862,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, keyword_loc: Location, arguments: ::T.nilable(ArgumentsNode)).returns(ReturnNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), keyword_loc: T.unsafe(nil), arguments: T.unsafe(nil)); end @@ -12474,10 +11930,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(SelfNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -12530,10 +11982,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, write: ::T.any(ConstantWriteNode, ConstantAndWriteNode, ConstantOrWriteNode, ConstantOperatorWriteNode, ConstantPathWriteNode, ConstantPathAndWriteNode, ConstantPathOrWriteNode, ConstantPathOperatorWriteNode)).returns(ShareableConstantNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), write: T.unsafe(nil)); end @@ -12601,10 +12049,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, locals: T::Array[Symbol], class_keyword_loc: Location, operator_loc: Location, expression: Node, body: ::T.nilable(::T.any(StatementsNode, BeginNode)), end_keyword_loc: Location).returns(SingletonClassNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), locals: T.unsafe(nil), class_keyword_loc: T.unsafe(nil), operator_loc: T.unsafe(nil), expression: T.unsafe(nil), body: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -12707,10 +12151,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(SourceEncodingNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -12762,10 +12202,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, filepath: String).returns(SourceFileNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), filepath: T.unsafe(nil)); end @@ -12837,10 +12273,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(SourceLineNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -12892,10 +12324,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, operator_loc: Location, expression: ::T.nilable(Node)).returns(SplatNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), operator_loc: T.unsafe(nil), expression: T.unsafe(nil)); end @@ -12964,10 +12392,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, body: T::Array[Node]).returns(StatementsNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), body: T.unsafe(nil)); end @@ -13029,10 +12453,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: ::T.nilable(Location), content_loc: Location, closing_loc: ::T.nilable(Location), unescaped: String).returns(StringNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), content_loc: T.unsafe(nil), closing_loc: T.unsafe(nil), unescaped: T.unsafe(nil)); end @@ -13148,10 +12568,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, keyword_loc: Location, lparen_loc: ::T.nilable(Location), arguments: ::T.nilable(ArgumentsNode), rparen_loc: ::T.nilable(Location), block: ::T.nilable(::T.any(BlockNode, BlockArgumentNode))).returns(SuperNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), keyword_loc: T.unsafe(nil), lparen_loc: T.unsafe(nil), arguments: T.unsafe(nil), rparen_loc: T.unsafe(nil), block: T.unsafe(nil)); end @@ -13253,10 +12669,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: ::T.nilable(Location), content_loc: Location, closing_loc: ::T.nilable(Location), unescaped: String).returns(SymbolNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), content_loc: T.unsafe(nil), closing_loc: T.unsafe(nil), unescaped: T.unsafe(nil)); end @@ -13363,10 +12775,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer).returns(TrueNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil)); end @@ -13418,10 +12826,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, names: T::Array[::T.any(SymbolNode, InterpolatedSymbolNode)], keyword_loc: Location).returns(UndefNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), names: T.unsafe(nil), keyword_loc: T.unsafe(nil)); end @@ -13493,10 +12897,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, unless_keyword_loc: Location, predicate: Node, then_keyword_loc: ::T.nilable(Location), statements: ::T.nilable(StatementsNode), else_clause: ::T.nilable(ElseNode), end_keyword_loc: ::T.nilable(Location)).returns(UnlessNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), unless_keyword_loc: T.unsafe(nil), predicate: T.unsafe(nil), then_keyword_loc: T.unsafe(nil), statements: T.unsafe(nil), else_clause: T.unsafe(nil), end_keyword_loc: T.unsafe(nil)); end @@ -13627,10 +13027,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, until_keyword_loc: Location, do_keyword_loc: ::T.nilable(Location), end_keyword_loc: ::T.nilable(Location), predicate: Node, statements: ::T.nilable(StatementsNode)).returns(UntilNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), until_keyword_loc: T.unsafe(nil), do_keyword_loc: T.unsafe(nil), end_keyword_loc: T.unsafe(nil), predicate: T.unsafe(nil), statements: T.unsafe(nil)); end @@ -13735,10 +13131,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, when_keyword_loc: Location, conditions: T::Array[Node], then_keyword_loc: ::T.nilable(Location), statements: ::T.nilable(StatementsNode)).returns(WhenNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), when_keyword_loc: T.unsafe(nil), conditions: T.unsafe(nil), then_keyword_loc: T.unsafe(nil), statements: T.unsafe(nil)); end @@ -13827,10 +13219,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, while_keyword_loc: Location, do_keyword_loc: ::T.nilable(Location), end_keyword_loc: ::T.nilable(Location), predicate: Node, statements: ::T.nilable(StatementsNode)).returns(WhileNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), while_keyword_loc: T.unsafe(nil), do_keyword_loc: T.unsafe(nil), end_keyword_loc: T.unsafe(nil), predicate: T.unsafe(nil), statements: T.unsafe(nil)); end @@ -13933,10 +13321,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, opening_loc: Location, content_loc: Location, closing_loc: Location, unescaped: String).returns(XStringNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), opening_loc: T.unsafe(nil), content_loc: T.unsafe(nil), closing_loc: T.unsafe(nil), unescaped: T.unsafe(nil)); end @@ -14039,10 +13423,6 @@ module Prism sig { override.returns(T::Array[Node]) } def compact_child_nodes; end - # See Node.comment_targets. - sig { override.returns(T::Array[::T.any(Node, Location)]) } - def comment_targets; end - # Creates a copy of self with the given fields, using self as the template. sig { params(node_id: Integer, location: Location, flags: Integer, keyword_loc: Location, lparen_loc: ::T.nilable(Location), arguments: ::T.nilable(ArgumentsNode), rparen_loc: ::T.nilable(Location)).returns(YieldNode) } def copy(node_id: T.unsafe(nil), location: T.unsafe(nil), flags: T.unsafe(nil), keyword_loc: T.unsafe(nil), lparen_loc: T.unsafe(nil), arguments: T.unsafe(nil), rparen_loc: T.unsafe(nil)); end diff --git a/rbi/generated/prism/parse_result.rbi b/rbi/generated/prism/parse_result.rbi index 5e244e2e2f..9e5106c9d4 100644 --- a/rbi/generated/prism/parse_result.rbi +++ b/rbi/generated/prism/parse_result.rbi @@ -18,8 +18,13 @@ module Prism # can be calculated by iterating through the source code and recording the # byte offset whenever a newline character is encountered. The first # element is always 0 to mark the first line. - sig { params(source: String, start_line: Integer, offsets: T::Array[Integer]).returns(Source) } - def self.for(source, start_line, offsets); end + # + # The comments, comment_attachments, and comment_ranges parameters are the + # lists described by the attributes of the same names. They are passed in + # empty when the source is created by the parser and filled in afterward, + # because the comments themselves refer to the source. + sig { params(source: String, start_line: Integer, offsets: T::Array[Integer], comments: T::Array[Comment], comment_attachments: T::Array[Comment], comment_ranges: T::Array[::T.nilable(Integer)]).returns(Source) } + def self.for(source, start_line, offsets, comments = T.unsafe(nil), comment_attachments = T.unsafe(nil), comment_ranges = T.unsafe(nil)); end # The source code that this source object represents. sig { returns(String) } @@ -29,6 +34,25 @@ module Prism sig { returns(Integer) } attr_reader :start_line + # The list of comments that were encountered during parsing. When the source + # is parsed with the attach_comments option, these are sorted by start + # offset. + sig { returns(T::Array[Comment]) } + attr_reader :comments + + # The comments attached to nodes, grouped by node in order of node id. This + # is empty unless the source was parsed with the attach_comments option. + sig { returns(T::Array[Comment]) } + attr_reader :comment_attachments + + # Indices into comment_attachments, indexed by node id. For each node that + # owns comments, the index at which its comments begin is stored at its node + # id and the index at which they end is stored at the following node id. The + # other entries are nil. This is empty unless the source was parsed with the + # attach_comments option. + sig { returns(T::Array[::T.nilable(Integer)]) } + attr_reader :comment_ranges + # The list of newline byte offsets in the source code. When initialized from # the C extension, this may be a packed binary string of uint32_t values # that is lazily unpacked on first access. @@ -38,8 +62,8 @@ module Prism # Create a new source object with the given source code. The offsets # parameter can be either an Array of Integer byte offsets or a packed # binary string of uint32_t values (from the C extension). - sig { params(source: String, start_line: Integer, offsets: ::T.any(T::Array[Integer], String)).void } - def initialize(source, start_line, offsets); end + sig { params(source: String, start_line: Integer, offsets: ::T.any(T::Array[Integer], String), comments: T::Array[Comment], comment_attachments: T::Array[Comment], comment_ranges: T::Array[::T.nilable(Integer)]).void } + def initialize(source, start_line, offsets, comments = T.unsafe(nil), comment_attachments = T.unsafe(nil), comment_ranges = T.unsafe(nil)); end # Replace the value of start_line with the given value. sig { params(start_line: Integer).void } @@ -49,6 +73,12 @@ module Prism sig { params(offsets: T::Array[Integer]).void } def replace_offsets(offsets); end + # The comments attached to the node with the given id, ordered by start + # offset. Comments are only attached when the source is parsed with the + # attach_comments option. + sig { params(node_id: Integer).returns(T::Array[Comment]) } + def comments_for(node_id); end + # Returns the encoding of the source code, which is set by parameters to the # parser or by the encoding magic comment. sig { returns(Encoding) } @@ -237,29 +267,6 @@ module Prism sig { params(source: Source, start_offset: Integer, length: Integer).void } def initialize(source, start_offset, length); end - # These are the comments that are associated with this location that exist - # before the start of this location. - sig { returns(T::Array[Comment]) } - def leading_comments; end - - # Attach a comment to the leading comments of this location. - sig { params(comment: Comment).void } - def leading_comment(comment); end - - # These are the comments that are associated with this location that exist - # after the end of this location. - sig { returns(T::Array[Comment]) } - def trailing_comments; end - - # Attach a comment to the trailing comments of this location. - sig { params(comment: Comment).void } - def trailing_comment(comment); end - - # Returns all comments that are associated with this location (both leading - # and trailing comments). - sig { returns(T::Array[Comment]) } - def comments; end - # Create a new location object with the given options. sig { params(source: Source, start_offset: Integer, length: Integer).returns(Location) } def copy(source: T.unsafe(nil), start_offset: T.unsafe(nil), length: T.unsafe(nil)); end @@ -545,10 +552,6 @@ module Prism # It contains the requested structure, any comments that were encounters, # and any errors that were encountered. class Result - # The list of comments that were encountered during parsing. - sig { returns(T::Array[Comment]) } - attr_reader :comments - # The list of magic comments that were encountered during parsing. sig { returns(T::Array[MagicComment]) } attr_reader :magic_comments @@ -572,8 +575,12 @@ module Prism attr_reader :source # Create a new result object with the given values. - sig { params(comments: T::Array[Comment], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } - def initialize(comments, magic_comments, data_loc, errors, warnings, continuable, source); end + sig { params(magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } + def initialize(magic_comments, data_loc, errors, warnings, continuable, source); end + + # The list of comments that were encountered during parsing. + sig { returns(T::Array[Comment]) } + def comments; end # Implement the hash pattern matching interface for Result. sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) } @@ -627,17 +634,13 @@ module Prism attr_reader :value # Create a new parse result object with the given values. - sig { params(value: ProgramNode, comments: T::Array[Comment], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } - def initialize(value, comments, magic_comments, data_loc, errors, warnings, continuable, source); end + sig { params(value: ProgramNode, magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } + def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source); end # Implement the hash pattern matching interface for ParseResult. sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) } def deconstruct_keys(keys); end - # Attach the list of comments to their respective locations in the tree. - sig { void } - def attach_comments!; end - # Walk the tree and mark nodes that are on a new line, loosely emulating # the behavior of CRuby's `:line` tracepoint event. sig { void } @@ -656,8 +659,8 @@ module Prism attr_reader :value # Create a new lex result object with the given values. - sig { params(value: T::Array[Token], comments: T::Array[Comment], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } - def initialize(value, comments, magic_comments, data_loc, errors, warnings, continuable, source); end + sig { params(value: T::Array[Token], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } + def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source); end # Implement the hash pattern matching interface for LexResult. sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) } @@ -672,8 +675,8 @@ module Prism attr_reader :value # Create a new parse lex result object with the given values. - sig { params(value: [ProgramNode, T::Array[Token]], comments: T::Array[Comment], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } - def initialize(value, comments, magic_comments, data_loc, errors, warnings, continuable, source); end + sig { params(value: [ProgramNode, T::Array[Token]], magic_comments: T::Array[MagicComment], data_loc: ::T.nilable(Location), errors: T::Array[ParseError], warnings: T::Array[ParseWarning], continuable: T::Boolean, source: Source).void } + def initialize(value, magic_comments, data_loc, errors, warnings, continuable, source); end # Implement the hash pattern matching interface for ParseLexResult. sig { params(keys: ::T.nilable(T::Array[Symbol])).returns(T::Hash[Symbol, ::T.untyped]) } diff --git a/rbi/generated/prism/parse_result/comments.rbi b/rbi/generated/prism/parse_result/comments.rbi deleted file mode 100644 index f386d03f34..0000000000 --- a/rbi/generated/prism/parse_result/comments.rbi +++ /dev/null @@ -1,90 +0,0 @@ -# typed: true - -module Prism - class ParseResult < Result - # When we've parsed the source, we have both the syntax tree and the list of - # comments that we found in the source. This class is responsible for - # walking the tree and finding the nearest location to attach each comment. - # - # It does this by first finding the nearest locations to each comment. - # Locations can either come from nodes directly or from location fields on - # nodes. For example, a `ClassNode` has an overall location encompassing the - # entire class, but it also has a location for the `class` keyword. - # - # Once the nearest locations are found, it determines which one to attach - # to. If it's a trailing comment (a comment on the same line as other source - # code), it will favor attaching to the nearest location that occurs before - # the comment. Otherwise it will favor attaching to the nearest location - # that is after the comment. - class Comments - # A target for attaching comments that is based on a specific node's - # location. - class NodeTarget - sig { returns(Node) } - attr_reader :node - - sig { params(node: Node).void } - def initialize(node); end - - sig { returns(Integer) } - def start_offset; end - - sig { returns(Integer) } - def end_offset; end - - sig { params(comment: Comment).returns(T::Boolean) } - def encloses?(comment); end - - sig { params(comment: Comment).void } - def leading_comment(comment); end - - sig { params(comment: Comment).void } - def trailing_comment(comment); end - end - - # A target for attaching comments that is based on a location field on a - # node. For example, the `end` token of a ClassNode. - class LocationTarget - sig { returns(Location) } - attr_reader :location - - sig { params(location: Location).void } - def initialize(location); end - - sig { returns(Integer) } - def start_offset; end - - sig { returns(Integer) } - def end_offset; end - - sig { params(comment: Comment).returns(T::Boolean) } - def encloses?(comment); end - - sig { params(comment: Comment).void } - def leading_comment(comment); end - - sig { params(comment: Comment).void } - def trailing_comment(comment); end - end - - # The parse result that we are attaching comments to. - sig { returns(ParseResult) } - attr_reader :parse_result - - # Create a new Comments object that will attach comments to the given - # parse result. - sig { params(parse_result: ParseResult).void } - def initialize(parse_result); end - - # Attach the comments to their respective locations in the tree by - # mutating the parse result. - sig { void } - def attach!; end - - # Responsible for finding the nearest targets to the given comment within - # the context of the given encapsulating node. - sig { params(node: Node, comment: Comment).returns([::T.untyped, ::T.untyped, ::T.untyped]) } - private def nearest_targets(node, comment); end - end - end -end diff --git a/rbi/generated/prism/relocation.rbi b/rbi/generated/prism/relocation.rbi index e04e51fff1..54c003a35c 100644 --- a/rbi/generated/prism/relocation.rbi +++ b/rbi/generated/prism/relocation.rbi @@ -87,18 +87,6 @@ module Prism sig { returns(Integer) } def end_code_units_column; end - # Fetch the leading comments of the value. - sig { returns(T::Array[CommentsField::Comment]) } - def leading_comments; end - - # Fetch the trailing comments of the value. - sig { returns(T::Array[CommentsField::Comment]) } - def trailing_comments; end - - # Fetch the leading and trailing comments of the value. - sig { returns(T::Array[CommentsField::Comment]) } - def comments; end - # Reify the values on this entry with the given values. This is an # internal-only API that is called from the repository when it is time to # reify the values. @@ -248,38 +236,6 @@ module Prism private def cache; end end - # An abstract field used as the parent class of the two comments fields. - class CommentsField - # An object that represents a slice of a comment. - class Comment - # The slice of the comment. - sig { returns(String) } - attr_reader :slice - - # Initialize a new comment with the given slice. - sig { params(slice: String).void } - def initialize(slice); end - end - - # Create comment objects from the given values. - sig { params(values: ::T.untyped).returns(T::Array[Comment]) } - private def comments(values); end - end - - # A field representing the leading comments. - class LeadingCommentsField < CommentsField - # Fetches the leading comments of a value. - sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) } - def fields(value); end - end - - # A field representing the trailing comments. - class TrailingCommentsField < CommentsField - # Fetches the trailing comments of a value. - sig { params(value: ::T.untyped).returns(T::Hash[Symbol, ::T.untyped]) } - def fields(value); end - end - # A repository is a configured collection of fields and a set of entries # that knows how to reparse a source and reify the values. class Repository @@ -344,21 +300,6 @@ module Prism sig { params(encoding: Encoding).returns(::T.self_type) } def code_unit_columns(encoding); end - # Configure the leading comments field for this repository and return - # self. - sig { returns(::T.self_type) } - def leading_comments; end - - # Configure the trailing comments field for this repository and return - # self. - sig { returns(::T.self_type) } - def trailing_comments; end - - # Configure both the leading and trailing comment fields for this - # repository and return self. - sig { returns(::T.self_type) } - def comments; end - # This method is called from nodes and locations when they want to enter # themselves into the repository. It it internal-only and meant to be # called from the #save* APIs. diff --git a/rbi/generated/prism/serialize.rbi b/rbi/generated/prism/serialize.rbi index ec84dfdfb8..8e693c3f2a 100644 --- a/rbi/generated/prism/serialize.rbi +++ b/rbi/generated/prism/serialize.rbi @@ -86,8 +86,17 @@ module Prism sig { params(freeze: T::Boolean).returns(T::Array[Integer]) } def load_line_offsets(freeze); end - sig { params(freeze: T::Boolean).returns(T::Array[Comment]) } - def load_comments(freeze); end + # Load the comments attached to each node into the comment attachments and + # comment ranges of the given source. For each node that owns comments, the + # index at which its comments begin is stored at its node id and the index + # at which they end at the following node id. + sig { params(source: Source, freeze: T::Boolean).void } + def load_comment_attachments(source, freeze); end + + # Load the comments into the given list, which belongs to the source that + # the comments refer to. + sig { params(comments: T::Array[Comment], freeze: T::Boolean).returns(T::Array[Comment]) } + def load_comments(comments, freeze); end sig { params(freeze: T::Boolean).returns(T::Array[MagicComment]) } def load_magic_comments(freeze); end diff --git a/sample/prism/find_comments.rb b/sample/prism/find_comments.rb index 314bbb9b8e..ce99e4c544 100644 --- a/sample/prism/find_comments.rb +++ b/sample/prism/find_comments.rb @@ -3,10 +3,11 @@ require "prism" class FindMethodComments < Prism::Visitor - def initialize(target, comments, nesting = []) + def initialize(target, comments, nesting = [], candidates = []) @target = target @comments = comments @nesting = nesting + @candidates = candidates end # These visit methods are specific to each class. Defining a visitor allows @@ -29,15 +30,29 @@ def visit_class_node(node) node.each_child_node { |child| child.accept(visitor) } end + def visit_statements_node(node) + visitor = FindMethodComments.new(@target, @comments, @nesting, node.comments) + node.each_child_node { |child| child.accept(visitor) } + end + def visit_def_node(node) if [*@nesting, node.name] == @target - # Comments are always attached to locations (either inner locations on a - # node like the location of a keyword or the location on the node itself). - # Nodes are considered either "leading" or "trailing", which means that - # they occur before or after the location, respectively. In this case of - # documentation, we only want to consider leading comments. You can also - # fetch all of the comments on a location with #comments. - @comments.concat(node.location.leading_comments) + # Each comment is attached to a single node. A comment on its own line + # within a body is attached to the statements of that body, so + # documentation above a method is attached to the statements around the + # method rather than to the method itself. We kept the comments attached + # to those statements as we descended, which are ordered by where they + # start, so here we walk back from the method and take the ones on the + # lines directly above it. + expected_line = node.location.start_line - 1 + + @candidates.reverse_each do |comment| + next if comment.location.start_offset > node.location.start_offset + break if comment.location.start_line != expected_line + + @comments.unshift(comment) + expected_line -= 1 + end else super end @@ -55,8 +70,8 @@ def find_comments(result, path) comments end -result = Prism.parse_stream(DATA) -result.attach_comments! +# Comments are only attached to nodes when the attach_comments option is set. +result = Prism.parse_stream(DATA, attach_comments: true) find_comments(result, "Foo#foo").each do |comment| puts comment.inspect diff --git a/sample/prism/multiplex_constants.rb b/sample/prism/multiplex_constants.rb index e39f2c36f6..60beea87c7 100644 --- a/sample/prism/multiplex_constants.rb +++ b/sample/prism/multiplex_constants.rb @@ -117,7 +117,7 @@ def index_glob(glob, count = Etc.nprocessors - 1) Thread.new do while (line = index_reader.gets(chomp: true)) filepath, *entries = line.split("|") - repository = Prism::Relocation.filepath(filepath).filepath.lines.code_unit_columns(Encoding::UTF_16LE).leading_comments + repository = Prism::Relocation.filepath(filepath).filepath.lines.code_unit_columns(Encoding::UTF_16LE) entries.each_slice(3) do |(name, node_id, field_name)| index[name] << repository.enter(Integer(node_id), field_name.to_sym) diff --git a/sig/generated/prism.rbs b/sig/generated/prism.rbs index 5965084b2d..3ec0dd5108 100644 --- a/sig/generated/prism.rbs +++ b/sig/generated/prism.rbs @@ -48,37 +48,37 @@ module Prism def gets: (?Integer integer) -> (String | nil) end - def self.parse: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult + def self.parse: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult - def self.profile: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void + def self.profile: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void - def self.lex: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult + def self.lex: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult - def self.parse_lex: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult + def self.parse_lex: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult - def self.dump: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String + def self.dump: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String - def self.parse_comments: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment] + def self.parse_comments: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment] - def self.parse_success?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool + def self.parse_success?: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool - def self.parse_failure?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool + def self.parse_failure?: (String source, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool - def self.parse_stream: (_Stream stream, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult + def self.parse_stream: (_Stream stream, ?filepath: String, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult - def self.parse_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult + def self.parse_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult - def self.profile_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void + def self.profile_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> void - def self.lex_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult + def self.lex_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult - def self.parse_lex_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult + def self.parse_lex_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult - def self.dump_file: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String + def self.dump_file: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> String - def self.parse_file_comments: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment] + def self.parse_file_comments: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment] - def self.parse_file_success?: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool + def self.parse_file_success?: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool - def self.parse_file_failure?: (path filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool + def self.parse_file_failure?: (path filepath, ?attach_comments: bool, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?raise_error: Symbol | true, ?scopes: Array[Array[Symbol]], ?version: String) -> bool end diff --git a/sig/generated/prism/lex_compat.rbs b/sig/generated/prism/lex_compat.rbs index 6e8f0ac093..d7f8c1ae61 100644 --- a/sig/generated/prism/lex_compat.rbs +++ b/sig/generated/prism/lex_compat.rbs @@ -44,8 +44,8 @@ module Prism # Create a new lex compat result object with the given values. # - # : (Array[lex_compat_token] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize: (Array[lex_compat_token] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + # : (Array[lex_compat_token] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize: (Array[lex_compat_token] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void # Implement the hash pattern matching interface for Result. # diff --git a/sig/generated/prism/node.rbs b/sig/generated/prism/node.rbs index 9b5ae2cf9b..e23073cc65 100644 --- a/sig/generated/prism/node.rbs +++ b/sig/generated/prism/node.rbs @@ -122,17 +122,8 @@ module Prism # : (_CodeUnitsCache cache) -> Integer def cached_end_code_units_column: (_CodeUnitsCache cache) -> Integer - # Delegates to [`leading_comments`](rdoc-ref:Location#leading_comments) of the associated location object. - # - # : () -> Array[Comment] - def leading_comments: () -> Array[Comment] - - # Delegates to [`trailing_comments`](rdoc-ref:Location#trailing_comments) of the associated location object. - # - # : () -> Array[Comment] - def trailing_comments: () -> Array[Comment] - - # Delegates to [`comments`](rdoc-ref:Location#comments) of the associated location object. + # The comments attached to this node, ordered by start offset. Comments are + # only attached when the source is parsed with the attach_comments option. # # : () -> Array[Comment] def comments: () -> Array[Comment] @@ -251,12 +242,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # Returns an array of child nodes and locations that could potentially have - # comments attached to them. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # Returns a string representation of the node. # # : () -> String @@ -325,11 +310,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> AliasGlobalVariableNode # @@ -447,11 +427,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> AliasMethodNode # @@ -581,11 +556,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> AlternationPatternNode # @@ -703,11 +673,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> AndNode # @@ -827,11 +792,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ArgumentsNode # @@ -941,11 +901,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ArrayNode # @@ -1104,11 +1059,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ArrayPatternNode # @@ -1281,11 +1231,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> AssocNode # @@ -1410,11 +1355,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> AssocSplatNode # @@ -1517,11 +1457,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> BackReferenceReadNode # @@ -1610,11 +1545,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> BeginNode # @@ -1779,11 +1709,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> BlockArgumentNode # @@ -1886,11 +1811,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> BlockLocalVariableNode # @@ -1980,11 +1900,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> BlockNode # @@ -2145,11 +2060,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> BlockParameterNode # @@ -2289,11 +2199,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> BlockParametersNode # @@ -2452,11 +2357,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> BreakNode # @@ -2571,11 +2471,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> CallAndWriteNode # @@ -2820,11 +2715,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> CallNode # @@ -3118,11 +3008,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> CallOperatorWriteNode # @@ -3351,11 +3236,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> CallOrWriteNode # @@ -3583,11 +3463,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> CallTargetNode # @@ -3756,11 +3631,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> CapturePatternNode # @@ -3884,11 +3754,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> CaseMatchNode # @@ -4050,11 +3915,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> CaseNode # @@ -4220,11 +4080,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ClassNode # @@ -4424,11 +4279,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ClassVariableAndWriteNode # @@ -4569,11 +4419,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ClassVariableOperatorWriteNode # @@ -4700,11 +4545,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ClassVariableOrWriteNode # @@ -4825,11 +4665,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ClassVariableReadNode # @@ -4906,11 +4741,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ClassVariableTargetNode # @@ -4989,11 +4819,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ClassVariableWriteNode # @@ -5136,11 +4961,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantAndWriteNode # @@ -5269,11 +5089,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantOperatorWriteNode # @@ -5400,11 +5215,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantOrWriteNode # @@ -5529,11 +5339,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantPathAndWriteNode # @@ -5644,11 +5449,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantPathNode # @@ -5796,11 +5596,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantPathOperatorWriteNode # @@ -5909,11 +5704,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantPathOrWriteNode # @@ -6024,11 +5814,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantPathTargetNode # @@ -6159,11 +5944,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantPathWriteNode # @@ -6280,11 +6060,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantReadNode # @@ -6361,11 +6136,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantTargetNode # @@ -6444,11 +6214,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ConstantWriteNode # @@ -6608,11 +6373,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> DefNode # @@ -6883,11 +6643,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> DefinedNode # @@ -7036,11 +6791,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ElseNode # @@ -7165,11 +6915,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> EmbeddedStatementsNode # @@ -7292,11 +7037,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> EmbeddedVariableNode # @@ -7401,11 +7141,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> EnsureNode # @@ -7523,11 +7258,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ErrorRecoveryNode # @@ -7598,11 +7328,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> FalseNode # @@ -7686,11 +7411,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> FindPatternNode # @@ -7872,11 +7592,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> FlipFlopNode # @@ -7987,11 +7702,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> FloatNode # @@ -8076,11 +7786,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ForNode # @@ -8288,11 +7993,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ForwardingArgumentsNode # @@ -8356,11 +8056,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ForwardingParameterNode # @@ -8432,11 +8127,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ForwardingSuperNode # @@ -8543,11 +8233,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> GlobalVariableAndWriteNode # @@ -8676,11 +8361,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> GlobalVariableOperatorWriteNode # @@ -8807,11 +8487,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> GlobalVariableOrWriteNode # @@ -8932,11 +8607,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> GlobalVariableReadNode # @@ -9013,11 +8683,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> GlobalVariableTargetNode # @@ -9096,11 +8761,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> GlobalVariableWriteNode # @@ -9241,11 +8901,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> HashNode # @@ -9395,11 +9050,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> HashPatternNode # @@ -9582,11 +9232,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> IfNode # @@ -9793,11 +9438,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ImaginaryNode # @@ -9876,11 +9516,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ImplicitNode # @@ -9960,11 +9595,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ImplicitRestNode # @@ -10035,11 +9665,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InNode # @@ -10182,11 +9807,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> IndexAndWriteNode # @@ -10419,11 +10039,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> IndexOperatorWriteNode # @@ -10654,11 +10269,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> IndexOrWriteNode # @@ -10891,11 +10501,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> IndexTargetNode # @@ -11062,11 +10667,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InstanceVariableAndWriteNode # @@ -11195,11 +10795,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InstanceVariableOperatorWriteNode # @@ -11326,11 +10921,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InstanceVariableOrWriteNode # @@ -11451,11 +11041,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InstanceVariableReadNode # @@ -11532,11 +11117,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InstanceVariableTargetNode # @@ -11615,11 +11195,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InstanceVariableWriteNode # @@ -11756,11 +11331,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> IntegerNode # @@ -11861,11 +11431,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InterpolatedMatchLastLineNode # @@ -12056,11 +11621,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InterpolatedRegularExpressionNode # @@ -12251,11 +11811,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InterpolatedStringNode # @@ -12392,11 +11947,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InterpolatedSymbolNode # @@ -12521,11 +12071,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> InterpolatedXStringNode # @@ -12644,11 +12189,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ItLocalVariableReadNode # @@ -12711,11 +12251,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ItParametersNode # @@ -12780,11 +12315,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> KeywordHashNode # @@ -12868,11 +12398,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> KeywordRestParameterNode # @@ -13001,11 +12526,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> LambdaNode # @@ -13174,11 +12694,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> LocalVariableAndWriteNode # @@ -13317,11 +12832,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> LocalVariableOperatorWriteNode # @@ -13458,11 +12968,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> LocalVariableOrWriteNode # @@ -13562,10 +13067,10 @@ module Prism # foo # ^^^ class LocalVariableReadNode < Node - @depth: Integer - @name: Symbol + @depth: Integer + # Initialize a new LocalVariableReadNode node. # # : (Source source, Integer node_id, Location location, Integer flags, Symbol name, Integer depth) -> void @@ -13593,11 +13098,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> LocalVariableReadNode # @@ -13666,10 +13166,10 @@ module Prism # foo => baz # ^^^ class LocalVariableTargetNode < Node - @depth: Integer - @name: Symbol + @depth: Integer + # Initialize a new LocalVariableTargetNode node. # # : (Source source, Integer node_id, Location location, Integer flags, Symbol name, Integer depth) -> void @@ -13697,11 +13197,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> LocalVariableTargetNode # @@ -13790,11 +13285,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> LocalVariableWriteNode # @@ -13955,11 +13445,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> MatchLastLineNode # @@ -14174,11 +13659,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> MatchPredicateNode # @@ -14287,11 +13767,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> MatchRequiredNode # @@ -14415,10 +13890,10 @@ module Prism # /(?bar)/ =~ baz # ^^^^^^^^^^^^^^^^^^^^ class MatchWriteNode < Node - @targets: Array[LocalVariableTargetNode] - @call: CallNode + @targets: Array[LocalVariableTargetNode] + # Initialize a new MatchWriteNode node. # # : (Source source, Integer node_id, Location location, Integer flags, CallNode call, Array[LocalVariableTargetNode] targets) -> void @@ -14446,11 +13921,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> MatchWriteNode # @@ -14541,11 +14011,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ModuleNode # @@ -14703,11 +14168,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> MultiTargetNode # @@ -14886,11 +14346,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> MultiWriteNode # @@ -15097,11 +14552,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> NextNode # @@ -15196,11 +14646,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> NilNode # @@ -15268,11 +14713,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> NoBlockParameterNode # @@ -15388,11 +14828,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> NoKeywordsParameterNode # @@ -15505,11 +14940,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> NumberedParametersNode # @@ -15582,11 +15012,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> NumberedReferenceReadNode # @@ -15670,11 +15095,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> OptionalKeywordParameterNode # @@ -15784,11 +15204,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> OptionalParameterNode # @@ -15919,11 +15334,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> OrNode # @@ -16056,11 +15466,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ParametersNode # @@ -16185,11 +15590,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ParenthesesNode # @@ -16322,11 +15722,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> PinnedExpressionNode # @@ -16485,11 +15880,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> PinnedVariableNode # @@ -16598,11 +15988,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> PostExecutionNode # @@ -16753,11 +16138,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> PreExecutionNode # @@ -16870,10 +16250,10 @@ module Prism # The top level node of any parse tree. class ProgramNode < Node - @statements: StatementsNode - @locals: Array[Symbol] + @statements: StatementsNode + # Initialize a new ProgramNode node. # # : (Source source, Integer node_id, Location location, Integer flags, Array[Symbol] locals, StatementsNode statements) -> void @@ -16901,11 +16281,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ProgramNode # @@ -16993,11 +16368,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RangeNode # @@ -17123,11 +16493,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RationalNode # @@ -17234,11 +16599,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RedoNode # @@ -17309,11 +16669,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RegularExpressionNode # @@ -17527,11 +16882,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RequiredKeywordParameterNode # @@ -17627,11 +16977,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RequiredParameterNode # @@ -17714,11 +17059,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RescueModifierNode # @@ -17840,11 +17180,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RescueNode # @@ -18018,11 +17353,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RestParameterNode # @@ -18139,11 +17469,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> RetryNode # @@ -18210,11 +17535,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ReturnNode # @@ -18309,11 +17629,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> SelfNode # @@ -18379,11 +17694,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> ShareableConstantNode # @@ -18484,11 +17794,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> SingletonClassNode # @@ -18647,11 +17952,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> SourceEncodingNode # @@ -18716,11 +18016,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> SourceFileNode # @@ -18815,11 +18110,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> SourceLineNode # @@ -18886,11 +18176,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> SplatNode # @@ -18987,11 +18272,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> StatementsNode # @@ -19076,11 +18356,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> StringNode # @@ -19262,11 +18537,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> SuperNode # @@ -19428,11 +18698,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> SymbolNode # @@ -19593,11 +18858,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> TrueNode # @@ -19664,11 +18924,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> UndefNode # @@ -19778,11 +19033,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> UnlessNode # @@ -19979,11 +19229,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> UntilNode # @@ -20150,11 +19395,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> WhenNode # @@ -20294,11 +19534,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> WhileNode # @@ -20463,11 +19698,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> XStringNode # @@ -20630,11 +19860,6 @@ module Prism # : () -> Array[node] def compact_child_nodes: () -> Array[node] - # See Node.comment_targets. - # - # : () -> Array[node | Location] - def comment_targets: () -> Array[node | Location] - # :call-seq: # copy(**fields) -> YieldNode # diff --git a/sig/generated/prism/parse_result.rbs b/sig/generated/prism/parse_result.rbs index 67cf6f4112..ff1a49ba98 100644 --- a/sig/generated/prism/parse_result.rbs +++ b/sig/generated/prism/parse_result.rbs @@ -25,8 +25,13 @@ module Prism # byte offset whenever a newline character is encountered. The first # element is always 0 to mark the first line. # - # : (String source, Integer start_line, Array[Integer] offsets) -> Source - def self.for: (String source, Integer start_line, Array[Integer] offsets) -> Source + # The comments, comment_attachments, and comment_ranges parameters are the + # lists described by the attributes of the same names. They are passed in + # empty when the source is created by the parser and filled in afterward, + # because the comments themselves refer to the source. + # + # : (String source, Integer start_line, Array[Integer] offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges) -> Source + def self.for: (String source, Integer start_line, Array[Integer] offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges) -> Source # The source code that this source object represents. attr_reader source: String @@ -34,6 +39,22 @@ module Prism # The line number where this source starts. attr_reader start_line: Integer + # The list of comments that were encountered during parsing. When the source + # is parsed with the attach_comments option, these are sorted by start + # offset. + attr_reader comments: Array[Comment] + + # The comments attached to nodes, grouped by node in order of node id. This + # is empty unless the source was parsed with the attach_comments option. + attr_reader comment_attachments: Array[Comment] + + # Indices into comment_attachments, indexed by node id. For each node that + # owns comments, the index at which its comments begin is stored at its node + # id and the index at which they end is stored at the following node id. The + # other entries are nil. This is empty unless the source was parsed with the + # attach_comments option. + attr_reader comment_ranges: Array[Integer?] + # The list of newline byte offsets in the source code. When initialized from # the C extension, this may be a packed binary string of uint32_t values # that is lazily unpacked on first access. @@ -45,8 +66,8 @@ module Prism # parameter can be either an Array of Integer byte offsets or a packed # binary string of uint32_t values (from the C extension). # - # : (String source, Integer start_line, Array[Integer] | String offsets) -> void - def initialize: (String source, Integer start_line, Array[Integer] | String offsets) -> void + # : (String source, Integer start_line, Array[Integer] | String offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges) -> void + def initialize: (String source, Integer start_line, Array[Integer] | String offsets, ?Array[Comment] comments, ?Array[Comment] comment_attachments, ?Array[Integer?] comment_ranges) -> void # Replace the value of start_line with the given value. # @@ -58,6 +79,13 @@ module Prism # : (Array[Integer] offsets) -> void def replace_offsets: (Array[Integer] offsets) -> void + # The comments attached to the node with the given id, ordered by start + # offset. Comments are only attached when the source is parsed with the + # attach_comments option. + # + # : (Integer node_id) -> Array[Comment] + def comments_for: (Integer node_id) -> Array[Comment] + # Returns the encoding of the source code, which is set by parameters to the # parser or by the encoding magic comment. # @@ -276,44 +304,12 @@ module Prism # The length of this location in bytes. attr_reader length: Integer - @trailing_comments: Array[Comment]? - - @leading_comments: Array[Comment]? - # Create a new location object with the given source, start byte offset, and # byte length. # # : (Source source, Integer start_offset, Integer length) -> void def initialize: (Source source, Integer start_offset, Integer length) -> void - # These are the comments that are associated with this location that exist - # before the start of this location. - # - # : () -> Array[Comment] - def leading_comments: () -> Array[Comment] - - # Attach a comment to the leading comments of this location. - # - # : (Comment comment) -> void - def leading_comment: (Comment comment) -> void - - # These are the comments that are associated with this location that exist - # after the end of this location. - # - # : () -> Array[Comment] - def trailing_comments: () -> Array[Comment] - - # Attach a comment to the trailing comments of this location. - # - # : (Comment comment) -> void - def trailing_comment: (Comment comment) -> void - - # Returns all comments that are associated with this location (both leading - # and trailing comments). - # - # : () -> Array[Comment] - def comments: () -> Array[Comment] - # Create a new location object with the given options. # # : (?source: Source, ?start_offset: Integer, ?length: Integer) -> Location @@ -636,9 +632,6 @@ module Prism # It contains the requested structure, any comments that were encounters, # and any errors that were encountered. class Result - # The list of comments that were encountered during parsing. - attr_reader comments: Array[Comment] - # The list of magic comments that were encountered during parsing. attr_reader magic_comments: Array[MagicComment] @@ -658,8 +651,13 @@ module Prism # Create a new result object with the given values. # - # : (Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize: (Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + # : (Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize: (Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + + # The list of comments that were encountered during parsing. + # + # : () -> Array[Comment] + def comments: () -> Array[Comment] # Implement the hash pattern matching interface for Result. # @@ -719,19 +717,14 @@ module Prism # Create a new parse result object with the given values. # - # : (ProgramNode value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize: (ProgramNode value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + # : (ProgramNode value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize: (ProgramNode value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void # Implement the hash pattern matching interface for ParseResult. # # : (Array[Symbol]? keys) -> Hash[Symbol, untyped] def deconstruct_keys: (Array[Symbol]? keys) -> Hash[Symbol, untyped] - # Attach the list of comments to their respective locations in the tree. - # - # : () -> void - def attach_comments!: () -> void - # Walk the tree and mark nodes that are on a new line, loosely emulating # the behavior of CRuby's `:line` tracepoint event. # @@ -752,8 +745,8 @@ module Prism # Create a new lex result object with the given values. # - # : (Array[Token] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize: (Array[Token] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + # : (Array[Token] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize: (Array[Token] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void # Implement the hash pattern matching interface for LexResult. # @@ -769,8 +762,8 @@ module Prism # Create a new parse lex result object with the given values. # - # : ([ProgramNode, Array[Token]] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void - def initialize: ([ ProgramNode, Array[Token] ] value, Array[Comment] comments, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + # : ([ProgramNode, Array[Token]] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void + def initialize: ([ ProgramNode, Array[Token] ] value, Array[MagicComment] magic_comments, Location? data_loc, Array[ParseError] errors, Array[ParseWarning] warnings, bool continuable, Source source) -> void # Implement the hash pattern matching interface for ParseLexResult. # diff --git a/sig/generated/prism/parse_result/comments.rbs b/sig/generated/prism/parse_result/comments.rbs deleted file mode 100644 index 5f5a401644..0000000000 --- a/sig/generated/prism/parse_result/comments.rbs +++ /dev/null @@ -1,108 +0,0 @@ -# Generated from lib/prism/parse_result/comments.rb with RBS::Inline - -module Prism - class ParseResult < Result - # When we've parsed the source, we have both the syntax tree and the list of - # comments that we found in the source. This class is responsible for - # walking the tree and finding the nearest location to attach each comment. - # - # It does this by first finding the nearest locations to each comment. - # Locations can either come from nodes directly or from location fields on - # nodes. For example, a `ClassNode` has an overall location encompassing the - # entire class, but it also has a location for the `class` keyword. - # - # Once the nearest locations are found, it determines which one to attach - # to. If it's a trailing comment (a comment on the same line as other source - # code), it will favor attaching to the nearest location that occurs before - # the comment. Otherwise it will favor attaching to the nearest location - # that is after the comment. - class Comments - # An internal interface for a target that comments can be attached - # to. This is either going to be a NodeTarget or a CommentTarget. - interface _CommentTarget - def start_offset: () -> Integer - - def end_offset: () -> Integer - - def encloses?: (Comment) -> bool - - def leading_comment: (Comment) -> void - - def trailing_comment: (Comment) -> void - end - - # A target for attaching comments that is based on a specific node's - # location. - class NodeTarget - # :nodoc: - attr_reader node: node - - # : (node node) -> void - def initialize: (node node) -> void - - # : () -> Integer - def start_offset: () -> Integer - - # : () -> Integer - def end_offset: () -> Integer - - # : (Comment comment) -> bool - def encloses?: (Comment comment) -> bool - - # : (Comment comment) -> void - def leading_comment: (Comment comment) -> void - - # : (Comment comment) -> void - def trailing_comment: (Comment comment) -> void - end - - # A target for attaching comments that is based on a location field on a - # node. For example, the `end` token of a ClassNode. - class LocationTarget - # :nodoc: - attr_reader location: Location - - # : (Location location) -> void - def initialize: (Location location) -> void - - # : () -> Integer - def start_offset: () -> Integer - - # : () -> Integer - def end_offset: () -> Integer - - # : (Comment comment) -> bool - def encloses?: (Comment comment) -> bool - - # : (Comment comment) -> void - def leading_comment: (Comment comment) -> void - - # : (Comment comment) -> void - def trailing_comment: (Comment comment) -> void - end - - # The parse result that we are attaching comments to. - attr_reader parse_result: ParseResult - - # Create a new Comments object that will attach comments to the given - # parse result. - # - # : (ParseResult parse_result) -> void - def initialize: (ParseResult parse_result) -> void - - # Attach the comments to their respective locations in the tree by - # mutating the parse result. - # - # : () -> void - def attach!: () -> void - - private - - # Responsible for finding the nearest targets to the given comment within - # the context of the given encapsulating node. - # - # : (node node, Comment comment) -> [_CommentTarget?, _CommentTarget?, _CommentTarget?] - def nearest_targets: (node node, Comment comment) -> [ _CommentTarget?, _CommentTarget?, _CommentTarget? ] - end - end -end diff --git a/sig/generated/prism/relocation.rbs b/sig/generated/prism/relocation.rbs index 43d1a80540..fd81ebf3a1 100644 --- a/sig/generated/prism/relocation.rbs +++ b/sig/generated/prism/relocation.rbs @@ -43,10 +43,6 @@ module Prism def cached_start_code_units_column: (_CodeUnitsCache cache) -> Integer def cached_end_code_units_column: (_CodeUnitsCache cache) -> Integer - - def leading_comments: () -> Array[Comment] - - def trailing_comments: () -> Array[Comment] end interface _Field @@ -150,21 +146,6 @@ module Prism # : () -> Integer def end_code_units_column: () -> Integer - # Fetch the leading comments of the value. - # - # : () -> Array[CommentsField::Comment] - def leading_comments: () -> Array[CommentsField::Comment] - - # Fetch the trailing comments of the value. - # - # : () -> Array[CommentsField::Comment] - def trailing_comments: () -> Array[CommentsField::Comment] - - # Fetch the leading and trailing comments of the value. - # - # : () -> Array[CommentsField::Comment] - def comments: () -> Array[CommentsField::Comment] - # Reify the values on this entry with the given values. This is an # internal-only API that is called from the repository when it is time to # reify the values. @@ -339,43 +320,6 @@ module Prism def cache: () -> _CodeUnitsCache end - # An abstract field used as the parent class of the two comments fields. - class CommentsField - # An object that represents a slice of a comment. - class Comment - # The slice of the comment. - attr_reader slice: String - - # Initialize a new comment with the given slice. - # - # : (String slice) -> void - def initialize: (String slice) -> void - end - - private - - # Create comment objects from the given values. - # - # : (entry_value values) -> Array[Comment] - def comments: (entry_value values) -> Array[Comment] - end - - # A field representing the leading comments. - class LeadingCommentsField < CommentsField - # Fetches the leading comments of a value. - # - # : (_Value value) -> entry_values - def fields: (_Value value) -> entry_values - end - - # A field representing the trailing comments. - class TrailingCommentsField < CommentsField - # Fetches the trailing comments of a value. - # - # : (_Value value) -> entry_values - def fields: (_Value value) -> entry_values - end - # A repository is a configured collection of fields and a set of entries # that knows how to reparse a source and reify the values. class Repository @@ -448,24 +392,6 @@ module Prism # : (Encoding encoding) -> self def code_unit_columns: (Encoding encoding) -> self - # Configure the leading comments field for this repository and return - # self. - # - # : () -> self - def leading_comments: () -> self - - # Configure the trailing comments field for this repository and return - # self. - # - # : () -> self - def trailing_comments: () -> self - - # Configure both the leading and trailing comment fields for this - # repository and return self. - # - # : () -> self - def comments: () -> self - # This method is called from nodes and locations when they want to enter # themselves into the repository. It it internal-only and meant to be # called from the #save* APIs. diff --git a/sig/generated/prism/serialize.rbs b/sig/generated/prism/serialize.rbs index 2886bd0e27..e1eb2cedbb 100644 --- a/sig/generated/prism/serialize.rbs +++ b/sig/generated/prism/serialize.rbs @@ -94,8 +94,19 @@ module Prism # : (bool freeze) -> Array[Integer] def load_line_offsets: (bool freeze) -> Array[Integer] - # : (bool freeze) -> Array[Comment] - def load_comments: (bool freeze) -> Array[Comment] + # Load the comments attached to each node into the comment attachments and + # comment ranges of the given source. For each node that owns comments, the + # index at which its comments begin is stored at its node id and the index + # at which they end at the following node id. + # + # : (Source source, bool freeze) -> void + def load_comment_attachments: (Source source, bool freeze) -> void + + # Load the comments into the given list, which belongs to the source that + # the comments refer to. + # + # : (Array[Comment] comments, bool freeze) -> Array[Comment] + def load_comments: (Array[Comment] comments, bool freeze) -> Array[Comment] # : (bool freeze) -> Array[MagicComment] def load_magic_comments: (bool freeze) -> Array[MagicComment] diff --git a/src/char.c b/src/char.c index 08e457aa1f..a6986f6b88 100644 --- a/src/char.c +++ b/src/char.c @@ -78,6 +78,21 @@ pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length) { return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_WHITESPACE); } +/** + * Returns the number of characters at the end of the string that are + * whitespace. Disallows searching past the given maximum number of characters. + */ +size_t +pm_strrspn_whitespace(const uint8_t *string, ptrdiff_t length) { + if (length <= 0) return 0; + + size_t size = 0; + size_t maximum = (size_t) length; + + while (size < maximum && (pm_byte_table[string[maximum - size - 1]] & PRISM_CHAR_BIT_WHITESPACE)) size++; + return size; +} + /** * Returns the number of characters at the start of the string that are * whitespace while also tracking the location of each newline. Disallows diff --git a/src/comments.c b/src/comments.c new file mode 100644 index 0000000000..4ef1ee5fe6 --- /dev/null +++ b/src/comments.c @@ -0,0 +1,454 @@ +#include "prism/internal/comments.h" + +#include "prism/internal/arena.h" +#include "prism/internal/char.h" +#include "prism/internal/node.h" +#include "prism/internal/parser.h" + +#include +#include +#include + +/* The state used while walking the tree to find the owner of each comment. */ +typedef struct { + /* The arena for memory that is only needed during the walk. */ + pm_arena_t *arena; + + /* The start of the source that was parsed. */ + const uint8_t *source; + + /* The comments found while parsing, sorted by start offset. */ + const pm_comment_t **comments; + + /* The number of comments. */ + uint32_t size; + + /* The start offset of each comment. */ + uint32_t *starts; + + /* + * The result of the most recent search for the first comment after the end + * of a node. This is a hint to the search to avoid fully binary searching + * the comments list if possible. + */ + uint32_t cursor; + + /* The node each comment is attached to. */ + const pm_node_t **attached; + + /* + * A disjoint set over comment indices that maps each index to the next + * index at or after it that has not yet been claimed. It has one extra + * entry at the end that is never claimed, so that every lookup ends. This + * allows quickly finding the next unclaimed comment without having to check + * the state of each comment individually. + */ + uint32_t *unclaimed; + + /* + * A stack of nodes whose children are being visited. Each level of the + * walk pushes its children, visits them, then pops back to where it + * started. + */ + struct { + const pm_node_t **nodes; + size_t size; + size_t capacity; + } stack; +} pm_comments_walk_t; + +/* Compare two comments by start offset for qsort. */ +static int +pm_comments_compare(const void *left, const void *right) { + uint32_t left_start = (*(const pm_comment_t *const *) left)->location.start; + uint32_t right_start = (*(const pm_comment_t *const *) right)->location.start; + return (left_start > right_start) - (left_start < right_start); +} + +/* + * Copy the linked list of comments from the parser sorted by start offset, and + * relink the list in that order. Usually comments arrive in source order, but + * unfortunately because of heredocs they can occasionally be out of order. + */ +static const pm_comment_t ** +pm_comments_sort(pm_parser_t *parser, uint32_t size) { + pm_comment_t **comments = (pm_comment_t **) pm_arena_alloc(&parser->metadata_arena, sizeof(pm_comment_t *) * size, PRISM_ALIGNOF(pm_comment_t *)); + + uint32_t index = 0; + for (pm_list_node_t *node = parser->comment_list.head; node != NULL; node = node->next) { + comments[index++] = (pm_comment_t *) node; + } + + qsort((void *) comments, size, sizeof(pm_comment_t *), pm_comments_compare); + + for (index = 0; index + 1 < size; index++) { + comments[index]->node.next = &comments[index + 1]->node; + } + + comments[size - 1]->node.next = NULL; + parser->comment_list.head = &comments[0]->node; + parser->comment_list.tail = &comments[size - 1]->node; + + return (const pm_comment_t **) comments; +} + +/* + * Return the index of the first comment in [left, right) that starts at or + * after the given offset, or right if there is none. + */ +static uint32_t +pm_comments_lower_bound(const pm_comments_walk_t *walk, uint32_t left, uint32_t right, uint32_t offset) { + while (left < right) { + uint32_t middle = left + (right - left) / 2; + + if (walk->starts[middle] < offset) { + left = middle + 1; + } else { + right = middle; + } + } + + return left; +} + +/* + * Return the index of the first comment that starts at or after the given + * offset, or the number of comments if there is none. This gallops outward + * from the previous result to find a range to search, so that a run of nearby + * offsets costs a constant number of comparisons each. + */ +static uint32_t +pm_comments_seek(pm_comments_walk_t *walk, uint32_t offset) { + const uint32_t *starts = walk->starts; + + uint32_t size = walk->size; + uint32_t cursor = walk->cursor; + uint32_t left; + uint32_t right; + uint32_t step = 1; + + if (cursor == size || starts[cursor] >= offset) { + /* + * The answer is at or before the cursor. Widen the range backward + * until the comment before it starts before the offset. + */ + right = cursor; + left = cursor; + + while (left > 0 && starts[left - 1] >= offset) { + right = left - 1; + left = (left - 1 > step) ? left - 1 - step : 0; + step *= 2; + } + } else { + /* + * The answer is after the cursor. Widen the range forward until it + * ends at a comment that starts at or after the offset. + */ + left = cursor + 1; + right = left; + + while (right < size && starts[right] < offset) { + left = right + 1; + right = (size - left > step) ? left + step : size; + step *= 2; + } + } + + walk->cursor = pm_comments_lower_bound(walk, left, right, offset); + return walk->cursor; +} + +/* + * The first comment index at or after the given index that has not yet been + * claimed, compressing the path along the way. + */ +static uint32_t +pm_comments_unclaimed(pm_comments_walk_t *walk, uint32_t index) { + uint32_t *unclaimed = walk->unclaimed; + + while (unclaimed[index] != index) { + unclaimed[index] = unclaimed[unclaimed[index]]; + index = unclaimed[index]; + } + + return index; +} + +/* + * Return the earliest offset before the given one from which the source up to + * it holds only whitespace and comments. Any comment that starts at or after + * the returned offset is separated from the given offset by only whitespace and + * other comments. + */ +static uint32_t +pm_comments_blank_before(const pm_comments_walk_t *walk, uint32_t offset) { + uint32_t index = pm_comments_lower_bound(walk, 0, walk->size, offset); + + while (true) { + offset -= (uint32_t) pm_strrspn_whitespace(walk->source, (ptrdiff_t) offset); + if (index == 0) return offset; + + /* An embedded document's location includes its trailing newline, so + * the whitespace that was just skipped can end inside a comment. */ + const pm_location_t *location = &walk->comments[index - 1]->location; + if (location->start >= offset || PM_LOCATION_END(location) < offset) return offset; + + offset = location->start; + index--; + } +} + +/* + * Return the latest offset after the given one, and no later than the given + * end, up to which the source from the given offset holds only whitespace and + * comments. Any comment that ends at or before the returned offset is + * separated from the given offset by only whitespace and other comments. + */ +static uint32_t +pm_comments_blank_after(const pm_comments_walk_t *walk, uint32_t offset, uint32_t end) { + uint32_t index = pm_comments_lower_bound(walk, 0, walk->size, offset); + + while (true) { + offset += (uint32_t) pm_strspn_whitespace(walk->source + offset, (ptrdiff_t) end - (ptrdiff_t) offset); + if (index == walk->size || walk->starts[index] != offset) return offset; + + offset = PM_LOCATION_END(&walk->comments[index]->location); + index++; + } +} + +/* + * Push a child node onto the walk stack without descending into it. The walk + * descends itself, so that it can visit children in source order and handle + * each node after all of its descendants. + */ +static bool +pm_comments_push(const pm_node_t *node, void *data) { + pm_comments_walk_t *walk = (pm_comments_walk_t *) data; + + if (walk->stack.size == walk->stack.capacity) { + size_t capacity = walk->stack.capacity == 0 ? 64 : walk->stack.capacity * 2; + const pm_node_t **nodes = (const pm_node_t **) pm_arena_alloc(walk->arena, sizeof(pm_node_t *) * capacity, PRISM_ALIGNOF(pm_node_t *)); + if (walk->stack.size > 0) memcpy((void *) nodes, (const void *) walk->stack.nodes, sizeof(pm_node_t *) * walk->stack.size); + + walk->stack.nodes = nodes; + walk->stack.capacity = capacity; + } + + walk->stack.nodes[walk->stack.size++] = node; + return false; +} + +/* + * Visit the given node and its descendants in post-order, attaching comments as + * the nodes are visited. + */ +static void +pm_comments_visit(pm_comments_walk_t *walk, const pm_node_t *node) { + /* First, push all of the children of this node onto the stack. */ + size_t base = walk->stack.size; + pm_visit_child_nodes(node, pm_comments_push, walk); + size_t top = walk->stack.size; + + /* Next, in-place sort the children by their starting location. */ + for (size_t index = base + 1; index < top; index++) { + const pm_node_t *child = walk->stack.nodes[index]; + size_t insert = index; + + while (insert > base && walk->stack.nodes[insert - 1]->location.start > child->location.start) { + walk->stack.nodes[insert] = walk->stack.nodes[insert - 1]; + insert--; + } + + walk->stack.nodes[insert] = child; + } + + /* Next, visit all of the children so that they can claim comments. */ + for (size_t index = base; index < top; index++) { + pm_comments_visit(walk, walk->stack.nodes[index]); + } + + uint32_t start = node->location.start; + uint32_t end = PM_LOCATION_END(&node->location); + uint32_t after = pm_comments_seek(walk, end); + + /* If this node is followed by a comment on the same line, attach it if + * appropriate. Appropriate in this case means if no other node has claimed + * it or if we are closer in distance or equal in distance to the current + * claimant. */ + if ( + after < walk->size && + !PM_NODE_TYPE_P(node, PM_PROGRAM_NODE) && + !PM_NODE_TYPE_P(node, PM_STATEMENTS_NODE) && + (node->location.length == 0 || walk->source[end - 1] != '\n') + ) { + uint32_t comment_start = walk->starts[after]; + + if (memchr(walk->source + end, '\n', comment_start - end) == NULL) { + const pm_node_t *attached = walk->attached[after]; + uint32_t attached_end = attached == NULL ? 0 : PM_LOCATION_END(&attached->location); + + if (end >= attached_end || attached_end > comment_start) { + walk->attached[after] = node; + } + } + } + + /* Grab up the remaining comments within the range of this node that were + * not claimed by any of its descendants. A comment that is separated by + * only whitespace and other comments from a statements node child, either + * the child after it or the child before it, is attached to the statements + * instead, so that the comments before the first statement and after the + * last statement in a body belong to the body. The claimed comments are in + * order, so the children around each one are found by moving forward + * through the sorted children. */ + if (after > 0 && walk->starts[after - 1] >= start) { + uint32_t index = pm_comments_unclaimed(walk, pm_comments_lower_bound(walk, 0, after, start)); + size_t child_index = base; + + /* The boundaries around the statements children are each found once, + * when the first comment that needs them is reached, since the + * comments that follow reach the same children. */ + const pm_node_t *leading = NULL; + uint32_t leading_boundary = 0; + const pm_node_t *trailing = NULL; + uint32_t trailing_boundary = 0; + + while (index < after && PM_LOCATION_END(&walk->comments[index]->location) <= end) { + if (walk->attached[index] == NULL) { + uint32_t comment_end = PM_LOCATION_END(&walk->comments[index]->location); + const pm_node_t *attached = node; + + while (child_index < top && walk->stack.nodes[child_index]->location.start < comment_end) child_index++; + + if (child_index < top) { + const pm_node_t *child = walk->stack.nodes[child_index]; + + if (PM_NODE_TYPE_P(child, PM_STATEMENTS_NODE)) { + if (child != leading) { + leading = child; + leading_boundary = pm_comments_blank_before(walk, child->location.start); + } + + if (walk->starts[index] >= leading_boundary) attached = child; + } + } + + if (attached == node && child_index > base) { + const pm_node_t *child = walk->stack.nodes[child_index - 1]; + + /* A rescue clause ends at its last statement rather than at + * the keyword that follows it, and the first clause in a + * body contains the clauses after it. So a comment after + * the statements of the last clause follows the first + * clause, and belongs to the statements of the last. */ + if (PM_NODE_TYPE_P(child, PM_RESCUE_NODE)) { + const pm_rescue_node_t *rescue = (const pm_rescue_node_t *) child; + while (rescue->subsequent != NULL) rescue = rescue->subsequent; + child = (const pm_node_t *) rescue->statements; + } + + if (child != NULL && PM_NODE_TYPE_P(child, PM_STATEMENTS_NODE) && PM_LOCATION_END(&child->location) <= walk->starts[index]) { + if (child != trailing) { + trailing = child; + trailing_boundary = pm_comments_blank_after(walk, PM_LOCATION_END(&child->location), end); + } + + if (comment_end <= trailing_boundary) attached = child; + } + } + + walk->attached[index] = attached; + } + + walk->unclaimed[index] = index + 1; + index = pm_comments_unclaimed(walk, index + 1); + } + } + + /* Truncate the stack back to the base size. */ + walk->stack.size = base; +} + +/* + * Sort the parser's comment list in place by start offset, then assign every + * comment to the node that owns it. A comment is owned by: + * + * 1. the node that ends latest on the comment's line before the comment starts, + * with ties going to the node that is higher in the tree; + * 2. otherwise, the innermost node whose location contains the comment, or the + * statements node child of that node if only whitespace and other comments + * come between the statements and the comment, on either side; + * 3. otherwise, the top-level statements node of the program. + */ +void +pm_comments_attach(pm_parser_t *parser, const pm_node_t *root) { + assert(PM_NODE_TYPE_P(root, PM_PROGRAM_NODE)); + + uint32_t size = (uint32_t) parser->comment_list.size; + if (size == 0) return; + + pm_arena_t arena = { 0 }; + pm_comments_walk_t walk = { + .arena = &arena, + .source = parser->start, + .comments = pm_comments_sort(parser, size), + .size = size, + .starts = (uint32_t *) pm_arena_alloc(&arena, sizeof(uint32_t) * size, PRISM_ALIGNOF(uint32_t)), + .attached = (const pm_node_t **) pm_arena_zalloc(&arena, sizeof(pm_node_t *) * size, PRISM_ALIGNOF(pm_node_t *)), + .unclaimed = (uint32_t *) pm_arena_alloc(&arena, sizeof(uint32_t) * (size + 1), PRISM_ALIGNOF(uint32_t)) + }; + + for (uint32_t index = 0; index < size; index++) walk.starts[index] = walk.comments[index]->location.start; + for (uint32_t index = 0; index <= size; index++) walk.unclaimed[index] = index; + + pm_comments_visit(&walk, root); + + /* + * Attach comments that no node attached to during the walk to the + * top-level statements, then group the comments by node with a counting + * sort. Comments are placed in sorted order, so each node's comments stay + * sorted by start offset. + */ + const pm_node_t *statements = (const pm_node_t *) ((const pm_program_node_t *) root)->statements; + uint32_t ranges_size = 0; + + for (uint32_t index = 0; index < size; index++) { + if (walk.attached[index] == NULL) walk.attached[index] = statements; + + uint32_t node_id = walk.attached[index]->node_id; + assert(node_id <= parser->node_id); + if (node_id >= ranges_size) ranges_size = node_id + 1; + } + + /* The ranges only extend to the largest node id that owns a comment, since + * none of the nodes after it own any. */ + pm_comment_range_t *ranges = (pm_comment_range_t *) pm_arena_zalloc(&parser->metadata_arena, sizeof(pm_comment_range_t) * ranges_size, PRISM_ALIGNOF(pm_comment_range_t)); + uint32_t *attachments = (uint32_t *) pm_arena_alloc(&parser->metadata_arena, sizeof(uint32_t) * size, PRISM_ALIGNOF(uint32_t)); + + for (uint32_t index = 0; index < size; index++) { + ranges[walk.attached[index]->node_id].length++; + } + + uint32_t offset = 0; + for (uint32_t index = 0; index < ranges_size; index++) { + ranges[index].index = offset; + offset += ranges[index].length; + ranges[index].length = 0; + } + + for (uint32_t index = 0; index < size; index++) { + pm_comment_range_t *range = &ranges[walk.attached[index]->node_id]; + attachments[range->index + range->length++] = index; + } + + pm_arena_cleanup(&arena); + + parser->comment_attachments = (pm_comment_attachments_t) { + .comments = walk.comments, + .attachments = attachments, + .ranges = ranges, + .ranges_size = ranges_size + }; +} diff --git a/src/options.c b/src/options.c index 9e9cbf7915..66b21439e3 100644 --- a/src/options.c +++ b/src/options.c @@ -243,6 +243,22 @@ pm_options_freeze_set(pm_options_t *options, bool freeze) { options->freeze = freeze; } +/** + * Get the attach_comments option on the given options struct. + */ +bool +pm_options_attach_comments(const pm_options_t *options) { + return options->attach_comments; +} + +/** + * Set the attach_comments option on the given options struct. + */ +void +pm_options_attach_comments_set(pm_options_t *options, bool attach_comments) { + options->attach_comments = attach_comments; +} + /** * Get the raise_error option on the given options struct. */ @@ -401,6 +417,7 @@ pm_options_read(pm_options_t *options, const char *data) { options->main_script = ((uint8_t) *data++) > 0; options->partial_script = ((uint8_t) *data++) > 0; options->freeze = ((uint8_t) *data++) > 0; + options->attach_comments = ((uint8_t) *data++) > 0; uint32_t scopes_count = pm_options_read_u32(data); data += 4; diff --git a/src/parser.c b/src/parser.c index 415cd31984..2691cc59a7 100644 --- a/src/parser.c +++ b/src/parser.c @@ -189,6 +189,53 @@ pm_parser_comments_each(const pm_parser_t *parser, pm_comment_callback_t callbac } } +/** + * Returns the number of comments owned by the given node. + */ +uint32_t +pm_node_comments_size(const pm_parser_t *parser, const pm_node_t *node) { + return pm_parser_comment_range(parser, node->node_id).length; +} + +/** + * Returns the comment at the given index among the comments owned by the given + * node. + */ +const pm_comment_t * +pm_node_comment(const pm_parser_t *parser, const pm_node_t *node, uint32_t index) { + pm_comment_range_t range = pm_parser_comment_range(parser, node->node_id); + if (index >= range.length) return NULL; + + return parser->comment_attachments.comments[parser->comment_attachments.attachments[range.index + index]]; +} + +/** + * Returns the index, among the comments associated with the given parser, of + * the comment at the given index among the comment attachments. + */ +uint32_t +pm_parser_comment_attachment(const pm_parser_t *parser, uint32_t index) { + if (parser->comment_attachments.attachments == NULL || index >= parser->comment_list.size) return UINT32_MAX; + return parser->comment_attachments.attachments[index]; +} + +/** + * Returns the number of node ids that have a comment range. + */ +uint32_t +pm_parser_comment_ranges_size(const pm_parser_t *parser) { + return parser->comment_attachments.ranges_size; +} + +/** + * Returns the range of comment attachments owned by the node with the given id. + */ +pm_comment_range_t +pm_parser_comment_range(const pm_parser_t *parser, uint32_t node_id) { + if (node_id >= parser->comment_attachments.ranges_size) return (pm_comment_range_t) { .index = 0, .length = 0 }; + return parser->comment_attachments.ranges[node_id]; +} + /** * Returns the location associated with the given magic comment key. */ diff --git a/src/prism.c b/src/prism.c index 2e2811d216..04fe33a5c5 100644 --- a/src/prism.c +++ b/src/prism.c @@ -113,9 +113,6 @@ pm_version(void) { #define FL PM_NODE_FLAGS #define UP PM_NODE_UPCAST -#define PM_LOCATION_START(location_) ((location_)->start) -#define PM_LOCATION_END(location_) ((location_)->start + (location_)->length) - #define PM_TOKEN_START(parser_, token_) U32((token_)->start - (parser_)->start) #define PM_TOKEN_END(parser_, token_) U32((token_)->end - (parser_)->start) #define PM_TOKEN_LENGTH(token_) U32((token_)->end - (token_)->start) @@ -23002,6 +22999,7 @@ pm_parser_init(pm_arena_t *arena, pm_parser_t *parser, const uint8_t *source, si .command_line = 0, .parsing_eval = false, .partial_script = false, + .attach_comments = false, .command_start = true, .recovering = false, .continuable = true, @@ -23069,6 +23067,9 @@ pm_parser_init(pm_arena_t *arena, pm_parser_t *parser, const uint8_t *source, si // partial_script parser->partial_script = options->partial_script; + // attach_comments + parser->attach_comments = options->attach_comments; + // scopes option parser->parsing_eval = options->scopes_count > 0; if (parser->parsing_eval) parser->warn_mismatched_indentation = false; @@ -23429,6 +23430,7 @@ pm_node_t * pm_parse(pm_parser_t *parser) { pm_node_t *node = parse_program(parser); pm_parse_continuable(parser); + if (parser->attach_comments) pm_comments_attach(parser, node); return node; } diff --git a/templates/ext/prism/api_node.c.erb b/templates/ext/prism/api_node.c.erb index 9ef799be10..fed16a0e11 100644 --- a/templates/ext/prism/api_node.c.erb +++ b/templates/ext/prism/api_node.c.erb @@ -77,7 +77,7 @@ pm_integer_new(const pm_integer_t *integer) { // Create a Prism::Source object from the given parser, after pm_parse() was called. VALUE -pm_source_new(const pm_parser_t *parser, rb_encoding *encoding, bool freeze) { +pm_source_new(const pm_parser_t *parser, rb_encoding *encoding, VALUE comments, VALUE comment_attachments, VALUE comment_ranges, bool freeze) { const uint8_t *start = pm_parser_start(parser); VALUE source_string = rb_enc_str_new((const char *) start, pm_parser_end(parser) - start, encoding); @@ -96,7 +96,7 @@ pm_source_new(const pm_parser_t *parser, rb_encoding *encoding, bool freeze) { offsets = rb_str_new((const char *) line_offsets->offsets, line_offsets->size * sizeof(uint32_t)); } - VALUE source = rb_funcall(rb_cPrismSource, rb_intern("for"), 3, source_string, LONG2NUM(pm_parser_start_line(parser)), offsets); + VALUE source = rb_funcall(rb_cPrismSource, rb_intern("for"), 6, source_string, LONG2NUM(pm_parser_start_line(parser)), offsets, comments, comment_attachments, comment_ranges); if (freeze) rb_obj_freeze(source); return source; diff --git a/templates/javascript/src/deserialize.js.erb b/templates/javascript/src/deserialize.js.erb index 5673edb181..e00e0f26a9 100644 --- a/templates/javascript/src/deserialize.js.erb +++ b/templates/javascript/src/deserialize.js.erb @@ -297,6 +297,16 @@ export function deserialize(source, array) { location: buffer.readLocation() })); + // Skip the comments attached to each node, which this library does not + // expose. Each entry is a node id followed by the indices of its comments. + for (let count = buffer.readVarInt(); count > 0; count--) { + buffer.readVarInt(); + + for (let length = buffer.readVarInt(); length > 0; length--) { + buffer.readVarInt(); + } + } + const magicComments = Array.from({ length: buffer.readVarInt() }, () => ({ startLocation: buffer.readLocation(), endLocation: buffer.readLocation() diff --git a/templates/lib/prism/node.rb.erb b/templates/lib/prism/node.rb.erb index 5b9a9a98a8..3233acec2a 100644 --- a/templates/lib/prism/node.rb.erb +++ b/templates/lib/prism/node.rb.erb @@ -170,25 +170,12 @@ module Prism location.cached_end_code_units_column(cache) end - # Delegates to [`leading_comments`](rdoc-ref:Location#leading_comments) of the associated location object. - # - #: () -> Array[Comment] - def leading_comments - location.leading_comments - end - - # Delegates to [`trailing_comments`](rdoc-ref:Location#trailing_comments) of the associated location object. - # - #: () -> Array[Comment] - def trailing_comments - location.trailing_comments - end - - # Delegates to [`comments`](rdoc-ref:Location#comments) of the associated location object. + # The comments attached to this node, ordered by start offset. Comments are + # only attached when the source is parsed with the attach_comments option. # #: () -> Array[Comment] def comments - location.comments + source.comments_for(node_id) end # :section: @@ -380,14 +367,6 @@ module Prism raise NoMethodError, "undefined method `compact_child_nodes' for #{inspect}" end - # Returns an array of child nodes and locations that could potentially have - # comments attached to them. - # - #: () -> Array[node | Location] - def comment_targets - raise NoMethodError, "undefined method `comment_targets' for #{inspect}" - end - # Returns a string representation of the node. # #: () -> String @@ -525,18 +504,6 @@ module Prism <%- end -%> end - # See Node.comment_targets. - # - #: () -> Array[node | Location] - def comment_targets - [<%= node.fields.map { |field| - case field - when Prism::Template::NodeField, Prism::Template::LocationField then field.name - when Prism::Template::OptionalNodeField, Prism::Template::NodeListField, Prism::Template::OptionalLocationField then "*#{field.name}" - end - }.compact.join(", ") %>] #: Array[Prism::node | Location] - end - # :call-seq: # copy(**fields) -> <%= node.name %> # diff --git a/templates/lib/prism/serialize.rb.erb b/templates/lib/prism/serialize.rb.erb index 1577044f70..d6e92ab5e7 100644 --- a/templates/lib/prism/serialize.rb.erb +++ b/templates/lib/prism/serialize.rb.erb @@ -38,7 +38,8 @@ module Prism source.replace_start_line(start_line) source.replace_offsets(offsets) - comments = loader.load_comments(freeze) + loader.load_comments(source.comments, freeze) + loader.load_comment_attachments(source, freeze) magic_comments = loader.load_magic_comments(freeze) data_loc = loader.load_optional_location_object(freeze) errors = loader.load_errors(encoding, freeze) @@ -53,7 +54,7 @@ module Prism loader.load_constant_pool(constant_pool) raise unless loader.eof? - result = ParseResult.new(node, comments, magic_comments, data_loc, errors, warnings, continuable, source) + result = ParseResult.new(node, magic_comments, data_loc, errors, warnings, continuable, source) result.freeze if freeze input.force_encoding(encoding) @@ -93,7 +94,8 @@ module Prism source.replace_start_line(start_line) source.replace_offsets(offsets) - comments = loader.load_comments(freeze) + loader.load_comments(source.comments, freeze) + loader.load_comment_attachments(source, freeze) magic_comments = loader.load_magic_comments(freeze) data_loc = loader.load_optional_location_object(freeze) errors = loader.load_errors(encoding, freeze) @@ -101,7 +103,7 @@ module Prism continuable = loader.load_bool raise unless loader.eof? - result = LexResult.new(tokens, comments, magic_comments, data_loc, errors, warnings, continuable, source) + result = LexResult.new(tokens, magic_comments, data_loc, errors, warnings, continuable, source) tokens.each do |token| token[0].value.force_encoding(encoding) @@ -140,7 +142,7 @@ module Prism source.replace_start_line(start_line) source.replace_offsets(offsets) - result = loader.load_comments(freeze) + result = loader.load_comments(source.comments, freeze) raise unless loader.eof? source.deep_freeze if freeze @@ -167,7 +169,8 @@ module Prism source.replace_start_line(start_line) source.replace_offsets(offsets) - comments = loader.load_comments(freeze) + loader.load_comments(source.comments, freeze) + loader.load_comment_attachments(source, freeze) magic_comments = loader.load_magic_comments(freeze) data_loc = loader.load_optional_location_object(freeze) errors = loader.load_errors(encoding, freeze) @@ -183,7 +186,7 @@ module Prism raise unless loader.eof? value = [node, tokens] #: [ProgramNode, Array[Token]] - result = ParseLexResult.new(value, comments, magic_comments, data_loc, errors, warnings, continuable, source) + result = ParseLexResult.new(value, magic_comments, data_loc, errors, warnings, continuable, source) tokens.each do |token| token[0].value.force_encoding(encoding) @@ -316,20 +319,46 @@ module Prism offsets end - #: (bool freeze) -> Array[Comment] - def load_comments(freeze) - comments = - Array.new(load_varuint) do - comment = - case load_varuint - when 0 then InlineComment.new(load_location_object(freeze)) - when 1 then EmbDocComment.new(load_location_object(freeze)) - else raise - end - - comment.freeze if freeze - comment - end + # Load the comments attached to each node into the comment attachments and + # comment ranges of the given source. For each node that owns comments, the + # index at which its comments begin is stored at its node id and the index + # at which they end at the following node id. + # + #: (Source source, bool freeze) -> void + def load_comment_attachments(source, freeze) + comments = source.comments + attachments = source.comment_attachments + ranges = source.comment_ranges + + load_varuint.times do + node_id = load_varuint + ranges[node_id] = attachments.length + load_varuint.times { attachments << comments[load_varuint] } + ranges[node_id + 1] = attachments.length + end + + if freeze + attachments.freeze + ranges.freeze + end + end + + # Load the comments into the given list, which belongs to the source that + # the comments refer to. + # + #: (Array[Comment] comments, bool freeze) -> Array[Comment] + def load_comments(comments, freeze) + load_varuint.times do + comment = + case load_varuint + when 0 then InlineComment.new(load_location_object(freeze)) + when 1 then EmbDocComment.new(load_location_object(freeze)) + else raise + end + + comment.freeze if freeze + comments << comment + end comments.freeze if freeze comments diff --git a/templates/src/serialize.c.erb b/templates/src/serialize.c.erb index 09d80ed1a5..dc27399c62 100644 --- a/templates/src/serialize.c.erb +++ b/templates/src/serialize.c.erb @@ -192,6 +192,36 @@ pm_serialize_comment_list(pm_list_t *list, pm_buffer_t *buffer) { } } +<%- unless Prism::Template::SERIALIZE_ONLY_SEMANTICS_FIELDS -%> +/** + * Serialize the comments attached to each node. This is the number of nodes + * that own comments, followed by each of those nodes' id, the number of + * comments it owns, and the index of each of those comments in the comment + * list. + */ +static void +pm_serialize_comment_attachments(const pm_comment_attachments_t *attachments, pm_buffer_t *buffer) { + uint32_t count = 0; + for (uint32_t node_id = 0; node_id < attachments->ranges_size; node_id++) { + if (attachments->ranges[node_id].length > 0) count++; + } + + pm_buffer_append_varuint(buffer, count); + + for (uint32_t node_id = 0; node_id < attachments->ranges_size; node_id++) { + pm_comment_range_t range = attachments->ranges[node_id]; + if (range.length == 0) continue; + + pm_buffer_append_varuint(buffer, node_id); + pm_buffer_append_varuint(buffer, range.length); + + for (uint32_t index = 0; index < range.length; index++) { + pm_buffer_append_varuint(buffer, attachments->attachments[range.index + index]); + } + } +} +<%- end -%> + static void pm_serialize_magic_comment(pm_magic_comment_t *magic_comment, pm_buffer_t *buffer) { // serialize key location @@ -266,6 +296,7 @@ pm_serialize_metadata(pm_parser_t *parser, pm_buffer_t *buffer) { pm_serialize_line_offset_list(&parser->line_offsets, buffer); <%- unless Prism::Template::SERIALIZE_ONLY_SEMANTICS_FIELDS -%> pm_serialize_comment_list(&parser->comment_list, buffer); + pm_serialize_comment_attachments(&parser->comment_attachments, buffer); <%- end -%> pm_serialize_magic_comment_list(&parser->magic_comment_list, buffer); pm_serialize_data_loc(parser, buffer); diff --git a/test/prism/api/freeze_test.rb b/test/prism/api/freeze_test.rb index bf91792e69..f77200479c 100644 --- a/test/prism/api/freeze_test.rb +++ b/test/prism/api/freeze_test.rb @@ -38,17 +38,22 @@ def test_dump private - def assert_frozen_each(value) + # Sources and the locations within them refer to each other, so each object + # is only checked the first time it is reached. + def assert_frozen_each(value, seen = {}.compare_by_identity) + return if seen.key?(value) + seen[value] = true + assert_predicate value, :frozen? value.instance_variables.each do |name| case (child = value.instance_variable_get(name)) when Array - child.each { |item| assert_frozen_each(item) } + child.each { |item| assert_frozen_each(item, seen) } when Hash - child.each { |key, item| assert_frozen_each(key); assert_frozen_each(item) } + child.each { |key, item| assert_frozen_each(key, seen); assert_frozen_each(item, seen) } else - assert_frozen_each(child) + assert_frozen_each(child, seen) end end end diff --git a/test/prism/api/parse_test.rb b/test/prism/api/parse_test.rb index 5ca67d20bd..6d487e6ce9 100644 --- a/test/prism/api/parse_test.rb +++ b/test/prism/api/parse_test.rb @@ -110,6 +110,15 @@ def test_partial_script assert Prism.parse_success?("yield", partial_script: true) end + def test_attach_comments + assert Prism.parse_success?("foo # comment", attach_comments: true) + assert Prism.parse_success?("foo # comment", attach_comments: false) + + # The serialized options are positional, so the scopes that follow + # attach_comments must still be read correctly. + assert_kind_of Prism::LocalVariableReadNode, Prism.parse_statement("foo", attach_comments: true, scopes: [[:foo]]) + end + def test_version assert Prism.parse_success?("1 + 1", version: "3.3") assert Prism.parse_success?("1 + 1", version: "3.3.0") diff --git a/test/prism/result/attach_comments_test.rb b/test/prism/result/attach_comments_test.rb new file mode 100644 index 0000000000..dca5ec9dfc --- /dev/null +++ b/test/prism/result/attach_comments_test.rb @@ -0,0 +1,262 @@ +# frozen_string_literal: true + +require_relative "../test_helper" + +module Prism + class AttachCommentsTest < TestCase + Fixture.each do |fixture| + define_method(fixture.test_name) { assert_attachments(fixture.read) } + end + + def test_trailing_ties_go_to_the_higher_node + assert_attached({ "# c" => [:alias_method_node, "alias :foo :bar"] }, "alias :foo :bar # c") + end + + def test_trailing_goes_to_the_node_ending_on_the_line + assert_attached({ "# c" => [:symbol_node, ":foo"] }, "alias :foo # c\n:bar") + end + + def test_trailing_in_body + assert_attached({ "# c" => [:call_node, "a"] }, "def foo\na # c\nb\nend") + end + + def test_trailing_after_heredoc_opener + assert_attached({ "# c" => [:call_node, "foo(<<~A)"] }, "foo(<<~A) # c\n x\nA\n") + end + + def test_trailing_after_last_statement + assert_attached({ "# c" => [:call_node, "b"] }, "a\nb # c") + end + + def test_own_line_goes_to_the_innermost_enclosing_node + assert_attached({ "# c" => [:statements_node, "a\n# c\nb"] }, "def foo\na\n# c\nb\nend") + end + + def test_own_line_in_arguments + assert_attached({ "# c" => [:call_node, "foo(# c\n x)"] }, "foo(# c\n x)") + end + + def test_own_line_before_class_body + assert_attached({ "# doc" => [:statements_node, "def b; end"] }, "class A\n # doc\n def b; end\nend") + end + + def test_own_line_block_before_body + assert_attached({ "# a" => [:statements_node, "def b; end"], "# b" => [:statements_node, "def b; end"] }, "class A\n # a\n\n # b\n def b; end\nend") + end + + def test_own_line_before_method_body + assert_attached({ "# c" => [:statements_node, "body"] }, "def foo(a)\n # c\n body\nend") + end + + def test_own_line_before_block_body + assert_attached({ "# c" => [:statements_node, "bar"] }, "foo do |x|\n # c\n bar\nend") + end + + def test_own_line_separated_from_body + assert_attached({ "# c" => [:def_node, "def foo(a\n # c\n)\n body\nend"] }, "def foo(a\n # c\n)\n body\nend") + end + + def test_own_line_after_class_body + assert_attached({ "# note" => [:statements_node, "def x; end"] }, "class A\n def x; end\n # note\nend") + end + + def test_embdoc_before_and_after_class_body + source = "class A\n=begin\nbefore\n=end\n def b; end\n=begin\nafter\n=end\nend" + assert_attached({ "=begin\nbefore\n=end\n" => [:statements_node, "def b; end"], "=begin\nafter\n=end\n" => [:statements_node, "def b; end"] }, source) + end + + def test_own_line_after_method_body + assert_attached({ "# c" => [:statements_node, "a"] }, "def foo\n a\n # c\nend") + end + + def test_own_line_around_class_body + assert_attached({ "# doc" => [:statements_node, "def b; end"], "# tail" => [:statements_node, "def b; end"] }, "class A\n # doc\n def b; end\n # tail\nend") + end + + def test_own_line_after_branch_bodies + assert_attached({ "# c" => [:statements_node, "b"], "# e" => [:statements_node, "d"] }, "if a\n b\n # c\nelse\n d\n # e\nend") + end + + def test_own_line_after_rescue_body + assert_attached({ "# c" => [:statements_node, "b"] }, "def foo\n a\nrescue\n b\n # c\nend") + end + + def test_own_line_after_each_rescue_body + assert_attached({ "# c1" => [:statements_node, "x"], "# c2" => [:statements_node, "y"] }, "begin\n a\nrescue A\n x\n # c1\nrescue B\n y\n # c2\nend") + end + + def test_own_line_after_rescue_body_before_ensure + assert_attached({ "# c" => [:statements_node, "b"] }, "def foo\n a\nrescue => e\n b\n # c\nensure\n z\nend") + end + + def test_own_line_in_empty_rescue_body + assert_attached({ "# c" => [:begin_node, "def foo\n a\nrescue\n # c\nend"] }, "def foo\n a\nrescue\n # c\nend") + end + + def test_own_line_after_block_body + assert_attached({ "# c" => [:statements_node, "bar"] }, "foo do\n bar\n # c\nend") + end + + def test_own_line_in_empty_class_body + assert_attached({ "# c" => [:class_node, "class A\n # c\nend"] }, "class A\n # c\nend") + end + + def test_own_line_at_top_level + assert_attached({ "# doc" => [:statements_node, "def foo; end"] }, "# doc\ndef foo; end") + end + + def test_only_comments + assert_attached({ "# only" => [:statements_node, ""] }, "# only") + end + + def test_embdoc + assert_attached({ "=begin\nembdoc\n=end\n" => [:statements_node, "foo"] }, "=begin\nembdoc\n=end\nfoo") + end + + def test_comments_around_a_child + source = "foo(# a\n x, # m\n y) # b" + call = "foo(# a\n x, # m\n y)" + + assert_attached({ "# a" => [:call_node, call], "# m" => [:call_node, "x"], "# b" => [:call_node, call] }, source) + end + + def test_heredoc_body_inside_later_sibling + source = "foo(<<~A, [\n \#{ # c\n x }\nA\n 1])\n" + assert_attached({ "# c" => [:statements_node, "x"] }, source) + end + + def test_heredoc_part_ending_in_newline + source = "<<~A\n text\n \#{ # c\n x }\nA\n" + assert_attached({ "# c" => [:statements_node, "x"] }, source) + end + + def test_heredoc_comments_are_sorted + source = "foo(<<~A) # after\n \#{x # body\n }\nA\n" + + assert_equal ["# after", "# body"], Prism.parse(source, attach_comments: true).comments.map(&:slice) + assert_equal ["# body", "# after"], Prism.parse(source).comments.map(&:slice) + end + + def test_nested_heredoc_comments + source = "foo(<<~A, <<~B) # after\n \#{x # body a\n }\nA\n \#{y # body b\n }\nB\n" + + assert_attached( + { + "# after" => [:call_node, "foo(<<~A, <<~B)"], + "# body a" => [:call_node, "x"], + "# body b" => [:call_node, "y"] + }, + source + ) + end + + def test_comments_are_shared_with_the_result + result = Prism.parse("foo # c", attach_comments: true) + assert_same result.comments.first, result.value.statements.body.first.comments.first + end + + def test_without_attach_comments + result = Prism.parse("foo # c") + each_node(result.value) { |node| assert_empty node.comments } + end + + def test_freeze + result = Prism.parse("foo # c", attach_comments: true, freeze: true) + comments = result.value.statements.body.first.comments + + assert_equal ["# c"], comments.map(&:slice) + assert_predicate result.source.comment_attachments, :frozen? + assert_predicate result.source.comment_ranges, :frozen? + assert Ractor.shareable?(result) if defined?(Ractor.shareable?) + end + + def test_parse_lex + node, = Prism.parse_lex("foo # c", attach_comments: true).value + assert_equal ["# c"], node.statements.body.first.comments.map(&:slice) + end + + def test_parse_stream + result = Prism.parse_stream(StringIO.new("foo # c"), attach_comments: true) + assert_equal ["# c"], result.value.statements.body.first.comments.map(&:slice) + end + + private + + # Assert that each comment in the source is attached to the node with the + # given type and slice. + def assert_attached(expected, source) + actual = {} + + each_node(Prism.parse(source, attach_comments: true).value) do |node| + node.comments.each { |comment| actual[comment.slice] = [node.type, node.slice] } + end + + assert_equal expected, actual + end + + # Assert that every comment is attached to exactly one node, that each + # node's comments are sorted, and that each node only owns comments on the + # lines it covers. The exceptions are statements nodes, which own the + # comments that come before or after them with only whitespace and comments + # in between, and the top-level statements, which own the comments that no + # other node covers. + def assert_attachments(source) + result = Prism.parse(source, attach_comments: true) + offsets = result.comments.map { |comment| comment.location.start_offset } + assert_equal offsets.sort, offsets + + top = result.value.statements + attached = [] + + each_node(result.value) do |node| + comments = node.comments + assert_equal comments.sort_by { |comment| comment.location.start_offset }, comments + attached.concat(comments) + + next if node.equal?(top) + + location = node.location + end_line = location.length == 0 ? location.start_line : result.source.line(location.end_offset - 1) + + comments.each do |comment| + if node.is_a?(StatementsNode) && (comment.location.end_offset <= location.start_offset || comment.location.start_offset >= location.end_offset) + range = comment.location.end_offset <= location.start_offset ? (comment.location.end_offset...location.start_offset) : (location.end_offset...comment.location.start_offset) + gap = result.source.source.byteslice(range) + result.comments.each { |other| gap = gap.sub(other.slice, "") if gap.include?(other.slice) } + assert_match(/\A\s*\z/, gap) + else + assert_operator comment.location.start_line, :>=, location.start_line + assert_operator comment.location.start_line, :<=, end_line + end + end + end + + assert_equal result.comments.map(&:object_id).sort, attached.map(&:object_id).sort + + if !ENV["PRISM_BUILD_MINIMAL"] + loaded = Prism.load(source, Prism.dump(source, attach_comments: true)) + assert_equal attachments(result.value), attachments(loaded.value) + end + end + + # The start offsets of the comments attached to each node, keyed by node id. + def attachments(root) + attachments = {} + + each_node(root) do |node| + attachments[node.node_id] = node.comments.map { |comment| comment.location.start_offset } if node.comments.any? + end + + attachments + end + + def each_node(root) + queue = [root] + + while (node = queue.shift) + yield node + queue.concat(node.compact_child_nodes) + end + end + end +end diff --git a/test/prism/result/comments_test.rb b/test/prism/result/comments_test.rb index 140eddd5d1..54a4bd3e8c 100644 --- a/test/prism/result/comments_test.rb +++ b/test/prism/result/comments_test.rb @@ -105,30 +105,6 @@ def test_comment_embedded_document_with_content_on_same_line ) end - def test_attaching_comments - source = <<~RUBY - # Foo class - class Foo - # bar method - def bar - # baz invocation - baz - end # bar end - end # Foo end - RUBY - - result = Prism.parse(source) - result.attach_comments! - tree = result.value - class_node = tree.statements.body.first - method_node = class_node.body.body.first - call_node = method_node.body.body.first - - assert_equal("# Foo class\n# Foo end", class_node.location.comments.map { |c| c.location.slice }.join("\n")) - assert_equal("# bar method\n# bar end", method_node.location.comments.map { |c| c.location.slice }.join("\n")) - assert_equal("# baz invocation", call_node.location.comments.map { |c| c.location.slice }.join("\n")) - end - private def assert_comment(source, type, start_offset:, end_offset:, start_line:, end_line:, start_column:, end_column:) diff --git a/test/prism/ruby/relocation_test.rb b/test/prism/ruby/relocation_test.rb index f8372afa6d..6a798f42c8 100644 --- a/test/prism/ruby/relocation_test.rb +++ b/test/prism/ruby/relocation_test.rb @@ -123,51 +123,7 @@ def test_code_unit_columns assert_equal 11, location_entry.end_code_units_column end - def test_leading_comments - source = "# leading\nclass Foo\nend" - repository = Relocation.string(source).leading_comments - declaration = Prism.parse(source).value.statements.body.first - - node_entry = declaration.save(repository) - location_entry = declaration.save_location(repository) - - assert_equal ["# leading"], node_entry.leading_comments.map(&:slice) - assert_equal ["# leading"], location_entry.leading_comments.map(&:slice) - end - - def test_trailing_comments - source = "class Foo\nend\n# trailing" - repository = Relocation.string(source).trailing_comments - declaration = Prism.parse(source).value.statements.body.first - - node_entry = declaration.save(repository) - location_entry = declaration.save_location(repository) - - assert_equal ["# trailing"], node_entry.trailing_comments.map(&:slice) - assert_equal ["# trailing"], location_entry.trailing_comments.map(&:slice) - end - - def test_comments - source = "# leading\nclass Foo\nend\n# trailing" - repository = Relocation.string(source).comments - declaration = Prism.parse(source).value.statements.body.first - - node_entry = declaration.save(repository) - location_entry = declaration.save_location(repository) - - assert_equal ["# leading", "# trailing"], node_entry.comments.map(&:slice) - assert_equal ["# leading", "# trailing"], location_entry.comments.map(&:slice) - end - def test_misconfiguration - assert_raise Relocation::Repository::ConfigurationError do - Relocation.string("").comments.leading_comments - end - - assert_raise Relocation::Repository::ConfigurationError do - Relocation.string("").comments.trailing_comments - end - assert_raise Relocation::Repository::ConfigurationError do Relocation.string("").code_unit_offsets(Encoding::UTF_8).code_unit_offsets(Encoding::UTF_16LE) end diff --git a/test/prism/ruby/ruby_parser_test.rb b/test/prism/ruby/ruby_parser_test.rb index 600f97c80b..d4df715661 100644 --- a/test/prism/ruby/ruby_parser_test.rb +++ b/test/prism/ruby/ruby_parser_test.rb @@ -112,12 +112,22 @@ def assert_ruby_parser(fixture, allowed_failure) unless actual.nil? assert_equal(expected.line, actual.line, on_failure) assert_equal(expected.file, actual.file, on_failure) + assert_comments(expected, actual) end elsif expected == actual && expected.line && actual.line && expected.file == actual.file puts "#{name} now passes" end end + def assert_comments(expected, actual) + assert_equal(expected.comments, actual.comments, "comments mismatch on #{expected.inspect}") + + expected.each_with_index do |child, index| + next unless child.is_a?(Sexp) && actual[index].is_a?(Sexp) + assert_comments(child, actual[index]) + end + end + def message(expected, actual) if expected == actual nil