231 lines
5.9 KiB
C
231 lines
5.9 KiB
C
|
|
#ifndef PARCEL_LOGGER_H
|
|
#define PARCEL_LOGGER_H
|
|
|
|
#include <utility.h>
|
|
|
|
typedef enum
|
|
{
|
|
PAC_UNKNOWN_ERROR_TYPE = 0,
|
|
PAC_SYNTAX_ERROR,
|
|
PAC_NAMING_ERROR,
|
|
PAC_VALIDATION_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_INVALID_ITEM,
|
|
PAC_SYNTAX_ERROR_MISSING_ITEM_SEPARATOR
|
|
|
|
} pac_syntax_error_e;
|
|
|
|
typedef enum
|
|
{
|
|
PAC_NAMING_ERROR_INVALID_REFERENCE_NAME,
|
|
PAC_NAMING_ERROR_INVALID_RULE_NAME
|
|
|
|
} pac_naming_error_e;
|
|
|
|
typedef enum
|
|
{
|
|
PAC_VALIDATION_ERROR_UNKNOWN_RULE,
|
|
PAC_VALIDATION_ERROR_RULE_NAMING_CONFLICT,
|
|
PAC_VALIDATION_ERROR_VARIANT_DUPLICATION,
|
|
PAC_VALIDATION_ERROR_CIRCULAR_REFERENCE
|
|
|
|
} pac_validation_error_e;
|
|
|
|
typedef enum
|
|
{
|
|
PAC_INTERNAL_ERROR_INVALID_ARGUMENTS,
|
|
PAC_INTERNAL_ERROR_INVALID_RETURNED_STATUS,
|
|
PAC_INTERNAL_ERROR_INVALID_FUNCTION_ENTRY,
|
|
PAC_INTERNAL_ERROR_NOT_IMPLEMENTED
|
|
|
|
} pac_internal_error_e;
|
|
|
|
typedef struct pac_source_location
|
|
{
|
|
char *file;
|
|
usz_t line;
|
|
usz_t column;
|
|
|
|
char *rule;
|
|
usz_t variant_index;
|
|
usz_t item_index;
|
|
|
|
} pac_source_location_s;
|
|
|
|
typedef struct pac_syntax_error
|
|
{
|
|
pac_source_location_s location;
|
|
|
|
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 *present_token;
|
|
char *hint;
|
|
} odd_token;
|
|
|
|
struct pac_syntax_error_invalid_item
|
|
{
|
|
char *present_construct;
|
|
char *hint;
|
|
|
|
} invalid_item;
|
|
|
|
} 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_validation_error
|
|
{
|
|
char *rule;
|
|
usz_t variant;
|
|
|
|
pac_validation_error_e type;
|
|
union pac_validation_error_specifics
|
|
{
|
|
struct pac_naming_error_unknown_rule
|
|
{
|
|
char *searched_name;
|
|
|
|
} unknown_rule;
|
|
|
|
struct pac_naming_error_rule_naming_conflict
|
|
{
|
|
char *rule_name;
|
|
usz_t original_line;
|
|
usz_t duplicate_line;
|
|
|
|
} rule_naming_conflict;
|
|
|
|
struct pac_naming_error_variant_duplication
|
|
{
|
|
char *rule_name;
|
|
usz_t original;
|
|
usz_t duplicate;
|
|
|
|
} variant_doubling;
|
|
|
|
} specifics;
|
|
|
|
} pac_validation_error_s;
|
|
|
|
typedef struct pac_internal_error
|
|
{
|
|
pac_internal_error_e type;
|
|
union pac_internal_error_specifics
|
|
{
|
|
struct pac_internal_error_invalid_arguments
|
|
{
|
|
char *argument;
|
|
char *value;
|
|
char *error_description;
|
|
|
|
} invalid_arguments;
|
|
|
|
struct pac_internal_error_invalid_returned_status
|
|
{
|
|
char *function;
|
|
char *immediate_returner;
|
|
char *value;
|
|
|
|
} invalid_returned_status;
|
|
|
|
struct pac_internal_error_invalid_function_entry
|
|
{
|
|
char *function;
|
|
char *error_description;
|
|
|
|
} invalid_function_entry;
|
|
|
|
struct pac_internal_error_not_implemented
|
|
{
|
|
char *feature_name;
|
|
char *feature_description;
|
|
|
|
} not_implemented;
|
|
|
|
} specifics;
|
|
|
|
} pac_internal_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;
|
|
pac_validation_error_s validation_error;
|
|
pac_internal_error_s internal_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_delete_logger (pac_logger_s logger);
|
|
|
|
void pac_display_log (pac_logger_s *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_validation_error (pac_logger_s *logger, pac_validation_error_s error);
|
|
void pac_log_internal_error (pac_logger_s *logger, pac_internal_error_s error);
|
|
|
|
void * pac_log_alloc (pac_logger_s *logger, usz_t num_bytes);
|
|
|
|
#endif // PARCEL_LOGGER_H
|