2023-11-28 20:25:53 +00:00
|
|
|
|
|
|
|
#ifndef PARCEL_LOGGER_H
|
|
|
|
#define PARCEL_LOGGER_H
|
|
|
|
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PAC_SYNTAX_ERROR,
|
|
|
|
PAC_NAMING_ERROR,
|
|
|
|
PAC_INTERNAL_ERROR
|
|
|
|
|
|
|
|
} pac_error_e;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PAC_SYNTAX_ERROR_UNSPECIFIED,
|
|
|
|
PAC_SYNTAX_ERROR_STRAY,
|
|
|
|
PAC_SYNTAX_ERROR_MISSING_TOKEN,
|
|
|
|
PAC_SYNTAX_ERROR_ODD_TOKEN
|
|
|
|
|
|
|
|
} pac_syntax_error_e;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
2023-11-28 21:21:23 +00:00
|
|
|
PAC_NAMING_ERROR_INVALID_RULE_NAME
|
2023-11-28 20:25:53 +00:00
|
|
|
|
|
|
|
} pac_naming_error_e;
|
|
|
|
|
|
|
|
typedef struct pac_syntax_error
|
|
|
|
{
|
|
|
|
usz_t line;
|
|
|
|
usz_t column;
|
|
|
|
|
|
|
|
pac_syntax_error_e type;
|
|
|
|
union pac_syntax_error_specifics
|
|
|
|
{
|
|
|
|
struct pac_syntax_error_stray
|
|
|
|
{
|
|
|
|
rune_t sign;
|
|
|
|
} stray;
|
|
|
|
|
|
|
|
struct pac_syntax_error_missing_token
|
|
|
|
{
|
|
|
|
char *wanted_token;
|
|
|
|
char *hint;
|
|
|
|
} missing_token;
|
|
|
|
|
|
|
|
struct pac_syntax_error_odd_token
|
|
|
|
{
|
|
|
|
usz_t num_valid_options;
|
|
|
|
char *valid_options[16];
|
|
|
|
char *found_token;
|
|
|
|
char *hint;
|
|
|
|
} odd_token;
|
|
|
|
|
|
|
|
} specifics;
|
|
|
|
|
|
|
|
} pac_syntax_error_s;
|
|
|
|
|
|
|
|
typedef struct pac_naming_error
|
|
|
|
{
|
|
|
|
usz_t line;
|
|
|
|
usz_t column;
|
|
|
|
|
|
|
|
pac_naming_error_e type;
|
|
|
|
union pac_naming_error_specifics
|
|
|
|
{
|
|
|
|
struct pac_naming_error_invalid_rule_name
|
|
|
|
{
|
|
|
|
char *given_rule_name;
|
|
|
|
} invalid_rule_name;
|
|
|
|
} specifics;
|
|
|
|
|
|
|
|
} pac_naming_error_s;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct pac_error
|
|
|
|
{
|
|
|
|
pac_error_e type;
|
|
|
|
union pac_error_data
|
|
|
|
{
|
|
|
|
pac_syntax_error_s syntax_error;
|
|
|
|
pac_naming_error_s naming_error;
|
|
|
|
} specifics;
|
|
|
|
|
|
|
|
} pac_error_s;
|
|
|
|
|
|
|
|
typedef struct pac_logger
|
|
|
|
{
|
|
|
|
usz_t allocated_errors;
|
|
|
|
usz_t num_errors;
|
|
|
|
pac_error_s *errors;
|
|
|
|
|
|
|
|
pac_arena_s string_arena;
|
|
|
|
|
|
|
|
} pac_logger_s;
|
|
|
|
|
|
|
|
pac_logger_s pac_create_logger ();
|
|
|
|
void pac_log_syntax_error (pac_logger_s *logger, pac_syntax_error_s error);
|
|
|
|
void pac_log_naming_error (pac_logger_s *logger, pac_naming_error_s error);
|
|
|
|
|
|
|
|
void * pac_log_alloc (pac_logger_s *logger, usz_t num_bytes);
|
|
|
|
|
|
|
|
#endif // PARCEL_LOGGER_H
|