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
@@ -238,6 +238,11 @@ bool search_else_nodes(analyzed_ruby_T* analyzed) {
238
238
 
239
239
  bool search_end_nodes(analyzed_ruby_T* analyzed) {
240
240
  if (has_error_message(analyzed, "unexpected 'end', ignoring it")) {
241
+ if (has_error_message(analyzed, "unexpected '=', ignoring it")) {
242
+ // `=end`
243
+ return false;
244
+ }
245
+
241
246
  analyzed->has_end = true;
242
247
  return true;
243
248
  }
@@ -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,14 +12,15 @@ 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;
19
- node->location = location_init(position_copy(start), position_copy(end));
19
+ node->location.start = start;
20
+ node->location.end = end;
20
21
 
21
22
  if (errors == NULL) {
22
- node->errors = array_init(8);
23
+ node->errors = hb_array_init(8);
23
24
  } else {
24
25
  node->errors = errors;
25
26
  }
@@ -28,7 +29,7 @@ void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T* sta
28
29
  AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token) {
29
30
  AST_LITERAL_NODE_T* literal = malloc(sizeof(AST_LITERAL_NODE_T));
30
31
 
31
- ast_node_init(&literal->base, AST_LITERAL_NODE, token->location->start, token->location->end, NULL);
32
+ ast_node_init(&literal->base, AST_LITERAL_NODE, token->location.start, token->location.end, NULL);
32
33
 
33
34
  literal->content = herb_strdup(token->value);
34
35
 
@@ -40,35 +41,31 @@ ast_node_type_T ast_node_type(const AST_NODE_T* node) {
40
41
  }
41
42
 
42
43
  size_t ast_node_errors_count(const AST_NODE_T* node) {
43
- return array_size(node->errors);
44
+ return hb_array_size(node->errors);
44
45
  }
45
46
 
46
- array_T* ast_node_errors(const AST_NODE_T* node) {
47
+ hb_array_T* ast_node_errors(const AST_NODE_T* node) {
47
48
  return node->errors;
48
49
  }
49
50
 
50
51
  void ast_node_append_error(const AST_NODE_T* node, ERROR_T* error) {
51
- array_append(node->errors, error);
52
+ hb_array_append(node->errors, error);
52
53
  }
53
54
 
54
- void ast_node_set_start(AST_NODE_T* node, position_T* position) {
55
- if (node->location->start != NULL) { position_free(node->location->start); }
56
-
57
- node->location->start = position_copy(position);
55
+ void ast_node_set_start(AST_NODE_T* node, position_T position) {
56
+ node->location.start = position;
58
57
  }
59
58
 
60
- void ast_node_set_end(AST_NODE_T* node, position_T* position) {
61
- if (node->location->end != NULL) { position_free(node->location->end); }
62
-
63
- node->location->end = position_copy(position);
59
+ void ast_node_set_end(AST_NODE_T* node, position_T position) {
60
+ node->location.end = position;
64
61
  }
65
62
 
66
63
  void ast_node_set_start_from_token(AST_NODE_T* node, const token_T* token) {
67
- ast_node_set_start(node, token->location->start);
64
+ ast_node_set_start(node, token->location.start);
68
65
  }
69
66
 
70
67
  void ast_node_set_end_from_token(AST_NODE_T* node, const token_T* token) {
71
- ast_node_set_end(node, token->location->end);
68
+ ast_node_set_end(node, token->location.end);
72
69
  }
73
70
 
74
71
  void ast_node_set_positions_from_token(AST_NODE_T* node, const token_T* token) {