herb 0.8.6-x86_64-linux-gnu → 0.8.8-x86_64-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/Rakefile +7 -0
- data/config.yml +12 -0
- data/ext/herb/error_helpers.c +1 -1
- data/ext/herb/extconf.rb +0 -4
- data/ext/herb/extension_helpers.c +1 -1
- data/ext/herb/nodes.c +18 -10
- 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/nodes.rb +32 -8
- data/lib/herb/engine/debug_visitor.rb +1 -1
- data/lib/herb/version.rb +1 -1
- data/lib/herb.rb +30 -3
- data/sig/herb/ast/nodes.rbs +16 -8
- data/sig/serialized_ast_nodes.rbs +4 -0
- data/src/analyze.c +137 -42
- data/src/analyze_helpers.c +80 -12
- data/src/analyzed_ruby.c +1 -0
- data/src/ast_node.c +1 -1
- data/src/ast_nodes.c +65 -161
- data/src/ast_pretty_print.c +52 -0
- data/src/errors.c +5 -5
- data/src/extract.c +2 -2
- data/src/herb.c +2 -2
- data/src/include/analyze_helpers.h +7 -0
- data/src/include/analyzed_ruby.h +1 -0
- data/src/include/ast_nodes.h +8 -4
- data/src/include/location.h +4 -0
- data/src/include/prism_helpers.h +6 -0
- data/src/include/util/hb_narray.h +1 -0
- data/src/include/version.h +1 -1
- data/src/location.c +16 -0
- data/src/parser.c +9 -9
- data/src/parser_helpers.c +4 -4
- data/src/pretty_print.c +6 -6
- data/src/prism_helpers.c +188 -0
- data/src/util/hb_array.c +1 -0
- data/src/util/hb_narray.c +6 -0
- data/src/visitor.c +26 -26
- data/templates/ext/herb/error_helpers.c.erb +1 -1
- data/templates/ext/herb/nodes.c.erb +3 -1
- data/templates/java/error_helpers.c.erb +1 -1
- data/templates/java/nodes.c.erb +5 -3
- data/templates/java/org/herb/ast/Nodes.java.erb +11 -0
- data/templates/javascript/packages/core/src/nodes.ts.erb +14 -0
- data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +1 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +10 -1
- data/templates/lib/herb/ast/nodes.rb.erb +4 -0
- data/templates/rust/src/ast/nodes.rs.erb +12 -2
- data/templates/rust/src/nodes.rs.erb +4 -0
- data/templates/src/ast_nodes.c.erb +7 -7
- data/templates/src/ast_pretty_print.c.erb +14 -0
- data/templates/src/errors.c.erb +5 -5
- data/templates/src/visitor.c.erb +1 -1
- data/templates/template.rb +11 -0
- data/templates/wasm/error_helpers.cpp.erb +1 -1
- data/templates/wasm/nodes.cpp.erb +7 -1
- data/vendor/prism/include/prism/version.h +2 -2
- data/vendor/prism/src/prism.c +48 -27
- data/vendor/prism/templates/java/org/prism/Loader.java.erb +1 -1
- data/vendor/prism/templates/javascript/src/deserialize.js.erb +1 -1
- data/vendor/prism/templates/lib/prism/compiler.rb.erb +2 -2
- data/vendor/prism/templates/lib/prism/node.rb.erb +24 -1
- data/vendor/prism/templates/lib/prism/serialize.rb.erb +1 -1
- data/vendor/prism/templates/lib/prism/visitor.rb.erb +2 -2
- data/vendor/prism/templates/sig/prism/node.rbs.erb +1 -0
- metadata +2 -2
data/src/prism_helpers.c
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
#include "include/prism_helpers.h"
|
|
2
2
|
#include "include/ast_nodes.h"
|
|
3
3
|
#include "include/errors.h"
|
|
4
|
+
#include "include/location.h"
|
|
4
5
|
#include "include/position.h"
|
|
5
6
|
#include "include/util.h"
|
|
7
|
+
#include "include/util/hb_buffer.h"
|
|
6
8
|
|
|
7
9
|
#include <prism.h>
|
|
10
|
+
#include <stdlib.h>
|
|
11
|
+
#include <string.h>
|
|
8
12
|
|
|
9
13
|
const char* pm_error_level_to_string(pm_error_level_t level) {
|
|
10
14
|
switch (level) {
|
|
@@ -50,3 +54,187 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error_with_positions(
|
|
|
50
54
|
end
|
|
51
55
|
);
|
|
52
56
|
}
|
|
57
|
+
|
|
58
|
+
typedef struct {
|
|
59
|
+
pm_location_t then_keyword_loc;
|
|
60
|
+
bool found;
|
|
61
|
+
} then_keyword_search_context_T;
|
|
62
|
+
|
|
63
|
+
static bool has_pm_location(pm_location_t location) {
|
|
64
|
+
return location.start != NULL && location.end != NULL && (location.end - location.start) > 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static bool search_then_keyword_location(const pm_node_t* node, void* data) {
|
|
68
|
+
then_keyword_search_context_T* context = (then_keyword_search_context_T*) data;
|
|
69
|
+
|
|
70
|
+
if (context->found) { return false; }
|
|
71
|
+
|
|
72
|
+
switch (node->type) {
|
|
73
|
+
case PM_IF_NODE: {
|
|
74
|
+
const pm_if_node_t* if_node = (const pm_if_node_t*) node;
|
|
75
|
+
if (has_pm_location(if_node->then_keyword_loc)) {
|
|
76
|
+
context->then_keyword_loc = if_node->then_keyword_loc;
|
|
77
|
+
context->found = true;
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
case PM_UNLESS_NODE: {
|
|
84
|
+
const pm_unless_node_t* unless_node = (const pm_unless_node_t*) node;
|
|
85
|
+
if (has_pm_location(unless_node->then_keyword_loc)) {
|
|
86
|
+
context->then_keyword_loc = unless_node->then_keyword_loc;
|
|
87
|
+
context->found = true;
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
case PM_WHEN_NODE: {
|
|
94
|
+
const pm_when_node_t* when_node = (const pm_when_node_t*) node;
|
|
95
|
+
if (has_pm_location(when_node->then_keyword_loc)) {
|
|
96
|
+
context->then_keyword_loc = when_node->then_keyword_loc;
|
|
97
|
+
context->found = true;
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
case PM_IN_NODE: {
|
|
104
|
+
const pm_in_node_t* in_node = (const pm_in_node_t*) node;
|
|
105
|
+
if (has_pm_location(in_node->then_loc)) {
|
|
106
|
+
context->then_keyword_loc = in_node->then_loc;
|
|
107
|
+
context->found = true;
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
default: break;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
pm_visit_child_nodes(node, search_then_keyword_location, context);
|
|
117
|
+
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
location_T* get_then_keyword_location(analyzed_ruby_T* analyzed, const char* source) {
|
|
122
|
+
if (analyzed == NULL || analyzed->root == NULL || source == NULL) { return NULL; }
|
|
123
|
+
|
|
124
|
+
then_keyword_search_context_T context = { .then_keyword_loc = { .start = NULL, .end = NULL }, .found = false };
|
|
125
|
+
|
|
126
|
+
pm_visit_child_nodes(analyzed->root, search_then_keyword_location, &context);
|
|
127
|
+
|
|
128
|
+
if (!context.found) { return NULL; }
|
|
129
|
+
|
|
130
|
+
size_t start_offset = (size_t) (context.then_keyword_loc.start - analyzed->parser.start);
|
|
131
|
+
size_t end_offset = (size_t) (context.then_keyword_loc.end - analyzed->parser.start);
|
|
132
|
+
|
|
133
|
+
position_T start_position = position_from_source_with_offset(source, start_offset);
|
|
134
|
+
position_T end_position = position_from_source_with_offset(source, end_offset);
|
|
135
|
+
|
|
136
|
+
return location_create(start_position, end_position);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static location_T* parse_wrapped_and_find_then_keyword(
|
|
140
|
+
hb_buffer_T* buffer,
|
|
141
|
+
const char* source,
|
|
142
|
+
size_t source_length,
|
|
143
|
+
size_t prefix_length,
|
|
144
|
+
size_t adjustment_threshold,
|
|
145
|
+
size_t adjustment_amount
|
|
146
|
+
) {
|
|
147
|
+
pm_parser_t parser;
|
|
148
|
+
pm_parser_init(&parser, (const uint8_t*) hb_buffer_value(buffer), hb_buffer_length(buffer), NULL);
|
|
149
|
+
pm_node_t* root = pm_parse(&parser);
|
|
150
|
+
|
|
151
|
+
if (root == NULL) {
|
|
152
|
+
pm_parser_free(&parser);
|
|
153
|
+
|
|
154
|
+
return NULL;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
then_keyword_search_context_T context = { .then_keyword_loc = { .start = NULL, .end = NULL }, .found = false };
|
|
158
|
+
|
|
159
|
+
pm_visit_child_nodes(root, search_then_keyword_location, &context);
|
|
160
|
+
|
|
161
|
+
location_T* location = NULL;
|
|
162
|
+
|
|
163
|
+
if (context.found) {
|
|
164
|
+
size_t start_offset = (size_t) (context.then_keyword_loc.start - parser.start);
|
|
165
|
+
size_t end_offset = (size_t) (context.then_keyword_loc.end - parser.start);
|
|
166
|
+
|
|
167
|
+
if (start_offset >= prefix_length && end_offset >= prefix_length) {
|
|
168
|
+
start_offset -= prefix_length;
|
|
169
|
+
end_offset -= prefix_length;
|
|
170
|
+
|
|
171
|
+
if (start_offset > adjustment_threshold) {
|
|
172
|
+
start_offset += adjustment_amount;
|
|
173
|
+
end_offset += adjustment_amount;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (start_offset <= source_length && end_offset <= source_length) {
|
|
177
|
+
position_T start_position = position_from_source_with_offset(source, start_offset);
|
|
178
|
+
position_T end_position = position_from_source_with_offset(source, end_offset);
|
|
179
|
+
|
|
180
|
+
location = location_create(start_position, end_position);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
pm_node_destroy(&parser, root);
|
|
186
|
+
pm_parser_free(&parser);
|
|
187
|
+
|
|
188
|
+
return location;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
location_T* get_then_keyword_location_wrapped(const char* source, bool is_in_clause) {
|
|
192
|
+
if (source == NULL) { return NULL; }
|
|
193
|
+
|
|
194
|
+
size_t source_length = strlen(source);
|
|
195
|
+
|
|
196
|
+
hb_buffer_T buffer;
|
|
197
|
+
|
|
198
|
+
if (!hb_buffer_init(&buffer, source_length + 16)) { return NULL; }
|
|
199
|
+
|
|
200
|
+
hb_buffer_append(&buffer, "case x\n");
|
|
201
|
+
size_t prefix_length = hb_buffer_length(&buffer);
|
|
202
|
+
hb_buffer_append(&buffer, source);
|
|
203
|
+
hb_buffer_append(&buffer, "\nend");
|
|
204
|
+
|
|
205
|
+
location_T* location =
|
|
206
|
+
parse_wrapped_and_find_then_keyword(&buffer, source, source_length, prefix_length, SIZE_MAX, 0);
|
|
207
|
+
|
|
208
|
+
free(buffer.value);
|
|
209
|
+
|
|
210
|
+
return location;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
location_T* get_then_keyword_location_elsif_wrapped(const char* source) {
|
|
214
|
+
if (source == NULL) { return NULL; }
|
|
215
|
+
|
|
216
|
+
const char* elsif_position = strstr(source, "elsif");
|
|
217
|
+
|
|
218
|
+
if (elsif_position == NULL) { return NULL; }
|
|
219
|
+
|
|
220
|
+
size_t source_length = strlen(source);
|
|
221
|
+
size_t elsif_offset = (size_t) (elsif_position - source);
|
|
222
|
+
size_t replacement_diff = strlen("elsif") - strlen("if");
|
|
223
|
+
|
|
224
|
+
hb_buffer_T buffer;
|
|
225
|
+
|
|
226
|
+
if (!hb_buffer_init(&buffer, source_length + 8)) { return NULL; }
|
|
227
|
+
|
|
228
|
+
hb_buffer_append_with_length(&buffer, source, elsif_offset);
|
|
229
|
+
hb_buffer_append(&buffer, "if");
|
|
230
|
+
size_t if_end_offset = hb_buffer_length(&buffer);
|
|
231
|
+
hb_buffer_append(&buffer, source + elsif_offset + strlen("elsif"));
|
|
232
|
+
hb_buffer_append(&buffer, "\nend");
|
|
233
|
+
|
|
234
|
+
location_T* location =
|
|
235
|
+
parse_wrapped_and_find_then_keyword(&buffer, source, source_length, 0, if_end_offset, replacement_diff);
|
|
236
|
+
|
|
237
|
+
free(buffer.value);
|
|
238
|
+
|
|
239
|
+
return location;
|
|
240
|
+
}
|
data/src/util/hb_array.c
CHANGED
data/src/util/hb_narray.c
CHANGED
data/src/visitor.c
CHANGED
|
@@ -24,7 +24,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
24
24
|
const AST_DOCUMENT_NODE_T* document_node = ((const AST_DOCUMENT_NODE_T *) node);
|
|
25
25
|
|
|
26
26
|
if (document_node->children != NULL) {
|
|
27
|
-
for (size_t index = 0; index < document_node->children
|
|
27
|
+
for (size_t index = 0; index < hb_array_size(document_node->children); index++) {
|
|
28
28
|
herb_visit_node(hb_array_get(document_node->children, index), visitor, data);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -35,7 +35,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
35
35
|
const AST_HTML_OPEN_TAG_NODE_T* html_open_tag_node = ((const AST_HTML_OPEN_TAG_NODE_T *) node);
|
|
36
36
|
|
|
37
37
|
if (html_open_tag_node->children != NULL) {
|
|
38
|
-
for (size_t index = 0; index < html_open_tag_node->children
|
|
38
|
+
for (size_t index = 0; index < hb_array_size(html_open_tag_node->children); index++) {
|
|
39
39
|
herb_visit_node(hb_array_get(html_open_tag_node->children, index), visitor, data);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -46,7 +46,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
46
46
|
const AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node = ((const AST_HTML_CLOSE_TAG_NODE_T *) node);
|
|
47
47
|
|
|
48
48
|
if (html_close_tag_node->children != NULL) {
|
|
49
|
-
for (size_t index = 0; index < html_close_tag_node->children
|
|
49
|
+
for (size_t index = 0; index < hb_array_size(html_close_tag_node->children); index++) {
|
|
50
50
|
herb_visit_node(hb_array_get(html_close_tag_node->children, index), visitor, data);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -61,7 +61,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
if (html_element_node->body != NULL) {
|
|
64
|
-
for (size_t index = 0; index < html_element_node->body
|
|
64
|
+
for (size_t index = 0; index < hb_array_size(html_element_node->body); index++) {
|
|
65
65
|
herb_visit_node(hb_array_get(html_element_node->body, index), visitor, data);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -76,7 +76,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
76
76
|
const AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node = ((const AST_HTML_ATTRIBUTE_VALUE_NODE_T *) node);
|
|
77
77
|
|
|
78
78
|
if (html_attribute_value_node->children != NULL) {
|
|
79
|
-
for (size_t index = 0; index < html_attribute_value_node->children
|
|
79
|
+
for (size_t index = 0; index < hb_array_size(html_attribute_value_node->children); index++) {
|
|
80
80
|
herb_visit_node(hb_array_get(html_attribute_value_node->children, index), visitor, data);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -87,7 +87,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
87
87
|
const AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node = ((const AST_HTML_ATTRIBUTE_NAME_NODE_T *) node);
|
|
88
88
|
|
|
89
89
|
if (html_attribute_name_node->children != NULL) {
|
|
90
|
-
for (size_t index = 0; index < html_attribute_name_node->children
|
|
90
|
+
for (size_t index = 0; index < hb_array_size(html_attribute_name_node->children); index++) {
|
|
91
91
|
herb_visit_node(hb_array_get(html_attribute_name_node->children, index), visitor, data);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -111,7 +111,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
111
111
|
const AST_HTML_COMMENT_NODE_T* html_comment_node = ((const AST_HTML_COMMENT_NODE_T *) node);
|
|
112
112
|
|
|
113
113
|
if (html_comment_node->children != NULL) {
|
|
114
|
-
for (size_t index = 0; index < html_comment_node->children
|
|
114
|
+
for (size_t index = 0; index < hb_array_size(html_comment_node->children); index++) {
|
|
115
115
|
herb_visit_node(hb_array_get(html_comment_node->children, index), visitor, data);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -122,7 +122,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
122
122
|
const AST_HTML_DOCTYPE_NODE_T* html_doctype_node = ((const AST_HTML_DOCTYPE_NODE_T *) node);
|
|
123
123
|
|
|
124
124
|
if (html_doctype_node->children != NULL) {
|
|
125
|
-
for (size_t index = 0; index < html_doctype_node->children
|
|
125
|
+
for (size_t index = 0; index < hb_array_size(html_doctype_node->children); index++) {
|
|
126
126
|
herb_visit_node(hb_array_get(html_doctype_node->children, index), visitor, data);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -133,7 +133,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
133
133
|
const AST_XML_DECLARATION_NODE_T* xml_declaration_node = ((const AST_XML_DECLARATION_NODE_T *) node);
|
|
134
134
|
|
|
135
135
|
if (xml_declaration_node->children != NULL) {
|
|
136
|
-
for (size_t index = 0; index < xml_declaration_node->children
|
|
136
|
+
for (size_t index = 0; index < hb_array_size(xml_declaration_node->children); index++) {
|
|
137
137
|
herb_visit_node(hb_array_get(xml_declaration_node->children, index), visitor, data);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
@@ -144,7 +144,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
144
144
|
const AST_CDATA_NODE_T* cdata_node = ((const AST_CDATA_NODE_T *) node);
|
|
145
145
|
|
|
146
146
|
if (cdata_node->children != NULL) {
|
|
147
|
-
for (size_t index = 0; index < cdata_node->children
|
|
147
|
+
for (size_t index = 0; index < hb_array_size(cdata_node->children); index++) {
|
|
148
148
|
herb_visit_node(hb_array_get(cdata_node->children, index), visitor, data);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
@@ -155,7 +155,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
155
155
|
const AST_ERB_ELSE_NODE_T* erb_else_node = ((const AST_ERB_ELSE_NODE_T *) node);
|
|
156
156
|
|
|
157
157
|
if (erb_else_node->statements != NULL) {
|
|
158
|
-
for (size_t index = 0; index < erb_else_node->statements
|
|
158
|
+
for (size_t index = 0; index < hb_array_size(erb_else_node->statements); index++) {
|
|
159
159
|
herb_visit_node(hb_array_get(erb_else_node->statements, index), visitor, data);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -166,7 +166,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
166
166
|
const AST_ERB_IF_NODE_T* erb_if_node = ((const AST_ERB_IF_NODE_T *) node);
|
|
167
167
|
|
|
168
168
|
if (erb_if_node->statements != NULL) {
|
|
169
|
-
for (size_t index = 0; index < erb_if_node->statements
|
|
169
|
+
for (size_t index = 0; index < hb_array_size(erb_if_node->statements); index++) {
|
|
170
170
|
herb_visit_node(hb_array_get(erb_if_node->statements, index), visitor, data);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -185,7 +185,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
185
185
|
const AST_ERB_BLOCK_NODE_T* erb_block_node = ((const AST_ERB_BLOCK_NODE_T *) node);
|
|
186
186
|
|
|
187
187
|
if (erb_block_node->body != NULL) {
|
|
188
|
-
for (size_t index = 0; index < erb_block_node->body
|
|
188
|
+
for (size_t index = 0; index < hb_array_size(erb_block_node->body); index++) {
|
|
189
189
|
herb_visit_node(hb_array_get(erb_block_node->body, index), visitor, data);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
@@ -200,7 +200,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
200
200
|
const AST_ERB_WHEN_NODE_T* erb_when_node = ((const AST_ERB_WHEN_NODE_T *) node);
|
|
201
201
|
|
|
202
202
|
if (erb_when_node->statements != NULL) {
|
|
203
|
-
for (size_t index = 0; index < erb_when_node->statements
|
|
203
|
+
for (size_t index = 0; index < hb_array_size(erb_when_node->statements); index++) {
|
|
204
204
|
herb_visit_node(hb_array_get(erb_when_node->statements, index), visitor, data);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
@@ -211,13 +211,13 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
211
211
|
const AST_ERB_CASE_NODE_T* erb_case_node = ((const AST_ERB_CASE_NODE_T *) node);
|
|
212
212
|
|
|
213
213
|
if (erb_case_node->children != NULL) {
|
|
214
|
-
for (size_t index = 0; index < erb_case_node->children
|
|
214
|
+
for (size_t index = 0; index < hb_array_size(erb_case_node->children); index++) {
|
|
215
215
|
herb_visit_node(hb_array_get(erb_case_node->children, index), visitor, data);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
if (erb_case_node->conditions != NULL) {
|
|
220
|
-
for (size_t index = 0; index < erb_case_node->conditions
|
|
220
|
+
for (size_t index = 0; index < hb_array_size(erb_case_node->conditions); index++) {
|
|
221
221
|
herb_visit_node(hb_array_get(erb_case_node->conditions, index), visitor, data);
|
|
222
222
|
}
|
|
223
223
|
}
|
|
@@ -236,13 +236,13 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
236
236
|
const AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = ((const AST_ERB_CASE_MATCH_NODE_T *) node);
|
|
237
237
|
|
|
238
238
|
if (erb_case_match_node->children != NULL) {
|
|
239
|
-
for (size_t index = 0; index < erb_case_match_node->children
|
|
239
|
+
for (size_t index = 0; index < hb_array_size(erb_case_match_node->children); index++) {
|
|
240
240
|
herb_visit_node(hb_array_get(erb_case_match_node->children, index), visitor, data);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
if (erb_case_match_node->conditions != NULL) {
|
|
245
|
-
for (size_t index = 0; index < erb_case_match_node->conditions
|
|
245
|
+
for (size_t index = 0; index < hb_array_size(erb_case_match_node->conditions); index++) {
|
|
246
246
|
herb_visit_node(hb_array_get(erb_case_match_node->conditions, index), visitor, data);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
@@ -261,7 +261,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
261
261
|
const AST_ERB_WHILE_NODE_T* erb_while_node = ((const AST_ERB_WHILE_NODE_T *) node);
|
|
262
262
|
|
|
263
263
|
if (erb_while_node->statements != NULL) {
|
|
264
|
-
for (size_t index = 0; index < erb_while_node->statements
|
|
264
|
+
for (size_t index = 0; index < hb_array_size(erb_while_node->statements); index++) {
|
|
265
265
|
herb_visit_node(hb_array_get(erb_while_node->statements, index), visitor, data);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
@@ -276,7 +276,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
276
276
|
const AST_ERB_UNTIL_NODE_T* erb_until_node = ((const AST_ERB_UNTIL_NODE_T *) node);
|
|
277
277
|
|
|
278
278
|
if (erb_until_node->statements != NULL) {
|
|
279
|
-
for (size_t index = 0; index < erb_until_node->statements
|
|
279
|
+
for (size_t index = 0; index < hb_array_size(erb_until_node->statements); index++) {
|
|
280
280
|
herb_visit_node(hb_array_get(erb_until_node->statements, index), visitor, data);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
@@ -291,7 +291,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
291
291
|
const AST_ERB_FOR_NODE_T* erb_for_node = ((const AST_ERB_FOR_NODE_T *) node);
|
|
292
292
|
|
|
293
293
|
if (erb_for_node->statements != NULL) {
|
|
294
|
-
for (size_t index = 0; index < erb_for_node->statements
|
|
294
|
+
for (size_t index = 0; index < hb_array_size(erb_for_node->statements); index++) {
|
|
295
295
|
herb_visit_node(hb_array_get(erb_for_node->statements, index), visitor, data);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
@@ -306,7 +306,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
306
306
|
const AST_ERB_RESCUE_NODE_T* erb_rescue_node = ((const AST_ERB_RESCUE_NODE_T *) node);
|
|
307
307
|
|
|
308
308
|
if (erb_rescue_node->statements != NULL) {
|
|
309
|
-
for (size_t index = 0; index < erb_rescue_node->statements
|
|
309
|
+
for (size_t index = 0; index < hb_array_size(erb_rescue_node->statements); index++) {
|
|
310
310
|
herb_visit_node(hb_array_get(erb_rescue_node->statements, index), visitor, data);
|
|
311
311
|
}
|
|
312
312
|
}
|
|
@@ -321,7 +321,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
321
321
|
const AST_ERB_ENSURE_NODE_T* erb_ensure_node = ((const AST_ERB_ENSURE_NODE_T *) node);
|
|
322
322
|
|
|
323
323
|
if (erb_ensure_node->statements != NULL) {
|
|
324
|
-
for (size_t index = 0; index < erb_ensure_node->statements
|
|
324
|
+
for (size_t index = 0; index < hb_array_size(erb_ensure_node->statements); index++) {
|
|
325
325
|
herb_visit_node(hb_array_get(erb_ensure_node->statements, index), visitor, data);
|
|
326
326
|
}
|
|
327
327
|
}
|
|
@@ -332,7 +332,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
332
332
|
const AST_ERB_BEGIN_NODE_T* erb_begin_node = ((const AST_ERB_BEGIN_NODE_T *) node);
|
|
333
333
|
|
|
334
334
|
if (erb_begin_node->statements != NULL) {
|
|
335
|
-
for (size_t index = 0; index < erb_begin_node->statements
|
|
335
|
+
for (size_t index = 0; index < hb_array_size(erb_begin_node->statements); index++) {
|
|
336
336
|
herb_visit_node(hb_array_get(erb_begin_node->statements, index), visitor, data);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
@@ -359,7 +359,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
359
359
|
const AST_ERB_UNLESS_NODE_T* erb_unless_node = ((const AST_ERB_UNLESS_NODE_T *) node);
|
|
360
360
|
|
|
361
361
|
if (erb_unless_node->statements != NULL) {
|
|
362
|
-
for (size_t index = 0; index < erb_unless_node->statements
|
|
362
|
+
for (size_t index = 0; index < hb_array_size(erb_unless_node->statements); index++) {
|
|
363
363
|
herb_visit_node(hb_array_get(erb_unless_node->statements, index), visitor, data);
|
|
364
364
|
}
|
|
365
365
|
}
|
|
@@ -378,7 +378,7 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
378
378
|
const AST_ERB_IN_NODE_T* erb_in_node = ((const AST_ERB_IN_NODE_T *) node);
|
|
379
379
|
|
|
380
380
|
if (erb_in_node->statements != NULL) {
|
|
381
|
-
for (size_t index = 0; index < erb_in_node->statements
|
|
381
|
+
for (size_t index = 0; index < hb_array_size(erb_in_node->statements); index++) {
|
|
382
382
|
herb_visit_node(hb_array_get(erb_in_node->statements, index), visitor, data);
|
|
383
383
|
}
|
|
384
384
|
}
|
|
@@ -71,7 +71,7 @@ VALUE rb_errors_array_from_c_array(hb_array_T* array) {
|
|
|
71
71
|
VALUE rb_array = rb_ary_new();
|
|
72
72
|
|
|
73
73
|
if (array) {
|
|
74
|
-
for (size_t i = 0; i < array
|
|
74
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
75
75
|
ERROR_T* child_node = (ERROR_T*) hb_array_get(array, i);
|
|
76
76
|
|
|
77
77
|
if (child_node) {
|
|
@@ -45,6 +45,8 @@ static VALUE rb_<%= node.human %>_from_c_struct(<%= node.struct_type %>* <%= nod
|
|
|
45
45
|
hb_string_T element_source_string = element_source_to_string(<%= node.human %>-><%= field.name %>);
|
|
46
46
|
<%= node.human %>_<%= field.name %> = rb_utf8_str_new(element_source_string.data, element_source_string.length);
|
|
47
47
|
}
|
|
48
|
+
<%- when Herb::Template::LocationField -%>
|
|
49
|
+
VALUE <%= node.human %>_<%= field.name %> = (<%= node.human %>-><%= field.name %> != NULL) ? rb_location_from_c_struct(*<%= node.human %>-><%= field.name %>) : Qnil;
|
|
48
50
|
<%- else -%>
|
|
49
51
|
/* <%= field.inspect %> */
|
|
50
52
|
VALUE <%= node.human %>_<%= field.name %> = Qnil;
|
|
@@ -81,7 +83,7 @@ static VALUE rb_nodes_array_from_c_array(hb_array_T* array) {
|
|
|
81
83
|
VALUE rb_array = rb_ary_new();
|
|
82
84
|
|
|
83
85
|
if (array) {
|
|
84
|
-
for (size_t i = 0; i < array
|
|
86
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
85
87
|
AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
|
|
86
88
|
|
|
87
89
|
if (child_node) {
|
|
@@ -46,7 +46,7 @@ jobject ErrorsArrayFromCArray(JNIEnv* env, hb_array_T* array) {
|
|
|
46
46
|
jobject javaList = (*env)->NewObject(env, arrayListClass, arrayListConstructor, 0);
|
|
47
47
|
|
|
48
48
|
if (array) {
|
|
49
|
-
for (size_t i = 0; i < array
|
|
49
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
50
50
|
ERROR_T* error = (ERROR_T*) hb_array_get(array, i);
|
|
51
51
|
|
|
52
52
|
if (error) {
|
data/templates/java/nodes.c.erb
CHANGED
|
@@ -37,12 +37,14 @@ jobject <%= node.name %>FromCStruct(JNIEnv* env, <%= node.struct_type %>* <%= no
|
|
|
37
37
|
<%- elsif field.is_a?(Herb::Template::ElementSourceField) -%>
|
|
38
38
|
// TODO: Convert element_source to string
|
|
39
39
|
jstring <%= field.name %> = (*env)->NewStringUTF(env, "");
|
|
40
|
+
<%- elsif field.is_a?(Herb::Template::LocationField) -%>
|
|
41
|
+
jobject <%= field.name %> = <%= node.human %>-><%= field.name %> ? CreateLocation(env, *<%= node.human %>-><%= field.name %>) : NULL;
|
|
40
42
|
<%- elsif field.is_a?(Herb::Template::AnalyzedRubyField) || field.is_a?(Herb::Template::PrismNodeField) -%>
|
|
41
43
|
// Skip <%= field.name %> (<%= field.class.name.split('::').last %>) - not supported in Java yet
|
|
42
44
|
<%- end -%>
|
|
43
45
|
<%- end -%>
|
|
44
46
|
|
|
45
|
-
const char* signature = "(Ljava/lang/String;Lorg/herb/Location;Ljava/util/List;<%- node.fields.each do |f| -%><%- unless f.is_a?(Herb::Template::AnalyzedRubyField) || f.is_a?(Herb::Template::PrismNodeField) -%><%- if f.is_a?(Herb::Template::StringField) -%>Ljava/lang/String;<%- elsif f.is_a?(Herb::Template::TokenField) -%>Lorg/herb/Token;<%- elsif f.is_a?(Herb::Template::BooleanField) -%>Z<%- elsif f.is_a?(Herb::Template::ArrayField) -%>Ljava/util/List;<%- elsif f.is_a?(Herb::Template::NodeField) -%>Lorg/herb/ast/<%= f.specific_kind || 'Node' %>;<%- elsif f.is_a?(Herb::Template::ElementSourceField) -%>Ljava/lang/String;<%- end -%><%- end -%><%- end -%>)V";
|
|
47
|
+
const char* signature = "(Ljava/lang/String;Lorg/herb/Location;Ljava/util/List;<%- node.fields.each do |f| -%><%- unless f.is_a?(Herb::Template::AnalyzedRubyField) || f.is_a?(Herb::Template::PrismNodeField) -%><%- if f.is_a?(Herb::Template::StringField) -%>Ljava/lang/String;<%- elsif f.is_a?(Herb::Template::TokenField) -%>Lorg/herb/Token;<%- elsif f.is_a?(Herb::Template::BooleanField) -%>Z<%- elsif f.is_a?(Herb::Template::ArrayField) -%>Ljava/util/List;<%- elsif f.is_a?(Herb::Template::NodeField) -%>Lorg/herb/ast/<%= f.specific_kind || 'Node' %>;<%- elsif f.is_a?(Herb::Template::ElementSourceField) -%>Ljava/lang/String;<%- elsif f.is_a?(Herb::Template::LocationField) -%>Lorg/herb/Location;<%- end -%><%- end -%><%- end -%>)V";
|
|
46
48
|
jmethodID constructor = (*env)->GetMethodID(env, nodeClass, "<init>", signature);
|
|
47
49
|
if (!constructor) { return NULL; }
|
|
48
50
|
|
|
@@ -75,9 +77,9 @@ jobject NodesArrayFromCArray(JNIEnv* env, hb_array_T* array) {
|
|
|
75
77
|
return (*env)->NewObject(env, arrayListClass, arrayListConstructor, 0);
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
jobject javaList = (*env)->NewObject(env, arrayListClass, arrayListConstructor, (jint) array
|
|
80
|
+
jobject javaList = (*env)->NewObject(env, arrayListClass, arrayListConstructor, (jint) hb_array_size(array));
|
|
79
81
|
|
|
80
|
-
for (size_t i = 0; i < array
|
|
82
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
81
83
|
AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
|
|
82
84
|
|
|
83
85
|
if (child_node) {
|
|
@@ -26,6 +26,8 @@ class <%= node.name %> extends BaseNode {
|
|
|
26
26
|
<%- end -%>
|
|
27
27
|
<%- elsif field.is_a?(Herb::Template::ElementSourceField) -%>
|
|
28
28
|
private final String <%= field.name %>;
|
|
29
|
+
<%- elsif field.is_a?(Herb::Template::LocationField) -%>
|
|
30
|
+
private final Location <%= field.name %>;
|
|
29
31
|
<%- else -%>
|
|
30
32
|
// private final Object <%= field.name %>;
|
|
31
33
|
<%- end -%>
|
|
@@ -50,6 +52,8 @@ class <%= node.name %> extends BaseNode {
|
|
|
50
52
|
<%= field.specific_kind || 'Node' %> <%= field.name %><%- if node.fields.last != field %>,<% end %>
|
|
51
53
|
<%- elsif field.is_a?(Herb::Template::ElementSourceField) -%>
|
|
52
54
|
String <%= field.name %><%- if node.fields.last != field %>,<% end %>
|
|
55
|
+
<%- elsif field.is_a?(Herb::Template::LocationField) -%>
|
|
56
|
+
Location <%= field.name %><%- if node.fields.last != field %>,<% end %>
|
|
53
57
|
<%- else -%>
|
|
54
58
|
// <%= field.c_type %> <%= field.name %>
|
|
55
59
|
<%- end -%>
|
|
@@ -101,6 +105,11 @@ class <%= node.name %> extends BaseNode {
|
|
|
101
105
|
return <%= field.name %>;
|
|
102
106
|
}
|
|
103
107
|
|
|
108
|
+
<%- elsif field.is_a?(Herb::Template::LocationField) -%>
|
|
109
|
+
public Location get<%= field.name.split('_').map(&:capitalize).join %>() {
|
|
110
|
+
return <%= field.name %>;
|
|
111
|
+
}
|
|
112
|
+
|
|
104
113
|
<%- else -%>
|
|
105
114
|
/*
|
|
106
115
|
public Object get<%= field.name.split('_').map(&:capitalize).join %>() {
|
|
@@ -157,6 +166,8 @@ class <%= node.name %> extends BaseNode {
|
|
|
157
166
|
output.append("<%= symbol %><%= field.name %>: ").append(<%= field.name %> != null ? <%= field.name %>.treeInspect() : "∅").append("\n");
|
|
158
167
|
<%- elsif field.is_a?(Herb::Template::BooleanField) -%>
|
|
159
168
|
output.append("<%= symbol %><%= field.name %>: ").append(<%= field.name %>).append("\n");
|
|
169
|
+
<%- elsif field.is_a?(Herb::Template::LocationField) -%>
|
|
170
|
+
output.append("<%= symbol %><%= field.name %>: ").append(<%= field.name %> != null ? "(location: " + <%= field.name %>.treeInspect() + ")" : "∅").append("\n");
|
|
160
171
|
<%- elsif field.is_a?(Herb::Template::ArrayField) -%>
|
|
161
172
|
output.append("<%= symbol %><%= field.name %>: ").append(inspectArray(<%= field.name %>, "<%= prefix %>"));
|
|
162
173
|
<%- elsif field.is_a?(Herb::Template::NodeField) -%>
|
|
@@ -143,6 +143,8 @@ export interface Serialized<%= node.name %> extends SerializedNode {
|
|
|
143
143
|
<%= field.name %>: boolean;
|
|
144
144
|
<%- when Herb::Template::ElementSourceField -%>
|
|
145
145
|
<%= field.name %>: string;
|
|
146
|
+
<%- when Herb::Template::LocationField -%>
|
|
147
|
+
<%= field.name %>: SerializedLocation | null;
|
|
146
148
|
<%- when Herb::Template::NodeField -%>
|
|
147
149
|
<%- if field.specific_kind -%>
|
|
148
150
|
<%= field.name %>: Serialized<%= field.specific_kind %> | null;
|
|
@@ -170,6 +172,8 @@ export interface <%= node.name %>Props extends BaseNodeProps {
|
|
|
170
172
|
<%= field.name %>: boolean;
|
|
171
173
|
<%- when Herb::Template::ElementSourceField -%>
|
|
172
174
|
<%= field.name %>: string;
|
|
175
|
+
<%- when Herb::Template::LocationField -%>
|
|
176
|
+
<%= field.name %>: Location | null;
|
|
173
177
|
<%- when Herb::Template::NodeField -%>
|
|
174
178
|
<%- if field.specific_kind -%>
|
|
175
179
|
<%= field.name %>: <%= field.specific_kind %> | null;
|
|
@@ -201,6 +205,8 @@ export class <%= node.name %> extends Node {
|
|
|
201
205
|
readonly <%= field.name %>: boolean;
|
|
202
206
|
<%- when Herb::Template::ElementSourceField -%>
|
|
203
207
|
readonly <%= field.name %>: string;
|
|
208
|
+
<%- when Herb::Template::LocationField -%>
|
|
209
|
+
readonly <%= field.name %>: Location | null;
|
|
204
210
|
<%- when Herb::Template::NodeField -%>
|
|
205
211
|
<%- if field.specific_kind -%>
|
|
206
212
|
readonly <%= field.name %>: <%= field.specific_kind %> | null;
|
|
@@ -239,6 +245,8 @@ export class <%= node.name %> extends Node {
|
|
|
239
245
|
<%= field.name %>: data.<%= field.name %>,
|
|
240
246
|
<%- when Herb::Template::ElementSourceField -%>
|
|
241
247
|
<%= field.name %>: data.<%= field.name %>,
|
|
248
|
+
<%- when Herb::Template::LocationField -%>
|
|
249
|
+
<%= field.name %>: data.<%= field.name %> ? Location.from(data.<%= field.name %>) : null,
|
|
242
250
|
<%- when Herb::Template::NodeField -%>
|
|
243
251
|
<%= field.name %>: data.<%= field.name %> ? fromSerializedNode((data.<%= field.name %>)) : null,
|
|
244
252
|
<%- when Herb::Template::ArrayField -%>
|
|
@@ -268,6 +276,8 @@ export class <%= node.name %> extends Node {
|
|
|
268
276
|
this.<%= field.name %> = props.<%= field.name %>;
|
|
269
277
|
<%- when Herb::Template::ElementSourceField -%>
|
|
270
278
|
this.<%= field.name %> = props.<%= field.name %>;
|
|
279
|
+
<%- when Herb::Template::LocationField -%>
|
|
280
|
+
this.<%= field.name %> = props.<%= field.name %>;
|
|
271
281
|
<%- when Herb::Template::PrismNodeField, Herb::Template::AnalyzedRubyField -%>
|
|
272
282
|
// no-op for <%= field.name %>
|
|
273
283
|
<%- else -%>
|
|
@@ -325,6 +335,8 @@ export class <%= node.name %> extends Node {
|
|
|
325
335
|
<%= field.name %>: this.<%= field.name %>,
|
|
326
336
|
<%- when Herb::Template::ElementSourceField -%>
|
|
327
337
|
<%= field.name %>: this.<%= field.name %>,
|
|
338
|
+
<%- when Herb::Template::LocationField -%>
|
|
339
|
+
<%= field.name %>: this.<%= field.name %> ? this.<%= field.name %>.toJSON() : null,
|
|
328
340
|
<%- when Herb::Template::NodeField -%>
|
|
329
341
|
<%= field.name %>: this.<%= field.name %> ? this.<%= field.name %>.toJSON() : null,
|
|
330
342
|
<%- when Herb::Template::ArrayField -%>
|
|
@@ -355,6 +367,8 @@ export class <%= node.name %> extends Node {
|
|
|
355
367
|
output += `<%= name %>${typeof this.<%= field.name %> === 'boolean' ? String(this.<%= field.name %>) : "∅"}\n`;
|
|
356
368
|
<%- when Herb::Template::ElementSourceField -%>
|
|
357
369
|
output += `<%= name %>${this.<%= field.name %> ? JSON.stringify(this.<%= field.name %>) : "∅"}\n`;
|
|
370
|
+
<%- when Herb::Template::LocationField -%>
|
|
371
|
+
output += `<%= name %>${this.<%= field.name %> ? "(location: " + this.<%= field.name %>.treeInspect() + ")" : "∅"}\n`;
|
|
358
372
|
<%- when Herb::Template::NodeField -%>
|
|
359
373
|
output += `<%= name %>${this.inspectNode(this.<%= field.name %>, "<%= (node.fields.last == field) ? " " : "│ " %>")}`;
|
|
360
374
|
<%- when Herb::Template::ArrayField -%>
|
|
@@ -80,7 +80,7 @@ napi_value ErrorsArrayFromCArray(napi_env env, hb_array_T* array) {
|
|
|
80
80
|
napi_create_array(env, &result);
|
|
81
81
|
|
|
82
82
|
if (array) {
|
|
83
|
-
for (size_t i = 0; i < array
|
|
83
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
84
84
|
ERROR_T* error = (ERROR_T*) hb_array_get(array, i);
|
|
85
85
|
if (error) {
|
|
86
86
|
napi_value js_error = ErrorFromCStruct(env, error);
|
|
@@ -61,6 +61,15 @@ napi_value <%= node.human %>NodeFromCStruct(napi_env env, <%= node.struct_type %
|
|
|
61
61
|
napi_value <%= field.name %> = CreateStringFromHbString(env, element_source_to_string(<%= node.human %>-><%= field.name %>));
|
|
62
62
|
napi_set_named_property(env, result, "<%= field.name %>", <%= field.name %>);
|
|
63
63
|
|
|
64
|
+
<%- when Herb::Template::LocationField -%>
|
|
65
|
+
napi_value <%= field.name %>;
|
|
66
|
+
if (<%= node.human %>-><%= field.name %> != NULL) {
|
|
67
|
+
<%= field.name %> = CreateLocation(env, *<%= node.human %>-><%= field.name %>);
|
|
68
|
+
} else {
|
|
69
|
+
napi_get_null(env, &<%= field.name %>);
|
|
70
|
+
}
|
|
71
|
+
napi_set_named_property(env, result, "<%= field.name %>", <%= field.name %>);
|
|
72
|
+
|
|
64
73
|
<%- else -%>
|
|
65
74
|
napi_value <%= field.name %>;
|
|
66
75
|
napi_get_null(env, &<%= field.name %>);
|
|
@@ -78,7 +87,7 @@ napi_value NodesArrayFromCArray(napi_env env, hb_array_T* array) {
|
|
|
78
87
|
napi_create_array(env, &result);
|
|
79
88
|
|
|
80
89
|
if (array) {
|
|
81
|
-
for (size_t i = 0; i < array
|
|
90
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
82
91
|
AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
|
|
83
92
|
if (child_node) {
|
|
84
93
|
napi_value js_child = NodeFromCStruct(env, child_node);
|
|
@@ -85,6 +85,10 @@ module Herb
|
|
|
85
85
|
output += white("<%= symbol %> <%= field.name %>: ")
|
|
86
86
|
output += [true, false].include?(<%= field.name %>) ? bold(magenta(<%= field.name %>.to_s)) : magenta("∅")
|
|
87
87
|
output += "\n"
|
|
88
|
+
<%- when Herb::Template::LocationField -%>
|
|
89
|
+
output += white("<%= symbol %> <%= field.name %>: ")
|
|
90
|
+
output += <%= field.name %> ? dimmed("(location: #{<%= field.name %>.tree_inspect})") : magenta("∅")
|
|
91
|
+
output += "\n"
|
|
88
92
|
<%- when Herb::Template::ElementSourceField -%>
|
|
89
93
|
output += white("<%= symbol %> <%= field.name %>: #{green(<%= field.name %>.inspect)}\n")
|
|
90
94
|
<%- when Herb::Template::PrismNodeField -%>
|