herb 0.8.6 → 0.8.7
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 +4 -4
- data/ext/herb/error_helpers.c +1 -1
- data/ext/herb/extension_helpers.c +1 -1
- data/ext/herb/nodes.c +2 -2
- data/lib/herb/version.rb +1 -1
- data/src/analyze.c +27 -27
- data/src/ast_node.c +1 -1
- data/src/ast_nodes.c +53 -157
- data/src/errors.c +5 -5
- data/src/extract.c +2 -2
- data/src/herb.c +2 -2
- data/src/include/util/hb_narray.h +1 -0
- data/src/include/version.h +1 -1
- data/src/parser.c +9 -9
- data/src/parser_helpers.c +4 -4
- data/src/pretty_print.c +6 -6
- data/src/util/hb_array.c +1 -0
- data/src/util/hb_narray.c +6 -0
- data/src/visitor.c +26 -26
- data/templates/ext/herb/error_helpers.c.erb +1 -1
- data/templates/ext/herb/nodes.c.erb +1 -1
- data/templates/java/error_helpers.c.erb +1 -1
- data/templates/java/nodes.c.erb +2 -2
- data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +1 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +1 -1
- data/templates/rust/src/ast/nodes.rs.erb +2 -2
- data/templates/src/ast_nodes.c.erb +3 -7
- data/templates/src/errors.c.erb +5 -5
- data/templates/src/visitor.c.erb +1 -1
- data/templates/wasm/error_helpers.cpp.erb +1 -1
- data/templates/wasm/nodes.cpp.erb +1 -1
- metadata +2 -2
data/src/ast_nodes.c
CHANGED
|
@@ -20,11 +20,7 @@ AST_DOCUMENT_NODE_T* ast_document_node_init(hb_array_T* children, position_T sta
|
|
|
20
20
|
|
|
21
21
|
ast_node_init(&document_node->base, AST_DOCUMENT_NODE, start_position, end_position, errors);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
document_node->children = hb_array_init(8);
|
|
25
|
-
} else {
|
|
26
|
-
document_node->children = children;
|
|
27
|
-
}
|
|
23
|
+
document_node->children = children;
|
|
28
24
|
|
|
29
25
|
return document_node;
|
|
30
26
|
}
|
|
@@ -47,11 +43,7 @@ AST_HTML_OPEN_TAG_NODE_T* ast_html_open_tag_node_init(token_T* tag_opening, toke
|
|
|
47
43
|
html_open_tag_node->tag_opening = token_copy(tag_opening);
|
|
48
44
|
html_open_tag_node->tag_name = token_copy(tag_name);
|
|
49
45
|
html_open_tag_node->tag_closing = token_copy(tag_closing);
|
|
50
|
-
|
|
51
|
-
html_open_tag_node->children = hb_array_init(8);
|
|
52
|
-
} else {
|
|
53
|
-
html_open_tag_node->children = children;
|
|
54
|
-
}
|
|
46
|
+
html_open_tag_node->children = children;
|
|
55
47
|
html_open_tag_node->is_void = is_void;
|
|
56
48
|
|
|
57
49
|
return html_open_tag_node;
|
|
@@ -64,11 +56,7 @@ AST_HTML_CLOSE_TAG_NODE_T* ast_html_close_tag_node_init(token_T* tag_opening, to
|
|
|
64
56
|
|
|
65
57
|
html_close_tag_node->tag_opening = token_copy(tag_opening);
|
|
66
58
|
html_close_tag_node->tag_name = token_copy(tag_name);
|
|
67
|
-
|
|
68
|
-
html_close_tag_node->children = hb_array_init(8);
|
|
69
|
-
} else {
|
|
70
|
-
html_close_tag_node->children = children;
|
|
71
|
-
}
|
|
59
|
+
html_close_tag_node->children = children;
|
|
72
60
|
html_close_tag_node->tag_closing = token_copy(tag_closing);
|
|
73
61
|
|
|
74
62
|
return html_close_tag_node;
|
|
@@ -81,11 +69,7 @@ AST_HTML_ELEMENT_NODE_T* ast_html_element_node_init(struct AST_HTML_OPEN_TAG_NOD
|
|
|
81
69
|
|
|
82
70
|
html_element_node->open_tag = open_tag;
|
|
83
71
|
html_element_node->tag_name = token_copy(tag_name);
|
|
84
|
-
|
|
85
|
-
html_element_node->body = hb_array_init(8);
|
|
86
|
-
} else {
|
|
87
|
-
html_element_node->body = body;
|
|
88
|
-
}
|
|
72
|
+
html_element_node->body = body;
|
|
89
73
|
html_element_node->close_tag = close_tag;
|
|
90
74
|
html_element_node->is_void = is_void;
|
|
91
75
|
html_element_node->source = source;
|
|
@@ -99,11 +83,7 @@ AST_HTML_ATTRIBUTE_VALUE_NODE_T* ast_html_attribute_value_node_init(token_T* ope
|
|
|
99
83
|
ast_node_init(&html_attribute_value_node->base, AST_HTML_ATTRIBUTE_VALUE_NODE, start_position, end_position, errors);
|
|
100
84
|
|
|
101
85
|
html_attribute_value_node->open_quote = token_copy(open_quote);
|
|
102
|
-
|
|
103
|
-
html_attribute_value_node->children = hb_array_init(8);
|
|
104
|
-
} else {
|
|
105
|
-
html_attribute_value_node->children = children;
|
|
106
|
-
}
|
|
86
|
+
html_attribute_value_node->children = children;
|
|
107
87
|
html_attribute_value_node->close_quote = token_copy(close_quote);
|
|
108
88
|
html_attribute_value_node->quoted = quoted;
|
|
109
89
|
|
|
@@ -115,11 +95,7 @@ AST_HTML_ATTRIBUTE_NAME_NODE_T* ast_html_attribute_name_node_init(hb_array_T* ch
|
|
|
115
95
|
|
|
116
96
|
ast_node_init(&html_attribute_name_node->base, AST_HTML_ATTRIBUTE_NAME_NODE, start_position, end_position, errors);
|
|
117
97
|
|
|
118
|
-
|
|
119
|
-
html_attribute_name_node->children = hb_array_init(8);
|
|
120
|
-
} else {
|
|
121
|
-
html_attribute_name_node->children = children;
|
|
122
|
-
}
|
|
98
|
+
html_attribute_name_node->children = children;
|
|
123
99
|
|
|
124
100
|
return html_attribute_name_node;
|
|
125
101
|
}
|
|
@@ -152,11 +128,7 @@ AST_HTML_COMMENT_NODE_T* ast_html_comment_node_init(token_T* comment_start, hb_a
|
|
|
152
128
|
ast_node_init(&html_comment_node->base, AST_HTML_COMMENT_NODE, start_position, end_position, errors);
|
|
153
129
|
|
|
154
130
|
html_comment_node->comment_start = token_copy(comment_start);
|
|
155
|
-
|
|
156
|
-
html_comment_node->children = hb_array_init(8);
|
|
157
|
-
} else {
|
|
158
|
-
html_comment_node->children = children;
|
|
159
|
-
}
|
|
131
|
+
html_comment_node->children = children;
|
|
160
132
|
html_comment_node->comment_end = token_copy(comment_end);
|
|
161
133
|
|
|
162
134
|
return html_comment_node;
|
|
@@ -168,11 +140,7 @@ AST_HTML_DOCTYPE_NODE_T* ast_html_doctype_node_init(token_T* tag_opening, hb_arr
|
|
|
168
140
|
ast_node_init(&html_doctype_node->base, AST_HTML_DOCTYPE_NODE, start_position, end_position, errors);
|
|
169
141
|
|
|
170
142
|
html_doctype_node->tag_opening = token_copy(tag_opening);
|
|
171
|
-
|
|
172
|
-
html_doctype_node->children = hb_array_init(8);
|
|
173
|
-
} else {
|
|
174
|
-
html_doctype_node->children = children;
|
|
175
|
-
}
|
|
143
|
+
html_doctype_node->children = children;
|
|
176
144
|
html_doctype_node->tag_closing = token_copy(tag_closing);
|
|
177
145
|
|
|
178
146
|
return html_doctype_node;
|
|
@@ -184,11 +152,7 @@ AST_XML_DECLARATION_NODE_T* ast_xml_declaration_node_init(token_T* tag_opening,
|
|
|
184
152
|
ast_node_init(&xml_declaration_node->base, AST_XML_DECLARATION_NODE, start_position, end_position, errors);
|
|
185
153
|
|
|
186
154
|
xml_declaration_node->tag_opening = token_copy(tag_opening);
|
|
187
|
-
|
|
188
|
-
xml_declaration_node->children = hb_array_init(8);
|
|
189
|
-
} else {
|
|
190
|
-
xml_declaration_node->children = children;
|
|
191
|
-
}
|
|
155
|
+
xml_declaration_node->children = children;
|
|
192
156
|
xml_declaration_node->tag_closing = token_copy(tag_closing);
|
|
193
157
|
|
|
194
158
|
return xml_declaration_node;
|
|
@@ -200,11 +164,7 @@ AST_CDATA_NODE_T* ast_cdata_node_init(token_T* tag_opening, hb_array_T* children
|
|
|
200
164
|
ast_node_init(&cdata_node->base, AST_CDATA_NODE, start_position, end_position, errors);
|
|
201
165
|
|
|
202
166
|
cdata_node->tag_opening = token_copy(tag_opening);
|
|
203
|
-
|
|
204
|
-
cdata_node->children = hb_array_init(8);
|
|
205
|
-
} else {
|
|
206
|
-
cdata_node->children = children;
|
|
207
|
-
}
|
|
167
|
+
cdata_node->children = children;
|
|
208
168
|
cdata_node->tag_closing = token_copy(tag_closing);
|
|
209
169
|
|
|
210
170
|
return cdata_node;
|
|
@@ -255,11 +215,7 @@ AST_ERB_ELSE_NODE_T* ast_erb_else_node_init(token_T* tag_opening, token_T* conte
|
|
|
255
215
|
erb_else_node->tag_opening = token_copy(tag_opening);
|
|
256
216
|
erb_else_node->content = token_copy(content);
|
|
257
217
|
erb_else_node->tag_closing = token_copy(tag_closing);
|
|
258
|
-
|
|
259
|
-
erb_else_node->statements = hb_array_init(8);
|
|
260
|
-
} else {
|
|
261
|
-
erb_else_node->statements = statements;
|
|
262
|
-
}
|
|
218
|
+
erb_else_node->statements = statements;
|
|
263
219
|
|
|
264
220
|
return erb_else_node;
|
|
265
221
|
}
|
|
@@ -272,11 +228,7 @@ AST_ERB_IF_NODE_T* ast_erb_if_node_init(token_T* tag_opening, token_T* content,
|
|
|
272
228
|
erb_if_node->tag_opening = token_copy(tag_opening);
|
|
273
229
|
erb_if_node->content = token_copy(content);
|
|
274
230
|
erb_if_node->tag_closing = token_copy(tag_closing);
|
|
275
|
-
|
|
276
|
-
erb_if_node->statements = hb_array_init(8);
|
|
277
|
-
} else {
|
|
278
|
-
erb_if_node->statements = statements;
|
|
279
|
-
}
|
|
231
|
+
erb_if_node->statements = statements;
|
|
280
232
|
erb_if_node->subsequent = subsequent;
|
|
281
233
|
erb_if_node->end_node = end_node;
|
|
282
234
|
|
|
@@ -291,11 +243,7 @@ AST_ERB_BLOCK_NODE_T* ast_erb_block_node_init(token_T* tag_opening, token_T* con
|
|
|
291
243
|
erb_block_node->tag_opening = token_copy(tag_opening);
|
|
292
244
|
erb_block_node->content = token_copy(content);
|
|
293
245
|
erb_block_node->tag_closing = token_copy(tag_closing);
|
|
294
|
-
|
|
295
|
-
erb_block_node->body = hb_array_init(8);
|
|
296
|
-
} else {
|
|
297
|
-
erb_block_node->body = body;
|
|
298
|
-
}
|
|
246
|
+
erb_block_node->body = body;
|
|
299
247
|
erb_block_node->end_node = end_node;
|
|
300
248
|
|
|
301
249
|
return erb_block_node;
|
|
@@ -309,11 +257,7 @@ AST_ERB_WHEN_NODE_T* ast_erb_when_node_init(token_T* tag_opening, token_T* conte
|
|
|
309
257
|
erb_when_node->tag_opening = token_copy(tag_opening);
|
|
310
258
|
erb_when_node->content = token_copy(content);
|
|
311
259
|
erb_when_node->tag_closing = token_copy(tag_closing);
|
|
312
|
-
|
|
313
|
-
erb_when_node->statements = hb_array_init(8);
|
|
314
|
-
} else {
|
|
315
|
-
erb_when_node->statements = statements;
|
|
316
|
-
}
|
|
260
|
+
erb_when_node->statements = statements;
|
|
317
261
|
|
|
318
262
|
return erb_when_node;
|
|
319
263
|
}
|
|
@@ -326,16 +270,8 @@ AST_ERB_CASE_NODE_T* ast_erb_case_node_init(token_T* tag_opening, token_T* conte
|
|
|
326
270
|
erb_case_node->tag_opening = token_copy(tag_opening);
|
|
327
271
|
erb_case_node->content = token_copy(content);
|
|
328
272
|
erb_case_node->tag_closing = token_copy(tag_closing);
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
} else {
|
|
332
|
-
erb_case_node->children = children;
|
|
333
|
-
}
|
|
334
|
-
if (conditions == NULL) {
|
|
335
|
-
erb_case_node->conditions = hb_array_init(8);
|
|
336
|
-
} else {
|
|
337
|
-
erb_case_node->conditions = conditions;
|
|
338
|
-
}
|
|
273
|
+
erb_case_node->children = children;
|
|
274
|
+
erb_case_node->conditions = conditions;
|
|
339
275
|
erb_case_node->else_clause = else_clause;
|
|
340
276
|
erb_case_node->end_node = end_node;
|
|
341
277
|
|
|
@@ -350,16 +286,8 @@ AST_ERB_CASE_MATCH_NODE_T* ast_erb_case_match_node_init(token_T* tag_opening, to
|
|
|
350
286
|
erb_case_match_node->tag_opening = token_copy(tag_opening);
|
|
351
287
|
erb_case_match_node->content = token_copy(content);
|
|
352
288
|
erb_case_match_node->tag_closing = token_copy(tag_closing);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
} else {
|
|
356
|
-
erb_case_match_node->children = children;
|
|
357
|
-
}
|
|
358
|
-
if (conditions == NULL) {
|
|
359
|
-
erb_case_match_node->conditions = hb_array_init(8);
|
|
360
|
-
} else {
|
|
361
|
-
erb_case_match_node->conditions = conditions;
|
|
362
|
-
}
|
|
289
|
+
erb_case_match_node->children = children;
|
|
290
|
+
erb_case_match_node->conditions = conditions;
|
|
363
291
|
erb_case_match_node->else_clause = else_clause;
|
|
364
292
|
erb_case_match_node->end_node = end_node;
|
|
365
293
|
|
|
@@ -374,11 +302,7 @@ AST_ERB_WHILE_NODE_T* ast_erb_while_node_init(token_T* tag_opening, token_T* con
|
|
|
374
302
|
erb_while_node->tag_opening = token_copy(tag_opening);
|
|
375
303
|
erb_while_node->content = token_copy(content);
|
|
376
304
|
erb_while_node->tag_closing = token_copy(tag_closing);
|
|
377
|
-
|
|
378
|
-
erb_while_node->statements = hb_array_init(8);
|
|
379
|
-
} else {
|
|
380
|
-
erb_while_node->statements = statements;
|
|
381
|
-
}
|
|
305
|
+
erb_while_node->statements = statements;
|
|
382
306
|
erb_while_node->end_node = end_node;
|
|
383
307
|
|
|
384
308
|
return erb_while_node;
|
|
@@ -392,11 +316,7 @@ AST_ERB_UNTIL_NODE_T* ast_erb_until_node_init(token_T* tag_opening, token_T* con
|
|
|
392
316
|
erb_until_node->tag_opening = token_copy(tag_opening);
|
|
393
317
|
erb_until_node->content = token_copy(content);
|
|
394
318
|
erb_until_node->tag_closing = token_copy(tag_closing);
|
|
395
|
-
|
|
396
|
-
erb_until_node->statements = hb_array_init(8);
|
|
397
|
-
} else {
|
|
398
|
-
erb_until_node->statements = statements;
|
|
399
|
-
}
|
|
319
|
+
erb_until_node->statements = statements;
|
|
400
320
|
erb_until_node->end_node = end_node;
|
|
401
321
|
|
|
402
322
|
return erb_until_node;
|
|
@@ -410,11 +330,7 @@ AST_ERB_FOR_NODE_T* ast_erb_for_node_init(token_T* tag_opening, token_T* content
|
|
|
410
330
|
erb_for_node->tag_opening = token_copy(tag_opening);
|
|
411
331
|
erb_for_node->content = token_copy(content);
|
|
412
332
|
erb_for_node->tag_closing = token_copy(tag_closing);
|
|
413
|
-
|
|
414
|
-
erb_for_node->statements = hb_array_init(8);
|
|
415
|
-
} else {
|
|
416
|
-
erb_for_node->statements = statements;
|
|
417
|
-
}
|
|
333
|
+
erb_for_node->statements = statements;
|
|
418
334
|
erb_for_node->end_node = end_node;
|
|
419
335
|
|
|
420
336
|
return erb_for_node;
|
|
@@ -428,11 +344,7 @@ AST_ERB_RESCUE_NODE_T* ast_erb_rescue_node_init(token_T* tag_opening, token_T* c
|
|
|
428
344
|
erb_rescue_node->tag_opening = token_copy(tag_opening);
|
|
429
345
|
erb_rescue_node->content = token_copy(content);
|
|
430
346
|
erb_rescue_node->tag_closing = token_copy(tag_closing);
|
|
431
|
-
|
|
432
|
-
erb_rescue_node->statements = hb_array_init(8);
|
|
433
|
-
} else {
|
|
434
|
-
erb_rescue_node->statements = statements;
|
|
435
|
-
}
|
|
347
|
+
erb_rescue_node->statements = statements;
|
|
436
348
|
erb_rescue_node->subsequent = subsequent;
|
|
437
349
|
|
|
438
350
|
return erb_rescue_node;
|
|
@@ -446,11 +358,7 @@ AST_ERB_ENSURE_NODE_T* ast_erb_ensure_node_init(token_T* tag_opening, token_T* c
|
|
|
446
358
|
erb_ensure_node->tag_opening = token_copy(tag_opening);
|
|
447
359
|
erb_ensure_node->content = token_copy(content);
|
|
448
360
|
erb_ensure_node->tag_closing = token_copy(tag_closing);
|
|
449
|
-
|
|
450
|
-
erb_ensure_node->statements = hb_array_init(8);
|
|
451
|
-
} else {
|
|
452
|
-
erb_ensure_node->statements = statements;
|
|
453
|
-
}
|
|
361
|
+
erb_ensure_node->statements = statements;
|
|
454
362
|
|
|
455
363
|
return erb_ensure_node;
|
|
456
364
|
}
|
|
@@ -463,11 +371,7 @@ AST_ERB_BEGIN_NODE_T* ast_erb_begin_node_init(token_T* tag_opening, token_T* con
|
|
|
463
371
|
erb_begin_node->tag_opening = token_copy(tag_opening);
|
|
464
372
|
erb_begin_node->content = token_copy(content);
|
|
465
373
|
erb_begin_node->tag_closing = token_copy(tag_closing);
|
|
466
|
-
|
|
467
|
-
erb_begin_node->statements = hb_array_init(8);
|
|
468
|
-
} else {
|
|
469
|
-
erb_begin_node->statements = statements;
|
|
470
|
-
}
|
|
374
|
+
erb_begin_node->statements = statements;
|
|
471
375
|
erb_begin_node->rescue_clause = rescue_clause;
|
|
472
376
|
erb_begin_node->else_clause = else_clause;
|
|
473
377
|
erb_begin_node->ensure_clause = ensure_clause;
|
|
@@ -484,11 +388,7 @@ AST_ERB_UNLESS_NODE_T* ast_erb_unless_node_init(token_T* tag_opening, token_T* c
|
|
|
484
388
|
erb_unless_node->tag_opening = token_copy(tag_opening);
|
|
485
389
|
erb_unless_node->content = token_copy(content);
|
|
486
390
|
erb_unless_node->tag_closing = token_copy(tag_closing);
|
|
487
|
-
|
|
488
|
-
erb_unless_node->statements = hb_array_init(8);
|
|
489
|
-
} else {
|
|
490
|
-
erb_unless_node->statements = statements;
|
|
491
|
-
}
|
|
391
|
+
erb_unless_node->statements = statements;
|
|
492
392
|
erb_unless_node->else_clause = else_clause;
|
|
493
393
|
erb_unless_node->end_node = end_node;
|
|
494
394
|
|
|
@@ -515,11 +415,7 @@ AST_ERB_IN_NODE_T* ast_erb_in_node_init(token_T* tag_opening, token_T* content,
|
|
|
515
415
|
erb_in_node->tag_opening = token_copy(tag_opening);
|
|
516
416
|
erb_in_node->content = token_copy(content);
|
|
517
417
|
erb_in_node->tag_closing = token_copy(tag_closing);
|
|
518
|
-
|
|
519
|
-
erb_in_node->statements = hb_array_init(8);
|
|
520
|
-
} else {
|
|
521
|
-
erb_in_node->statements = statements;
|
|
522
|
-
}
|
|
418
|
+
erb_in_node->statements = statements;
|
|
523
419
|
|
|
524
420
|
return erb_in_node;
|
|
525
421
|
}
|
|
@@ -604,7 +500,7 @@ void ast_free_base_node(AST_NODE_T* node) {
|
|
|
604
500
|
if (node == NULL) { return; }
|
|
605
501
|
|
|
606
502
|
if (node->errors) {
|
|
607
|
-
for (size_t i = 0; i < node->errors
|
|
503
|
+
for (size_t i = 0; i < hb_array_size(node->errors); i++) {
|
|
608
504
|
ERROR_T* child = hb_array_get(node->errors, i);
|
|
609
505
|
if (child != NULL) { error_free(child); }
|
|
610
506
|
}
|
|
@@ -618,7 +514,7 @@ void ast_free_base_node(AST_NODE_T* node) {
|
|
|
618
514
|
|
|
619
515
|
static void ast_free_document_node(AST_DOCUMENT_NODE_T* document_node) {
|
|
620
516
|
if (document_node->children != NULL) {
|
|
621
|
-
for (size_t i = 0; i < document_node->children
|
|
517
|
+
for (size_t i = 0; i < hb_array_size(document_node->children); i++) {
|
|
622
518
|
AST_NODE_T* child = hb_array_get(document_node->children, i);
|
|
623
519
|
if (child) { ast_node_free(child); }
|
|
624
520
|
}
|
|
@@ -640,7 +536,7 @@ static void ast_free_html_open_tag_node(AST_HTML_OPEN_TAG_NODE_T* html_open_tag_
|
|
|
640
536
|
if (html_open_tag_node->tag_name != NULL) { token_free(html_open_tag_node->tag_name); }
|
|
641
537
|
if (html_open_tag_node->tag_closing != NULL) { token_free(html_open_tag_node->tag_closing); }
|
|
642
538
|
if (html_open_tag_node->children != NULL) {
|
|
643
|
-
for (size_t i = 0; i < html_open_tag_node->children
|
|
539
|
+
for (size_t i = 0; i < hb_array_size(html_open_tag_node->children); i++) {
|
|
644
540
|
AST_NODE_T* child = hb_array_get(html_open_tag_node->children, i);
|
|
645
541
|
if (child) { ast_node_free(child); }
|
|
646
542
|
}
|
|
@@ -655,7 +551,7 @@ static void ast_free_html_close_tag_node(AST_HTML_CLOSE_TAG_NODE_T* html_close_t
|
|
|
655
551
|
if (html_close_tag_node->tag_opening != NULL) { token_free(html_close_tag_node->tag_opening); }
|
|
656
552
|
if (html_close_tag_node->tag_name != NULL) { token_free(html_close_tag_node->tag_name); }
|
|
657
553
|
if (html_close_tag_node->children != NULL) {
|
|
658
|
-
for (size_t i = 0; i < html_close_tag_node->children
|
|
554
|
+
for (size_t i = 0; i < hb_array_size(html_close_tag_node->children); i++) {
|
|
659
555
|
AST_NODE_T* child = hb_array_get(html_close_tag_node->children, i);
|
|
660
556
|
if (child) { ast_node_free(child); }
|
|
661
557
|
}
|
|
@@ -671,7 +567,7 @@ static void ast_free_html_element_node(AST_HTML_ELEMENT_NODE_T* html_element_nod
|
|
|
671
567
|
ast_node_free((AST_NODE_T*) html_element_node->open_tag);
|
|
672
568
|
if (html_element_node->tag_name != NULL) { token_free(html_element_node->tag_name); }
|
|
673
569
|
if (html_element_node->body != NULL) {
|
|
674
|
-
for (size_t i = 0; i < html_element_node->body
|
|
570
|
+
for (size_t i = 0; i < hb_array_size(html_element_node->body); i++) {
|
|
675
571
|
AST_NODE_T* child = hb_array_get(html_element_node->body, i);
|
|
676
572
|
if (child) { ast_node_free(child); }
|
|
677
573
|
}
|
|
@@ -686,7 +582,7 @@ static void ast_free_html_element_node(AST_HTML_ELEMENT_NODE_T* html_element_nod
|
|
|
686
582
|
static void ast_free_html_attribute_value_node(AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node) {
|
|
687
583
|
if (html_attribute_value_node->open_quote != NULL) { token_free(html_attribute_value_node->open_quote); }
|
|
688
584
|
if (html_attribute_value_node->children != NULL) {
|
|
689
|
-
for (size_t i = 0; i < html_attribute_value_node->children
|
|
585
|
+
for (size_t i = 0; i < hb_array_size(html_attribute_value_node->children); i++) {
|
|
690
586
|
AST_NODE_T* child = hb_array_get(html_attribute_value_node->children, i);
|
|
691
587
|
if (child) { ast_node_free(child); }
|
|
692
588
|
}
|
|
@@ -700,7 +596,7 @@ static void ast_free_html_attribute_value_node(AST_HTML_ATTRIBUTE_VALUE_NODE_T*
|
|
|
700
596
|
|
|
701
597
|
static void ast_free_html_attribute_name_node(AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node) {
|
|
702
598
|
if (html_attribute_name_node->children != NULL) {
|
|
703
|
-
for (size_t i = 0; i < html_attribute_name_node->children
|
|
599
|
+
for (size_t i = 0; i < hb_array_size(html_attribute_name_node->children); i++) {
|
|
704
600
|
AST_NODE_T* child = hb_array_get(html_attribute_name_node->children, i);
|
|
705
601
|
if (child) { ast_node_free(child); }
|
|
706
602
|
}
|
|
@@ -728,7 +624,7 @@ static void ast_free_html_text_node(AST_HTML_TEXT_NODE_T* html_text_node) {
|
|
|
728
624
|
static void ast_free_html_comment_node(AST_HTML_COMMENT_NODE_T* html_comment_node) {
|
|
729
625
|
if (html_comment_node->comment_start != NULL) { token_free(html_comment_node->comment_start); }
|
|
730
626
|
if (html_comment_node->children != NULL) {
|
|
731
|
-
for (size_t i = 0; i < html_comment_node->children
|
|
627
|
+
for (size_t i = 0; i < hb_array_size(html_comment_node->children); i++) {
|
|
732
628
|
AST_NODE_T* child = hb_array_get(html_comment_node->children, i);
|
|
733
629
|
if (child) { ast_node_free(child); }
|
|
734
630
|
}
|
|
@@ -743,7 +639,7 @@ static void ast_free_html_comment_node(AST_HTML_COMMENT_NODE_T* html_comment_nod
|
|
|
743
639
|
static void ast_free_html_doctype_node(AST_HTML_DOCTYPE_NODE_T* html_doctype_node) {
|
|
744
640
|
if (html_doctype_node->tag_opening != NULL) { token_free(html_doctype_node->tag_opening); }
|
|
745
641
|
if (html_doctype_node->children != NULL) {
|
|
746
|
-
for (size_t i = 0; i < html_doctype_node->children
|
|
642
|
+
for (size_t i = 0; i < hb_array_size(html_doctype_node->children); i++) {
|
|
747
643
|
AST_NODE_T* child = hb_array_get(html_doctype_node->children, i);
|
|
748
644
|
if (child) { ast_node_free(child); }
|
|
749
645
|
}
|
|
@@ -758,7 +654,7 @@ static void ast_free_html_doctype_node(AST_HTML_DOCTYPE_NODE_T* html_doctype_nod
|
|
|
758
654
|
static void ast_free_xml_declaration_node(AST_XML_DECLARATION_NODE_T* xml_declaration_node) {
|
|
759
655
|
if (xml_declaration_node->tag_opening != NULL) { token_free(xml_declaration_node->tag_opening); }
|
|
760
656
|
if (xml_declaration_node->children != NULL) {
|
|
761
|
-
for (size_t i = 0; i < xml_declaration_node->children
|
|
657
|
+
for (size_t i = 0; i < hb_array_size(xml_declaration_node->children); i++) {
|
|
762
658
|
AST_NODE_T* child = hb_array_get(xml_declaration_node->children, i);
|
|
763
659
|
if (child) { ast_node_free(child); }
|
|
764
660
|
}
|
|
@@ -773,7 +669,7 @@ static void ast_free_xml_declaration_node(AST_XML_DECLARATION_NODE_T* xml_declar
|
|
|
773
669
|
static void ast_free_cdata_node(AST_CDATA_NODE_T* cdata_node) {
|
|
774
670
|
if (cdata_node->tag_opening != NULL) { token_free(cdata_node->tag_opening); }
|
|
775
671
|
if (cdata_node->children != NULL) {
|
|
776
|
-
for (size_t i = 0; i < cdata_node->children
|
|
672
|
+
for (size_t i = 0; i < hb_array_size(cdata_node->children); i++) {
|
|
777
673
|
AST_NODE_T* child = hb_array_get(cdata_node->children, i);
|
|
778
674
|
if (child) { ast_node_free(child); }
|
|
779
675
|
}
|
|
@@ -815,7 +711,7 @@ static void ast_free_erb_else_node(AST_ERB_ELSE_NODE_T* erb_else_node) {
|
|
|
815
711
|
if (erb_else_node->content != NULL) { token_free(erb_else_node->content); }
|
|
816
712
|
if (erb_else_node->tag_closing != NULL) { token_free(erb_else_node->tag_closing); }
|
|
817
713
|
if (erb_else_node->statements != NULL) {
|
|
818
|
-
for (size_t i = 0; i < erb_else_node->statements
|
|
714
|
+
for (size_t i = 0; i < hb_array_size(erb_else_node->statements); i++) {
|
|
819
715
|
AST_NODE_T* child = hb_array_get(erb_else_node->statements, i);
|
|
820
716
|
if (child) { ast_node_free(child); }
|
|
821
717
|
}
|
|
@@ -831,7 +727,7 @@ static void ast_free_erb_if_node(AST_ERB_IF_NODE_T* erb_if_node) {
|
|
|
831
727
|
if (erb_if_node->content != NULL) { token_free(erb_if_node->content); }
|
|
832
728
|
if (erb_if_node->tag_closing != NULL) { token_free(erb_if_node->tag_closing); }
|
|
833
729
|
if (erb_if_node->statements != NULL) {
|
|
834
|
-
for (size_t i = 0; i < erb_if_node->statements
|
|
730
|
+
for (size_t i = 0; i < hb_array_size(erb_if_node->statements); i++) {
|
|
835
731
|
AST_NODE_T* child = hb_array_get(erb_if_node->statements, i);
|
|
836
732
|
if (child) { ast_node_free(child); }
|
|
837
733
|
}
|
|
@@ -849,7 +745,7 @@ static void ast_free_erb_block_node(AST_ERB_BLOCK_NODE_T* erb_block_node) {
|
|
|
849
745
|
if (erb_block_node->content != NULL) { token_free(erb_block_node->content); }
|
|
850
746
|
if (erb_block_node->tag_closing != NULL) { token_free(erb_block_node->tag_closing); }
|
|
851
747
|
if (erb_block_node->body != NULL) {
|
|
852
|
-
for (size_t i = 0; i < erb_block_node->body
|
|
748
|
+
for (size_t i = 0; i < hb_array_size(erb_block_node->body); i++) {
|
|
853
749
|
AST_NODE_T* child = hb_array_get(erb_block_node->body, i);
|
|
854
750
|
if (child) { ast_node_free(child); }
|
|
855
751
|
}
|
|
@@ -866,7 +762,7 @@ static void ast_free_erb_when_node(AST_ERB_WHEN_NODE_T* erb_when_node) {
|
|
|
866
762
|
if (erb_when_node->content != NULL) { token_free(erb_when_node->content); }
|
|
867
763
|
if (erb_when_node->tag_closing != NULL) { token_free(erb_when_node->tag_closing); }
|
|
868
764
|
if (erb_when_node->statements != NULL) {
|
|
869
|
-
for (size_t i = 0; i < erb_when_node->statements
|
|
765
|
+
for (size_t i = 0; i < hb_array_size(erb_when_node->statements); i++) {
|
|
870
766
|
AST_NODE_T* child = hb_array_get(erb_when_node->statements, i);
|
|
871
767
|
if (child) { ast_node_free(child); }
|
|
872
768
|
}
|
|
@@ -882,7 +778,7 @@ static void ast_free_erb_case_node(AST_ERB_CASE_NODE_T* erb_case_node) {
|
|
|
882
778
|
if (erb_case_node->content != NULL) { token_free(erb_case_node->content); }
|
|
883
779
|
if (erb_case_node->tag_closing != NULL) { token_free(erb_case_node->tag_closing); }
|
|
884
780
|
if (erb_case_node->children != NULL) {
|
|
885
|
-
for (size_t i = 0; i < erb_case_node->children
|
|
781
|
+
for (size_t i = 0; i < hb_array_size(erb_case_node->children); i++) {
|
|
886
782
|
AST_NODE_T* child = hb_array_get(erb_case_node->children, i);
|
|
887
783
|
if (child) { ast_node_free(child); }
|
|
888
784
|
}
|
|
@@ -890,7 +786,7 @@ static void ast_free_erb_case_node(AST_ERB_CASE_NODE_T* erb_case_node) {
|
|
|
890
786
|
hb_array_free(&erb_case_node->children);
|
|
891
787
|
}
|
|
892
788
|
if (erb_case_node->conditions != NULL) {
|
|
893
|
-
for (size_t i = 0; i < erb_case_node->conditions
|
|
789
|
+
for (size_t i = 0; i < hb_array_size(erb_case_node->conditions); i++) {
|
|
894
790
|
AST_NODE_T* child = hb_array_get(erb_case_node->conditions, i);
|
|
895
791
|
if (child) { ast_node_free(child); }
|
|
896
792
|
}
|
|
@@ -908,7 +804,7 @@ static void ast_free_erb_case_match_node(AST_ERB_CASE_MATCH_NODE_T* erb_case_mat
|
|
|
908
804
|
if (erb_case_match_node->content != NULL) { token_free(erb_case_match_node->content); }
|
|
909
805
|
if (erb_case_match_node->tag_closing != NULL) { token_free(erb_case_match_node->tag_closing); }
|
|
910
806
|
if (erb_case_match_node->children != NULL) {
|
|
911
|
-
for (size_t i = 0; i < erb_case_match_node->children
|
|
807
|
+
for (size_t i = 0; i < hb_array_size(erb_case_match_node->children); i++) {
|
|
912
808
|
AST_NODE_T* child = hb_array_get(erb_case_match_node->children, i);
|
|
913
809
|
if (child) { ast_node_free(child); }
|
|
914
810
|
}
|
|
@@ -916,7 +812,7 @@ static void ast_free_erb_case_match_node(AST_ERB_CASE_MATCH_NODE_T* erb_case_mat
|
|
|
916
812
|
hb_array_free(&erb_case_match_node->children);
|
|
917
813
|
}
|
|
918
814
|
if (erb_case_match_node->conditions != NULL) {
|
|
919
|
-
for (size_t i = 0; i < erb_case_match_node->conditions
|
|
815
|
+
for (size_t i = 0; i < hb_array_size(erb_case_match_node->conditions); i++) {
|
|
920
816
|
AST_NODE_T* child = hb_array_get(erb_case_match_node->conditions, i);
|
|
921
817
|
if (child) { ast_node_free(child); }
|
|
922
818
|
}
|
|
@@ -934,7 +830,7 @@ static void ast_free_erb_while_node(AST_ERB_WHILE_NODE_T* erb_while_node) {
|
|
|
934
830
|
if (erb_while_node->content != NULL) { token_free(erb_while_node->content); }
|
|
935
831
|
if (erb_while_node->tag_closing != NULL) { token_free(erb_while_node->tag_closing); }
|
|
936
832
|
if (erb_while_node->statements != NULL) {
|
|
937
|
-
for (size_t i = 0; i < erb_while_node->statements
|
|
833
|
+
for (size_t i = 0; i < hb_array_size(erb_while_node->statements); i++) {
|
|
938
834
|
AST_NODE_T* child = hb_array_get(erb_while_node->statements, i);
|
|
939
835
|
if (child) { ast_node_free(child); }
|
|
940
836
|
}
|
|
@@ -951,7 +847,7 @@ static void ast_free_erb_until_node(AST_ERB_UNTIL_NODE_T* erb_until_node) {
|
|
|
951
847
|
if (erb_until_node->content != NULL) { token_free(erb_until_node->content); }
|
|
952
848
|
if (erb_until_node->tag_closing != NULL) { token_free(erb_until_node->tag_closing); }
|
|
953
849
|
if (erb_until_node->statements != NULL) {
|
|
954
|
-
for (size_t i = 0; i < erb_until_node->statements
|
|
850
|
+
for (size_t i = 0; i < hb_array_size(erb_until_node->statements); i++) {
|
|
955
851
|
AST_NODE_T* child = hb_array_get(erb_until_node->statements, i);
|
|
956
852
|
if (child) { ast_node_free(child); }
|
|
957
853
|
}
|
|
@@ -968,7 +864,7 @@ static void ast_free_erb_for_node(AST_ERB_FOR_NODE_T* erb_for_node) {
|
|
|
968
864
|
if (erb_for_node->content != NULL) { token_free(erb_for_node->content); }
|
|
969
865
|
if (erb_for_node->tag_closing != NULL) { token_free(erb_for_node->tag_closing); }
|
|
970
866
|
if (erb_for_node->statements != NULL) {
|
|
971
|
-
for (size_t i = 0; i < erb_for_node->statements
|
|
867
|
+
for (size_t i = 0; i < hb_array_size(erb_for_node->statements); i++) {
|
|
972
868
|
AST_NODE_T* child = hb_array_get(erb_for_node->statements, i);
|
|
973
869
|
if (child) { ast_node_free(child); }
|
|
974
870
|
}
|
|
@@ -985,7 +881,7 @@ static void ast_free_erb_rescue_node(AST_ERB_RESCUE_NODE_T* erb_rescue_node) {
|
|
|
985
881
|
if (erb_rescue_node->content != NULL) { token_free(erb_rescue_node->content); }
|
|
986
882
|
if (erb_rescue_node->tag_closing != NULL) { token_free(erb_rescue_node->tag_closing); }
|
|
987
883
|
if (erb_rescue_node->statements != NULL) {
|
|
988
|
-
for (size_t i = 0; i < erb_rescue_node->statements
|
|
884
|
+
for (size_t i = 0; i < hb_array_size(erb_rescue_node->statements); i++) {
|
|
989
885
|
AST_NODE_T* child = hb_array_get(erb_rescue_node->statements, i);
|
|
990
886
|
if (child) { ast_node_free(child); }
|
|
991
887
|
}
|
|
@@ -1002,7 +898,7 @@ static void ast_free_erb_ensure_node(AST_ERB_ENSURE_NODE_T* erb_ensure_node) {
|
|
|
1002
898
|
if (erb_ensure_node->content != NULL) { token_free(erb_ensure_node->content); }
|
|
1003
899
|
if (erb_ensure_node->tag_closing != NULL) { token_free(erb_ensure_node->tag_closing); }
|
|
1004
900
|
if (erb_ensure_node->statements != NULL) {
|
|
1005
|
-
for (size_t i = 0; i < erb_ensure_node->statements
|
|
901
|
+
for (size_t i = 0; i < hb_array_size(erb_ensure_node->statements); i++) {
|
|
1006
902
|
AST_NODE_T* child = hb_array_get(erb_ensure_node->statements, i);
|
|
1007
903
|
if (child) { ast_node_free(child); }
|
|
1008
904
|
}
|
|
@@ -1018,7 +914,7 @@ static void ast_free_erb_begin_node(AST_ERB_BEGIN_NODE_T* erb_begin_node) {
|
|
|
1018
914
|
if (erb_begin_node->content != NULL) { token_free(erb_begin_node->content); }
|
|
1019
915
|
if (erb_begin_node->tag_closing != NULL) { token_free(erb_begin_node->tag_closing); }
|
|
1020
916
|
if (erb_begin_node->statements != NULL) {
|
|
1021
|
-
for (size_t i = 0; i < erb_begin_node->statements
|
|
917
|
+
for (size_t i = 0; i < hb_array_size(erb_begin_node->statements); i++) {
|
|
1022
918
|
AST_NODE_T* child = hb_array_get(erb_begin_node->statements, i);
|
|
1023
919
|
if (child) { ast_node_free(child); }
|
|
1024
920
|
}
|
|
@@ -1038,7 +934,7 @@ static void ast_free_erb_unless_node(AST_ERB_UNLESS_NODE_T* erb_unless_node) {
|
|
|
1038
934
|
if (erb_unless_node->content != NULL) { token_free(erb_unless_node->content); }
|
|
1039
935
|
if (erb_unless_node->tag_closing != NULL) { token_free(erb_unless_node->tag_closing); }
|
|
1040
936
|
if (erb_unless_node->statements != NULL) {
|
|
1041
|
-
for (size_t i = 0; i < erb_unless_node->statements
|
|
937
|
+
for (size_t i = 0; i < hb_array_size(erb_unless_node->statements); i++) {
|
|
1042
938
|
AST_NODE_T* child = hb_array_get(erb_unless_node->statements, i);
|
|
1043
939
|
if (child) { ast_node_free(child); }
|
|
1044
940
|
}
|
|
@@ -1064,7 +960,7 @@ static void ast_free_erb_in_node(AST_ERB_IN_NODE_T* erb_in_node) {
|
|
|
1064
960
|
if (erb_in_node->content != NULL) { token_free(erb_in_node->content); }
|
|
1065
961
|
if (erb_in_node->tag_closing != NULL) { token_free(erb_in_node->tag_closing); }
|
|
1066
962
|
if (erb_in_node->statements != NULL) {
|
|
1067
|
-
for (size_t i = 0; i < erb_in_node->statements
|
|
963
|
+
for (size_t i = 0; i < hb_array_size(erb_in_node->statements); i++) {
|
|
1068
964
|
AST_NODE_T* child = hb_array_get(erb_in_node->statements, i);
|
|
1069
965
|
if (child) { ast_node_free(child); }
|
|
1070
966
|
}
|
data/src/errors.c
CHANGED
|
@@ -667,7 +667,7 @@ void error_pretty_print_array(
|
|
|
667
667
|
return;
|
|
668
668
|
}
|
|
669
669
|
|
|
670
|
-
if (array
|
|
670
|
+
if (hb_array_size(array) == 0) {
|
|
671
671
|
pretty_print_property(hb_string(name), hb_string("[]"), indent, relative_indent, last_property, buffer);
|
|
672
672
|
|
|
673
673
|
return;
|
|
@@ -678,17 +678,17 @@ void error_pretty_print_array(
|
|
|
678
678
|
hb_buffer_append(buffer, "(");
|
|
679
679
|
|
|
680
680
|
char count[16];
|
|
681
|
-
sprintf(count, "%zu", array
|
|
681
|
+
sprintf(count, "%zu", hb_array_size(array));
|
|
682
682
|
hb_buffer_append(buffer, count);
|
|
683
683
|
hb_buffer_append(buffer, ")\n");
|
|
684
684
|
|
|
685
685
|
if (indent < 20) {
|
|
686
|
-
for (size_t i = 0; i < array
|
|
686
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
687
687
|
ERROR_T* child = hb_array_get(array, i);
|
|
688
688
|
pretty_print_indent(buffer, indent);
|
|
689
689
|
pretty_print_indent(buffer, relative_indent + 1);
|
|
690
690
|
|
|
691
|
-
if (i == array
|
|
691
|
+
if (i == hb_array_size(array) - 1) {
|
|
692
692
|
hb_buffer_append(buffer, "└── ");
|
|
693
693
|
} else {
|
|
694
694
|
hb_buffer_append(buffer, "├── ");
|
|
@@ -696,7 +696,7 @@ void error_pretty_print_array(
|
|
|
696
696
|
|
|
697
697
|
error_pretty_print(child, indent + 1, relative_indent + 1, buffer);
|
|
698
698
|
|
|
699
|
-
if (i != array
|
|
699
|
+
if (i != hb_array_size(array) - 1) { pretty_print_newline(indent + 1, relative_indent, buffer); }
|
|
700
700
|
}
|
|
701
701
|
}
|
|
702
702
|
}
|
data/src/extract.c
CHANGED
|
@@ -12,7 +12,7 @@ void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output) {
|
|
|
12
12
|
bool skip_erb_content = false;
|
|
13
13
|
bool is_comment_tag = false;
|
|
14
14
|
|
|
15
|
-
for (size_t i = 0; i < tokens
|
|
15
|
+
for (size_t i = 0; i < hb_array_size(tokens); i++) {
|
|
16
16
|
const token_T* token = hb_array_get(tokens, i);
|
|
17
17
|
|
|
18
18
|
switch (token->type) {
|
|
@@ -95,7 +95,7 @@ void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output) {
|
|
|
95
95
|
void herb_extract_html_to_buffer(const char* source, hb_buffer_T* output) {
|
|
96
96
|
hb_array_T* tokens = herb_lex(source);
|
|
97
97
|
|
|
98
|
-
for (size_t i = 0; i < tokens
|
|
98
|
+
for (size_t i = 0; i < hb_array_size(tokens); i++) {
|
|
99
99
|
const token_T* token = hb_array_get(tokens, i);
|
|
100
100
|
|
|
101
101
|
switch (token->type) {
|
data/src/herb.c
CHANGED
|
@@ -58,7 +58,7 @@ HERB_EXPORTED_FUNCTION hb_array_T* herb_lex_file(const char* path) {
|
|
|
58
58
|
HERB_EXPORTED_FUNCTION void herb_lex_to_buffer(const char* source, hb_buffer_T* output) {
|
|
59
59
|
hb_array_T* tokens = herb_lex(source);
|
|
60
60
|
|
|
61
|
-
for (size_t i = 0; i < tokens
|
|
61
|
+
for (size_t i = 0; i < hb_array_size(tokens); i++) {
|
|
62
62
|
token_T* token = hb_array_get(tokens, i);
|
|
63
63
|
|
|
64
64
|
hb_string_T type = token_to_string(token);
|
|
@@ -74,7 +74,7 @@ HERB_EXPORTED_FUNCTION void herb_lex_to_buffer(const char* source, hb_buffer_T*
|
|
|
74
74
|
HERB_EXPORTED_FUNCTION void herb_free_tokens(hb_array_T** tokens) {
|
|
75
75
|
if (!tokens || !*tokens) { return; }
|
|
76
76
|
|
|
77
|
-
for (size_t i = 0; i < (*tokens)
|
|
77
|
+
for (size_t i = 0; i < hb_array_size(*tokens); i++) {
|
|
78
78
|
token_T* token = hb_array_get(*tokens, i);
|
|
79
79
|
if (token) { token_free(token); }
|
|
80
80
|
}
|
|
@@ -18,6 +18,7 @@ void hb_narray_init(hb_narray_T* array, size_t item_size, size_t initial_capacit
|
|
|
18
18
|
void* hb_narray_get(const hb_narray_T* array, size_t index);
|
|
19
19
|
void* hb_narray_first(hb_narray_T* array);
|
|
20
20
|
void* hb_narray_last(hb_narray_T* array);
|
|
21
|
+
size_t hb_narray_size(const hb_narray_T* array);
|
|
21
22
|
|
|
22
23
|
void hb_narray_append(hb_narray_T* array, void* item);
|
|
23
24
|
void hb_narray_remove(hb_narray_T* array, size_t index);
|