herb 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/{LICENSE → LICENSE.txt} +4 -3
- data/Makefile +121 -0
- data/README.md +102 -107
- data/Rakefile +184 -0
- data/exe/herb +5 -0
- data/ext/herb/error_helpers.c +302 -0
- data/ext/herb/error_helpers.h +15 -0
- data/ext/herb/extconf.rb +75 -0
- data/ext/herb/extension.c +110 -0
- data/ext/herb/extension.h +6 -0
- data/ext/herb/extension_helpers.c +117 -0
- data/ext/herb/extension_helpers.h +24 -0
- data/ext/herb/nodes.c +936 -0
- data/ext/herb/nodes.h +12 -0
- data/herb.gemspec +49 -0
- data/lib/herb/ast/node.rb +61 -0
- data/lib/herb/ast/nodes.rb +1542 -0
- data/lib/herb/ast.rb +6 -0
- data/lib/herb/cli.rb +164 -0
- data/lib/herb/errors.rb +352 -0
- data/lib/herb/lex_result.rb +20 -0
- data/lib/herb/libherb/array.rb +48 -0
- data/lib/herb/libherb/ast_node.rb +47 -0
- data/lib/herb/libherb/buffer.rb +53 -0
- data/lib/herb/libherb/extract_result.rb +17 -0
- data/lib/herb/libherb/lex_result.rb +29 -0
- data/lib/herb/libherb/libherb.rb +49 -0
- data/lib/herb/libherb/parse_result.rb +17 -0
- data/lib/herb/libherb/token.rb +43 -0
- data/lib/herb/libherb.rb +32 -0
- data/lib/herb/location.rb +42 -0
- data/lib/herb/parse_result.rb +26 -0
- data/lib/herb/position.rb +36 -0
- data/lib/herb/project.rb +361 -0
- data/lib/herb/range.rb +40 -0
- data/lib/herb/result.rb +21 -0
- data/lib/herb/token.rb +43 -0
- data/lib/herb/token_list.rb +11 -0
- data/lib/herb/version.rb +5 -0
- data/lib/herb.rb +21 -68
- data/src/analyze.c +989 -0
- data/src/analyze_helpers.c +241 -0
- data/src/analyzed_ruby.c +35 -0
- data/src/array.c +137 -0
- data/src/ast_node.c +81 -0
- data/src/ast_nodes.c +866 -0
- data/src/ast_pretty_print.c +588 -0
- data/src/buffer.c +199 -0
- data/src/errors.c +740 -0
- data/src/extract.c +110 -0
- data/src/herb.c +103 -0
- data/src/html_util.c +143 -0
- data/src/include/analyze.h +36 -0
- data/src/include/analyze_helpers.h +43 -0
- data/src/include/analyzed_ruby.h +33 -0
- data/src/include/array.h +33 -0
- data/src/include/ast_node.h +35 -0
- data/src/include/ast_nodes.h +303 -0
- data/src/include/ast_pretty_print.h +17 -0
- data/src/include/buffer.h +36 -0
- data/src/include/errors.h +125 -0
- data/src/include/extract.h +20 -0
- data/src/include/herb.h +32 -0
- data/src/include/html_util.h +13 -0
- data/src/include/io.h +9 -0
- data/src/include/json.h +28 -0
- data/src/include/lexer.h +13 -0
- data/src/include/lexer_peek_helpers.h +23 -0
- data/src/include/lexer_struct.h +32 -0
- data/src/include/location.h +25 -0
- data/src/include/macros.h +10 -0
- data/src/include/memory.h +12 -0
- data/src/include/parser.h +22 -0
- data/src/include/parser_helpers.h +33 -0
- data/src/include/position.h +22 -0
- data/src/include/pretty_print.h +53 -0
- data/src/include/prism_helpers.h +18 -0
- data/src/include/range.h +23 -0
- data/src/include/ruby_parser.h +6 -0
- data/src/include/token.h +25 -0
- data/src/include/token_matchers.h +21 -0
- data/src/include/token_struct.h +51 -0
- data/src/include/util.h +25 -0
- data/src/include/version.h +6 -0
- data/src/include/visitor.h +11 -0
- data/src/io.c +30 -0
- data/src/json.c +205 -0
- data/src/lexer.c +284 -0
- data/src/lexer_peek_helpers.c +59 -0
- data/src/location.c +41 -0
- data/src/main.c +162 -0
- data/src/memory.c +53 -0
- data/src/parser.c +704 -0
- data/src/parser_helpers.c +161 -0
- data/src/position.c +33 -0
- data/src/pretty_print.c +242 -0
- data/src/prism_helpers.c +50 -0
- data/src/range.c +38 -0
- data/src/ruby_parser.c +47 -0
- data/src/token.c +194 -0
- data/src/token_matchers.c +32 -0
- data/src/util.c +128 -0
- data/src/visitor.c +321 -0
- metadata +126 -82
- data/test/helper.rb +0 -7
- data/test/helpers_test.rb +0 -25
- data/test/parsing_test.rb +0 -110
@@ -0,0 +1,303 @@
|
|
1
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/src/include/ast_nodes.h.erb
|
3
|
+
|
4
|
+
#ifndef HERB_AST_NODES_H
|
5
|
+
#define HERB_AST_NODES_H
|
6
|
+
|
7
|
+
#include <stdbool.h>
|
8
|
+
#include <prism.h>
|
9
|
+
|
10
|
+
#include "array.h"
|
11
|
+
#include "buffer.h"
|
12
|
+
#include "position.h"
|
13
|
+
#include "location.h"
|
14
|
+
#include "token_struct.h"
|
15
|
+
#include "analyzed_ruby.h"
|
16
|
+
|
17
|
+
typedef enum {
|
18
|
+
AST_DOCUMENT_NODE,
|
19
|
+
AST_LITERAL_NODE,
|
20
|
+
AST_HTML_OPEN_TAG_NODE,
|
21
|
+
AST_HTML_CLOSE_TAG_NODE,
|
22
|
+
AST_HTML_SELF_CLOSE_TAG_NODE,
|
23
|
+
AST_HTML_ELEMENT_NODE,
|
24
|
+
AST_HTML_ATTRIBUTE_VALUE_NODE,
|
25
|
+
AST_HTML_ATTRIBUTE_NAME_NODE,
|
26
|
+
AST_HTML_ATTRIBUTE_NODE,
|
27
|
+
AST_HTML_TEXT_NODE,
|
28
|
+
AST_HTML_COMMENT_NODE,
|
29
|
+
AST_HTML_DOCTYPE_NODE,
|
30
|
+
AST_WHITESPACE_NODE,
|
31
|
+
AST_ERB_CONTENT_NODE,
|
32
|
+
AST_ERB_END_NODE,
|
33
|
+
AST_ERB_ELSE_NODE,
|
34
|
+
AST_ERB_IF_NODE,
|
35
|
+
AST_ERB_BLOCK_NODE,
|
36
|
+
AST_ERB_WHEN_NODE,
|
37
|
+
AST_ERB_CASE_NODE,
|
38
|
+
AST_ERB_WHILE_NODE,
|
39
|
+
AST_ERB_UNTIL_NODE,
|
40
|
+
AST_ERB_FOR_NODE,
|
41
|
+
AST_ERB_RESCUE_NODE,
|
42
|
+
AST_ERB_ENSURE_NODE,
|
43
|
+
AST_ERB_BEGIN_NODE,
|
44
|
+
AST_ERB_UNLESS_NODE,
|
45
|
+
} ast_node_type_T;
|
46
|
+
|
47
|
+
typedef struct AST_NODE_STRUCT {
|
48
|
+
ast_node_type_T type;
|
49
|
+
location_T* location;
|
50
|
+
// maybe a range too?
|
51
|
+
array_T* errors;
|
52
|
+
} AST_NODE_T;
|
53
|
+
|
54
|
+
|
55
|
+
typedef struct AST_DOCUMENT_NODE_STRUCT {
|
56
|
+
AST_NODE_T base;
|
57
|
+
array_T* children;
|
58
|
+
} AST_DOCUMENT_NODE_T;
|
59
|
+
|
60
|
+
typedef struct AST_LITERAL_NODE_STRUCT {
|
61
|
+
AST_NODE_T base;
|
62
|
+
const char* content;
|
63
|
+
} AST_LITERAL_NODE_T;
|
64
|
+
|
65
|
+
typedef struct AST_HTML_OPEN_TAG_NODE_STRUCT {
|
66
|
+
AST_NODE_T base;
|
67
|
+
token_T* tag_opening;
|
68
|
+
token_T* tag_name;
|
69
|
+
token_T* tag_closing;
|
70
|
+
array_T* children;
|
71
|
+
bool is_void;
|
72
|
+
} AST_HTML_OPEN_TAG_NODE_T;
|
73
|
+
|
74
|
+
typedef struct AST_HTML_CLOSE_TAG_NODE_STRUCT {
|
75
|
+
AST_NODE_T base;
|
76
|
+
token_T* tag_opening;
|
77
|
+
token_T* tag_name;
|
78
|
+
token_T* tag_closing;
|
79
|
+
} AST_HTML_CLOSE_TAG_NODE_T;
|
80
|
+
|
81
|
+
typedef struct AST_HTML_SELF_CLOSE_TAG_NODE_STRUCT {
|
82
|
+
AST_NODE_T base;
|
83
|
+
token_T* tag_opening;
|
84
|
+
token_T* tag_name;
|
85
|
+
array_T* attributes;
|
86
|
+
token_T* tag_closing;
|
87
|
+
bool is_void;
|
88
|
+
} AST_HTML_SELF_CLOSE_TAG_NODE_T;
|
89
|
+
|
90
|
+
typedef struct AST_HTML_ELEMENT_NODE_STRUCT {
|
91
|
+
AST_NODE_T base;
|
92
|
+
struct AST_HTML_OPEN_TAG_NODE_STRUCT* open_tag;
|
93
|
+
token_T* tag_name;
|
94
|
+
array_T* body;
|
95
|
+
struct AST_HTML_CLOSE_TAG_NODE_STRUCT* close_tag;
|
96
|
+
bool is_void;
|
97
|
+
} AST_HTML_ELEMENT_NODE_T;
|
98
|
+
|
99
|
+
typedef struct AST_HTML_ATTRIBUTE_VALUE_NODE_STRUCT {
|
100
|
+
AST_NODE_T base;
|
101
|
+
token_T* open_quote;
|
102
|
+
array_T* children;
|
103
|
+
token_T* close_quote;
|
104
|
+
bool quoted;
|
105
|
+
} AST_HTML_ATTRIBUTE_VALUE_NODE_T;
|
106
|
+
|
107
|
+
typedef struct AST_HTML_ATTRIBUTE_NAME_NODE_STRUCT {
|
108
|
+
AST_NODE_T base;
|
109
|
+
token_T* name;
|
110
|
+
} AST_HTML_ATTRIBUTE_NAME_NODE_T;
|
111
|
+
|
112
|
+
typedef struct AST_HTML_ATTRIBUTE_NODE_STRUCT {
|
113
|
+
AST_NODE_T base;
|
114
|
+
struct AST_HTML_ATTRIBUTE_NAME_NODE_STRUCT* name;
|
115
|
+
token_T* equals;
|
116
|
+
struct AST_HTML_ATTRIBUTE_VALUE_NODE_STRUCT* value;
|
117
|
+
} AST_HTML_ATTRIBUTE_NODE_T;
|
118
|
+
|
119
|
+
typedef struct AST_HTML_TEXT_NODE_STRUCT {
|
120
|
+
AST_NODE_T base;
|
121
|
+
const char* content;
|
122
|
+
} AST_HTML_TEXT_NODE_T;
|
123
|
+
|
124
|
+
typedef struct AST_HTML_COMMENT_NODE_STRUCT {
|
125
|
+
AST_NODE_T base;
|
126
|
+
token_T* comment_start;
|
127
|
+
array_T* children;
|
128
|
+
token_T* comment_end;
|
129
|
+
} AST_HTML_COMMENT_NODE_T;
|
130
|
+
|
131
|
+
typedef struct AST_HTML_DOCTYPE_NODE_STRUCT {
|
132
|
+
AST_NODE_T base;
|
133
|
+
token_T* tag_opening;
|
134
|
+
array_T* children;
|
135
|
+
token_T* tag_closing;
|
136
|
+
} AST_HTML_DOCTYPE_NODE_T;
|
137
|
+
|
138
|
+
typedef struct AST_WHITESPACE_NODE_STRUCT {
|
139
|
+
AST_NODE_T base;
|
140
|
+
token_T* value;
|
141
|
+
} AST_WHITESPACE_NODE_T;
|
142
|
+
|
143
|
+
typedef struct AST_ERB_CONTENT_NODE_STRUCT {
|
144
|
+
AST_NODE_T base;
|
145
|
+
token_T* tag_opening;
|
146
|
+
token_T* content;
|
147
|
+
token_T* tag_closing;
|
148
|
+
analyzed_ruby_T* analyzed_ruby;
|
149
|
+
bool parsed;
|
150
|
+
bool valid;
|
151
|
+
} AST_ERB_CONTENT_NODE_T;
|
152
|
+
|
153
|
+
typedef struct AST_ERB_END_NODE_STRUCT {
|
154
|
+
AST_NODE_T base;
|
155
|
+
token_T* tag_opening;
|
156
|
+
token_T* content;
|
157
|
+
token_T* tag_closing;
|
158
|
+
} AST_ERB_END_NODE_T;
|
159
|
+
|
160
|
+
typedef struct AST_ERB_ELSE_NODE_STRUCT {
|
161
|
+
AST_NODE_T base;
|
162
|
+
token_T* tag_opening;
|
163
|
+
token_T* content;
|
164
|
+
token_T* tag_closing;
|
165
|
+
array_T* statements;
|
166
|
+
} AST_ERB_ELSE_NODE_T;
|
167
|
+
|
168
|
+
typedef struct AST_ERB_IF_NODE_STRUCT {
|
169
|
+
AST_NODE_T base;
|
170
|
+
token_T* tag_opening;
|
171
|
+
token_T* content;
|
172
|
+
token_T* tag_closing;
|
173
|
+
array_T* statements;
|
174
|
+
AST_NODE_T* subsequent;
|
175
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
176
|
+
} AST_ERB_IF_NODE_T;
|
177
|
+
|
178
|
+
typedef struct AST_ERB_BLOCK_NODE_STRUCT {
|
179
|
+
AST_NODE_T base;
|
180
|
+
token_T* tag_opening;
|
181
|
+
token_T* content;
|
182
|
+
token_T* tag_closing;
|
183
|
+
array_T* body;
|
184
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
185
|
+
} AST_ERB_BLOCK_NODE_T;
|
186
|
+
|
187
|
+
typedef struct AST_ERB_WHEN_NODE_STRUCT {
|
188
|
+
AST_NODE_T base;
|
189
|
+
token_T* tag_opening;
|
190
|
+
token_T* content;
|
191
|
+
token_T* tag_closing;
|
192
|
+
array_T* statements;
|
193
|
+
} AST_ERB_WHEN_NODE_T;
|
194
|
+
|
195
|
+
typedef struct AST_ERB_CASE_NODE_STRUCT {
|
196
|
+
AST_NODE_T base;
|
197
|
+
token_T* tag_opening;
|
198
|
+
token_T* content;
|
199
|
+
token_T* tag_closing;
|
200
|
+
array_T* children;
|
201
|
+
array_T* conditions;
|
202
|
+
struct AST_ERB_ELSE_NODE_STRUCT* else_clause;
|
203
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
204
|
+
} AST_ERB_CASE_NODE_T;
|
205
|
+
|
206
|
+
typedef struct AST_ERB_WHILE_NODE_STRUCT {
|
207
|
+
AST_NODE_T base;
|
208
|
+
token_T* tag_opening;
|
209
|
+
token_T* content;
|
210
|
+
token_T* tag_closing;
|
211
|
+
array_T* statements;
|
212
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
213
|
+
} AST_ERB_WHILE_NODE_T;
|
214
|
+
|
215
|
+
typedef struct AST_ERB_UNTIL_NODE_STRUCT {
|
216
|
+
AST_NODE_T base;
|
217
|
+
token_T* tag_opening;
|
218
|
+
token_T* content;
|
219
|
+
token_T* tag_closing;
|
220
|
+
array_T* statements;
|
221
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
222
|
+
} AST_ERB_UNTIL_NODE_T;
|
223
|
+
|
224
|
+
typedef struct AST_ERB_FOR_NODE_STRUCT {
|
225
|
+
AST_NODE_T base;
|
226
|
+
token_T* tag_opening;
|
227
|
+
token_T* content;
|
228
|
+
token_T* tag_closing;
|
229
|
+
array_T* statements;
|
230
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
231
|
+
} AST_ERB_FOR_NODE_T;
|
232
|
+
|
233
|
+
typedef struct AST_ERB_RESCUE_NODE_STRUCT {
|
234
|
+
AST_NODE_T base;
|
235
|
+
token_T* tag_opening;
|
236
|
+
token_T* content;
|
237
|
+
token_T* tag_closing;
|
238
|
+
array_T* statements;
|
239
|
+
struct AST_ERB_RESCUE_NODE_STRUCT* subsequent;
|
240
|
+
} AST_ERB_RESCUE_NODE_T;
|
241
|
+
|
242
|
+
typedef struct AST_ERB_ENSURE_NODE_STRUCT {
|
243
|
+
AST_NODE_T base;
|
244
|
+
token_T* tag_opening;
|
245
|
+
token_T* content;
|
246
|
+
token_T* tag_closing;
|
247
|
+
array_T* statements;
|
248
|
+
} AST_ERB_ENSURE_NODE_T;
|
249
|
+
|
250
|
+
typedef struct AST_ERB_BEGIN_NODE_STRUCT {
|
251
|
+
AST_NODE_T base;
|
252
|
+
token_T* tag_opening;
|
253
|
+
token_T* content;
|
254
|
+
token_T* tag_closing;
|
255
|
+
array_T* statements;
|
256
|
+
struct AST_ERB_RESCUE_NODE_STRUCT* rescue_clause;
|
257
|
+
struct AST_ERB_ELSE_NODE_STRUCT* else_clause;
|
258
|
+
struct AST_ERB_ENSURE_NODE_STRUCT* ensure_clause;
|
259
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
260
|
+
} AST_ERB_BEGIN_NODE_T;
|
261
|
+
|
262
|
+
typedef struct AST_ERB_UNLESS_NODE_STRUCT {
|
263
|
+
AST_NODE_T base;
|
264
|
+
token_T* tag_opening;
|
265
|
+
token_T* content;
|
266
|
+
token_T* tag_closing;
|
267
|
+
array_T* statements;
|
268
|
+
struct AST_ERB_ELSE_NODE_STRUCT* else_clause;
|
269
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
270
|
+
} AST_ERB_UNLESS_NODE_T;
|
271
|
+
|
272
|
+
AST_DOCUMENT_NODE_T* ast_document_node_init(array_T* children, position_T* start_position, position_T* end_position, array_T* errors);
|
273
|
+
AST_LITERAL_NODE_T* ast_literal_node_init(const char* content, position_T* start_position, position_T* end_position, array_T* errors);
|
274
|
+
AST_HTML_OPEN_TAG_NODE_T* ast_html_open_tag_node_init(token_T* tag_opening, token_T* tag_name, token_T* tag_closing, array_T* children, bool is_void, position_T* start_position, position_T* end_position, array_T* errors);
|
275
|
+
AST_HTML_CLOSE_TAG_NODE_T* ast_html_close_tag_node_init(token_T* tag_opening, token_T* tag_name, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
|
276
|
+
AST_HTML_SELF_CLOSE_TAG_NODE_T* ast_html_self_close_tag_node_init(token_T* tag_opening, token_T* tag_name, array_T* attributes, token_T* tag_closing, bool is_void, position_T* start_position, position_T* end_position, array_T* errors);
|
277
|
+
AST_HTML_ELEMENT_NODE_T* ast_html_element_node_init(struct AST_HTML_OPEN_TAG_NODE_STRUCT* open_tag, token_T* tag_name, array_T* body, struct AST_HTML_CLOSE_TAG_NODE_STRUCT* close_tag, bool is_void, position_T* start_position, position_T* end_position, array_T* errors);
|
278
|
+
AST_HTML_ATTRIBUTE_VALUE_NODE_T* ast_html_attribute_value_node_init(token_T* open_quote, array_T* children, token_T* close_quote, bool quoted, position_T* start_position, position_T* end_position, array_T* errors);
|
279
|
+
AST_HTML_ATTRIBUTE_NAME_NODE_T* ast_html_attribute_name_node_init(token_T* name, position_T* start_position, position_T* end_position, array_T* errors);
|
280
|
+
AST_HTML_ATTRIBUTE_NODE_T* ast_html_attribute_node_init(struct AST_HTML_ATTRIBUTE_NAME_NODE_STRUCT* name, token_T* equals, struct AST_HTML_ATTRIBUTE_VALUE_NODE_STRUCT* value, position_T* start_position, position_T* end_position, array_T* errors);
|
281
|
+
AST_HTML_TEXT_NODE_T* ast_html_text_node_init(const char* content, position_T* start_position, position_T* end_position, array_T* errors);
|
282
|
+
AST_HTML_COMMENT_NODE_T* ast_html_comment_node_init(token_T* comment_start, array_T* children, token_T* comment_end, position_T* start_position, position_T* end_position, array_T* errors);
|
283
|
+
AST_HTML_DOCTYPE_NODE_T* ast_html_doctype_node_init(token_T* tag_opening, array_T* children, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
|
284
|
+
AST_WHITESPACE_NODE_T* ast_whitespace_node_init(token_T* value, position_T* start_position, position_T* end_position, array_T* errors);
|
285
|
+
AST_ERB_CONTENT_NODE_T* ast_erb_content_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, analyzed_ruby_T* analyzed_ruby, bool parsed, bool valid, position_T* start_position, position_T* end_position, array_T* errors);
|
286
|
+
AST_ERB_END_NODE_T* ast_erb_end_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
|
287
|
+
AST_ERB_ELSE_NODE_T* ast_erb_else_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, position_T* start_position, position_T* end_position, array_T* errors);
|
288
|
+
AST_ERB_IF_NODE_T* ast_erb_if_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, AST_NODE_T* subsequent, struct AST_ERB_END_NODE_STRUCT* end_node, position_T* start_position, position_T* end_position, array_T* errors);
|
289
|
+
AST_ERB_BLOCK_NODE_T* ast_erb_block_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* body, struct AST_ERB_END_NODE_STRUCT* end_node, position_T* start_position, position_T* end_position, array_T* errors);
|
290
|
+
AST_ERB_WHEN_NODE_T* ast_erb_when_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, position_T* start_position, position_T* end_position, array_T* errors);
|
291
|
+
AST_ERB_CASE_NODE_T* ast_erb_case_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* children, array_T* conditions, struct AST_ERB_ELSE_NODE_STRUCT* else_clause, struct AST_ERB_END_NODE_STRUCT* end_node, position_T* start_position, position_T* end_position, array_T* errors);
|
292
|
+
AST_ERB_WHILE_NODE_T* ast_erb_while_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, struct AST_ERB_END_NODE_STRUCT* end_node, position_T* start_position, position_T* end_position, array_T* errors);
|
293
|
+
AST_ERB_UNTIL_NODE_T* ast_erb_until_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, struct AST_ERB_END_NODE_STRUCT* end_node, position_T* start_position, position_T* end_position, array_T* errors);
|
294
|
+
AST_ERB_FOR_NODE_T* ast_erb_for_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, struct AST_ERB_END_NODE_STRUCT* end_node, position_T* start_position, position_T* end_position, array_T* errors);
|
295
|
+
AST_ERB_RESCUE_NODE_T* ast_erb_rescue_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, struct AST_ERB_RESCUE_NODE_STRUCT* subsequent, position_T* start_position, position_T* end_position, array_T* errors);
|
296
|
+
AST_ERB_ENSURE_NODE_T* ast_erb_ensure_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, position_T* start_position, position_T* end_position, array_T* errors);
|
297
|
+
AST_ERB_BEGIN_NODE_T* ast_erb_begin_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, struct AST_ERB_RESCUE_NODE_STRUCT* rescue_clause, struct AST_ERB_ELSE_NODE_STRUCT* else_clause, struct AST_ERB_ENSURE_NODE_STRUCT* ensure_clause, struct AST_ERB_END_NODE_STRUCT* end_node, position_T* start_position, position_T* end_position, array_T* errors);
|
298
|
+
AST_ERB_UNLESS_NODE_T* ast_erb_unless_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, array_T* statements, struct AST_ERB_ELSE_NODE_STRUCT* else_clause, struct AST_ERB_END_NODE_STRUCT* end_node, position_T* start_position, position_T* end_position, array_T* errors);
|
299
|
+
|
300
|
+
const char* ast_node_type_to_string(AST_NODE_T* node);
|
301
|
+
const char* ast_node_human_type(AST_NODE_T* node);
|
302
|
+
|
303
|
+
#endif
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/src/include/ast_pretty_print.h.erb
|
3
|
+
|
4
|
+
#ifndef HERB_AST_PRETTY_PRINT_H
|
5
|
+
#define HERB_AST_PRETTY_PRINT_H
|
6
|
+
|
7
|
+
#include "ast_nodes.h"
|
8
|
+
#include "buffer.h"
|
9
|
+
|
10
|
+
void ast_pretty_print_node(
|
11
|
+
AST_NODE_T* node,
|
12
|
+
size_t indent,
|
13
|
+
size_t relative_indent,
|
14
|
+
buffer_T* buffer
|
15
|
+
);
|
16
|
+
|
17
|
+
#endif
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#ifndef HERB_BUFFER_H
|
2
|
+
#define HERB_BUFFER_H
|
3
|
+
|
4
|
+
#include <stdbool.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
|
7
|
+
typedef struct BUFFER_STRUCT {
|
8
|
+
char* value;
|
9
|
+
size_t length;
|
10
|
+
size_t capacity;
|
11
|
+
} buffer_T;
|
12
|
+
|
13
|
+
bool buffer_init(buffer_T* buffer);
|
14
|
+
buffer_T buffer_new(void);
|
15
|
+
|
16
|
+
bool buffer_increase_capacity(buffer_T* buffer, size_t required_length);
|
17
|
+
bool buffer_reserve(buffer_T* buffer, size_t min_capacity);
|
18
|
+
|
19
|
+
void buffer_append(buffer_T* buffer, const char* text);
|
20
|
+
void buffer_append_with_length(buffer_T* buffer, const char* text, size_t length);
|
21
|
+
void buffer_append_char(buffer_T* buffer, char character);
|
22
|
+
void buffer_append_repeated(buffer_T* buffer, char character, size_t length);
|
23
|
+
void buffer_append_whitespace(buffer_T* buffer, size_t length);
|
24
|
+
void buffer_prepend(buffer_T* buffer, const char* text);
|
25
|
+
void buffer_concat(buffer_T* destination, buffer_T* source);
|
26
|
+
|
27
|
+
char* buffer_value(const buffer_T* buffer);
|
28
|
+
|
29
|
+
size_t buffer_length(const buffer_T* buffer);
|
30
|
+
size_t buffer_capacity(const buffer_T* buffer);
|
31
|
+
size_t buffer_sizeof(void);
|
32
|
+
|
33
|
+
void buffer_clear(buffer_T* buffer);
|
34
|
+
void buffer_free(buffer_T* buffer);
|
35
|
+
|
36
|
+
#endif
|
@@ -0,0 +1,125 @@
|
|
1
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/src/include/errors.h.erb
|
3
|
+
|
4
|
+
#ifndef HERB_ERRORS_H
|
5
|
+
#define HERB_ERRORS_H
|
6
|
+
|
7
|
+
#include "array.h"
|
8
|
+
#include "buffer.h"
|
9
|
+
#include "errors.h"
|
10
|
+
#include "location.h"
|
11
|
+
#include "position.h"
|
12
|
+
#include "token.h"
|
13
|
+
|
14
|
+
typedef enum {
|
15
|
+
UNEXPECTED_ERROR,
|
16
|
+
UNEXPECTED_TOKEN_ERROR,
|
17
|
+
MISSING_OPENING_TAG_ERROR,
|
18
|
+
MISSING_CLOSING_TAG_ERROR,
|
19
|
+
TAG_NAMES_MISMATCH_ERROR,
|
20
|
+
QUOTES_MISMATCH_ERROR,
|
21
|
+
VOID_ELEMENT_CLOSING_TAG_ERROR,
|
22
|
+
UNCLOSED_ELEMENT_ERROR,
|
23
|
+
RUBY_PARSE_ERROR,
|
24
|
+
} error_type_T;
|
25
|
+
|
26
|
+
typedef struct ERROR_STRUCT {
|
27
|
+
error_type_T type;
|
28
|
+
location_T* location;
|
29
|
+
char* message;
|
30
|
+
} ERROR_T;
|
31
|
+
|
32
|
+
|
33
|
+
typedef struct {
|
34
|
+
ERROR_T base;
|
35
|
+
const char* description;
|
36
|
+
const char* expected;
|
37
|
+
const char* found;
|
38
|
+
} UNEXPECTED_ERROR_T;
|
39
|
+
|
40
|
+
typedef struct {
|
41
|
+
ERROR_T base;
|
42
|
+
token_type_T expected_type;
|
43
|
+
token_T* found;
|
44
|
+
} UNEXPECTED_TOKEN_ERROR_T;
|
45
|
+
|
46
|
+
typedef struct {
|
47
|
+
ERROR_T base;
|
48
|
+
token_T* closing_tag;
|
49
|
+
} MISSING_OPENING_TAG_ERROR_T;
|
50
|
+
|
51
|
+
typedef struct {
|
52
|
+
ERROR_T base;
|
53
|
+
token_T* opening_tag;
|
54
|
+
} MISSING_CLOSING_TAG_ERROR_T;
|
55
|
+
|
56
|
+
typedef struct {
|
57
|
+
ERROR_T base;
|
58
|
+
token_T* opening_tag;
|
59
|
+
token_T* closing_tag;
|
60
|
+
} TAG_NAMES_MISMATCH_ERROR_T;
|
61
|
+
|
62
|
+
typedef struct {
|
63
|
+
ERROR_T base;
|
64
|
+
token_T* opening_quote;
|
65
|
+
token_T* closing_quote;
|
66
|
+
} QUOTES_MISMATCH_ERROR_T;
|
67
|
+
|
68
|
+
typedef struct {
|
69
|
+
ERROR_T base;
|
70
|
+
token_T* tag_name;
|
71
|
+
const char* expected;
|
72
|
+
const char* found;
|
73
|
+
} VOID_ELEMENT_CLOSING_TAG_ERROR_T;
|
74
|
+
|
75
|
+
typedef struct {
|
76
|
+
ERROR_T base;
|
77
|
+
token_T* opening_tag;
|
78
|
+
} UNCLOSED_ELEMENT_ERROR_T;
|
79
|
+
|
80
|
+
typedef struct {
|
81
|
+
ERROR_T base;
|
82
|
+
const char* error_message;
|
83
|
+
const char* diagnostic_id;
|
84
|
+
const char* level;
|
85
|
+
} RUBY_PARSE_ERROR_T;
|
86
|
+
|
87
|
+
UNEXPECTED_ERROR_T* unexpected_error_init(const char* description, const char* expected, const char* found, position_T* start, position_T* end);
|
88
|
+
void append_unexpected_error(const char* description, const char* expected, const char* found, position_T* start, position_T* end, array_T* errors);
|
89
|
+
UNEXPECTED_TOKEN_ERROR_T* unexpected_token_error_init(token_type_T expected_type, token_T* found, position_T* start, position_T* end);
|
90
|
+
void append_unexpected_token_error(token_type_T expected_type, token_T* found, position_T* start, position_T* end, array_T* errors);
|
91
|
+
MISSING_OPENING_TAG_ERROR_T* missing_opening_tag_error_init(token_T* closing_tag, position_T* start, position_T* end);
|
92
|
+
void append_missing_opening_tag_error(token_T* closing_tag, position_T* start, position_T* end, array_T* errors);
|
93
|
+
MISSING_CLOSING_TAG_ERROR_T* missing_closing_tag_error_init(token_T* opening_tag, position_T* start, position_T* end);
|
94
|
+
void append_missing_closing_tag_error(token_T* opening_tag, position_T* start, position_T* end, array_T* errors);
|
95
|
+
TAG_NAMES_MISMATCH_ERROR_T* tag_names_mismatch_error_init(token_T* opening_tag, token_T* closing_tag, position_T* start, position_T* end);
|
96
|
+
void append_tag_names_mismatch_error(token_T* opening_tag, token_T* closing_tag, position_T* start, position_T* end, array_T* errors);
|
97
|
+
QUOTES_MISMATCH_ERROR_T* quotes_mismatch_error_init(token_T* opening_quote, token_T* closing_quote, position_T* start, position_T* end);
|
98
|
+
void append_quotes_mismatch_error(token_T* opening_quote, token_T* closing_quote, position_T* start, position_T* end, array_T* errors);
|
99
|
+
VOID_ELEMENT_CLOSING_TAG_ERROR_T* void_element_closing_tag_error_init(token_T* tag_name, const char* expected, const char* found, position_T* start, position_T* end);
|
100
|
+
void append_void_element_closing_tag_error(token_T* tag_name, const char* expected, const char* found, position_T* start, position_T* end, array_T* errors);
|
101
|
+
UNCLOSED_ELEMENT_ERROR_T* unclosed_element_error_init(token_T* opening_tag, position_T* start, position_T* end);
|
102
|
+
void append_unclosed_element_error(token_T* opening_tag, position_T* start, position_T* end, array_T* errors);
|
103
|
+
RUBY_PARSE_ERROR_T* ruby_parse_error_init(const char* error_message, const char* diagnostic_id, const char* level, position_T* start, position_T* end);
|
104
|
+
void append_ruby_parse_error(const char* error_message, const char* diagnostic_id, const char* level, position_T* start, position_T* end, array_T* errors);
|
105
|
+
|
106
|
+
void error_init(ERROR_T* error, error_type_T type, position_T* start, position_T* end);
|
107
|
+
|
108
|
+
size_t error_sizeof(void);
|
109
|
+
error_type_T error_type(ERROR_T* error);
|
110
|
+
|
111
|
+
char* error_message(ERROR_T* error);
|
112
|
+
|
113
|
+
const char* error_type_to_string(ERROR_T* error);
|
114
|
+
const char* error_human_type(ERROR_T* error);
|
115
|
+
|
116
|
+
void error_free(ERROR_T* error);
|
117
|
+
|
118
|
+
void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, buffer_T* buffer);
|
119
|
+
|
120
|
+
void error_pretty_print_array(
|
121
|
+
const char* name, array_T* array, size_t indent, size_t relative_indent, bool last_property,
|
122
|
+
buffer_T* buffer
|
123
|
+
);
|
124
|
+
|
125
|
+
#endif
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#ifndef HERB_EXTRACT_H
|
2
|
+
#define HERB_EXTRACT_H
|
3
|
+
|
4
|
+
#include "buffer.h"
|
5
|
+
|
6
|
+
typedef enum {
|
7
|
+
HERB_EXTRACT_LANGUAGE_RUBY,
|
8
|
+
HERB_EXTRACT_LANGUAGE_HTML,
|
9
|
+
} herb_extract_language_T;
|
10
|
+
|
11
|
+
void herb_extract_ruby_to_buffer(const char* source, buffer_T* output);
|
12
|
+
void herb_extract_html_to_buffer(const char* source, buffer_T* output);
|
13
|
+
|
14
|
+
char* herb_extract_ruby_with_semicolons(const char* source);
|
15
|
+
void herb_extract_ruby_to_buffer_with_semicolons(const char* source, buffer_T* output);
|
16
|
+
|
17
|
+
char* herb_extract(const char* source, herb_extract_language_T language);
|
18
|
+
char* herb_extract_from_file(const char* path, herb_extract_language_T language);
|
19
|
+
|
20
|
+
#endif
|
data/src/include/herb.h
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef HERB_H
|
2
|
+
#define HERB_H
|
3
|
+
|
4
|
+
#include "array.h"
|
5
|
+
#include "ast_node.h"
|
6
|
+
#include "buffer.h"
|
7
|
+
#include "extract.h"
|
8
|
+
|
9
|
+
#include <stdint.h>
|
10
|
+
|
11
|
+
#ifdef __cplusplus
|
12
|
+
extern "C" {
|
13
|
+
#endif
|
14
|
+
|
15
|
+
void herb_lex_to_buffer(const char* source, buffer_T* output);
|
16
|
+
void herb_lex_json_to_buffer(const char* source, buffer_T* output);
|
17
|
+
|
18
|
+
array_T* herb_lex(const char* source);
|
19
|
+
array_T* herb_lex_file(const char* path);
|
20
|
+
|
21
|
+
AST_DOCUMENT_NODE_T* herb_parse(const char* source);
|
22
|
+
|
23
|
+
const char* herb_version(void);
|
24
|
+
const char* herb_prism_version(void);
|
25
|
+
|
26
|
+
void herb_free_tokens(array_T** tokens);
|
27
|
+
|
28
|
+
#ifdef __cplusplus
|
29
|
+
}
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#endif
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#ifndef HERB_HTML_UTIL_H
|
2
|
+
#define HERB_HTML_UTIL_H
|
3
|
+
|
4
|
+
#include <stdbool.h>
|
5
|
+
|
6
|
+
bool is_void_element(const char* tag_name);
|
7
|
+
bool is_html4_void_element(const char* tag_name);
|
8
|
+
|
9
|
+
char* html_opening_tag_string(const char* tag_name);
|
10
|
+
char* html_closing_tag_string(const char* tag_name);
|
11
|
+
char* html_self_closing_tag_string(const char* tag_name);
|
12
|
+
|
13
|
+
#endif
|
data/src/include/io.h
ADDED
data/src/include/json.h
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#ifndef HERB_JSON_H
|
2
|
+
#define HERB_JSON_H
|
3
|
+
|
4
|
+
#include "buffer.h"
|
5
|
+
|
6
|
+
void json_start_root_object(buffer_T* json);
|
7
|
+
void json_start_root_array(buffer_T* json);
|
8
|
+
|
9
|
+
void json_escape_string(buffer_T* json, const char* string);
|
10
|
+
|
11
|
+
void json_add_string(buffer_T* json, const char* key, const char* value);
|
12
|
+
void json_add_int(buffer_T* json, const char* key, int value);
|
13
|
+
void json_add_size_t(buffer_T* json, const char* key, size_t value);
|
14
|
+
void json_add_double(buffer_T* json, const char* key, double value);
|
15
|
+
void json_add_bool(buffer_T* json, const char* key, int value);
|
16
|
+
|
17
|
+
void json_add_raw_string(buffer_T* json, const char* string);
|
18
|
+
|
19
|
+
void json_start_object(buffer_T* json, const char* key);
|
20
|
+
void json_end_object(buffer_T* json);
|
21
|
+
|
22
|
+
void json_start_array(buffer_T* json, const char* key);
|
23
|
+
void json_end_array(buffer_T* json);
|
24
|
+
|
25
|
+
void json_double_to_string(double value, char* buffer);
|
26
|
+
void json_int_to_string(int value, char* buffer);
|
27
|
+
|
28
|
+
#endif
|
data/src/include/lexer.h
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#ifndef HERB_LEXER_H
|
2
|
+
#define HERB_LEXER_H
|
3
|
+
|
4
|
+
#include "lexer_struct.h"
|
5
|
+
#include "token_struct.h"
|
6
|
+
|
7
|
+
lexer_T* lexer_init(const char* source);
|
8
|
+
token_T* lexer_next_token(lexer_T* lexer);
|
9
|
+
token_T* lexer_error(lexer_T* lexer, const char* message);
|
10
|
+
|
11
|
+
void lexer_free(lexer_T* lexer);
|
12
|
+
|
13
|
+
#endif
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#ifndef HERB_LEXER_PEEK_H
|
2
|
+
#define HERB_LEXER_PEEK_H
|
3
|
+
|
4
|
+
#include "lexer_struct.h"
|
5
|
+
|
6
|
+
#include <stdbool.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <stdlib.h>
|
9
|
+
|
10
|
+
char lexer_peek(const lexer_T* lexer, int offset);
|
11
|
+
bool lexer_peek_for_doctype(const lexer_T* lexer, int offset);
|
12
|
+
|
13
|
+
bool lexer_peek_for_html_comment_start(const lexer_T* lexer, int offset);
|
14
|
+
bool lexer_peek_for_html_comment_end(const lexer_T* lexer, int offset);
|
15
|
+
|
16
|
+
bool lexer_peek_erb_close_tag(const lexer_T* lexer, int offset);
|
17
|
+
bool lexer_peek_erb_dash_close_tag(const lexer_T* lexer, int offset);
|
18
|
+
bool lexer_peek_erb_percent_close_tag(const lexer_T* lexer, int offset);
|
19
|
+
bool lexer_peek_erb_end(const lexer_T* lexer, int offset);
|
20
|
+
|
21
|
+
char lexer_backtrack(const lexer_T* lexer, int offset);
|
22
|
+
|
23
|
+
#endif
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#ifndef HERB_LEXER_STRUCT_H
|
2
|
+
#define HERB_LEXER_STRUCT_H
|
3
|
+
|
4
|
+
#include <stdbool.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
|
7
|
+
typedef enum {
|
8
|
+
STATE_DATA,
|
9
|
+
STATE_ERB_CONTENT,
|
10
|
+
STATE_ERB_CLOSE,
|
11
|
+
} lexer_state_T;
|
12
|
+
|
13
|
+
typedef struct LEXER_STRUCT {
|
14
|
+
const char* source;
|
15
|
+
size_t source_length;
|
16
|
+
|
17
|
+
size_t current_line;
|
18
|
+
size_t current_column;
|
19
|
+
size_t current_position;
|
20
|
+
|
21
|
+
size_t previous_line;
|
22
|
+
size_t previous_column;
|
23
|
+
size_t previous_position;
|
24
|
+
|
25
|
+
char current_character;
|
26
|
+
lexer_state_T state;
|
27
|
+
size_t stall_counter;
|
28
|
+
size_t last_position;
|
29
|
+
bool stalled;
|
30
|
+
} lexer_T;
|
31
|
+
|
32
|
+
#endif
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#ifndef HERB_LOCATION_H
|
2
|
+
#define HERB_LOCATION_H
|
3
|
+
|
4
|
+
#include <stdlib.h>
|
5
|
+
|
6
|
+
#include "position.h"
|
7
|
+
|
8
|
+
typedef struct LOCATION_STRUCT {
|
9
|
+
position_T* start;
|
10
|
+
position_T* end;
|
11
|
+
} location_T;
|
12
|
+
|
13
|
+
location_T* location_init(position_T* start, position_T* end);
|
14
|
+
location_T* location_from(size_t start_line, size_t start_column, size_t end_line, size_t end_column);
|
15
|
+
|
16
|
+
position_T* location_start(location_T* location);
|
17
|
+
position_T* location_end_(location_T* location);
|
18
|
+
|
19
|
+
size_t location_sizeof(void);
|
20
|
+
|
21
|
+
location_T* location_copy(location_T* location);
|
22
|
+
|
23
|
+
void location_free(location_T* location);
|
24
|
+
|
25
|
+
#endif
|