Ruby 4.1.0dev (2026-11-17 revision b4ade67ba58e9a4d70f887701cb8692d67093087)
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 <inttypes.h>
13#include <stdbool.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;
44 size_t idx;
46
47static int
48pm_rich_error_compare(const void *a, const void *b) {
49 const pm_rich_error_t *left = (const pm_rich_error_t *) a;
50 const pm_rich_error_t *right = (const pm_rich_error_t *) b;
51
52 if (left->line_index != right->line_index) {
53 return (left->line_index < right->line_index) ? -1 : 1;
54 }
55
56 if (left->column_start != right->column_start) {
57 return (left->column_start < right->column_start) ? -1 : 1;
58 }
59
60 if (left->idx != right->idx) {
61 return (left->idx < right->idx) ? 1 : -1;
62 }
63
64 return 0;
65}
66
71static uint32_t
72pm_rich_errors_final_line(const pm_parser_t *parser) {
73 const pm_line_offset_list_t *line_offsets = &parser->line_offsets;
74 uint32_t final_line = (uint32_t) (line_offsets->size - 1);
75
76 if (final_line > 0 && (parser->start + line_offsets->offsets[final_line]) == parser->end) {
77 final_line--;
78 }
79
80 return final_line;
81}
82
89static void
90pm_rich_error_context(uint32_t line, uint32_t final_line, uint32_t *first, uint32_t *last) {
91 *first = (line > 2) ? (line - 2) : 0;
92 *last = (final_line > line && final_line - line > 2) ? (line + 2) : final_line;
93 if (*last < line) *last = line;
94}
95
103static bool
104rich_errors_are_utf8(const pm_parser_t *parser, size_t nerrors, const pm_rich_error_t *rich_errors) {
105 uint32_t final_line = pm_rich_errors_final_line(parser);
106
107 /* Every line from the first line of context of the most recently visited
108 * error up to (but not including) this index has already been checked.
109 * Because the errors are sorted, the first line of context never
110 * decreases, so any later error only needs the lines from this index
111 * onward. */
112 size_t checked_index = 0;
113
114 for (size_t idx = 0; idx < nerrors; idx++) {
115 uint32_t first_line;
116 uint32_t last_line;
117 pm_rich_error_context(rich_errors[idx].line_index, final_line, &first_line, &last_line);
118
119 size_t start_index = (size_t) first_line;
120 size_t end_index = (size_t) last_line;
121
122 if (start_index < checked_index) start_index = checked_index;
123 if (start_index > end_index) continue;
124
125 if (!lines_are_utf8(parser, start_index, end_index)) return false;
126 checked_index = end_index + 1;
127 }
128
129 return true;
130}
131
132#define COLOR_BOLD "\033[1m"
133#define COLOR_GRAY "\033[2m"
134#define COLOR_RED "\033[1;31m"
135#define COLOR_RESET "\033[m"
136#define TRUNCATE 30
137
138/* The maximum number of columns of a line that errors are displayed beneath
139 * before the line is displayed again. This must be at least TRUNCATE so that
140 * every window after the first on a line starts with a truncated line. Lines
141 * of context are cut off at the same width. */
142#define WINDOW 80
143
155
162static uint8_t
163pm_error_line_digits(int32_t line, char digits[11]) {
164 /* The magnitude is computed in unsigned arithmetic so that negating the
165 * minimum value of a 32-bit integer is well-defined. */
166 uint32_t magnitude = (line < 0) ? (0U - (uint32_t) line) : (uint32_t) line;
167 uint8_t length = 0;
168
169 do {
170 digits[10 - length++] = (char) ('0' + (magnitude % 10));
171 magnitude /= 10;
172 } while (magnitude > 0);
173
174 if (line < 0) digits[10 - length++] = '-';
175 return length;
176}
177
182static void
183pm_error_append_line_number(pm_buffer_t *buffer, int32_t line, uint8_t width) {
184 char digits[11];
185 uint8_t length = pm_error_line_digits(line, digits);
186
187 if (width > length) pm_buffer_append_repeated(buffer, ' ', (size_t) (width - length));
188 pm_buffer_append_string(buffer, digits + sizeof(digits) - length, length);
189}
190
196static void
197pm_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) {
198 char digits[11];
199 uint8_t first_width = pm_error_line_digits(pm_line_offset_list_line_number(first_line, parser->start_line), digits);
200 uint8_t last_width = pm_error_line_digits(pm_line_offset_list_line_number(last_line, parser->start_line), digits);
201
202 /* The range may cross the signed 32-bit display boundary. */
203 uint32_t wrap_index = (uint32_t) INT32_MAX - (uint32_t) parser->start_line;
204 if (first_line <= wrap_index && last_line > wrap_index) last_width = 11;
205
206 *format = (pm_error_line_format_t) {
207 .type = format_type,
208 .width = (first_width > last_width) ? first_width : last_width
209 };
210}
211
216static void
217pm_error_line_format_number(const pm_error_line_format_t *format, pm_buffer_t *buffer, int32_t line) {
218 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_GRAY);
219 pm_error_append_line_number(buffer, line, format->width);
220 PM_BUFFER_APPEND_LITERAL(buffer, " | ");
221 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RESET);
222}
223
228static void
229pm_error_line_format_blank(const pm_error_line_format_t *format, pm_buffer_t *buffer) {
230 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_GRAY);
231 pm_buffer_append_repeated(buffer, ' ', (size_t) format->width + 1);
232 PM_BUFFER_APPEND_LITERAL(buffer, "| ");
233 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RESET);
234}
235
240static void
241pm_error_line_format_divider(const pm_error_line_format_t *format, pm_buffer_t *buffer) {
242 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_GRAY);
243 PM_BUFFER_APPEND_LITERAL(buffer, " ");
244 pm_buffer_append_repeated(buffer, '~', (size_t) format->width + 4);
245 if (format->type > PM_ERRORS_FORMAT_PLAIN) PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RESET);
246 pm_buffer_append_byte(buffer, '\n');
247}
248
256static size_t
257pm_error_advance_columns(const pm_parser_t *parser, const uint8_t *start, size_t *column, size_t limit) {
258 size_t count = 0;
259
260 while (*column < limit) {
261 const uint8_t *cursor = start + *column;
262 size_t char_width = 1;
263
264 /* Every supported encoding is ASCII-compatible, so a byte below 0x80
265 * at the start of a character is a character by itself. */
266 if ((cursor < parser->end) && (*cursor >= 0x80)) {
267 char_width = pm_parser_encoding_char_width(parser, cursor, parser->end - cursor);
268 if (char_width == 0) char_width = 1;
269 }
270
271 *column += char_width;
272 count++;
273 }
274
275 return count;
276}
277
278static void
279pm_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) {
280 size_t index = line;
281 PRISM_ASSERT(index < parser->line_offsets.size);
282
283 const uint8_t *start = parser->start + parser->line_offsets.offsets[index];
284 const uint8_t *end;
285
286 if (index >= parser->line_offsets.size - 1) {
287 end = parser->end;
288 } else {
289 end = parser->start + parser->line_offsets.offsets[index + 1];
290 }
291
292 pm_error_line_format_number(format, buffer, pm_line_offset_list_line_number(line, parser->start_line));
293
294 /* Here we determine if we should truncate the start of the line. The
295 * column is the start of a diagnostic, so it is on a character boundary. */
296 bool truncate_start = column_start >= TRUNCATE;
297 const uint8_t *display_start = truncate_start ? (start + column_start) : start;
298
299 /* Here we determine if we should truncate the end of the line. Note that
300 * this is written to avoid computing start + column_end, which could be
301 * more than one past the end of the source when the error is at the end
302 * of the input. The walk to find a character boundary begins at the
303 * displayed start so that its cost is bounded by the displayed width. */
304 bool truncate_end = false;
305 if ((column_end != 0) && ((end - start) - ((ptrdiff_t) column_end) >= TRUNCATE)) {
306 const uint8_t *end_candidate = start + column_end + TRUNCATE;
307
308 for (const uint8_t *cursor = display_start; cursor < end_candidate;) {
309 size_t char_width = pm_parser_encoding_char_width(parser, cursor, parser->end - cursor);
310
311 /* If we failed to decode a character, then just bail out and
312 * truncate at the fixed width. */
313 if (char_width == 0) break;
314
315 /* If this next character would go past the end candidate,
316 * then we need to truncate before it. */
317 if (cursor + char_width > end_candidate) {
318 end_candidate = cursor;
319 break;
320 }
321
322 cursor += char_width;
323 }
324
325 end = end_candidate;
326 truncate_end = true;
327 }
328
329 if (truncate_start) PM_BUFFER_APPEND_LITERAL(buffer, "... ");
330 pm_buffer_append_string(buffer, (const char *) display_start, (size_t) (end - display_start));
331
332 if (truncate_end) {
333 PM_BUFFER_APPEND_LITERAL(buffer, " ...\n");
334 } else if (end == parser->end && end > parser->start && end[-1] != '\n') {
335 pm_buffer_append_byte(buffer, '\n');
336 }
337}
338
343static void
344pm_error_format_context_line(const pm_parser_t *parser, pm_buffer_t *buffer, const pm_error_line_format_t *format, uint32_t line) {
345 PM_BUFFER_APPEND_LITERAL(buffer, " ");
346 pm_error_format_line(parser, buffer, format, line, 0, WINDOW);
347}
348
349static void
350pm_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) {
351 uint32_t final_line = pm_rich_errors_final_line(parser);
352
353 /* The line numbers that are displayed range from the first line of context
354 * of the first error to the last line of context of the last error. */
355 uint32_t first_displayed_line;
356 uint32_t last_displayed_line;
357 uint32_t unused_line;
358 pm_rich_error_context(rich_errors[0].line_index, final_line, &first_displayed_line, &unused_line);
359 pm_rich_error_context(rich_errors[nerrors - 1].line_index, final_line, &unused_line, &last_displayed_line);
360
362 pm_error_line_format_init(&format, format_type, parser, first_displayed_line, last_displayed_line);
363
364 /* We are going to iterate through every error in our error list and display
365 * it. While we are iterating, we will display some padding lines of the
366 * source before the error to give some context. We will be careful not to
367 * display the same line twice in case the errors are close enough in the
368 * source.
369 *
370 * The errors on a line are split into windows of at most WINDOW columns.
371 * Each window displays its own slice of the line, and the markers beneath
372 * it are padded relative to the start of that slice and cut off at its
373 * end. This bounds the length of every marker line, so the output grows
374 * linearly with the number of errors no matter how long the line is. */
375 uint32_t last_line = 0;
376 uint32_t window_column_start = 0;
377 uint32_t window_column_end = 0;
378 size_t window_end_idx = 0;
379
380 for (size_t idx = 0; idx < nerrors; idx++) {
381 pm_rich_error_t *rich_error = rich_errors + idx;
382
383 /* Here we determine how many lines of padding of the source to display,
384 * based on the difference from the last line that was displayed. */
385 uint32_t first_context = (rich_error->line_index > 2) ? (rich_error->line_index - 2) : 0;
386 if (idx != 0) {
387 if (rich_error->line_index > last_line && rich_error->line_index - last_line > 3) {
388 pm_error_line_format_divider(&format, buffer);
389 }
390 if (last_line >= rich_error->line_index) first_context = rich_error->line_index;
391 else if (first_context <= last_line) first_context = last_line + 1;
392 }
393
394 for (uint32_t line = first_context; line < rich_error->line_index; line++) {
395 pm_error_format_context_line(parser, buffer, &format, line);
396 }
397
398 /* If this error is not in the current window (because it is the first
399 * error, it is on a new line, or it is too far to the right), then we
400 * start a new window and display the line that has the error in it. */
401 if (idx == window_end_idx) {
402 switch (format_type) {
404 PM_BUFFER_APPEND_LITERAL(buffer, "> ");
405 break;
407 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_BOLD "> " COLOR_RESET);
408 break;
410 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RED "> " COLOR_RESET);
411 break;
412 }
413
414 /* The displayed slice of the line starts at this error, unless it
415 * is close enough to the start of the line to show it all. */
416 window_column_start = (rich_error->column_start >= TRUNCATE) ? rich_error->column_start : 0;
417 uint32_t window_limit = window_column_start + WINDOW;
418
419 /* Find the errors on this line that start within the window, and
420 * the maximum column end of all of them, capped at the window. */
421 window_column_end = rich_error->column_end;
422 for (window_end_idx = idx + 1; window_end_idx < nerrors; window_end_idx++) {
423 const pm_rich_error_t *next_error = &rich_errors[window_end_idx];
424 if ((next_error->line_index != rich_error->line_index) || (next_error->column_start >= window_limit)) break;
425 if (next_error->column_end > window_column_end) window_column_end = next_error->column_end;
426 }
427
428 if (window_column_end > window_limit) window_column_end = window_limit;
429 pm_error_format_line(parser, buffer, &format, rich_error->line_index, rich_error->column_start, window_column_end);
430 }
431
432 const uint8_t *start = parser->start + parser->line_offsets.offsets[rich_error->line_index];
433 if (start == parser->end) pm_buffer_append_byte(buffer, '\n');
434
435 /* Now we will display the actual error message. We will do this by
436 * first putting the prefix to the line, then a bunch of blank spaces
437 * depending on the column, then as many tildes as we need to display
438 * the width of the error, then the error message itself.
439 *
440 * Note that this doesn't take into account the width of the actual
441 * character when displayed in the terminal. For some east-asian
442 * languages or emoji, this means it can be thrown off pretty badly. We
443 * will need to solve this eventually. */
444 PM_BUFFER_APPEND_LITERAL(buffer, " ");
445 pm_error_line_format_blank(&format, buffer);
446
447 size_t column = 0;
448 if (window_column_start > 0) {
449 PM_BUFFER_APPEND_LITERAL(buffer, " ");
450 column = window_column_start;
451 }
452
453 pm_buffer_append_repeated(buffer, ' ', pm_error_advance_columns(parser, start, &column, rich_error->column_start));
454
455 switch (format_type) {
457 pm_buffer_append_byte(buffer, '^');
458 break;
460 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_BOLD "^");
461 break;
463 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RED "^");
464 break;
465 }
466
467 /* The caret marks the first character of the error, and the tildes
468 * mark the rest of it, up to the end of the window. */
469 pm_error_advance_columns(parser, start, &column, column + 1);
470 size_t tilde_limit = (rich_error->column_end < window_column_end) ? rich_error->column_end : window_column_end;
471 pm_buffer_append_repeated(buffer, '~', pm_error_advance_columns(parser, start, &column, tilde_limit));
472
473 if (format_type != PM_ERRORS_FORMAT_PLAIN) {
474 PM_BUFFER_APPEND_LITERAL(buffer, COLOR_RESET);
475 }
476
477 if (inline_messages) {
478 const char *message = pm_diagnostic_message(rich_error->diagnostic);
479
480 pm_buffer_append_byte(buffer, ' ');
481 pm_buffer_append_string(buffer, message, strlen(message));
482 }
483
484 pm_buffer_append_byte(buffer, '\n');
485
486 /* Here we determine how many lines of padding to display after the
487 * diagnostic, depending on where the next diagnostic is in source. The
488 * context after the last error is limited to the source. */
489 last_line = rich_error->line_index;
490 uint32_t last_context = final_line;
491 if (idx + 1 < nerrors) {
492 uint32_t next_line = rich_errors[idx + 1].line_index;
493 last_context = (next_line > last_line) ? next_line - 1 : last_line;
494 }
495
496 for (uint32_t count = 0; count < 2 && last_line < last_context; count++) {
497 pm_error_format_context_line(parser, buffer, &format, ++last_line);
498 }
499 }
500}
501
502static void
503pm_rich_error_init(const pm_parser_t *parser, pm_rich_error_t *rich_error, pm_diagnostic_t *diagnostic, pm_location_t *location) {
504 const pm_line_offset_list_t *line_offsets = &parser->line_offsets;
505 pm_line_column_t start_line_column = pm_line_offset_list_line_column(line_offsets, location->start, 0);
506 pm_line_column_t end_line_column = pm_line_offset_list_line_column(line_offsets, location->start + location->length, 0);
507
508 uint32_t column_end;
509 if (start_line_column.line == end_line_column.line) {
510 column_end = end_line_column.column;
511 } else {
512 column_end = (uint32_t) (line_offsets->offsets[(uint32_t) start_line_column.line + 1] - line_offsets->offsets[(uint32_t) start_line_column.line] - 1);
513 }
514
515 /* Ensure we have at least one column of error. */
516 if (start_line_column.column == column_end) column_end++;
517
518 *rich_error = (pm_rich_error_t) {
519 .diagnostic = diagnostic,
520 .line_index = (uint32_t) start_line_column.line,
521 .column_start = start_line_column.column,
522 .column_end = column_end
523 };
524}
525
530static void
531pm_error_append_summary(const pm_parser_t *parser, pm_buffer_t *buffer, uint32_t line, const char *message) {
532 pm_buffer_append_string(buffer, (const char *) pm_string_source(&parser->filepath), pm_string_length(&parser->filepath));
533 pm_buffer_append_byte(buffer, ':');
534 pm_error_append_line_number(buffer, pm_line_offset_list_line_number(line, parser->start_line), 0);
535 PM_BUFFER_APPEND_LITERAL(buffer, ": ");
536 pm_buffer_append_string(buffer, message, strlen(message));
537}
538
540pm_errors_format(const pm_parser_t *parser, pm_buffer_t *buffer, pm_errors_format_type_t format_type) {
541 size_t nerrors = parser->error_list.size;
542 PRISM_ASSERT(nerrors > 0);
543
544 size_t rich_errors_size = nerrors * sizeof(pm_rich_error_t);
545 if (rich_errors_size / sizeof(pm_rich_error_t) != nerrors) PRISM_OOM();
546
547 pm_rich_error_t *rich_errors = xmalloc(rich_errors_size);
548 if (rich_errors == NULL) PRISM_OOM();
549
550 size_t rich_errors_idx = 0;
551
552 for (pm_diagnostic_t *diagnostic = (pm_diagnostic_t *) parser->error_list.head; diagnostic != NULL; diagnostic = (pm_diagnostic_t *) diagnostic->node.next) {
553 pm_location_t location = pm_diagnostic_location(diagnostic);
554
555 switch (pm_diagnostic_error_level(diagnostic)) {
557 pm_rich_error_init(parser, &rich_errors[rich_errors_idx], diagnostic, &location);
558 rich_errors[rich_errors_idx].idx = rich_errors_idx;
559 rich_errors_idx++;
560 break;
561 }
563 /* If we get an argument error, we want to format it and return it
564 * immediately. They should include a snippet of the source if
565 * possible. */
566 pm_rich_error_init(parser, rich_errors, diagnostic, &location);
567 pm_error_append_summary(parser, buffer, rich_errors[0].line_index, pm_diagnostic_message(diagnostic));
568
569 if (rich_errors_are_utf8(parser, 1, rich_errors)) {
570 pm_buffer_append_byte(buffer, '\n');
571 pm_rich_errors_format(parser, buffer, format_type, 1, rich_errors, false);
572 }
573
574 xfree_sized(rich_errors, rich_errors_size);
576 }
577 case PM_ERROR_LEVEL_LOAD: {
578 /* If we get a load error, we want to format it and return it
579 * immediately. It should only include the diagnostic message. */
580 const char *message = pm_diagnostic_message(diagnostic);
581 pm_buffer_append_string(buffer, message, strlen(message));
582
583 xfree_sized(rich_errors, rich_errors_size);
584 return PM_ERROR_LEVEL_LOAD;
585 }
587 /* If we get a stack error, we want to format it and return it
588 * immediately. Once the stack is exhausted, the syntax errors
589 * around it come from recovering from that point rather than from
590 * the source, so they are left out. It should include a snippet of
591 * the source if possible. */
592 pm_rich_error_init(parser, rich_errors, diagnostic, &location);
593 pm_error_append_summary(parser, buffer, rich_errors[0].line_index, pm_diagnostic_message(diagnostic));
594
595 if (rich_errors_are_utf8(parser, 1, rich_errors)) {
596 pm_buffer_append_byte(buffer, '\n');
597 pm_rich_errors_format(parser, buffer, format_type, 1, rich_errors, false);
598 }
599
600 xfree_sized(rich_errors, rich_errors_size);
602 }
603 }
604 }
605
606 PRISM_ASSERT(rich_errors_idx == nerrors);
607
608 /* The header displays the line of the first error in parse order, which
609 * is the first entry in the array because it has not been sorted yet. */
610 pm_error_append_summary(parser, buffer, rich_errors[0].line_index, (nerrors > 1) ? "syntax errors found\n" : "syntax error found\n");
611
612 /* Sort the errors so that they are in the order that they appear in the
613 * source. This is the order they are displayed in, and it also lets the
614 * UTF-8 check visit each line only once. */
615 qsort(rich_errors, nerrors, sizeof(pm_rich_error_t), pm_rich_error_compare);
616
617 if (rich_errors_are_utf8(parser, nerrors, rich_errors)) {
618 /* In here, we have all of the rich diagnostic information and we know
619 * the snippets are valid UTF-8, so we format them all together with
620 * the source code snippets. */
621 pm_rich_errors_format(parser, buffer, format_type, nerrors, rich_errors, true);
622 } else {
623 /* In here, we have content in the source that is not valid UTF-8. In
624 * that case, we do not want to attempt to format the source code
625 * snippets because we do not know how the terminal will handle it. The
626 * diagnostics are displayed in the order that they appear in the
627 * source, as they are when the snippets are displayed. */
628 for (size_t idx = 0; idx < nerrors; idx++) {
629 if (idx > 0) pm_buffer_append_byte(buffer, '\n');
630 pm_error_append_summary(parser, buffer, rich_errors[idx].line_index, pm_diagnostic_message(rich_errors[idx].diagnostic));
631 }
632 }
633
634 xfree_sized(rich_errors, rich_errors_size);
636}
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_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