#ifndef HERB_ERRORS_H #define HERB_ERRORS_H #include "errors.h" #include "location/location.h" #include "location/position.h" #include "lexer/token.h" #include "lib/hb_allocator.h" #include "lib/hb_array.h" #include "lib/hb_buffer.h" #include "lib/hb_string.h" struct PARSER_OPTIONS_STRUCT; typedef enum { <%- errors.each do |error| -%> <%= error.type.upcase %>, <%- end -%> } error_type_T; typedef struct ERROR_STRUCT { error_type_T type; location_T location; hb_string_T message; } ERROR_T; <%- errors.each do |error| -%> <%- arguments = error.fields.any? ? error.fields.map { |field| [field.c_type, " ", field.name, ";"].join }.join("\n ") : "/* no additional fields */" -%> typedef struct { ERROR_T base; <%= arguments %> } <%= error.struct_type %>; <%- end -%> <%- errors.each do |error| -%> <%- error_arguments = error.fields.any? ? error.fields.map { |field| [field.c_type, " ", field.name].join } : [] -%> <%- arguments = error_arguments + ["position_T start", "position_T end", "hb_allocator_T* allocator"] -%> <%= error.struct_type %>* <%= error.human %>_init(<%= arguments.join(", ") %>); void append_<%= error.human %>(<%= (arguments + ["hb_array_T** errors", "const struct PARSER_OPTIONS_STRUCT* options"]).join(", ") %>); <%- end -%> void error_init(ERROR_T* error, error_type_T type, position_T start, position_T end); size_t error_sizeof(void); error_type_T error_type(ERROR_T* error); hb_string_T error_message(ERROR_T* error); hb_string_T error_type_to_string(ERROR_T* error); hb_string_T error_human_type(ERROR_T* error); void error_free(ERROR_T* error, hb_allocator_T* allocator); #ifndef HERB_EXCLUDE_PRETTYPRINT void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, hb_buffer_T* buffer); void error_pretty_print_array( const char* name, hb_array_T* array, size_t indent, size_t relative_indent, bool last_property, hb_buffer_T* buffer ); #endif #endif