Ruby 4.1.0dev (2026-11-24 revision 1d9227aada79d3927eabc4be639594f1efae4d00)
errors_format.c
2
3#include "prism/internal/allocator.h"
4#include "prism/internal/assert.h"
5#include "prism/internal/buffer.h"
6#include "prism/internal/diagnostic.h"
7#include "prism/internal/encoding.h"
8#include "prism/internal/line_offset_list.h"
9#include "prism/internal/oom.h"
10#include "prism/internal/parser.h"
11
12#include <stdbool.h>
13#include <stdint.h>
14#include <stdlib.h>
15#include <string.h>
16
22static bool
23lines_are_utf8(const pm_parser_t *parser, size_t start_index, size_t end_index) {
24 const pm_line_offset_list_t *line_offsets = &parser->line_offsets;
25 const uint8_t *cursor = parser->start + line_offsets->offsets[start_index];
26 const uint8_t *end = (end_index + 1 == line_offsets->size) ? parser->end : (parser->start + line_offsets->offsets[end_index + 1]);
27
28 while (cursor < end) {
29 size_t width = pm_encoding_utf_8_char_width(cursor, end - cursor);
30 if (width == 0) return false;
31
32 cursor += width;
33 }
34
35 return true;
36}
37
38typedef struct {
39 pm_diagnostic_t *diagnostic;
40 /* Zero-based line indices preserve source order across line-number wraparound. */
41 uint32_t line_index;
42 uint32_t column_start;
43 uint32_t column_end;
45
50static uint32_t
51pm_rich_errors_final_line(const pm_parser_t *parser) {
52 const pm_line_offset_list_t *line_offsets = &parser->line_offsets;
53 uint32_t final_line = (uint32_t) (line_offsets->size - 1);
54
55 if (final_line > 0 && (parser->start + line_offsets->offsets[final_line]) == parser->end) {
56 final_line--;
57 }
58
59 return final_line;
60}
61
68static void
69pm_rich_error_context(uint32_t line, uint32_t final_line, uint32_t *first, uint32_t *last) {
70 *first = (line > 2) ? (line - 2) : 0;
71 *last = (final_line > line && final_line - line > 2) ? (line + 2) : final_line;
72 if (*last < line) *last = line;
73}
74
82static bool
83rich_errors_are_utf8(const pm_parser_t *parser, size_t nerrors, const pm_rich_error_t *rich_errors) {
84 uint32_t final_line = pm_rich_errors_final_line(parser);
85
86 /* Every line from the first line of context of the most recently visited
87 * error up to (but not including) this index has already been checked.
88 * Because the errors are sorted, the first line of context never
89 * decreases, so any later error only needs the lines from this index
90 * onward. */
91 size_t checked_index = 0;
92
93 for (size_t idx = 0; idx < nerrors; idx++) {
94 uint32_t first_line;
95 uint32_t last_line;
96 pm_rich_error_context(rich_errors[idx].line_index, final_line, &first_line, &last_line);
97
98 size_t start_index = (size_t) first_line;
99 size_t end_index = (size_t) last_line;
100
101 if (start_index < checked_index) start_index = checked_index;
102 if (start_index > end_index) continue;
103
104 if (!lines_are_utf8(parser, start_index, end_index)) return false;
105 checked_index = end_index + 1;
106 }
107
108 return true;
109}
110
111#define COLOR_BOLD "\033[1m"
112#define COLOR_GRAY "\033[2m"
113#define COLOR_RED "\033[1;31m"
114#define COLOR_RESET "\033[m"
115#define TRUNCATE 30
116
117/* The maximum number of columns of a line that errors are displayed beneath
118 * before the line is displayed again. This must be at least TRUNCATE so that
119 * every window after the first on a line starts with a truncated line. Lines
120 * of context are cut off at the same width. */
121#define WINDOW 80
122
134
140static void
141pm_error_line_format_init(pm_error_line_format_t *format, pm_errors_format_type_t format_type, const pm_parser_t *parser, uint32_t first_line, uint32_t last_line) {
142 uint8_t first_width = pm_buffer_line_number_width(pm_line_offset_list_line_number(first_line, parser->start_line));
143 uint8_t last_width = pm_buffer_line_number_width(pm_line_offset_list_line_number(last_line, parser->start_line));
144
145 /* The range may cross the signed 32-bit display boundary. */
146 uint32_t wrap_index = (uint32_t) INT32_MAX - (uint32_t) parser->start_line;
147 if (first_line <= wrap_index && last_line > wrap_index) last_width = 11;
148
149 *format = (pm_error_line_format_t) {
150 .type = format_type,
151 .width = (first_width > last_width) ? first_width : last_width
152 };
153}
154
159static void
160pm_error_line_format_number(const pm_error_line_format_t *format, pm_buffer_t *buffer, int32_t line) {
161 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_GRAY);
162 pm_buffer_append_line_number(buffer, line, format->width);
163 PM_BUFFER_APPEND_LITERAL(buffer, " | ");
164 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RESET);
165}
166
171static void
172pm_error_line_format_blank(const pm_error_line_format_t *format, pm_buffer_t *buffer) {
173 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_GRAY);
174 pm_buffer_append_repeated(buffer, ' ', (size_t) format->width + 1);
175 PM_BUFFER_APPEND_LITERAL(buffer, "| ");
176 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RESET);
177}
178
183static void
184pm_error_line_format_divider(const pm_error_line_format_t *format, pm_buffer_t *buffer) {
185 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_GRAY);
186 PM_BUFFER_APPEND_LITERAL(buffer, " ");
187 pm_buffer_append_repeated(buffer, '~', (size_t) format->width + 4);
188 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RESET);
189 pm_buffer_append_byte(buffer, '\n');
190}
191
199static size_t
200pm_error_advance_columns(const pm_parser_t *parser, const uint8_t *start, size_t *column, size_t limit) {
201 size_t count = 0;
202
203 while (*column < limit) {
204 const uint8_t *cursor = start + *column;
205 size_t char_width = 1;
206
207 /* Every supported encoding is ASCII-compatible, so a byte below 0x80
208 * at the start of a character is a character by itself. */
209 if ((cursor < parser->end) && (*cursor >= 0x80)) {
210 char_width = pm_parser_encoding_char_width(parser, cursor, parser->end - cursor);
211 if (char_width == 0) char_width = 1;
212 }
213
214 *column += char_width;
215 count++;
216 }
217
218 return count;
219}
220
221static void
222pm_error_format_line(const pm_parser_t *parser, pm_buffer_t *buffer, const pm_error_line_format_t *format, uint32_t line, uint32_t column_start, uint32_t column_end) {
223 size_t index = line;
224 PRISM_ASSERT(index < parser->line_offsets.size);
225
226 const uint8_t *start = parser->start + parser->line_offsets.offsets[index];
227 const uint8_t *end;
228
229 if (index >= parser->line_offsets.size - 1) {
230 end = parser->end;
231 } else {
232 end = parser->start + parser->line_offsets.offsets[index + 1];
233 }
234
235 pm_error_line_format_number(format, buffer, pm_line_offset_list_line_number(line, parser->start_line));
236
237 /* Here we determine if we should truncate the start of the line. The
238 * column is the start of a diagnostic, so it is on a character boundary. */
239 bool truncate_start = column_start >= TRUNCATE;
240 const uint8_t *display_start = truncate_start ? (start + column_start) : start;
241
242 /* Here we determine if we should truncate the end of the line. Note that
243 * this is written to avoid computing start + column_end, which could be
244 * more than one past the end of the source when the error is at the end
245 * of the input. The walk to find a character boundary begins at the
246 * displayed start so that its cost is bounded by the displayed width. */
247 bool truncate_end = false;
248 if ((column_end != 0) && ((end - start) - ((ptrdiff_t) column_end) >= TRUNCATE)) {
249 const uint8_t *end_candidate = start + column_end + TRUNCATE;
250
251 for (const uint8_t *cursor = display_start; cursor < end_candidate;) {
252 size_t char_width = pm_parser_encoding_char_width(parser, cursor, parser->end - cursor);
253
254 /* If we failed to decode a character, then just bail out and
255 * truncate at the fixed width. */
256 if (char_width == 0) break;
257
258 /* If this next character would go past the end candidate,
259 * then we need to truncate before it. */
260 if (cursor + char_width > end_candidate) {
261 end_candidate = cursor;
262 break;
263 }
264
265 cursor += char_width;
266 }
267
268 end = end_candidate;
269 truncate_end = true;
270 }
271
272 if (truncate_start) PM_BUFFER_APPEND_LITERAL(buffer, "... ");
273 pm_buffer_append_string(buffer, (const char *) display_start, (size_t) (end - display_start));
274
275 if (truncate_end) {
276 PM_BUFFER_APPEND_LITERAL(buffer, " ...\n");
277 } else if (end == parser->end && end > parser->start && end[-1] != '\n') {
278 pm_buffer_append_byte(buffer, '\n');
279 }
280}
281
286static void
287pm_error_format_context_line(const pm_parser_t *parser, pm_buffer_t *buffer, const pm_error_line_format_t *format, uint32_t line) {
288 PM_BUFFER_APPEND_LITERAL(buffer, " ");
289 pm_error_format_line(parser, buffer, format, line, 0, WINDOW);
290}
291
292static void
293pm_rich_errors_format(const pm_parser_t *parser, pm_buffer_t *buffer, pm_errors_format_type_t format_type, size_t nerrors, pm_rich_error_t *rich_errors, bool inline_messages) {
294 uint32_t final_line = pm_rich_errors_final_line(parser);
295
296 /* The line numbers that are displayed range from the first line of context
297 * of the first error to the last line of context of the last error. */
298 uint32_t first_displayed_line;
299 uint32_t last_displayed_line;
300 uint32_t unused_line;
301 pm_rich_error_context(rich_errors[0].line_index, final_line, &first_displayed_line, &unused_line);
302 pm_rich_error_context(rich_errors[nerrors - 1].line_index, final_line, &unused_line, &last_displayed_line);
303
305 pm_error_line_format_init(&format, format_type, parser, first_displayed_line, last_displayed_line);
306
307 /* We are going to iterate through every error in our error list and display
308 * it. While we are iterating, we will display some padding lines of the
309 * source before the error to give some context. We will be careful not to
310 * display the same line twice in case the errors are close enough in the
311 * source.
312 *
313 * The errors on a line are split into windows of at most WINDOW columns.
314 * Each window displays its own slice of the line, and the markers beneath
315 * it are padded relative to the start of that slice and cut off at its
316 * end. This bounds the length of every marker line, so the output grows
317 * linearly with the number of errors no matter how long the line is. */
318 uint32_t last_line = 0;
319 uint32_t window_column_start = 0;
320 uint32_t window_column_end = 0;
321 size_t window_end_idx = 0;
322
323 for (size_t idx = 0; idx < nerrors; idx++) {
324 pm_rich_error_t *rich_error = rich_errors + idx;
325
326 /* Here we determine how many lines of padding of the source to display,
327 * based on the difference from the last line that was displayed. */
328 uint32_t first_context = (rich_error->line_index > 2) ? (rich_error->line_index - 2) : 0;
329 if (idx != 0) {
330 if (rich_error->line_index > last_line && rich_error->line_index - last_line > 3) {
331 pm_error_line_format_divider(&format, buffer);
332 }
333 if (last_line >= rich_error->line_index) first_context = rich_error->line_index;
334 else if (first_context <= last_line) first_context = last_line + 1;
335 }
336
337 for (uint32_t line = first_context; line < rich_error->line_index; line++) {
338 pm_error_format_context_line(parser, buffer, &format, line);
339 }
340
341 /* If this error is not in the current window (because it is the first
342 * error, it is on a new line, or it is too far to the right), then we
343 * start a new window and display the line that has the error in it. */
344 if (idx == window_end_idx) {
345 switch (format_type) {
347 PM_BUFFER_APPEND_LITERAL(buffer, "> ");
348 break;
350 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_BOLD "> " COLOR_RESET);
351 break;
353 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RED "> " COLOR_RESET);
354 break;
355 }
356
357 /* The displayed slice of the line starts at this error, unless it
358 * is close enough to the start of the line to show it all. */
359 window_column_start = (rich_error->column_start >= TRUNCATE) ? rich_error->column_start : 0;
360 uint32_t window_limit = window_column_start + WINDOW;
361
362 /* Find the errors on this line that start within the window, and
363 * the maximum column end of all of them, capped at the window. */
364 window_column_end = rich_error->column_end;
365 for (window_end_idx = idx + 1; window_end_idx < nerrors; window_end_idx++) {
366 const pm_rich_error_t *next_error = &rich_errors[window_end_idx];
367 if ((next_error->line_index != rich_error->line_index) || (next_error->column_start >= window_limit)) break;
368 if (next_error->column_end > window_column_end) window_column_end = next_error->column_end;
369 }
370
371 if (window_column_end > window_limit) window_column_end = window_limit;
372 pm_error_format_line(parser, buffer, &format, rich_error->line_index, rich_error->column_start, window_column_end);
373 }
374
375 const uint8_t *start = parser->start + parser->line_offsets.offsets[rich_error->line_index];
376 if (start == parser->end) pm_buffer_append_byte(buffer, '\n');
377
378 /* Now we will display the actual error message. We will do this by
379 * first putting the prefix to the line, then a bunch of blank spaces
380 * depending on the column, then as many tildes as we need to display
381 * the width of the error, then the error message itself.
382 *
383 * Note that this doesn't take into account the width of the actual
384 * character when displayed in the terminal. For some east-asian
385 * languages or emoji, this means it can be thrown off pretty badly. We
386 * will need to solve this eventually. */
387 PM_BUFFER_APPEND_LITERAL(buffer, " ");
388 pm_error_line_format_blank(&format, buffer);
389
390 size_t column = 0;
391 if (window_column_start > 0) {
392 PM_BUFFER_APPEND_LITERAL(buffer, " ");
393 column = window_column_start;
394 }
395
396 pm_buffer_append_repeated(buffer, ' ', pm_error_advance_columns(parser, start, &column, rich_error->column_start));
397
398 switch (format_type) {
400 pm_buffer_append_byte(buffer, '^');
401 break;
403 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_BOLD "^");
404 break;
406 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RED "^");
407 break;
408 }
409
410 /* The caret marks the first character of the error, and the tildes
411 * mark the rest of it, up to the end of the window. */
412 pm_error_advance_columns(parser, start, &column, column + 1);
413 size_t tilde_limit = (rich_error->column_end < window_column_end) ? rich_error->column_end : window_column_end;
414 pm_buffer_append_repeated(buffer, '~', pm_error_advance_columns(parser, start, &column, tilde_limit));
415
416 if (format_type != PM_ERRORS_FORMAT_PLAIN) {
417 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RESET);
418 }
419
420 if (inline_messages) {
421 const char *message = pm_diagnostic_message(rich_error->diagnostic);
422
423 pm_buffer_append_byte(buffer, ' ');
424 pm_buffer_append_string(buffer, message, strlen(message));
425 }
426
427 pm_buffer_append_byte(buffer, '\n');
428
429 /* Here we determine how many lines of padding to display after the
430 * diagnostic, depending on where the next diagnostic is in source. The
431 * context after the last error is limited to the source. */
432 last_line = rich_error->line_index;
433 uint32_t last_context = final_line;
434 if (idx + 1 < nerrors) {
435 uint32_t next_line = rich_errors[idx + 1].line_index;
436 last_context = (next_line > last_line) ? next_line - 1 : last_line;
437 }
438
439 for (uint32_t count = 0; count < 2 && last_line < last_context; count++) {
440 pm_error_format_context_line(parser, buffer, &format, ++last_line);
441 }
442 }
443}
444
445static void
446pm_rich_error_init(const pm_parser_t *parser, pm_rich_error_t *rich_error, pm_diagnostic_t *diagnostic, pm_location_t *location) {
447 const pm_line_offset_list_t *line_offsets = &parser->line_offsets;
448 pm_line_column_t start_line_column = pm_line_offset_list_line_column(line_offsets, location->start, 0);
449 pm_line_column_t end_line_column = pm_line_offset_list_line_column(line_offsets, location->start + location->length, 0);
450
451 uint32_t column_end;
452 if (start_line_column.line == end_line_column.line) {
453 column_end = end_line_column.column;
454 } else {
455 column_end = (uint32_t) (line_offsets->offsets[(uint32_t) start_line_column.line + 1] - line_offsets->offsets[(uint32_t) start_line_column.line] - 1);
456 }
457
458 /* Ensure we have at least one column of error. */
459 if (start_line_column.column == column_end) column_end++;
460
461 *rich_error = (pm_rich_error_t) {
462 .diagnostic = diagnostic,
463 .line_index = (uint32_t) start_line_column.line,
464 .column_start = start_line_column.column,
465 .column_end = column_end
466 };
467}
468
473static void
474pm_error_append_summary(const pm_parser_t *parser, pm_buffer_t *buffer, uint32_t line, const char *message) {
475 pm_buffer_append_string(buffer, (const char *) pm_string_source(&parser->filepath), pm_string_length(&parser->filepath));
476 pm_buffer_append_byte(buffer, ':');
477 pm_buffer_append_line_number(buffer, pm_line_offset_list_line_number(line, parser->start_line), 0);
478 PM_BUFFER_APPEND_LITERAL(buffer, ": ");
479 pm_buffer_append_string(buffer, message, strlen(message));
480}
481
483pm_errors_format(const pm_parser_t *parser, pm_buffer_t *buffer, pm_errors_format_type_t format_type) {
484 size_t nerrors = parser->error_list.size;
485 PRISM_ASSERT(nerrors > 0);
486
487 size_t rich_errors_size = nerrors * sizeof(pm_rich_error_t);
488 if (rich_errors_size / sizeof(pm_rich_error_t) != nerrors) PRISM_OOM();
489
490 pm_rich_error_t *rich_errors = xmalloc(rich_errors_size);
491 if (rich_errors == NULL) PRISM_OOM();
492
493 size_t rich_errors_idx = 0;
494 uint32_t first_syntax_line_index = 0;
495 const pm_diagnostic_t *encoding_error = NULL;
496
497 for (pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) parser->error_list.head; diagnostic != NULL; diagnostic = (pm_diagnostic_t *) diagnostic->node.next) {
498 pm_location_t location = pm_diagnostic_location(diagnostic);
499
500 switch (pm_diagnostic_error_level(diagnostic)) {
502 /* Keep errors in source order. At the same offset, display the newest error first. */
503 size_t position = rich_errors_idx;
504 while (position > 0 && rich_errors[position - 1].diagnostic->location.start >= location.start) {
505 rich_errors[position] = rich_errors[position - 1];
506 position--;
507 }
508
509 pm_rich_error_init(parser, &rich_errors[position], diagnostic, &location);
510 if (rich_errors_idx == 0) first_syntax_line_index = rich_errors[position].line_index;
511 rich_errors_idx++;
512 break;
513 }
515 /* If we get an argument error, we want to format it and return it
516 * immediately. They should include a snippet of the source if
517 * possible. */
518 pm_rich_error_init(parser, rich_errors, diagnostic, &location);
519 pm_error_append_summary(parser, buffer, rich_errors[0].line_index, pm_diagnostic_message(diagnostic));
520
521 if (rich_errors_are_utf8(parser, 1, rich_errors)) {
522 pm_buffer_append_byte(buffer, '\n');
523 pm_rich_errors_format(parser, buffer, format_type, 1, rich_errors, false);
524 }
525
526 xfree_sized(rich_errors, rich_errors_size);
528 }
529 case PM_ERROR_LEVEL_LOAD: {
530 /* If we get a load error, we want to format it and return it
531 * immediately. It should only include the diagnostic message. */
532 const char *message = pm_diagnostic_message(diagnostic);
533 pm_buffer_append_string(buffer, message, strlen(message));
534
535 xfree_sized(rich_errors, rich_errors_size);
536 return PM_ERROR_LEVEL_LOAD;
537 }
539 /* If we get a stack error, we want to format it and return it
540 * immediately. Once the stack is exhausted, the syntax errors
541 * around it come from recovering from that point rather than from
542 * the source, so they are left out. It should include a snippet of
543 * the source if possible. */
544 pm_rich_error_init(parser, rich_errors, diagnostic, &location);
545 pm_error_append_summary(parser, buffer, rich_errors[0].line_index, pm_diagnostic_message(diagnostic));
546
547 if (rich_errors_are_utf8(parser, 1, rich_errors)) {
548 pm_buffer_append_byte(buffer, '\n');
549 pm_rich_errors_format(parser, buffer, format_type, 1, rich_errors, false);
550 }
551
552 xfree_sized(rich_errors, rich_errors_size);
554 }
556 if (encoding_error == NULL) encoding_error = diagnostic;
557 break;
558 }
559 }
560
561 /* The compiler would encounter a syntax error before joining any strings. */
562 if (rich_errors_idx == 0) {
563 PRISM_ASSERT(encoding_error != NULL);
564 const char *message = pm_diagnostic_message(encoding_error);
565 pm_buffer_append_string(buffer, message, strlen(message));
566
567 xfree_sized(rich_errors, rich_errors_size);
569 }
570
571 nerrors = rich_errors_idx;
572
573 /* The header displays the line of the first syntax error in parse order. */
574 pm_error_append_summary(parser, buffer, first_syntax_line_index, (nerrors > 1) ? "syntax errors found\n" : "syntax error found\n");
575
576 if (rich_errors_are_utf8(parser, nerrors, rich_errors)) {
577 /* In here, we have all of the rich diagnostic information and we know
578 * the snippets are valid UTF-8, so we format them all together with
579 * the source code snippets. */
580 pm_rich_errors_format(parser, buffer, format_type, nerrors, rich_errors, true);
581 } else {
582 /* In here, we have content in the source that is not valid UTF-8. In
583 * that case, we do not want to attempt to format the source code
584 * snippets because we do not know how the terminal will handle it. The
585 * diagnostics are displayed in the order that they appear in the
586 * source, as they are when the snippets are displayed. */
587 for (size_t idx = 0; idx < nerrors; idx++) {
588 if (idx > 0) pm_buffer_append_byte(buffer, '\n');
589 pm_error_append_summary(parser, buffer, rich_errors[idx].line_index, pm_diagnostic_message(rich_errors[idx].diagnostic));
590 }
591 }
592
593 xfree_sized(rich_errors, rich_errors_size);
595}
pm_error_level_t
The levels of errors generated during parsing.
Definition diagnostic.h:27
@ PM_ERROR_LEVEL_ARGUMENT
For errors that should raise an argument error.
Definition diagnostic.h:32
@ PM_ERROR_LEVEL_LOAD
For errors that should raise a load error.
Definition diagnostic.h:35
@ PM_ERROR_LEVEL_STACK
For errors that should raise a system stack error.
Definition diagnostic.h:42
@ PM_ERROR_LEVEL_ENCODING_COMPATIBILITY
For errors that should raise an encoding compatibility error.
Definition diagnostic.h:45
@ PM_ERROR_LEVEL_SYNTAX
For errors that should raise a syntax error.
Definition diagnostic.h:29
A function for formatting the errors in a parser into a buffer.
pm_errors_format_type_t
The type of formatting to use when formatting errors.
@ PM_ERRORS_FORMAT_PLAIN
Format errors in a plain format with no colors or styles.
@ PM_ERRORS_FORMAT_COLOR
Format errors in a color format with bold and colors.
@ PM_ERRORS_FORMAT_STYLE
Format errors in a style format with bold only.
#define xmalloc
Old name of ruby_xmalloc.
Definition xmalloc.h:53
C99 shim for <stdbool.h>.
pm_errors_format_type_t type
The type of formatting to use when formatting the errors.
uint8_t width
The number of columns taken up by the widest line number that will be displayed, including the sign o...
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 the start of lines in a string.
uint32_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.
This struct represents a slice in the source code, defined by an offset and a length.
Definition ast.h:579
uint32_t start
The offset of the location from the start of the source.
Definition ast.h:581
uint32_t length
The length of the location.
Definition ast.h:584