Parcel/core-parser/inc/parcel.h

89 lines
2.0 KiB
C
Raw Normal View History

2023-11-26 18:49:54 +00:00
#ifndef PARCEL_H
#define PARCEL_H
#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;
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
// 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;
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
} data;
2023-11-26 18:49:54 +00:00
};
struct pac_variant
2023-11-26 18:49:54 +00:00
{
usz_t num_items;
pac_item_s *items;
2023-11-26 18:49:54 +00:00
};
struct pac_rule
2023-11-26 18:49:54 +00:00
{
char *name;
2023-11-26 18:49:54 +00:00
usz_t num_variants;
pac_variant_s *variants;
2023-11-26 18:49:54 +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-29 13:00:43 +00:00
pac_grammar_s pac_convert_grammar (char *source, usz_t len_source);
void pac_delete_grammar (pac_grammar_s grammar);
void pac_display_log (pac_logger_s *logger);
void pac_display_grammar (pac_grammar_s grammar);
2023-11-26 18:49:54 +00:00
#endif // PARCEL_H