Ruby 4.1.0dev (2026-02-17 revision 4f5805fd61974bf654164e205d24b6091d6ba89b)
pm_newline_list.h
Go to the documentation of this file.
1
14#ifndef PRISM_NEWLINE_LIST_H
15#define PRISM_NEWLINE_LIST_H
16
17#include "prism/defines.h"
18
19#include <assert.h>
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdlib.h>
23
28typedef struct {
30 size_t size;
31
33 size_t capacity;
34
36 uint32_t *offsets;
38
42typedef struct {
44 int32_t line;
45
47 uint32_t column;
49
58bool pm_newline_list_init(pm_newline_list_t *list, size_t capacity);
59
66
76bool pm_newline_list_append(pm_newline_list_t *list, uint32_t cursor);
77
87int32_t pm_newline_list_line(const pm_newline_list_t *list, uint32_t cursor, int32_t start_line);
88
99pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, uint32_t cursor, int32_t start_line);
100
107
108#endif
pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, uint32_t cursor, int32_t start_line)
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.
int32_t pm_newline_list_line(const pm_newline_list_t *list, uint32_t cursor, int32_t start_line)
Returns the line of the given offset.
bool pm_newline_list_init(pm_newline_list_t *list, size_t capacity)
Initialize a new newline list with the given capacity.
bool pm_newline_list_append(pm_newline_list_t *list, uint32_t cursor)
Append a new offset to the newline list.
void pm_newline_list_clear(pm_newline_list_t *list)
Clear out the newlines that have been appended to the list.
Macro definitions used throughout the prism library.
C99 shim for <stdbool.h>
A line and column in a string.
uint32_t column
The column in bytes.
int32_t line
The line number.
A list of offsets of newlines in a string.
uint32_t * offsets
The list of offsets.
size_t capacity
The capacity of the list that has been allocated.
size_t size
The number of offsets in the list.