Ruby 3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0)
|
A list of byte offsets of newlines in a string. More...
#include "prism/defines.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_newline_list_t |
A list of offsets of newlines in a string. More... | |
struct | pm_line_column_t |
A line and column in a string. More... | |
Functions | |
bool | pm_newline_list_init (pm_newline_list_t *list, const uint8_t *start, size_t capacity) |
Initialize a new newline list with the given capacity. | |
bool | pm_newline_list_append (pm_newline_list_t *list, const uint8_t *cursor) |
Append a new offset to the newline list. | |
bool | pm_newline_list_check_append (pm_newline_list_t *list, const uint8_t *cursor) |
Conditionally append a new offset to the newline list, if the value passed in is a newline. | |
pm_line_column_t | pm_newline_list_line_column (const pm_newline_list_t *list, const uint8_t *cursor) |
Returns the line and column of the given offset. | |
void | pm_newline_list_free (pm_newline_list_t *list) |
Free the internal memory allocated for the newline list. | |
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_newline_list.h.
bool pm_newline_list_append | ( | pm_newline_list_t * | list, |
const uint8_t * | cursor ) |
Append a new offset to the newline list.
Returns true if the reallocation of the offsets succeeds (if one was necessary), otherwise returns false.
list | The list to append to. |
cursor | A pointer to the offset to append. |
Returns true if the reallocation of the offsets succeeds (if one was necessary), otherwise returns false.
Definition at line 27 of file pm_newline_list.c.
bool pm_newline_list_check_append | ( | pm_newline_list_t * | list, |
const uint8_t * | cursor ) |
Conditionally append a new offset to the newline list, if the value passed in is a newline.
list | The list to append to. |
cursor | A pointer to the offset to append. |
Definition at line 53 of file pm_newline_list.c.
void pm_newline_list_free | ( | pm_newline_list_t * | list | ) |
Free the internal memory allocated for the newline list.
list | The list to free. |
Definition at line 94 of file pm_newline_list.c.
bool pm_newline_list_init | ( | pm_newline_list_t * | list, |
const uint8_t * | start, | ||
size_t | capacity ) |
Initialize a new newline list with the given capacity.
Returns true if the allocation of the offsets succeeds, otherwise returns false.
list | The list to initialize. |
start | A pointer to the start of the source string. |
capacity | The initial capacity of the list. |
Returns true if the allocation of the offsets succeeds, otherwise returns false.
Definition at line 8 of file pm_newline_list.c.
pm_line_column_t pm_newline_list_line_column | ( | const pm_newline_list_t * | list, |
const uint8_t * | cursor ) |
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 | A pointer to the offset to search for. |
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 66 of file pm_newline_list.c.