herb 0.7.5-x86_64-darwin → 0.8.1-x86_64-darwin

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 (166) 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/3.0/herb.bundle +0 -0
  13. data/lib/herb/3.1/herb.bundle +0 -0
  14. data/lib/herb/3.2/herb.bundle +0 -0
  15. data/lib/herb/3.3/herb.bundle +0 -0
  16. data/lib/herb/3.4/herb.bundle +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 +8 -14
  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 +549 -204
  42. data/src/analyze_helpers.c +17 -4
  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 +5 -5
  47. data/src/ast_nodes.c +179 -179
  48. data/src/ast_pretty_print.c +232 -232
  49. data/src/element_source.c +7 -6
  50. data/src/errors.c +246 -126
  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 +2 -2
  58. data/src/include/ast_nodes.h +67 -66
  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 +30 -14
  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 +14 -14
  67. data/src/include/lexer_struct.h +3 -2
  68. data/src/include/macros.h +4 -0
  69. data/src/include/parser.h +12 -6
  70. data/src/include/parser_helpers.h +25 -15
  71. data/src/include/pretty_print.h +38 -28
  72. data/src/include/token.h +5 -8
  73. data/src/include/utf8.h +3 -2
  74. data/src/include/util/hb_arena.h +31 -0
  75. data/src/include/util/hb_arena_debug.h +8 -0
  76. data/src/include/util/hb_array.h +33 -0
  77. data/src/include/util/hb_buffer.h +33 -0
  78. data/src/include/util/hb_string.h +29 -0
  79. data/src/include/util/hb_system.h +9 -0
  80. data/src/include/util.h +3 -14
  81. data/src/include/version.h +1 -1
  82. data/src/include/visitor.h +1 -1
  83. data/src/io.c +7 -4
  84. data/src/lexer.c +61 -88
  85. data/src/lexer_peek_helpers.c +35 -37
  86. data/src/main.c +19 -23
  87. data/src/parser.c +280 -201
  88. data/src/parser_helpers.c +46 -40
  89. data/src/parser_match_tags.c +316 -0
  90. data/src/pretty_print.c +82 -106
  91. data/src/token.c +18 -65
  92. data/src/utf8.c +4 -4
  93. data/src/util/hb_arena.c +179 -0
  94. data/src/util/hb_arena_debug.c +237 -0
  95. data/src/{array.c → util/hb_array.c} +26 -27
  96. data/src/util/hb_buffer.c +194 -0
  97. data/src/util/hb_string.c +85 -0
  98. data/src/util/hb_system.c +30 -0
  99. data/src/util.c +29 -99
  100. data/src/visitor.c +54 -54
  101. data/templates/ext/herb/error_helpers.c.erb +3 -3
  102. data/templates/ext/herb/error_helpers.h.erb +1 -1
  103. data/templates/ext/herb/nodes.c.erb +11 -6
  104. data/templates/java/error_helpers.c.erb +75 -0
  105. data/templates/java/error_helpers.h.erb +20 -0
  106. data/templates/java/nodes.c.erb +97 -0
  107. data/templates/java/nodes.h.erb +23 -0
  108. data/templates/java/org/herb/ast/Errors.java.erb +121 -0
  109. data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
  110. data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
  111. data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
  112. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
  113. data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
  114. data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
  115. data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
  116. data/templates/lib/herb/ast/nodes.rb.erb +28 -16
  117. data/templates/lib/herb/errors.rb.erb +17 -12
  118. data/templates/rust/src/ast/nodes.rs.erb +220 -0
  119. data/templates/rust/src/errors.rs.erb +216 -0
  120. data/templates/rust/src/nodes.rs.erb +374 -0
  121. data/templates/src/analyze_missing_end.c.erb +36 -0
  122. data/templates/src/analyze_transform.c.erb +24 -0
  123. data/templates/src/ast_nodes.c.erb +14 -14
  124. data/templates/src/ast_pretty_print.c.erb +36 -36
  125. data/templates/src/errors.c.erb +31 -31
  126. data/templates/src/include/ast_nodes.h.erb +10 -9
  127. data/templates/src/include/ast_pretty_print.h.erb +2 -2
  128. data/templates/src/include/errors.h.erb +6 -6
  129. data/templates/src/parser_match_tags.c.erb +38 -0
  130. data/templates/src/visitor.c.erb +4 -4
  131. data/templates/template.rb +22 -3
  132. data/templates/wasm/error_helpers.cpp.erb +9 -9
  133. data/templates/wasm/error_helpers.h.erb +1 -1
  134. data/templates/wasm/nodes.cpp.erb +9 -9
  135. data/templates/wasm/nodes.h.erb +1 -1
  136. data/vendor/prism/Rakefile +4 -1
  137. data/vendor/prism/config.yml +2 -1
  138. data/vendor/prism/include/prism/ast.h +31 -1
  139. data/vendor/prism/include/prism/diagnostic.h +1 -0
  140. data/vendor/prism/include/prism/version.h +3 -3
  141. data/vendor/prism/src/diagnostic.c +3 -1
  142. data/vendor/prism/src/prism.c +130 -71
  143. data/vendor/prism/src/util/pm_string.c +6 -8
  144. data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
  145. data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
  146. data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
  147. data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
  148. data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
  149. data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
  150. metadata +34 -20
  151. data/lib/herb/libherb/array.rb +0 -51
  152. data/lib/herb/libherb/ast_node.rb +0 -50
  153. data/lib/herb/libherb/buffer.rb +0 -56
  154. data/lib/herb/libherb/extract_result.rb +0 -20
  155. data/lib/herb/libherb/lex_result.rb +0 -32
  156. data/lib/herb/libherb/libherb.rb +0 -52
  157. data/lib/herb/libherb/parse_result.rb +0 -20
  158. data/lib/herb/libherb/token.rb +0 -46
  159. data/lib/herb/libherb.rb +0 -35
  160. data/src/buffer.c +0 -241
  161. data/src/include/array.h +0 -33
  162. data/src/include/buffer.h +0 -39
  163. data/src/include/json.h +0 -28
  164. data/src/include/memory.h +0 -12
  165. data/src/json.c +0 -205
  166. data/src/memory.c +0 -53
@@ -110,12 +110,20 @@ bool search_block_nodes(const pm_node_t* node, void* data) {
110
110
  analyzed_ruby_T* analyzed = (analyzed_ruby_T*) data;
111
111
 
112
112
  if (node->type == PM_BLOCK_NODE) {
113
- analyzed->has_block_node = true;
114
- return true;
115
- } else {
116
- pm_visit_child_nodes(node, search_block_nodes, analyzed);
113
+ pm_block_node_t* block_node = (pm_block_node_t*) node;
114
+
115
+ size_t opening_length = block_node->opening_loc.end - block_node->opening_loc.start;
116
+
117
+ if ((opening_length == 2 && block_node->opening_loc.start[0] == 'd' && block_node->opening_loc.start[1] == 'o')
118
+ || (opening_length == 1 && block_node->opening_loc.start[0] == '{')) {
119
+ analyzed->has_block_node = true;
120
+
121
+ return true;
122
+ }
117
123
  }
118
124
 
125
+ pm_visit_child_nodes(node, search_block_nodes, analyzed);
126
+
119
127
  return false;
120
128
  }
121
129
 
@@ -238,6 +246,11 @@ bool search_else_nodes(analyzed_ruby_T* analyzed) {
238
246
 
239
247
  bool search_end_nodes(analyzed_ruby_T* analyzed) {
240
248
  if (has_error_message(analyzed, "unexpected 'end', ignoring it")) {
249
+ if (has_error_message(analyzed, "unexpected '=', ignoring it")) {
250
+ // `=end`
251
+ return false;
252
+ }
253
+
241
254
  analyzed->has_end = true;
242
255
  return true;
243
256
  }
@@ -0,0 +1,147 @@
1
+ // NOTE: This file is generated by the templates/template.rb script and should not
2
+ // be modified manually. See /home/runner/work/herb/herb/templates/src/analyze_missing_end.c.erb
3
+
4
+ #include "include/analyze_helpers.h"
5
+ #include "include/errors.h"
6
+
7
+
8
+ void check_erb_node_for_missing_end(const AST_NODE_T* node) {
9
+ switch (node->type) {
10
+ case AST_ERB_IF_NODE: {
11
+ const AST_ERB_IF_NODE_T* erb_if_node = (const AST_ERB_IF_NODE_T*) node;
12
+
13
+ if (erb_if_node->end_node == NULL) {
14
+ append_missingerb_end_tag_error(
15
+ "`<" "%" " if " "%" ">`",
16
+ erb_if_node->tag_opening->location.start,
17
+ erb_if_node->tag_closing->location.end,
18
+ node->errors
19
+ );
20
+ }
21
+
22
+ break;
23
+ }
24
+
25
+ case AST_ERB_BLOCK_NODE: {
26
+ const AST_ERB_BLOCK_NODE_T* erb_block_node = (const AST_ERB_BLOCK_NODE_T*) node;
27
+
28
+ if (erb_block_node->end_node == NULL) {
29
+ append_missingerb_end_tag_error(
30
+ "ERB block",
31
+ erb_block_node->tag_opening->location.start,
32
+ erb_block_node->tag_closing->location.end,
33
+ node->errors
34
+ );
35
+ }
36
+
37
+ break;
38
+ }
39
+
40
+ case AST_ERB_CASE_NODE: {
41
+ const AST_ERB_CASE_NODE_T* erb_case_node = (const AST_ERB_CASE_NODE_T*) node;
42
+
43
+ if (erb_case_node->end_node == NULL) {
44
+ append_missingerb_end_tag_error(
45
+ "`<" "%" " case " "%" ">`",
46
+ erb_case_node->tag_opening->location.start,
47
+ erb_case_node->tag_closing->location.end,
48
+ node->errors
49
+ );
50
+ }
51
+
52
+ break;
53
+ }
54
+
55
+ case AST_ERB_CASE_MATCH_NODE: {
56
+ const AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = (const AST_ERB_CASE_MATCH_NODE_T*) node;
57
+
58
+ if (erb_case_match_node->end_node == NULL) {
59
+ append_missingerb_end_tag_error(
60
+ "`<" "%" " case " "%" ">`",
61
+ erb_case_match_node->tag_opening->location.start,
62
+ erb_case_match_node->tag_closing->location.end,
63
+ node->errors
64
+ );
65
+ }
66
+
67
+ break;
68
+ }
69
+
70
+ case AST_ERB_WHILE_NODE: {
71
+ const AST_ERB_WHILE_NODE_T* erb_while_node = (const AST_ERB_WHILE_NODE_T*) node;
72
+
73
+ if (erb_while_node->end_node == NULL) {
74
+ append_missingerb_end_tag_error(
75
+ "`<" "%" " while " "%" ">`",
76
+ erb_while_node->tag_opening->location.start,
77
+ erb_while_node->tag_closing->location.end,
78
+ node->errors
79
+ );
80
+ }
81
+
82
+ break;
83
+ }
84
+
85
+ case AST_ERB_UNTIL_NODE: {
86
+ const AST_ERB_UNTIL_NODE_T* erb_until_node = (const AST_ERB_UNTIL_NODE_T*) node;
87
+
88
+ if (erb_until_node->end_node == NULL) {
89
+ append_missingerb_end_tag_error(
90
+ "`<" "%" " until " "%" ">`",
91
+ erb_until_node->tag_opening->location.start,
92
+ erb_until_node->tag_closing->location.end,
93
+ node->errors
94
+ );
95
+ }
96
+
97
+ break;
98
+ }
99
+
100
+ case AST_ERB_FOR_NODE: {
101
+ const AST_ERB_FOR_NODE_T* erb_for_node = (const AST_ERB_FOR_NODE_T*) node;
102
+
103
+ if (erb_for_node->end_node == NULL) {
104
+ append_missingerb_end_tag_error(
105
+ "`<" "%" " for " "%" ">`",
106
+ erb_for_node->tag_opening->location.start,
107
+ erb_for_node->tag_closing->location.end,
108
+ node->errors
109
+ );
110
+ }
111
+
112
+ break;
113
+ }
114
+
115
+ case AST_ERB_BEGIN_NODE: {
116
+ const AST_ERB_BEGIN_NODE_T* erb_begin_node = (const AST_ERB_BEGIN_NODE_T*) node;
117
+
118
+ if (erb_begin_node->end_node == NULL) {
119
+ append_missingerb_end_tag_error(
120
+ "`<" "%" " begin " "%" ">`",
121
+ erb_begin_node->tag_opening->location.start,
122
+ erb_begin_node->tag_closing->location.end,
123
+ node->errors
124
+ );
125
+ }
126
+
127
+ break;
128
+ }
129
+
130
+ case AST_ERB_UNLESS_NODE: {
131
+ const AST_ERB_UNLESS_NODE_T* erb_unless_node = (const AST_ERB_UNLESS_NODE_T*) node;
132
+
133
+ if (erb_unless_node->end_node == NULL) {
134
+ append_missingerb_end_tag_error(
135
+ "`<" "%" " unless " "%" ">`",
136
+ erb_unless_node->tag_opening->location.start,
137
+ erb_unless_node->tag_closing->location.end,
138
+ node->errors
139
+ );
140
+ }
141
+
142
+ break;
143
+ }
144
+
145
+ default: break;
146
+ }
147
+ }
@@ -0,0 +1,196 @@
1
+ // NOTE: This file is generated by the templates/template.rb script and should not
2
+ // be modified manually. See /home/runner/work/herb/herb/templates/src/analyze_transform.c.erb
3
+
4
+ #include "include/analyze.h"
5
+ #include "include/visitor.h"
6
+
7
+ bool transform_erb_nodes(const AST_NODE_T* node, void* data) {
8
+ analyze_ruby_context_T* context = (analyze_ruby_context_T*) data;
9
+ context->parent = (AST_NODE_T*) node;
10
+
11
+ if (node->type == AST_DOCUMENT_NODE) {
12
+ AST_DOCUMENT_NODE_T* document_node = (AST_DOCUMENT_NODE_T*) node;
13
+ hb_array_T* old_array = document_node->children;
14
+ document_node->children = rewrite_node_array((AST_NODE_T*) node, document_node->children, context);
15
+ hb_array_free(&old_array);
16
+ }
17
+
18
+ if (node->type == AST_HTML_OPEN_TAG_NODE) {
19
+ AST_HTML_OPEN_TAG_NODE_T* html_open_tag_node = (AST_HTML_OPEN_TAG_NODE_T*) node;
20
+ hb_array_T* old_array = html_open_tag_node->children;
21
+ html_open_tag_node->children = rewrite_node_array((AST_NODE_T*) node, html_open_tag_node->children, context);
22
+ hb_array_free(&old_array);
23
+ }
24
+
25
+ if (node->type == AST_HTML_CLOSE_TAG_NODE) {
26
+ AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node = (AST_HTML_CLOSE_TAG_NODE_T*) node;
27
+ hb_array_T* old_array = html_close_tag_node->children;
28
+ html_close_tag_node->children = rewrite_node_array((AST_NODE_T*) node, html_close_tag_node->children, context);
29
+ hb_array_free(&old_array);
30
+ }
31
+
32
+ if (node->type == AST_HTML_ELEMENT_NODE) {
33
+ AST_HTML_ELEMENT_NODE_T* html_element_node = (AST_HTML_ELEMENT_NODE_T*) node;
34
+ hb_array_T* old_array = html_element_node->body;
35
+ html_element_node->body = rewrite_node_array((AST_NODE_T*) node, html_element_node->body, context);
36
+ hb_array_free(&old_array);
37
+ }
38
+
39
+ if (node->type == AST_HTML_ATTRIBUTE_VALUE_NODE) {
40
+ AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node = (AST_HTML_ATTRIBUTE_VALUE_NODE_T*) node;
41
+ hb_array_T* old_array = html_attribute_value_node->children;
42
+ html_attribute_value_node->children = rewrite_node_array((AST_NODE_T*) node, html_attribute_value_node->children, context);
43
+ hb_array_free(&old_array);
44
+ }
45
+
46
+ if (node->type == AST_HTML_ATTRIBUTE_NAME_NODE) {
47
+ AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node = (AST_HTML_ATTRIBUTE_NAME_NODE_T*) node;
48
+ hb_array_T* old_array = html_attribute_name_node->children;
49
+ html_attribute_name_node->children = rewrite_node_array((AST_NODE_T*) node, html_attribute_name_node->children, context);
50
+ hb_array_free(&old_array);
51
+ }
52
+
53
+ if (node->type == AST_HTML_COMMENT_NODE) {
54
+ AST_HTML_COMMENT_NODE_T* html_comment_node = (AST_HTML_COMMENT_NODE_T*) node;
55
+ hb_array_T* old_array = html_comment_node->children;
56
+ html_comment_node->children = rewrite_node_array((AST_NODE_T*) node, html_comment_node->children, context);
57
+ hb_array_free(&old_array);
58
+ }
59
+
60
+ if (node->type == AST_HTML_DOCTYPE_NODE) {
61
+ AST_HTML_DOCTYPE_NODE_T* html_doctype_node = (AST_HTML_DOCTYPE_NODE_T*) node;
62
+ hb_array_T* old_array = html_doctype_node->children;
63
+ html_doctype_node->children = rewrite_node_array((AST_NODE_T*) node, html_doctype_node->children, context);
64
+ hb_array_free(&old_array);
65
+ }
66
+
67
+ if (node->type == AST_XML_DECLARATION_NODE) {
68
+ AST_XML_DECLARATION_NODE_T* xml_declaration_node = (AST_XML_DECLARATION_NODE_T*) node;
69
+ hb_array_T* old_array = xml_declaration_node->children;
70
+ xml_declaration_node->children = rewrite_node_array((AST_NODE_T*) node, xml_declaration_node->children, context);
71
+ hb_array_free(&old_array);
72
+ }
73
+
74
+ if (node->type == AST_CDATA_NODE) {
75
+ AST_CDATA_NODE_T* cdata_node = (AST_CDATA_NODE_T*) node;
76
+ hb_array_T* old_array = cdata_node->children;
77
+ cdata_node->children = rewrite_node_array((AST_NODE_T*) node, cdata_node->children, context);
78
+ hb_array_free(&old_array);
79
+ }
80
+
81
+ if (node->type == AST_ERB_ELSE_NODE) {
82
+ AST_ERB_ELSE_NODE_T* erb_else_node = (AST_ERB_ELSE_NODE_T*) node;
83
+ hb_array_T* old_array = erb_else_node->statements;
84
+ erb_else_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_else_node->statements, context);
85
+ hb_array_free(&old_array);
86
+ }
87
+
88
+ if (node->type == AST_ERB_IF_NODE) {
89
+ AST_ERB_IF_NODE_T* erb_if_node = (AST_ERB_IF_NODE_T*) node;
90
+ hb_array_T* old_array = erb_if_node->statements;
91
+ erb_if_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_if_node->statements, context);
92
+ hb_array_free(&old_array);
93
+ }
94
+
95
+ if (node->type == AST_ERB_BLOCK_NODE) {
96
+ AST_ERB_BLOCK_NODE_T* erb_block_node = (AST_ERB_BLOCK_NODE_T*) node;
97
+ hb_array_T* old_array = erb_block_node->body;
98
+ erb_block_node->body = rewrite_node_array((AST_NODE_T*) node, erb_block_node->body, context);
99
+ hb_array_free(&old_array);
100
+ }
101
+
102
+ if (node->type == AST_ERB_WHEN_NODE) {
103
+ AST_ERB_WHEN_NODE_T* erb_when_node = (AST_ERB_WHEN_NODE_T*) node;
104
+ hb_array_T* old_array = erb_when_node->statements;
105
+ erb_when_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_when_node->statements, context);
106
+ hb_array_free(&old_array);
107
+ }
108
+
109
+ if (node->type == AST_ERB_CASE_NODE) {
110
+ AST_ERB_CASE_NODE_T* erb_case_node = (AST_ERB_CASE_NODE_T*) node;
111
+ hb_array_T* old_array = erb_case_node->children;
112
+ erb_case_node->children = rewrite_node_array((AST_NODE_T*) node, erb_case_node->children, context);
113
+ hb_array_free(&old_array);
114
+ }
115
+
116
+ if (node->type == AST_ERB_CASE_NODE) {
117
+ AST_ERB_CASE_NODE_T* erb_case_node = (AST_ERB_CASE_NODE_T*) node;
118
+ hb_array_T* old_array = erb_case_node->conditions;
119
+ erb_case_node->conditions = rewrite_node_array((AST_NODE_T*) node, erb_case_node->conditions, context);
120
+ hb_array_free(&old_array);
121
+ }
122
+
123
+ if (node->type == AST_ERB_CASE_MATCH_NODE) {
124
+ AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = (AST_ERB_CASE_MATCH_NODE_T*) node;
125
+ hb_array_T* old_array = erb_case_match_node->children;
126
+ erb_case_match_node->children = rewrite_node_array((AST_NODE_T*) node, erb_case_match_node->children, context);
127
+ hb_array_free(&old_array);
128
+ }
129
+
130
+ if (node->type == AST_ERB_CASE_MATCH_NODE) {
131
+ AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = (AST_ERB_CASE_MATCH_NODE_T*) node;
132
+ hb_array_T* old_array = erb_case_match_node->conditions;
133
+ erb_case_match_node->conditions = rewrite_node_array((AST_NODE_T*) node, erb_case_match_node->conditions, context);
134
+ hb_array_free(&old_array);
135
+ }
136
+
137
+ if (node->type == AST_ERB_WHILE_NODE) {
138
+ AST_ERB_WHILE_NODE_T* erb_while_node = (AST_ERB_WHILE_NODE_T*) node;
139
+ hb_array_T* old_array = erb_while_node->statements;
140
+ erb_while_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_while_node->statements, context);
141
+ hb_array_free(&old_array);
142
+ }
143
+
144
+ if (node->type == AST_ERB_UNTIL_NODE) {
145
+ AST_ERB_UNTIL_NODE_T* erb_until_node = (AST_ERB_UNTIL_NODE_T*) node;
146
+ hb_array_T* old_array = erb_until_node->statements;
147
+ erb_until_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_until_node->statements, context);
148
+ hb_array_free(&old_array);
149
+ }
150
+
151
+ if (node->type == AST_ERB_FOR_NODE) {
152
+ AST_ERB_FOR_NODE_T* erb_for_node = (AST_ERB_FOR_NODE_T*) node;
153
+ hb_array_T* old_array = erb_for_node->statements;
154
+ erb_for_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_for_node->statements, context);
155
+ hb_array_free(&old_array);
156
+ }
157
+
158
+ if (node->type == AST_ERB_RESCUE_NODE) {
159
+ AST_ERB_RESCUE_NODE_T* erb_rescue_node = (AST_ERB_RESCUE_NODE_T*) node;
160
+ hb_array_T* old_array = erb_rescue_node->statements;
161
+ erb_rescue_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_rescue_node->statements, context);
162
+ hb_array_free(&old_array);
163
+ }
164
+
165
+ if (node->type == AST_ERB_ENSURE_NODE) {
166
+ AST_ERB_ENSURE_NODE_T* erb_ensure_node = (AST_ERB_ENSURE_NODE_T*) node;
167
+ hb_array_T* old_array = erb_ensure_node->statements;
168
+ erb_ensure_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_ensure_node->statements, context);
169
+ hb_array_free(&old_array);
170
+ }
171
+
172
+ if (node->type == AST_ERB_BEGIN_NODE) {
173
+ AST_ERB_BEGIN_NODE_T* erb_begin_node = (AST_ERB_BEGIN_NODE_T*) node;
174
+ hb_array_T* old_array = erb_begin_node->statements;
175
+ erb_begin_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_begin_node->statements, context);
176
+ hb_array_free(&old_array);
177
+ }
178
+
179
+ if (node->type == AST_ERB_UNLESS_NODE) {
180
+ AST_ERB_UNLESS_NODE_T* erb_unless_node = (AST_ERB_UNLESS_NODE_T*) node;
181
+ hb_array_T* old_array = erb_unless_node->statements;
182
+ erb_unless_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_unless_node->statements, context);
183
+ hb_array_free(&old_array);
184
+ }
185
+
186
+ if (node->type == AST_ERB_IN_NODE) {
187
+ AST_ERB_IN_NODE_T* erb_in_node = (AST_ERB_IN_NODE_T*) node;
188
+ hb_array_T* old_array = erb_in_node->statements;
189
+ erb_in_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_in_node->statements, context);
190
+ hb_array_free(&old_array);
191
+ }
192
+
193
+ herb_visit_child_nodes(node, transform_erb_nodes, data);
194
+
195
+ return false;
196
+ }
data/src/analyzed_ruby.c CHANGED
@@ -1,12 +1,13 @@
1
1
  #include "include/analyzed_ruby.h"
2
+ #include "include/util/hb_string.h"
2
3
 
3
4
  #include <prism.h>
4
5
  #include <string.h>
5
6
 
6
- analyzed_ruby_T* init_analyzed_ruby(char* source) {
7
+ analyzed_ruby_T* init_analyzed_ruby(hb_string_T source) {
7
8
  analyzed_ruby_T* analyzed = malloc(sizeof(analyzed_ruby_T));
8
9
 
9
- pm_parser_init(&analyzed->parser, (const uint8_t*) source, strlen(source), NULL);
10
+ pm_parser_init(&analyzed->parser, (const uint8_t*) source.data, source.length, NULL);
10
11
 
11
12
  analyzed->root = pm_parse(&analyzed->parser);
12
13
  analyzed->valid = (analyzed->parser.error_list.size == 0);
@@ -42,3 +43,23 @@ void free_analyzed_ruby(analyzed_ruby_T* analyzed) {
42
43
 
43
44
  free(analyzed);
44
45
  }
46
+
47
+ const char* erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed) {
48
+ if (analyzed->has_end) {
49
+ return "`<% end %>`";
50
+ } else if (analyzed->has_else_node) {
51
+ return "`<% else %>`";
52
+ } else if (analyzed->has_elsif_node) {
53
+ return "`<% elsif %>`";
54
+ } else if (analyzed->has_when_node) {
55
+ return "`<% when %>`";
56
+ } else if (analyzed->has_in_node) {
57
+ return "`<% in %>`";
58
+ } else if (analyzed->has_rescue_node) {
59
+ return "`<% rescue %>`";
60
+ } else if (analyzed->has_ensure_node) {
61
+ return "`<% ensure %>`";
62
+ }
63
+
64
+ return NULL;
65
+ }
data/src/ast_node.c CHANGED
@@ -12,7 +12,7 @@ size_t ast_node_sizeof(void) {
12
12
  return sizeof(struct AST_NODE_STRUCT);
13
13
  }
14
14
 
15
- void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T start, position_T end, array_T* errors) {
15
+ void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T start, position_T end, hb_array_T* errors) {
16
16
  if (!node) { return; }
17
17
 
18
18
  node->type = type;
@@ -20,7 +20,7 @@ void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T star
20
20
  node->location.end = end;
21
21
 
22
22
  if (errors == NULL) {
23
- node->errors = array_init(8);
23
+ node->errors = hb_array_init(8);
24
24
  } else {
25
25
  node->errors = errors;
26
26
  }
@@ -41,15 +41,15 @@ ast_node_type_T ast_node_type(const AST_NODE_T* node) {
41
41
  }
42
42
 
43
43
  size_t ast_node_errors_count(const AST_NODE_T* node) {
44
- return array_size(node->errors);
44
+ return hb_array_size(node->errors);
45
45
  }
46
46
 
47
- array_T* ast_node_errors(const AST_NODE_T* node) {
47
+ hb_array_T* ast_node_errors(const AST_NODE_T* node) {
48
48
  return node->errors;
49
49
  }
50
50
 
51
51
  void ast_node_append_error(const AST_NODE_T* node, ERROR_T* error) {
52
- array_append(node->errors, error);
52
+ hb_array_append(node->errors, error);
53
53
  }
54
54
 
55
55
  void ast_node_set_start(AST_NODE_T* node, position_T position) {