@herb-tools/node 0.1.0 → 0.2.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/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/main.c +1 -1
- 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 +11 -20
|
@@ -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
|
}
|
|
@@ -0,0 +1,335 @@
|
|
|
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_CASE_MATCH_NODE,
|
|
39
|
+
AST_ERB_WHILE_NODE,
|
|
40
|
+
AST_ERB_UNTIL_NODE,
|
|
41
|
+
AST_ERB_FOR_NODE,
|
|
42
|
+
AST_ERB_RESCUE_NODE,
|
|
43
|
+
AST_ERB_ENSURE_NODE,
|
|
44
|
+
AST_ERB_BEGIN_NODE,
|
|
45
|
+
AST_ERB_UNLESS_NODE,
|
|
46
|
+
AST_ERB_YIELD_NODE,
|
|
47
|
+
AST_ERB_IN_NODE,
|
|
48
|
+
} ast_node_type_T;
|
|
49
|
+
|
|
50
|
+
typedef struct AST_NODE_STRUCT {
|
|
51
|
+
ast_node_type_T type;
|
|
52
|
+
location_T* location;
|
|
53
|
+
// maybe a range too?
|
|
54
|
+
array_T* errors;
|
|
55
|
+
} AST_NODE_T;
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
typedef struct AST_DOCUMENT_NODE_STRUCT {
|
|
59
|
+
AST_NODE_T base;
|
|
60
|
+
array_T* children;
|
|
61
|
+
} AST_DOCUMENT_NODE_T;
|
|
62
|
+
|
|
63
|
+
typedef struct AST_LITERAL_NODE_STRUCT {
|
|
64
|
+
AST_NODE_T base;
|
|
65
|
+
const char* content;
|
|
66
|
+
} AST_LITERAL_NODE_T;
|
|
67
|
+
|
|
68
|
+
typedef struct AST_HTML_OPEN_TAG_NODE_STRUCT {
|
|
69
|
+
AST_NODE_T base;
|
|
70
|
+
token_T* tag_opening;
|
|
71
|
+
token_T* tag_name;
|
|
72
|
+
token_T* tag_closing;
|
|
73
|
+
array_T* children;
|
|
74
|
+
bool is_void;
|
|
75
|
+
} AST_HTML_OPEN_TAG_NODE_T;
|
|
76
|
+
|
|
77
|
+
typedef struct AST_HTML_CLOSE_TAG_NODE_STRUCT {
|
|
78
|
+
AST_NODE_T base;
|
|
79
|
+
token_T* tag_opening;
|
|
80
|
+
token_T* tag_name;
|
|
81
|
+
token_T* tag_closing;
|
|
82
|
+
} AST_HTML_CLOSE_TAG_NODE_T;
|
|
83
|
+
|
|
84
|
+
typedef struct AST_HTML_SELF_CLOSE_TAG_NODE_STRUCT {
|
|
85
|
+
AST_NODE_T base;
|
|
86
|
+
token_T* tag_opening;
|
|
87
|
+
token_T* tag_name;
|
|
88
|
+
array_T* attributes;
|
|
89
|
+
token_T* tag_closing;
|
|
90
|
+
bool is_void;
|
|
91
|
+
} AST_HTML_SELF_CLOSE_TAG_NODE_T;
|
|
92
|
+
|
|
93
|
+
typedef struct AST_HTML_ELEMENT_NODE_STRUCT {
|
|
94
|
+
AST_NODE_T base;
|
|
95
|
+
struct AST_HTML_OPEN_TAG_NODE_STRUCT* open_tag;
|
|
96
|
+
token_T* tag_name;
|
|
97
|
+
array_T* body;
|
|
98
|
+
struct AST_HTML_CLOSE_TAG_NODE_STRUCT* close_tag;
|
|
99
|
+
bool is_void;
|
|
100
|
+
} AST_HTML_ELEMENT_NODE_T;
|
|
101
|
+
|
|
102
|
+
typedef struct AST_HTML_ATTRIBUTE_VALUE_NODE_STRUCT {
|
|
103
|
+
AST_NODE_T base;
|
|
104
|
+
token_T* open_quote;
|
|
105
|
+
array_T* children;
|
|
106
|
+
token_T* close_quote;
|
|
107
|
+
bool quoted;
|
|
108
|
+
} AST_HTML_ATTRIBUTE_VALUE_NODE_T;
|
|
109
|
+
|
|
110
|
+
typedef struct AST_HTML_ATTRIBUTE_NAME_NODE_STRUCT {
|
|
111
|
+
AST_NODE_T base;
|
|
112
|
+
token_T* name;
|
|
113
|
+
} AST_HTML_ATTRIBUTE_NAME_NODE_T;
|
|
114
|
+
|
|
115
|
+
typedef struct AST_HTML_ATTRIBUTE_NODE_STRUCT {
|
|
116
|
+
AST_NODE_T base;
|
|
117
|
+
struct AST_HTML_ATTRIBUTE_NAME_NODE_STRUCT* name;
|
|
118
|
+
token_T* equals;
|
|
119
|
+
struct AST_HTML_ATTRIBUTE_VALUE_NODE_STRUCT* value;
|
|
120
|
+
} AST_HTML_ATTRIBUTE_NODE_T;
|
|
121
|
+
|
|
122
|
+
typedef struct AST_HTML_TEXT_NODE_STRUCT {
|
|
123
|
+
AST_NODE_T base;
|
|
124
|
+
const char* content;
|
|
125
|
+
} AST_HTML_TEXT_NODE_T;
|
|
126
|
+
|
|
127
|
+
typedef struct AST_HTML_COMMENT_NODE_STRUCT {
|
|
128
|
+
AST_NODE_T base;
|
|
129
|
+
token_T* comment_start;
|
|
130
|
+
array_T* children;
|
|
131
|
+
token_T* comment_end;
|
|
132
|
+
} AST_HTML_COMMENT_NODE_T;
|
|
133
|
+
|
|
134
|
+
typedef struct AST_HTML_DOCTYPE_NODE_STRUCT {
|
|
135
|
+
AST_NODE_T base;
|
|
136
|
+
token_T* tag_opening;
|
|
137
|
+
array_T* children;
|
|
138
|
+
token_T* tag_closing;
|
|
139
|
+
} AST_HTML_DOCTYPE_NODE_T;
|
|
140
|
+
|
|
141
|
+
typedef struct AST_WHITESPACE_NODE_STRUCT {
|
|
142
|
+
AST_NODE_T base;
|
|
143
|
+
token_T* value;
|
|
144
|
+
} AST_WHITESPACE_NODE_T;
|
|
145
|
+
|
|
146
|
+
typedef struct AST_ERB_CONTENT_NODE_STRUCT {
|
|
147
|
+
AST_NODE_T base;
|
|
148
|
+
token_T* tag_opening;
|
|
149
|
+
token_T* content;
|
|
150
|
+
token_T* tag_closing;
|
|
151
|
+
analyzed_ruby_T* analyzed_ruby;
|
|
152
|
+
bool parsed;
|
|
153
|
+
bool valid;
|
|
154
|
+
} AST_ERB_CONTENT_NODE_T;
|
|
155
|
+
|
|
156
|
+
typedef struct AST_ERB_END_NODE_STRUCT {
|
|
157
|
+
AST_NODE_T base;
|
|
158
|
+
token_T* tag_opening;
|
|
159
|
+
token_T* content;
|
|
160
|
+
token_T* tag_closing;
|
|
161
|
+
} AST_ERB_END_NODE_T;
|
|
162
|
+
|
|
163
|
+
typedef struct AST_ERB_ELSE_NODE_STRUCT {
|
|
164
|
+
AST_NODE_T base;
|
|
165
|
+
token_T* tag_opening;
|
|
166
|
+
token_T* content;
|
|
167
|
+
token_T* tag_closing;
|
|
168
|
+
array_T* statements;
|
|
169
|
+
} AST_ERB_ELSE_NODE_T;
|
|
170
|
+
|
|
171
|
+
typedef struct AST_ERB_IF_NODE_STRUCT {
|
|
172
|
+
AST_NODE_T base;
|
|
173
|
+
token_T* tag_opening;
|
|
174
|
+
token_T* content;
|
|
175
|
+
token_T* tag_closing;
|
|
176
|
+
array_T* statements;
|
|
177
|
+
AST_NODE_T* subsequent;
|
|
178
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
179
|
+
} AST_ERB_IF_NODE_T;
|
|
180
|
+
|
|
181
|
+
typedef struct AST_ERB_BLOCK_NODE_STRUCT {
|
|
182
|
+
AST_NODE_T base;
|
|
183
|
+
token_T* tag_opening;
|
|
184
|
+
token_T* content;
|
|
185
|
+
token_T* tag_closing;
|
|
186
|
+
array_T* body;
|
|
187
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
188
|
+
} AST_ERB_BLOCK_NODE_T;
|
|
189
|
+
|
|
190
|
+
typedef struct AST_ERB_WHEN_NODE_STRUCT {
|
|
191
|
+
AST_NODE_T base;
|
|
192
|
+
token_T* tag_opening;
|
|
193
|
+
token_T* content;
|
|
194
|
+
token_T* tag_closing;
|
|
195
|
+
array_T* statements;
|
|
196
|
+
} AST_ERB_WHEN_NODE_T;
|
|
197
|
+
|
|
198
|
+
typedef struct AST_ERB_CASE_NODE_STRUCT {
|
|
199
|
+
AST_NODE_T base;
|
|
200
|
+
token_T* tag_opening;
|
|
201
|
+
token_T* content;
|
|
202
|
+
token_T* tag_closing;
|
|
203
|
+
array_T* children;
|
|
204
|
+
array_T* conditions;
|
|
205
|
+
struct AST_ERB_ELSE_NODE_STRUCT* else_clause;
|
|
206
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
207
|
+
} AST_ERB_CASE_NODE_T;
|
|
208
|
+
|
|
209
|
+
typedef struct AST_ERB_CASE_MATCH_NODE_STRUCT {
|
|
210
|
+
AST_NODE_T base;
|
|
211
|
+
token_T* tag_opening;
|
|
212
|
+
token_T* content;
|
|
213
|
+
token_T* tag_closing;
|
|
214
|
+
array_T* children;
|
|
215
|
+
array_T* conditions;
|
|
216
|
+
struct AST_ERB_ELSE_NODE_STRUCT* else_clause;
|
|
217
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
218
|
+
} AST_ERB_CASE_MATCH_NODE_T;
|
|
219
|
+
|
|
220
|
+
typedef struct AST_ERB_WHILE_NODE_STRUCT {
|
|
221
|
+
AST_NODE_T base;
|
|
222
|
+
token_T* tag_opening;
|
|
223
|
+
token_T* content;
|
|
224
|
+
token_T* tag_closing;
|
|
225
|
+
array_T* statements;
|
|
226
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
227
|
+
} AST_ERB_WHILE_NODE_T;
|
|
228
|
+
|
|
229
|
+
typedef struct AST_ERB_UNTIL_NODE_STRUCT {
|
|
230
|
+
AST_NODE_T base;
|
|
231
|
+
token_T* tag_opening;
|
|
232
|
+
token_T* content;
|
|
233
|
+
token_T* tag_closing;
|
|
234
|
+
array_T* statements;
|
|
235
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
236
|
+
} AST_ERB_UNTIL_NODE_T;
|
|
237
|
+
|
|
238
|
+
typedef struct AST_ERB_FOR_NODE_STRUCT {
|
|
239
|
+
AST_NODE_T base;
|
|
240
|
+
token_T* tag_opening;
|
|
241
|
+
token_T* content;
|
|
242
|
+
token_T* tag_closing;
|
|
243
|
+
array_T* statements;
|
|
244
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
245
|
+
} AST_ERB_FOR_NODE_T;
|
|
246
|
+
|
|
247
|
+
typedef struct AST_ERB_RESCUE_NODE_STRUCT {
|
|
248
|
+
AST_NODE_T base;
|
|
249
|
+
token_T* tag_opening;
|
|
250
|
+
token_T* content;
|
|
251
|
+
token_T* tag_closing;
|
|
252
|
+
array_T* statements;
|
|
253
|
+
struct AST_ERB_RESCUE_NODE_STRUCT* subsequent;
|
|
254
|
+
} AST_ERB_RESCUE_NODE_T;
|
|
255
|
+
|
|
256
|
+
typedef struct AST_ERB_ENSURE_NODE_STRUCT {
|
|
257
|
+
AST_NODE_T base;
|
|
258
|
+
token_T* tag_opening;
|
|
259
|
+
token_T* content;
|
|
260
|
+
token_T* tag_closing;
|
|
261
|
+
array_T* statements;
|
|
262
|
+
} AST_ERB_ENSURE_NODE_T;
|
|
263
|
+
|
|
264
|
+
typedef struct AST_ERB_BEGIN_NODE_STRUCT {
|
|
265
|
+
AST_NODE_T base;
|
|
266
|
+
token_T* tag_opening;
|
|
267
|
+
token_T* content;
|
|
268
|
+
token_T* tag_closing;
|
|
269
|
+
array_T* statements;
|
|
270
|
+
struct AST_ERB_RESCUE_NODE_STRUCT* rescue_clause;
|
|
271
|
+
struct AST_ERB_ELSE_NODE_STRUCT* else_clause;
|
|
272
|
+
struct AST_ERB_ENSURE_NODE_STRUCT* ensure_clause;
|
|
273
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
274
|
+
} AST_ERB_BEGIN_NODE_T;
|
|
275
|
+
|
|
276
|
+
typedef struct AST_ERB_UNLESS_NODE_STRUCT {
|
|
277
|
+
AST_NODE_T base;
|
|
278
|
+
token_T* tag_opening;
|
|
279
|
+
token_T* content;
|
|
280
|
+
token_T* tag_closing;
|
|
281
|
+
array_T* statements;
|
|
282
|
+
struct AST_ERB_ELSE_NODE_STRUCT* else_clause;
|
|
283
|
+
struct AST_ERB_END_NODE_STRUCT* end_node;
|
|
284
|
+
} AST_ERB_UNLESS_NODE_T;
|
|
285
|
+
|
|
286
|
+
typedef struct AST_ERB_YIELD_NODE_STRUCT {
|
|
287
|
+
AST_NODE_T base;
|
|
288
|
+
token_T* tag_opening;
|
|
289
|
+
token_T* content;
|
|
290
|
+
token_T* tag_closing;
|
|
291
|
+
} AST_ERB_YIELD_NODE_T;
|
|
292
|
+
|
|
293
|
+
typedef struct AST_ERB_IN_NODE_STRUCT {
|
|
294
|
+
AST_NODE_T base;
|
|
295
|
+
token_T* tag_opening;
|
|
296
|
+
token_T* content;
|
|
297
|
+
token_T* tag_closing;
|
|
298
|
+
array_T* statements;
|
|
299
|
+
} AST_ERB_IN_NODE_T;
|
|
300
|
+
|
|
301
|
+
AST_DOCUMENT_NODE_T* ast_document_node_init(array_T* children, position_T* start_position, position_T* end_position, array_T* errors);
|
|
302
|
+
AST_LITERAL_NODE_T* ast_literal_node_init(const char* content, position_T* start_position, position_T* end_position, array_T* errors);
|
|
303
|
+
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);
|
|
304
|
+
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);
|
|
305
|
+
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);
|
|
306
|
+
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);
|
|
307
|
+
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);
|
|
308
|
+
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);
|
|
309
|
+
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);
|
|
310
|
+
AST_HTML_TEXT_NODE_T* ast_html_text_node_init(const char* content, position_T* start_position, position_T* end_position, array_T* errors);
|
|
311
|
+
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);
|
|
312
|
+
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);
|
|
313
|
+
AST_WHITESPACE_NODE_T* ast_whitespace_node_init(token_T* value, position_T* start_position, position_T* end_position, array_T* errors);
|
|
314
|
+
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);
|
|
315
|
+
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);
|
|
316
|
+
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);
|
|
317
|
+
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);
|
|
318
|
+
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);
|
|
319
|
+
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);
|
|
320
|
+
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);
|
|
321
|
+
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);
|
|
322
|
+
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);
|
|
323
|
+
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);
|
|
324
|
+
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);
|
|
325
|
+
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);
|
|
326
|
+
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);
|
|
327
|
+
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);
|
|
328
|
+
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);
|
|
329
|
+
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);
|
|
330
|
+
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);
|
|
331
|
+
|
|
332
|
+
const char* ast_node_type_to_string(AST_NODE_T* node);
|
|
333
|
+
const char* ast_node_human_type(AST_NODE_T* node);
|
|
334
|
+
|
|
335
|
+
#endif
|
|
@@ -364,6 +364,47 @@ void ast_pretty_print_node(AST_NODE_T* node, const size_t indent, const size_t r
|
|
|
364
364
|
|
|
365
365
|
} break;
|
|
366
366
|
|
|
367
|
+
case AST_ERB_CASE_MATCH_NODE: {
|
|
368
|
+
const AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = (AST_ERB_CASE_MATCH_NODE_T*) node;
|
|
369
|
+
|
|
370
|
+
pretty_print_errors(node, indent, relative_indent, false, buffer);
|
|
371
|
+
pretty_print_token_property(erb_case_match_node->tag_opening, "tag_opening", indent, relative_indent, false, buffer);
|
|
372
|
+
pretty_print_token_property(erb_case_match_node->content, "content", indent, relative_indent, false, buffer);
|
|
373
|
+
pretty_print_token_property(erb_case_match_node->tag_closing, "tag_closing", indent, relative_indent, false, buffer);
|
|
374
|
+
pretty_print_array("children", erb_case_match_node->children, indent, relative_indent, false, buffer);
|
|
375
|
+
pretty_print_array("conditions", erb_case_match_node->conditions, indent, relative_indent, false, buffer);
|
|
376
|
+
|
|
377
|
+
pretty_print_label("else_clause", indent, relative_indent, false, buffer);
|
|
378
|
+
|
|
379
|
+
if (erb_case_match_node->else_clause) {
|
|
380
|
+
buffer_append(buffer, "\n");
|
|
381
|
+
pretty_print_indent(buffer, indent);
|
|
382
|
+
pretty_print_indent(buffer, relative_indent + 1);
|
|
383
|
+
|
|
384
|
+
buffer_append(buffer, "└── ");
|
|
385
|
+
ast_pretty_print_node((AST_NODE_T*) erb_case_match_node->else_clause, indent, relative_indent + 2, buffer);
|
|
386
|
+
} else {
|
|
387
|
+
buffer_append(buffer, " ∅\n");
|
|
388
|
+
}
|
|
389
|
+
buffer_append(buffer, "\n");
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
pretty_print_label("end_node", indent, relative_indent, true, buffer);
|
|
393
|
+
|
|
394
|
+
if (erb_case_match_node->end_node) {
|
|
395
|
+
buffer_append(buffer, "\n");
|
|
396
|
+
pretty_print_indent(buffer, indent);
|
|
397
|
+
pretty_print_indent(buffer, relative_indent + 1);
|
|
398
|
+
|
|
399
|
+
buffer_append(buffer, "└── ");
|
|
400
|
+
ast_pretty_print_node((AST_NODE_T*) erb_case_match_node->end_node, indent, relative_indent + 2, buffer);
|
|
401
|
+
} else {
|
|
402
|
+
buffer_append(buffer, " ∅\n");
|
|
403
|
+
}
|
|
404
|
+
buffer_append(buffer, "\n");
|
|
405
|
+
|
|
406
|
+
} break;
|
|
407
|
+
|
|
367
408
|
case AST_ERB_WHILE_NODE: {
|
|
368
409
|
const AST_ERB_WHILE_NODE_T* erb_while_node = (AST_ERB_WHILE_NODE_T*) node;
|
|
369
410
|
|
|
@@ -584,5 +625,24 @@ void ast_pretty_print_node(AST_NODE_T* node, const size_t indent, const size_t r
|
|
|
584
625
|
|
|
585
626
|
} break;
|
|
586
627
|
|
|
628
|
+
case AST_ERB_YIELD_NODE: {
|
|
629
|
+
const AST_ERB_YIELD_NODE_T* erb_yield_node = (AST_ERB_YIELD_NODE_T*) node;
|
|
630
|
+
|
|
631
|
+
pretty_print_errors(node, indent, relative_indent, false, buffer);
|
|
632
|
+
pretty_print_token_property(erb_yield_node->tag_opening, "tag_opening", indent, relative_indent, false, buffer);
|
|
633
|
+
pretty_print_token_property(erb_yield_node->content, "content", indent, relative_indent, false, buffer);
|
|
634
|
+
pretty_print_token_property(erb_yield_node->tag_closing, "tag_closing", indent, relative_indent, true, buffer);
|
|
635
|
+
} break;
|
|
636
|
+
|
|
637
|
+
case AST_ERB_IN_NODE: {
|
|
638
|
+
const AST_ERB_IN_NODE_T* erb_in_node = (AST_ERB_IN_NODE_T*) node;
|
|
639
|
+
|
|
640
|
+
pretty_print_errors(node, indent, relative_indent, false, buffer);
|
|
641
|
+
pretty_print_token_property(erb_in_node->tag_opening, "tag_opening", indent, relative_indent, false, buffer);
|
|
642
|
+
pretty_print_token_property(erb_in_node->content, "content", indent, relative_indent, false, buffer);
|
|
643
|
+
pretty_print_token_property(erb_in_node->tag_closing, "tag_closing", indent, relative_indent, false, buffer);
|
|
644
|
+
pretty_print_array("statements", erb_in_node->statements, indent, relative_indent, true, buffer);
|
|
645
|
+
} break;
|
|
646
|
+
|
|
587
647
|
}
|
|
588
648
|
}
|