@herb-tools/node 0.8.10 → 0.9.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 (169) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/binding.gyp +26 -8
  3. package/dist/herb-node.cjs +41 -12
  4. package/dist/herb-node.cjs.map +1 -1
  5. package/dist/herb-node.esm.js +8 -1
  6. package/dist/herb-node.esm.js.map +1 -1
  7. package/dist/types/node-backend.d.ts +3 -1
  8. package/extension/error_helpers.cpp +395 -73
  9. package/extension/error_helpers.h +13 -3
  10. package/extension/extension_helpers.cpp +38 -35
  11. package/extension/extension_helpers.h +2 -2
  12. package/extension/herb.cpp +183 -64
  13. package/extension/libherb/analyze/action_view/attribute_extraction_helpers.c +290 -0
  14. package/extension/libherb/analyze/action_view/attribute_extraction_helpers.h +36 -0
  15. package/extension/libherb/analyze/action_view/content_tag.c +70 -0
  16. package/extension/libherb/analyze/action_view/link_to.c +143 -0
  17. package/extension/libherb/analyze/action_view/registry.c +60 -0
  18. package/extension/libherb/analyze/action_view/tag.c +64 -0
  19. package/extension/libherb/analyze/action_view/tag_helper_handler.h +41 -0
  20. package/extension/libherb/analyze/action_view/tag_helper_node_builders.c +305 -0
  21. package/extension/libherb/analyze/action_view/tag_helper_node_builders.h +70 -0
  22. package/extension/libherb/analyze/action_view/tag_helpers.c +748 -0
  23. package/extension/libherb/analyze/action_view/tag_helpers.h +38 -0
  24. package/extension/libherb/analyze/action_view/turbo_frame_tag.c +88 -0
  25. package/extension/libherb/analyze/analyze.c +882 -0
  26. package/extension/libherb/{include → analyze}/analyze.h +14 -4
  27. package/extension/libherb/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
  28. package/extension/libherb/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
  29. package/extension/libherb/analyze/builders.c +343 -0
  30. package/extension/libherb/analyze/builders.h +27 -0
  31. package/extension/libherb/analyze/conditional_elements.c +594 -0
  32. package/extension/libherb/analyze/conditional_elements.h +9 -0
  33. package/extension/libherb/analyze/conditional_open_tags.c +640 -0
  34. package/extension/libherb/analyze/conditional_open_tags.h +9 -0
  35. package/extension/libherb/analyze/control_type.c +250 -0
  36. package/extension/libherb/analyze/control_type.h +14 -0
  37. package/extension/libherb/{analyze_helpers.c → analyze/helpers.c} +48 -23
  38. package/extension/libherb/{analyze_helpers.h → analyze/helpers.h} +4 -2
  39. package/extension/libherb/analyze/invalid_structures.c +193 -0
  40. package/extension/libherb/analyze/invalid_structures.h +11 -0
  41. package/extension/libherb/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
  42. package/extension/libherb/analyze/parse_errors.c +84 -0
  43. package/extension/libherb/analyze/prism_annotate.c +397 -0
  44. package/extension/libherb/analyze/prism_annotate.h +16 -0
  45. package/extension/libherb/{analyze_transform.c → analyze/transform.c} +17 -3
  46. package/extension/libherb/ast_node.c +17 -7
  47. package/extension/libherb/ast_node.h +11 -5
  48. package/extension/libherb/ast_nodes.c +663 -388
  49. package/extension/libherb/ast_nodes.h +118 -39
  50. package/extension/libherb/ast_pretty_print.c +191 -7
  51. package/extension/libherb/ast_pretty_print.h +6 -1
  52. package/extension/libherb/element_source.h +3 -8
  53. package/extension/libherb/errors.c +1077 -521
  54. package/extension/libherb/errors.h +149 -56
  55. package/extension/libherb/extract.c +145 -49
  56. package/extension/libherb/extract.h +21 -5
  57. package/extension/libherb/herb.c +52 -34
  58. package/extension/libherb/herb.h +18 -6
  59. package/extension/libherb/herb_prism_node.h +13 -0
  60. package/extension/libherb/html_util.c +241 -12
  61. package/extension/libherb/html_util.h +7 -2
  62. package/extension/libherb/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
  63. package/extension/libherb/include/analyze/action_view/tag_helper_handler.h +41 -0
  64. package/extension/libherb/include/analyze/action_view/tag_helper_node_builders.h +70 -0
  65. package/extension/libherb/include/analyze/action_view/tag_helpers.h +38 -0
  66. package/extension/libherb/{analyze.h → include/analyze/analyze.h} +14 -4
  67. package/extension/libherb/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
  68. package/extension/libherb/include/analyze/builders.h +27 -0
  69. package/extension/libherb/include/analyze/conditional_elements.h +9 -0
  70. package/extension/libherb/include/analyze/conditional_open_tags.h +9 -0
  71. package/extension/libherb/include/analyze/control_type.h +14 -0
  72. package/extension/libherb/include/{analyze_helpers.h → analyze/helpers.h} +4 -2
  73. package/extension/libherb/include/analyze/invalid_structures.h +11 -0
  74. package/extension/libherb/include/analyze/prism_annotate.h +16 -0
  75. package/extension/libherb/include/ast_node.h +11 -5
  76. package/extension/libherb/include/ast_nodes.h +118 -39
  77. package/extension/libherb/include/ast_pretty_print.h +6 -1
  78. package/extension/libherb/include/element_source.h +3 -8
  79. package/extension/libherb/include/errors.h +149 -56
  80. package/extension/libherb/include/extract.h +21 -5
  81. package/extension/libherb/include/herb.h +18 -6
  82. package/extension/libherb/include/herb_prism_node.h +13 -0
  83. package/extension/libherb/include/html_util.h +7 -2
  84. package/extension/libherb/include/io.h +3 -1
  85. package/extension/libherb/include/lex_helpers.h +29 -0
  86. package/extension/libherb/include/lexer.h +1 -1
  87. package/extension/libherb/include/lexer_peek_helpers.h +87 -13
  88. package/extension/libherb/include/lexer_struct.h +2 -0
  89. package/extension/libherb/include/location.h +2 -1
  90. package/extension/libherb/include/parser.h +27 -2
  91. package/extension/libherb/include/parser_helpers.h +19 -3
  92. package/extension/libherb/include/pretty_print.h +10 -5
  93. package/extension/libherb/include/prism_context.h +45 -0
  94. package/extension/libherb/include/prism_helpers.h +10 -7
  95. package/extension/libherb/include/prism_serialized.h +12 -0
  96. package/extension/libherb/include/token.h +16 -4
  97. package/extension/libherb/include/token_struct.h +10 -3
  98. package/extension/libherb/include/utf8.h +2 -1
  99. package/extension/libherb/include/util/hb_allocator.h +78 -0
  100. package/extension/libherb/include/util/hb_arena.h +6 -1
  101. package/extension/libherb/include/util/hb_arena_debug.h +12 -1
  102. package/extension/libherb/include/util/hb_array.h +7 -3
  103. package/extension/libherb/include/util/hb_buffer.h +6 -4
  104. package/extension/libherb/include/util/hb_foreach.h +79 -0
  105. package/extension/libherb/include/util/hb_narray.h +8 -4
  106. package/extension/libherb/include/util/hb_string.h +56 -9
  107. package/extension/libherb/include/util.h +6 -3
  108. package/extension/libherb/include/version.h +1 -1
  109. package/extension/libherb/io.c +3 -2
  110. package/extension/libherb/io.h +3 -1
  111. package/extension/libherb/lex_helpers.h +29 -0
  112. package/extension/libherb/lexer.c +42 -30
  113. package/extension/libherb/lexer.h +1 -1
  114. package/extension/libherb/lexer_peek_helpers.c +12 -74
  115. package/extension/libherb/lexer_peek_helpers.h +87 -13
  116. package/extension/libherb/lexer_struct.h +2 -0
  117. package/extension/libherb/location.c +2 -2
  118. package/extension/libherb/location.h +2 -1
  119. package/extension/libherb/main.c +53 -28
  120. package/extension/libherb/parser.c +783 -247
  121. package/extension/libherb/parser.h +27 -2
  122. package/extension/libherb/parser_helpers.c +110 -23
  123. package/extension/libherb/parser_helpers.h +19 -3
  124. package/extension/libherb/parser_match_tags.c +110 -49
  125. package/extension/libherb/pretty_print.c +29 -24
  126. package/extension/libherb/pretty_print.h +10 -5
  127. package/extension/libherb/prism_context.h +45 -0
  128. package/extension/libherb/prism_helpers.c +30 -27
  129. package/extension/libherb/prism_helpers.h +10 -7
  130. package/extension/libherb/prism_serialized.h +12 -0
  131. package/extension/libherb/ruby_parser.c +2 -0
  132. package/extension/libherb/token.c +151 -66
  133. package/extension/libherb/token.h +16 -4
  134. package/extension/libherb/token_matchers.c +0 -1
  135. package/extension/libherb/token_struct.h +10 -3
  136. package/extension/libherb/utf8.c +7 -6
  137. package/extension/libherb/utf8.h +2 -1
  138. package/extension/libherb/util/hb_allocator.c +341 -0
  139. package/extension/libherb/util/hb_allocator.h +78 -0
  140. package/extension/libherb/util/hb_arena.c +81 -56
  141. package/extension/libherb/util/hb_arena.h +6 -1
  142. package/extension/libherb/util/hb_arena_debug.c +32 -17
  143. package/extension/libherb/util/hb_arena_debug.h +12 -1
  144. package/extension/libherb/util/hb_array.c +30 -15
  145. package/extension/libherb/util/hb_array.h +7 -3
  146. package/extension/libherb/util/hb_buffer.c +17 -21
  147. package/extension/libherb/util/hb_buffer.h +6 -4
  148. package/extension/libherb/util/hb_foreach.h +79 -0
  149. package/extension/libherb/util/hb_narray.c +22 -7
  150. package/extension/libherb/util/hb_narray.h +8 -4
  151. package/extension/libherb/util/hb_string.c +49 -35
  152. package/extension/libherb/util/hb_string.h +56 -9
  153. package/extension/libherb/util.c +21 -11
  154. package/extension/libherb/util.h +6 -3
  155. package/extension/libherb/version.h +1 -1
  156. package/extension/libherb/visitor.c +48 -1
  157. package/extension/nodes.cpp +451 -6
  158. package/extension/nodes.h +8 -1
  159. package/package.json +12 -8
  160. package/src/node-backend.ts +11 -1
  161. package/dist/types/index-cjs.d.cts +0 -1
  162. package/extension/libherb/analyze.c +0 -1608
  163. package/extension/libherb/element_source.c +0 -12
  164. package/extension/libherb/include/util/hb_system.h +0 -9
  165. package/extension/libherb/util/hb_system.c +0 -30
  166. package/extension/libherb/util/hb_system.h +0 -9
  167. package/src/index-cjs.cts +0 -22
  168. /package/dist/types/{index-esm.d.mts → index.d.ts} +0 -0
  169. /package/src/{index-esm.mts → index.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  // NOTE: This file is generated by the templates/template.rb script and should not
2
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.10/templates/src/parser_match_tags.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.9.0/templates/src/parser_match_tags.c.erb
3
3
 
4
4
  #include "include/parser.h"
5
5
  #include "include/ast_nodes.h"
@@ -7,118 +7,161 @@
7
7
  #include "include/visitor.h"
8
8
 
9
9
  bool match_tags_visitor(const AST_NODE_T* node, void* data) {
10
- hb_array_T* errors = (hb_array_T*) data;
10
+ match_tags_context_T* context = (match_tags_context_T*) data;
11
11
 
12
12
  if (node == NULL) { return false; }
13
13
 
14
14
  switch (node->type) {
15
15
 
16
+
16
17
  case AST_DOCUMENT_NODE: {
17
18
  const AST_DOCUMENT_NODE_T* document_node = (const AST_DOCUMENT_NODE_T*) node;
18
19
 
19
20
  if (document_node->children != NULL) {
20
- match_tags_in_node_array(document_node->children, errors);
21
+ match_tags_in_node_array(document_node->children, context->errors, context->options, context->allocator);
21
22
  }
22
23
  } break;
23
24
 
24
25
 
25
26
 
27
+
28
+
26
29
  case AST_HTML_OPEN_TAG_NODE: {
27
30
  const AST_HTML_OPEN_TAG_NODE_T* html_open_tag_node = (const AST_HTML_OPEN_TAG_NODE_T*) node;
28
31
 
29
32
  if (html_open_tag_node->children != NULL) {
30
- match_tags_in_node_array(html_open_tag_node->children, errors);
33
+ match_tags_in_node_array(html_open_tag_node->children, context->errors, context->options, context->allocator);
31
34
  }
32
35
  } break;
33
36
 
34
37
 
38
+
39
+
40
+
35
41
  case AST_HTML_CLOSE_TAG_NODE: {
36
42
  const AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node = (const AST_HTML_CLOSE_TAG_NODE_T*) node;
37
43
 
38
44
  if (html_close_tag_node->children != NULL) {
39
- match_tags_in_node_array(html_close_tag_node->children, errors);
45
+ match_tags_in_node_array(html_close_tag_node->children, context->errors, context->options, context->allocator);
40
46
  }
41
47
  } break;
42
48
 
43
49
 
50
+
51
+
52
+
53
+
54
+
44
55
  case AST_HTML_ELEMENT_NODE: {
45
56
  const AST_HTML_ELEMENT_NODE_T* html_element_node = (const AST_HTML_ELEMENT_NODE_T*) node;
46
57
 
47
58
  if (html_element_node->body != NULL) {
48
- match_tags_in_node_array(html_element_node->body, errors);
59
+ match_tags_in_node_array(html_element_node->body, context->errors, context->options, context->allocator);
49
60
  }
50
61
  if (html_element_node->open_tag != NULL) {
51
- herb_visit_node((AST_NODE_T*) html_element_node->open_tag, match_tags_visitor, errors);
62
+ herb_visit_node((AST_NODE_T*) html_element_node->open_tag, match_tags_visitor, context);
52
63
  }
53
64
  if (html_element_node->close_tag != NULL) {
54
- herb_visit_node((AST_NODE_T*) html_element_node->close_tag, match_tags_visitor, errors);
65
+ herb_visit_node((AST_NODE_T*) html_element_node->close_tag, match_tags_visitor, context);
55
66
  }
56
67
  } break;
57
68
 
58
69
 
70
+
71
+ case AST_HTML_CONDITIONAL_ELEMENT_NODE: {
72
+ const AST_HTML_CONDITIONAL_ELEMENT_NODE_T* html_conditional_element_node = (const AST_HTML_CONDITIONAL_ELEMENT_NODE_T*) node;
73
+
74
+ if (html_conditional_element_node->body != NULL) {
75
+ match_tags_in_node_array(html_conditional_element_node->body, context->errors, context->options, context->allocator);
76
+ }
77
+ } break;
78
+
79
+
80
+
59
81
  case AST_HTML_ATTRIBUTE_VALUE_NODE: {
60
82
  const AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node = (const AST_HTML_ATTRIBUTE_VALUE_NODE_T*) node;
61
83
 
62
84
  if (html_attribute_value_node->children != NULL) {
63
- match_tags_in_node_array(html_attribute_value_node->children, errors);
85
+ match_tags_in_node_array(html_attribute_value_node->children, context->errors, context->options, context->allocator);
64
86
  }
65
87
  } break;
66
88
 
67
89
 
90
+
68
91
  case AST_HTML_ATTRIBUTE_NAME_NODE: {
69
92
  const AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node = (const AST_HTML_ATTRIBUTE_NAME_NODE_T*) node;
70
93
 
71
94
  if (html_attribute_name_node->children != NULL) {
72
- match_tags_in_node_array(html_attribute_name_node->children, errors);
95
+ match_tags_in_node_array(html_attribute_name_node->children, context->errors, context->options, context->allocator);
73
96
  }
74
97
  } break;
75
98
 
76
99
 
100
+
77
101
  case AST_HTML_ATTRIBUTE_NODE: {
78
102
  const AST_HTML_ATTRIBUTE_NODE_T* html_attribute_node = (const AST_HTML_ATTRIBUTE_NODE_T*) node;
79
103
 
80
104
  if (html_attribute_node->name != NULL) {
81
- herb_visit_node((AST_NODE_T*) html_attribute_node->name, match_tags_visitor, errors);
105
+ herb_visit_node((AST_NODE_T*) html_attribute_node->name, match_tags_visitor, context);
82
106
  }
83
107
  if (html_attribute_node->value != NULL) {
84
- herb_visit_node((AST_NODE_T*) html_attribute_node->value, match_tags_visitor, errors);
108
+ herb_visit_node((AST_NODE_T*) html_attribute_node->value, match_tags_visitor, context);
85
109
  }
86
110
  } break;
87
111
 
88
112
 
89
113
 
114
+
115
+
116
+
117
+
118
+ case AST_ERB_OPEN_TAG_NODE: {
119
+ const AST_ERB_OPEN_TAG_NODE_T* erb_open_tag_node = (const AST_ERB_OPEN_TAG_NODE_T*) node;
120
+
121
+ if (erb_open_tag_node->children != NULL) {
122
+ match_tags_in_node_array(erb_open_tag_node->children, context->errors, context->options, context->allocator);
123
+ }
124
+ } break;
125
+
126
+
127
+
128
+
129
+
90
130
  case AST_HTML_COMMENT_NODE: {
91
131
  const AST_HTML_COMMENT_NODE_T* html_comment_node = (const AST_HTML_COMMENT_NODE_T*) node;
92
132
 
93
133
  if (html_comment_node->children != NULL) {
94
- match_tags_in_node_array(html_comment_node->children, errors);
134
+ match_tags_in_node_array(html_comment_node->children, context->errors, context->options, context->allocator);
95
135
  }
96
136
  } break;
97
137
 
98
138
 
139
+
99
140
  case AST_HTML_DOCTYPE_NODE: {
100
141
  const AST_HTML_DOCTYPE_NODE_T* html_doctype_node = (const AST_HTML_DOCTYPE_NODE_T*) node;
101
142
 
102
143
  if (html_doctype_node->children != NULL) {
103
- match_tags_in_node_array(html_doctype_node->children, errors);
144
+ match_tags_in_node_array(html_doctype_node->children, context->errors, context->options, context->allocator);
104
145
  }
105
146
  } break;
106
147
 
107
148
 
149
+
108
150
  case AST_XML_DECLARATION_NODE: {
109
151
  const AST_XML_DECLARATION_NODE_T* xml_declaration_node = (const AST_XML_DECLARATION_NODE_T*) node;
110
152
 
111
153
  if (xml_declaration_node->children != NULL) {
112
- match_tags_in_node_array(xml_declaration_node->children, errors);
154
+ match_tags_in_node_array(xml_declaration_node->children, context->errors, context->options, context->allocator);
113
155
  }
114
156
  } break;
115
157
 
116
158
 
159
+
117
160
  case AST_CDATA_NODE: {
118
161
  const AST_CDATA_NODE_T* cdata_node = (const AST_CDATA_NODE_T*) node;
119
162
 
120
163
  if (cdata_node->children != NULL) {
121
- match_tags_in_node_array(cdata_node->children, errors);
164
+ match_tags_in_node_array(cdata_node->children, context->errors, context->options, context->allocator);
122
165
  }
123
166
  } break;
124
167
 
@@ -126,186 +169,204 @@ bool match_tags_visitor(const AST_NODE_T* node, void* data) {
126
169
 
127
170
 
128
171
 
172
+
173
+
174
+
175
+
129
176
  case AST_ERB_ELSE_NODE: {
130
177
  const AST_ERB_ELSE_NODE_T* erb_else_node = (const AST_ERB_ELSE_NODE_T*) node;
131
178
 
132
179
  if (erb_else_node->statements != NULL) {
133
- match_tags_in_node_array(erb_else_node->statements, errors);
180
+ match_tags_in_node_array(erb_else_node->statements, context->errors, context->options, context->allocator);
134
181
  }
135
182
  } break;
136
183
 
137
184
 
185
+
138
186
  case AST_ERB_IF_NODE: {
139
187
  const AST_ERB_IF_NODE_T* erb_if_node = (const AST_ERB_IF_NODE_T*) node;
140
188
 
141
189
  if (erb_if_node->statements != NULL) {
142
- match_tags_in_node_array(erb_if_node->statements, errors);
190
+ match_tags_in_node_array(erb_if_node->statements, context->errors, context->options, context->allocator);
143
191
  }
144
192
  if (erb_if_node->subsequent != NULL) {
145
- herb_visit_node((AST_NODE_T*) erb_if_node->subsequent, match_tags_visitor, errors);
193
+ herb_visit_node((AST_NODE_T*) erb_if_node->subsequent, match_tags_visitor, context);
146
194
  }
147
195
  if (erb_if_node->end_node != NULL) {
148
- herb_visit_node((AST_NODE_T*) erb_if_node->end_node, match_tags_visitor, errors);
196
+ herb_visit_node((AST_NODE_T*) erb_if_node->end_node, match_tags_visitor, context);
149
197
  }
150
198
  } break;
151
199
 
152
200
 
201
+
153
202
  case AST_ERB_BLOCK_NODE: {
154
203
  const AST_ERB_BLOCK_NODE_T* erb_block_node = (const AST_ERB_BLOCK_NODE_T*) node;
155
204
 
156
205
  if (erb_block_node->body != NULL) {
157
- match_tags_in_node_array(erb_block_node->body, errors);
206
+ match_tags_in_node_array(erb_block_node->body, context->errors, context->options, context->allocator);
158
207
  }
159
208
  if (erb_block_node->end_node != NULL) {
160
- herb_visit_node((AST_NODE_T*) erb_block_node->end_node, match_tags_visitor, errors);
209
+ herb_visit_node((AST_NODE_T*) erb_block_node->end_node, match_tags_visitor, context);
161
210
  }
162
211
  } break;
163
212
 
164
213
 
214
+
165
215
  case AST_ERB_WHEN_NODE: {
166
216
  const AST_ERB_WHEN_NODE_T* erb_when_node = (const AST_ERB_WHEN_NODE_T*) node;
167
217
 
168
218
  if (erb_when_node->statements != NULL) {
169
- match_tags_in_node_array(erb_when_node->statements, errors);
219
+ match_tags_in_node_array(erb_when_node->statements, context->errors, context->options, context->allocator);
170
220
  }
171
221
  } break;
172
222
 
173
223
 
224
+
174
225
  case AST_ERB_CASE_NODE: {
175
226
  const AST_ERB_CASE_NODE_T* erb_case_node = (const AST_ERB_CASE_NODE_T*) node;
176
227
 
177
228
  if (erb_case_node->children != NULL) {
178
- match_tags_in_node_array(erb_case_node->children, errors);
229
+ match_tags_in_node_array(erb_case_node->children, context->errors, context->options, context->allocator);
179
230
  }
180
231
  if (erb_case_node->conditions != NULL) {
181
- match_tags_in_node_array(erb_case_node->conditions, errors);
232
+ match_tags_in_node_array(erb_case_node->conditions, context->errors, context->options, context->allocator);
182
233
  }
183
234
  if (erb_case_node->else_clause != NULL) {
184
- herb_visit_node((AST_NODE_T*) erb_case_node->else_clause, match_tags_visitor, errors);
235
+ herb_visit_node((AST_NODE_T*) erb_case_node->else_clause, match_tags_visitor, context);
185
236
  }
186
237
  if (erb_case_node->end_node != NULL) {
187
- herb_visit_node((AST_NODE_T*) erb_case_node->end_node, match_tags_visitor, errors);
238
+ herb_visit_node((AST_NODE_T*) erb_case_node->end_node, match_tags_visitor, context);
188
239
  }
189
240
  } break;
190
241
 
191
242
 
243
+
192
244
  case AST_ERB_CASE_MATCH_NODE: {
193
245
  const AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = (const AST_ERB_CASE_MATCH_NODE_T*) node;
194
246
 
195
247
  if (erb_case_match_node->children != NULL) {
196
- match_tags_in_node_array(erb_case_match_node->children, errors);
248
+ match_tags_in_node_array(erb_case_match_node->children, context->errors, context->options, context->allocator);
197
249
  }
198
250
  if (erb_case_match_node->conditions != NULL) {
199
- match_tags_in_node_array(erb_case_match_node->conditions, errors);
251
+ match_tags_in_node_array(erb_case_match_node->conditions, context->errors, context->options, context->allocator);
200
252
  }
201
253
  if (erb_case_match_node->else_clause != NULL) {
202
- herb_visit_node((AST_NODE_T*) erb_case_match_node->else_clause, match_tags_visitor, errors);
254
+ herb_visit_node((AST_NODE_T*) erb_case_match_node->else_clause, match_tags_visitor, context);
203
255
  }
204
256
  if (erb_case_match_node->end_node != NULL) {
205
- herb_visit_node((AST_NODE_T*) erb_case_match_node->end_node, match_tags_visitor, errors);
257
+ herb_visit_node((AST_NODE_T*) erb_case_match_node->end_node, match_tags_visitor, context);
206
258
  }
207
259
  } break;
208
260
 
209
261
 
262
+
210
263
  case AST_ERB_WHILE_NODE: {
211
264
  const AST_ERB_WHILE_NODE_T* erb_while_node = (const AST_ERB_WHILE_NODE_T*) node;
212
265
 
213
266
  if (erb_while_node->statements != NULL) {
214
- match_tags_in_node_array(erb_while_node->statements, errors);
267
+ match_tags_in_node_array(erb_while_node->statements, context->errors, context->options, context->allocator);
215
268
  }
216
269
  if (erb_while_node->end_node != NULL) {
217
- herb_visit_node((AST_NODE_T*) erb_while_node->end_node, match_tags_visitor, errors);
270
+ herb_visit_node((AST_NODE_T*) erb_while_node->end_node, match_tags_visitor, context);
218
271
  }
219
272
  } break;
220
273
 
221
274
 
275
+
222
276
  case AST_ERB_UNTIL_NODE: {
223
277
  const AST_ERB_UNTIL_NODE_T* erb_until_node = (const AST_ERB_UNTIL_NODE_T*) node;
224
278
 
225
279
  if (erb_until_node->statements != NULL) {
226
- match_tags_in_node_array(erb_until_node->statements, errors);
280
+ match_tags_in_node_array(erb_until_node->statements, context->errors, context->options, context->allocator);
227
281
  }
228
282
  if (erb_until_node->end_node != NULL) {
229
- herb_visit_node((AST_NODE_T*) erb_until_node->end_node, match_tags_visitor, errors);
283
+ herb_visit_node((AST_NODE_T*) erb_until_node->end_node, match_tags_visitor, context);
230
284
  }
231
285
  } break;
232
286
 
233
287
 
288
+
234
289
  case AST_ERB_FOR_NODE: {
235
290
  const AST_ERB_FOR_NODE_T* erb_for_node = (const AST_ERB_FOR_NODE_T*) node;
236
291
 
237
292
  if (erb_for_node->statements != NULL) {
238
- match_tags_in_node_array(erb_for_node->statements, errors);
293
+ match_tags_in_node_array(erb_for_node->statements, context->errors, context->options, context->allocator);
239
294
  }
240
295
  if (erb_for_node->end_node != NULL) {
241
- herb_visit_node((AST_NODE_T*) erb_for_node->end_node, match_tags_visitor, errors);
296
+ herb_visit_node((AST_NODE_T*) erb_for_node->end_node, match_tags_visitor, context);
242
297
  }
243
298
  } break;
244
299
 
245
300
 
301
+
246
302
  case AST_ERB_RESCUE_NODE: {
247
303
  const AST_ERB_RESCUE_NODE_T* erb_rescue_node = (const AST_ERB_RESCUE_NODE_T*) node;
248
304
 
249
305
  if (erb_rescue_node->statements != NULL) {
250
- match_tags_in_node_array(erb_rescue_node->statements, errors);
306
+ match_tags_in_node_array(erb_rescue_node->statements, context->errors, context->options, context->allocator);
251
307
  }
252
308
  if (erb_rescue_node->subsequent != NULL) {
253
- herb_visit_node((AST_NODE_T*) erb_rescue_node->subsequent, match_tags_visitor, errors);
309
+ herb_visit_node((AST_NODE_T*) erb_rescue_node->subsequent, match_tags_visitor, context);
254
310
  }
255
311
  } break;
256
312
 
257
313
 
314
+
258
315
  case AST_ERB_ENSURE_NODE: {
259
316
  const AST_ERB_ENSURE_NODE_T* erb_ensure_node = (const AST_ERB_ENSURE_NODE_T*) node;
260
317
 
261
318
  if (erb_ensure_node->statements != NULL) {
262
- match_tags_in_node_array(erb_ensure_node->statements, errors);
319
+ match_tags_in_node_array(erb_ensure_node->statements, context->errors, context->options, context->allocator);
263
320
  }
264
321
  } break;
265
322
 
266
323
 
324
+
267
325
  case AST_ERB_BEGIN_NODE: {
268
326
  const AST_ERB_BEGIN_NODE_T* erb_begin_node = (const AST_ERB_BEGIN_NODE_T*) node;
269
327
 
270
328
  if (erb_begin_node->statements != NULL) {
271
- match_tags_in_node_array(erb_begin_node->statements, errors);
329
+ match_tags_in_node_array(erb_begin_node->statements, context->errors, context->options, context->allocator);
272
330
  }
273
331
  if (erb_begin_node->rescue_clause != NULL) {
274
- herb_visit_node((AST_NODE_T*) erb_begin_node->rescue_clause, match_tags_visitor, errors);
332
+ herb_visit_node((AST_NODE_T*) erb_begin_node->rescue_clause, match_tags_visitor, context);
275
333
  }
276
334
  if (erb_begin_node->else_clause != NULL) {
277
- herb_visit_node((AST_NODE_T*) erb_begin_node->else_clause, match_tags_visitor, errors);
335
+ herb_visit_node((AST_NODE_T*) erb_begin_node->else_clause, match_tags_visitor, context);
278
336
  }
279
337
  if (erb_begin_node->ensure_clause != NULL) {
280
- herb_visit_node((AST_NODE_T*) erb_begin_node->ensure_clause, match_tags_visitor, errors);
338
+ herb_visit_node((AST_NODE_T*) erb_begin_node->ensure_clause, match_tags_visitor, context);
281
339
  }
282
340
  if (erb_begin_node->end_node != NULL) {
283
- herb_visit_node((AST_NODE_T*) erb_begin_node->end_node, match_tags_visitor, errors);
341
+ herb_visit_node((AST_NODE_T*) erb_begin_node->end_node, match_tags_visitor, context);
284
342
  }
285
343
  } break;
286
344
 
287
345
 
346
+
288
347
  case AST_ERB_UNLESS_NODE: {
289
348
  const AST_ERB_UNLESS_NODE_T* erb_unless_node = (const AST_ERB_UNLESS_NODE_T*) node;
290
349
 
291
350
  if (erb_unless_node->statements != NULL) {
292
- match_tags_in_node_array(erb_unless_node->statements, errors);
351
+ match_tags_in_node_array(erb_unless_node->statements, context->errors, context->options, context->allocator);
293
352
  }
294
353
  if (erb_unless_node->else_clause != NULL) {
295
- herb_visit_node((AST_NODE_T*) erb_unless_node->else_clause, match_tags_visitor, errors);
354
+ herb_visit_node((AST_NODE_T*) erb_unless_node->else_clause, match_tags_visitor, context);
296
355
  }
297
356
  if (erb_unless_node->end_node != NULL) {
298
- herb_visit_node((AST_NODE_T*) erb_unless_node->end_node, match_tags_visitor, errors);
357
+ herb_visit_node((AST_NODE_T*) erb_unless_node->end_node, match_tags_visitor, context);
299
358
  }
300
359
  } break;
301
360
 
302
361
 
303
362
 
363
+
364
+
304
365
  case AST_ERB_IN_NODE: {
305
366
  const AST_ERB_IN_NODE_T* erb_in_node = (const AST_ERB_IN_NODE_T*) node;
306
367
 
307
368
  if (erb_in_node->statements != NULL) {
308
- match_tags_in_node_array(erb_in_node->statements, errors);
369
+ match_tags_in_node_array(erb_in_node->statements, context->errors, context->options, context->allocator);
309
370
  }
310
371
  } break;
311
372
 
@@ -1,17 +1,20 @@
1
- #include "include/pretty_print.h"
2
- #include "include/analyzed_ruby.h"
3
- #include "include/ast_node.h"
4
- #include "include/ast_nodes.h"
5
- #include "include/ast_pretty_print.h"
6
- #include "include/errors.h"
7
- #include "include/token_struct.h"
8
- #include "include/util.h"
9
- #include "include/util/hb_buffer.h"
10
- #include "include/util/hb_string.h"
11
-
12
- #include <stdbool.h>
13
- #include <stdio.h>
14
- #include <stdlib.h>
1
+ #ifdef HERB_EXCLUDE_PRETTYPRINT
2
+ // Pretty print support excluded
3
+ #else
4
+
5
+ # include "include/pretty_print.h"
6
+ # include "include/ast_nodes.h"
7
+ # include "include/ast_pretty_print.h"
8
+ # include "include/errors.h"
9
+ # include "include/token_struct.h"
10
+ # include "include/util.h"
11
+ # include "include/util/hb_allocator.h"
12
+ # include "include/util/hb_buffer.h"
13
+ # include "include/util/hb_string.h"
14
+
15
+ # include <stdbool.h>
16
+ # include <stdio.h>
17
+ # include <stdlib.h>
15
18
 
16
19
  void pretty_print_indent(hb_buffer_T* buffer, const size_t indent) {
17
20
  for (size_t i = 0; i < indent; i++) {
@@ -53,9 +56,9 @@ void pretty_print_quoted_property(
53
56
  const bool last_property,
54
57
  hb_buffer_T* buffer
55
58
  ) {
56
- hb_string_T quoted = quoted_string(value);
59
+ hb_string_T quoted = quoted_string(buffer->allocator, value);
57
60
  pretty_print_property(name, quoted, indent, relative_indent, last_property, buffer);
58
- free(quoted.data);
61
+ hb_allocator_dealloc(buffer->allocator, quoted.data);
59
62
  }
60
63
 
61
64
  void pretty_print_boolean_property(
@@ -212,10 +215,10 @@ void pretty_print_token_property(
212
215
  ) {
213
216
  pretty_print_label(name, indent, relative_indent, last_property, buffer);
214
217
 
215
- if (token != NULL && token->value != NULL) {
216
- hb_string_T quoted = quoted_string(hb_string(token->value));
218
+ if (token != NULL && !hb_string_is_empty(token->value)) {
219
+ hb_string_T quoted = quoted_string(buffer->allocator, token->value);
217
220
  hb_buffer_append_string(buffer, quoted);
218
- free(quoted.data);
221
+ hb_allocator_dealloc(buffer->allocator, quoted.data);
219
222
 
220
223
  hb_buffer_append(buffer, " ");
221
224
  pretty_print_location(token->location, buffer);
@@ -235,19 +238,21 @@ void pretty_print_string_property(
235
238
  hb_buffer_T* buffer
236
239
  ) {
237
240
  hb_string_T value = hb_string("∅");
238
- hb_string_T escaped = { .data = NULL, .length = 0 };
241
+ hb_string_T escaped = HB_STRING_NULL;
239
242
  hb_string_T quoted;
240
243
 
241
244
  if (!hb_string_is_empty(string)) {
242
- escaped = escape_newlines(string);
243
- quoted = quoted_string(escaped);
245
+ escaped = escape_newlines(buffer->allocator, string);
246
+ quoted = quoted_string(buffer->allocator, escaped);
244
247
  value = quoted;
245
248
  }
246
249
 
247
250
  pretty_print_property(name, value, indent, relative_indent, last_property, buffer);
248
251
 
249
252
  if (!hb_string_is_empty(string)) {
250
- if (!hb_string_is_empty(escaped)) { free(escaped.data); }
251
- if (!hb_string_is_empty(quoted)) { free(quoted.data); }
253
+ if (!hb_string_is_empty(escaped)) { hb_allocator_dealloc(buffer->allocator, escaped.data); }
254
+ if (!hb_string_is_empty(quoted)) { hb_allocator_dealloc(buffer->allocator, quoted.data); }
252
255
  }
253
256
  }
257
+
258
+ #endif
@@ -1,12 +1,16 @@
1
1
  #ifndef HERB_PRETTY_PRINT_H
2
2
  #define HERB_PRETTY_PRINT_H
3
3
 
4
- #include "analyzed_ruby.h"
5
- #include "ast_nodes.h"
6
- #include "location.h"
7
- #include "util/hb_buffer.h"
4
+ #ifdef HERB_EXCLUDE_PRETTYPRINT
5
+ // Pretty print support excluded
6
+ #else
8
7
 
9
- #include <stdbool.h>
8
+ # include "analyze/analyzed_ruby.h"
9
+ # include "ast_nodes.h"
10
+ # include "location.h"
11
+ # include "util/hb_buffer.h"
12
+
13
+ # include <stdbool.h>
10
14
 
11
15
  void pretty_print_indent(hb_buffer_T* buffer, size_t indent);
12
16
  void pretty_print_newline(size_t indent, size_t relative_indent, hb_buffer_T* buffer);
@@ -101,3 +105,4 @@ void pretty_print_errors(
101
105
  );
102
106
 
103
107
  #endif
108
+ #endif
@@ -0,0 +1,45 @@
1
+ #ifndef HERB_PRISM_CONTEXT_H
2
+ #define HERB_PRISM_CONTEXT_H
3
+
4
+ #include "util/hb_allocator.h"
5
+ #include "util/hb_buffer.h"
6
+ #include <prism.h>
7
+ #include <stdbool.h>
8
+
9
+ typedef struct {
10
+ pm_parser_t parser;
11
+ pm_options_t pm_opts;
12
+ pm_node_t* root;
13
+ hb_buffer_T ruby_buf;
14
+
15
+ bool has_structural;
16
+ pm_parser_t structural_parser;
17
+ pm_options_t structural_pm_opts;
18
+ pm_node_t* structural_root;
19
+ hb_buffer_T structural_buf;
20
+
21
+ hb_allocator_T* allocator;
22
+ } herb_prism_context_T;
23
+
24
+ static inline void herb_prism_context_free(herb_prism_context_T* context) {
25
+ if (!context) { return; }
26
+
27
+ if (context->root) { pm_node_destroy(&context->parser, context->root); }
28
+
29
+ pm_parser_free(&context->parser);
30
+ pm_options_free(&context->pm_opts);
31
+ hb_buffer_free(&context->ruby_buf);
32
+
33
+ if (context->has_structural) {
34
+ if (context->structural_root) { pm_node_destroy(&context->structural_parser, context->structural_root); }
35
+
36
+ pm_parser_free(&context->structural_parser);
37
+ pm_options_free(&context->structural_pm_opts);
38
+
39
+ if (context->structural_buf.value) { hb_buffer_free(&context->structural_buf); }
40
+ }
41
+
42
+ hb_allocator_dealloc(context->allocator, context);
43
+ }
44
+
45
+ #endif