From a157285d2804210537cd7be1dca3c62701a836a8 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sat, 31 Jan 2026 20:12:13 -0500 Subject: [PATCH 01/12] rename `pm_newline_list.h` --- include/prism/util/{pm_newline_list.h => pm_line_offset_list.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename include/prism/util/{pm_newline_list.h => pm_line_offset_list.h} (100%) diff --git a/include/prism/util/pm_newline_list.h b/include/prism/util/pm_line_offset_list.h similarity index 100% rename from include/prism/util/pm_newline_list.h rename to include/prism/util/pm_line_offset_list.h From d213c7e12c143aa56640e0b8039223abf0ca0492 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sat, 31 Jan 2026 20:15:02 -0500 Subject: [PATCH 02/12] `fd -e h -e c . |xargs perl -p -i -e s/pm_newline_list.h/pm_line_offset_list.h/` --- include/prism/parser.h | 2 +- include/prism/static_literals.h | 2 +- include/prism/util/pm_char.h | 2 +- include/prism/util/pm_line_offset_list.h | 2 +- prism.gemspec | 2 +- src/util/pm_newline_list.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/prism/parser.h b/include/prism/parser.h index a8d840d3bf..3e748e4e7a 100644 --- a/include/prism/parser.h +++ b/include/prism/parser.h @@ -13,7 +13,7 @@ #include "prism/static_literals.h" #include "prism/util/pm_constant_pool.h" #include "prism/util/pm_list.h" -#include "prism/util/pm_newline_list.h" +#include "prism/util/pm_line_offset_list.h" #include "prism/util/pm_string.h" #include diff --git a/include/prism/static_literals.h b/include/prism/static_literals.h index 0f8eb43bfa..f52440b6f1 100644 --- a/include/prism/static_literals.h +++ b/include/prism/static_literals.h @@ -8,7 +8,7 @@ #include "prism/defines.h" #include "prism/ast.h" -#include "prism/util/pm_newline_list.h" +#include "prism/util/pm_line_offset_list.h" #include #include diff --git a/include/prism/util/pm_char.h b/include/prism/util/pm_char.h index b213e8edee..58dcc75272 100644 --- a/include/prism/util/pm_char.h +++ b/include/prism/util/pm_char.h @@ -7,7 +7,7 @@ #define PRISM_CHAR_H #include "prism/defines.h" -#include "prism/util/pm_newline_list.h" +#include "prism/util/pm_line_offset_list.h" #include #include diff --git a/include/prism/util/pm_line_offset_list.h b/include/prism/util/pm_line_offset_list.h index dd3e625089..83f8ad4ead 100644 --- a/include/prism/util/pm_line_offset_list.h +++ b/include/prism/util/pm_line_offset_list.h @@ -1,5 +1,5 @@ /** - * @file pm_newline_list.h + * @file pm_line_offset_list.h * * A list of byte offsets of newlines in a string. * diff --git a/prism.gemspec b/prism.gemspec index c5c315fc8d..c8fb2e0a0d 100644 --- a/prism.gemspec +++ b/prism.gemspec @@ -61,7 +61,7 @@ Gem::Specification.new do |spec| "include/prism/util/pm_integer.h", "include/prism/util/pm_list.h", "include/prism/util/pm_memchr.h", - "include/prism/util/pm_newline_list.h", + "include/prism/util/pm_line_offset_list.h", "include/prism/util/pm_strncasecmp.h", "include/prism/util/pm_string.h", "include/prism/util/pm_strpbrk.h", diff --git a/src/util/pm_newline_list.c b/src/util/pm_newline_list.c index 89c294a6d7..099a74c5f3 100644 --- a/src/util/pm_newline_list.c +++ b/src/util/pm_newline_list.c @@ -1,4 +1,4 @@ -#include "prism/util/pm_newline_list.h" +#include "prism/util/pm_line_offset_list.h" /** * Initialize a new newline list with the given capacity. Returns true if the From 979c4525a51458adb42e988bfb66f7e983ae0384 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sat, 31 Jan 2026 20:17:06 -0500 Subject: [PATCH 03/12] fix include guards --- include/prism/util/pm_line_offset_list.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/prism/util/pm_line_offset_list.h b/include/prism/util/pm_line_offset_list.h index 83f8ad4ead..d17c6fe51c 100644 --- a/include/prism/util/pm_line_offset_list.h +++ b/include/prism/util/pm_line_offset_list.h @@ -11,8 +11,8 @@ * end column on every node in addition to the offsets that we already store, * but that would be quite a lot of memory overhead. */ -#ifndef PRISM_NEWLINE_LIST_H -#define PRISM_NEWLINE_LIST_H +#ifndef PRISM_LINE_OFFSET_LIST_H +#define PRISM_LINE_OFFSET_LIST_H #include "prism/defines.h" From 9a2d7845ab3a7c723f348c7fddbed40401bc18ab Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sat, 31 Jan 2026 20:19:51 -0500 Subject: [PATCH 04/12] rename the C type everywhere --- include/prism/parser.h | 2 +- include/prism/static_literals.h | 4 ++-- include/prism/util/pm_char.h | 2 +- include/prism/util/pm_line_offset_list.h | 14 +++++++------- src/static_literals.c | 6 +++--- src/util/pm_char.c | 2 +- src/util/pm_newline_list.c | 12 ++++++------ templates/src/serialize.c.erb | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/prism/parser.h b/include/prism/parser.h index 3e748e4e7a..5324d3f894 100644 --- a/include/prism/parser.h +++ b/include/prism/parser.h @@ -783,7 +783,7 @@ struct pm_parser { pm_constant_pool_t constant_pool; /** This is the list of newline offsets in the source file. */ - pm_newline_list_t newline_list; + pm_line_offset_list_t newline_list; /** * We want to add a flag to integer nodes that indicates their base. We only diff --git a/include/prism/static_literals.h b/include/prism/static_literals.h index f52440b6f1..a8a185c145 100644 --- a/include/prism/static_literals.h +++ b/include/prism/static_literals.h @@ -99,7 +99,7 @@ typedef struct { * @param replace Whether to replace the previous node if one already exists. * @return A pointer to the node that is being overwritten, if there is one. */ -pm_node_t * pm_static_literals_add(const pm_newline_list_t *newline_list, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace); +pm_node_t * pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace); /** * Free the internal memory associated with the given static literals set. @@ -118,6 +118,6 @@ void pm_static_literals_free(pm_static_literals_t *literals); * @param encoding_name The name of the encoding of the source being parsed. * @param node The node to create a string representation of. */ -void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node); +void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *newline_list, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node); #endif diff --git a/include/prism/util/pm_char.h b/include/prism/util/pm_char.h index 58dcc75272..2800c448cf 100644 --- a/include/prism/util/pm_char.h +++ b/include/prism/util/pm_char.h @@ -36,7 +36,7 @@ size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length); * @return The number of characters at the start of the string that are * whitespace. */ -size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list, uint32_t start_offset); +size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_line_offset_list_t *newline_list, uint32_t start_offset); /** * Returns the number of characters at the start of the string that are inline diff --git a/include/prism/util/pm_line_offset_list.h b/include/prism/util/pm_line_offset_list.h index d17c6fe51c..950210e6a4 100644 --- a/include/prism/util/pm_line_offset_list.h +++ b/include/prism/util/pm_line_offset_list.h @@ -34,7 +34,7 @@ typedef struct { /** The list of offsets. */ uint32_t *offsets; -} pm_newline_list_t; +} pm_line_offset_list_t; /** * A line and column in a string. @@ -55,14 +55,14 @@ typedef struct { * @param capacity The initial capacity of the list. * @return True if the allocation of the offsets succeeds, otherwise false. */ -bool pm_newline_list_init(pm_newline_list_t *list, size_t capacity); +bool pm_newline_list_init(pm_line_offset_list_t *list, size_t capacity); /** * Clear out the newlines that have been appended to the list. * * @param list The list to clear. */ -void pm_newline_list_clear(pm_newline_list_t *list); +void pm_newline_list_clear(pm_line_offset_list_t *list); /** * Append a new offset to the newline list. Returns true if the reallocation of @@ -73,7 +73,7 @@ void pm_newline_list_clear(pm_newline_list_t *list); * @return True if the reallocation of the offsets succeeds (if one was * necessary), otherwise false. */ -bool pm_newline_list_append(pm_newline_list_t *list, uint32_t cursor); +bool pm_newline_list_append(pm_line_offset_list_t *list, uint32_t cursor); /** * Returns the line of the given offset. If the offset is not in the list, the @@ -84,7 +84,7 @@ bool pm_newline_list_append(pm_newline_list_t *list, uint32_t cursor); * @param start_line The line to start counting from. * @return The line of the given offset. */ -int32_t pm_newline_list_line(const pm_newline_list_t *list, uint32_t cursor, int32_t start_line); +int32_t pm_newline_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line); /** * Returns the line and column of the given offset. If the offset is not in the @@ -96,13 +96,13 @@ int32_t pm_newline_list_line(const pm_newline_list_t *list, uint32_t cursor, int * @param start_line The line to start counting from. * @return The line and column of the given offset. */ -pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, uint32_t cursor, int32_t start_line); +pm_line_column_t pm_newline_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line); /** * Free the internal memory allocated for the newline list. * * @param list The list to free. */ -void pm_newline_list_free(pm_newline_list_t *list); +void pm_newline_list_free(pm_line_offset_list_t *list); #endif diff --git a/src/static_literals.c b/src/static_literals.c index 13a52378dd..e54b50c02f 100644 --- a/src/static_literals.c +++ b/src/static_literals.c @@ -7,7 +7,7 @@ */ typedef struct { /** The list of newline offsets to use to calculate line numbers. */ - const pm_newline_list_t *newline_list; + const pm_line_offset_list_t *newline_list; /** The start of the source being parsed. */ const uint8_t *start; @@ -356,7 +356,7 @@ pm_compare_regular_expression_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_liter * Add a node to the set of static literals. */ pm_node_t * -pm_static_literals_add(const pm_newline_list_t *newline_list, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace) { +pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace) { switch (PM_NODE_TYPE(node)) { case PM_INTEGER_NODE: case PM_SOURCE_LINE_NODE: @@ -613,7 +613,7 @@ pm_static_literal_inspect_node(pm_buffer_t *buffer, const pm_static_literals_met * Create a string-based representation of the given static literal. */ void -pm_static_literal_inspect(pm_buffer_t *buffer, const pm_newline_list_t *newline_list, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node) { +pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *newline_list, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node) { pm_static_literal_inspect_node( buffer, &(pm_static_literals_metadata_t) { diff --git a/src/util/pm_char.c b/src/util/pm_char.c index 748582b7fe..80ae63441c 100644 --- a/src/util/pm_char.c +++ b/src/util/pm_char.c @@ -83,7 +83,7 @@ pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length) { * searching past the given maximum number of characters. */ size_t -pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list, uint32_t start_offset) { +pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_line_offset_list_t *newline_list, uint32_t start_offset) { if (length <= 0) return 0; uint32_t size = 0; diff --git a/src/util/pm_newline_list.c b/src/util/pm_newline_list.c index 099a74c5f3..ad00a1db50 100644 --- a/src/util/pm_newline_list.c +++ b/src/util/pm_newline_list.c @@ -5,7 +5,7 @@ * allocation of the offsets succeeds, otherwise returns false. */ bool -pm_newline_list_init(pm_newline_list_t *list, size_t capacity) { +pm_newline_list_init(pm_line_offset_list_t *list, size_t capacity) { list->offsets = (uint32_t *) xcalloc(capacity, sizeof(uint32_t)); if (list->offsets == NULL) return false; @@ -21,7 +21,7 @@ pm_newline_list_init(pm_newline_list_t *list, size_t capacity) { * Clear out the newlines that have been appended to the list. */ void -pm_newline_list_clear(pm_newline_list_t *list) { +pm_newline_list_clear(pm_line_offset_list_t *list) { list->size = 1; } @@ -30,7 +30,7 @@ pm_newline_list_clear(pm_newline_list_t *list) { * the offsets succeeds (if one was necessary), otherwise returns false. */ bool -pm_newline_list_append(pm_newline_list_t *list, uint32_t cursor) { +pm_newline_list_append(pm_line_offset_list_t *list, uint32_t cursor) { if (list->size == list->capacity) { uint32_t *original_offsets = list->offsets; @@ -53,7 +53,7 @@ pm_newline_list_append(pm_newline_list_t *list, uint32_t cursor) { * line of the closest offset less than the given offset is returned. */ int32_t -pm_newline_list_line(const pm_newline_list_t *list, uint32_t cursor, int32_t start_line) { +pm_newline_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) { size_t left = 0; size_t right = list->size - 1; @@ -80,7 +80,7 @@ pm_newline_list_line(const pm_newline_list_t *list, uint32_t cursor, int32_t sta * are returned. */ pm_line_column_t -pm_newline_list_line_column(const pm_newline_list_t *list, uint32_t cursor, int32_t start_line) { +pm_newline_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) { size_t left = 0; size_t right = list->size - 1; @@ -108,6 +108,6 @@ pm_newline_list_line_column(const pm_newline_list_t *list, uint32_t cursor, int3 * Free the internal memory allocated for the newline list. */ void -pm_newline_list_free(pm_newline_list_t *list) { +pm_newline_list_free(pm_line_offset_list_t *list) { xfree(list->offsets); } diff --git a/templates/src/serialize.c.erb b/templates/src/serialize.c.erb index 958b0fd7cf..b9dde28786 100644 --- a/templates/src/serialize.c.erb +++ b/templates/src/serialize.c.erb @@ -154,7 +154,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) { } static void -pm_serialize_newline_list(pm_newline_list_t *list, pm_buffer_t *buffer) { +pm_serialize_newline_list(pm_line_offset_list_t *list, pm_buffer_t *buffer) { uint32_t size = pm_sizet_to_u32(list->size); pm_buffer_append_varuint(buffer, size); From 0fbd9c125d878135c4323f9c172a58068c840104 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sat, 31 Jan 2026 20:21:20 -0500 Subject: [PATCH 05/12] rename the C functions --- include/prism/util/pm_line_offset_list.h | 12 +++--- src/prism.c | 54 ++++++++++++------------ src/static_literals.c | 6 +-- src/util/pm_char.c | 2 +- src/util/pm_newline_list.c | 12 +++--- templates/src/prettyprint.c.erb | 4 +- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/include/prism/util/pm_line_offset_list.h b/include/prism/util/pm_line_offset_list.h index 950210e6a4..00176bc0d8 100644 --- a/include/prism/util/pm_line_offset_list.h +++ b/include/prism/util/pm_line_offset_list.h @@ -55,14 +55,14 @@ typedef struct { * @param capacity The initial capacity of the list. * @return True if the allocation of the offsets succeeds, otherwise false. */ -bool pm_newline_list_init(pm_line_offset_list_t *list, size_t capacity); +bool pm_line_offset_list_init(pm_line_offset_list_t *list, size_t capacity); /** * Clear out the newlines that have been appended to the list. * * @param list The list to clear. */ -void pm_newline_list_clear(pm_line_offset_list_t *list); +void pm_line_offset_list_clear(pm_line_offset_list_t *list); /** * Append a new offset to the newline list. Returns true if the reallocation of @@ -73,7 +73,7 @@ void pm_newline_list_clear(pm_line_offset_list_t *list); * @return True if the reallocation of the offsets succeeds (if one was * necessary), otherwise false. */ -bool pm_newline_list_append(pm_line_offset_list_t *list, uint32_t cursor); +bool pm_line_offset_list_append(pm_line_offset_list_t *list, uint32_t cursor); /** * Returns the line of the given offset. If the offset is not in the list, the @@ -84,7 +84,7 @@ bool pm_newline_list_append(pm_line_offset_list_t *list, uint32_t cursor); * @param start_line The line to start counting from. * @return The line of the given offset. */ -int32_t pm_newline_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line); +int32_t pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line); /** * Returns the line and column of the given offset. If the offset is not in the @@ -96,13 +96,13 @@ int32_t pm_newline_list_line(const pm_line_offset_list_t *list, uint32_t cursor, * @param start_line The line to start counting from. * @return The line and column of the given offset. */ -pm_line_column_t pm_newline_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line); +pm_line_column_t pm_line_offset_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line); /** * Free the internal memory allocated for the newline list. * * @param list The list to free. */ -void pm_newline_list_free(pm_line_offset_list_t *list); +void pm_line_offset_list_free(pm_line_offset_list_t *list); #endif diff --git a/src/prism.c b/src/prism.c index ca0f2a55aa..3b0a79fa03 100644 --- a/src/prism.c +++ b/src/prism.c @@ -1000,7 +1000,7 @@ pm_locals_order(PRISM_ATTRIBUTE_UNUSED pm_parser_t *parser, pm_locals_t *locals, if (local->name != PM_CONSTANT_ID_UNSET) { pm_constant_id_list_insert(list, (size_t) local->index, local->name); - if (warn_unused && local->reads == 0 && ((parser->start_line >= 0) || (pm_newline_list_line(&parser->newline_list, local->location.start, parser->start_line) >= 0))) { + if (warn_unused && local->reads == 0 && ((parser->start_line >= 0) || (pm_line_offset_list_line(&parser->newline_list, local->location.start, parser->start_line) >= 0))) { pm_constant_t *constant = pm_constant_pool_id_to_constant(&parser->constant_pool, local->name); if (constant->length >= 1 && *constant->start != '_') { @@ -9367,7 +9367,7 @@ lex_embdoc(pm_parser_t *parser) { if (newline == NULL) { parser->current.end = parser->end; } else { - pm_newline_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); parser->current.end = newline + 1; } @@ -9401,7 +9401,7 @@ lex_embdoc(pm_parser_t *parser) { if (newline == NULL) { parser->current.end = parser->end; } else { - pm_newline_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); parser->current.end = newline + 1; } @@ -9421,7 +9421,7 @@ lex_embdoc(pm_parser_t *parser) { if (newline == NULL) { parser->current.end = parser->end; } else { - pm_newline_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); parser->current.end = newline + 1; } @@ -9735,7 +9735,7 @@ pm_lex_percent_delimiter(pm_parser_t *parser) { parser_flush_heredoc_end(parser); } else { // Otherwise, we'll add the newline to the list of newlines. - pm_newline_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + U32(eol_length)); + pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + U32(eol_length)); } uint8_t delimiter = *parser->current.end; @@ -9839,7 +9839,7 @@ parser_lex(pm_parser_t *parser) { parser->heredoc_end = NULL; } else { parser->current.end += eol_length + 1; - pm_newline_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); space_seen = true; } } else if (pm_char_is_inline_whitespace(*parser->current.end)) { @@ -9941,7 +9941,7 @@ parser_lex(pm_parser_t *parser) { } if (parser->heredoc_end == NULL) { - pm_newline_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); } } @@ -10450,7 +10450,7 @@ parser_lex(pm_parser_t *parser) { } else { // Otherwise, we want to indicate that the body of the // heredoc starts on the character after the next newline. - pm_newline_list_append(&parser->newline_list, U32(body_start - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(body_start - parser->start + 1)); body_start++; } @@ -11091,7 +11091,7 @@ parser_lex(pm_parser_t *parser) { // correct column information for it. const uint8_t *cursor = parser->current.end; while ((cursor = next_newline(cursor, parser->end - cursor)) != NULL) { - pm_newline_list_append(&parser->newline_list, U32(++cursor - parser->start)); + pm_line_offset_list_append(&parser->newline_list, U32(++cursor - parser->start)); } parser->current.end = parser->end; @@ -11267,7 +11267,7 @@ parser_lex(pm_parser_t *parser) { LEX(PM_TOKEN_STRING_CONTENT); } else { // ... else track the newline. - pm_newline_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); + pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); } parser->current.end++; @@ -11405,7 +11405,7 @@ parser_lex(pm_parser_t *parser) { // would have already have added the newline to the // list. if (parser->heredoc_end == NULL) { - pm_newline_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); } } else { parser->current.end = breakpoint + 1; @@ -11452,7 +11452,7 @@ parser_lex(pm_parser_t *parser) { // If we've hit a newline, then we need to track that in // the list of newlines. if (parser->heredoc_end == NULL) { - pm_newline_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); parser->current.end = breakpoint + 1; breakpoint = pm_strpbrk(parser, parser->current.end, breakpoints, parser->end - parser->current.end, false); break; @@ -11500,7 +11500,7 @@ parser_lex(pm_parser_t *parser) { LEX(PM_TOKEN_STRING_CONTENT); } else { // ... else track the newline. - pm_newline_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); + pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); } parser->current.end++; @@ -11665,7 +11665,7 @@ parser_lex(pm_parser_t *parser) { // would have already have added the newline to the // list. if (parser->heredoc_end == NULL) { - pm_newline_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); } } else { parser->current.end = breakpoint + 1; @@ -11717,7 +11717,7 @@ parser_lex(pm_parser_t *parser) { // for the terminator in case the terminator is a // newline character. if (parser->heredoc_end == NULL) { - pm_newline_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); parser->current.end = breakpoint + 1; breakpoint = pm_strpbrk(parser, parser->current.end, breakpoints, parser->end - parser->current.end, true); break; @@ -11771,7 +11771,7 @@ parser_lex(pm_parser_t *parser) { LEX(PM_TOKEN_STRING_CONTENT); } else { // ... else track the newline. - pm_newline_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); + pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); } parser->current.end++; @@ -11900,7 +11900,7 @@ parser_lex(pm_parser_t *parser) { (memcmp(terminator_start, ident_start, ident_length) == 0) ) { if (newline != NULL) { - pm_newline_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); } parser->current.end = terminator_end; @@ -11972,7 +11972,7 @@ parser_lex(pm_parser_t *parser) { LEX(PM_TOKEN_STRING_CONTENT); } - pm_newline_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); // If we have a - or ~ heredoc, then we can match after // some leading whitespace. @@ -12092,7 +12092,7 @@ parser_lex(pm_parser_t *parser) { const uint8_t *end = parser->current.end; if (parser->heredoc_end == NULL) { - pm_newline_list_append(&parser->newline_list, U32(end - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(end - parser->start + 1)); } // Here we want the buffer to only @@ -13329,7 +13329,7 @@ pm_hash_key_static_literals_add(pm_parser_t *parser, pm_static_literals_t *liter PM_WARN_DUPLICATED_HASH_KEY, (int) pm_buffer_length(&buffer), pm_buffer_value(&buffer), - pm_newline_list_line_column(&parser->newline_list, PM_NODE_START(node), parser->start_line).line + pm_line_offset_list_line_column(&parser->newline_list, PM_NODE_START(node), parser->start_line).line ); pm_buffer_free(&buffer); @@ -13350,8 +13350,8 @@ pm_when_clause_static_literals_add(pm_parser_t *parser, pm_static_literals_t *li PM_NODE_START(node), PM_NODE_LENGTH(node), PM_WARN_DUPLICATED_WHEN_CLAUSE, - pm_newline_list_line_column(&parser->newline_list, PM_NODE_START(node), parser->start_line).line, - pm_newline_list_line_column(&parser->newline_list, PM_NODE_START(previous), parser->start_line).line + pm_line_offset_list_line_column(&parser->newline_list, PM_NODE_START(node), parser->start_line).line, + pm_line_offset_list_line_column(&parser->newline_list, PM_NODE_START(previous), parser->start_line).line ); } } @@ -14299,7 +14299,7 @@ token_newline_index(const pm_parser_t *parser) { // start of a heredoc, so we cannot rely on looking at the previous // offset of the newline list, and instead must go through the whole // process of a binary search for the line number. - return (size_t) pm_newline_list_line(&parser->newline_list, PM_TOKEN_START(parser, &parser->current), 0); + return (size_t) pm_line_offset_list_line(&parser->newline_list, PM_TOKEN_START(parser, &parser->current), 0); } } @@ -21990,7 +21990,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm // guess at the number of newlines that we'll need based on the size of the // input. size_t newline_size = size / 22; - pm_newline_list_init(&parser->newline_list, newline_size < 4 ? 4 : newline_size); + pm_line_offset_list_init(&parser->newline_list, newline_size < 4 ? 4 : newline_size); // If options were provided to this parse, establish them here. if (options != NULL) { @@ -22129,7 +22129,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm const uint8_t *newline = next_newline(cursor, parser->end - cursor); while (newline != NULL) { - pm_newline_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); cursor = newline + 1; newline = next_newline(cursor, parser->end - cursor); @@ -22159,7 +22159,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm parser->current = (pm_token_t) { .type = PM_TOKEN_EOF, .start = cursor, .end = cursor }; } else { pm_parser_err(parser, 0, 0, PM_ERR_SCRIPT_NOT_FOUND); - pm_newline_list_clear(&parser->newline_list); + pm_line_offset_list_clear(&parser->newline_list); } } @@ -22219,7 +22219,7 @@ pm_parser_free(pm_parser_t *parser) { pm_comment_list_free(&parser->comment_list); pm_magic_comment_list_free(&parser->magic_comment_list); pm_constant_pool_free(&parser->constant_pool); - pm_newline_list_free(&parser->newline_list); + pm_line_offset_list_free(&parser->newline_list); while (parser->current_scope != NULL) { // Normally, popping the scope doesn't free the locals since it is diff --git a/src/static_literals.c b/src/static_literals.c index e54b50c02f..64bf1740c9 100644 --- a/src/static_literals.c +++ b/src/static_literals.c @@ -95,7 +95,7 @@ node_hash(const pm_static_literals_metadata_t *metadata, const pm_node_t *node) } case PM_SOURCE_LINE_NODE: { // Source lines hash their line number. - const pm_line_column_t line_column = pm_newline_list_line_column(metadata->newline_list, node->location.start, metadata->start_line); + const pm_line_column_t line_column = pm_line_offset_list_line_column(metadata->newline_list, node->location.start, metadata->start_line); const int32_t *value = &line_column.line; return murmur_hash((const uint8_t *) value, sizeof(int32_t)); } @@ -243,7 +243,7 @@ pm_int64_value(const pm_static_literals_metadata_t *metadata, const pm_node_t *n return integer->negative ? -value : value; } case PM_SOURCE_LINE_NODE: - return (int64_t) pm_newline_list_line_column(metadata->newline_list, node->location.start, metadata->start_line).line; + return (int64_t) pm_line_offset_list_line_column(metadata->newline_list, node->location.start, metadata->start_line).line; default: assert(false && "unreachable"); return 0; @@ -585,7 +585,7 @@ pm_static_literal_inspect_node(pm_buffer_t *buffer, const pm_static_literals_met break; } case PM_SOURCE_LINE_NODE: - pm_buffer_append_format(buffer, "%d", pm_newline_list_line_column(metadata->newline_list, node->location.start, metadata->start_line).line); + pm_buffer_append_format(buffer, "%d", pm_line_offset_list_line_column(metadata->newline_list, node->location.start, metadata->start_line).line); break; case PM_STRING_NODE: { const pm_string_t *unescaped = &((const pm_string_node_t *) node)->unescaped; diff --git a/src/util/pm_char.c b/src/util/pm_char.c index 80ae63441c..1b4493ef7f 100644 --- a/src/util/pm_char.c +++ b/src/util/pm_char.c @@ -91,7 +91,7 @@ pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_line_o while (size < maximum && (pm_byte_table[string[size]] & PRISM_CHAR_BIT_WHITESPACE)) { if (string[size] == '\n') { - pm_newline_list_append(newline_list, start_offset + size + 1); + pm_line_offset_list_append(newline_list, start_offset + size + 1); } size++; diff --git a/src/util/pm_newline_list.c b/src/util/pm_newline_list.c index ad00a1db50..710fa4b788 100644 --- a/src/util/pm_newline_list.c +++ b/src/util/pm_newline_list.c @@ -5,7 +5,7 @@ * allocation of the offsets succeeds, otherwise returns false. */ bool -pm_newline_list_init(pm_line_offset_list_t *list, size_t capacity) { +pm_line_offset_list_init(pm_line_offset_list_t *list, size_t capacity) { list->offsets = (uint32_t *) xcalloc(capacity, sizeof(uint32_t)); if (list->offsets == NULL) return false; @@ -21,7 +21,7 @@ pm_newline_list_init(pm_line_offset_list_t *list, size_t capacity) { * Clear out the newlines that have been appended to the list. */ void -pm_newline_list_clear(pm_line_offset_list_t *list) { +pm_line_offset_list_clear(pm_line_offset_list_t *list) { list->size = 1; } @@ -30,7 +30,7 @@ pm_newline_list_clear(pm_line_offset_list_t *list) { * the offsets succeeds (if one was necessary), otherwise returns false. */ bool -pm_newline_list_append(pm_line_offset_list_t *list, uint32_t cursor) { +pm_line_offset_list_append(pm_line_offset_list_t *list, uint32_t cursor) { if (list->size == list->capacity) { uint32_t *original_offsets = list->offsets; @@ -53,7 +53,7 @@ pm_newline_list_append(pm_line_offset_list_t *list, uint32_t cursor) { * line of the closest offset less than the given offset is returned. */ int32_t -pm_newline_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) { +pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) { size_t left = 0; size_t right = list->size - 1; @@ -80,7 +80,7 @@ pm_newline_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t * are returned. */ pm_line_column_t -pm_newline_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) { +pm_line_offset_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) { size_t left = 0; size_t right = list->size - 1; @@ -108,6 +108,6 @@ pm_newline_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, * Free the internal memory allocated for the newline list. */ void -pm_newline_list_free(pm_line_offset_list_t *list) { +pm_line_offset_list_free(pm_line_offset_list_t *list) { xfree(list->offsets); } diff --git a/templates/src/prettyprint.c.erb b/templates/src/prettyprint.c.erb index 74c0f6dbdf..5e849f3557 100644 --- a/templates/src/prettyprint.c.erb +++ b/templates/src/prettyprint.c.erb @@ -12,8 +12,8 @@ void pm_prettyprint(void) {} static inline void prettyprint_location(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm_location_t *location) { - pm_line_column_t start = pm_newline_list_line_column(&parser->newline_list, location->start, parser->start_line); - pm_line_column_t end = pm_newline_list_line_column(&parser->newline_list, location->start + location->length, parser->start_line); + pm_line_column_t start = pm_line_offset_list_line_column(&parser->newline_list, location->start, parser->start_line); + pm_line_column_t end = pm_line_offset_list_line_column(&parser->newline_list, location->start + location->length, parser->start_line); pm_buffer_append_format(output_buffer, "(%" PRIi32 ",%" PRIu32 ")-(%" PRIi32 ",%" PRIu32 ")", start.line, start.column, end.line, end.column); } From d863f5c9c8f4ac2969c395e0ebb147cb22ebb77b Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sun, 15 Feb 2026 16:47:17 -0500 Subject: [PATCH 06/12] rename struct fields in `pm_parser_t` and `pm_static_literals_metadata_t` --- ext/prism/extension.c | 6 +-- include/prism/parser.h | 2 +- src/prism.c | 70 +++++++++++++++--------------- src/static_literals.c | 22 +++++----- templates/ext/prism/api_node.c.erb | 6 +-- templates/src/prettyprint.c.erb | 4 +- templates/src/serialize.c.erb | 2 +- 7 files changed, 56 insertions(+), 56 deletions(-) diff --git a/ext/prism/extension.c b/ext/prism/extension.c index 7a5dd8a984..9b3a66caf5 100644 --- a/ext/prism/extension.c +++ b/ext/prism/extension.c @@ -739,7 +739,7 @@ parse_lex_input(pm_string_t *input, const pm_options_t *options, bool return_nod pm_parser_register_encoding_changed_callback(&parser, parse_lex_encoding_changed_callback); VALUE source_string = rb_str_new((const char *) pm_string_source(input), pm_string_length(input)); - VALUE offsets = rb_ary_new_capa(parser.newline_list.size); + VALUE offsets = rb_ary_new_capa(parser.line_offsets.size); VALUE source = rb_funcall(rb_cPrismSource, rb_id_source_for, 3, source_string, LONG2NUM(parser.start_line), offsets); parse_lex_data_t parse_lex_data = { @@ -765,8 +765,8 @@ parse_lex_input(pm_string_t *input, const pm_options_t *options, bool return_nod rb_encoding *encoding = rb_enc_find(parser.encoding->name); rb_enc_associate(source_string, encoding); - for (size_t index = 0; index < parser.newline_list.size; index++) { - rb_ary_push(offsets, ULONG2NUM(parser.newline_list.offsets[index])); + for (size_t index = 0; index < parser.line_offsets.size; index++) { + rb_ary_push(offsets, ULONG2NUM(parser.line_offsets.offsets[index])); } if (options->freeze) { diff --git a/include/prism/parser.h b/include/prism/parser.h index 5324d3f894..aad0d985a3 100644 --- a/include/prism/parser.h +++ b/include/prism/parser.h @@ -783,7 +783,7 @@ struct pm_parser { pm_constant_pool_t constant_pool; /** This is the list of newline offsets in the source file. */ - pm_line_offset_list_t newline_list; + pm_line_offset_list_t line_offsets; /** * We want to add a flag to integer nodes that indicates their base. We only diff --git a/src/prism.c b/src/prism.c index 3b0a79fa03..c9d002b52a 100644 --- a/src/prism.c +++ b/src/prism.c @@ -1000,7 +1000,7 @@ pm_locals_order(PRISM_ATTRIBUTE_UNUSED pm_parser_t *parser, pm_locals_t *locals, if (local->name != PM_CONSTANT_ID_UNSET) { pm_constant_id_list_insert(list, (size_t) local->index, local->name); - if (warn_unused && local->reads == 0 && ((parser->start_line >= 0) || (pm_line_offset_list_line(&parser->newline_list, local->location.start, parser->start_line) >= 0))) { + if (warn_unused && local->reads == 0 && ((parser->start_line >= 0) || (pm_line_offset_list_line(&parser->line_offsets, local->location.start, parser->start_line) >= 0))) { pm_constant_t *constant = pm_constant_pool_id_to_constant(&parser->constant_pool, local->name); if (constant->length >= 1 && *constant->start != '_') { @@ -9367,7 +9367,7 @@ lex_embdoc(pm_parser_t *parser) { if (newline == NULL) { parser->current.end = parser->end; } else { - pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(newline - parser->start + 1)); parser->current.end = newline + 1; } @@ -9401,7 +9401,7 @@ lex_embdoc(pm_parser_t *parser) { if (newline == NULL) { parser->current.end = parser->end; } else { - pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(newline - parser->start + 1)); parser->current.end = newline + 1; } @@ -9421,7 +9421,7 @@ lex_embdoc(pm_parser_t *parser) { if (newline == NULL) { parser->current.end = parser->end; } else { - pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(newline - parser->start + 1)); parser->current.end = newline + 1; } @@ -9735,7 +9735,7 @@ pm_lex_percent_delimiter(pm_parser_t *parser) { parser_flush_heredoc_end(parser); } else { // Otherwise, we'll add the newline to the list of newlines. - pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + U32(eol_length)); + pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + U32(eol_length)); } uint8_t delimiter = *parser->current.end; @@ -9839,7 +9839,7 @@ parser_lex(pm_parser_t *parser) { parser->heredoc_end = NULL; } else { parser->current.end += eol_length + 1; - pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current)); space_seen = true; } } else if (pm_char_is_inline_whitespace(*parser->current.end)) { @@ -9941,7 +9941,7 @@ parser_lex(pm_parser_t *parser) { } if (parser->heredoc_end == NULL) { - pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current)); } } @@ -10450,7 +10450,7 @@ parser_lex(pm_parser_t *parser) { } else { // Otherwise, we want to indicate that the body of the // heredoc starts on the character after the next newline. - pm_line_offset_list_append(&parser->newline_list, U32(body_start - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(body_start - parser->start + 1)); body_start++; } @@ -11091,7 +11091,7 @@ parser_lex(pm_parser_t *parser) { // correct column information for it. const uint8_t *cursor = parser->current.end; while ((cursor = next_newline(cursor, parser->end - cursor)) != NULL) { - pm_line_offset_list_append(&parser->newline_list, U32(++cursor - parser->start)); + pm_line_offset_list_append(&parser->line_offsets, U32(++cursor - parser->start)); } parser->current.end = parser->end; @@ -11152,7 +11152,7 @@ parser_lex(pm_parser_t *parser) { whitespace += 1; } } else { - whitespace = pm_strspn_whitespace_newlines(parser->current.end, parser->end - parser->current.end, &parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + whitespace = pm_strspn_whitespace_newlines(parser->current.end, parser->end - parser->current.end, &parser->line_offsets, PM_TOKEN_END(parser, &parser->current)); } if (whitespace > 0) { @@ -11267,7 +11267,7 @@ parser_lex(pm_parser_t *parser) { LEX(PM_TOKEN_STRING_CONTENT); } else { // ... else track the newline. - pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); + pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1); } parser->current.end++; @@ -11405,7 +11405,7 @@ parser_lex(pm_parser_t *parser) { // would have already have added the newline to the // list. if (parser->heredoc_end == NULL) { - pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current)); } } else { parser->current.end = breakpoint + 1; @@ -11452,7 +11452,7 @@ parser_lex(pm_parser_t *parser) { // If we've hit a newline, then we need to track that in // the list of newlines. if (parser->heredoc_end == NULL) { - pm_line_offset_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(breakpoint - parser->start + 1)); parser->current.end = breakpoint + 1; breakpoint = pm_strpbrk(parser, parser->current.end, breakpoints, parser->end - parser->current.end, false); break; @@ -11500,7 +11500,7 @@ parser_lex(pm_parser_t *parser) { LEX(PM_TOKEN_STRING_CONTENT); } else { // ... else track the newline. - pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); + pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1); } parser->current.end++; @@ -11665,7 +11665,7 @@ parser_lex(pm_parser_t *parser) { // would have already have added the newline to the // list. if (parser->heredoc_end == NULL) { - pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current)); + pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current)); } } else { parser->current.end = breakpoint + 1; @@ -11717,7 +11717,7 @@ parser_lex(pm_parser_t *parser) { // for the terminator in case the terminator is a // newline character. if (parser->heredoc_end == NULL) { - pm_line_offset_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(breakpoint - parser->start + 1)); parser->current.end = breakpoint + 1; breakpoint = pm_strpbrk(parser, parser->current.end, breakpoints, parser->end - parser->current.end, true); break; @@ -11771,7 +11771,7 @@ parser_lex(pm_parser_t *parser) { LEX(PM_TOKEN_STRING_CONTENT); } else { // ... else track the newline. - pm_line_offset_list_append(&parser->newline_list, PM_TOKEN_END(parser, &parser->current) + 1); + pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1); } parser->current.end++; @@ -11900,7 +11900,7 @@ parser_lex(pm_parser_t *parser) { (memcmp(terminator_start, ident_start, ident_length) == 0) ) { if (newline != NULL) { - pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(newline - parser->start + 1)); } parser->current.end = terminator_end; @@ -11972,7 +11972,7 @@ parser_lex(pm_parser_t *parser) { LEX(PM_TOKEN_STRING_CONTENT); } - pm_line_offset_list_append(&parser->newline_list, U32(breakpoint - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(breakpoint - parser->start + 1)); // If we have a - or ~ heredoc, then we can match after // some leading whitespace. @@ -12092,7 +12092,7 @@ parser_lex(pm_parser_t *parser) { const uint8_t *end = parser->current.end; if (parser->heredoc_end == NULL) { - pm_line_offset_list_append(&parser->newline_list, U32(end - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(end - parser->start + 1)); } // Here we want the buffer to only @@ -13316,11 +13316,11 @@ parse_statements(pm_parser_t *parser, pm_context_t context, uint16_t depth) { */ static void pm_hash_key_static_literals_add(pm_parser_t *parser, pm_static_literals_t *literals, pm_node_t *node) { - const pm_node_t *duplicated = pm_static_literals_add(&parser->newline_list, parser->start, parser->start_line, literals, node, true); + const pm_node_t *duplicated = pm_static_literals_add(&parser->line_offsets, parser->start, parser->start_line, literals, node, true); if (duplicated != NULL) { pm_buffer_t buffer = { 0 }; - pm_static_literal_inspect(&buffer, &parser->newline_list, parser->start, parser->start_line, parser->encoding->name, duplicated); + pm_static_literal_inspect(&buffer, &parser->line_offsets, parser->start, parser->start_line, parser->encoding->name, duplicated); pm_diagnostic_list_append_format( &parser->warning_list, @@ -13329,7 +13329,7 @@ pm_hash_key_static_literals_add(pm_parser_t *parser, pm_static_literals_t *liter PM_WARN_DUPLICATED_HASH_KEY, (int) pm_buffer_length(&buffer), pm_buffer_value(&buffer), - pm_line_offset_list_line_column(&parser->newline_list, PM_NODE_START(node), parser->start_line).line + pm_line_offset_list_line_column(&parser->line_offsets, PM_NODE_START(node), parser->start_line).line ); pm_buffer_free(&buffer); @@ -13344,14 +13344,14 @@ static void pm_when_clause_static_literals_add(pm_parser_t *parser, pm_static_literals_t *literals, pm_node_t *node) { pm_node_t *previous; - if ((previous = pm_static_literals_add(&parser->newline_list, parser->start, parser->start_line, literals, node, false)) != NULL) { + if ((previous = pm_static_literals_add(&parser->line_offsets, parser->start, parser->start_line, literals, node, false)) != NULL) { pm_diagnostic_list_append_format( &parser->warning_list, PM_NODE_START(node), PM_NODE_LENGTH(node), PM_WARN_DUPLICATED_WHEN_CLAUSE, - pm_line_offset_list_line_column(&parser->newline_list, PM_NODE_START(node), parser->start_line).line, - pm_line_offset_list_line_column(&parser->newline_list, PM_NODE_START(previous), parser->start_line).line + pm_line_offset_list_line_column(&parser->line_offsets, PM_NODE_START(node), parser->start_line).line, + pm_line_offset_list_line_column(&parser->line_offsets, PM_NODE_START(previous), parser->start_line).line ); } } @@ -14293,13 +14293,13 @@ token_newline_index(const pm_parser_t *parser) { // This is the common case. In this case we can look at the previously // recorded newline in the newline list and subtract from the current // offset. - return parser->newline_list.size - 1; + return parser->line_offsets.size - 1; } else { // This is unlikely. This is the case that we have already parsed the // start of a heredoc, so we cannot rely on looking at the previous // offset of the newline list, and instead must go through the whole // process of a binary search for the line number. - return (size_t) pm_line_offset_list_line(&parser->newline_list, PM_TOKEN_START(parser, &parser->current), 0); + return (size_t) pm_line_offset_list_line(&parser->line_offsets, PM_TOKEN_START(parser, &parser->current), 0); } } @@ -14309,7 +14309,7 @@ token_newline_index(const pm_parser_t *parser) { */ static int64_t token_column(const pm_parser_t *parser, size_t newline_index, const pm_token_t *token, bool break_on_non_space) { - const uint8_t *cursor = parser->start + parser->newline_list.offsets[newline_index]; + const uint8_t *cursor = parser->start + parser->line_offsets.offsets[newline_index]; const uint8_t *end = token->start; // Skip over the BOM if it is present. @@ -16458,7 +16458,7 @@ parse_pattern_hash_implicit_value(pm_parser_t *parser, pm_constant_id_list_t *ca */ static void parse_pattern_hash_key(pm_parser_t *parser, pm_static_literals_t *keys, pm_node_t *node) { - if (pm_static_literals_add(&parser->newline_list, parser->start, parser->start_line, keys, node, true) != NULL) { + if (pm_static_literals_add(&parser->line_offsets, parser->start, parser->start_line, keys, node, true) != NULL) { pm_parser_err_node(parser, node, PM_ERR_PATTERN_HASH_KEY_DUPLICATE); } } @@ -21948,7 +21948,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm .lex_callback = NULL, .filepath = { 0 }, .constant_pool = { 0 }, - .newline_list = { 0 }, + .line_offsets = { 0 }, .integer_base = 0, .current_string = PM_STRING_EMPTY, .start_line = 1, @@ -21990,7 +21990,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm // guess at the number of newlines that we'll need based on the size of the // input. size_t newline_size = size / 22; - pm_line_offset_list_init(&parser->newline_list, newline_size < 4 ? 4 : newline_size); + pm_line_offset_list_init(&parser->line_offsets, newline_size < 4 ? 4 : newline_size); // If options were provided to this parse, establish them here. if (options != NULL) { @@ -22129,7 +22129,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm const uint8_t *newline = next_newline(cursor, parser->end - cursor); while (newline != NULL) { - pm_line_offset_list_append(&parser->newline_list, U32(newline - parser->start + 1)); + pm_line_offset_list_append(&parser->line_offsets, U32(newline - parser->start + 1)); cursor = newline + 1; newline = next_newline(cursor, parser->end - cursor); @@ -22159,7 +22159,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm parser->current = (pm_token_t) { .type = PM_TOKEN_EOF, .start = cursor, .end = cursor }; } else { pm_parser_err(parser, 0, 0, PM_ERR_SCRIPT_NOT_FOUND); - pm_line_offset_list_clear(&parser->newline_list); + pm_line_offset_list_clear(&parser->line_offsets); } } @@ -22219,7 +22219,7 @@ pm_parser_free(pm_parser_t *parser) { pm_comment_list_free(&parser->comment_list); pm_magic_comment_list_free(&parser->magic_comment_list); pm_constant_pool_free(&parser->constant_pool); - pm_line_offset_list_free(&parser->newline_list); + pm_line_offset_list_free(&parser->line_offsets); while (parser->current_scope != NULL) { // Normally, popping the scope doesn't free the locals since it is diff --git a/src/static_literals.c b/src/static_literals.c index 64bf1740c9..ef2d2436a9 100644 --- a/src/static_literals.c +++ b/src/static_literals.c @@ -7,7 +7,7 @@ */ typedef struct { /** The list of newline offsets to use to calculate line numbers. */ - const pm_line_offset_list_t *newline_list; + const pm_line_offset_list_t *line_offsets; /** The start of the source being parsed. */ const uint8_t *start; @@ -95,7 +95,7 @@ node_hash(const pm_static_literals_metadata_t *metadata, const pm_node_t *node) } case PM_SOURCE_LINE_NODE: { // Source lines hash their line number. - const pm_line_column_t line_column = pm_line_offset_list_line_column(metadata->newline_list, node->location.start, metadata->start_line); + const pm_line_column_t line_column = pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line); const int32_t *value = &line_column.line; return murmur_hash((const uint8_t *) value, sizeof(int32_t)); } @@ -243,7 +243,7 @@ pm_int64_value(const pm_static_literals_metadata_t *metadata, const pm_node_t *n return integer->negative ? -value : value; } case PM_SOURCE_LINE_NODE: - return (int64_t) pm_line_offset_list_line_column(metadata->newline_list, node->location.start, metadata->start_line).line; + return (int64_t) pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line).line; default: assert(false && "unreachable"); return 0; @@ -363,7 +363,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->integer_nodes, &(pm_static_literals_metadata_t) { - .newline_list = newline_list, + .line_offsets = newline_list, .start = start, .start_line = start_line, .encoding_name = NULL @@ -376,7 +376,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->float_nodes, &(pm_static_literals_metadata_t) { - .newline_list = newline_list, + .line_offsets = newline_list, .start = start, .start_line = start_line, .encoding_name = NULL @@ -390,7 +390,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->number_nodes, &(pm_static_literals_metadata_t) { - .newline_list = newline_list, + .line_offsets = newline_list, .start = start, .start_line = start_line, .encoding_name = NULL @@ -404,7 +404,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->string_nodes, &(pm_static_literals_metadata_t) { - .newline_list = newline_list, + .line_offsets = newline_list, .start = start, .start_line = start_line, .encoding_name = NULL @@ -417,7 +417,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->regexp_nodes, &(pm_static_literals_metadata_t) { - .newline_list = newline_list, + .line_offsets = newline_list, .start = start, .start_line = start_line, .encoding_name = NULL @@ -430,7 +430,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->symbol_nodes, &(pm_static_literals_metadata_t) { - .newline_list = newline_list, + .line_offsets = newline_list, .start = start, .start_line = start_line, .encoding_name = NULL @@ -585,7 +585,7 @@ pm_static_literal_inspect_node(pm_buffer_t *buffer, const pm_static_literals_met break; } case PM_SOURCE_LINE_NODE: - pm_buffer_append_format(buffer, "%d", pm_line_offset_list_line_column(metadata->newline_list, node->location.start, metadata->start_line).line); + pm_buffer_append_format(buffer, "%d", pm_line_offset_list_line_column(metadata->line_offsets, node->location.start, metadata->start_line).line); break; case PM_STRING_NODE: { const pm_string_t *unescaped = &((const pm_string_node_t *) node)->unescaped; @@ -617,7 +617,7 @@ pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *newl pm_static_literal_inspect_node( buffer, &(pm_static_literals_metadata_t) { - .newline_list = newline_list, + .line_offsets = newline_list, .start = start, .start_line = start_line, .encoding_name = encoding_name diff --git a/templates/ext/prism/api_node.c.erb b/templates/ext/prism/api_node.c.erb index e9c3742085..69f70240f8 100644 --- a/templates/ext/prism/api_node.c.erb +++ b/templates/ext/prism/api_node.c.erb @@ -76,9 +76,9 @@ VALUE pm_source_new(const pm_parser_t *parser, rb_encoding *encoding, bool freeze) { VALUE source_string = rb_enc_str_new((const char *) parser->start, parser->end - parser->start, encoding); - VALUE offsets = rb_ary_new_capa(parser->newline_list.size); - for (size_t index = 0; index < parser->newline_list.size; index++) { - rb_ary_push(offsets, ULONG2NUM(parser->newline_list.offsets[index])); + VALUE offsets = rb_ary_new_capa(parser->line_offsets.size); + for (size_t index = 0; index < parser->line_offsets.size; index++) { + rb_ary_push(offsets, ULONG2NUM(parser->line_offsets.offsets[index])); } if (freeze) { diff --git a/templates/src/prettyprint.c.erb b/templates/src/prettyprint.c.erb index 5e849f3557..44423ca42b 100644 --- a/templates/src/prettyprint.c.erb +++ b/templates/src/prettyprint.c.erb @@ -12,8 +12,8 @@ void pm_prettyprint(void) {} static inline void prettyprint_location(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm_location_t *location) { - pm_line_column_t start = pm_line_offset_list_line_column(&parser->newline_list, location->start, parser->start_line); - pm_line_column_t end = pm_line_offset_list_line_column(&parser->newline_list, location->start + location->length, parser->start_line); + pm_line_column_t start = pm_line_offset_list_line_column(&parser->line_offsets, location->start, parser->start_line); + pm_line_column_t end = pm_line_offset_list_line_column(&parser->line_offsets, location->start + location->length, parser->start_line); pm_buffer_append_format(output_buffer, "(%" PRIi32 ",%" PRIu32 ")-(%" PRIi32 ",%" PRIu32 ")", start.line, start.column, end.line, end.column); } diff --git a/templates/src/serialize.c.erb b/templates/src/serialize.c.erb index b9dde28786..33389345a8 100644 --- a/templates/src/serialize.c.erb +++ b/templates/src/serialize.c.erb @@ -257,7 +257,7 @@ static void pm_serialize_metadata(pm_parser_t *parser, pm_buffer_t *buffer) { pm_serialize_encoding(parser->encoding, buffer); pm_buffer_append_varsint(buffer, parser->start_line); - pm_serialize_newline_list(&parser->newline_list, buffer); + pm_serialize_newline_list(&parser->line_offsets, buffer); <%- unless Prism::Template::SERIALIZE_ONLY_SEMANTICS_FIELDS -%> pm_serialize_comment_list(&parser->comment_list, buffer); <%- end -%> From 5717054258f77fb81bd783cc6f92a1ae5476d2d6 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sun, 15 Feb 2026 16:48:40 -0500 Subject: [PATCH 07/12] rename function parameters in `static_literals.c` --- src/static_literals.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/static_literals.c b/src/static_literals.c index ef2d2436a9..58a08a8c03 100644 --- a/src/static_literals.c +++ b/src/static_literals.c @@ -356,14 +356,14 @@ pm_compare_regular_expression_nodes(PRISM_ATTRIBUTE_UNUSED const pm_static_liter * Add a node to the set of static literals. */ pm_node_t * -pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace) { +pm_static_literals_add(const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace) { switch (PM_NODE_TYPE(node)) { case PM_INTEGER_NODE: case PM_SOURCE_LINE_NODE: return pm_node_hash_insert( &literals->integer_nodes, &(pm_static_literals_metadata_t) { - .line_offsets = newline_list, + .line_offsets = line_offsets, .start = start, .start_line = start_line, .encoding_name = NULL @@ -376,7 +376,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->float_nodes, &(pm_static_literals_metadata_t) { - .line_offsets = newline_list, + .line_offsets = line_offsets, .start = start, .start_line = start_line, .encoding_name = NULL @@ -390,7 +390,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->number_nodes, &(pm_static_literals_metadata_t) { - .line_offsets = newline_list, + .line_offsets = line_offsets, .start = start, .start_line = start_line, .encoding_name = NULL @@ -404,7 +404,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->string_nodes, &(pm_static_literals_metadata_t) { - .line_offsets = newline_list, + .line_offsets = line_offsets, .start = start, .start_line = start_line, .encoding_name = NULL @@ -417,7 +417,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->regexp_nodes, &(pm_static_literals_metadata_t) { - .line_offsets = newline_list, + .line_offsets = line_offsets, .start = start, .start_line = start_line, .encoding_name = NULL @@ -430,7 +430,7 @@ pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t return pm_node_hash_insert( &literals->symbol_nodes, &(pm_static_literals_metadata_t) { - .line_offsets = newline_list, + .line_offsets = line_offsets, .start = start, .start_line = start_line, .encoding_name = NULL @@ -613,11 +613,11 @@ pm_static_literal_inspect_node(pm_buffer_t *buffer, const pm_static_literals_met * Create a string-based representation of the given static literal. */ void -pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *newline_list, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node) { +pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node) { pm_static_literal_inspect_node( buffer, &(pm_static_literals_metadata_t) { - .line_offsets = newline_list, + .line_offsets = line_offsets, .start = start, .start_line = start_line, .encoding_name = encoding_name From b19020366c0886b1971ddbc9199c69a3c09e279b Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sun, 15 Feb 2026 16:50:49 -0500 Subject: [PATCH 08/12] rename function parameters and docs --- include/prism/static_literals.h | 8 ++++---- include/prism/util/pm_char.h | 4 ++-- src/util/pm_char.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/prism/static_literals.h b/include/prism/static_literals.h index a8a185c145..6d73e5d04f 100644 --- a/include/prism/static_literals.h +++ b/include/prism/static_literals.h @@ -91,7 +91,7 @@ typedef struct { /** * Add a node to the set of static literals. * - * @param newline_list The list of newline offsets to use to calculate lines. + * @param line_offsets The list of newline offsets to use to calculate lines. * @param start The start of the source being parsed. * @param start_line The line number that the parser starts on. * @param literals The set of static literals to add the node to. @@ -99,7 +99,7 @@ typedef struct { * @param replace Whether to replace the previous node if one already exists. * @return A pointer to the node that is being overwritten, if there is one. */ -pm_node_t * pm_static_literals_add(const pm_line_offset_list_t *newline_list, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace); +pm_node_t * pm_static_literals_add(const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, pm_static_literals_t *literals, pm_node_t *node, bool replace); /** * Free the internal memory associated with the given static literals set. @@ -112,12 +112,12 @@ void pm_static_literals_free(pm_static_literals_t *literals); * Create a string-based representation of the given static literal. * * @param buffer The buffer to write the string to. - * @param newline_list The list of newline offsets to use to calculate lines. + * @param line_offsets The list of newline offsets to use to calculate lines. * @param start The start of the source being parsed. * @param start_line The line number that the parser starts on. * @param encoding_name The name of the encoding of the source being parsed. * @param node The node to create a string representation of. */ -void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *newline_list, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node); +void pm_static_literal_inspect(pm_buffer_t *buffer, const pm_line_offset_list_t *line_offsets, const uint8_t *start, int32_t start_line, const char *encoding_name, const pm_node_t *node); #endif diff --git a/include/prism/util/pm_char.h b/include/prism/util/pm_char.h index 2800c448cf..ab1f513a66 100644 --- a/include/prism/util/pm_char.h +++ b/include/prism/util/pm_char.h @@ -30,13 +30,13 @@ size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length); * * @param string The string to search. * @param length The maximum number of characters to search. - * @param newline_list The list of newlines to populate. + * @param line_offsets The list of newlines to populate. * @param start_offset The offset at which the string occurs in the source, for * the purpose of tracking newlines. * @return The number of characters at the start of the string that are * whitespace. */ -size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_line_offset_list_t *newline_list, uint32_t start_offset); +size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_line_offset_list_t *line_offsets, uint32_t start_offset); /** * Returns the number of characters at the start of the string that are inline diff --git a/src/util/pm_char.c b/src/util/pm_char.c index 1b4493ef7f..f0baf47784 100644 --- a/src/util/pm_char.c +++ b/src/util/pm_char.c @@ -83,7 +83,7 @@ pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length) { * searching past the given maximum number of characters. */ size_t -pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_line_offset_list_t *newline_list, uint32_t start_offset) { +pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_line_offset_list_t *line_offsets, uint32_t start_offset) { if (length <= 0) return 0; uint32_t size = 0; @@ -91,7 +91,7 @@ pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_line_o while (size < maximum && (pm_byte_table[string[size]] & PRISM_CHAR_BIT_WHITESPACE)) { if (string[size] == '\n') { - pm_line_offset_list_append(newline_list, start_offset + size + 1); + pm_line_offset_list_append(line_offsets, start_offset + size + 1); } size++; From 5337f97b895c2f99e6eefb4fe02f865c8be34746 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sun, 15 Feb 2026 16:51:00 -0500 Subject: [PATCH 09/12] rename in serialization code --- templates/src/serialize.c.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/src/serialize.c.erb b/templates/src/serialize.c.erb index 33389345a8..54a499d8bb 100644 --- a/templates/src/serialize.c.erb +++ b/templates/src/serialize.c.erb @@ -154,7 +154,7 @@ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) { } static void -pm_serialize_newline_list(pm_line_offset_list_t *list, pm_buffer_t *buffer) { +pm_serialize_line_offset_list(pm_line_offset_list_t *list, pm_buffer_t *buffer) { uint32_t size = pm_sizet_to_u32(list->size); pm_buffer_append_varuint(buffer, size); @@ -257,7 +257,7 @@ static void pm_serialize_metadata(pm_parser_t *parser, pm_buffer_t *buffer) { pm_serialize_encoding(parser->encoding, buffer); pm_buffer_append_varsint(buffer, parser->start_line); - pm_serialize_newline_list(&parser->line_offsets, 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); <%- end -%> From 8fc63ee2611e21c81f1b2e51b86325071a692fe0 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sun, 15 Feb 2026 16:53:45 -0500 Subject: [PATCH 10/12] fixup docs for the list header itself --- include/prism/util/pm_line_offset_list.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/prism/util/pm_line_offset_list.h b/include/prism/util/pm_line_offset_list.h index 00176bc0d8..fe16e0b034 100644 --- a/include/prism/util/pm_line_offset_list.h +++ b/include/prism/util/pm_line_offset_list.h @@ -22,8 +22,8 @@ #include /** - * A list of offsets of newlines in a string. The offsets are assumed to be - * sorted/inserted in ascending order. + * A list of offsets of the start of lines in a string. The offsets are assumed + * to be sorted/inserted in ascending order. */ typedef struct { /** The number of offsets in the list. */ @@ -48,8 +48,8 @@ typedef struct { } pm_line_column_t; /** - * Initialize a new newline list with the given capacity. Returns true if the - * allocation of the offsets succeeds, otherwise returns false. + * Initialize a new line offset list with the given capacity. Returns true if + * the allocation of the offsets succeeds, otherwise returns false. * * @param list The list to initialize. * @param capacity The initial capacity of the list. @@ -58,15 +58,15 @@ typedef struct { bool pm_line_offset_list_init(pm_line_offset_list_t *list, size_t capacity); /** - * Clear out the newlines that have been appended to the list. + * Clear out the offsets that have been appended to the list. * * @param list The list to clear. */ void pm_line_offset_list_clear(pm_line_offset_list_t *list); /** - * Append a new offset to the newline list. Returns true if the reallocation of - * the offsets succeeds (if one was necessary), otherwise returns false. + * Append a new offset to the list. Returns true if the reallocation of the + * offsets succeeds (if one was necessary), otherwise returns false. * * @param list The list to append to. * @param cursor The offset to append. @@ -99,7 +99,7 @@ int32_t pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cur pm_line_column_t pm_line_offset_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line); /** - * Free the internal memory allocated for the newline list. + * Free the internal memory allocated for the list. * * @param list The list to free. */ From d5ef71b403e27cd33c9324fb9ce230088dfab3e5 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sun, 15 Feb 2026 16:54:10 -0500 Subject: [PATCH 11/12] fixup docs in `parser.h` --- include/prism/parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/prism/parser.h b/include/prism/parser.h index aad0d985a3..b4e3038439 100644 --- a/include/prism/parser.h +++ b/include/prism/parser.h @@ -782,7 +782,7 @@ struct pm_parser { */ pm_constant_pool_t constant_pool; - /** This is the list of newline offsets in the source file. */ + /** This is the list of line offsets in the source file. */ pm_line_offset_list_t line_offsets; /** From 92bfa49da784f98c84e1e7daabae050ff979b40a Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Sun, 15 Feb 2026 16:56:10 -0500 Subject: [PATCH 12/12] rename `pm_newline_list.c` --- prism.gemspec | 2 +- src/util/{pm_newline_list.c => pm_line_offset_list.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/util/{pm_newline_list.c => pm_line_offset_list.c} (100%) diff --git a/prism.gemspec b/prism.gemspec index c8fb2e0a0d..d7f31716ce 100644 --- a/prism.gemspec +++ b/prism.gemspec @@ -154,7 +154,7 @@ Gem::Specification.new do |spec| "src/util/pm_integer.c", "src/util/pm_list.c", "src/util/pm_memchr.c", - "src/util/pm_newline_list.c", + "src/util/pm_line_offset_list.c", "src/util/pm_string.c", "src/util/pm_strncasecmp.c", "src/util/pm_strpbrk.c" diff --git a/src/util/pm_newline_list.c b/src/util/pm_line_offset_list.c similarity index 100% rename from src/util/pm_newline_list.c rename to src/util/pm_line_offset_list.c