Luma 0.1.0
A low-level compiled alternative to C, C++, and more!
Loading...
Searching...
No Matches
Classes | Functions
error.h File Reference

Error reporting utilities for lexer and parser diagnostics. More...

#include <stdbool.h>
#include "../../lexer/lexer.h"
#include "../memory/memory.h"
Include dependency graph for error.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ErrorInformation
 Stores detailed information about an error. More...
 

Functions

const char * generate_line (ArenaAllocator *arena, Token *tokens, int token_count, int target_line)
 Generates the source code line text for a given line number.
 
int error_get_count (void)
 Gets the current error count.
 
ErrorInformationerror_get_at_index (int index)
 Gets the error at the specified index.
 
bool error_has_errors (void)
 Checks if there are any errors.
 
void error_add (ErrorInformation err)
 Adds a new error to the internal error list.
 
bool error_report (void)
 Reports all accumulated errors to stderr or appropriate output.
 
void error_clear (void)
 Clears all accumulated errors.
 

Detailed Description

Error reporting utilities for lexer and parser diagnostics.

This module defines an error information struct and functions to add, report, and clear errors, with support for detailed source location and optional notes and help messages.

Function Documentation

◆ error_add()

void error_add ( ErrorInformation  err)

Adds a new error to the internal error list.

The error information is copied or referenced for later reporting.

Parameters
errThe error information struct to add.

Adds a new error to the internal error list.

◆ error_clear()

void error_clear ( void  )

Clears all accumulated errors.

Frees any internal storage and resets the error list.

Clears all accumulated errors.

◆ error_get_at_index()

ErrorInformation * error_get_at_index ( int  index)

Gets the error at the specified index.

Parameters
indexIndex of the error to retrieve (0-based).
Returns
Pointer to the ErrorInformation struct, or NULL if index is invalid.

◆ error_get_count()

int error_get_count ( void  )

Gets the current error count.

Returns
Number of errors currently accumulated.

◆ error_has_errors()

bool error_has_errors ( void  )

Checks if there are any errors.

Returns
true if there are errors, false otherwise.

◆ error_report()

bool error_report ( void  )

Reports all accumulated errors to stderr or appropriate output.

Returns
true if there were errors to report, false if none.

Reports all accumulated errors to stderr or appropriate output.

◆ generate_line()

const char * generate_line ( ArenaAllocator arena,
Token tokens,
int  token_count,
int  target_line 
)

Generates the source code line text for a given line number.

Uses the provided tokens and copies the line text into memory allocated from the given arena.

Parameters
arenaArena allocator used for string allocation.
tokensArray of tokens representing the source.
token_countNumber of tokens in the array.
target_lineThe line number for which to generate the line text.
Returns
Pointer to a null-terminated string containing the line text, allocated in the arena. Returns NULL if the line is not found.

Generates the source code line text for a given line number.