herb 0.8.0-x86_64-linux-musl → 0.8.2-x86_64-linux-musl
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/README.md +6 -1
- data/ext/herb/nodes.c +1 -1
- 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/version.rb +1 -1
- data/src/analyze.c +142 -46
- data/src/analyze_helpers.c +12 -4
- data/src/include/util/hb_buffer.h +3 -1
- data/src/include/version.h +1 -1
- data/src/parser.c +5 -7
- data/src/util/hb_buffer.c +18 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9c555da17eab91d5c3683746b4b948ecf670f1fcd6930ca1dc230cc64ac12a6d
|
|
4
|
+
data.tar.gz: 69693530b00c403c51bb2f19dfab434cda2354a36abcab3729881d7d501839c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ece3bddb321a80c22bb599b7165e195f51084fb60d28a98255ebb35fc077c8228126b44a711619370de1fcbe80e1beaf558fce722d15bb616fa265c15fca039
|
|
7
|
+
data.tar.gz: 76d499b555f260e4dba23765c8ff01d588026264cdba4ab62b8f5b9745fc783d5539342101bc0c213dee84fc706f4e56cd403ba54f4e1775cfbff40d6980eb58
|
data/README.md
CHANGED
|
@@ -10,8 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
12
12
|
<a href="https://rubygems.org/gems/herb"><img alt="Gem Version" src="https://img.shields.io/gem/v/herb"></a>
|
|
13
|
+
<a href="https://crates.io/crates/herb"><img alt="Crates.io Version" src="https://img.shields.io/crates/v/herb"></a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@herb-tools/core"><img alt="npm Version" src="https://img.shields.io/npm/v/@herb-tools/core"></a>
|
|
15
|
+
<a href="https://marketplace.visualstudio.com/items?itemName=marcoroth.herb-lsp"><img alt="VS Code Marketplace" src="https://img.shields.io/visual-studio-marketplace/v/marcoroth.herb-lsp"></a>
|
|
16
|
+
<a href="https://open-vsx.org/extension/marcoroth/herb-lsp"><img alt="Open VSX" src="https://img.shields.io/open-vsx/v/marcoroth/herb-lsp"></a>
|
|
13
17
|
<a href="https://herb-tools.dev"><img alt="Documentation" src="https://img.shields.io/badge/documentation-available-green"></a>
|
|
14
18
|
<a href="https://herb-tools.dev/playground"><img alt="playground" src="https://img.shields.io/badge/playground-Try_it_in_the_browser!-green"></a>
|
|
19
|
+
<a href="https://pkg.pr.new/~/marcoroth/herb"><img alt="pkg.pr.new" src="https://pkg.pr.new/badge/marcoroth/herb"></a>
|
|
15
20
|
<a href="https://github.com/marcoroth/herb/blob/main/LICENSE.txt"><img alt="License" src="https://img.shields.io/github/license/marcoroth/herb"></a>
|
|
16
21
|
<a href="https://github.com/marcoroth/herb/issues"><img alt="Issues" src="https://img.shields.io/github/issues/marcoroth/herb"></a>
|
|
17
22
|
</p>
|
|
@@ -99,7 +104,7 @@ Commands:
|
|
|
99
104
|
bundle exec herb version Prints the versions of the Herb gem and the libherb library.
|
|
100
105
|
```
|
|
101
106
|
|
|
102
|
-
For detailed information, like how you can use Herb
|
|
107
|
+
For detailed information, like how you can use Herb programmatically in Ruby and JavaScript, visit the [documentation site](https://herb-tools.dev/bindings/ruby/reference).
|
|
103
108
|
|
|
104
109
|
|
|
105
110
|
## Background and Talk
|
data/ext/herb/nodes.c
CHANGED
|
@@ -464,7 +464,7 @@ static VALUE rb_erb_content_node_from_c_struct(AST_ERB_CONTENT_NODE_T* erb_conte
|
|
|
464
464
|
VALUE erb_content_node_tag_opening = rb_token_from_c_struct(erb_content_node->tag_opening);
|
|
465
465
|
VALUE erb_content_node_content = rb_token_from_c_struct(erb_content_node->content);
|
|
466
466
|
VALUE erb_content_node_tag_closing = rb_token_from_c_struct(erb_content_node->tag_closing);
|
|
467
|
-
/* #<Herb::Template::AnalyzedRubyField:
|
|
467
|
+
/* #<Herb::Template::AnalyzedRubyField:0x00007f1dda6b72c8 @name="analyzed_ruby", @options={kind: nil}> */
|
|
468
468
|
VALUE erb_content_node_analyzed_ruby = Qnil;
|
|
469
469
|
VALUE erb_content_node_parsed = (erb_content_node->parsed) ? Qtrue : Qfalse;
|
|
470
470
|
VALUE erb_content_node_valid = (erb_content_node->valid) ? Qtrue : Qfalse;
|
data/lib/herb/3.0/herb.so
CHANGED
|
Binary file
|
data/lib/herb/3.1/herb.so
CHANGED
|
Binary file
|
data/lib/herb/3.2/herb.so
CHANGED
|
Binary file
|
data/lib/herb/3.3/herb.so
CHANGED
|
Binary file
|
data/lib/herb/3.4/herb.so
CHANGED
|
Binary file
|
data/lib/herb/version.rb
CHANGED
data/src/analyze.c
CHANGED
|
@@ -90,6 +90,138 @@ static size_t process_subsequent_block(
|
|
|
90
90
|
control_type_t parent_type
|
|
91
91
|
);
|
|
92
92
|
|
|
93
|
+
typedef struct {
|
|
94
|
+
control_type_t type;
|
|
95
|
+
uint32_t offset;
|
|
96
|
+
bool found;
|
|
97
|
+
} earliest_control_keyword_t;
|
|
98
|
+
|
|
99
|
+
typedef struct {
|
|
100
|
+
earliest_control_keyword_t* result;
|
|
101
|
+
const uint8_t* source_start;
|
|
102
|
+
} location_walker_context_t;
|
|
103
|
+
|
|
104
|
+
static bool find_earliest_control_keyword_walker(const pm_node_t* node, void* data) {
|
|
105
|
+
if (!node) { return true; }
|
|
106
|
+
|
|
107
|
+
location_walker_context_t* context = (location_walker_context_t*) data;
|
|
108
|
+
earliest_control_keyword_t* result = context->result;
|
|
109
|
+
|
|
110
|
+
control_type_t current_type = CONTROL_TYPE_UNKNOWN;
|
|
111
|
+
uint32_t keyword_offset = UINT32_MAX;
|
|
112
|
+
|
|
113
|
+
switch (node->type) {
|
|
114
|
+
case PM_IF_NODE: {
|
|
115
|
+
pm_if_node_t* if_node = (pm_if_node_t*) node;
|
|
116
|
+
current_type = CONTROL_TYPE_IF;
|
|
117
|
+
keyword_offset = (uint32_t) (if_node->if_keyword_loc.start - context->source_start);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
case PM_UNLESS_NODE: {
|
|
122
|
+
pm_unless_node_t* unless_node = (pm_unless_node_t*) node;
|
|
123
|
+
current_type = CONTROL_TYPE_UNLESS;
|
|
124
|
+
keyword_offset = (uint32_t) (unless_node->keyword_loc.start - context->source_start);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
case PM_CASE_NODE: {
|
|
129
|
+
pm_case_node_t* case_node = (pm_case_node_t*) node;
|
|
130
|
+
current_type = CONTROL_TYPE_CASE;
|
|
131
|
+
keyword_offset = (uint32_t) (case_node->case_keyword_loc.start - context->source_start);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
case PM_CASE_MATCH_NODE: {
|
|
136
|
+
pm_case_match_node_t* case_match_node = (pm_case_match_node_t*) node;
|
|
137
|
+
current_type = CONTROL_TYPE_CASE_MATCH;
|
|
138
|
+
keyword_offset = (uint32_t) (case_match_node->case_keyword_loc.start - context->source_start);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
case PM_WHILE_NODE: {
|
|
143
|
+
pm_while_node_t* while_node = (pm_while_node_t*) node;
|
|
144
|
+
current_type = CONTROL_TYPE_WHILE;
|
|
145
|
+
keyword_offset = (uint32_t) (while_node->keyword_loc.start - context->source_start);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
case PM_UNTIL_NODE: {
|
|
150
|
+
pm_until_node_t* until_node = (pm_until_node_t*) node;
|
|
151
|
+
current_type = CONTROL_TYPE_UNTIL;
|
|
152
|
+
keyword_offset = (uint32_t) (until_node->keyword_loc.start - context->source_start);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
case PM_FOR_NODE: {
|
|
157
|
+
pm_for_node_t* for_node = (pm_for_node_t*) node;
|
|
158
|
+
current_type = CONTROL_TYPE_FOR;
|
|
159
|
+
keyword_offset = (uint32_t) (for_node->for_keyword_loc.start - context->source_start);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
case PM_BEGIN_NODE: {
|
|
164
|
+
pm_begin_node_t* begin_node = (pm_begin_node_t*) node;
|
|
165
|
+
current_type = CONTROL_TYPE_BEGIN;
|
|
166
|
+
|
|
167
|
+
if (begin_node->begin_keyword_loc.start != NULL) {
|
|
168
|
+
keyword_offset = (uint32_t) (begin_node->begin_keyword_loc.start - context->source_start);
|
|
169
|
+
} else {
|
|
170
|
+
keyword_offset = (uint32_t) (node->location.start - context->source_start);
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
case PM_YIELD_NODE: {
|
|
176
|
+
current_type = CONTROL_TYPE_YIELD;
|
|
177
|
+
keyword_offset = (uint32_t) (node->location.start - context->source_start);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
case PM_CALL_NODE: {
|
|
182
|
+
pm_call_node_t* call = (pm_call_node_t*) node;
|
|
183
|
+
|
|
184
|
+
if (call->block != NULL) {
|
|
185
|
+
current_type = CONTROL_TYPE_BLOCK;
|
|
186
|
+
keyword_offset = (uint32_t) (node->location.start - context->source_start);
|
|
187
|
+
}
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
case PM_NEXT_NODE:
|
|
192
|
+
case PM_BREAK_NODE:
|
|
193
|
+
case PM_RETURN_NODE: {
|
|
194
|
+
current_type = CONTROL_TYPE_UNKNOWN;
|
|
195
|
+
keyword_offset = (uint32_t) (node->location.start - context->source_start);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
default: break;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (keyword_offset != UINT32_MAX) {
|
|
203
|
+
if (!result->found || keyword_offset < result->offset) {
|
|
204
|
+
result->type = current_type;
|
|
205
|
+
result->offset = keyword_offset;
|
|
206
|
+
result->found = true;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
static control_type_t find_earliest_control_keyword(pm_node_t* root, const uint8_t* source_start) {
|
|
214
|
+
if (!root) { return CONTROL_TYPE_UNKNOWN; }
|
|
215
|
+
|
|
216
|
+
earliest_control_keyword_t result = { .type = CONTROL_TYPE_UNKNOWN, .offset = UINT32_MAX, .found = false };
|
|
217
|
+
|
|
218
|
+
location_walker_context_t context = { .result = &result, .source_start = source_start };
|
|
219
|
+
|
|
220
|
+
pm_visit_node(root, find_earliest_control_keyword_walker, &context);
|
|
221
|
+
|
|
222
|
+
return result.found ? result.type : CONTROL_TYPE_UNKNOWN;
|
|
223
|
+
}
|
|
224
|
+
|
|
93
225
|
static control_type_t detect_control_type(AST_ERB_CONTENT_NODE_T* erb_node) {
|
|
94
226
|
if (!erb_node || erb_node->base.type != AST_ERB_CONTENT_NODE) { return CONTROL_TYPE_UNKNOWN; }
|
|
95
227
|
|
|
@@ -99,26 +231,18 @@ static control_type_t detect_control_type(AST_ERB_CONTENT_NODE_T* erb_node) {
|
|
|
99
231
|
|
|
100
232
|
if (ruby->valid) { return CONTROL_TYPE_UNKNOWN; }
|
|
101
233
|
|
|
102
|
-
|
|
103
|
-
|
|
234
|
+
pm_node_t* root = ruby->root;
|
|
235
|
+
|
|
104
236
|
if (has_elsif_node(ruby)) { return CONTROL_TYPE_ELSIF; }
|
|
105
237
|
if (has_else_node(ruby)) { return CONTROL_TYPE_ELSE; }
|
|
106
238
|
if (has_end(ruby)) { return CONTROL_TYPE_END; }
|
|
107
|
-
if (has_case_node(ruby)) { return CONTROL_TYPE_CASE; }
|
|
108
|
-
if (has_case_match_node(ruby)) { return CONTROL_TYPE_CASE_MATCH; }
|
|
109
239
|
if (has_when_node(ruby)) { return CONTROL_TYPE_WHEN; }
|
|
110
240
|
if (has_in_node(ruby)) { return CONTROL_TYPE_IN; }
|
|
111
|
-
if (has_begin_node(ruby)) { return CONTROL_TYPE_BEGIN; }
|
|
112
241
|
if (has_rescue_node(ruby)) { return CONTROL_TYPE_RESCUE; }
|
|
113
242
|
if (has_ensure_node(ruby)) { return CONTROL_TYPE_ENSURE; }
|
|
114
|
-
if (has_unless_node(ruby)) { return CONTROL_TYPE_UNLESS; }
|
|
115
|
-
if (has_while_node(ruby)) { return CONTROL_TYPE_WHILE; }
|
|
116
|
-
if (has_until_node(ruby)) { return CONTROL_TYPE_UNTIL; }
|
|
117
|
-
if (has_for_node(ruby)) { return CONTROL_TYPE_FOR; }
|
|
118
243
|
if (has_block_closing(ruby)) { return CONTROL_TYPE_BLOCK_CLOSE; }
|
|
119
|
-
if (has_yield_node(ruby)) { return CONTROL_TYPE_YIELD; }
|
|
120
244
|
|
|
121
|
-
return
|
|
245
|
+
return find_earliest_control_keyword(root, ruby->parser.start);
|
|
122
246
|
}
|
|
123
247
|
|
|
124
248
|
static bool is_subsequent_type(control_type_t parent_type, control_type_t child_type) {
|
|
@@ -164,7 +288,7 @@ static AST_NODE_T* create_control_node(
|
|
|
164
288
|
if (end_node) {
|
|
165
289
|
end_position = end_node->base.location.end;
|
|
166
290
|
} else if (children && hb_array_size(children) > 0) {
|
|
167
|
-
AST_NODE_T* last_child =
|
|
291
|
+
AST_NODE_T* last_child = hb_array_last(children);
|
|
168
292
|
end_position = last_child->location.end;
|
|
169
293
|
} else if (subsequent) {
|
|
170
294
|
end_position = subsequent->location.end;
|
|
@@ -515,21 +639,7 @@ static size_t process_control_structure(
|
|
|
515
639
|
|
|
516
640
|
index++;
|
|
517
641
|
|
|
518
|
-
|
|
519
|
-
AST_NODE_T* child = hb_array_get(array, index);
|
|
520
|
-
|
|
521
|
-
if (!child) { break; }
|
|
522
|
-
|
|
523
|
-
if (child->type == AST_ERB_CONTENT_NODE) {
|
|
524
|
-
AST_ERB_CONTENT_NODE_T* child_erb = (AST_ERB_CONTENT_NODE_T*) child;
|
|
525
|
-
control_type_t child_type = detect_control_type(child_erb);
|
|
526
|
-
|
|
527
|
-
if (child_type == CONTROL_TYPE_END) { break; }
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
hb_array_append(else_children, child);
|
|
531
|
-
index++;
|
|
532
|
-
}
|
|
642
|
+
index = process_block_children(node, array, index, else_children, context, initial_type);
|
|
533
643
|
|
|
534
644
|
hb_array_T* else_errors = next_erb->base.errors;
|
|
535
645
|
next_erb->base.errors = NULL;
|
|
@@ -585,10 +695,10 @@ static size_t process_control_structure(
|
|
|
585
695
|
} else if (else_clause) {
|
|
586
696
|
end_position = else_clause->base.location.end;
|
|
587
697
|
} else if (hb_array_size(when_conditions) > 0) {
|
|
588
|
-
AST_NODE_T* last_when =
|
|
698
|
+
AST_NODE_T* last_when = hb_array_last(when_conditions);
|
|
589
699
|
end_position = last_when->location.end;
|
|
590
700
|
} else if (hb_array_size(in_conditions) > 0) {
|
|
591
|
-
AST_NODE_T* last_in =
|
|
701
|
+
AST_NODE_T* last_in = hb_array_last(in_conditions);
|
|
592
702
|
end_position = last_in->location.end;
|
|
593
703
|
}
|
|
594
704
|
|
|
@@ -677,21 +787,7 @@ static size_t process_control_structure(
|
|
|
677
787
|
|
|
678
788
|
index++;
|
|
679
789
|
|
|
680
|
-
|
|
681
|
-
AST_NODE_T* child = hb_array_get(array, index);
|
|
682
|
-
|
|
683
|
-
if (!child) { break; }
|
|
684
|
-
|
|
685
|
-
if (child->type == AST_ERB_CONTENT_NODE) {
|
|
686
|
-
AST_ERB_CONTENT_NODE_T* child_erb = (AST_ERB_CONTENT_NODE_T*) child;
|
|
687
|
-
control_type_t child_type = detect_control_type(child_erb);
|
|
688
|
-
|
|
689
|
-
if (child_type == CONTROL_TYPE_ENSURE || child_type == CONTROL_TYPE_END) { break; }
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
hb_array_append(else_children, child);
|
|
693
|
-
index++;
|
|
694
|
-
}
|
|
790
|
+
index = process_block_children(node, array, index, else_children, context, initial_type);
|
|
695
791
|
|
|
696
792
|
hb_array_T* else_errors = next_erb->base.errors;
|
|
697
793
|
next_erb->base.errors = NULL;
|
|
@@ -859,7 +955,7 @@ static size_t process_control_structure(
|
|
|
859
955
|
if (end_node) {
|
|
860
956
|
end_position = end_node->base.location.end;
|
|
861
957
|
} else if (children && hb_array_size(children) > 0) {
|
|
862
|
-
AST_NODE_T* last_child =
|
|
958
|
+
AST_NODE_T* last_child = hb_array_last(children);
|
|
863
959
|
end_position = last_child->location.end;
|
|
864
960
|
}
|
|
865
961
|
|
|
@@ -1043,7 +1139,7 @@ static size_t process_block_children(
|
|
|
1043
1139
|
hb_array_T* temp_array = hb_array_init(1);
|
|
1044
1140
|
size_t new_index = process_control_structure(node, array, index, temp_array, context, child_type);
|
|
1045
1141
|
|
|
1046
|
-
if (hb_array_size(temp_array) > 0) { hb_array_append(children_array,
|
|
1142
|
+
if (hb_array_size(temp_array) > 0) { hb_array_append(children_array, hb_array_first(temp_array)); }
|
|
1047
1143
|
|
|
1048
1144
|
hb_array_free(&temp_array);
|
|
1049
1145
|
|
data/src/analyze_helpers.c
CHANGED
|
@@ -110,12 +110,20 @@ bool search_block_nodes(const pm_node_t* node, void* data) {
|
|
|
110
110
|
analyzed_ruby_T* analyzed = (analyzed_ruby_T*) data;
|
|
111
111
|
|
|
112
112
|
if (node->type == PM_BLOCK_NODE) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
pm_block_node_t* block_node = (pm_block_node_t*) node;
|
|
114
|
+
|
|
115
|
+
size_t opening_length = block_node->opening_loc.end - block_node->opening_loc.start;
|
|
116
|
+
|
|
117
|
+
if ((opening_length == 2 && block_node->opening_loc.start[0] == 'd' && block_node->opening_loc.start[1] == 'o')
|
|
118
|
+
|| (opening_length == 1 && block_node->opening_loc.start[0] == '{')) {
|
|
119
|
+
analyzed->has_block_node = true;
|
|
120
|
+
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
117
123
|
}
|
|
118
124
|
|
|
125
|
+
pm_visit_child_nodes(node, search_block_nodes, analyzed);
|
|
126
|
+
|
|
119
127
|
return false;
|
|
120
128
|
}
|
|
121
129
|
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
#ifndef HERB_BUFFER_H
|
|
2
2
|
#define HERB_BUFFER_H
|
|
3
3
|
|
|
4
|
+
#include "hb_arena.h"
|
|
4
5
|
#include "hb_string.h"
|
|
5
6
|
|
|
6
7
|
#include <stdbool.h>
|
|
7
8
|
#include <stdlib.h>
|
|
8
9
|
|
|
9
10
|
typedef struct HB_BUFFER_STRUCT {
|
|
11
|
+
hb_arena_T* allocator;
|
|
10
12
|
char* value;
|
|
11
13
|
size_t length;
|
|
12
14
|
size_t capacity;
|
|
13
15
|
} hb_buffer_T;
|
|
14
16
|
|
|
15
17
|
bool hb_buffer_init(hb_buffer_T* buffer, size_t capacity);
|
|
18
|
+
bool hb_buffer_init_arena(hb_buffer_T* buffer, hb_arena_T* allocator, size_t capacity);
|
|
16
19
|
|
|
17
20
|
void hb_buffer_append(hb_buffer_T* buffer, const char* text);
|
|
18
21
|
void hb_buffer_append_with_length(hb_buffer_T* buffer, const char* text, size_t length);
|
|
@@ -29,6 +32,5 @@ size_t hb_buffer_capacity(const hb_buffer_T* buffer);
|
|
|
29
32
|
size_t hb_buffer_sizeof(void);
|
|
30
33
|
|
|
31
34
|
void hb_buffer_clear(hb_buffer_T* buffer);
|
|
32
|
-
void hb_buffer_free(hb_buffer_T** buffer);
|
|
33
35
|
|
|
34
36
|
#endif
|
data/src/include/version.h
CHANGED
data/src/parser.c
CHANGED
|
@@ -315,8 +315,8 @@ static AST_HTML_ATTRIBUTE_NAME_NODE_T* parser_parse_html_attribute_name(parser_T
|
|
|
315
315
|
position_T node_end = { 0 };
|
|
316
316
|
|
|
317
317
|
if (children->size > 0) {
|
|
318
|
-
AST_NODE_T* first_child =
|
|
319
|
-
AST_NODE_T* last_child =
|
|
318
|
+
AST_NODE_T* first_child = hb_array_first(children);
|
|
319
|
+
AST_NODE_T* last_child = hb_array_last(children);
|
|
320
320
|
|
|
321
321
|
node_start = first_child->location.start;
|
|
322
322
|
node_end = last_child->location.end;
|
|
@@ -1301,17 +1301,15 @@ void match_tags_in_node_array(hb_array_T* nodes, hb_array_T* errors) {
|
|
|
1301
1301
|
|
|
1302
1302
|
hb_array_T* processed = parser_build_elements_from_tags(nodes, errors);
|
|
1303
1303
|
|
|
1304
|
-
|
|
1305
|
-
hb_array_remove(nodes, 0);
|
|
1306
|
-
}
|
|
1304
|
+
nodes->size = 0;
|
|
1307
1305
|
|
|
1308
|
-
for (size_t i = 0; i <
|
|
1306
|
+
for (size_t i = 0; i < processed->size; i++) {
|
|
1309
1307
|
hb_array_append(nodes, hb_array_get(processed, i));
|
|
1310
1308
|
}
|
|
1311
1309
|
|
|
1312
1310
|
hb_array_free(&processed);
|
|
1313
1311
|
|
|
1314
|
-
for (size_t i = 0; i <
|
|
1312
|
+
for (size_t i = 0; i < nodes->size; i++) {
|
|
1315
1313
|
AST_NODE_T* node = (AST_NODE_T*) hb_array_get(nodes, i);
|
|
1316
1314
|
if (node == NULL) { continue; }
|
|
1317
1315
|
|
data/src/util/hb_buffer.c
CHANGED
|
@@ -22,8 +22,14 @@ static bool hb_buffer_resize(hb_buffer_T* buffer, const size_t new_capacity) {
|
|
|
22
22
|
fprintf(stderr, "Error: Buffer capacity would overflow system limits.\n");
|
|
23
23
|
exit(1);
|
|
24
24
|
}
|
|
25
|
+
char* new_value = NULL;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
if (buffer->allocator == NULL) {
|
|
28
|
+
new_value = realloc(buffer->value, new_capacity + 1);
|
|
29
|
+
} else {
|
|
30
|
+
new_value = hb_arena_alloc(buffer->allocator, new_capacity + 1);
|
|
31
|
+
memcpy(new_value, buffer->value, buffer->capacity + 1);
|
|
32
|
+
}
|
|
27
33
|
|
|
28
34
|
if (unlikely(new_value == NULL)) {
|
|
29
35
|
fprintf(stderr, "Error: Failed to resize buffer to %zu.\n", new_capacity);
|
|
@@ -61,6 +67,7 @@ static bool hb_buffer_expand_if_needed(hb_buffer_T* buffer, const size_t require
|
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
bool hb_buffer_init(hb_buffer_T* buffer, const size_t capacity) {
|
|
70
|
+
buffer->allocator = NULL;
|
|
64
71
|
buffer->capacity = capacity;
|
|
65
72
|
buffer->length = 0;
|
|
66
73
|
buffer->value = malloc(sizeof(char) * (buffer->capacity + 1));
|
|
@@ -76,6 +83,16 @@ bool hb_buffer_init(hb_buffer_T* buffer, const size_t capacity) {
|
|
|
76
83
|
return true;
|
|
77
84
|
}
|
|
78
85
|
|
|
86
|
+
bool hb_buffer_init_arena(hb_buffer_T* buffer, hb_arena_T* allocator, size_t capacity) {
|
|
87
|
+
buffer->allocator = allocator;
|
|
88
|
+
buffer->capacity = capacity;
|
|
89
|
+
buffer->length = 0;
|
|
90
|
+
buffer->value = hb_arena_alloc(allocator, sizeof(char) * (buffer->capacity + 1));
|
|
91
|
+
buffer->value[0] = '\0';
|
|
92
|
+
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
|
|
79
96
|
char* hb_buffer_value(const hb_buffer_T* buffer) {
|
|
80
97
|
return buffer->value;
|
|
81
98
|
}
|
|
@@ -192,12 +209,3 @@ void hb_buffer_clear(hb_buffer_T* buffer) {
|
|
|
192
209
|
buffer->length = 0;
|
|
193
210
|
buffer->value[0] = '\0';
|
|
194
211
|
}
|
|
195
|
-
|
|
196
|
-
void hb_buffer_free(hb_buffer_T** buffer) {
|
|
197
|
-
if (!buffer || !*buffer) { return; }
|
|
198
|
-
|
|
199
|
-
if ((*buffer)->value != NULL) { free((*buffer)->value); }
|
|
200
|
-
|
|
201
|
-
free(*buffer);
|
|
202
|
-
*buffer = NULL;
|
|
203
|
-
}
|