|
Ruby 4.1.0dev (2026-03-20 revision eb04ab9117336f2b3613244cfe8a528c52faf6d6)
|
A list of byte offsets of newlines in a string. More...
#include "prism/defines.h"#include "prism/util/pm_arena.h"#include <assert.h>#include <stdbool.h>#include <stddef.h>#include <stdlib.h>

Go to the source code of this file.
Data Structures | |
| struct | pm_line_offset_list_t |
| A list of offsets of the start of lines in a string. More... | |
| struct | pm_line_column_t |
| A line and column in a string. More... | |
Functions | |
| void | pm_line_offset_list_init (pm_arena_t *arena, pm_line_offset_list_t *list, size_t capacity) |
| Initialize a new line offset list with the given capacity. | |
| void | pm_line_offset_list_clear (pm_line_offset_list_t *list) |
| Clear out the offsets that have been appended to the list. | |
| void | pm_line_offset_list_append_slow (pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor) |
| Append a new offset to the list (slow path with resize). | |
| static PRISM_FORCE_INLINE void | pm_line_offset_list_append (pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor) |
| Append a new offset to the list. | |
| int32_t | pm_line_offset_list_line (const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) |
| Returns the line of the given offset. | |
| PRISM_EXPORTED_FUNCTION pm_line_column_t | pm_line_offset_list_line_column (const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line) |
| Returns the line and column of the given offset. | |
A list of byte offsets of newlines in a string.
When compiling the syntax tree, it's necessary to know the line and column of many nodes. This is necessary to support things like error messages, tracepoints, etc.
It's possible that we could store the start line, start column, end line, and end column on every node in addition to the offsets that we already store, but that would be quite a lot of memory overhead.
Definition in file pm_line_offset_list.h.
|
static |
Append a new offset to the list.
| arena | The arena to allocate from. |
| list | The list to append to. |
| cursor | The offset to append. |
Definition at line 84 of file pm_line_offset_list.h.
Referenced by pm_parser::pm_parser_init(), and pm_strspn_whitespace_newlines().
| void pm_line_offset_list_append_slow | ( | pm_arena_t * | arena, |
| pm_line_offset_list_t * | list, | ||
| uint32_t | cursor | ||
| ) |
Append a new offset to the list (slow path with resize).
| arena | The arena to allocate from. |
| list | The list to append to. |
| cursor | The offset to append. |
Append a new offset to the list (slow path with resize).
Definition at line 28 of file pm_line_offset_list.c.
Referenced by pm_line_offset_list_append().
| void pm_line_offset_list_clear | ( | pm_line_offset_list_t * | list | ) |
Clear out the offsets that have been appended to the list.
| list | The list to clear. |
Clear out the offsets that have been appended to the list.
Definition at line 20 of file pm_line_offset_list.c.
| void pm_line_offset_list_init | ( | pm_arena_t * | arena, |
| pm_line_offset_list_t * | list, | ||
| size_t | capacity | ||
| ) |
Initialize a new line offset list with the given capacity.
| arena | The arena to allocate from. |
| list | The list to initialize. |
| capacity | The initial capacity of the list. |
Definition at line 7 of file pm_line_offset_list.c.
| int32_t pm_line_offset_list_line | ( | const pm_line_offset_list_t * | list, |
| uint32_t | cursor, | ||
| int32_t | start_line | ||
| ) |
Returns the line of the given offset.
If the offset is not in the list, the line of the closest offset less than the given offset is returned.
| list | The list to search. |
| cursor | The offset to search for. |
| start_line | The line to start counting from. |
If the offset is not in the list, the line of the closest offset less than the given offset is returned.
Definition at line 46 of file pm_line_offset_list.c.
| PRISM_EXPORTED_FUNCTION pm_line_column_t pm_line_offset_list_line_column | ( | 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 list, the line and column of the closest offset less than the given offset are returned.
| list | The list to search. |
| cursor | The offset to search for. |
| start_line | The line to start counting from. |
If the offset is not in the list, the line and column of the closest offset less than the given offset are returned.
Definition at line 73 of file pm_line_offset_list.c.