herb 0.7.4-aarch64-linux-gnu → 0.8.0-aarch64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +8 -5
- data/config.yml +40 -20
- 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 +12 -18
- data/ext/herb/extension_helpers.h +4 -4
- data/ext/herb/nodes.c +72 -37
- data/herb.gemspec +0 -2
- data/lib/herb/3.0/herb.so +0 -0
- data/lib/herb/3.1/herb.so +0 -0
- data/lib/herb/3.2/herb.so +0 -0
- data/lib/herb/3.3/herb.so +0 -0
- data/lib/herb/3.4/herb.so +0 -0
- data/lib/herb/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 +18 -20
- 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 +461 -249
- 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 +14 -17
- data/src/ast_nodes.c +179 -181
- data/src/ast_pretty_print.c +232 -232
- data/src/element_source.c +7 -6
- data/src/errors.c +272 -152
- 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 +4 -4
- data/src/include/ast_nodes.h +68 -67
- data/src/include/ast_pretty_print.h +2 -2
- data/src/include/element_source.h +3 -1
- data/src/include/errors.h +42 -26
- 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 +21 -19
- data/src/include/lexer_struct.h +12 -10
- data/src/include/location.h +10 -13
- data/src/include/macros.h +4 -0
- data/src/include/parser.h +12 -6
- data/src/include/parser_helpers.h +26 -16
- data/src/include/position.h +3 -14
- data/src/include/pretty_print.h +38 -28
- data/src/include/prism_helpers.h +1 -1
- data/src/include/range.h +4 -13
- data/src/include/token.h +5 -11
- data/src/include/token_struct.h +2 -2
- 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 +62 -88
- data/src/lexer_peek_helpers.c +42 -38
- data/src/location.c +9 -37
- data/src/main.c +19 -23
- data/src/parser.c +373 -313
- data/src/parser_helpers.c +60 -54
- data/src/parser_match_tags.c +316 -0
- data/src/pretty_print.c +88 -117
- data/src/prism_helpers.c +7 -7
- data/src/range.c +2 -35
- data/src/token.c +36 -87
- 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/core/src/visitor.ts.erb +29 -1
- 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 -16
- data/templates/src/ast_pretty_print.c.erb +36 -36
- data/templates/src/errors.c.erb +36 -38
- data/templates/src/include/ast_nodes.h.erb +11 -10
- data/templates/src/include/ast_pretty_print.h.erb +2 -2
- data/templates/src/include/errors.h.erb +9 -9
- 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 -21
- 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 -232
- 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/position.c +0 -33
data/templates/src/errors.c.erb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#include "include/array.h"
|
|
2
1
|
#include "include/errors.h"
|
|
3
2
|
#include "include/location.h"
|
|
4
3
|
#include "include/position.h"
|
|
5
4
|
#include "include/pretty_print.h"
|
|
6
5
|
#include "include/token.h"
|
|
7
6
|
#include "include/util.h"
|
|
7
|
+
#include "include/util/hb_array.h"
|
|
8
8
|
|
|
9
9
|
#include <stdio.h>
|
|
10
10
|
#include <stdbool.h>
|
|
@@ -17,15 +17,16 @@ size_t error_sizeof(void) {
|
|
|
17
17
|
return sizeof(struct ERROR_STRUCT);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
void error_init(ERROR_T* error, const error_type_T type, position_T
|
|
20
|
+
void error_init(ERROR_T* error, const error_type_T type, position_T start, position_T end) {
|
|
21
21
|
if (!error) { return; }
|
|
22
22
|
|
|
23
23
|
error->type = type;
|
|
24
|
-
error->location =
|
|
24
|
+
error->location.start = start;
|
|
25
|
+
error->location.end = end;
|
|
25
26
|
}
|
|
26
27
|
<%- errors.each do |error| -%>
|
|
27
28
|
<%- error_arguments = error.fields.any? ? error.fields.map { |field| [field.c_type, " ", field.name].join } : [] -%>
|
|
28
|
-
<%- arguments = error_arguments + ["position_T
|
|
29
|
+
<%- arguments = error_arguments + ["position_T start", "position_T end"] -%>
|
|
29
30
|
|
|
30
31
|
<%= error.struct_type %>* <%= error.human %>_init(<%= arguments.join(", ") %>) {
|
|
31
32
|
<%= error.struct_type %>* <%= error.human %> = malloc(sizeof(<%= error.struct_type %>));
|
|
@@ -72,7 +73,7 @@ void error_init(ERROR_T* error, const error_type_T type, position_T* start, posi
|
|
|
72
73
|
<%- error.fields.each do |field| -%>
|
|
73
74
|
<%- case field -%>
|
|
74
75
|
<%- when Herb::Template::PositionField -%>
|
|
75
|
-
<%= error.human %>-><%= field.name %> =
|
|
76
|
+
<%= error.human %>-><%= field.name %> = <%= field.name %>;
|
|
76
77
|
<%- when Herb::Template::TokenField -%>
|
|
77
78
|
<%= error.human %>-><%= field.name %> = token_copy(<%= field.name %>);
|
|
78
79
|
<%- when Herb::Template::TokenTypeField -%>
|
|
@@ -88,8 +89,8 @@ void error_init(ERROR_T* error, const error_type_T type, position_T* start, posi
|
|
|
88
89
|
return <%= error.human %>;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
void append_<%= error.human %>(<%= (arguments + ["
|
|
92
|
-
|
|
92
|
+
void append_<%= error.human %>(<%= (arguments + ["hb_array_T* errors"]).join(", ") %>) {
|
|
93
|
+
hb_array_append(errors, <%= error.human %>_init(<%= arguments.map { |argument| argument.split(" ").last.strip }.join(", ") %>));
|
|
93
94
|
}
|
|
94
95
|
<%- end -%>
|
|
95
96
|
|
|
@@ -116,7 +117,6 @@ const char* error_human_type(ERROR_T* error) {
|
|
|
116
117
|
void error_free_base_error(ERROR_T* error) {
|
|
117
118
|
if (error == NULL) { return; }
|
|
118
119
|
|
|
119
|
-
if (error->location != NULL) { location_free(error->location); }
|
|
120
120
|
if (error->message != NULL) { free(error->message); }
|
|
121
121
|
|
|
122
122
|
free(error);
|
|
@@ -130,8 +130,6 @@ static void error_free_<%= error.human %>(<%= error.struct_type %>* <%= error.hu
|
|
|
130
130
|
<%- end -%>
|
|
131
131
|
<%- error.fields.each do |field| -%>
|
|
132
132
|
<%- case field -%>
|
|
133
|
-
<%- when Herb::Template::PositionField -%>
|
|
134
|
-
if (<%= error.human %>-><%= field.name %> != NULL) { position_free(<%= error.human %>-><%= field.name %>); }
|
|
135
133
|
<%- when Herb::Template::TokenField -%>
|
|
136
134
|
if (<%= error.human %>-><%= field.name %> != NULL) { token_free(<%= error.human %>-><%= field.name %>); }
|
|
137
135
|
<%- when Herb::Template::TokenTypeField -%>
|
|
@@ -160,73 +158,73 @@ void error_free(ERROR_T* error) {
|
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
void error_pretty_print_array(
|
|
163
|
-
const char* name,
|
|
164
|
-
|
|
161
|
+
const char* name, hb_array_T* array, const size_t indent, const size_t relative_indent, const bool last_property,
|
|
162
|
+
hb_buffer_T* buffer
|
|
165
163
|
) {
|
|
166
164
|
if (array == NULL) {
|
|
167
|
-
pretty_print_property(name, "∅", indent, relative_indent, last_property, buffer);
|
|
165
|
+
pretty_print_property(hb_string(name), hb_string("∅"), indent, relative_indent, last_property, buffer);
|
|
168
166
|
|
|
169
167
|
return;
|
|
170
168
|
}
|
|
171
169
|
|
|
172
|
-
if (
|
|
173
|
-
pretty_print_property(name, "[]", indent, relative_indent, last_property, buffer);
|
|
170
|
+
if (hb_array_size(array) == 0) {
|
|
171
|
+
pretty_print_property(hb_string(name), hb_string("[]"), indent, relative_indent, last_property, buffer);
|
|
174
172
|
|
|
175
173
|
return;
|
|
176
174
|
}
|
|
177
175
|
|
|
178
|
-
pretty_print_label(name, indent, relative_indent, last_property, buffer);
|
|
176
|
+
pretty_print_label(hb_string(name), indent, relative_indent, last_property, buffer);
|
|
179
177
|
|
|
180
|
-
|
|
178
|
+
hb_buffer_append(buffer, "(");
|
|
181
179
|
|
|
182
180
|
char count[16];
|
|
183
|
-
sprintf(count, "%zu",
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
sprintf(count, "%zu", hb_array_size(array));
|
|
182
|
+
hb_buffer_append(buffer, count);
|
|
183
|
+
hb_buffer_append(buffer, ")\n");
|
|
186
184
|
|
|
187
185
|
if (indent < 20) {
|
|
188
|
-
for (size_t i = 0; i <
|
|
189
|
-
ERROR_T* child =
|
|
186
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
187
|
+
ERROR_T* child = hb_array_get(array, i);
|
|
190
188
|
pretty_print_indent(buffer, indent);
|
|
191
189
|
pretty_print_indent(buffer, relative_indent + 1);
|
|
192
190
|
|
|
193
|
-
if (i ==
|
|
194
|
-
|
|
191
|
+
if (i == hb_array_size(array) - 1) {
|
|
192
|
+
hb_buffer_append(buffer, "└── ");
|
|
195
193
|
} else {
|
|
196
|
-
|
|
194
|
+
hb_buffer_append(buffer, "├── ");
|
|
197
195
|
}
|
|
198
196
|
|
|
199
197
|
error_pretty_print(child, indent + 1, relative_indent + 1, buffer);
|
|
200
198
|
|
|
201
|
-
if (i !=
|
|
199
|
+
if (i != hb_array_size(array) - 1) { pretty_print_newline(indent + 1, relative_indent, buffer); }
|
|
202
200
|
}
|
|
203
201
|
}
|
|
204
202
|
}
|
|
205
203
|
|
|
206
204
|
<%- errors.each do |error| -%>
|
|
207
|
-
static void error_pretty_print_<%= error.human %>(<%= error.struct_type %>* error, const size_t indent, const size_t relative_indent,
|
|
205
|
+
static void error_pretty_print_<%= error.human %>(<%= error.struct_type %>* error, const size_t indent, const size_t relative_indent, hb_buffer_T* buffer) {
|
|
208
206
|
if (!error) { return; }
|
|
209
207
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
208
|
+
hb_buffer_append(buffer, "@ ");
|
|
209
|
+
hb_buffer_append(buffer, error_human_type((ERROR_T*) error));
|
|
210
|
+
hb_buffer_append(buffer, " ");
|
|
213
211
|
|
|
214
212
|
pretty_print_location(error->base.location, buffer);
|
|
215
|
-
|
|
213
|
+
hb_buffer_append(buffer, "\n");
|
|
216
214
|
|
|
217
|
-
pretty_print_quoted_property("message", error->base.message, indent, relative_indent, <%= error.fields.none? %>, buffer);
|
|
215
|
+
pretty_print_quoted_property(hb_string("message"), hb_string(error->base.message), indent, relative_indent, <%= error.fields.none? %>, buffer);
|
|
218
216
|
<%- error.fields.each_with_index do |field, index| -%>
|
|
219
217
|
<%- case field -%>
|
|
220
218
|
<%- when Herb::Template::PositionField -%>
|
|
221
|
-
pretty_print_position_property(error-><%= field.name
|
|
219
|
+
pretty_print_position_property(hb_string(error-><%= field.name %>), hb_string("<%= field.name %>"), indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
|
|
222
220
|
<%- when Herb::Template::TokenField -%>
|
|
223
|
-
pretty_print_token_property(error-><%= field.name %>, "<%= field.name %>", indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
|
|
221
|
+
pretty_print_token_property(error-><%= field.name %>, hb_string("<%= field.name %>"), indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
|
|
224
222
|
<%- when Herb::Template::TokenTypeField -%>
|
|
225
|
-
pretty_print_property(token_type_to_string(error-><%= field.name %>), "<%= field.name %>", indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
|
|
223
|
+
pretty_print_property(hb_string(token_type_to_string(error-><%= field.name %>)), hb_string("<%= field.name %>"), indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
|
|
226
224
|
<%- when Herb::Template::SizeTField -%>
|
|
227
|
-
pretty_print_size_t_property(error-><%= field.name
|
|
225
|
+
pretty_print_size_t_property(hb_string(error-><%= field.name %>), hb_string("<%= field.name %>"), indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
|
|
228
226
|
<%- when Herb::Template::StringField -%>
|
|
229
|
-
pretty_print_quoted_property("<%= field.name %>", error-><%= field.name
|
|
227
|
+
pretty_print_quoted_property(hb_string("<%= field.name %>"), hb_string(error-><%= field.name %>), indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
|
|
230
228
|
<%- else -%>
|
|
231
229
|
<%= field.inspect %>
|
|
232
230
|
<%- end -%>
|
|
@@ -234,7 +232,7 @@ static void error_pretty_print_<%= error.human %>(<%= error.struct_type %>* erro
|
|
|
234
232
|
}
|
|
235
233
|
|
|
236
234
|
<%- end -%>
|
|
237
|
-
void error_pretty_print(ERROR_T* error, const size_t indent, const size_t relative_indent,
|
|
235
|
+
void error_pretty_print(ERROR_T* error, const size_t indent, const size_t relative_indent, hb_buffer_T* buffer) {
|
|
238
236
|
if (!error) { return; }
|
|
239
237
|
|
|
240
238
|
switch (error->type) {
|
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
#include <stdbool.h>
|
|
5
5
|
#include <prism.h>
|
|
6
6
|
|
|
7
|
-
#include "array.h"
|
|
8
|
-
#include "buffer.h"
|
|
9
|
-
#include "position.h"
|
|
10
|
-
#include "location.h"
|
|
11
|
-
#include "token_struct.h"
|
|
12
7
|
#include "analyzed_ruby.h"
|
|
13
8
|
#include "element_source.h"
|
|
9
|
+
#include "location.h"
|
|
10
|
+
#include "position.h"
|
|
11
|
+
#include "token_struct.h"
|
|
12
|
+
#include "util/hb_array.h"
|
|
13
|
+
#include "util/hb_buffer.h"
|
|
14
|
+
#include "util/hb_string.h"
|
|
14
15
|
|
|
15
16
|
typedef enum {
|
|
16
17
|
<%- nodes.each do |node| -%>
|
|
@@ -20,9 +21,9 @@ typedef enum {
|
|
|
20
21
|
|
|
21
22
|
typedef struct AST_NODE_STRUCT {
|
|
22
23
|
ast_node_type_T type;
|
|
23
|
-
location_T
|
|
24
|
+
location_T location;
|
|
24
25
|
// maybe a range too?
|
|
25
|
-
|
|
26
|
+
hb_array_T* errors;
|
|
26
27
|
} AST_NODE_T;
|
|
27
28
|
|
|
28
29
|
<%- nodes.each do |node| -%>
|
|
@@ -36,11 +37,11 @@ typedef struct <%= node.struct_name %> {
|
|
|
36
37
|
|
|
37
38
|
<%- nodes.each do |node| -%>
|
|
38
39
|
<%- node_arguments = node.fields.any? ? node.fields.map { |field| [field.c_type, " ", field.name].join } : [] -%>
|
|
39
|
-
<%- arguments = node_arguments + ["position_T
|
|
40
|
+
<%- arguments = node_arguments + ["position_T start_position", "position_T end_position", "hb_array_T* errors"] -%>
|
|
40
41
|
<%= node.struct_type %>* ast_<%= node.human %>_init(<%= arguments.join(", ") %>);
|
|
41
42
|
<%- end -%>
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
hb_string_T ast_node_type_to_string(AST_NODE_T* node);
|
|
45
|
+
hb_string_T ast_node_human_type(AST_NODE_T* node);
|
|
45
46
|
|
|
46
47
|
#endif
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
#define HERB_AST_PRETTY_PRINT_H
|
|
3
3
|
|
|
4
4
|
#include "ast_nodes.h"
|
|
5
|
-
#include "
|
|
5
|
+
#include "util/hb_buffer.h"
|
|
6
6
|
|
|
7
7
|
void ast_pretty_print_node(
|
|
8
8
|
AST_NODE_T* node,
|
|
9
9
|
size_t indent,
|
|
10
10
|
size_t relative_indent,
|
|
11
|
-
|
|
11
|
+
hb_buffer_T* buffer
|
|
12
12
|
);
|
|
13
13
|
|
|
14
14
|
#endif
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#ifndef HERB_ERRORS_H
|
|
2
2
|
#define HERB_ERRORS_H
|
|
3
3
|
|
|
4
|
-
#include "array.h"
|
|
5
|
-
#include "buffer.h"
|
|
6
4
|
#include "errors.h"
|
|
7
5
|
#include "location.h"
|
|
8
6
|
#include "position.h"
|
|
9
7
|
#include "token.h"
|
|
8
|
+
#include "util/hb_array.h"
|
|
9
|
+
#include "util/hb_buffer.h"
|
|
10
10
|
|
|
11
11
|
typedef enum {
|
|
12
12
|
<%- errors.each do |error| -%>
|
|
@@ -16,7 +16,7 @@ typedef enum {
|
|
|
16
16
|
|
|
17
17
|
typedef struct ERROR_STRUCT {
|
|
18
18
|
error_type_T type;
|
|
19
|
-
location_T
|
|
19
|
+
location_T location;
|
|
20
20
|
char* message;
|
|
21
21
|
} ERROR_T;
|
|
22
22
|
|
|
@@ -31,12 +31,12 @@ typedef struct {
|
|
|
31
31
|
|
|
32
32
|
<%- errors.each do |error| -%>
|
|
33
33
|
<%- error_arguments = error.fields.any? ? error.fields.map { |field| [field.c_type, " ", field.name].join } : [] -%>
|
|
34
|
-
<%- arguments = error_arguments + ["position_T
|
|
34
|
+
<%- arguments = error_arguments + ["position_T start", "position_T end"] -%>
|
|
35
35
|
<%= error.struct_type %>* <%= error.human %>_init(<%= arguments.join(", ") %>);
|
|
36
|
-
void append_<%= error.human %>(<%= (arguments << "
|
|
36
|
+
void append_<%= error.human %>(<%= (arguments << "hb_array_T* errors").join(", ") %>);
|
|
37
37
|
<%- end -%>
|
|
38
38
|
|
|
39
|
-
void error_init(ERROR_T* error, error_type_T type, position_T
|
|
39
|
+
void error_init(ERROR_T* error, error_type_T type, position_T start, position_T end);
|
|
40
40
|
|
|
41
41
|
size_t error_sizeof(void);
|
|
42
42
|
error_type_T error_type(ERROR_T* error);
|
|
@@ -48,11 +48,11 @@ const char* error_human_type(ERROR_T* error);
|
|
|
48
48
|
|
|
49
49
|
void error_free(ERROR_T* error);
|
|
50
50
|
|
|
51
|
-
void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent,
|
|
51
|
+
void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, hb_buffer_T* buffer);
|
|
52
52
|
|
|
53
53
|
void error_pretty_print_array(
|
|
54
|
-
const char* name,
|
|
55
|
-
|
|
54
|
+
const char* name, hb_array_T* array, size_t indent, size_t relative_indent, bool last_property,
|
|
55
|
+
hb_buffer_T* buffer
|
|
56
56
|
);
|
|
57
57
|
|
|
58
58
|
#endif
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#include "include/parser.h"
|
|
2
|
+
#include "include/ast_nodes.h"
|
|
3
|
+
#include "include/util/hb_array.h"
|
|
4
|
+
#include "include/visitor.h"
|
|
5
|
+
|
|
6
|
+
bool match_tags_visitor(const AST_NODE_T* node, void* data) {
|
|
7
|
+
hb_array_T* errors = (hb_array_T*) data;
|
|
8
|
+
|
|
9
|
+
if (node == NULL) { return false; }
|
|
10
|
+
|
|
11
|
+
switch (node->type) {
|
|
12
|
+
<%- nodes.each do |node| -%>
|
|
13
|
+
<%- array_fields = node.fields.select { |f| f.is_a?(Herb::Template::ArrayField) && f.name != "errors" } -%>
|
|
14
|
+
<%- single_node_fields = node.fields.select { |f| f.is_a?(Herb::Template::NodeField) } -%>
|
|
15
|
+
|
|
16
|
+
<%- if array_fields.any? || single_node_fields.any? -%>
|
|
17
|
+
case <%= node.type %>: {
|
|
18
|
+
const <%= node.struct_type %>* <%= node.human %> = (const <%= node.struct_type %>*) node;
|
|
19
|
+
|
|
20
|
+
<%- array_fields.each do |field| -%>
|
|
21
|
+
if (<%= node.human %>-><%= field.name %> != NULL) {
|
|
22
|
+
match_tags_in_node_array(<%= node.human %>-><%= field.name %>, errors);
|
|
23
|
+
}
|
|
24
|
+
<%- end -%>
|
|
25
|
+
<%- single_node_fields.each do |field| -%>
|
|
26
|
+
if (<%= node.human %>-><%= field.name %> != NULL) {
|
|
27
|
+
herb_visit_node((AST_NODE_T*) <%= node.human %>-><%= field.name %>, match_tags_visitor, errors);
|
|
28
|
+
}
|
|
29
|
+
<%- end -%>
|
|
30
|
+
} break;
|
|
31
|
+
|
|
32
|
+
<%- end -%>
|
|
33
|
+
<%- end -%>
|
|
34
|
+
default: break;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
}
|
data/templates/src/visitor.c.erb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#include <stdio.h>
|
|
2
2
|
|
|
3
|
-
#include "include/array.h"
|
|
4
|
-
#include "include/visitor.h"
|
|
5
3
|
#include "include/ast_node.h"
|
|
6
4
|
#include "include/ast_nodes.h"
|
|
5
|
+
#include "include/util/hb_array.h"
|
|
6
|
+
#include "include/visitor.h"
|
|
7
7
|
|
|
8
8
|
void herb_visit_node(const AST_NODE_T* node, bool (*visitor)(const AST_NODE_T*, void*), void* data) {
|
|
9
9
|
if (visitor(node, data) && node != NULL) {
|
|
@@ -31,8 +31,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
31
31
|
|
|
32
32
|
<%- when Herb::Template::ArrayField -%>
|
|
33
33
|
if (<%= node.human %>-><%= field.name %> != NULL) {
|
|
34
|
-
for (size_t index = 0; index <
|
|
35
|
-
herb_visit_node(
|
|
34
|
+
for (size_t index = 0; index < hb_array_size(<%= node.human %>-><%= field.name %>); index++) {
|
|
35
|
+
herb_visit_node(hb_array_get(<%= node.human %>-><%= field.name %>, index), visitor, data);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
data/templates/template.rb
CHANGED
|
@@ -30,7 +30,7 @@ module Herb
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def c_type
|
|
33
|
-
"
|
|
33
|
+
"hb_array_T*"
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def c_item_type
|
|
@@ -245,6 +245,10 @@ module Herb
|
|
|
245
245
|
type.new(name: field_name, kind: kind)
|
|
246
246
|
end
|
|
247
247
|
end
|
|
248
|
+
|
|
249
|
+
def c_type
|
|
250
|
+
@struct_type
|
|
251
|
+
end
|
|
248
252
|
end
|
|
249
253
|
|
|
250
254
|
class NodeType
|
|
@@ -268,6 +272,10 @@ module Herb
|
|
|
268
272
|
type.new(name: field_name, kind: kind)
|
|
269
273
|
end
|
|
270
274
|
end
|
|
275
|
+
|
|
276
|
+
def c_type
|
|
277
|
+
@struct_type
|
|
278
|
+
end
|
|
271
279
|
end
|
|
272
280
|
|
|
273
281
|
class PrintfMessageTemplate
|
|
@@ -331,6 +339,8 @@ module Herb
|
|
|
331
339
|
end
|
|
332
340
|
|
|
333
341
|
def self.render(template_file)
|
|
342
|
+
template_file_display = template_file.delete_prefix("#{File.expand_path("../", __dir__)}/")
|
|
343
|
+
|
|
334
344
|
name = Pathname.new(template_file)
|
|
335
345
|
name = if name.absolute?
|
|
336
346
|
template_file.gsub(
|
|
@@ -351,8 +361,6 @@ module Herb
|
|
|
351
361
|
)
|
|
352
362
|
end
|
|
353
363
|
|
|
354
|
-
puts "Rendering #{template_file.delete_prefix("#{File.expand_path("../", __dir__)}/")} → #{destination}"
|
|
355
|
-
|
|
356
364
|
template_file = Pathname.new(template_file)
|
|
357
365
|
template_path = if template_file.absolute?
|
|
358
366
|
template_file
|
|
@@ -367,6 +375,17 @@ module Herb
|
|
|
367
375
|
|
|
368
376
|
check_gitignore(name)
|
|
369
377
|
|
|
378
|
+
if File.exist?(destination)
|
|
379
|
+
existing_content = File.read(destination, encoding: Encoding::UTF_8)
|
|
380
|
+
|
|
381
|
+
if existing_content == content
|
|
382
|
+
puts "[unchanged] #{destination}"
|
|
383
|
+
return
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
puts "Rendering #{template_file_display} → #{destination}"
|
|
388
|
+
|
|
370
389
|
FileUtils.mkdir_p(File.dirname(destination))
|
|
371
390
|
File.write(destination, content)
|
|
372
391
|
rescue SyntaxError => e
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
#include "extension_helpers.h"
|
|
9
9
|
|
|
10
10
|
extern "C" {
|
|
11
|
-
#include "../src/include/herb.h"
|
|
12
|
-
#include "../src/include/token.h"
|
|
13
|
-
#include "../src/include/array.h"
|
|
14
|
-
#include "../src/include/errors.h"
|
|
15
11
|
#include "../src/include/ast_node.h"
|
|
16
12
|
#include "../src/include/ast_nodes.h"
|
|
13
|
+
#include "../src/include/errors.h"
|
|
14
|
+
#include "../src/include/herb.h"
|
|
15
|
+
#include "../src/include/token.h"
|
|
16
|
+
#include "../src/include/util/hb_array.h"
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
using namespace emscripten;
|
|
@@ -21,9 +21,9 @@ using namespace emscripten;
|
|
|
21
21
|
val CreateLocation(location_T* location);
|
|
22
22
|
val CreateToken(token_T* token);
|
|
23
23
|
val NodeFromCStruct(AST_NODE_T* node);
|
|
24
|
-
val NodesArrayFromCArray(
|
|
24
|
+
val NodesArrayFromCArray(hb_array_T* array);
|
|
25
25
|
val ErrorFromCStruct(ERROR_T* error);
|
|
26
|
-
val ErrorsArrayFromCArray(
|
|
26
|
+
val ErrorsArrayFromCArray(hb_array_T* array);
|
|
27
27
|
|
|
28
28
|
<%- errors.each do |error| -%>
|
|
29
29
|
val <%= error.name %>FromCStruct(<%= error.struct_type %>* <%= error.human %>) {
|
|
@@ -61,13 +61,13 @@ val <%= error.name %>FromCStruct(<%= error.struct_type %>* <%= error.human %>) {
|
|
|
61
61
|
|
|
62
62
|
<%- end -%>
|
|
63
63
|
|
|
64
|
-
val ErrorsArrayFromCArray(
|
|
64
|
+
val ErrorsArrayFromCArray(hb_array_T* array) {
|
|
65
65
|
val Array = val::global("Array");
|
|
66
66
|
val result = Array.new_();
|
|
67
67
|
|
|
68
68
|
if (array) {
|
|
69
|
-
for (size_t i = 0; i <
|
|
70
|
-
ERROR_T* error = (ERROR_T*)
|
|
69
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
70
|
+
ERROR_T* error = (ERROR_T*)hb_array_get(array, i);
|
|
71
71
|
if (error) {
|
|
72
72
|
result.call<void>("push", ErrorFromCStruct(error));
|
|
73
73
|
}
|
|
@@ -6,7 +6,7 @@ extern "C" {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
emscripten::val ErrorFromCStruct(ERROR_T* error);
|
|
9
|
-
emscripten::val ErrorsArrayFromCArray(
|
|
9
|
+
emscripten::val ErrorsArrayFromCArray(hb_array_T* array);
|
|
10
10
|
|
|
11
11
|
<%- errors.each do |error| -%>
|
|
12
12
|
emscripten::val <%= error.name %>FromCStruct(<%= error.struct_type %>* <%= error.human %>);
|
|
@@ -4,24 +4,24 @@
|
|
|
4
4
|
#include "error_helpers.h"
|
|
5
5
|
#include "extension_helpers.h"
|
|
6
6
|
|
|
7
|
-
#include "../src/include/herb.h"
|
|
8
|
-
#include "../src/include/token.h"
|
|
9
|
-
#include "../src/include/array.h"
|
|
10
7
|
#include "../src/include/ast_node.h"
|
|
11
8
|
#include "../src/include/ast_nodes.h"
|
|
9
|
+
#include "../src/include/herb.h"
|
|
12
10
|
#include "../src/include/location.h"
|
|
11
|
+
#include "../src/include/token.h"
|
|
12
|
+
#include "../src/include/util/hb_array.h"
|
|
13
13
|
|
|
14
14
|
using namespace emscripten;
|
|
15
15
|
|
|
16
16
|
val NodeFromCStruct(AST_NODE_T* node);
|
|
17
|
-
val NodesArrayFromCArray(
|
|
17
|
+
val NodesArrayFromCArray(hb_array_T* array);
|
|
18
18
|
|
|
19
19
|
<%- nodes.each do |node| -%>
|
|
20
20
|
val <%= node.name %>FromCStruct(<%= node.struct_type %>* <%= node.human %>) {
|
|
21
21
|
if (!<%= node.human %>) return val::null();
|
|
22
22
|
|
|
23
23
|
val result = val::object();
|
|
24
|
-
result.set("type",
|
|
24
|
+
result.set("type", CreateStringFromHbString(ast_node_type_to_string(&<%= node.human %>->base)));
|
|
25
25
|
result.set("location", CreateLocation(<%= node.human %>->base.location));
|
|
26
26
|
result.set("errors", ErrorsArrayFromCArray(<%= node.human %>->base.errors));
|
|
27
27
|
|
|
@@ -38,7 +38,7 @@ val <%= node.name %>FromCStruct(<%= node.struct_type %>* <%= node.human %>) {
|
|
|
38
38
|
<%- when Herb::Template::ArrayField -%>
|
|
39
39
|
result.set("<%= field.name %>", NodesArrayFromCArray(<%= node.human %>-><%= field.name %>));
|
|
40
40
|
<%- when Herb::Template::ElementSourceField -%>
|
|
41
|
-
result.set("<%= field.name %>",
|
|
41
|
+
result.set("<%= field.name %>", CreateStringFromHbString(element_source_to_string(<%= node.human %>-><%= field.name %>)));
|
|
42
42
|
<%- else -%>
|
|
43
43
|
result.set("<%= field.name %>", val::null());
|
|
44
44
|
<%- end -%>
|
|
@@ -62,13 +62,13 @@ val NodeFromCStruct(AST_NODE_T* node) {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
val NodesArrayFromCArray(
|
|
65
|
+
val NodesArrayFromCArray(hb_array_T* array) {
|
|
66
66
|
if (!array) return val::null();
|
|
67
67
|
|
|
68
68
|
val jsArray = val::array();
|
|
69
69
|
|
|
70
|
-
for (size_t i = 0; i <
|
|
71
|
-
AST_NODE_T* child_node = (AST_NODE_T*)
|
|
70
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
71
|
+
AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
|
|
72
72
|
|
|
73
73
|
if (child_node) {
|
|
74
74
|
jsArray.set(i, NodeFromCStruct(child_node));
|
data/templates/wasm/nodes.h.erb
CHANGED
|
@@ -6,7 +6,7 @@ extern "C" {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
emscripten::val NodeFromCStruct(AST_NODE_T* node);
|
|
9
|
-
emscripten::val NodesArrayFromCArray(
|
|
9
|
+
emscripten::val NodesArrayFromCArray(hb_array_T* array);
|
|
10
10
|
|
|
11
11
|
<%- nodes.each do |node| -%>
|
|
12
12
|
emscripten::val <%= node.human %>NodeFromCStruct(<%= node.struct_type %>* <%= node.human %>);
|
data/vendor/prism/Rakefile
CHANGED
|
@@ -11,7 +11,10 @@ desc "Generate all ERB template based files"
|
|
|
11
11
|
task templates: Prism::Template::TEMPLATES
|
|
12
12
|
|
|
13
13
|
make = RUBY_PLATFORM.match?(/openbsd|freebsd/) ? "gmake" : "make"
|
|
14
|
-
task(make: :templates) {
|
|
14
|
+
task(make: :templates) {
|
|
15
|
+
ENV["MAKEFLAGS"] ||= "-j"
|
|
16
|
+
sh(make)
|
|
17
|
+
}
|
|
15
18
|
task(make_no_debug: :templates) { sh("#{make} all-no-debug") }
|
|
16
19
|
task(make_minimal: :templates) { sh("#{make} minimal") }
|
|
17
20
|
|
data/vendor/prism/config.yml
CHANGED
|
@@ -60,6 +60,7 @@ errors:
|
|
|
60
60
|
- CONDITIONAL_WHILE_PREDICATE
|
|
61
61
|
- CONSTANT_PATH_COLON_COLON_CONSTANT
|
|
62
62
|
- DEF_ENDLESS
|
|
63
|
+
- DEF_ENDLESS_PARAMETERS
|
|
63
64
|
- DEF_ENDLESS_SETTER
|
|
64
65
|
- DEF_NAME
|
|
65
66
|
- DEF_PARAMS_TERM
|
|
@@ -1800,7 +1801,7 @@ nodes:
|
|
|
1800
1801
|
Represents the predicate of the case statement. This can be either `nil` or any [non-void expressions](https://github.com/ruby/prism/blob/main/docs/parsing_rules.md#non-void-expression).
|
|
1801
1802
|
|
|
1802
1803
|
case true; when false; end
|
|
1803
|
-
|
|
1804
|
+
^^^^
|
|
1804
1805
|
- name: conditions
|
|
1805
1806
|
type: node[]
|
|
1806
1807
|
kind: WhenNode
|