@herb-tools/node 0.8.10 → 0.9.1
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/binding.gyp +27 -8
- package/dist/herb-node.cjs +41 -12
- package/dist/herb-node.cjs.map +1 -1
- package/dist/herb-node.esm.js +8 -1
- package/dist/herb-node.esm.js.map +1 -1
- package/dist/types/node-backend.d.ts +3 -1
- package/extension/error_helpers.cpp +598 -73
- package/extension/error_helpers.h +20 -3
- package/extension/extension_helpers.cpp +40 -35
- package/extension/extension_helpers.h +2 -2
- package/extension/herb.cpp +194 -64
- package/extension/libherb/analyze/action_view/attribute_extraction_helpers.c +303 -0
- package/extension/libherb/analyze/action_view/attribute_extraction_helpers.h +36 -0
- package/extension/libherb/analyze/action_view/content_tag.c +78 -0
- package/extension/libherb/analyze/action_view/link_to.c +167 -0
- package/extension/libherb/analyze/action_view/registry.c +83 -0
- package/extension/libherb/analyze/action_view/tag.c +70 -0
- package/extension/libherb/analyze/action_view/tag_helper_handler.h +43 -0
- package/extension/libherb/analyze/action_view/tag_helper_node_builders.c +305 -0
- package/extension/libherb/analyze/action_view/tag_helper_node_builders.h +70 -0
- package/extension/libherb/analyze/action_view/tag_helpers.c +815 -0
- package/extension/libherb/analyze/action_view/tag_helpers.h +38 -0
- package/extension/libherb/analyze/action_view/turbo_frame_tag.c +88 -0
- package/extension/libherb/analyze/analyze.c +885 -0
- package/extension/libherb/{include → analyze}/analyze.h +14 -4
- package/extension/libherb/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
- package/extension/libherb/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- package/extension/libherb/analyze/builders.c +343 -0
- package/extension/libherb/analyze/builders.h +27 -0
- package/extension/libherb/analyze/conditional_elements.c +594 -0
- package/extension/libherb/analyze/conditional_elements.h +9 -0
- package/extension/libherb/analyze/conditional_open_tags.c +640 -0
- package/extension/libherb/analyze/conditional_open_tags.h +9 -0
- package/extension/libherb/analyze/control_type.c +250 -0
- package/extension/libherb/analyze/control_type.h +14 -0
- package/extension/libherb/{analyze_helpers.c → analyze/helpers.c} +48 -23
- package/extension/libherb/{analyze_helpers.h → analyze/helpers.h} +4 -2
- package/extension/libherb/analyze/invalid_structures.c +193 -0
- package/extension/libherb/analyze/invalid_structures.h +11 -0
- package/extension/libherb/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
- package/extension/libherb/analyze/parse_errors.c +84 -0
- package/extension/libherb/analyze/prism_annotate.c +399 -0
- package/extension/libherb/analyze/prism_annotate.h +16 -0
- package/extension/libherb/analyze/render_nodes.c +761 -0
- package/extension/libherb/analyze/render_nodes.h +11 -0
- package/extension/libherb/{analyze_transform.c → analyze/transform.c} +24 -3
- package/extension/libherb/ast_node.c +17 -7
- package/extension/libherb/ast_node.h +11 -5
- package/extension/libherb/ast_nodes.c +760 -388
- package/extension/libherb/ast_nodes.h +155 -39
- package/extension/libherb/ast_pretty_print.c +265 -7
- package/extension/libherb/ast_pretty_print.h +6 -1
- package/extension/libherb/element_source.h +3 -8
- package/extension/libherb/errors.c +1455 -520
- package/extension/libherb/errors.h +207 -56
- package/extension/libherb/extract.c +145 -49
- package/extension/libherb/extract.h +21 -5
- package/extension/libherb/herb.c +52 -34
- package/extension/libherb/herb.h +18 -6
- package/extension/libherb/herb_prism_node.h +13 -0
- package/extension/libherb/html_util.c +241 -12
- package/extension/libherb/html_util.h +7 -2
- package/extension/libherb/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
- package/extension/libherb/include/analyze/action_view/tag_helper_handler.h +43 -0
- package/extension/libherb/include/analyze/action_view/tag_helper_node_builders.h +70 -0
- package/extension/libherb/include/analyze/action_view/tag_helpers.h +38 -0
- package/extension/libherb/{analyze.h → include/analyze/analyze.h} +14 -4
- package/extension/libherb/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- package/extension/libherb/include/analyze/builders.h +27 -0
- package/extension/libherb/include/analyze/conditional_elements.h +9 -0
- package/extension/libherb/include/analyze/conditional_open_tags.h +9 -0
- package/extension/libherb/include/analyze/control_type.h +14 -0
- package/extension/libherb/include/{analyze_helpers.h → analyze/helpers.h} +4 -2
- package/extension/libherb/include/analyze/invalid_structures.h +11 -0
- package/extension/libherb/include/analyze/prism_annotate.h +16 -0
- package/extension/libherb/include/analyze/render_nodes.h +11 -0
- package/extension/libherb/include/ast_node.h +11 -5
- package/extension/libherb/include/ast_nodes.h +155 -39
- package/extension/libherb/include/ast_pretty_print.h +6 -1
- package/extension/libherb/include/element_source.h +3 -8
- package/extension/libherb/include/errors.h +207 -56
- package/extension/libherb/include/extract.h +21 -5
- package/extension/libherb/include/herb.h +18 -6
- package/extension/libherb/include/herb_prism_node.h +13 -0
- package/extension/libherb/include/html_util.h +7 -2
- package/extension/libherb/include/io.h +3 -1
- package/extension/libherb/include/lex_helpers.h +29 -0
- package/extension/libherb/include/lexer.h +1 -1
- package/extension/libherb/include/lexer_peek_helpers.h +87 -13
- package/extension/libherb/include/lexer_struct.h +2 -0
- package/extension/libherb/include/location.h +2 -1
- package/extension/libherb/include/parser.h +28 -2
- package/extension/libherb/include/parser_helpers.h +19 -3
- package/extension/libherb/include/pretty_print.h +10 -5
- package/extension/libherb/include/prism_context.h +45 -0
- package/extension/libherb/include/prism_helpers.h +10 -7
- package/extension/libherb/include/prism_serialized.h +12 -0
- package/extension/libherb/include/token.h +16 -4
- package/extension/libherb/include/token_struct.h +10 -3
- package/extension/libherb/include/utf8.h +2 -1
- package/extension/libherb/include/util/hb_allocator.h +78 -0
- package/extension/libherb/include/util/hb_arena.h +6 -1
- package/extension/libherb/include/util/hb_arena_debug.h +12 -1
- package/extension/libherb/include/util/hb_array.h +7 -3
- package/extension/libherb/include/util/hb_buffer.h +6 -4
- package/extension/libherb/include/util/hb_foreach.h +79 -0
- package/extension/libherb/include/util/hb_narray.h +8 -4
- package/extension/libherb/include/util/hb_string.h +56 -9
- package/extension/libherb/include/util.h +6 -3
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/io.c +3 -2
- package/extension/libherb/io.h +3 -1
- package/extension/libherb/lex_helpers.h +29 -0
- package/extension/libherb/lexer.c +42 -30
- package/extension/libherb/lexer.h +1 -1
- package/extension/libherb/lexer_peek_helpers.c +12 -74
- package/extension/libherb/lexer_peek_helpers.h +87 -13
- package/extension/libherb/lexer_struct.h +2 -0
- package/extension/libherb/location.c +2 -2
- package/extension/libherb/location.h +2 -1
- package/extension/libherb/main.c +53 -28
- package/extension/libherb/parser.c +784 -247
- package/extension/libherb/parser.h +28 -2
- package/extension/libherb/parser_helpers.c +110 -23
- package/extension/libherb/parser_helpers.h +19 -3
- package/extension/libherb/parser_match_tags.c +130 -49
- package/extension/libherb/pretty_print.c +29 -24
- package/extension/libherb/pretty_print.h +10 -5
- package/extension/libherb/prism_context.h +45 -0
- package/extension/libherb/prism_helpers.c +30 -27
- package/extension/libherb/prism_helpers.h +10 -7
- package/extension/libherb/prism_serialized.h +12 -0
- package/extension/libherb/ruby_parser.c +2 -0
- package/extension/libherb/token.c +151 -66
- package/extension/libherb/token.h +16 -4
- package/extension/libherb/token_matchers.c +0 -1
- package/extension/libherb/token_struct.h +10 -3
- package/extension/libherb/utf8.c +7 -6
- package/extension/libherb/utf8.h +2 -1
- package/extension/libherb/util/hb_allocator.c +341 -0
- package/extension/libherb/util/hb_allocator.h +78 -0
- package/extension/libherb/util/hb_arena.c +81 -56
- package/extension/libherb/util/hb_arena.h +6 -1
- package/extension/libherb/util/hb_arena_debug.c +32 -17
- package/extension/libherb/util/hb_arena_debug.h +12 -1
- package/extension/libherb/util/hb_array.c +30 -15
- package/extension/libherb/util/hb_array.h +7 -3
- package/extension/libherb/util/hb_buffer.c +17 -21
- package/extension/libherb/util/hb_buffer.h +6 -4
- package/extension/libherb/util/hb_foreach.h +79 -0
- package/extension/libherb/util/hb_narray.c +22 -7
- package/extension/libherb/util/hb_narray.h +8 -4
- package/extension/libherb/util/hb_string.c +49 -35
- package/extension/libherb/util/hb_string.h +56 -9
- package/extension/libherb/util.c +21 -11
- package/extension/libherb/util.h +6 -3
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +68 -1
- package/extension/nodes.cpp +593 -6
- package/extension/nodes.h +10 -1
- package/package.json +12 -8
- package/src/node-backend.ts +11 -1
- package/dist/types/index-cjs.d.cts +0 -1
- package/extension/libherb/analyze.c +0 -1608
- package/extension/libherb/element_source.c +0 -12
- package/extension/libherb/include/util/hb_system.h +0 -9
- package/extension/libherb/util/hb_system.c +0 -30
- package/extension/libherb/util/hb_system.h +0 -9
- package/src/index-cjs.cts +0 -22
- /package/dist/types/{index-esm.d.mts → index.d.ts} +0 -0
- /package/src/{index-esm.mts → index.ts} +0 -0
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
#ifndef HERB_ANALYZE_H
|
|
2
2
|
#define HERB_ANALYZE_H
|
|
3
3
|
|
|
4
|
+
#include "../ast_nodes.h"
|
|
5
|
+
#include "../parser.h"
|
|
6
|
+
#include "../util/hb_allocator.h"
|
|
7
|
+
#include "../util/hb_array.h"
|
|
4
8
|
#include "analyzed_ruby.h"
|
|
5
|
-
#include "ast_nodes.h"
|
|
6
|
-
#include "util/hb_array.h"
|
|
7
9
|
|
|
8
10
|
typedef struct ANALYZE_RUBY_CONTEXT_STRUCT {
|
|
9
11
|
AST_DOCUMENT_NODE_T* document;
|
|
10
12
|
AST_NODE_T* parent;
|
|
11
13
|
hb_array_T* ruby_context_stack;
|
|
14
|
+
hb_allocator_T* allocator;
|
|
15
|
+
const char* source;
|
|
12
16
|
} analyze_ruby_context_T;
|
|
13
17
|
|
|
14
18
|
typedef enum {
|
|
@@ -36,10 +40,16 @@ typedef enum {
|
|
|
36
40
|
typedef struct {
|
|
37
41
|
int loop_depth;
|
|
38
42
|
int rescue_depth;
|
|
43
|
+
hb_allocator_T* allocator;
|
|
39
44
|
} invalid_erb_context_T;
|
|
40
45
|
|
|
41
|
-
void herb_analyze_parse_errors(AST_DOCUMENT_NODE_T* document, const char* source);
|
|
42
|
-
void herb_analyze_parse_tree(
|
|
46
|
+
void herb_analyze_parse_errors(AST_DOCUMENT_NODE_T* document, const char* source, hb_allocator_T* allocator);
|
|
47
|
+
void herb_analyze_parse_tree(
|
|
48
|
+
AST_DOCUMENT_NODE_T* document,
|
|
49
|
+
const char* source,
|
|
50
|
+
const parser_options_T* options,
|
|
51
|
+
hb_allocator_T* allocator
|
|
52
|
+
);
|
|
43
53
|
|
|
44
54
|
hb_array_T* rewrite_node_array(AST_NODE_T* node, hb_array_T* array, analyze_ruby_context_T* context);
|
|
45
55
|
bool transform_erb_nodes(const AST_NODE_T* node, void* data);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#include "include/analyzed_ruby.h"
|
|
2
|
-
#include "include/util/hb_string.h"
|
|
1
|
+
#include "../include/analyze/analyzed_ruby.h"
|
|
2
|
+
#include "../include/util/hb_string.h"
|
|
3
3
|
|
|
4
4
|
#include <prism.h>
|
|
5
5
|
#include <string.h>
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
analyzed_ruby_T* init_analyzed_ruby(hb_string_T source) {
|
|
8
8
|
analyzed_ruby_T* analyzed = malloc(sizeof(analyzed_ruby_T));
|
|
9
9
|
|
|
10
|
+
if (!analyzed) { return NULL; }
|
|
11
|
+
|
|
10
12
|
pm_parser_init(&analyzed->parser, (const uint8_t*) source.data, source.length, NULL);
|
|
11
13
|
|
|
12
14
|
analyzed->root = pm_parse(&analyzed->parser);
|
|
@@ -46,22 +48,22 @@ void free_analyzed_ruby(analyzed_ruby_T* analyzed) {
|
|
|
46
48
|
free(analyzed);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
hb_string_T erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed) {
|
|
50
52
|
if (analyzed->end_count > 0) {
|
|
51
|
-
return "`<% end %>`";
|
|
53
|
+
return hb_string("`<% end %>`");
|
|
52
54
|
} else if (analyzed->else_node_count > 0) {
|
|
53
|
-
return "`<% else %>`";
|
|
55
|
+
return hb_string("`<% else %>`");
|
|
54
56
|
} else if (analyzed->elsif_node_count > 0) {
|
|
55
|
-
return "`<% elsif %>`";
|
|
57
|
+
return hb_string("`<% elsif %>`");
|
|
56
58
|
} else if (analyzed->when_node_count > 0) {
|
|
57
|
-
return "`<% when %>`";
|
|
59
|
+
return hb_string("`<% when %>`");
|
|
58
60
|
} else if (analyzed->in_node_count > 0) {
|
|
59
|
-
return "`<% in %>`";
|
|
61
|
+
return hb_string("`<% in %>`");
|
|
60
62
|
} else if (analyzed->rescue_node_count > 0) {
|
|
61
|
-
return "`<% rescue %>`";
|
|
63
|
+
return hb_string("`<% rescue %>`");
|
|
62
64
|
} else if (analyzed->ensure_node_count > 0) {
|
|
63
|
-
return "`<% ensure %>`";
|
|
65
|
+
return hb_string("`<% ensure %>`");
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
return
|
|
68
|
+
return HB_STRING_NULL;
|
|
67
69
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#ifndef HERB_ANALYZED_RUBY_H
|
|
2
2
|
#define HERB_ANALYZED_RUBY_H
|
|
3
3
|
|
|
4
|
-
#include "util/hb_array.h"
|
|
5
|
-
#include "util/hb_string.h"
|
|
4
|
+
#include "../util/hb_array.h"
|
|
5
|
+
#include "../util/hb_string.h"
|
|
6
6
|
|
|
7
7
|
#include <prism.h>
|
|
8
8
|
|
|
@@ -35,6 +35,6 @@ typedef struct ANALYZED_RUBY_STRUCT {
|
|
|
35
35
|
|
|
36
36
|
analyzed_ruby_T* init_analyzed_ruby(hb_string_T source);
|
|
37
37
|
void free_analyzed_ruby(analyzed_ruby_T* analyzed);
|
|
38
|
-
|
|
38
|
+
hb_string_T erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed);
|
|
39
39
|
|
|
40
40
|
#endif
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
#include "../include/analyze/builders.h"
|
|
2
|
+
#include "../include/analyze/analyze.h"
|
|
3
|
+
#include "../include/ast_nodes.h"
|
|
4
|
+
#include "../include/location.h"
|
|
5
|
+
#include "../include/position.h"
|
|
6
|
+
#include "../include/prism_helpers.h"
|
|
7
|
+
#include "../include/token_struct.h"
|
|
8
|
+
#include "../include/util/hb_allocator.h"
|
|
9
|
+
#include "../include/util/hb_array.h"
|
|
10
|
+
#include "../include/util/hb_string.h"
|
|
11
|
+
|
|
12
|
+
#include <stddef.h>
|
|
13
|
+
#include <string.h>
|
|
14
|
+
|
|
15
|
+
position_T erb_content_end_position(const AST_ERB_CONTENT_NODE_T* erb_node) {
|
|
16
|
+
if (erb_node->tag_closing != NULL) {
|
|
17
|
+
return erb_node->tag_closing->location.end;
|
|
18
|
+
} else if (erb_node->content != NULL) {
|
|
19
|
+
return erb_node->content->location.end;
|
|
20
|
+
} else {
|
|
21
|
+
return erb_node->tag_opening->location.end;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
location_T* compute_then_keyword(
|
|
26
|
+
AST_ERB_CONTENT_NODE_T* erb_node,
|
|
27
|
+
control_type_t control_type,
|
|
28
|
+
hb_allocator_T* allocator
|
|
29
|
+
) {
|
|
30
|
+
if (control_type != CONTROL_TYPE_IF && control_type != CONTROL_TYPE_ELSIF && control_type != CONTROL_TYPE_UNLESS
|
|
31
|
+
&& control_type != CONTROL_TYPE_WHEN && control_type != CONTROL_TYPE_IN) {
|
|
32
|
+
return NULL;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
token_T* content = erb_node->content;
|
|
36
|
+
const char* source = (content && !hb_string_is_empty(content->value))
|
|
37
|
+
? hb_allocator_strndup(allocator, content->value.data, content->value.length)
|
|
38
|
+
: NULL;
|
|
39
|
+
location_T* then_keyword = NULL;
|
|
40
|
+
|
|
41
|
+
if (control_type == CONTROL_TYPE_WHEN || control_type == CONTROL_TYPE_IN) {
|
|
42
|
+
if (source != NULL && strstr(source, "then") != NULL) {
|
|
43
|
+
then_keyword = get_then_keyword_location_wrapped(source, control_type == CONTROL_TYPE_IN, allocator);
|
|
44
|
+
}
|
|
45
|
+
} else if (control_type == CONTROL_TYPE_ELSIF) {
|
|
46
|
+
if (source != NULL && strstr(source, "then") != NULL) {
|
|
47
|
+
then_keyword = get_then_keyword_location_elsif_wrapped(source, allocator);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
then_keyword = get_then_keyword_location(erb_node->analyzed_ruby, source, allocator);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (then_keyword != NULL && content != NULL) {
|
|
54
|
+
position_T content_start = content->location.start;
|
|
55
|
+
|
|
56
|
+
then_keyword->start.line = content_start.line + then_keyword->start.line - 1;
|
|
57
|
+
then_keyword->start.column = content_start.column + then_keyword->start.column;
|
|
58
|
+
then_keyword->end.line = content_start.line + then_keyword->end.line - 1;
|
|
59
|
+
then_keyword->end.column = content_start.column + then_keyword->end.column;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return then_keyword;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
typedef struct {
|
|
66
|
+
AST_ERB_CONTENT_NODE_T* erb;
|
|
67
|
+
hb_array_T* children;
|
|
68
|
+
AST_NODE_T* subsequent;
|
|
69
|
+
AST_ERB_END_NODE_T* end_node;
|
|
70
|
+
token_T* tag_opening;
|
|
71
|
+
token_T* content;
|
|
72
|
+
token_T* tag_closing;
|
|
73
|
+
location_T* then_keyword;
|
|
74
|
+
position_T start_position;
|
|
75
|
+
position_T end_position;
|
|
76
|
+
hb_array_T* errors;
|
|
77
|
+
control_type_t control_type;
|
|
78
|
+
hb_allocator_T* allocator;
|
|
79
|
+
} control_builder_context_T;
|
|
80
|
+
|
|
81
|
+
typedef AST_NODE_T* (*control_builder_fn)(control_builder_context_T* context);
|
|
82
|
+
|
|
83
|
+
typedef struct {
|
|
84
|
+
control_type_t type;
|
|
85
|
+
control_builder_fn builder;
|
|
86
|
+
} control_builder_entry_T;
|
|
87
|
+
|
|
88
|
+
static AST_NODE_T* build_if_node(control_builder_context_T* context);
|
|
89
|
+
static AST_NODE_T* build_else_node(control_builder_context_T* context);
|
|
90
|
+
static AST_NODE_T* build_when_node(control_builder_context_T* context);
|
|
91
|
+
static AST_NODE_T* build_in_node(control_builder_context_T* context);
|
|
92
|
+
static AST_NODE_T* build_rescue_node(control_builder_context_T* context);
|
|
93
|
+
static AST_NODE_T* build_ensure_node(control_builder_context_T* context);
|
|
94
|
+
static AST_NODE_T* build_unless_node(control_builder_context_T* context);
|
|
95
|
+
static AST_NODE_T* build_while_node(control_builder_context_T* context);
|
|
96
|
+
static AST_NODE_T* build_until_node(control_builder_context_T* context);
|
|
97
|
+
static AST_NODE_T* build_for_node(control_builder_context_T* context);
|
|
98
|
+
static AST_NODE_T* build_block_node(control_builder_context_T* context);
|
|
99
|
+
static AST_NODE_T* build_yield_node(control_builder_context_T* context);
|
|
100
|
+
|
|
101
|
+
static const control_builder_entry_T CONTROL_BUILDERS[] = {
|
|
102
|
+
{ CONTROL_TYPE_IF, build_if_node }, { CONTROL_TYPE_ELSIF, build_if_node },
|
|
103
|
+
{ CONTROL_TYPE_ELSE, build_else_node }, { CONTROL_TYPE_WHEN, build_when_node },
|
|
104
|
+
{ CONTROL_TYPE_IN, build_in_node }, { CONTROL_TYPE_RESCUE, build_rescue_node },
|
|
105
|
+
{ CONTROL_TYPE_ENSURE, build_ensure_node }, { CONTROL_TYPE_UNLESS, build_unless_node },
|
|
106
|
+
{ CONTROL_TYPE_WHILE, build_while_node }, { CONTROL_TYPE_UNTIL, build_until_node },
|
|
107
|
+
{ CONTROL_TYPE_FOR, build_for_node }, { CONTROL_TYPE_BLOCK, build_block_node },
|
|
108
|
+
{ CONTROL_TYPE_YIELD, build_yield_node },
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
static control_builder_fn lookup_control_builder(control_type_t type) {
|
|
112
|
+
for (size_t i = 0; i < sizeof(CONTROL_BUILDERS) / sizeof(CONTROL_BUILDERS[0]); i++) {
|
|
113
|
+
if (CONTROL_BUILDERS[i].type == type) { return CONTROL_BUILDERS[i].builder; }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return NULL;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
AST_NODE_T* create_control_node(
|
|
120
|
+
AST_ERB_CONTENT_NODE_T* erb_node,
|
|
121
|
+
hb_array_T* children,
|
|
122
|
+
AST_NODE_T* subsequent,
|
|
123
|
+
AST_ERB_END_NODE_T* end_node,
|
|
124
|
+
control_type_t control_type,
|
|
125
|
+
hb_allocator_T* allocator
|
|
126
|
+
) {
|
|
127
|
+
control_builder_context_T context = { .erb = erb_node,
|
|
128
|
+
.children = children,
|
|
129
|
+
.subsequent = subsequent,
|
|
130
|
+
.end_node = end_node,
|
|
131
|
+
.tag_opening = erb_node->tag_opening,
|
|
132
|
+
.content = erb_node->content,
|
|
133
|
+
.tag_closing = erb_node->tag_closing,
|
|
134
|
+
.then_keyword = compute_then_keyword(erb_node, control_type, allocator),
|
|
135
|
+
.start_position = erb_node->tag_opening->location.start,
|
|
136
|
+
.end_position = erb_content_end_position(erb_node),
|
|
137
|
+
.errors = erb_node->base.errors,
|
|
138
|
+
.control_type = control_type,
|
|
139
|
+
.allocator = allocator };
|
|
140
|
+
|
|
141
|
+
erb_node->base.errors = NULL;
|
|
142
|
+
|
|
143
|
+
if (context.end_node) {
|
|
144
|
+
context.end_position = context.end_node->base.location.end;
|
|
145
|
+
} else if (hb_array_size(context.children) > 0) {
|
|
146
|
+
AST_NODE_T* last_child = hb_array_last(context.children);
|
|
147
|
+
context.end_position = last_child->location.end;
|
|
148
|
+
} else if (context.subsequent) {
|
|
149
|
+
context.end_position = context.subsequent->location.end;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
control_builder_fn builder = lookup_control_builder(control_type);
|
|
153
|
+
|
|
154
|
+
if (!builder) { return NULL; }
|
|
155
|
+
|
|
156
|
+
return builder(&context);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static AST_NODE_T* build_if_node(control_builder_context_T* context) {
|
|
160
|
+
return (AST_NODE_T*) ast_erb_if_node_init(
|
|
161
|
+
context->tag_opening,
|
|
162
|
+
context->content,
|
|
163
|
+
context->tag_closing,
|
|
164
|
+
context->then_keyword,
|
|
165
|
+
HERB_PRISM_NODE_EMPTY,
|
|
166
|
+
context->children,
|
|
167
|
+
context->subsequent,
|
|
168
|
+
context->end_node,
|
|
169
|
+
context->start_position,
|
|
170
|
+
context->end_position,
|
|
171
|
+
context->errors,
|
|
172
|
+
context->allocator
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static AST_NODE_T* build_else_node(control_builder_context_T* context) {
|
|
177
|
+
return (AST_NODE_T*) ast_erb_else_node_init(
|
|
178
|
+
context->tag_opening,
|
|
179
|
+
context->content,
|
|
180
|
+
context->tag_closing,
|
|
181
|
+
context->children,
|
|
182
|
+
context->start_position,
|
|
183
|
+
context->end_position,
|
|
184
|
+
context->errors,
|
|
185
|
+
context->allocator
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static AST_NODE_T* build_when_node(control_builder_context_T* context) {
|
|
190
|
+
return (AST_NODE_T*) ast_erb_when_node_init(
|
|
191
|
+
context->tag_opening,
|
|
192
|
+
context->content,
|
|
193
|
+
context->tag_closing,
|
|
194
|
+
context->then_keyword,
|
|
195
|
+
context->children,
|
|
196
|
+
context->start_position,
|
|
197
|
+
context->end_position,
|
|
198
|
+
context->errors,
|
|
199
|
+
context->allocator
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
static AST_NODE_T* build_in_node(control_builder_context_T* context) {
|
|
204
|
+
return (AST_NODE_T*) ast_erb_in_node_init(
|
|
205
|
+
context->tag_opening,
|
|
206
|
+
context->content,
|
|
207
|
+
context->tag_closing,
|
|
208
|
+
context->then_keyword,
|
|
209
|
+
context->children,
|
|
210
|
+
context->start_position,
|
|
211
|
+
context->end_position,
|
|
212
|
+
context->errors,
|
|
213
|
+
context->allocator
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static AST_NODE_T* build_rescue_node(control_builder_context_T* context) {
|
|
218
|
+
AST_ERB_RESCUE_NODE_T* rescue_node = NULL;
|
|
219
|
+
|
|
220
|
+
if (context->subsequent && context->subsequent->type == AST_ERB_RESCUE_NODE) {
|
|
221
|
+
rescue_node = (AST_ERB_RESCUE_NODE_T*) context->subsequent;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return (AST_NODE_T*) ast_erb_rescue_node_init(
|
|
225
|
+
context->tag_opening,
|
|
226
|
+
context->content,
|
|
227
|
+
context->tag_closing,
|
|
228
|
+
context->children,
|
|
229
|
+
rescue_node,
|
|
230
|
+
context->start_position,
|
|
231
|
+
context->end_position,
|
|
232
|
+
context->errors,
|
|
233
|
+
context->allocator
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
static AST_NODE_T* build_ensure_node(control_builder_context_T* context) {
|
|
238
|
+
return (AST_NODE_T*) ast_erb_ensure_node_init(
|
|
239
|
+
context->tag_opening,
|
|
240
|
+
context->content,
|
|
241
|
+
context->tag_closing,
|
|
242
|
+
context->children,
|
|
243
|
+
context->start_position,
|
|
244
|
+
context->end_position,
|
|
245
|
+
context->errors,
|
|
246
|
+
context->allocator
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
static AST_NODE_T* build_unless_node(control_builder_context_T* context) {
|
|
251
|
+
AST_ERB_ELSE_NODE_T* else_clause = NULL;
|
|
252
|
+
|
|
253
|
+
if (context->subsequent && context->subsequent->type == AST_ERB_ELSE_NODE) {
|
|
254
|
+
else_clause = (AST_ERB_ELSE_NODE_T*) context->subsequent;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return (AST_NODE_T*) ast_erb_unless_node_init(
|
|
258
|
+
context->tag_opening,
|
|
259
|
+
context->content,
|
|
260
|
+
context->tag_closing,
|
|
261
|
+
context->then_keyword,
|
|
262
|
+
HERB_PRISM_NODE_EMPTY,
|
|
263
|
+
context->children,
|
|
264
|
+
else_clause,
|
|
265
|
+
context->end_node,
|
|
266
|
+
context->start_position,
|
|
267
|
+
context->end_position,
|
|
268
|
+
context->errors,
|
|
269
|
+
context->allocator
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
static AST_NODE_T* build_while_node(control_builder_context_T* context) {
|
|
274
|
+
return (AST_NODE_T*) ast_erb_while_node_init(
|
|
275
|
+
context->tag_opening,
|
|
276
|
+
context->content,
|
|
277
|
+
context->tag_closing,
|
|
278
|
+
HERB_PRISM_NODE_EMPTY,
|
|
279
|
+
context->children,
|
|
280
|
+
context->end_node,
|
|
281
|
+
context->start_position,
|
|
282
|
+
context->end_position,
|
|
283
|
+
context->errors,
|
|
284
|
+
context->allocator
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
static AST_NODE_T* build_until_node(control_builder_context_T* context) {
|
|
289
|
+
return (AST_NODE_T*) ast_erb_until_node_init(
|
|
290
|
+
context->tag_opening,
|
|
291
|
+
context->content,
|
|
292
|
+
context->tag_closing,
|
|
293
|
+
HERB_PRISM_NODE_EMPTY,
|
|
294
|
+
context->children,
|
|
295
|
+
context->end_node,
|
|
296
|
+
context->start_position,
|
|
297
|
+
context->end_position,
|
|
298
|
+
context->errors,
|
|
299
|
+
context->allocator
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
static AST_NODE_T* build_for_node(control_builder_context_T* context) {
|
|
304
|
+
return (AST_NODE_T*) ast_erb_for_node_init(
|
|
305
|
+
context->tag_opening,
|
|
306
|
+
context->content,
|
|
307
|
+
context->tag_closing,
|
|
308
|
+
HERB_PRISM_NODE_EMPTY,
|
|
309
|
+
context->children,
|
|
310
|
+
context->end_node,
|
|
311
|
+
context->start_position,
|
|
312
|
+
context->end_position,
|
|
313
|
+
context->errors,
|
|
314
|
+
context->allocator
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
static AST_NODE_T* build_block_node(control_builder_context_T* context) {
|
|
319
|
+
return (AST_NODE_T*) ast_erb_block_node_init(
|
|
320
|
+
context->tag_opening,
|
|
321
|
+
context->content,
|
|
322
|
+
context->tag_closing,
|
|
323
|
+
HERB_PRISM_NODE_EMPTY,
|
|
324
|
+
context->children,
|
|
325
|
+
context->end_node,
|
|
326
|
+
context->start_position,
|
|
327
|
+
context->end_position,
|
|
328
|
+
context->errors,
|
|
329
|
+
context->allocator
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
static AST_NODE_T* build_yield_node(control_builder_context_T* context) {
|
|
334
|
+
return (AST_NODE_T*) ast_erb_yield_node_init(
|
|
335
|
+
context->tag_opening,
|
|
336
|
+
context->content,
|
|
337
|
+
context->tag_closing,
|
|
338
|
+
context->start_position,
|
|
339
|
+
context->end_position,
|
|
340
|
+
context->errors,
|
|
341
|
+
context->allocator
|
|
342
|
+
);
|
|
343
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#ifndef HERB_ANALYZE_BUILDERS_H
|
|
2
|
+
#define HERB_ANALYZE_BUILDERS_H
|
|
3
|
+
|
|
4
|
+
#include "../ast_nodes.h"
|
|
5
|
+
#include "../location.h"
|
|
6
|
+
#include "../position.h"
|
|
7
|
+
#include "../util/hb_allocator.h"
|
|
8
|
+
#include "analyze.h"
|
|
9
|
+
|
|
10
|
+
position_T erb_content_end_position(const AST_ERB_CONTENT_NODE_T* erb_node);
|
|
11
|
+
|
|
12
|
+
location_T* compute_then_keyword(
|
|
13
|
+
AST_ERB_CONTENT_NODE_T* erb_node,
|
|
14
|
+
control_type_t control_type,
|
|
15
|
+
hb_allocator_T* allocator
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
AST_NODE_T* create_control_node(
|
|
19
|
+
AST_ERB_CONTENT_NODE_T* erb_node,
|
|
20
|
+
hb_array_T* children,
|
|
21
|
+
AST_NODE_T* subsequent,
|
|
22
|
+
AST_ERB_END_NODE_T* end_node,
|
|
23
|
+
control_type_t control_type,
|
|
24
|
+
hb_allocator_T* allocator
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
#endif
|