Prism Ruby parser
Loading...
Searching...
No Matches
pm_line_offset_list.h
Go to the documentation of this file.
1
14#ifndef PRISM_LINE_OFFSET_LIST_H
15#define PRISM_LINE_OFFSET_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_line_offset_list_init(pm_line_offset_list_t *list, size_t capacity);
59
66
76bool pm_line_offset_list_append(pm_line_offset_list_t *list, uint32_t cursor);
77
87int32_t pm_line_offset_list_line(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line);
88
99pm_line_column_t pm_line_offset_list_line_column(const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line);
100
107
108#endif
Macro definitions used throughout the prism library.
void pm_line_offset_list_clear(pm_line_offset_list_t *list)
Clear out the offsets that have been appended to the list.
Definition pm_line_offset_list.c:24
void pm_line_offset_list_free(pm_line_offset_list_t *list)
Free the internal memory allocated for the list.
Definition pm_line_offset_list.c:111
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.
Definition pm_line_offset_list.c:56
bool pm_line_offset_list_init(pm_line_offset_list_t *list, size_t capacity)
Initialize a new line offset list with the given capacity.
Definition pm_line_offset_list.c:8
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.
Definition pm_line_offset_list.c:83
bool pm_line_offset_list_append(pm_line_offset_list_t *list, uint32_t cursor)
Append a new offset to the list.
Definition pm_line_offset_list.c:33
A line and column in a string.
Definition pm_line_offset_list.h:42
uint32_t column
The column in bytes.
Definition pm_line_offset_list.h:47
int32_t line
The line number.
Definition pm_line_offset_list.h:44
A list of offsets of the start of lines in a string.
Definition pm_line_offset_list.h:28
uint32_t * offsets
The list of offsets.
Definition pm_line_offset_list.h:36
size_t size
The number of offsets in the list.
Definition pm_line_offset_list.h:30
size_t capacity
The capacity of the list that has been allocated.
Definition pm_line_offset_list.h:33