Parcel/core-parser/inc/parcel.h

85 lines
1.9 KiB
C

#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;
// 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
{
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;
} data;
};
struct pac_variant
{
usz_t num_items;
pac_item_s *items;
};
struct pac_rule
{
char *name;
usz_t num_variants;
pac_variant_s *variants;
};
struct pac_grammar
{
usz_t len_source;
char *source;
usz_t num_rules;
pac_rule_s *rules;
};
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);
#endif // PARCEL_H