Parcel/code/inc/parcel.h

85 lines
1.9 KiB
C
Raw Normal View History

2023-11-26 18:49:54 +00:00
#ifndef PARCEL_H
#define PARCEL_H
#include <utility.h>
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-26 18:49:54 +00:00
pac_grammar_s pac_convert_grammar (char *source);
void pac_delete_grammar (pac_grammar_s grammar);
void pac_display_log (pac_grammar_s grammar);
void pac_display_grammar (pac_grammar_s grammar);
2023-11-26 18:49:54 +00:00
#endif // PARCEL_H