@herb-tools/node 0.8.6 → 0.8.8
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/dist/herb-node.esm.js +1 -1
- package/extension/error_helpers.cpp +2 -2
- package/extension/error_helpers.h +1 -1
- package/extension/extension_helpers.cpp +1 -1
- package/extension/libherb/analyze.c +137 -42
- package/extension/libherb/analyze_helpers.c +80 -12
- package/extension/libherb/analyze_helpers.h +7 -0
- package/extension/libherb/analyze_missing_end.c +1 -1
- package/extension/libherb/analyze_transform.c +1 -1
- package/extension/libherb/analyzed_ruby.c +1 -0
- package/extension/libherb/analyzed_ruby.h +1 -0
- package/extension/libherb/ast_node.c +1 -1
- package/extension/libherb/ast_nodes.c +66 -162
- package/extension/libherb/ast_nodes.h +9 -5
- package/extension/libherb/ast_pretty_print.c +53 -1
- package/extension/libherb/ast_pretty_print.h +1 -1
- package/extension/libherb/errors.c +6 -6
- package/extension/libherb/errors.h +1 -1
- package/extension/libherb/extract.c +2 -2
- package/extension/libherb/herb.c +2 -2
- package/extension/libherb/include/analyze_helpers.h +7 -0
- package/extension/libherb/include/analyzed_ruby.h +1 -0
- package/extension/libherb/include/ast_nodes.h +9 -5
- package/extension/libherb/include/ast_pretty_print.h +1 -1
- package/extension/libherb/include/errors.h +1 -1
- package/extension/libherb/include/location.h +4 -0
- package/extension/libherb/include/prism_helpers.h +6 -0
- package/extension/libherb/include/util/hb_narray.h +1 -0
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/location.c +16 -0
- package/extension/libherb/location.h +4 -0
- package/extension/libherb/parser.c +9 -9
- package/extension/libherb/parser_helpers.c +4 -4
- package/extension/libherb/parser_match_tags.c +1 -1
- package/extension/libherb/pretty_print.c +6 -6
- package/extension/libherb/prism_helpers.c +188 -0
- package/extension/libherb/prism_helpers.h +6 -0
- package/extension/libherb/util/hb_array.c +1 -0
- package/extension/libherb/util/hb_narray.c +6 -0
- package/extension/libherb/util/hb_narray.h +1 -0
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +27 -27
- package/extension/nodes.cpp +34 -2
- package/extension/nodes.h +1 -1
- package/extension/prism/include/prism/version.h +2 -2
- package/extension/prism/src/prism.c +48 -27
- package/package.json +2 -2
|
@@ -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
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#ifndef HERB_PRISM_HELPERS_H
|
|
2
2
|
#define HERB_PRISM_HELPERS_H
|
|
3
3
|
|
|
4
|
+
#include "analyzed_ruby.h"
|
|
4
5
|
#include "ast_nodes.h"
|
|
5
6
|
#include "errors.h"
|
|
7
|
+
#include "location.h"
|
|
6
8
|
#include "position.h"
|
|
7
9
|
|
|
8
10
|
#include <prism.h>
|
|
@@ -22,4 +24,8 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error_with_positions(
|
|
|
22
24
|
position_T end
|
|
23
25
|
);
|
|
24
26
|
|
|
27
|
+
location_T* get_then_keyword_location(analyzed_ruby_T* analyzed, const char* source);
|
|
28
|
+
location_T* get_then_keyword_location_wrapped(const char* source, bool is_in_clause);
|
|
29
|
+
location_T* get_then_keyword_location_elsif_wrapped(const char* source);
|
|
30
|
+
|
|
25
31
|
#endif
|
|
@@ -18,6 +18,7 @@ void hb_narray_init(hb_narray_T* array, size_t item_size, size_t initial_capacit
|
|
|
18
18
|
void* hb_narray_get(const hb_narray_T* array, size_t index);
|
|
19
19
|
void* hb_narray_first(hb_narray_T* array);
|
|
20
20
|
void* hb_narray_last(hb_narray_T* array);
|
|
21
|
+
size_t hb_narray_size(const hb_narray_T* array);
|
|
21
22
|
|
|
22
23
|
void hb_narray_append(hb_narray_T* array, void* item);
|
|
23
24
|
void hb_narray_remove(hb_narray_T* array, size_t index);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.8/templates/src/visitor.c.erb
|
|
3
3
|
|
|
4
4
|
#include <stdio.h>
|
|
5
5
|
|
|
@@ -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
|
}
|
package/extension/nodes.cpp
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.8/templates/javascript/packages/node/extension/nodes.cpp.erb
|
|
3
3
|
|
|
4
4
|
#include <node_api.h>
|
|
5
5
|
#include "error_helpers.h"
|
|
@@ -581,6 +581,14 @@ napi_value erb_if_nodeNodeFromCStruct(napi_env env, AST_ERB_IF_NODE_T* erb_if_no
|
|
|
581
581
|
napi_value tag_closing = CreateToken(env, erb_if_node->tag_closing);
|
|
582
582
|
napi_set_named_property(env, result, "tag_closing", tag_closing);
|
|
583
583
|
|
|
584
|
+
napi_value then_keyword;
|
|
585
|
+
if (erb_if_node->then_keyword != NULL) {
|
|
586
|
+
then_keyword = CreateLocation(env, *erb_if_node->then_keyword);
|
|
587
|
+
} else {
|
|
588
|
+
napi_get_null(env, &then_keyword);
|
|
589
|
+
}
|
|
590
|
+
napi_set_named_property(env, result, "then_keyword", then_keyword);
|
|
591
|
+
|
|
584
592
|
napi_value statements = NodesArrayFromCArray(env, erb_if_node->statements);
|
|
585
593
|
napi_set_named_property(env, result, "statements", statements);
|
|
586
594
|
|
|
@@ -658,6 +666,14 @@ napi_value erb_when_nodeNodeFromCStruct(napi_env env, AST_ERB_WHEN_NODE_T* erb_w
|
|
|
658
666
|
napi_value tag_closing = CreateToken(env, erb_when_node->tag_closing);
|
|
659
667
|
napi_set_named_property(env, result, "tag_closing", tag_closing);
|
|
660
668
|
|
|
669
|
+
napi_value then_keyword;
|
|
670
|
+
if (erb_when_node->then_keyword != NULL) {
|
|
671
|
+
then_keyword = CreateLocation(env, *erb_when_node->then_keyword);
|
|
672
|
+
} else {
|
|
673
|
+
napi_get_null(env, &then_keyword);
|
|
674
|
+
}
|
|
675
|
+
napi_set_named_property(env, result, "then_keyword", then_keyword);
|
|
676
|
+
|
|
661
677
|
napi_value statements = NodesArrayFromCArray(env, erb_when_node->statements);
|
|
662
678
|
napi_set_named_property(env, result, "statements", statements);
|
|
663
679
|
|
|
@@ -1006,6 +1022,14 @@ napi_value erb_unless_nodeNodeFromCStruct(napi_env env, AST_ERB_UNLESS_NODE_T* e
|
|
|
1006
1022
|
napi_value tag_closing = CreateToken(env, erb_unless_node->tag_closing);
|
|
1007
1023
|
napi_set_named_property(env, result, "tag_closing", tag_closing);
|
|
1008
1024
|
|
|
1025
|
+
napi_value then_keyword;
|
|
1026
|
+
if (erb_unless_node->then_keyword != NULL) {
|
|
1027
|
+
then_keyword = CreateLocation(env, *erb_unless_node->then_keyword);
|
|
1028
|
+
} else {
|
|
1029
|
+
napi_get_null(env, &then_keyword);
|
|
1030
|
+
}
|
|
1031
|
+
napi_set_named_property(env, result, "then_keyword", then_keyword);
|
|
1032
|
+
|
|
1009
1033
|
napi_value statements = NodesArrayFromCArray(env, erb_unless_node->statements);
|
|
1010
1034
|
napi_set_named_property(env, result, "statements", statements);
|
|
1011
1035
|
|
|
@@ -1077,6 +1101,14 @@ napi_value erb_in_nodeNodeFromCStruct(napi_env env, AST_ERB_IN_NODE_T* erb_in_no
|
|
|
1077
1101
|
napi_value tag_closing = CreateToken(env, erb_in_node->tag_closing);
|
|
1078
1102
|
napi_set_named_property(env, result, "tag_closing", tag_closing);
|
|
1079
1103
|
|
|
1104
|
+
napi_value then_keyword;
|
|
1105
|
+
if (erb_in_node->then_keyword != NULL) {
|
|
1106
|
+
then_keyword = CreateLocation(env, *erb_in_node->then_keyword);
|
|
1107
|
+
} else {
|
|
1108
|
+
napi_get_null(env, &then_keyword);
|
|
1109
|
+
}
|
|
1110
|
+
napi_set_named_property(env, result, "then_keyword", then_keyword);
|
|
1111
|
+
|
|
1080
1112
|
napi_value statements = NodesArrayFromCArray(env, erb_in_node->statements);
|
|
1081
1113
|
napi_set_named_property(env, result, "statements", statements);
|
|
1082
1114
|
|
|
@@ -1089,7 +1121,7 @@ napi_value NodesArrayFromCArray(napi_env env, hb_array_T* array) {
|
|
|
1089
1121
|
napi_create_array(env, &result);
|
|
1090
1122
|
|
|
1091
1123
|
if (array) {
|
|
1092
|
-
for (size_t i = 0; i < array
|
|
1124
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
1093
1125
|
AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
|
|
1094
1126
|
if (child_node) {
|
|
1095
1127
|
napi_value js_child = NodeFromCStruct(env, child_node);
|
package/extension/nodes.h
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.8/templates/javascript/packages/node/extension/nodes.h.erb
|
|
3
3
|
|
|
4
4
|
#ifndef HERB_EXTENSION_NODES_H
|
|
5
5
|
#define HERB_EXTENSION_NODES_H
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
/**
|
|
15
15
|
* The minor version of the Prism library as an int.
|
|
16
16
|
*/
|
|
17
|
-
#define PRISM_VERSION_MINOR
|
|
17
|
+
#define PRISM_VERSION_MINOR 8
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* The patch version of the Prism library as an int.
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
/**
|
|
25
25
|
* The version of the Prism library as a constant string.
|
|
26
26
|
*/
|
|
27
|
-
#define PRISM_VERSION "1.
|
|
27
|
+
#define PRISM_VERSION "1.8.0"
|
|
28
28
|
|
|
29
29
|
#endif
|