Prism Ruby parser
Loading...
Searching...
No Matches
Enumerations | Functions
errors_format.h File Reference

A function for formatting the errors in a parser into a buffer. More...

#include "prism/compiler/exported.h"
#include "prism/compiler/nodiscard.h"
#include "prism/compiler/nonnull.h"
#include "prism/buffer.h"
#include "prism/diagnostic.h"
#include "prism/parser.h"
Include dependency graph for errors_format.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  pm_errors_format_type_t { PM_ERRORS_FORMAT_PLAIN = 1 , PM_ERRORS_FORMAT_STYLE = 2 , PM_ERRORS_FORMAT_COLOR = 3 }
 The type of formatting to use when formatting errors. More...
 

Functions

PRISM_EXPORTED_FUNCTION pm_error_level_t pm_errors_format (const pm_parser_t *parser, pm_buffer_t *buffer, pm_errors_format_type_t format_type) PRISM_NONNULL(1
 Format the errors in a parser into a buffer.
 

Detailed Description

A function for formatting the errors in a parser into a buffer.

Enumeration Type Documentation

◆ pm_errors_format_type_t

The type of formatting to use when formatting errors.

Enumerator
PM_ERRORS_FORMAT_PLAIN 

Format errors in a plain format with no colors or styles.

Typically used when outputting to a file or when the output is not a terminal.

PM_ERRORS_FORMAT_STYLE 

Format errors in a style format with bold only.

Typically used when outputting to a terminal where you do not want colors.

PM_ERRORS_FORMAT_COLOR 

Format errors in a color format with bold and colors.

The default case when outputting on the terminal.

Function Documentation

◆ pm_errors_format()

PRISM_EXPORTED_FUNCTION pm_error_level_t pm_errors_format ( const pm_parser_t parser,
pm_buffer_t buffer,
pm_errors_format_type_t  format_type 
)

Format the errors in a parser into a buffer.

After return, the buffer will contain the formatted errors and any relevant source snippets if available and possible.

Parameters
parserThe parser containing the errors to format. Note that the parser does not need to be fully initialized, but it will need to have start, end, start_line, encoding, line_offsets, filepath, and error_list initialized.
bufferThe buffer to format the errors into.
format_typeThe type of formatting to use when formatting the errors.
Returns
The error level of the error with the highest precedence that was formatted. In practice this means it will be the argument or load error level if any were found, otherwise it will be the syntax error level. Callers should raise appropriate error types based on the returned level.