herb 0.7.5 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +8 -5
- data/config.yml +26 -6
- data/ext/herb/error_helpers.c +57 -3
- data/ext/herb/error_helpers.h +1 -1
- data/ext/herb/extconf.rb +1 -0
- data/ext/herb/extension.c +10 -24
- data/ext/herb/extension_helpers.c +3 -3
- data/ext/herb/extension_helpers.h +1 -1
- data/ext/herb/nodes.c +72 -37
- data/herb.gemspec +0 -2
- data/lib/herb/ast/helpers.rb +11 -0
- data/lib/herb/ast/node.rb +15 -6
- data/lib/herb/ast/nodes.rb +609 -392
- data/lib/herb/cli.rb +31 -0
- data/lib/herb/colors.rb +82 -0
- data/lib/herb/engine/compiler.rb +140 -14
- data/lib/herb/engine/debug_visitor.rb +1 -5
- data/lib/herb/engine/parser_error_overlay.rb +1 -1
- data/lib/herb/engine.rb +8 -14
- data/lib/herb/errors.rb +166 -56
- data/lib/herb/location.rb +2 -2
- data/lib/herb/project.rb +86 -21
- data/lib/herb/token.rb +14 -2
- data/lib/herb/version.rb +1 -1
- data/lib/herb.rb +1 -0
- data/sig/herb/ast/helpers.rbs +3 -0
- data/sig/herb/ast/node.rbs +12 -5
- data/sig/herb/ast/nodes.rbs +124 -62
- data/sig/herb/colors.rbs +35 -0
- data/sig/herb/engine/compiler.rbs +23 -1
- data/sig/herb/errors.rbs +74 -20
- data/sig/herb/token.rbs +8 -0
- data/sig/herb_c_extension.rbs +1 -1
- data/sig/serialized_ast_errors.rbs +8 -0
- data/src/analyze.c +420 -171
- data/src/analyze_helpers.c +5 -0
- data/src/analyze_missing_end.c +147 -0
- data/src/analyze_transform.c +196 -0
- data/src/analyzed_ruby.c +23 -2
- data/src/ast_node.c +5 -5
- data/src/ast_nodes.c +179 -179
- data/src/ast_pretty_print.c +232 -232
- data/src/element_source.c +7 -6
- data/src/errors.c +246 -126
- data/src/extract.c +92 -34
- data/src/herb.c +37 -49
- data/src/html_util.c +34 -96
- data/src/include/analyze.h +10 -2
- data/src/include/analyze_helpers.h +3 -0
- data/src/include/analyzed_ruby.h +4 -2
- data/src/include/ast_node.h +2 -2
- data/src/include/ast_nodes.h +67 -66
- data/src/include/ast_pretty_print.h +2 -2
- data/src/include/element_source.h +3 -1
- data/src/include/errors.h +30 -14
- data/src/include/extract.h +4 -4
- data/src/include/herb.h +6 -7
- data/src/include/html_util.h +4 -5
- data/src/include/lexer.h +1 -3
- data/src/include/lexer_peek_helpers.h +14 -14
- data/src/include/lexer_struct.h +3 -2
- data/src/include/macros.h +4 -0
- data/src/include/parser.h +12 -6
- data/src/include/parser_helpers.h +25 -15
- data/src/include/pretty_print.h +38 -28
- data/src/include/token.h +5 -8
- data/src/include/utf8.h +3 -2
- data/src/include/util/hb_arena.h +31 -0
- data/src/include/util/hb_arena_debug.h +8 -0
- data/src/include/util/hb_array.h +33 -0
- data/src/include/util/hb_buffer.h +34 -0
- data/src/include/util/hb_string.h +29 -0
- data/src/include/util/hb_system.h +9 -0
- data/src/include/util.h +3 -14
- data/src/include/version.h +1 -1
- data/src/include/visitor.h +1 -1
- data/src/io.c +7 -4
- data/src/lexer.c +61 -88
- data/src/lexer_peek_helpers.c +35 -37
- data/src/main.c +19 -23
- data/src/parser.c +282 -201
- data/src/parser_helpers.c +46 -40
- data/src/parser_match_tags.c +316 -0
- data/src/pretty_print.c +82 -106
- data/src/token.c +18 -65
- data/src/utf8.c +4 -4
- data/src/util/hb_arena.c +179 -0
- data/src/util/hb_arena_debug.c +237 -0
- data/src/{array.c → util/hb_array.c} +26 -27
- data/src/util/hb_buffer.c +203 -0
- data/src/util/hb_string.c +85 -0
- data/src/util/hb_system.c +30 -0
- data/src/util.c +29 -99
- data/src/visitor.c +54 -54
- data/templates/ext/herb/error_helpers.c.erb +3 -3
- data/templates/ext/herb/error_helpers.h.erb +1 -1
- data/templates/ext/herb/nodes.c.erb +11 -6
- data/templates/java/error_helpers.c.erb +75 -0
- data/templates/java/error_helpers.h.erb +20 -0
- data/templates/java/nodes.c.erb +97 -0
- data/templates/java/nodes.h.erb +23 -0
- data/templates/java/org/herb/ast/Errors.java.erb +121 -0
- data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
- data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
- data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
- data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
- data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
- data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
- data/templates/lib/herb/ast/nodes.rb.erb +28 -16
- data/templates/lib/herb/errors.rb.erb +17 -12
- data/templates/rust/src/ast/nodes.rs.erb +220 -0
- data/templates/rust/src/errors.rs.erb +216 -0
- data/templates/rust/src/nodes.rs.erb +374 -0
- data/templates/src/analyze_missing_end.c.erb +36 -0
- data/templates/src/analyze_transform.c.erb +24 -0
- data/templates/src/ast_nodes.c.erb +14 -14
- data/templates/src/ast_pretty_print.c.erb +36 -36
- data/templates/src/errors.c.erb +31 -31
- data/templates/src/include/ast_nodes.h.erb +10 -9
- data/templates/src/include/ast_pretty_print.h.erb +2 -2
- data/templates/src/include/errors.h.erb +6 -6
- data/templates/src/parser_match_tags.c.erb +38 -0
- data/templates/src/visitor.c.erb +4 -4
- data/templates/template.rb +22 -3
- data/templates/wasm/error_helpers.cpp.erb +9 -9
- data/templates/wasm/error_helpers.h.erb +1 -1
- data/templates/wasm/nodes.cpp.erb +9 -9
- data/templates/wasm/nodes.h.erb +1 -1
- data/vendor/prism/Rakefile +4 -1
- data/vendor/prism/config.yml +2 -1
- data/vendor/prism/include/prism/ast.h +31 -1
- data/vendor/prism/include/prism/diagnostic.h +1 -0
- data/vendor/prism/include/prism/version.h +3 -3
- data/vendor/prism/src/diagnostic.c +3 -1
- data/vendor/prism/src/prism.c +130 -71
- data/vendor/prism/src/util/pm_string.c +6 -8
- data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
- data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
- data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
- data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
- data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
- data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
- metadata +34 -20
- data/lib/herb/libherb/array.rb +0 -51
- data/lib/herb/libherb/ast_node.rb +0 -50
- data/lib/herb/libherb/buffer.rb +0 -56
- data/lib/herb/libherb/extract_result.rb +0 -20
- data/lib/herb/libherb/lex_result.rb +0 -32
- data/lib/herb/libherb/libherb.rb +0 -52
- data/lib/herb/libherb/parse_result.rb +0 -20
- data/lib/herb/libherb/token.rb +0 -46
- data/lib/herb/libherb.rb +0 -35
- data/src/buffer.c +0 -241
- data/src/include/array.h +0 -33
- data/src/include/buffer.h +0 -39
- data/src/include/json.h +0 -28
- data/src/include/memory.h +0 -12
- data/src/json.c +0 -205
- data/src/memory.c +0 -53
data/src/visitor.c
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
#include <stdio.h>
|
|
5
5
|
|
|
6
|
-
#include "include/array.h"
|
|
7
|
-
#include "include/visitor.h"
|
|
8
6
|
#include "include/ast_node.h"
|
|
9
7
|
#include "include/ast_nodes.h"
|
|
8
|
+
#include "include/util/hb_array.h"
|
|
9
|
+
#include "include/visitor.h"
|
|
10
10
|
|
|
11
11
|
void herb_visit_node(const AST_NODE_T* node, bool (*visitor)(const AST_NODE_T*, void*), void* data) {
|
|
12
12
|
if (visitor(node, data) && node != NULL) {
|
|
@@ -24,8 +24,8 @@ 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 <
|
|
28
|
-
herb_visit_node(
|
|
27
|
+
for (size_t index = 0; index < hb_array_size(document_node->children); index++) {
|
|
28
|
+
herb_visit_node(hb_array_get(document_node->children, index), visitor, data);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -35,8 +35,8 @@ 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 <
|
|
39
|
-
herb_visit_node(
|
|
38
|
+
for (size_t index = 0; index < hb_array_size(html_open_tag_node->children); index++) {
|
|
39
|
+
herb_visit_node(hb_array_get(html_open_tag_node->children, index), visitor, data);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -46,8 +46,8 @@ 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 <
|
|
50
|
-
herb_visit_node(
|
|
49
|
+
for (size_t index = 0; index < hb_array_size(html_close_tag_node->children); index++) {
|
|
50
|
+
herb_visit_node(hb_array_get(html_close_tag_node->children, index), visitor, data);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -61,8 +61,8 @@ 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 <
|
|
65
|
-
herb_visit_node(
|
|
64
|
+
for (size_t index = 0; index < hb_array_size(html_element_node->body); index++) {
|
|
65
|
+
herb_visit_node(hb_array_get(html_element_node->body, index), visitor, data);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -76,8 +76,8 @@ 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 <
|
|
80
|
-
herb_visit_node(
|
|
79
|
+
for (size_t index = 0; index < hb_array_size(html_attribute_value_node->children); index++) {
|
|
80
|
+
herb_visit_node(hb_array_get(html_attribute_value_node->children, index), visitor, data);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -87,8 +87,8 @@ 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 <
|
|
91
|
-
herb_visit_node(
|
|
90
|
+
for (size_t index = 0; index < hb_array_size(html_attribute_name_node->children); index++) {
|
|
91
|
+
herb_visit_node(hb_array_get(html_attribute_name_node->children, index), visitor, data);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -111,8 +111,8 @@ 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 <
|
|
115
|
-
herb_visit_node(
|
|
114
|
+
for (size_t index = 0; index < hb_array_size(html_comment_node->children); index++) {
|
|
115
|
+
herb_visit_node(hb_array_get(html_comment_node->children, index), visitor, data);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -122,8 +122,8 @@ 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 <
|
|
126
|
-
herb_visit_node(
|
|
125
|
+
for (size_t index = 0; index < hb_array_size(html_doctype_node->children); index++) {
|
|
126
|
+
herb_visit_node(hb_array_get(html_doctype_node->children, index), visitor, data);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -133,8 +133,8 @@ 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 <
|
|
137
|
-
herb_visit_node(
|
|
136
|
+
for (size_t index = 0; index < hb_array_size(xml_declaration_node->children); index++) {
|
|
137
|
+
herb_visit_node(hb_array_get(xml_declaration_node->children, index), visitor, data);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -144,8 +144,8 @@ 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 <
|
|
148
|
-
herb_visit_node(
|
|
147
|
+
for (size_t index = 0; index < hb_array_size(cdata_node->children); index++) {
|
|
148
|
+
herb_visit_node(hb_array_get(cdata_node->children, index), visitor, data);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -155,8 +155,8 @@ 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 <
|
|
159
|
-
herb_visit_node(
|
|
158
|
+
for (size_t index = 0; index < hb_array_size(erb_else_node->statements); index++) {
|
|
159
|
+
herb_visit_node(hb_array_get(erb_else_node->statements, index), visitor, data);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -166,8 +166,8 @@ 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 <
|
|
170
|
-
herb_visit_node(
|
|
169
|
+
for (size_t index = 0; index < hb_array_size(erb_if_node->statements); index++) {
|
|
170
|
+
herb_visit_node(hb_array_get(erb_if_node->statements, index), visitor, data);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -185,8 +185,8 @@ 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 <
|
|
189
|
-
herb_visit_node(
|
|
188
|
+
for (size_t index = 0; index < hb_array_size(erb_block_node->body); index++) {
|
|
189
|
+
herb_visit_node(hb_array_get(erb_block_node->body, index), visitor, data);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
@@ -200,8 +200,8 @@ 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 <
|
|
204
|
-
herb_visit_node(
|
|
203
|
+
for (size_t index = 0; index < hb_array_size(erb_when_node->statements); index++) {
|
|
204
|
+
herb_visit_node(hb_array_get(erb_when_node->statements, index), visitor, data);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -211,14 +211,14 @@ 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 <
|
|
215
|
-
herb_visit_node(
|
|
214
|
+
for (size_t index = 0; index < hb_array_size(erb_case_node->children); index++) {
|
|
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 <
|
|
221
|
-
herb_visit_node(
|
|
220
|
+
for (size_t index = 0; index < hb_array_size(erb_case_node->conditions); index++) {
|
|
221
|
+
herb_visit_node(hb_array_get(erb_case_node->conditions, index), visitor, data);
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
@@ -236,14 +236,14 @@ 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 <
|
|
240
|
-
herb_visit_node(
|
|
239
|
+
for (size_t index = 0; index < hb_array_size(erb_case_match_node->children); index++) {
|
|
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 <
|
|
246
|
-
herb_visit_node(
|
|
245
|
+
for (size_t index = 0; index < hb_array_size(erb_case_match_node->conditions); index++) {
|
|
246
|
+
herb_visit_node(hb_array_get(erb_case_match_node->conditions, index), visitor, data);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
@@ -261,8 +261,8 @@ 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 <
|
|
265
|
-
herb_visit_node(
|
|
264
|
+
for (size_t index = 0; index < hb_array_size(erb_while_node->statements); index++) {
|
|
265
|
+
herb_visit_node(hb_array_get(erb_while_node->statements, index), visitor, data);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
@@ -276,8 +276,8 @@ 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 <
|
|
280
|
-
herb_visit_node(
|
|
279
|
+
for (size_t index = 0; index < hb_array_size(erb_until_node->statements); index++) {
|
|
280
|
+
herb_visit_node(hb_array_get(erb_until_node->statements, index), visitor, data);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
|
|
@@ -291,8 +291,8 @@ 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 <
|
|
295
|
-
herb_visit_node(
|
|
294
|
+
for (size_t index = 0; index < hb_array_size(erb_for_node->statements); index++) {
|
|
295
|
+
herb_visit_node(hb_array_get(erb_for_node->statements, index), visitor, data);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
|
|
@@ -306,8 +306,8 @@ 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 <
|
|
310
|
-
herb_visit_node(
|
|
309
|
+
for (size_t index = 0; index < hb_array_size(erb_rescue_node->statements); index++) {
|
|
310
|
+
herb_visit_node(hb_array_get(erb_rescue_node->statements, index), visitor, data);
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
|
|
@@ -321,8 +321,8 @@ 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 <
|
|
325
|
-
herb_visit_node(
|
|
324
|
+
for (size_t index = 0; index < hb_array_size(erb_ensure_node->statements); index++) {
|
|
325
|
+
herb_visit_node(hb_array_get(erb_ensure_node->statements, index), visitor, data);
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -332,8 +332,8 @@ 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 <
|
|
336
|
-
herb_visit_node(
|
|
335
|
+
for (size_t index = 0; index < hb_array_size(erb_begin_node->statements); index++) {
|
|
336
|
+
herb_visit_node(hb_array_get(erb_begin_node->statements, index), visitor, data);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
|
|
@@ -359,8 +359,8 @@ 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 <
|
|
363
|
-
herb_visit_node(
|
|
362
|
+
for (size_t index = 0; index < hb_array_size(erb_unless_node->statements); index++) {
|
|
363
|
+
herb_visit_node(hb_array_get(erb_unless_node->statements, index), visitor, data);
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
|
|
@@ -378,8 +378,8 @@ 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 <
|
|
382
|
-
herb_visit_node(
|
|
381
|
+
for (size_t index = 0; index < hb_array_size(erb_in_node->statements); index++) {
|
|
382
|
+
herb_visit_node(hb_array_get(erb_in_node->statements, index), visitor, data);
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
385
|
|
|
@@ -67,12 +67,12 @@ VALUE rb_error_from_c_struct(ERROR_T* error) {
|
|
|
67
67
|
return Qnil;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
VALUE rb_errors_array_from_c_array(
|
|
70
|
+
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 <
|
|
75
|
-
ERROR_T* child_node = (ERROR_T*)
|
|
74
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
75
|
+
ERROR_T* child_node = (ERROR_T*) hb_array_get(array, i);
|
|
76
76
|
|
|
77
77
|
if (child_node) {
|
|
78
78
|
VALUE rb_child = rb_error_from_c_struct(child_node);
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#include "../../src/include/token.h"
|
|
10
10
|
|
|
11
11
|
VALUE rb_node_from_c_struct(AST_NODE_T* node);
|
|
12
|
-
static VALUE rb_nodes_array_from_c_array(
|
|
12
|
+
static VALUE rb_nodes_array_from_c_array(hb_array_T* array);
|
|
13
13
|
|
|
14
14
|
<%- nodes.each do |node| -%>
|
|
15
15
|
static VALUE rb_<%= node.human %>_from_c_struct(<%= node.struct_type %>* <%= node.human %>) {
|
|
@@ -22,7 +22,8 @@ static VALUE rb_<%= node.human %>_from_c_struct(<%= node.struct_type %>* <%= nod
|
|
|
22
22
|
VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
|
|
23
23
|
VALUE <%= node.name %> = rb_define_class_under(AST, "<%= node.name %>", Node);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
hb_string_T node_type = ast_node_type_to_string(node);
|
|
26
|
+
VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
|
|
26
27
|
VALUE location = rb_location_from_c_struct(node->location);
|
|
27
28
|
VALUE errors = rb_errors_array_from_c_array(node->errors);
|
|
28
29
|
|
|
@@ -39,7 +40,11 @@ static VALUE rb_<%= node.human %>_from_c_struct(<%= node.struct_type %>* <%= nod
|
|
|
39
40
|
<%- when Herb::Template::ArrayField -%>
|
|
40
41
|
VALUE <%= node.human %>_<%= field.name %> = rb_nodes_array_from_c_array(<%= node.human %>-><%= field.name %>);
|
|
41
42
|
<%- when Herb::Template::ElementSourceField -%>
|
|
42
|
-
VALUE <%= node.human %>_<%= field.name
|
|
43
|
+
VALUE <%= node.human %>_<%= field.name %>;
|
|
44
|
+
{
|
|
45
|
+
hb_string_T element_source_string = element_source_to_string(<%= node.human %>-><%= field.name %>);
|
|
46
|
+
<%= node.human %>_<%= field.name %> = rb_utf8_str_new(element_source_string.data, element_source_string.length);
|
|
47
|
+
}
|
|
43
48
|
<%- else -%>
|
|
44
49
|
/* <%= field.inspect %> */
|
|
45
50
|
VALUE <%= node.human %>_<%= field.name %> = Qnil;
|
|
@@ -72,12 +77,12 @@ VALUE rb_node_from_c_struct(AST_NODE_T* node) {
|
|
|
72
77
|
return Qnil;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
static VALUE rb_nodes_array_from_c_array(
|
|
80
|
+
static VALUE rb_nodes_array_from_c_array(hb_array_T* array) {
|
|
76
81
|
VALUE rb_array = rb_ary_new();
|
|
77
82
|
|
|
78
83
|
if (array) {
|
|
79
|
-
for (size_t i = 0; i <
|
|
80
|
-
AST_NODE_T* child_node = (AST_NODE_T*)
|
|
84
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
85
|
+
AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
|
|
81
86
|
|
|
82
87
|
if (child_node) {
|
|
83
88
|
VALUE rb_child = rb_node_from_c_struct(child_node);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#include "error_helpers.h"
|
|
2
|
+
#include "extension_helpers.h"
|
|
3
|
+
|
|
4
|
+
#include "../../src/include/ast_node.h"
|
|
5
|
+
#include "../../src/include/errors.h"
|
|
6
|
+
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
|
|
9
|
+
<%- errors.each do |error| -%>
|
|
10
|
+
jobject <%= error.name %>FromCStruct(JNIEnv* env, <%= error.struct_type %>* <%= error.human %>) {
|
|
11
|
+
if (!<%= error.human %>) { return NULL; }
|
|
12
|
+
|
|
13
|
+
jclass errorClass = (*env)->FindClass(env, "org/herb/ast/ErrorNode");
|
|
14
|
+
if (!errorClass) { return NULL; }
|
|
15
|
+
|
|
16
|
+
jmethodID constructor = (*env)->GetMethodID(env, errorClass, "<init>", "(Ljava/lang/String;Lorg/herb/Location;Ljava/lang/String;)V");
|
|
17
|
+
if (!constructor) { return NULL; }
|
|
18
|
+
|
|
19
|
+
jstring jtype = (*env)->NewStringUTF(env, "<%= error.name %>");
|
|
20
|
+
jobject location = CreateLocation(env, <%= error.human %>->base.location);
|
|
21
|
+
jstring jmessage = (*env)->NewStringUTF(env, <%= error.human %>->base.message);
|
|
22
|
+
|
|
23
|
+
return (*env)->NewObject(env, errorClass, constructor, jtype, location, jmessage);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
<%- end -%>
|
|
27
|
+
|
|
28
|
+
jobject ErrorFromCStruct(JNIEnv* env, ERROR_T* error) {
|
|
29
|
+
if (!error) { return NULL; }
|
|
30
|
+
|
|
31
|
+
switch (error->type) {
|
|
32
|
+
<%- errors.each do |error| -%>
|
|
33
|
+
case <%= error.type %>:
|
|
34
|
+
return <%= error.name %>FromCStruct(env, (<%= error.struct_type %>*) error);
|
|
35
|
+
<%- end -%>
|
|
36
|
+
default:
|
|
37
|
+
return NULL;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
jobject ErrorsArrayFromCArray(JNIEnv* env, hb_array_T* array) {
|
|
42
|
+
jclass arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
|
|
43
|
+
jmethodID arrayListConstructor = (*env)->GetMethodID(env, arrayListClass, "<init>", "(I)V");
|
|
44
|
+
jmethodID addMethod = (*env)->GetMethodID(env, arrayListClass, "add", "(Ljava/lang/Object;)Z");
|
|
45
|
+
|
|
46
|
+
jobject javaList = (*env)->NewObject(env, arrayListClass, arrayListConstructor, 0);
|
|
47
|
+
|
|
48
|
+
if (array) {
|
|
49
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
50
|
+
ERROR_T* error = (ERROR_T*) hb_array_get(array, i);
|
|
51
|
+
|
|
52
|
+
if (error) {
|
|
53
|
+
jobject errorObj = ErrorFromCStruct(env, error);
|
|
54
|
+
if (errorObj) {
|
|
55
|
+
(*env)->CallBooleanMethod(env, javaList, addMethod, errorObj);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return javaList;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
jobject CreateErrorNode(JNIEnv* env, AST_NODE_T* error_node) {
|
|
65
|
+
if (!error_node) { return NULL; }
|
|
66
|
+
|
|
67
|
+
switch (error_node->type) {
|
|
68
|
+
<%- errors.each do |error| -%>
|
|
69
|
+
case <%= error.type %>:
|
|
70
|
+
return <%= error.name %>FromCStruct(env, (<%= error.struct_type %>*) error_node);
|
|
71
|
+
<%- end -%>
|
|
72
|
+
default:
|
|
73
|
+
return NULL;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#ifndef HERB_JNI_ERROR_HELPERS_H
|
|
2
|
+
#define HERB_JNI_ERROR_HELPERS_H
|
|
3
|
+
|
|
4
|
+
#include <jni.h>
|
|
5
|
+
|
|
6
|
+
#include "../../src/include/ast_node.h"
|
|
7
|
+
#include "../../src/include/util/hb_array.h"
|
|
8
|
+
|
|
9
|
+
#ifdef __cplusplus
|
|
10
|
+
extern "C" {
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
jobject CreateErrorNode(JNIEnv* env, AST_NODE_T* error_node);
|
|
14
|
+
jobject ErrorsArrayFromCArray(JNIEnv* env, hb_array_T* array);
|
|
15
|
+
|
|
16
|
+
#ifdef __cplusplus
|
|
17
|
+
}
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#endif
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#include "nodes.h"
|
|
2
|
+
#include "extension_helpers.h"
|
|
3
|
+
#include "error_helpers.h"
|
|
4
|
+
|
|
5
|
+
#include "../../src/include/ast_node.h"
|
|
6
|
+
#include "../../src/include/ast_nodes.h"
|
|
7
|
+
#include "../../src/include/location.h"
|
|
8
|
+
#include "../../src/include/util/hb_array.h"
|
|
9
|
+
|
|
10
|
+
#include <stdlib.h>
|
|
11
|
+
|
|
12
|
+
jobject NodeFromCStruct(JNIEnv* env, AST_NODE_T* node);
|
|
13
|
+
jobject NodesArrayFromCArray(JNIEnv* env, hb_array_T* array);
|
|
14
|
+
|
|
15
|
+
<%- nodes.each do |node| -%>
|
|
16
|
+
jobject <%= node.name %>FromCStruct(JNIEnv* env, <%= node.struct_type %>* <%= node.human %>) {
|
|
17
|
+
if (!<%= node.human %>) { return NULL; }
|
|
18
|
+
|
|
19
|
+
jclass nodeClass = (*env)->FindClass(env, "org/herb/ast/<%= node.name %>");
|
|
20
|
+
if (!nodeClass) { return NULL; }
|
|
21
|
+
|
|
22
|
+
jstring type = (*env)->NewStringUTF(env, "<%= node.name %>");
|
|
23
|
+
jobject location = CreateLocation(env, <%= node.human %>->base.location);
|
|
24
|
+
jobject errors = ErrorsArrayFromCArray(env, <%= node.human %>->base.errors);
|
|
25
|
+
|
|
26
|
+
<%- node.fields.each do |field| -%>
|
|
27
|
+
<%- if field.is_a?(Herb::Template::StringField) -%>
|
|
28
|
+
jstring <%= field.name %> = (*env)->NewStringUTF(env, <%= node.human %>-><%= field.name %>);
|
|
29
|
+
<%- elsif field.is_a?(Herb::Template::TokenField) -%>
|
|
30
|
+
jobject <%= field.name %> = <%= node.human %>-><%= field.name %> ? CreateToken(env, <%= node.human %>-><%= field.name %>) : NULL;
|
|
31
|
+
<%- elsif field.is_a?(Herb::Template::BooleanField) -%>
|
|
32
|
+
jboolean <%= field.name %> = <%= node.human %>-><%= field.name %> ? JNI_TRUE : JNI_FALSE;
|
|
33
|
+
<%- elsif field.is_a?(Herb::Template::ArrayField) -%>
|
|
34
|
+
jobject <%= field.name %> = NodesArrayFromCArray(env, <%= node.human %>-><%= field.name %>);
|
|
35
|
+
<%- elsif field.is_a?(Herb::Template::NodeField) -%>
|
|
36
|
+
jobject <%= field.name %> = <%= node.human %>-><%= field.name %> ? NodeFromCStruct(env, (AST_NODE_T*) <%= node.human %>-><%= field.name %>) : NULL;
|
|
37
|
+
<%- elsif field.is_a?(Herb::Template::ElementSourceField) -%>
|
|
38
|
+
// TODO: Convert element_source to string
|
|
39
|
+
jstring <%= field.name %> = (*env)->NewStringUTF(env, "");
|
|
40
|
+
<%- elsif field.is_a?(Herb::Template::AnalyzedRubyField) || field.is_a?(Herb::Template::PrismNodeField) -%>
|
|
41
|
+
// Skip <%= field.name %> (<%= field.class.name.split('::').last %>) - not supported in Java yet
|
|
42
|
+
<%- end -%>
|
|
43
|
+
<%- end -%>
|
|
44
|
+
|
|
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";
|
|
46
|
+
jmethodID constructor = (*env)->GetMethodID(env, nodeClass, "<init>", signature);
|
|
47
|
+
if (!constructor) { return NULL; }
|
|
48
|
+
|
|
49
|
+
jobject result = (*env)->NewObject(env, nodeClass, constructor, type, location, errors<%- node.fields.each do |field| -%><%- unless field.is_a?(Herb::Template::AnalyzedRubyField) || field.is_a?(Herb::Template::PrismNodeField) -%>, <%= field.name %><%- end -%><%- end -%>);
|
|
50
|
+
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
<%- end -%>
|
|
55
|
+
|
|
56
|
+
jobject NodeFromCStruct(JNIEnv* env, AST_NODE_T* node) {
|
|
57
|
+
if (!node) { return NULL; }
|
|
58
|
+
|
|
59
|
+
switch (node->type) {
|
|
60
|
+
<%- nodes.each do |node| -%>
|
|
61
|
+
case <%= node.type %>:
|
|
62
|
+
return <%= node.name %>FromCStruct(env, (<%= node.struct_type %>*) node);
|
|
63
|
+
<%- end -%>
|
|
64
|
+
default:
|
|
65
|
+
return NULL;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
jobject NodesArrayFromCArray(JNIEnv* env, hb_array_T* array) {
|
|
70
|
+
jclass arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
|
|
71
|
+
jmethodID arrayListConstructor = (*env)->GetMethodID(env, arrayListClass, "<init>", "(I)V");
|
|
72
|
+
jmethodID addMethod = (*env)->GetMethodID(env, arrayListClass, "add", "(Ljava/lang/Object;)Z");
|
|
73
|
+
|
|
74
|
+
if (!array) {
|
|
75
|
+
return (*env)->NewObject(env, arrayListClass, arrayListConstructor, 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
jobject javaList = (*env)->NewObject(env, arrayListClass, arrayListConstructor, (jint) hb_array_size(array));
|
|
79
|
+
|
|
80
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
81
|
+
AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
|
|
82
|
+
|
|
83
|
+
if (child_node) {
|
|
84
|
+
jobject nodeObj = NodeFromCStruct(env, child_node);
|
|
85
|
+
(*env)->CallBooleanMethod(env, javaList, addMethod, nodeObj);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return javaList;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
<%- nodes.each do |node| -%>
|
|
93
|
+
jobject Create<%= node.name %>(JNIEnv* env, <%= node.struct_type %>* <%= node.human %>) {
|
|
94
|
+
return <%= node.name %>FromCStruct(env, <%= node.human %>);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
<%- end -%>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#ifndef HERB_JNI_NODES_H
|
|
2
|
+
#define HERB_JNI_NODES_H
|
|
3
|
+
|
|
4
|
+
#include <jni.h>
|
|
5
|
+
|
|
6
|
+
#include "../../src/include/ast_nodes.h"
|
|
7
|
+
|
|
8
|
+
#ifdef __cplusplus
|
|
9
|
+
extern "C" {
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
<%- nodes.each do |node| -%>
|
|
13
|
+
jobject Create<%= node.name %>(JNIEnv* env, <%= node.struct_type %>* node);
|
|
14
|
+
<%- end -%>
|
|
15
|
+
|
|
16
|
+
jobject CreateErrorNode(JNIEnv* env, AST_NODE_T* error_node);
|
|
17
|
+
jobject CreateASTNode(JNIEnv* env, AST_NODE_T* node);
|
|
18
|
+
|
|
19
|
+
#ifdef __cplusplus
|
|
20
|
+
}
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
#endif
|