herb 0.8.10-arm-linux-gnu → 0.9.1-arm-linux-gnu
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/Makefile +11 -3
- data/README.md +64 -34
- data/Rakefile +48 -40
- data/config.yml +473 -34
- data/ext/herb/error_helpers.c +535 -140
- data/ext/herb/error_helpers.h +1 -0
- data/ext/herb/extconf.rb +67 -28
- data/ext/herb/extension.c +321 -51
- data/ext/herb/extension.h +1 -0
- data/ext/herb/extension_helpers.c +24 -14
- data/ext/herb/extension_helpers.h +2 -2
- data/ext/herb/nodes.c +647 -270
- data/ext/herb/nodes.h +1 -0
- data/herb.gemspec +3 -2
- data/lib/herb/3.0/herb.so +0 -0
- data/lib/herb/3.1/herb.so +0 -0
- data/lib/herb/3.2/herb.so +0 -0
- data/lib/herb/3.3/herb.so +0 -0
- data/lib/herb/3.4/herb.so +0 -0
- data/lib/herb/4.0/herb.so +0 -0
- data/lib/herb/ast/helpers.rb +3 -3
- data/lib/herb/ast/node.rb +15 -2
- data/lib/herb/ast/nodes.rb +1530 -179
- data/lib/herb/bootstrap.rb +87 -0
- data/lib/herb/cli.rb +341 -31
- data/lib/herb/configuration.rb +248 -0
- data/lib/herb/defaults.yml +32 -0
- data/lib/herb/engine/compiler.rb +78 -11
- data/lib/herb/engine/debug_visitor.rb +13 -3
- data/lib/herb/engine/error_formatter.rb +13 -9
- data/lib/herb/engine/parser_error_overlay.rb +10 -6
- data/lib/herb/engine/validator.rb +8 -3
- data/lib/herb/engine/validators/nesting_validator.rb +2 -2
- data/lib/herb/engine.rb +119 -43
- data/lib/herb/errors.rb +808 -88
- data/lib/herb/lex_result.rb +1 -0
- data/lib/herb/location.rb +7 -3
- data/lib/herb/parse_result.rb +12 -2
- data/lib/herb/parser_options.rb +62 -0
- data/lib/herb/position.rb +1 -0
- data/lib/herb/prism_inspect.rb +120 -0
- data/lib/herb/project.rb +923 -331
- data/lib/herb/range.rb +1 -0
- data/lib/herb/token.rb +7 -1
- data/lib/herb/version.rb +1 -1
- data/lib/herb/visitor.rb +47 -2
- data/lib/herb/warnings.rb +6 -1
- data/lib/herb.rb +35 -3
- data/sig/herb/ast/helpers.rbs +2 -2
- data/sig/herb/ast/node.rbs +12 -2
- data/sig/herb/ast/nodes.rbs +773 -128
- data/sig/herb/bootstrap.rbs +31 -0
- data/sig/herb/configuration.rbs +89 -0
- data/sig/herb/engine/compiler.rbs +9 -1
- data/sig/herb/engine/debug_visitor.rbs +2 -0
- data/sig/herb/engine/validator.rbs +5 -1
- data/sig/herb/engine.rbs +21 -3
- data/sig/herb/errors.rbs +372 -63
- data/sig/herb/location.rbs +4 -0
- data/sig/herb/parse_result.rbs +4 -2
- data/sig/herb/parser_options.rbs +46 -0
- data/sig/herb/position.rbs +1 -0
- data/sig/herb/prism_inspect.rbs +28 -0
- data/sig/herb/range.rbs +1 -0
- data/sig/herb/token.rbs +6 -0
- data/sig/herb/visitor.rbs +31 -4
- data/sig/herb/warnings.rbs +6 -1
- data/sig/herb.rbs +14 -0
- data/sig/herb_c_extension.rbs +5 -2
- data/sig/rubyvm.rbs +5 -0
- data/sig/serialized_ast_errors.rbs +82 -6
- data/sig/serialized_ast_nodes.rbs +91 -6
- data/src/analyze/action_view/attribute_extraction_helpers.c +303 -0
- data/src/analyze/action_view/content_tag.c +78 -0
- data/src/analyze/action_view/link_to.c +167 -0
- data/src/analyze/action_view/registry.c +83 -0
- data/src/analyze/action_view/tag.c +70 -0
- data/src/analyze/action_view/tag_helper_node_builders.c +305 -0
- data/src/analyze/action_view/tag_helpers.c +815 -0
- data/src/analyze/action_view/turbo_frame_tag.c +88 -0
- data/src/analyze/analyze.c +885 -0
- data/src/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
- data/src/analyze/builders.c +343 -0
- data/src/analyze/conditional_elements.c +594 -0
- data/src/analyze/conditional_open_tags.c +640 -0
- data/src/analyze/control_type.c +250 -0
- data/src/{analyze_helpers.c → analyze/helpers.c} +48 -23
- data/src/analyze/invalid_structures.c +193 -0
- data/src/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
- data/src/analyze/parse_errors.c +84 -0
- data/src/analyze/prism_annotate.c +399 -0
- data/src/analyze/render_nodes.c +761 -0
- data/src/{analyze_transform.c → analyze/transform.c} +24 -3
- data/src/ast_node.c +17 -7
- data/src/ast_nodes.c +759 -387
- data/src/ast_pretty_print.c +264 -6
- data/src/errors.c +1454 -519
- data/src/extract.c +145 -49
- data/src/herb.c +52 -34
- data/src/html_util.c +241 -12
- data/src/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
- data/src/include/analyze/action_view/tag_helper_handler.h +43 -0
- data/src/include/analyze/action_view/tag_helper_node_builders.h +70 -0
- data/src/include/analyze/action_view/tag_helpers.h +38 -0
- data/src/include/{analyze.h → analyze/analyze.h} +14 -4
- data/src/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- data/src/include/analyze/builders.h +27 -0
- data/src/include/analyze/conditional_elements.h +9 -0
- data/src/include/analyze/conditional_open_tags.h +9 -0
- data/src/include/analyze/control_type.h +14 -0
- data/src/include/{analyze_helpers.h → analyze/helpers.h} +4 -2
- data/src/include/analyze/invalid_structures.h +11 -0
- data/src/include/analyze/prism_annotate.h +16 -0
- data/src/include/analyze/render_nodes.h +11 -0
- data/src/include/ast_node.h +11 -5
- data/src/include/ast_nodes.h +154 -38
- data/src/include/ast_pretty_print.h +5 -0
- data/src/include/element_source.h +3 -8
- data/src/include/errors.h +206 -55
- data/src/include/extract.h +21 -5
- data/src/include/herb.h +18 -6
- data/src/include/herb_prism_node.h +13 -0
- data/src/include/html_util.h +7 -2
- data/src/include/io.h +3 -1
- data/src/include/lex_helpers.h +29 -0
- data/src/include/lexer.h +1 -1
- data/src/include/lexer_peek_helpers.h +87 -13
- data/src/include/lexer_struct.h +2 -0
- data/src/include/location.h +2 -1
- data/src/include/parser.h +28 -2
- data/src/include/parser_helpers.h +19 -3
- data/src/include/pretty_print.h +10 -5
- data/src/include/prism_context.h +45 -0
- data/src/include/prism_helpers.h +10 -7
- data/src/include/prism_serialized.h +12 -0
- data/src/include/token.h +16 -4
- data/src/include/token_struct.h +10 -3
- data/src/include/utf8.h +2 -1
- data/src/include/util/hb_allocator.h +78 -0
- data/src/include/util/hb_arena.h +6 -1
- data/src/include/util/hb_arena_debug.h +12 -1
- data/src/include/util/hb_array.h +7 -3
- data/src/include/util/hb_buffer.h +6 -4
- data/src/include/util/hb_foreach.h +79 -0
- data/src/include/util/hb_narray.h +8 -4
- data/src/include/util/hb_string.h +56 -9
- data/src/include/util.h +6 -3
- data/src/include/version.h +1 -1
- data/src/io.c +3 -2
- data/src/lexer.c +42 -30
- data/src/lexer_peek_helpers.c +12 -74
- data/src/location.c +2 -2
- data/src/main.c +53 -28
- data/src/parser.c +784 -247
- data/src/parser_helpers.c +110 -23
- data/src/parser_match_tags.c +129 -48
- data/src/pretty_print.c +29 -24
- data/src/prism_helpers.c +30 -27
- data/src/ruby_parser.c +2 -0
- data/src/token.c +151 -66
- data/src/token_matchers.c +0 -1
- data/src/utf8.c +7 -6
- data/src/util/hb_allocator.c +341 -0
- data/src/util/hb_arena.c +81 -56
- data/src/util/hb_arena_debug.c +32 -17
- data/src/util/hb_array.c +30 -15
- data/src/util/hb_buffer.c +17 -21
- data/src/util/hb_narray.c +22 -7
- data/src/util/hb_string.c +49 -35
- data/src/util.c +21 -11
- data/src/visitor.c +67 -0
- data/templates/ext/herb/error_helpers.c.erb +24 -11
- data/templates/ext/herb/error_helpers.h.erb +1 -0
- data/templates/ext/herb/nodes.c.erb +50 -16
- data/templates/ext/herb/nodes.h.erb +1 -0
- data/templates/java/error_helpers.c.erb +1 -1
- data/templates/java/nodes.c.erb +30 -8
- data/templates/java/org/herb/ast/Errors.java.erb +24 -1
- data/templates/java/org/herb/ast/Nodes.java.erb +80 -21
- data/templates/javascript/packages/core/src/errors.ts.erb +16 -3
- data/templates/javascript/packages/core/src/node-type-guards.ts.erb +3 -1
- data/templates/javascript/packages/core/src/nodes.ts.erb +109 -32
- data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +13 -4
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +43 -4
- data/templates/lib/herb/ast/nodes.rb.erb +95 -32
- data/templates/lib/herb/errors.rb.erb +15 -3
- data/templates/lib/herb/visitor.rb.erb +2 -2
- data/templates/rust/src/ast/nodes.rs.erb +97 -44
- data/templates/rust/src/errors.rs.erb +2 -1
- data/templates/rust/src/nodes.rs.erb +168 -16
- data/templates/rust/src/union_types.rs.erb +60 -0
- data/templates/rust/src/visitor.rs.erb +81 -0
- data/templates/src/{analyze_missing_end.c.erb → analyze/missing_end.c.erb} +9 -6
- data/templates/src/{analyze_transform.c.erb → analyze/transform.c.erb} +2 -2
- data/templates/src/ast_nodes.c.erb +34 -26
- data/templates/src/ast_pretty_print.c.erb +24 -5
- data/templates/src/errors.c.erb +60 -54
- data/templates/src/include/ast_nodes.h.erb +6 -2
- data/templates/src/include/ast_pretty_print.h.erb +5 -0
- data/templates/src/include/errors.h.erb +15 -11
- data/templates/src/include/util/hb_foreach.h.erb +20 -0
- data/templates/src/parser_match_tags.c.erb +10 -4
- data/templates/src/visitor.c.erb +2 -2
- data/templates/template.rb +204 -29
- data/templates/wasm/error_helpers.cpp.erb +9 -5
- data/templates/wasm/nodes.cpp.erb +41 -4
- metadata +60 -16
- data/src/analyze.c +0 -1608
- data/src/element_source.c +0 -12
- data/src/include/util/hb_system.h +0 -9
- data/src/util/hb_system.c +0 -30
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#include "../../include/analyze/action_view/tag_helper_handler.h"
|
|
2
|
+
|
|
3
|
+
#include <prism.h>
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
|
|
8
|
+
bool detect_tag_dot(pm_call_node_t* call_node, pm_parser_t* parser) {
|
|
9
|
+
if (!call_node || !call_node->receiver) { return false; }
|
|
10
|
+
if (call_node->receiver->type != PM_CALL_NODE) { return false; }
|
|
11
|
+
|
|
12
|
+
pm_call_node_t* receiver_node = (pm_call_node_t*) call_node->receiver;
|
|
13
|
+
if (!receiver_node->name) { return false; }
|
|
14
|
+
|
|
15
|
+
pm_constant_t* constant = pm_constant_pool_id_to_constant(&parser->constant_pool, receiver_node->name);
|
|
16
|
+
|
|
17
|
+
return constant && constant->length == 3 && strncmp((const char*) constant->start, "tag", 3) == 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
char* extract_tag_dot_name(pm_call_node_t* call_node, pm_parser_t* parser, hb_allocator_T* allocator) {
|
|
21
|
+
if (!call_node || !call_node->name) { return NULL; }
|
|
22
|
+
|
|
23
|
+
pm_constant_t* constant = pm_constant_pool_id_to_constant(&parser->constant_pool, call_node->name);
|
|
24
|
+
if (!constant) { return NULL; }
|
|
25
|
+
|
|
26
|
+
char* name = hb_allocator_strndup(allocator, (const char*) constant->start, constant->length);
|
|
27
|
+
|
|
28
|
+
for (size_t i = 0; i < constant->length && name[i] != '\0'; i++) {
|
|
29
|
+
if (name[i] == '_') { name[i] = '-'; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return name;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// TODO: this should probably be an array of nodes
|
|
36
|
+
char* extract_tag_dot_content(pm_call_node_t* call_node, pm_parser_t* parser, hb_allocator_T* allocator) {
|
|
37
|
+
(void) parser;
|
|
38
|
+
|
|
39
|
+
if (!call_node) { return NULL; }
|
|
40
|
+
|
|
41
|
+
char* block_content = extract_inline_block_content(call_node, allocator);
|
|
42
|
+
if (block_content) { return block_content; }
|
|
43
|
+
|
|
44
|
+
if (call_node->arguments) {
|
|
45
|
+
pm_arguments_node_t* arguments = call_node->arguments;
|
|
46
|
+
|
|
47
|
+
if (arguments->arguments.size) {
|
|
48
|
+
pm_node_t* first_argument = arguments->arguments.nodes[0];
|
|
49
|
+
|
|
50
|
+
if (first_argument->type == PM_STRING_NODE) {
|
|
51
|
+
pm_string_node_t* string_node = (pm_string_node_t*) first_argument;
|
|
52
|
+
size_t length = pm_string_length(&string_node->unescaped);
|
|
53
|
+
return hb_allocator_strndup(allocator, (const char*) pm_string_source(&string_node->unescaped), length);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return NULL;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
bool tag_dot_supports_block(void) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const tag_helper_handler_T tag_dot_handler = { .name = "tag",
|
|
66
|
+
.source = HB_STRING_LITERAL("ActionView::Helpers::TagHelper#tag"),
|
|
67
|
+
.detect = detect_tag_dot,
|
|
68
|
+
.extract_tag_name = extract_tag_dot_name,
|
|
69
|
+
.extract_content = extract_tag_dot_content,
|
|
70
|
+
.supports_block = tag_dot_supports_block };
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#include "../../include/analyze/action_view/tag_helper_node_builders.h"
|
|
2
|
+
#include "../../include/ast_nodes.h"
|
|
3
|
+
#include "../../include/location.h"
|
|
4
|
+
#include "../../include/position.h"
|
|
5
|
+
#include "../../include/range.h"
|
|
6
|
+
#include "../../include/token_struct.h"
|
|
7
|
+
#include "../../include/util/hb_allocator.h"
|
|
8
|
+
#include "../../include/util/hb_array.h"
|
|
9
|
+
#include "../../include/util/hb_string.h"
|
|
10
|
+
|
|
11
|
+
#include <prism.h>
|
|
12
|
+
#include <stdbool.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <string.h>
|
|
15
|
+
|
|
16
|
+
token_T* create_synthetic_token(
|
|
17
|
+
hb_allocator_T* allocator,
|
|
18
|
+
const char* value,
|
|
19
|
+
token_type_T type,
|
|
20
|
+
position_T start,
|
|
21
|
+
position_T end
|
|
22
|
+
) {
|
|
23
|
+
token_T* token = hb_allocator_alloc(allocator, sizeof(token_T));
|
|
24
|
+
if (!token) { return NULL; }
|
|
25
|
+
|
|
26
|
+
if (value) {
|
|
27
|
+
size_t length = strlen(value);
|
|
28
|
+
char* copied = hb_allocator_strndup(allocator, value, length);
|
|
29
|
+
token->value = (hb_string_T) { .data = copied, .length = (uint32_t) length };
|
|
30
|
+
} else {
|
|
31
|
+
token->value = HB_STRING_EMPTY;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
token->type = type;
|
|
35
|
+
location_from_positions(&token->location, start, end);
|
|
36
|
+
token->range = (range_T) { .from = 0, .to = 0 };
|
|
37
|
+
|
|
38
|
+
return token;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
AST_HTML_ATTRIBUTE_NAME_NODE_T* create_attribute_name_node(
|
|
42
|
+
const char* name_string,
|
|
43
|
+
position_T start_position,
|
|
44
|
+
position_T end_position,
|
|
45
|
+
hb_allocator_T* allocator
|
|
46
|
+
) {
|
|
47
|
+
AST_LITERAL_NODE_T* name_literal = ast_literal_node_init(
|
|
48
|
+
hb_string_from_c_string(name_string),
|
|
49
|
+
start_position,
|
|
50
|
+
end_position,
|
|
51
|
+
hb_array_init(0, allocator),
|
|
52
|
+
allocator
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
hb_array_T* name_children = hb_array_init(1, allocator);
|
|
56
|
+
hb_array_append(name_children, (AST_NODE_T*) name_literal);
|
|
57
|
+
|
|
58
|
+
return ast_html_attribute_name_node_init(
|
|
59
|
+
name_children,
|
|
60
|
+
start_position,
|
|
61
|
+
end_position,
|
|
62
|
+
hb_array_init(0, allocator),
|
|
63
|
+
allocator
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
hb_array_T* prepend_attribute(hb_array_T* attributes, AST_NODE_T* attribute, hb_allocator_T* allocator) {
|
|
68
|
+
hb_array_T* new_attributes = hb_array_init(hb_array_size(attributes) + 1, allocator);
|
|
69
|
+
hb_array_append(new_attributes, attribute);
|
|
70
|
+
|
|
71
|
+
for (size_t i = 0; i < hb_array_size(attributes); i++) {
|
|
72
|
+
hb_array_append(new_attributes, hb_array_get(attributes, i));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
hb_array_free(&attributes);
|
|
76
|
+
return new_attributes;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
AST_HTML_ATTRIBUTE_NODE_T* create_html_attribute_node(
|
|
80
|
+
const char* name_string,
|
|
81
|
+
const char* value_string,
|
|
82
|
+
position_T start_position,
|
|
83
|
+
position_T end_position,
|
|
84
|
+
hb_allocator_T* allocator
|
|
85
|
+
) {
|
|
86
|
+
if (!name_string) { return NULL; }
|
|
87
|
+
|
|
88
|
+
AST_HTML_ATTRIBUTE_NAME_NODE_T* name_node =
|
|
89
|
+
create_attribute_name_node(name_string, start_position, end_position, allocator);
|
|
90
|
+
|
|
91
|
+
token_T* equals_token = create_synthetic_token(allocator, "=", TOKEN_EQUALS, start_position, end_position);
|
|
92
|
+
AST_HTML_ATTRIBUTE_VALUE_NODE_T* value_node = NULL;
|
|
93
|
+
|
|
94
|
+
if (value_string) {
|
|
95
|
+
token_T* open_quote = create_synthetic_token(allocator, "\"", TOKEN_QUOTE, start_position, end_position);
|
|
96
|
+
token_T* close_quote = create_synthetic_token(allocator, "\"", TOKEN_QUOTE, end_position, end_position);
|
|
97
|
+
|
|
98
|
+
AST_LITERAL_NODE_T* value_literal = ast_literal_node_init(
|
|
99
|
+
hb_string_from_c_string(value_string),
|
|
100
|
+
start_position,
|
|
101
|
+
end_position,
|
|
102
|
+
hb_array_init(0, allocator),
|
|
103
|
+
allocator
|
|
104
|
+
);
|
|
105
|
+
hb_array_T* value_children = hb_array_init(1, allocator);
|
|
106
|
+
hb_array_append(value_children, (AST_NODE_T*) value_literal);
|
|
107
|
+
|
|
108
|
+
value_node = ast_html_attribute_value_node_init(
|
|
109
|
+
open_quote,
|
|
110
|
+
value_children,
|
|
111
|
+
close_quote,
|
|
112
|
+
true,
|
|
113
|
+
start_position,
|
|
114
|
+
end_position,
|
|
115
|
+
hb_array_init(0, allocator),
|
|
116
|
+
allocator
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return ast_html_attribute_node_init(
|
|
121
|
+
name_node,
|
|
122
|
+
equals_token,
|
|
123
|
+
value_node,
|
|
124
|
+
start_position,
|
|
125
|
+
end_position,
|
|
126
|
+
hb_array_init(0, allocator),
|
|
127
|
+
allocator
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
AST_HTML_ATTRIBUTE_NODE_T* create_html_attribute_with_ruby_literal(
|
|
132
|
+
const char* name_string,
|
|
133
|
+
const char* ruby_content,
|
|
134
|
+
position_T start_position,
|
|
135
|
+
position_T end_position,
|
|
136
|
+
hb_allocator_T* allocator
|
|
137
|
+
) {
|
|
138
|
+
if (!name_string || !ruby_content) { return NULL; }
|
|
139
|
+
|
|
140
|
+
AST_HTML_ATTRIBUTE_NAME_NODE_T* name_node =
|
|
141
|
+
create_attribute_name_node(name_string, start_position, end_position, allocator);
|
|
142
|
+
|
|
143
|
+
token_T* equals_token = create_synthetic_token(allocator, ":", TOKEN_COLON, start_position, end_position);
|
|
144
|
+
|
|
145
|
+
AST_RUBY_LITERAL_NODE_T* ruby_node = ast_ruby_literal_node_init(
|
|
146
|
+
hb_string_from_c_string(ruby_content),
|
|
147
|
+
start_position,
|
|
148
|
+
end_position,
|
|
149
|
+
hb_array_init(0, allocator),
|
|
150
|
+
allocator
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
hb_array_T* value_children = hb_array_init(1, allocator);
|
|
154
|
+
hb_array_append(value_children, (AST_NODE_T*) ruby_node);
|
|
155
|
+
|
|
156
|
+
AST_HTML_ATTRIBUTE_VALUE_NODE_T* value_node = ast_html_attribute_value_node_init(
|
|
157
|
+
NULL,
|
|
158
|
+
value_children,
|
|
159
|
+
NULL,
|
|
160
|
+
false,
|
|
161
|
+
start_position,
|
|
162
|
+
end_position,
|
|
163
|
+
hb_array_init(0, allocator),
|
|
164
|
+
allocator
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
return ast_html_attribute_node_init(
|
|
168
|
+
name_node,
|
|
169
|
+
equals_token,
|
|
170
|
+
value_node,
|
|
171
|
+
start_position,
|
|
172
|
+
end_position,
|
|
173
|
+
hb_array_init(0, allocator),
|
|
174
|
+
allocator
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static AST_HTML_ATTRIBUTE_VALUE_NODE_T* create_interpolated_attribute_value(
|
|
179
|
+
pm_interpolated_string_node_t* interpolated_node,
|
|
180
|
+
position_T start_position,
|
|
181
|
+
position_T end_position,
|
|
182
|
+
hb_allocator_T* allocator
|
|
183
|
+
) {
|
|
184
|
+
if (!interpolated_node) { return NULL; }
|
|
185
|
+
|
|
186
|
+
hb_array_T* value_children = hb_array_init(8, allocator);
|
|
187
|
+
|
|
188
|
+
for (size_t i = 0; i < interpolated_node->parts.size; i++) {
|
|
189
|
+
pm_node_t* part = interpolated_node->parts.nodes[i];
|
|
190
|
+
|
|
191
|
+
if (part->type == PM_STRING_NODE) {
|
|
192
|
+
pm_string_node_t* string_part = (pm_string_node_t*) part;
|
|
193
|
+
size_t content_length = pm_string_length(&string_part->unescaped);
|
|
194
|
+
|
|
195
|
+
if (content_length > 0) {
|
|
196
|
+
char* content =
|
|
197
|
+
hb_allocator_strndup(allocator, (const char*) pm_string_source(&string_part->unescaped), content_length);
|
|
198
|
+
if (content) {
|
|
199
|
+
AST_LITERAL_NODE_T* literal_node = ast_literal_node_init(
|
|
200
|
+
hb_string_from_c_string(content),
|
|
201
|
+
start_position,
|
|
202
|
+
end_position,
|
|
203
|
+
hb_array_init(0, allocator),
|
|
204
|
+
allocator
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
if (literal_node) { hb_array_append(value_children, (AST_NODE_T*) literal_node); }
|
|
208
|
+
|
|
209
|
+
hb_allocator_dealloc(allocator, content);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
} else if (part->type == PM_EMBEDDED_STATEMENTS_NODE) {
|
|
213
|
+
size_t ruby_length = part->location.end - part->location.start;
|
|
214
|
+
char* ruby_content = hb_allocator_strndup(allocator, (const char*) part->location.start, ruby_length);
|
|
215
|
+
|
|
216
|
+
if (ruby_content) {
|
|
217
|
+
AST_RUBY_LITERAL_NODE_T* ruby_node = ast_ruby_literal_node_init(
|
|
218
|
+
hb_string_from_c_string(ruby_content),
|
|
219
|
+
start_position,
|
|
220
|
+
end_position,
|
|
221
|
+
hb_array_init(0, allocator),
|
|
222
|
+
allocator
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
if (ruby_node) { hb_array_append(value_children, (AST_NODE_T*) ruby_node); }
|
|
226
|
+
|
|
227
|
+
hb_allocator_dealloc(allocator, ruby_content);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return ast_html_attribute_value_node_init(
|
|
233
|
+
NULL,
|
|
234
|
+
value_children,
|
|
235
|
+
NULL,
|
|
236
|
+
false,
|
|
237
|
+
start_position,
|
|
238
|
+
end_position,
|
|
239
|
+
hb_array_init(0, allocator),
|
|
240
|
+
allocator
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
AST_HTML_ATTRIBUTE_NODE_T* create_html_attribute_with_interpolated_value(
|
|
245
|
+
const char* name_string,
|
|
246
|
+
pm_interpolated_string_node_t* interpolated_node,
|
|
247
|
+
position_T start_position,
|
|
248
|
+
position_T end_position,
|
|
249
|
+
hb_allocator_T* allocator
|
|
250
|
+
) {
|
|
251
|
+
if (!name_string || !interpolated_node) { return NULL; }
|
|
252
|
+
|
|
253
|
+
AST_HTML_ATTRIBUTE_NAME_NODE_T* name_node =
|
|
254
|
+
create_attribute_name_node(name_string, start_position, end_position, allocator);
|
|
255
|
+
|
|
256
|
+
AST_HTML_ATTRIBUTE_VALUE_NODE_T* value_node =
|
|
257
|
+
create_interpolated_attribute_value(interpolated_node, start_position, end_position, allocator);
|
|
258
|
+
|
|
259
|
+
token_T* equals_token = create_synthetic_token(allocator, "=", TOKEN_EQUALS, start_position, end_position);
|
|
260
|
+
|
|
261
|
+
return ast_html_attribute_node_init(
|
|
262
|
+
name_node,
|
|
263
|
+
equals_token,
|
|
264
|
+
value_node,
|
|
265
|
+
start_position,
|
|
266
|
+
end_position,
|
|
267
|
+
hb_array_init(0, allocator),
|
|
268
|
+
allocator
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
AST_HTML_ATTRIBUTE_NODE_T* create_href_attribute(
|
|
273
|
+
const char* href,
|
|
274
|
+
bool is_ruby_expression,
|
|
275
|
+
position_T start_position,
|
|
276
|
+
position_T end_position,
|
|
277
|
+
hb_allocator_T* allocator
|
|
278
|
+
) {
|
|
279
|
+
return is_ruby_expression
|
|
280
|
+
? create_html_attribute_with_ruby_literal("href", href, start_position, end_position, allocator)
|
|
281
|
+
: create_html_attribute_node("href", href, start_position, end_position, allocator);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
void append_body_content_node(
|
|
285
|
+
hb_array_T* body,
|
|
286
|
+
const char* content,
|
|
287
|
+
bool is_ruby_expression,
|
|
288
|
+
position_T start,
|
|
289
|
+
position_T end,
|
|
290
|
+
hb_allocator_T* allocator
|
|
291
|
+
) {
|
|
292
|
+
if (!content || !body) { return; }
|
|
293
|
+
|
|
294
|
+
if (is_ruby_expression) {
|
|
295
|
+
AST_RUBY_LITERAL_NODE_T* ruby_node =
|
|
296
|
+
ast_ruby_literal_node_init(hb_string_from_c_string(content), start, end, hb_array_init(0, allocator), allocator);
|
|
297
|
+
|
|
298
|
+
if (ruby_node) { hb_array_append(body, (AST_NODE_T*) ruby_node); }
|
|
299
|
+
} else {
|
|
300
|
+
AST_HTML_TEXT_NODE_T* text_node =
|
|
301
|
+
ast_html_text_node_init(hb_string_from_c_string(content), start, end, hb_array_init(0, allocator), allocator);
|
|
302
|
+
|
|
303
|
+
if (text_node) { hb_array_append(body, (AST_NODE_T*) text_node); }
|
|
304
|
+
}
|
|
305
|
+
}
|