Parcel/core-parser/inc/ast.h

98 lines
2.4 KiB
C
Raw Normal View History

2023-11-26 18:49:54 +00:00
#ifndef PARCEL_AST_H
#define PARCEL_AST_H
#include <utility.h>
2023-11-28 21:21:23 +00:00
#include <logger.h>
2023-11-28 15:01:46 +00:00
#include <tokenizer.h>
2023-11-26 18:49:54 +00:00
typedef struct pac_ast pac_ast_s;
typedef struct pac_ast_rule pac_ast_rule_s;
typedef struct pac_ast_variant pac_ast_variant_s;
typedef struct pac_ast_literal pac_ast_literal_s;
typedef struct pac_ast_reference pac_ast_reference_s;
typedef struct pac_ast_item pac_ast_item_s;
struct pac_ast
{
usz_t num_rules;
pac_ast_rule_s *rules;
};
struct pac_ast_rule
{
char *name;
usz_t num_variants;
pac_ast_variant_s *variants;
};
struct pac_ast_variant
{
usz_t num_items;
pac_ast_item_s *items;
};
// pac_ast_reference: Also called non-terminal, a reference is an item
// which represents all the contents of another rule.
struct pac_ast_reference
{
usz_t len_name;
char *name;
};
struct pac_ast_literal
{
usz_t length;
char *string;
};
2023-11-28 15:21:50 +00:00
// pac_ast_set_e: An enumeration of all sets known in Parcel's AST.
2023-11-26 18:49:54 +00:00
//
2023-11-28 15:21:50 +00:00
// Sets are descriptions which describe a rough format of token, like
2023-11-26 18:49:54 +00:00
// with variable names; the format is known, but the actual name isn't.
typedef enum
{
2023-11-28 15:21:50 +00:00
PAC_AST_SET_RUNE,
PAC_AST_SET_WORD,
PAC_AST_SET_INTEGER,
PAC_AST_SET_FLOAT
2023-11-26 18:49:54 +00:00
2023-11-28 15:21:50 +00:00
} pac_ast_set_e;
2023-11-26 18:49:54 +00:00
2023-11-28 15:01:46 +00:00
typedef enum
{
PAC_AST_ITEM_INVALID = 0x00,
PAC_AST_ITEM_REFERENCE,
PAC_AST_ITEM_LITERAL,
2023-11-28 15:21:50 +00:00
PAC_AST_ITEM_SET
2023-11-28 15:01:46 +00:00
} pac_ast_item_e;
2023-11-26 18:49:54 +00:00
struct pac_ast_item
{
2023-11-28 15:01:46 +00:00
pac_ast_item_e type;
union pac_ast_item_data
2023-11-26 18:49:54 +00:00
{
pac_ast_literal_s literal;
2023-11-28 15:21:50 +00:00
pac_ast_set_e set;
2023-11-28 15:01:46 +00:00
pac_ast_reference_s reference;
2023-11-26 18:49:54 +00:00
} data;
};
2023-11-28 21:21:23 +00:00
typedef struct pac_ast_grower
{
pac_tlist_s *token_list;
pac_logger_s logger;
bool_t failed;
} pac_ast_grower_s;
pac_ast_s pac_grow_ast (pac_tlist_s tokens);
bool_t pac_ast_handle_invalid_reference_name_token (pac_ast_grower_s *grower);
bool_t pac_ast_handle_missing_reference_close_tag (pac_ast_grower_s *grower);
bool_t pac_ast_handle_reference_with_equals_sign (pac_ast_grower_s *grower);
2023-11-28 15:01:46 +00:00
2023-11-26 18:49:54 +00:00
#endif // PARCEL_AST_H