@herb-tools/node 0.1.1 → 0.3.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.
- package/CHANGELOG.md +8 -0
- package/bin/vendor.cjs +103 -0
- package/dist/herb-node.esm.js +1 -1
- package/extension/extension_helpers.cpp +2 -3
- package/extension/herb.cpp +9 -0
- package/extension/libherb/analyze.c +138 -43
- package/extension/libherb/analyze.h +39 -0
- package/extension/libherb/analyze_helpers.c +44 -1
- package/extension/libherb/analyze_helpers.h +49 -0
- package/extension/libherb/analyzed_ruby.c +10 -1
- package/extension/libherb/analyzed_ruby.h +36 -0
- package/extension/libherb/array.h +33 -0
- package/extension/libherb/ast_node.h +35 -0
- package/extension/libherb/ast_nodes.c +103 -1
- package/extension/libherb/ast_nodes.h +335 -0
- package/extension/libherb/ast_pretty_print.c +60 -0
- package/extension/libherb/ast_pretty_print.h +17 -0
- package/extension/libherb/buffer.c +60 -27
- package/extension/libherb/buffer.h +39 -0
- package/extension/libherb/errors.h +125 -0
- package/extension/libherb/extract.c +57 -20
- package/extension/libherb/extract.h +20 -0
- package/extension/libherb/herb.h +32 -0
- package/extension/libherb/html_util.h +13 -0
- package/extension/libherb/include/analyze.h +3 -0
- package/extension/libherb/include/analyze_helpers.h +6 -0
- package/extension/libherb/include/analyzed_ruby.h +3 -0
- package/extension/libherb/include/ast_nodes.h +32 -0
- package/extension/libherb/include/buffer.h +5 -2
- package/extension/libherb/include/lexer_peek_helpers.h +2 -2
- package/extension/libherb/include/macros.h +2 -2
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/io.h +9 -0
- package/extension/libherb/json.h +28 -0
- package/extension/libherb/lexer.c +1 -1
- package/extension/libherb/lexer.h +13 -0
- package/extension/libherb/lexer_peek_helpers.h +23 -0
- package/extension/libherb/lexer_struct.h +32 -0
- package/extension/libherb/location.h +25 -0
- package/extension/libherb/macros.h +10 -0
- package/extension/libherb/memory.h +12 -0
- package/extension/libherb/parser.c +17 -7
- package/extension/libherb/parser.h +22 -0
- package/extension/libherb/parser_helpers.h +33 -0
- package/extension/libherb/position.h +22 -0
- package/extension/libherb/pretty_print.h +53 -0
- package/extension/libherb/prism_helpers.h +18 -0
- package/extension/libherb/range.h +23 -0
- package/extension/libherb/ruby_parser.h +6 -0
- package/extension/libherb/token.c +1 -1
- package/extension/libherb/token.h +25 -0
- package/extension/libherb/token_matchers.h +21 -0
- package/extension/libherb/token_struct.h +51 -0
- package/extension/libherb/util.c +3 -1
- package/extension/libherb/util.h +25 -0
- package/extension/libherb/version.h +6 -0
- package/extension/libherb/visitor.c +36 -0
- package/extension/libherb/visitor.h +11 -0
- package/extension/nodes.cpp +117 -0
- package/extension/nodes.h +3 -0
- package/package.json +12 -20
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#ifndef HERB_ANALYZE_HELPERS_H
|
|
2
|
+
#define HERB_ANALYZE_HELPERS_H
|
|
3
|
+
|
|
4
|
+
#include <prism.h>
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
|
|
7
|
+
#include "analyzed_ruby.h"
|
|
8
|
+
|
|
9
|
+
bool has_if_node(analyzed_ruby_T* analyzed);
|
|
10
|
+
bool has_elsif_node(analyzed_ruby_T* analyzed);
|
|
11
|
+
bool has_else_node(analyzed_ruby_T* analyzed);
|
|
12
|
+
bool has_end(analyzed_ruby_T* analyzed);
|
|
13
|
+
bool has_block_node(analyzed_ruby_T* analyzed);
|
|
14
|
+
bool has_block_closing(analyzed_ruby_T* analyzed);
|
|
15
|
+
bool has_case_node(analyzed_ruby_T* analyzed);
|
|
16
|
+
bool has_case_match_node(analyzed_ruby_T* analyzed);
|
|
17
|
+
bool has_when_node(analyzed_ruby_T* analyzed);
|
|
18
|
+
bool has_in_node(analyzed_ruby_T* analyzed);
|
|
19
|
+
bool has_for_node(analyzed_ruby_T* analyzed);
|
|
20
|
+
bool has_while_node(analyzed_ruby_T* analyzed);
|
|
21
|
+
bool has_until_node(analyzed_ruby_T* analyzed);
|
|
22
|
+
bool has_begin_node(analyzed_ruby_T* analyzed);
|
|
23
|
+
bool has_rescue_node(analyzed_ruby_T* analyzed);
|
|
24
|
+
bool has_ensure_node(analyzed_ruby_T* analyzed);
|
|
25
|
+
bool has_unless_node(analyzed_ruby_T* analyzed);
|
|
26
|
+
bool has_yield_node(analyzed_ruby_T* analyzed);
|
|
27
|
+
|
|
28
|
+
bool has_error_message(analyzed_ruby_T* anlayzed, const char* message);
|
|
29
|
+
|
|
30
|
+
bool search_if_nodes(const pm_node_t* node, void* data);
|
|
31
|
+
bool search_block_nodes(const pm_node_t* node, void* data);
|
|
32
|
+
bool search_case_nodes(const pm_node_t* node, void* data);
|
|
33
|
+
bool search_case_match_nodes(const pm_node_t* node, void* data);
|
|
34
|
+
bool search_while_nodes(const pm_node_t* node, void* data);
|
|
35
|
+
bool search_for_nodes(const pm_node_t* node, void* data);
|
|
36
|
+
bool search_until_nodes(const pm_node_t* node, void* data);
|
|
37
|
+
bool search_begin_nodes(const pm_node_t* node, void* data);
|
|
38
|
+
bool search_unless_nodes(const pm_node_t* node, void* data);
|
|
39
|
+
bool search_elsif_nodes(analyzed_ruby_T* analyzed);
|
|
40
|
+
bool search_else_nodes(analyzed_ruby_T* analyzed);
|
|
41
|
+
bool search_end_nodes(analyzed_ruby_T* analyzed);
|
|
42
|
+
bool search_block_closing_nodes(analyzed_ruby_T* analyzed);
|
|
43
|
+
bool search_when_nodes(analyzed_ruby_T* analyzed);
|
|
44
|
+
bool search_in_nodes(analyzed_ruby_T* analyzed);
|
|
45
|
+
bool search_rescue_nodes(analyzed_ruby_T* analyzed);
|
|
46
|
+
bool search_ensure_nodes(analyzed_ruby_T* analyzed);
|
|
47
|
+
bool search_yield_nodes(analyzed_ruby_T* analyzed);
|
|
48
|
+
|
|
49
|
+
#endif
|
|
@@ -18,7 +18,9 @@ analyzed_ruby_T* init_analyzed_ruby(char* source) {
|
|
|
18
18
|
analyzed->has_block_node = false;
|
|
19
19
|
analyzed->has_block_closing = false;
|
|
20
20
|
analyzed->has_case_node = false;
|
|
21
|
+
analyzed->has_case_match_node = false;
|
|
21
22
|
analyzed->has_when_node = false;
|
|
23
|
+
analyzed->has_in_node = false;
|
|
22
24
|
analyzed->has_for_node = false;
|
|
23
25
|
analyzed->has_while_node = false;
|
|
24
26
|
analyzed->has_until_node = false;
|
|
@@ -26,10 +28,17 @@ analyzed_ruby_T* init_analyzed_ruby(char* source) {
|
|
|
26
28
|
analyzed->has_rescue_node = false;
|
|
27
29
|
analyzed->has_ensure_node = false;
|
|
28
30
|
analyzed->has_unless_node = false;
|
|
31
|
+
analyzed->has_yield_node = false;
|
|
29
32
|
|
|
30
33
|
return analyzed;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
void free_analyzed_ruby(analyzed_ruby_T* analyzed) {
|
|
34
|
-
|
|
37
|
+
if (!analyzed) { return; }
|
|
38
|
+
|
|
39
|
+
if (analyzed->parsed && analyzed->root != NULL) { pm_node_destroy(&analyzed->parser, analyzed->root); }
|
|
40
|
+
|
|
41
|
+
pm_parser_free(&analyzed->parser);
|
|
42
|
+
|
|
43
|
+
free(analyzed);
|
|
35
44
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#ifndef HERB_ANALYZED_RUBY_H
|
|
2
|
+
#define HERB_ANALYZED_RUBY_H
|
|
3
|
+
|
|
4
|
+
#include "array.h"
|
|
5
|
+
|
|
6
|
+
#include <prism.h>
|
|
7
|
+
|
|
8
|
+
typedef struct ANALYZED_RUBY_STRUCT {
|
|
9
|
+
pm_parser_t parser;
|
|
10
|
+
pm_node_t* root;
|
|
11
|
+
bool valid;
|
|
12
|
+
bool parsed;
|
|
13
|
+
bool has_if_node;
|
|
14
|
+
bool has_elsif_node;
|
|
15
|
+
bool has_else_node;
|
|
16
|
+
bool has_end;
|
|
17
|
+
bool has_block_closing;
|
|
18
|
+
bool has_block_node;
|
|
19
|
+
bool has_case_node;
|
|
20
|
+
bool has_case_match_node;
|
|
21
|
+
bool has_when_node;
|
|
22
|
+
bool has_in_node;
|
|
23
|
+
bool has_for_node;
|
|
24
|
+
bool has_while_node;
|
|
25
|
+
bool has_until_node;
|
|
26
|
+
bool has_begin_node;
|
|
27
|
+
bool has_rescue_node;
|
|
28
|
+
bool has_ensure_node;
|
|
29
|
+
bool has_unless_node;
|
|
30
|
+
bool has_yield_node;
|
|
31
|
+
} analyzed_ruby_T;
|
|
32
|
+
|
|
33
|
+
analyzed_ruby_T* init_analyzed_ruby(char* source);
|
|
34
|
+
void free_analyzed_ruby(analyzed_ruby_T* analyzed);
|
|
35
|
+
|
|
36
|
+
#endif
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#ifndef HERB_ARRAY_H
|
|
2
|
+
#define HERB_ARRAY_H
|
|
3
|
+
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
typedef struct ARRAY_STRUCT {
|
|
7
|
+
void** items;
|
|
8
|
+
size_t size;
|
|
9
|
+
size_t capacity;
|
|
10
|
+
} array_T;
|
|
11
|
+
|
|
12
|
+
array_T* array_init(size_t capacity);
|
|
13
|
+
|
|
14
|
+
void* array_get(const array_T* array, size_t index);
|
|
15
|
+
void* array_first(array_T* array);
|
|
16
|
+
void* array_last(array_T* array);
|
|
17
|
+
|
|
18
|
+
void array_append(array_T* array, void* item);
|
|
19
|
+
void array_set(const array_T* array, size_t index, void* item);
|
|
20
|
+
void array_free(array_T** array);
|
|
21
|
+
void array_remove(array_T* array, size_t index);
|
|
22
|
+
|
|
23
|
+
size_t array_index_of(array_T* array, void* item);
|
|
24
|
+
void array_remove_item(array_T* array, void* item);
|
|
25
|
+
|
|
26
|
+
void array_push(array_T* array, void* item);
|
|
27
|
+
void* array_pop(array_T* array);
|
|
28
|
+
|
|
29
|
+
size_t array_capacity(const array_T* array);
|
|
30
|
+
size_t array_size(const array_T* array);
|
|
31
|
+
size_t array_sizeof(void);
|
|
32
|
+
|
|
33
|
+
#endif
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#ifndef HERB_AST_H
|
|
2
|
+
#define HERB_AST_H
|
|
3
|
+
|
|
4
|
+
#include "ast_nodes.h"
|
|
5
|
+
#include "errors.h"
|
|
6
|
+
#include "position.h"
|
|
7
|
+
#include "token_struct.h"
|
|
8
|
+
|
|
9
|
+
void ast_node_init(AST_NODE_T* node, ast_node_type_T type, position_T* start, position_T* end, array_T* errors);
|
|
10
|
+
void ast_node_free(AST_NODE_T* node);
|
|
11
|
+
|
|
12
|
+
AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token);
|
|
13
|
+
|
|
14
|
+
size_t ast_node_sizeof(void);
|
|
15
|
+
size_t ast_node_child_count(AST_NODE_T* node);
|
|
16
|
+
|
|
17
|
+
ast_node_type_T ast_node_type(const AST_NODE_T* node);
|
|
18
|
+
|
|
19
|
+
char* ast_node_name(AST_NODE_T* node);
|
|
20
|
+
|
|
21
|
+
void ast_node_set_start(AST_NODE_T* node, position_T* position);
|
|
22
|
+
void ast_node_set_end(AST_NODE_T* node, position_T* position);
|
|
23
|
+
|
|
24
|
+
size_t ast_node_errors_count(const AST_NODE_T* node);
|
|
25
|
+
array_T* ast_node_errors(const AST_NODE_T* node);
|
|
26
|
+
void ast_node_append_error(const AST_NODE_T* node, ERROR_T* error);
|
|
27
|
+
|
|
28
|
+
void ast_node_set_start_from_token(AST_NODE_T* node, const token_T* token);
|
|
29
|
+
void ast_node_set_end_from_token(AST_NODE_T* node, const token_T* token);
|
|
30
|
+
|
|
31
|
+
void ast_node_set_positions_from_token(AST_NODE_T* node, const token_T* token);
|
|
32
|
+
|
|
33
|
+
bool ast_node_is(const AST_NODE_T* node, ast_node_type_T type);
|
|
34
|
+
|
|
35
|
+
#endif
|
|
@@ -266,6 +266,22 @@ AST_ERB_CASE_NODE_T* ast_erb_case_node_init(token_T* tag_opening, token_T* conte
|
|
|
266
266
|
return erb_case_node;
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
AST_ERB_CASE_MATCH_NODE_T* ast_erb_case_match_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) {
|
|
270
|
+
AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = malloc(sizeof(AST_ERB_CASE_MATCH_NODE_T));
|
|
271
|
+
|
|
272
|
+
ast_node_init(&erb_case_match_node->base, AST_ERB_CASE_MATCH_NODE, start_position, end_position, errors);
|
|
273
|
+
|
|
274
|
+
erb_case_match_node->tag_opening = token_copy(tag_opening);
|
|
275
|
+
erb_case_match_node->content = token_copy(content);
|
|
276
|
+
erb_case_match_node->tag_closing = token_copy(tag_closing);
|
|
277
|
+
erb_case_match_node->children = children;
|
|
278
|
+
erb_case_match_node->conditions = conditions;
|
|
279
|
+
erb_case_match_node->else_clause = else_clause;
|
|
280
|
+
erb_case_match_node->end_node = end_node;
|
|
281
|
+
|
|
282
|
+
return erb_case_match_node;
|
|
283
|
+
}
|
|
284
|
+
|
|
269
285
|
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) {
|
|
270
286
|
AST_ERB_WHILE_NODE_T* erb_while_node = malloc(sizeof(AST_ERB_WHILE_NODE_T));
|
|
271
287
|
|
|
@@ -367,6 +383,31 @@ AST_ERB_UNLESS_NODE_T* ast_erb_unless_node_init(token_T* tag_opening, token_T* c
|
|
|
367
383
|
return erb_unless_node;
|
|
368
384
|
}
|
|
369
385
|
|
|
386
|
+
AST_ERB_YIELD_NODE_T* ast_erb_yield_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors) {
|
|
387
|
+
AST_ERB_YIELD_NODE_T* erb_yield_node = malloc(sizeof(AST_ERB_YIELD_NODE_T));
|
|
388
|
+
|
|
389
|
+
ast_node_init(&erb_yield_node->base, AST_ERB_YIELD_NODE, start_position, end_position, errors);
|
|
390
|
+
|
|
391
|
+
erb_yield_node->tag_opening = token_copy(tag_opening);
|
|
392
|
+
erb_yield_node->content = token_copy(content);
|
|
393
|
+
erb_yield_node->tag_closing = token_copy(tag_closing);
|
|
394
|
+
|
|
395
|
+
return erb_yield_node;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
AST_ERB_IN_NODE_T* ast_erb_in_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) {
|
|
399
|
+
AST_ERB_IN_NODE_T* erb_in_node = malloc(sizeof(AST_ERB_IN_NODE_T));
|
|
400
|
+
|
|
401
|
+
ast_node_init(&erb_in_node->base, AST_ERB_IN_NODE, start_position, end_position, errors);
|
|
402
|
+
|
|
403
|
+
erb_in_node->tag_opening = token_copy(tag_opening);
|
|
404
|
+
erb_in_node->content = token_copy(content);
|
|
405
|
+
erb_in_node->tag_closing = token_copy(tag_closing);
|
|
406
|
+
erb_in_node->statements = statements;
|
|
407
|
+
|
|
408
|
+
return erb_in_node;
|
|
409
|
+
}
|
|
410
|
+
|
|
370
411
|
const char* ast_node_type_to_string(AST_NODE_T* node) {
|
|
371
412
|
switch (node->type) {
|
|
372
413
|
case AST_DOCUMENT_NODE: return "AST_DOCUMENT_NODE";
|
|
@@ -389,6 +430,7 @@ const char* ast_node_type_to_string(AST_NODE_T* node) {
|
|
|
389
430
|
case AST_ERB_BLOCK_NODE: return "AST_ERB_BLOCK_NODE";
|
|
390
431
|
case AST_ERB_WHEN_NODE: return "AST_ERB_WHEN_NODE";
|
|
391
432
|
case AST_ERB_CASE_NODE: return "AST_ERB_CASE_NODE";
|
|
433
|
+
case AST_ERB_CASE_MATCH_NODE: return "AST_ERB_CASE_MATCH_NODE";
|
|
392
434
|
case AST_ERB_WHILE_NODE: return "AST_ERB_WHILE_NODE";
|
|
393
435
|
case AST_ERB_UNTIL_NODE: return "AST_ERB_UNTIL_NODE";
|
|
394
436
|
case AST_ERB_FOR_NODE: return "AST_ERB_FOR_NODE";
|
|
@@ -396,6 +438,8 @@ const char* ast_node_type_to_string(AST_NODE_T* node) {
|
|
|
396
438
|
case AST_ERB_ENSURE_NODE: return "AST_ERB_ENSURE_NODE";
|
|
397
439
|
case AST_ERB_BEGIN_NODE: return "AST_ERB_BEGIN_NODE";
|
|
398
440
|
case AST_ERB_UNLESS_NODE: return "AST_ERB_UNLESS_NODE";
|
|
441
|
+
case AST_ERB_YIELD_NODE: return "AST_ERB_YIELD_NODE";
|
|
442
|
+
case AST_ERB_IN_NODE: return "AST_ERB_IN_NODE";
|
|
399
443
|
}
|
|
400
444
|
|
|
401
445
|
return "Unknown ast_node_type_T";
|
|
@@ -423,6 +467,7 @@ const char* ast_node_human_type(AST_NODE_T* node) {
|
|
|
423
467
|
case AST_ERB_BLOCK_NODE: return "ERBBlockNode";
|
|
424
468
|
case AST_ERB_WHEN_NODE: return "ERBWhenNode";
|
|
425
469
|
case AST_ERB_CASE_NODE: return "ERBCaseNode";
|
|
470
|
+
case AST_ERB_CASE_MATCH_NODE: return "ERBCaseMatchNode";
|
|
426
471
|
case AST_ERB_WHILE_NODE: return "ERBWhileNode";
|
|
427
472
|
case AST_ERB_UNTIL_NODE: return "ERBUntilNode";
|
|
428
473
|
case AST_ERB_FOR_NODE: return "ERBForNode";
|
|
@@ -430,6 +475,8 @@ const char* ast_node_human_type(AST_NODE_T* node) {
|
|
|
430
475
|
case AST_ERB_ENSURE_NODE: return "ERBEnsureNode";
|
|
431
476
|
case AST_ERB_BEGIN_NODE: return "ERBBeginNode";
|
|
432
477
|
case AST_ERB_UNLESS_NODE: return "ERBUnlessNode";
|
|
478
|
+
case AST_ERB_YIELD_NODE: return "ERBYieldNode";
|
|
479
|
+
case AST_ERB_IN_NODE: return "ERBInNode";
|
|
433
480
|
}
|
|
434
481
|
|
|
435
482
|
return "Unknown ast_node_type_T";
|
|
@@ -603,7 +650,9 @@ static void ast_free_erb_content_node(AST_ERB_CONTENT_NODE_T* erb_content_node)
|
|
|
603
650
|
if (erb_content_node->tag_opening != NULL) { token_free(erb_content_node->tag_opening); }
|
|
604
651
|
if (erb_content_node->content != NULL) { token_free(erb_content_node->content); }
|
|
605
652
|
if (erb_content_node->tag_closing != NULL) { token_free(erb_content_node->tag_closing); }
|
|
606
|
-
|
|
653
|
+
if (erb_content_node->analyzed_ruby != NULL) {
|
|
654
|
+
free_analyzed_ruby(erb_content_node->analyzed_ruby);
|
|
655
|
+
}
|
|
607
656
|
|
|
608
657
|
ast_free_base_node(&erb_content_node->base);
|
|
609
658
|
}
|
|
@@ -709,6 +758,32 @@ static void ast_free_erb_case_node(AST_ERB_CASE_NODE_T* erb_case_node) {
|
|
|
709
758
|
ast_free_base_node(&erb_case_node->base);
|
|
710
759
|
}
|
|
711
760
|
|
|
761
|
+
static void ast_free_erb_case_match_node(AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node) {
|
|
762
|
+
if (erb_case_match_node->tag_opening != NULL) { token_free(erb_case_match_node->tag_opening); }
|
|
763
|
+
if (erb_case_match_node->content != NULL) { token_free(erb_case_match_node->content); }
|
|
764
|
+
if (erb_case_match_node->tag_closing != NULL) { token_free(erb_case_match_node->tag_closing); }
|
|
765
|
+
if (erb_case_match_node->children != NULL) {
|
|
766
|
+
for (size_t i = 0; i < array_size(erb_case_match_node->children); i++) {
|
|
767
|
+
AST_NODE_T* child = array_get(erb_case_match_node->children, i);
|
|
768
|
+
if (child) { ast_node_free(child); }
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
array_free(&erb_case_match_node->children);
|
|
772
|
+
}
|
|
773
|
+
if (erb_case_match_node->conditions != NULL) {
|
|
774
|
+
for (size_t i = 0; i < array_size(erb_case_match_node->conditions); i++) {
|
|
775
|
+
AST_NODE_T* child = array_get(erb_case_match_node->conditions, i);
|
|
776
|
+
if (child) { ast_node_free(child); }
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
array_free(&erb_case_match_node->conditions);
|
|
780
|
+
}
|
|
781
|
+
ast_node_free((AST_NODE_T*) erb_case_match_node->else_clause);
|
|
782
|
+
ast_node_free((AST_NODE_T*) erb_case_match_node->end_node);
|
|
783
|
+
|
|
784
|
+
ast_free_base_node(&erb_case_match_node->base);
|
|
785
|
+
}
|
|
786
|
+
|
|
712
787
|
static void ast_free_erb_while_node(AST_ERB_WHILE_NODE_T* erb_while_node) {
|
|
713
788
|
if (erb_while_node->tag_opening != NULL) { token_free(erb_while_node->tag_opening); }
|
|
714
789
|
if (erb_while_node->content != NULL) { token_free(erb_while_node->content); }
|
|
@@ -831,6 +906,30 @@ static void ast_free_erb_unless_node(AST_ERB_UNLESS_NODE_T* erb_unless_node) {
|
|
|
831
906
|
ast_free_base_node(&erb_unless_node->base);
|
|
832
907
|
}
|
|
833
908
|
|
|
909
|
+
static void ast_free_erb_yield_node(AST_ERB_YIELD_NODE_T* erb_yield_node) {
|
|
910
|
+
if (erb_yield_node->tag_opening != NULL) { token_free(erb_yield_node->tag_opening); }
|
|
911
|
+
if (erb_yield_node->content != NULL) { token_free(erb_yield_node->content); }
|
|
912
|
+
if (erb_yield_node->tag_closing != NULL) { token_free(erb_yield_node->tag_closing); }
|
|
913
|
+
|
|
914
|
+
ast_free_base_node(&erb_yield_node->base);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
static void ast_free_erb_in_node(AST_ERB_IN_NODE_T* erb_in_node) {
|
|
918
|
+
if (erb_in_node->tag_opening != NULL) { token_free(erb_in_node->tag_opening); }
|
|
919
|
+
if (erb_in_node->content != NULL) { token_free(erb_in_node->content); }
|
|
920
|
+
if (erb_in_node->tag_closing != NULL) { token_free(erb_in_node->tag_closing); }
|
|
921
|
+
if (erb_in_node->statements != NULL) {
|
|
922
|
+
for (size_t i = 0; i < array_size(erb_in_node->statements); i++) {
|
|
923
|
+
AST_NODE_T* child = array_get(erb_in_node->statements, i);
|
|
924
|
+
if (child) { ast_node_free(child); }
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
array_free(&erb_in_node->statements);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
ast_free_base_node(&erb_in_node->base);
|
|
931
|
+
}
|
|
932
|
+
|
|
834
933
|
void ast_node_free(AST_NODE_T* node) {
|
|
835
934
|
if (!node) { return; }
|
|
836
935
|
|
|
@@ -855,6 +954,7 @@ void ast_node_free(AST_NODE_T* node) {
|
|
|
855
954
|
case AST_ERB_BLOCK_NODE: ast_free_erb_block_node((AST_ERB_BLOCK_NODE_T*) node); break;
|
|
856
955
|
case AST_ERB_WHEN_NODE: ast_free_erb_when_node((AST_ERB_WHEN_NODE_T*) node); break;
|
|
857
956
|
case AST_ERB_CASE_NODE: ast_free_erb_case_node((AST_ERB_CASE_NODE_T*) node); break;
|
|
957
|
+
case AST_ERB_CASE_MATCH_NODE: ast_free_erb_case_match_node((AST_ERB_CASE_MATCH_NODE_T*) node); break;
|
|
858
958
|
case AST_ERB_WHILE_NODE: ast_free_erb_while_node((AST_ERB_WHILE_NODE_T*) node); break;
|
|
859
959
|
case AST_ERB_UNTIL_NODE: ast_free_erb_until_node((AST_ERB_UNTIL_NODE_T*) node); break;
|
|
860
960
|
case AST_ERB_FOR_NODE: ast_free_erb_for_node((AST_ERB_FOR_NODE_T*) node); break;
|
|
@@ -862,5 +962,7 @@ void ast_node_free(AST_NODE_T* node) {
|
|
|
862
962
|
case AST_ERB_ENSURE_NODE: ast_free_erb_ensure_node((AST_ERB_ENSURE_NODE_T*) node); break;
|
|
863
963
|
case AST_ERB_BEGIN_NODE: ast_free_erb_begin_node((AST_ERB_BEGIN_NODE_T*) node); break;
|
|
864
964
|
case AST_ERB_UNLESS_NODE: ast_free_erb_unless_node((AST_ERB_UNLESS_NODE_T*) node); break;
|
|
965
|
+
case AST_ERB_YIELD_NODE: ast_free_erb_yield_node((AST_ERB_YIELD_NODE_T*) node); break;
|
|
966
|
+
case AST_ERB_IN_NODE: ast_free_erb_in_node((AST_ERB_IN_NODE_T*) node); break;
|
|
865
967
|
}
|
|
866
968
|
}
|