Compare commits

..

2 Commits

Author SHA1 Message Date
Eric-Paul Ickhorn 18a66011ef Added Logger 2023-09-13 19:21:33 +02:00
Eric-Paul Ickhorn 8797c6d948 Added files of Syntax Parser 2023-09-11 17:11:58 +02:00
8 changed files with 143 additions and 0 deletions

47
inc/logging.h Normal file
View File

@ -0,0 +1,47 @@
#ifndef CARROT_LOGGING_H
#define CARROT_LOGGING_H
#include <utility.h>
typedef enum
{
CARROT_PARSER_ERROR_SEVERITY_NOTE,
CARROT_PARSER_ERROR_SEVERITY_WARNING,
CARROT_PARSER_ERROR_SEVERITY_ERROR,
CARROT_PARSER_ERROR_SEVERITY_UNRECOVERABLE_ERROR
} carrot_error_severity_e;
typedef enum
{
CARROT_PARSER_LOG_ITEM,
CARROT_SYNTAX_LOG_ITEM
} carrot_log_item_type_e;
typedef struct carrot_log carrot_log_s;
typedef struct carrot_log_item carrot_log_item_s;
typedef struct carrot_log_message carrot_log_message_s;
struct carrot_log_message
{
carrot_error_severity_e severity;
cstr_s text;
};
struct carrot_log
{
u32_t capacity;
u32_t length;
carrot_log_message_s *items;
};
carrot_log_s carrot_create_log ();
void carrot_issue_note (carrot_log_s *log, char *message);
void carrot_issue_warning (carrot_log_s *log, char *message);
void carrot_issue_error (carrot_log_s *log, char *message);
void carrot_issue_unrecoverable_error (carrot_log_s *log, char *message);
#endif // CARROT_LOGGING_H

36
inc/utility.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef CARROT_UTILITY_H
#define CARROT_UTILITY_H
#define FALSE ((bool_t) 0)
#define TRUE ((bool_t) 1)
#define NULL ((void *) 0)
typedef signed char s8_t;
typedef signed short s16_t;
typedef signed int s32_t;
typedef signed long s64_t;
typedef unsigned char u8_t;
typedef unsigned short u16_t;
typedef unsigned int u32_t;
typedef unsigned long u64_t;
typedef u8_t bool_t;
typedef struct str_s
{
u32_t len_text;
char *text;
} cstr_s;
// Not implemented
cstr_s cstr_join (cstr_s string1, cstr_s string2);
// Not implemented
bool_t cstr_split (cstr_s string, u32_t middle, cstr_s *first, cstr_s *second);
cstr_s carrot_wrap_chars (char *chars)
#endif

37
src/logging.c Normal file
View File

@ -0,0 +1,37 @@
#include <logging.h>
carrot_log_s carrot_create_log()
{
carrot_log_s logger;
logger.capacity = 8192;
logger.length = 0;
logger.items = calloc(sizeof(carrot_log_message_s), logger.capacity);
return logger;
}
void carrot_issue_note(carrot_log_s *log, char *message)
{
log->items[log->length].text = carrot_wrap_chars(message);
log->items[log->length].severity = CARROT_PARSER_ERROR_SEVERITY_NOTE;
}
void carrot_issue_warning(carrot_log_s *log, char *message)
{
log->items[log->length].text = carrot_wrap_chars(message);
log->items[log->length].severity = CARROT_PARSER_ERROR_SEVERITY_WARNING;
}
void carrot_issue_error(carrot_log_s *log, char *message)
{
log->items[log->length].text = carrot_wrap_chars(message);
log->items[log->length].severity = CARROT_PARSER_ERROR_SEVERITY_ERROR;
}
void carrot_issue_unrecoverable_error(carrot_log_s *log, char *message)
{
log->items[log->length].text = carrot_wrap_chars(message);
log->items[log->length].severity = CARROT_PARSER_ERROR_SEVERITY_UNRECOVERABLE_ERROR;
}

3
src/syntax_parser.c Normal file
View File

@ -0,0 +1,3 @@
#include <definition.h>

View File

@ -0,0 +1,3 @@
#include <definition.h>

3
src/syntax_rule_parser.c Normal file
View File

@ -0,0 +1,3 @@
#include <definition.h>

3
src/syntax_unit_parser.c Normal file
View File

@ -0,0 +1,3 @@
#include <definition.h>

11
src/utility.c Normal file
View File

@ -0,0 +1,11 @@
#include <utility.h>
cstr_s carrot_wrap_chars(char *chars)
{
cstr_s result;
result.len_text = strlen(chars);
result.text = malloc(result.len_text);
memcpy(result.text, chars, result.len_text);
return result;
}