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.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +8 -5
  3. data/config.yml +40 -20
  4. data/ext/herb/error_helpers.c +57 -3
  5. data/ext/herb/error_helpers.h +1 -1
  6. data/ext/herb/extconf.rb +1 -0
  7. data/ext/herb/extension.c +10 -24
  8. data/ext/herb/extension_helpers.c +12 -18
  9. data/ext/herb/extension_helpers.h +4 -4
  10. data/ext/herb/nodes.c +72 -37
  11. data/herb.gemspec +0 -2
  12. data/lib/herb/3.0/herb.so +0 -0
  13. data/lib/herb/3.1/herb.so +0 -0
  14. data/lib/herb/3.2/herb.so +0 -0
  15. data/lib/herb/3.3/herb.so +0 -0
  16. data/lib/herb/3.4/herb.so +0 -0
  17. data/lib/herb/ast/helpers.rb +11 -0
  18. data/lib/herb/ast/node.rb +15 -6
  19. data/lib/herb/ast/nodes.rb +609 -392
  20. data/lib/herb/cli.rb +31 -0
  21. data/lib/herb/colors.rb +82 -0
  22. data/lib/herb/engine/compiler.rb +140 -14
  23. data/lib/herb/engine/debug_visitor.rb +1 -5
  24. data/lib/herb/engine/parser_error_overlay.rb +1 -1
  25. data/lib/herb/engine.rb +18 -20
  26. data/lib/herb/errors.rb +166 -56
  27. data/lib/herb/location.rb +2 -2
  28. data/lib/herb/project.rb +86 -21
  29. data/lib/herb/token.rb +14 -2
  30. data/lib/herb/version.rb +1 -1
  31. data/lib/herb.rb +1 -0
  32. data/sig/herb/ast/helpers.rbs +3 -0
  33. data/sig/herb/ast/node.rbs +12 -5
  34. data/sig/herb/ast/nodes.rbs +124 -62
  35. data/sig/herb/colors.rbs +35 -0
  36. data/sig/herb/engine/compiler.rbs +23 -1
  37. data/sig/herb/errors.rbs +74 -20
  38. data/sig/herb/token.rbs +8 -0
  39. data/sig/herb_c_extension.rbs +1 -1
  40. data/sig/serialized_ast_errors.rbs +8 -0
  41. data/src/analyze.c +461 -249
  42. data/src/analyze_helpers.c +5 -0
  43. data/src/analyze_missing_end.c +147 -0
  44. data/src/analyze_transform.c +196 -0
  45. data/src/analyzed_ruby.c +23 -2
  46. data/src/ast_node.c +14 -17
  47. data/src/ast_nodes.c +179 -181
  48. data/src/ast_pretty_print.c +232 -232
  49. data/src/element_source.c +7 -6
  50. data/src/errors.c +272 -152
  51. data/src/extract.c +92 -34
  52. data/src/herb.c +37 -49
  53. data/src/html_util.c +34 -96
  54. data/src/include/analyze.h +10 -2
  55. data/src/include/analyze_helpers.h +3 -0
  56. data/src/include/analyzed_ruby.h +4 -2
  57. data/src/include/ast_node.h +4 -4
  58. data/src/include/ast_nodes.h +68 -67
  59. data/src/include/ast_pretty_print.h +2 -2
  60. data/src/include/element_source.h +3 -1
  61. data/src/include/errors.h +42 -26
  62. data/src/include/extract.h +4 -4
  63. data/src/include/herb.h +6 -7
  64. data/src/include/html_util.h +4 -5
  65. data/src/include/lexer.h +1 -3
  66. data/src/include/lexer_peek_helpers.h +21 -19
  67. data/src/include/lexer_struct.h +12 -10
  68. data/src/include/location.h +10 -13
  69. data/src/include/macros.h +4 -0
  70. data/src/include/parser.h +12 -6
  71. data/src/include/parser_helpers.h +26 -16
  72. data/src/include/position.h +3 -14
  73. data/src/include/pretty_print.h +38 -28
  74. data/src/include/prism_helpers.h +1 -1
  75. data/src/include/range.h +4 -13
  76. data/src/include/token.h +5 -11
  77. data/src/include/token_struct.h +2 -2
  78. data/src/include/utf8.h +3 -2
  79. data/src/include/util/hb_arena.h +31 -0
  80. data/src/include/util/hb_arena_debug.h +8 -0
  81. data/src/include/util/hb_array.h +33 -0
  82. data/src/include/util/hb_buffer.h +34 -0
  83. data/src/include/util/hb_string.h +29 -0
  84. data/src/include/util/hb_system.h +9 -0
  85. data/src/include/util.h +3 -14
  86. data/src/include/version.h +1 -1
  87. data/src/include/visitor.h +1 -1
  88. data/src/io.c +7 -4
  89. data/src/lexer.c +62 -88
  90. data/src/lexer_peek_helpers.c +42 -38
  91. data/src/location.c +9 -37
  92. data/src/main.c +19 -23
  93. data/src/parser.c +373 -313
  94. data/src/parser_helpers.c +60 -54
  95. data/src/parser_match_tags.c +316 -0
  96. data/src/pretty_print.c +88 -117
  97. data/src/prism_helpers.c +7 -7
  98. data/src/range.c +2 -35
  99. data/src/token.c +36 -87
  100. data/src/utf8.c +4 -4
  101. data/src/util/hb_arena.c +179 -0
  102. data/src/util/hb_arena_debug.c +237 -0
  103. data/src/{array.c → util/hb_array.c} +26 -27
  104. data/src/util/hb_buffer.c +203 -0
  105. data/src/util/hb_string.c +85 -0
  106. data/src/util/hb_system.c +30 -0
  107. data/src/util.c +29 -99
  108. data/src/visitor.c +54 -54
  109. data/templates/ext/herb/error_helpers.c.erb +3 -3
  110. data/templates/ext/herb/error_helpers.h.erb +1 -1
  111. data/templates/ext/herb/nodes.c.erb +11 -6
  112. data/templates/java/error_helpers.c.erb +75 -0
  113. data/templates/java/error_helpers.h.erb +20 -0
  114. data/templates/java/nodes.c.erb +97 -0
  115. data/templates/java/nodes.h.erb +23 -0
  116. data/templates/java/org/herb/ast/Errors.java.erb +121 -0
  117. data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
  118. data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
  119. data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
  120. data/templates/javascript/packages/core/src/visitor.ts.erb +29 -1
  121. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
  122. data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
  123. data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
  124. data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
  125. data/templates/lib/herb/ast/nodes.rb.erb +28 -16
  126. data/templates/lib/herb/errors.rb.erb +17 -12
  127. data/templates/rust/src/ast/nodes.rs.erb +220 -0
  128. data/templates/rust/src/errors.rs.erb +216 -0
  129. data/templates/rust/src/nodes.rs.erb +374 -0
  130. data/templates/src/analyze_missing_end.c.erb +36 -0
  131. data/templates/src/analyze_transform.c.erb +24 -0
  132. data/templates/src/ast_nodes.c.erb +14 -16
  133. data/templates/src/ast_pretty_print.c.erb +36 -36
  134. data/templates/src/errors.c.erb +36 -38
  135. data/templates/src/include/ast_nodes.h.erb +11 -10
  136. data/templates/src/include/ast_pretty_print.h.erb +2 -2
  137. data/templates/src/include/errors.h.erb +9 -9
  138. data/templates/src/parser_match_tags.c.erb +38 -0
  139. data/templates/src/visitor.c.erb +4 -4
  140. data/templates/template.rb +22 -3
  141. data/templates/wasm/error_helpers.cpp.erb +9 -9
  142. data/templates/wasm/error_helpers.h.erb +1 -1
  143. data/templates/wasm/nodes.cpp.erb +9 -9
  144. data/templates/wasm/nodes.h.erb +1 -1
  145. data/vendor/prism/Rakefile +4 -1
  146. data/vendor/prism/config.yml +2 -1
  147. data/vendor/prism/include/prism/ast.h +31 -1
  148. data/vendor/prism/include/prism/diagnostic.h +1 -0
  149. data/vendor/prism/include/prism/version.h +3 -3
  150. data/vendor/prism/src/diagnostic.c +3 -1
  151. data/vendor/prism/src/prism.c +130 -71
  152. data/vendor/prism/src/util/pm_string.c +6 -8
  153. data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
  154. data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
  155. data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
  156. data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
  157. data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
  158. data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
  159. metadata +34 -21
  160. data/lib/herb/libherb/array.rb +0 -51
  161. data/lib/herb/libherb/ast_node.rb +0 -50
  162. data/lib/herb/libherb/buffer.rb +0 -56
  163. data/lib/herb/libherb/extract_result.rb +0 -20
  164. data/lib/herb/libherb/lex_result.rb +0 -32
  165. data/lib/herb/libherb/libherb.rb +0 -52
  166. data/lib/herb/libherb/parse_result.rb +0 -20
  167. data/lib/herb/libherb/token.rb +0 -46
  168. data/lib/herb/libherb.rb +0 -35
  169. data/src/buffer.c +0 -232
  170. data/src/include/array.h +0 -33
  171. data/src/include/buffer.h +0 -39
  172. data/src/include/json.h +0 -28
  173. data/src/include/memory.h +0 -12
  174. data/src/json.c +0 -205
  175. data/src/memory.c +0 -53
  176. data/src/position.c +0 -33
@@ -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* start, position_T* end) {
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 = location_init(position_copy(start), position_copy(end));
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* start", "position_T* end"] -%>
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 %> = position_copy(<%= 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 + ["array_T* errors"]).join(", ") %>) {
92
- array_append(errors, <%= error.human %>_init(<%= arguments.map { |argument| argument.split(" ").last.strip }.join(", ") %>));
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, array_T* array, const size_t indent, const size_t relative_indent, const bool last_property,
164
- buffer_T* buffer
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 (array_size(array) == 0) {
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
- buffer_append(buffer, "(");
178
+ hb_buffer_append(buffer, "(");
181
179
 
182
180
  char count[16];
183
- sprintf(count, "%zu", array_size(array));
184
- buffer_append(buffer, count);
185
- buffer_append(buffer, ")\n");
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 < array_size(array); i++) {
189
- ERROR_T* child = array_get(array, i);
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 == array_size(array) - 1) {
194
- buffer_append(buffer, "└── ");
191
+ if (i == hb_array_size(array) - 1) {
192
+ hb_buffer_append(buffer, "└── ");
195
193
  } else {
196
- buffer_append(buffer, "├── ");
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 != array_size(array) - 1) { pretty_print_newline(indent + 1, relative_indent, buffer); }
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, buffer_T* buffer) {
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
- buffer_append(buffer, "@ ");
211
- buffer_append(buffer, error_human_type((ERROR_T*) error));
212
- buffer_append(buffer, " ");
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
- buffer_append(buffer, "\n");
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 %>, "<%= field.name %>", indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
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 %>, "<%= field.name %>", indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
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 %>, indent, relative_indent, <%= error.fields.length - 1 == index %>, buffer);
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, buffer_T* buffer) {
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* location;
24
+ location_T location;
24
25
  // maybe a range too?
25
- array_T* errors;
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* start_position", "position_T* end_position", "array_T* errors"] -%>
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
- const char* ast_node_type_to_string(AST_NODE_T* node);
44
- const char* ast_node_human_type(AST_NODE_T* node);
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 "buffer.h"
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
- buffer_T* buffer
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* location;
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* start", "position_T* end"] -%>
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 << "array_T* errors").join(", ") %>);
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* start, position_T* end);
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, buffer_T* buffer);
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, array_T* array, size_t indent, size_t relative_indent, bool last_property,
55
- buffer_T* buffer
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
+ }
@@ -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 < array_size(<%= node.human %>-><%= field.name %>); index++) {
35
- herb_visit_node(array_get(<%= node.human %>-><%= field.name %>, index), visitor, data);
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
 
@@ -30,7 +30,7 @@ module Herb
30
30
  end
31
31
 
32
32
  def c_type
33
- "array_T*"
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(array_T* array);
24
+ val NodesArrayFromCArray(hb_array_T* array);
25
25
  val ErrorFromCStruct(ERROR_T* error);
26
- val ErrorsArrayFromCArray(array_T* array);
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(array_T* array) {
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 < array_size(array); i++) {
70
- ERROR_T* error = (ERROR_T*)array_get(array, i);
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(array_T* array);
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(array_T* array);
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", CreateString(ast_node_type_to_string(&<%= node.human %>->base)));
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 %>", CreateString(element_source_to_string(<%= node.human %>-><%= 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(array_T* array) {
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 < array_size(array); i++) {
71
- AST_NODE_T* child_node = (AST_NODE_T*) array_get(array, i);
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));
@@ -6,7 +6,7 @@ extern "C" {
6
6
  }
7
7
 
8
8
  emscripten::val NodeFromCStruct(AST_NODE_T* node);
9
- emscripten::val NodesArrayFromCArray(array_T* array);
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 %>);
@@ -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) { sh(make) }
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
 
@@ -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