Prism Ruby parser
Loading...
Searching...
No Matches
Data Structures | Functions
line_offset_list.h File Reference

A list of byte offsets of newlines in a string. More...

#include "prism/compiler/exported.h"
#include "prism/compiler/nonnull.h"
#include <stddef.h>
#include <stdint.h>
Include dependency graph for line_offset_list.h:
This graph shows which files directly or indirectly include this file:

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

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) PRISM_NONNULL(1)
 Returns the line and column of the given offset.
 

Detailed Description

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.

Function Documentation

◆ pm_line_offset_list_line_column()

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.

Parameters
listThe list to search.
cursorThe offset to search for.
start_lineThe line to start counting from.
Returns
The line and column of the given offset.