92 lines
2.3 KiB
C
92 lines
2.3 KiB
C
|
|
||
|
#ifndef CARROT_DEFINITION_GENERATOR_H
|
||
|
#define CARROT_DEFINITION_GENERATOR_H
|
||
|
|
||
|
#include <stdbool.h>
|
||
|
#include <stdint.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include <tokenizer.h>
|
||
|
|
||
|
typedef struct carrot_definition carrot_definition_s;
|
||
|
typedef struct carrot_rule carrot_rule_s;
|
||
|
typedef struct carrot_compound carrot_compound_s;
|
||
|
typedef struct carrot_element carrot_element_s;
|
||
|
typedef struct carrot_end_node carrot_end_node_s;
|
||
|
|
||
|
struct carrot_definition
|
||
|
{
|
||
|
uint32_t num_rules;
|
||
|
carrot_rule_s *rules;
|
||
|
};
|
||
|
|
||
|
struct carrot_rule
|
||
|
{
|
||
|
uint32_t len_name;
|
||
|
char *name;
|
||
|
|
||
|
uint32_t num_elements;
|
||
|
carrot_element_s *elements;
|
||
|
};
|
||
|
|
||
|
struct carrot_compound
|
||
|
{
|
||
|
carrot_rule_s *up;
|
||
|
|
||
|
uint32_t num_rules;
|
||
|
carrot_rule_s *rules;
|
||
|
};
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
CARROT_ELEMENT_RULE_INSERTION,
|
||
|
CARROT_ELEMENT_PATTERN,
|
||
|
CARROT_ELEMENT_RAW_LITERAL
|
||
|
|
||
|
} carrot_element_e;
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
CARROT_PATTERN_INVALID,
|
||
|
CARROT_PATTERN_WORD, // Keyword: "|word|"
|
||
|
CARROT_PATTERN_KEYWORD, // Keyword: "|keyword|" (belonging to a list of user-defined keywords
|
||
|
CARROT_PATTERN_NUMBER // Keyword: "|number|"
|
||
|
|
||
|
} carrot_pattern_e;
|
||
|
|
||
|
struct carrot_element
|
||
|
{
|
||
|
// char *text;
|
||
|
|
||
|
carrot_element_e type;
|
||
|
union carrot_specific_literal
|
||
|
{
|
||
|
struct carrot_tag_name
|
||
|
{
|
||
|
uint32_t len_name;
|
||
|
char *name;
|
||
|
|
||
|
} nonterminal;
|
||
|
|
||
|
struct carrot_pattern
|
||
|
{
|
||
|
carrot_pattern_e value;
|
||
|
|
||
|
} pattern;
|
||
|
|
||
|
struct carrot_raw_literal
|
||
|
{
|
||
|
uint32_t num_bytes;
|
||
|
char *bytes;
|
||
|
} raw_literal;
|
||
|
|
||
|
} specific;
|
||
|
};
|
||
|
|
||
|
carrot_definition_s carrot_parse_definition (carrot_token_stream_s *stream);
|
||
|
|
||
|
#endif // CARROT_DEFINITION_GENERATOR_H
|
||
|
|