2023-11-26 18:49:54 +00:00
|
|
|
|
2023-11-29 19:08:42 +00:00
|
|
|
#ifndef PARCEL_GRAMMAR_PARSER_H
|
|
|
|
#define PARCEL_GRAMMAR_PARSER_H
|
2023-11-26 18:49:54 +00:00
|
|
|
|
2023-11-29 18:17:00 +00:00
|
|
|
#include <parcel/utility/utility.h>
|
2023-11-29 13:00:43 +00:00
|
|
|
#include <logger.h>
|
2023-11-26 18:49:54 +00:00
|
|
|
|
|
|
|
typedef struct pac_grammar pac_grammar_s;
|
2023-11-28 17:57:36 +00:00
|
|
|
typedef struct pac_rule pac_rule_s;
|
|
|
|
typedef struct pac_variant pac_variant_s;
|
|
|
|
typedef struct pac_literal pac_literal_s;
|
|
|
|
typedef struct pac_item pac_item_s;
|
2023-11-26 18:49:54 +00:00
|
|
|
|
2023-11-28 17:57:36 +00:00
|
|
|
// pac_item_e: The type of an item of a rule variant.
|
|
|
|
//
|
|
|
|
// A rule (-variant) is made up of multiple items which
|
|
|
|
// can have one of the types that are listed in this enum.
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PAC_ITEM_INVALID = 0x00,
|
|
|
|
PAC_ITEM_REFERENCE,
|
|
|
|
PAC_ITEM_LITERAL,
|
|
|
|
PAC_ITEM_SET,
|
|
|
|
|
|
|
|
} pac_item_e;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
PAC_SET_INVALID = 0x00,
|
|
|
|
PAC_SET_RUNE,
|
|
|
|
PAC_SET_WORD,
|
|
|
|
PAC_SET_INTEGER,
|
|
|
|
PAC_SET_FLOAT
|
|
|
|
} pac_set_e;
|
|
|
|
|
|
|
|
struct pac_literal
|
2023-11-26 18:49:54 +00:00
|
|
|
{
|
|
|
|
usz_t length;
|
2023-11-28 17:57:36 +00:00
|
|
|
char *string;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pac_item
|
|
|
|
{
|
|
|
|
pac_item_e type;
|
|
|
|
union pac_item_data
|
|
|
|
{
|
|
|
|
pac_literal_s literal;
|
|
|
|
pac_set_e set;
|
|
|
|
pac_rule_s *reference;
|
2023-11-26 18:49:54 +00:00
|
|
|
|
2023-11-28 17:57:36 +00:00
|
|
|
} data;
|
2023-11-26 18:49:54 +00:00
|
|
|
};
|
|
|
|
|
2023-11-28 17:57:36 +00:00
|
|
|
struct pac_variant
|
2023-11-26 18:49:54 +00:00
|
|
|
{
|
2023-11-28 17:57:36 +00:00
|
|
|
usz_t num_items;
|
|
|
|
pac_item_s *items;
|
2023-11-26 18:49:54 +00:00
|
|
|
};
|
|
|
|
|
2023-11-28 17:57:36 +00:00
|
|
|
struct pac_rule
|
2023-11-26 18:49:54 +00:00
|
|
|
{
|
2023-11-28 17:57:36 +00:00
|
|
|
char *name;
|
2023-11-26 18:49:54 +00:00
|
|
|
|
2023-11-28 17:57:36 +00:00
|
|
|
usz_t num_variants;
|
|
|
|
pac_variant_s *variants;
|
2023-11-26 18:49:54 +00:00
|
|
|
};
|
|
|
|
|
2023-11-28 17:57:36 +00:00
|
|
|
struct pac_grammar
|
|
|
|
{
|
|
|
|
usz_t len_source;
|
|
|
|
char *source;
|
|
|
|
|
|
|
|
usz_t num_rules;
|
|
|
|
pac_rule_s *rules;
|
2023-11-29 13:00:43 +00:00
|
|
|
|
|
|
|
pac_logger_s log;
|
|
|
|
pac_arena_s result_arena;
|
2023-11-28 17:57:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-29 13:00:43 +00:00
|
|
|
pac_grammar_s pac_convert_grammar (char *source, usz_t len_source);
|
2023-11-28 17:57:36 +00:00
|
|
|
void pac_delete_grammar (pac_grammar_s grammar);
|
|
|
|
|
2023-11-29 17:27:46 +00:00
|
|
|
void pac_display_log (pac_logger_s *logger);
|
2023-11-28 17:57:36 +00:00
|
|
|
void pac_display_grammar (pac_grammar_s grammar);
|
2023-11-26 18:49:54 +00:00
|
|
|
|
2023-11-29 19:08:42 +00:00
|
|
|
#endif // PARCEL_GRAMMAR_PARSER_H
|