-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraon.h
More file actions
120 lines (103 loc) · 2.87 KB
/
raon.h
File metadata and controls
120 lines (103 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef RAON_H
#define RAON_H
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
enum raon_token_type {
// symbols
raon_token_type_equal,
raon_token_type_newline,
raon_token_type_comma,
raon_token_type_block_open,
raon_token_type_block_close,
raon_token_type_array_open,
raon_token_type_array_close,
// value types
raon_token_type_string,
raon_token_type_field,
raon_token_type_bool,
raon_token_type_int,
// used to indicate that an error ocurred
raon_token_type_error,
};
struct raon_token {
size_t from_x, from_y;
size_t to_x, to_y;
enum raon_token_type type;
union {
char *string_val;
intptr_t int_val;
char char_val;
bool bool_val;
};
};
struct raon_lexer {
bool start;
size_t curr_idx;
size_t curr_x, curr_y;
char *str;
size_t str_len;
};
struct raon_parser {
size_t curr_idx;
struct raon_token_vec *tokens;
};
enum raon_value_type {
raon_value_type_string,
raon_value_type_int,
raon_value_type_bool,
raon_value_type_block,
raon_value_type_error,
raon_value_type_array,
};
struct raon_parser_value {
enum raon_value_type type;
union {
char *string_val;
intptr_t int_val;
bool bool_val;
struct raon_parser_vec *block_val;
struct raon_value_vec *array_val;
};
};
struct raon_parser_array {
enum raon_value_type type;
struct raon_value_vec *values;
};
enum raon_field_type {
raon_field_type_string,
raon_field_type_int,
raon_field_type_error,
};
struct raon_parser_entry {
enum raon_field_type field_type;
union {
char *string_field;
intptr_t int_field;
};
struct raon_parser_value value;
};
// INTENDED PUBLIC API
struct raon_lexer raon_lexer_init_from_str(char *str);
struct raon_lexer raon_lexer_init_from_file(char *filepath);
struct raon_token_vec *raon_lexer_lex(struct raon_lexer *lex);
void raon_lexer_free(struct raon_lexer *lex);
struct raon_parser raon_parser_init(struct raon_token_vec *tokens);
struct raon_parser_vec *raon_parser_parse(struct raon_parser *parser);
struct raon_token_vec;
struct raon_parser_vec;
void raon_token_vec_free(struct raon_token_vec *vec);
void raon_parser_vec_free(struct raon_parser_vec *vec);
// MOSTLY USED INTERNALLY
char raon_lexer_peek(struct raon_lexer *lex);
void raon_lexer_eat(struct raon_lexer *lex);
struct raon_token raon_lexer_lex_number(struct raon_lexer *lex);
struct raon_token raon_lexer_lex_string(struct raon_lexer *lex);
struct raon_token raon_lexer_lex_ident(struct raon_lexer *lex);
struct raon_token raon_parser_peek(struct raon_parser *parser);
void raon_parser_eat(struct raon_parser *parser);
struct raon_parser_vec *raon_parser_parse_block(struct raon_parser *parser);
struct raon_parser_entry raon_parser_parse_entry(struct raon_parser *parser);
struct raon_parser_value raon_parser_parse_value(struct raon_parser *parser);
struct raon_value_vec *raon_parser_parse_array(struct raon_parser *parser);
#endif