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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +8 -5
  3. data/config.yml +26 -6
  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 +3 -3
  9. data/ext/herb/extension_helpers.h +1 -1
  10. data/ext/herb/nodes.c +72 -37
  11. data/herb.gemspec +0 -2
  12. data/lib/herb/ast/helpers.rb +11 -0
  13. data/lib/herb/ast/node.rb +15 -6
  14. data/lib/herb/ast/nodes.rb +609 -392
  15. data/lib/herb/cli.rb +31 -0
  16. data/lib/herb/colors.rb +82 -0
  17. data/lib/herb/engine/compiler.rb +140 -14
  18. data/lib/herb/engine/debug_visitor.rb +1 -5
  19. data/lib/herb/engine/parser_error_overlay.rb +1 -1
  20. data/lib/herb/engine.rb +8 -14
  21. data/lib/herb/errors.rb +166 -56
  22. data/lib/herb/location.rb +2 -2
  23. data/lib/herb/project.rb +86 -21
  24. data/lib/herb/token.rb +14 -2
  25. data/lib/herb/version.rb +1 -1
  26. data/lib/herb.rb +1 -0
  27. data/sig/herb/ast/helpers.rbs +3 -0
  28. data/sig/herb/ast/node.rbs +12 -5
  29. data/sig/herb/ast/nodes.rbs +124 -62
  30. data/sig/herb/colors.rbs +35 -0
  31. data/sig/herb/engine/compiler.rbs +23 -1
  32. data/sig/herb/errors.rbs +74 -20
  33. data/sig/herb/token.rbs +8 -0
  34. data/sig/herb_c_extension.rbs +1 -1
  35. data/sig/serialized_ast_errors.rbs +8 -0
  36. data/src/analyze.c +420 -171
  37. data/src/analyze_helpers.c +5 -0
  38. data/src/analyze_missing_end.c +147 -0
  39. data/src/analyze_transform.c +196 -0
  40. data/src/analyzed_ruby.c +23 -2
  41. data/src/ast_node.c +5 -5
  42. data/src/ast_nodes.c +179 -179
  43. data/src/ast_pretty_print.c +232 -232
  44. data/src/element_source.c +7 -6
  45. data/src/errors.c +246 -126
  46. data/src/extract.c +92 -34
  47. data/src/herb.c +37 -49
  48. data/src/html_util.c +34 -96
  49. data/src/include/analyze.h +10 -2
  50. data/src/include/analyze_helpers.h +3 -0
  51. data/src/include/analyzed_ruby.h +4 -2
  52. data/src/include/ast_node.h +2 -2
  53. data/src/include/ast_nodes.h +67 -66
  54. data/src/include/ast_pretty_print.h +2 -2
  55. data/src/include/element_source.h +3 -1
  56. data/src/include/errors.h +30 -14
  57. data/src/include/extract.h +4 -4
  58. data/src/include/herb.h +6 -7
  59. data/src/include/html_util.h +4 -5
  60. data/src/include/lexer.h +1 -3
  61. data/src/include/lexer_peek_helpers.h +14 -14
  62. data/src/include/lexer_struct.h +3 -2
  63. data/src/include/macros.h +4 -0
  64. data/src/include/parser.h +12 -6
  65. data/src/include/parser_helpers.h +25 -15
  66. data/src/include/pretty_print.h +38 -28
  67. data/src/include/token.h +5 -8
  68. data/src/include/utf8.h +3 -2
  69. data/src/include/util/hb_arena.h +31 -0
  70. data/src/include/util/hb_arena_debug.h +8 -0
  71. data/src/include/util/hb_array.h +33 -0
  72. data/src/include/util/hb_buffer.h +34 -0
  73. data/src/include/util/hb_string.h +29 -0
  74. data/src/include/util/hb_system.h +9 -0
  75. data/src/include/util.h +3 -14
  76. data/src/include/version.h +1 -1
  77. data/src/include/visitor.h +1 -1
  78. data/src/io.c +7 -4
  79. data/src/lexer.c +61 -88
  80. data/src/lexer_peek_helpers.c +35 -37
  81. data/src/main.c +19 -23
  82. data/src/parser.c +282 -201
  83. data/src/parser_helpers.c +46 -40
  84. data/src/parser_match_tags.c +316 -0
  85. data/src/pretty_print.c +82 -106
  86. data/src/token.c +18 -65
  87. data/src/utf8.c +4 -4
  88. data/src/util/hb_arena.c +179 -0
  89. data/src/util/hb_arena_debug.c +237 -0
  90. data/src/{array.c → util/hb_array.c} +26 -27
  91. data/src/util/hb_buffer.c +203 -0
  92. data/src/util/hb_string.c +85 -0
  93. data/src/util/hb_system.c +30 -0
  94. data/src/util.c +29 -99
  95. data/src/visitor.c +54 -54
  96. data/templates/ext/herb/error_helpers.c.erb +3 -3
  97. data/templates/ext/herb/error_helpers.h.erb +1 -1
  98. data/templates/ext/herb/nodes.c.erb +11 -6
  99. data/templates/java/error_helpers.c.erb +75 -0
  100. data/templates/java/error_helpers.h.erb +20 -0
  101. data/templates/java/nodes.c.erb +97 -0
  102. data/templates/java/nodes.h.erb +23 -0
  103. data/templates/java/org/herb/ast/Errors.java.erb +121 -0
  104. data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
  105. data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
  106. data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
  107. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
  108. data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
  109. data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
  110. data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
  111. data/templates/lib/herb/ast/nodes.rb.erb +28 -16
  112. data/templates/lib/herb/errors.rb.erb +17 -12
  113. data/templates/rust/src/ast/nodes.rs.erb +220 -0
  114. data/templates/rust/src/errors.rs.erb +216 -0
  115. data/templates/rust/src/nodes.rs.erb +374 -0
  116. data/templates/src/analyze_missing_end.c.erb +36 -0
  117. data/templates/src/analyze_transform.c.erb +24 -0
  118. data/templates/src/ast_nodes.c.erb +14 -14
  119. data/templates/src/ast_pretty_print.c.erb +36 -36
  120. data/templates/src/errors.c.erb +31 -31
  121. data/templates/src/include/ast_nodes.h.erb +10 -9
  122. data/templates/src/include/ast_pretty_print.h.erb +2 -2
  123. data/templates/src/include/errors.h.erb +6 -6
  124. data/templates/src/parser_match_tags.c.erb +38 -0
  125. data/templates/src/visitor.c.erb +4 -4
  126. data/templates/template.rb +22 -3
  127. data/templates/wasm/error_helpers.cpp.erb +9 -9
  128. data/templates/wasm/error_helpers.h.erb +1 -1
  129. data/templates/wasm/nodes.cpp.erb +9 -9
  130. data/templates/wasm/nodes.h.erb +1 -1
  131. data/vendor/prism/Rakefile +4 -1
  132. data/vendor/prism/config.yml +2 -1
  133. data/vendor/prism/include/prism/ast.h +31 -1
  134. data/vendor/prism/include/prism/diagnostic.h +1 -0
  135. data/vendor/prism/include/prism/version.h +3 -3
  136. data/vendor/prism/src/diagnostic.c +3 -1
  137. data/vendor/prism/src/prism.c +130 -71
  138. data/vendor/prism/src/util/pm_string.c +6 -8
  139. data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
  140. data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
  141. data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
  142. data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
  143. data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
  144. data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
  145. metadata +34 -20
  146. data/lib/herb/libherb/array.rb +0 -51
  147. data/lib/herb/libherb/ast_node.rb +0 -50
  148. data/lib/herb/libherb/buffer.rb +0 -56
  149. data/lib/herb/libherb/extract_result.rb +0 -20
  150. data/lib/herb/libherb/lex_result.rb +0 -32
  151. data/lib/herb/libherb/libherb.rb +0 -52
  152. data/lib/herb/libherb/parse_result.rb +0 -20
  153. data/lib/herb/libherb/token.rb +0 -46
  154. data/lib/herb/libherb.rb +0 -35
  155. data/src/buffer.c +0 -241
  156. data/src/include/array.h +0 -33
  157. data/src/include/buffer.h +0 -39
  158. data/src/include/json.h +0 -28
  159. data/src/include/memory.h +0 -12
  160. data/src/json.c +0 -205
  161. data/src/memory.c +0 -53
data/ext/herb/nodes.c CHANGED
@@ -12,7 +12,7 @@
12
12
  #include "../../src/include/token.h"
13
13
 
14
14
  VALUE rb_node_from_c_struct(AST_NODE_T* node);
15
- static VALUE rb_nodes_array_from_c_array(array_T* array);
15
+ static VALUE rb_nodes_array_from_c_array(hb_array_T* array);
16
16
 
17
17
  static VALUE rb_document_node_from_c_struct(AST_DOCUMENT_NODE_T* document_node) {
18
18
  if (document_node == NULL) { return Qnil; }
@@ -24,7 +24,8 @@ static VALUE rb_document_node_from_c_struct(AST_DOCUMENT_NODE_T* document_node)
24
24
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
25
25
  VALUE DocumentNode = rb_define_class_under(AST, "DocumentNode", Node);
26
26
 
27
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
27
+ hb_string_T node_type = ast_node_type_to_string(node);
28
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
28
29
  VALUE location = rb_location_from_c_struct(node->location);
29
30
  VALUE errors = rb_errors_array_from_c_array(node->errors);
30
31
 
@@ -50,7 +51,8 @@ static VALUE rb_literal_node_from_c_struct(AST_LITERAL_NODE_T* literal_node) {
50
51
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
51
52
  VALUE LiteralNode = rb_define_class_under(AST, "LiteralNode", Node);
52
53
 
53
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
54
+ hb_string_T node_type = ast_node_type_to_string(node);
55
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
54
56
  VALUE location = rb_location_from_c_struct(node->location);
55
57
  VALUE errors = rb_errors_array_from_c_array(node->errors);
56
58
 
@@ -76,7 +78,8 @@ static VALUE rb_html_open_tag_node_from_c_struct(AST_HTML_OPEN_TAG_NODE_T* html_
76
78
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
77
79
  VALUE HTMLOpenTagNode = rb_define_class_under(AST, "HTMLOpenTagNode", Node);
78
80
 
79
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
81
+ hb_string_T node_type = ast_node_type_to_string(node);
82
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
80
83
  VALUE location = rb_location_from_c_struct(node->location);
81
84
  VALUE errors = rb_errors_array_from_c_array(node->errors);
82
85
 
@@ -110,7 +113,8 @@ static VALUE rb_html_close_tag_node_from_c_struct(AST_HTML_CLOSE_TAG_NODE_T* htm
110
113
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
111
114
  VALUE HTMLCloseTagNode = rb_define_class_under(AST, "HTMLCloseTagNode", Node);
112
115
 
113
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
116
+ hb_string_T node_type = ast_node_type_to_string(node);
117
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
114
118
  VALUE location = rb_location_from_c_struct(node->location);
115
119
  VALUE errors = rb_errors_array_from_c_array(node->errors);
116
120
 
@@ -142,7 +146,8 @@ static VALUE rb_html_element_node_from_c_struct(AST_HTML_ELEMENT_NODE_T* html_el
142
146
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
143
147
  VALUE HTMLElementNode = rb_define_class_under(AST, "HTMLElementNode", Node);
144
148
 
145
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
149
+ hb_string_T node_type = ast_node_type_to_string(node);
150
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
146
151
  VALUE location = rb_location_from_c_struct(node->location);
147
152
  VALUE errors = rb_errors_array_from_c_array(node->errors);
148
153
 
@@ -151,7 +156,11 @@ static VALUE rb_html_element_node_from_c_struct(AST_HTML_ELEMENT_NODE_T* html_el
151
156
  VALUE html_element_node_body = rb_nodes_array_from_c_array(html_element_node->body);
152
157
  VALUE html_element_node_close_tag = rb_node_from_c_struct((AST_NODE_T*) html_element_node->close_tag);
153
158
  VALUE html_element_node_is_void = (html_element_node->is_void) ? Qtrue : Qfalse;
154
- VALUE html_element_node_source = rb_utf8_str_new_cstr(element_source_to_string(html_element_node->source));
159
+ VALUE html_element_node_source;
160
+ {
161
+ hb_string_T element_source_string = element_source_to_string(html_element_node->source);
162
+ html_element_node_source = rb_utf8_str_new(element_source_string.data, element_source_string.length);
163
+ }
155
164
 
156
165
  VALUE args[9] = {
157
166
  type,
@@ -178,7 +187,8 @@ static VALUE rb_html_attribute_value_node_from_c_struct(AST_HTML_ATTRIBUTE_VALUE
178
187
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
179
188
  VALUE HTMLAttributeValueNode = rb_define_class_under(AST, "HTMLAttributeValueNode", Node);
180
189
 
181
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
190
+ hb_string_T node_type = ast_node_type_to_string(node);
191
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
182
192
  VALUE location = rb_location_from_c_struct(node->location);
183
193
  VALUE errors = rb_errors_array_from_c_array(node->errors);
184
194
 
@@ -210,7 +220,8 @@ static VALUE rb_html_attribute_name_node_from_c_struct(AST_HTML_ATTRIBUTE_NAME_N
210
220
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
211
221
  VALUE HTMLAttributeNameNode = rb_define_class_under(AST, "HTMLAttributeNameNode", Node);
212
222
 
213
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
223
+ hb_string_T node_type = ast_node_type_to_string(node);
224
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
214
225
  VALUE location = rb_location_from_c_struct(node->location);
215
226
  VALUE errors = rb_errors_array_from_c_array(node->errors);
216
227
 
@@ -236,7 +247,8 @@ static VALUE rb_html_attribute_node_from_c_struct(AST_HTML_ATTRIBUTE_NODE_T* htm
236
247
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
237
248
  VALUE HTMLAttributeNode = rb_define_class_under(AST, "HTMLAttributeNode", Node);
238
249
 
239
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
250
+ hb_string_T node_type = ast_node_type_to_string(node);
251
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
240
252
  VALUE location = rb_location_from_c_struct(node->location);
241
253
  VALUE errors = rb_errors_array_from_c_array(node->errors);
242
254
 
@@ -266,7 +278,8 @@ static VALUE rb_html_text_node_from_c_struct(AST_HTML_TEXT_NODE_T* html_text_nod
266
278
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
267
279
  VALUE HTMLTextNode = rb_define_class_under(AST, "HTMLTextNode", Node);
268
280
 
269
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
281
+ hb_string_T node_type = ast_node_type_to_string(node);
282
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
270
283
  VALUE location = rb_location_from_c_struct(node->location);
271
284
  VALUE errors = rb_errors_array_from_c_array(node->errors);
272
285
 
@@ -292,7 +305,8 @@ static VALUE rb_html_comment_node_from_c_struct(AST_HTML_COMMENT_NODE_T* html_co
292
305
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
293
306
  VALUE HTMLCommentNode = rb_define_class_under(AST, "HTMLCommentNode", Node);
294
307
 
295
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
308
+ hb_string_T node_type = ast_node_type_to_string(node);
309
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
296
310
  VALUE location = rb_location_from_c_struct(node->location);
297
311
  VALUE errors = rb_errors_array_from_c_array(node->errors);
298
312
 
@@ -322,7 +336,8 @@ static VALUE rb_html_doctype_node_from_c_struct(AST_HTML_DOCTYPE_NODE_T* html_do
322
336
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
323
337
  VALUE HTMLDoctypeNode = rb_define_class_under(AST, "HTMLDoctypeNode", Node);
324
338
 
325
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
339
+ hb_string_T node_type = ast_node_type_to_string(node);
340
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
326
341
  VALUE location = rb_location_from_c_struct(node->location);
327
342
  VALUE errors = rb_errors_array_from_c_array(node->errors);
328
343
 
@@ -352,7 +367,8 @@ static VALUE rb_xml_declaration_node_from_c_struct(AST_XML_DECLARATION_NODE_T* x
352
367
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
353
368
  VALUE XMLDeclarationNode = rb_define_class_under(AST, "XMLDeclarationNode", Node);
354
369
 
355
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
370
+ hb_string_T node_type = ast_node_type_to_string(node);
371
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
356
372
  VALUE location = rb_location_from_c_struct(node->location);
357
373
  VALUE errors = rb_errors_array_from_c_array(node->errors);
358
374
 
@@ -382,7 +398,8 @@ static VALUE rb_cdata_node_from_c_struct(AST_CDATA_NODE_T* cdata_node) {
382
398
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
383
399
  VALUE CDATANode = rb_define_class_under(AST, "CDATANode", Node);
384
400
 
385
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
401
+ hb_string_T node_type = ast_node_type_to_string(node);
402
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
386
403
  VALUE location = rb_location_from_c_struct(node->location);
387
404
  VALUE errors = rb_errors_array_from_c_array(node->errors);
388
405
 
@@ -412,7 +429,8 @@ static VALUE rb_whitespace_node_from_c_struct(AST_WHITESPACE_NODE_T* whitespace_
412
429
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
413
430
  VALUE WhitespaceNode = rb_define_class_under(AST, "WhitespaceNode", Node);
414
431
 
415
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
432
+ hb_string_T node_type = ast_node_type_to_string(node);
433
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
416
434
  VALUE location = rb_location_from_c_struct(node->location);
417
435
  VALUE errors = rb_errors_array_from_c_array(node->errors);
418
436
 
@@ -438,14 +456,15 @@ static VALUE rb_erb_content_node_from_c_struct(AST_ERB_CONTENT_NODE_T* erb_conte
438
456
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
439
457
  VALUE ERBContentNode = rb_define_class_under(AST, "ERBContentNode", Node);
440
458
 
441
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
459
+ hb_string_T node_type = ast_node_type_to_string(node);
460
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
442
461
  VALUE location = rb_location_from_c_struct(node->location);
443
462
  VALUE errors = rb_errors_array_from_c_array(node->errors);
444
463
 
445
464
  VALUE erb_content_node_tag_opening = rb_token_from_c_struct(erb_content_node->tag_opening);
446
465
  VALUE erb_content_node_content = rb_token_from_c_struct(erb_content_node->content);
447
466
  VALUE erb_content_node_tag_closing = rb_token_from_c_struct(erb_content_node->tag_closing);
448
- /* #<Herb::Template::AnalyzedRubyField:0x00007f65e8372418 @name="analyzed_ruby", @options={kind: nil}> */
467
+ /* #<Herb::Template::AnalyzedRubyField:0x00007f1ba6dc8c50 @name="analyzed_ruby", @options={kind: nil}> */
449
468
  VALUE erb_content_node_analyzed_ruby = Qnil;
450
469
  VALUE erb_content_node_parsed = (erb_content_node->parsed) ? Qtrue : Qfalse;
451
470
  VALUE erb_content_node_valid = (erb_content_node->valid) ? Qtrue : Qfalse;
@@ -475,7 +494,8 @@ static VALUE rb_erb_end_node_from_c_struct(AST_ERB_END_NODE_T* erb_end_node) {
475
494
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
476
495
  VALUE ERBEndNode = rb_define_class_under(AST, "ERBEndNode", Node);
477
496
 
478
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
497
+ hb_string_T node_type = ast_node_type_to_string(node);
498
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
479
499
  VALUE location = rb_location_from_c_struct(node->location);
480
500
  VALUE errors = rb_errors_array_from_c_array(node->errors);
481
501
 
@@ -505,7 +525,8 @@ static VALUE rb_erb_else_node_from_c_struct(AST_ERB_ELSE_NODE_T* erb_else_node)
505
525
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
506
526
  VALUE ERBElseNode = rb_define_class_under(AST, "ERBElseNode", Node);
507
527
 
508
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
528
+ hb_string_T node_type = ast_node_type_to_string(node);
529
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
509
530
  VALUE location = rb_location_from_c_struct(node->location);
510
531
  VALUE errors = rb_errors_array_from_c_array(node->errors);
511
532
 
@@ -537,7 +558,8 @@ static VALUE rb_erb_if_node_from_c_struct(AST_ERB_IF_NODE_T* erb_if_node) {
537
558
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
538
559
  VALUE ERBIfNode = rb_define_class_under(AST, "ERBIfNode", Node);
539
560
 
540
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
561
+ hb_string_T node_type = ast_node_type_to_string(node);
562
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
541
563
  VALUE location = rb_location_from_c_struct(node->location);
542
564
  VALUE errors = rb_errors_array_from_c_array(node->errors);
543
565
 
@@ -573,7 +595,8 @@ static VALUE rb_erb_block_node_from_c_struct(AST_ERB_BLOCK_NODE_T* erb_block_nod
573
595
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
574
596
  VALUE ERBBlockNode = rb_define_class_under(AST, "ERBBlockNode", Node);
575
597
 
576
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
598
+ hb_string_T node_type = ast_node_type_to_string(node);
599
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
577
600
  VALUE location = rb_location_from_c_struct(node->location);
578
601
  VALUE errors = rb_errors_array_from_c_array(node->errors);
579
602
 
@@ -607,7 +630,8 @@ static VALUE rb_erb_when_node_from_c_struct(AST_ERB_WHEN_NODE_T* erb_when_node)
607
630
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
608
631
  VALUE ERBWhenNode = rb_define_class_under(AST, "ERBWhenNode", Node);
609
632
 
610
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
633
+ hb_string_T node_type = ast_node_type_to_string(node);
634
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
611
635
  VALUE location = rb_location_from_c_struct(node->location);
612
636
  VALUE errors = rb_errors_array_from_c_array(node->errors);
613
637
 
@@ -639,7 +663,8 @@ static VALUE rb_erb_case_node_from_c_struct(AST_ERB_CASE_NODE_T* erb_case_node)
639
663
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
640
664
  VALUE ERBCaseNode = rb_define_class_under(AST, "ERBCaseNode", Node);
641
665
 
642
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
666
+ hb_string_T node_type = ast_node_type_to_string(node);
667
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
643
668
  VALUE location = rb_location_from_c_struct(node->location);
644
669
  VALUE errors = rb_errors_array_from_c_array(node->errors);
645
670
 
@@ -677,7 +702,8 @@ static VALUE rb_erb_case_match_node_from_c_struct(AST_ERB_CASE_MATCH_NODE_T* erb
677
702
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
678
703
  VALUE ERBCaseMatchNode = rb_define_class_under(AST, "ERBCaseMatchNode", Node);
679
704
 
680
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
705
+ hb_string_T node_type = ast_node_type_to_string(node);
706
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
681
707
  VALUE location = rb_location_from_c_struct(node->location);
682
708
  VALUE errors = rb_errors_array_from_c_array(node->errors);
683
709
 
@@ -715,7 +741,8 @@ static VALUE rb_erb_while_node_from_c_struct(AST_ERB_WHILE_NODE_T* erb_while_nod
715
741
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
716
742
  VALUE ERBWhileNode = rb_define_class_under(AST, "ERBWhileNode", Node);
717
743
 
718
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
744
+ hb_string_T node_type = ast_node_type_to_string(node);
745
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
719
746
  VALUE location = rb_location_from_c_struct(node->location);
720
747
  VALUE errors = rb_errors_array_from_c_array(node->errors);
721
748
 
@@ -749,7 +776,8 @@ static VALUE rb_erb_until_node_from_c_struct(AST_ERB_UNTIL_NODE_T* erb_until_nod
749
776
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
750
777
  VALUE ERBUntilNode = rb_define_class_under(AST, "ERBUntilNode", Node);
751
778
 
752
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
779
+ hb_string_T node_type = ast_node_type_to_string(node);
780
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
753
781
  VALUE location = rb_location_from_c_struct(node->location);
754
782
  VALUE errors = rb_errors_array_from_c_array(node->errors);
755
783
 
@@ -783,7 +811,8 @@ static VALUE rb_erb_for_node_from_c_struct(AST_ERB_FOR_NODE_T* erb_for_node) {
783
811
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
784
812
  VALUE ERBForNode = rb_define_class_under(AST, "ERBForNode", Node);
785
813
 
786
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
814
+ hb_string_T node_type = ast_node_type_to_string(node);
815
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
787
816
  VALUE location = rb_location_from_c_struct(node->location);
788
817
  VALUE errors = rb_errors_array_from_c_array(node->errors);
789
818
 
@@ -817,7 +846,8 @@ static VALUE rb_erb_rescue_node_from_c_struct(AST_ERB_RESCUE_NODE_T* erb_rescue_
817
846
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
818
847
  VALUE ERBRescueNode = rb_define_class_under(AST, "ERBRescueNode", Node);
819
848
 
820
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
849
+ hb_string_T node_type = ast_node_type_to_string(node);
850
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
821
851
  VALUE location = rb_location_from_c_struct(node->location);
822
852
  VALUE errors = rb_errors_array_from_c_array(node->errors);
823
853
 
@@ -851,7 +881,8 @@ static VALUE rb_erb_ensure_node_from_c_struct(AST_ERB_ENSURE_NODE_T* erb_ensure_
851
881
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
852
882
  VALUE ERBEnsureNode = rb_define_class_under(AST, "ERBEnsureNode", Node);
853
883
 
854
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
884
+ hb_string_T node_type = ast_node_type_to_string(node);
885
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
855
886
  VALUE location = rb_location_from_c_struct(node->location);
856
887
  VALUE errors = rb_errors_array_from_c_array(node->errors);
857
888
 
@@ -883,7 +914,8 @@ static VALUE rb_erb_begin_node_from_c_struct(AST_ERB_BEGIN_NODE_T* erb_begin_nod
883
914
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
884
915
  VALUE ERBBeginNode = rb_define_class_under(AST, "ERBBeginNode", Node);
885
916
 
886
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
917
+ hb_string_T node_type = ast_node_type_to_string(node);
918
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
887
919
  VALUE location = rb_location_from_c_struct(node->location);
888
920
  VALUE errors = rb_errors_array_from_c_array(node->errors);
889
921
 
@@ -923,7 +955,8 @@ static VALUE rb_erb_unless_node_from_c_struct(AST_ERB_UNLESS_NODE_T* erb_unless_
923
955
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
924
956
  VALUE ERBUnlessNode = rb_define_class_under(AST, "ERBUnlessNode", Node);
925
957
 
926
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
958
+ hb_string_T node_type = ast_node_type_to_string(node);
959
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
927
960
  VALUE location = rb_location_from_c_struct(node->location);
928
961
  VALUE errors = rb_errors_array_from_c_array(node->errors);
929
962
 
@@ -959,7 +992,8 @@ static VALUE rb_erb_yield_node_from_c_struct(AST_ERB_YIELD_NODE_T* erb_yield_nod
959
992
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
960
993
  VALUE ERBYieldNode = rb_define_class_under(AST, "ERBYieldNode", Node);
961
994
 
962
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
995
+ hb_string_T node_type = ast_node_type_to_string(node);
996
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
963
997
  VALUE location = rb_location_from_c_struct(node->location);
964
998
  VALUE errors = rb_errors_array_from_c_array(node->errors);
965
999
 
@@ -989,7 +1023,8 @@ static VALUE rb_erb_in_node_from_c_struct(AST_ERB_IN_NODE_T* erb_in_node) {
989
1023
  VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
990
1024
  VALUE ERBInNode = rb_define_class_under(AST, "ERBInNode", Node);
991
1025
 
992
- VALUE type = rb_utf8_str_new_cstr(ast_node_type_to_string(node));
1026
+ hb_string_T node_type = ast_node_type_to_string(node);
1027
+ VALUE type = rb_utf8_str_new(node_type.data, node_type.length);
993
1028
  VALUE location = rb_location_from_c_struct(node->location);
994
1029
  VALUE errors = rb_errors_array_from_c_array(node->errors);
995
1030
 
@@ -1052,12 +1087,12 @@ VALUE rb_node_from_c_struct(AST_NODE_T* node) {
1052
1087
  return Qnil;
1053
1088
  }
1054
1089
 
1055
- static VALUE rb_nodes_array_from_c_array(array_T* array) {
1090
+ static VALUE rb_nodes_array_from_c_array(hb_array_T* array) {
1056
1091
  VALUE rb_array = rb_ary_new();
1057
1092
 
1058
1093
  if (array) {
1059
- for (size_t i = 0; i < array_size(array); i++) {
1060
- AST_NODE_T* child_node = (AST_NODE_T*) array_get(array, i);
1094
+ for (size_t i = 0; i < hb_array_size(array); i++) {
1095
+ AST_NODE_T* child_node = (AST_NODE_T*) hb_array_get(array, i);
1061
1096
 
1062
1097
  if (child_node) {
1063
1098
  VALUE rb_child = rb_node_from_c_struct(child_node);
data/herb.gemspec CHANGED
@@ -48,6 +48,4 @@ Gem::Specification.new do |spec|
48
48
  spec.metadata["source_code_uri"] = "https://github.com/marcoroth/herb"
49
49
  spec.metadata["bug_tracker_uri"] = "https://github.com/marcoroth/herb/issues"
50
50
  spec.metadata["documentation_uri"] = "https://docs.herb-tools.dev"
51
-
52
- # spec.add_dependency "ffi"
53
51
  end
@@ -21,6 +21,17 @@ module Herb
21
21
  def erb_output?(opening)
22
22
  opening.include?("=")
23
23
  end
24
+
25
+ #: (Herb::AST::ERBContentNode) -> bool
26
+ def inline_ruby_comment?(node)
27
+ return false unless node.is_a?(Herb::AST::ERBContentNode)
28
+ return false if erb_comment?(node.tag_opening&.value || "")
29
+
30
+ content = node.content&.value || ""
31
+ stripped = content.lstrip
32
+
33
+ stripped.start_with?("#") && node.location.start.line == node.location.end.line
34
+ end
24
35
  end
25
36
  end
26
37
  end
data/lib/herb/ast/node.rb CHANGED
@@ -46,8 +46,15 @@ module Herb
46
46
  "├── errors: #{inspect_array(errors, item_name: "error", prefix: prefix)}"
47
47
  end
48
48
 
49
- #: (Array[Herb::AST::Node|Herb::Errors::Error], ?item_name: String, ?prefix: String) -> String
50
- def inspect_array(array, item_name: "item", prefix: " ")
49
+ #: (
50
+ #| Array[Herb::AST::Node|Herb::Errors::Error],
51
+ #| ?item_name: String,
52
+ #| ?prefix: String,
53
+ #| ?indent: Integer,
54
+ #| ?depth: Integer,
55
+ #| ?depth_limit: Integer
56
+ #| ) -> String
57
+ def inspect_array(array, item_name: "item", prefix: " ", indent: 0, depth: 0, depth_limit: 25)
51
58
  output = +""
52
59
 
53
60
  if array.any?
@@ -55,10 +62,12 @@ module Herb
55
62
  output += "\n"
56
63
 
57
64
  items = array.map { |item|
65
+ kwargs = { indent: indent, depth: depth, depth_limit: depth_limit }
66
+
58
67
  if array.last == item
59
- "└── #{item.tree_inspect.gsub(/^/, " ").lstrip}"
68
+ "└── #{item.tree_inspect(**kwargs).gsub(/^/, " ").lstrip}"
60
69
  else
61
- "├── #{item.tree_inspect.gsub(/^/, "│ ")}".gsub("├── │ ", "├──")
70
+ "├── #{item.tree_inspect(**kwargs).gsub(/^/, "│ ")}".gsub("├── │ ", "├──")
62
71
  end
63
72
  }
64
73
 
@@ -71,8 +80,8 @@ module Herb
71
80
  output
72
81
  end
73
82
 
74
- #: (?Integer) -> String
75
- def tree_inspect(_indent = 0)
83
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
84
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 25)
76
85
  raise NotImplementedError
77
86
  end
78
87