herb 0.11.1 → 0.11.3

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 (275) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +2 -0
  3. data/Rakefile +4 -2
  4. data/config.yml +13 -8
  5. data/ext/herb/error_helpers.c +3 -3
  6. data/ext/herb/extconf.rb +8 -31
  7. data/ext/herb/nodes.c +75 -75
  8. data/ext/herb/parser_options_helpers.c +26 -0
  9. data/lib/herb/analysis/partial_index.rb +1 -1
  10. data/lib/herb/analysis/partial_resolution.rb +27 -0
  11. data/lib/herb/ast/erb_render_node.rb +6 -2
  12. data/lib/herb/ast/helpers.rb +1 -1
  13. data/lib/herb/cli.rb +7 -3
  14. data/lib/herb/configuration.rb +11 -1
  15. data/lib/herb/dev/classifier.rb +1 -1
  16. data/lib/herb/dev/runner.rb +5 -2
  17. data/lib/herb/engine/compiler.rb +44 -12
  18. data/lib/herb/engine/slots/dynamics_compiler.rb +54 -15
  19. data/lib/herb/engine/slots/state_compiler.rb +9 -1
  20. data/lib/herb/engine/slots/state_overrides.rb +17 -3
  21. data/lib/herb/engine/slots/subtree_compiler.rb +1 -1
  22. data/lib/herb/engine/slots/visitor.rb +69 -11
  23. data/lib/herb/engine/visitors/instrumentation_visitor.rb +18 -6
  24. data/lib/herb/engine.rb +11 -1
  25. data/lib/herb/errors.rb +7 -7
  26. data/lib/herb/parser_options.rb +6 -3
  27. data/lib/herb/project.rb +19 -8
  28. data/lib/herb/version.rb +1 -1
  29. data/lib/herb.rb +1 -1
  30. data/sig/herb/analysis/partial_resolution.rbs +8 -0
  31. data/sig/herb/ast/erb_render_node.rbs +2 -0
  32. data/sig/herb/configuration.rbs +3 -0
  33. data/sig/herb/dev/runner.rbs +2 -2
  34. data/sig/herb/engine/compiler.rbs +9 -0
  35. data/sig/herb/engine/slots/dynamics_compiler.rbs +24 -7
  36. data/sig/herb/engine/slots/state_compiler.rbs +3 -0
  37. data/sig/herb/engine/slots/state_overrides.rbs +11 -2
  38. data/sig/herb/engine/slots/visitor.rbs +21 -0
  39. data/sig/herb/engine/visitors/instrumentation_visitor.rbs +5 -1
  40. data/sig/herb/engine.rbs +2 -0
  41. data/sig/herb/errors.rbs +2 -2
  42. data/sig/herb/parser_options.rbs +6 -4
  43. data/sig/herb.rbs +2 -2
  44. data/sig/serialized_ast_errors.rbs +1 -1
  45. data/src/analyze/action_view/attribute_extraction_helpers.c +40 -21
  46. data/src/analyze/action_view/generated_handlers.c +36 -36
  47. data/src/analyze/action_view/image_tag.c +7 -3
  48. data/src/analyze/action_view/javascript_include_tag.c +6 -3
  49. data/src/analyze/action_view/link_to.c +23 -23
  50. data/src/analyze/action_view/registry.c +7 -3
  51. data/src/analyze/action_view/tag_helper_node_builders.c +6 -13
  52. data/src/analyze/action_view/tag_helpers.c +160 -97
  53. data/src/analyze/action_view/turbo_frame_tag.c +5 -4
  54. data/src/analyze/analyze.c +52 -29
  55. data/src/analyze/analyze_helpers.c +161 -188
  56. data/src/analyze/analyzed_ruby.c +8 -7
  57. data/src/analyze/control_type.c +29 -22
  58. data/src/analyze/herb_directives.c +16 -20
  59. data/src/analyze/iteration_nodes.c +69 -24
  60. data/src/analyze/parse_errors.c +32 -22
  61. data/src/analyze/postfix_conditionals.c +23 -13
  62. data/src/analyze/prism_annotate.c +29 -28
  63. data/src/analyze/render_nodes.c +239 -78
  64. data/src/analyze/strict_locals.c +14 -15
  65. data/src/analyze/ternary_conditionals.c +14 -10
  66. data/src/diff/herb_diff_children.c +1 -1
  67. data/src/diff/herb_diff_nodes.c +1 -9
  68. data/src/diff/herb_hash_tree.c +1 -1
  69. data/src/errors.c +17 -22
  70. data/src/extract.c +47 -7
  71. data/src/herb.c +10 -8
  72. data/src/include/analyze/action_view/tag_helper_handler.h +1 -1
  73. data/src/include/analyze/action_view/tag_helper_node_builders.h +1 -0
  74. data/src/include/analyze/action_view/tag_helpers.h +1 -1
  75. data/src/include/analyze/analyze.h +3 -2
  76. data/src/include/analyze/analyzed_ruby.h +4 -2
  77. data/src/include/analyze/helpers.h +6 -6
  78. data/src/include/errors.h +3 -3
  79. data/src/include/herb.h +3 -2
  80. data/src/include/parser/parser_options.h +5 -0
  81. data/src/include/prism/prism_context.h +12 -12
  82. data/src/include/prism/prism_helpers.h +30 -0
  83. data/src/include/prism_version.h +11 -0
  84. data/src/include/version.h +1 -1
  85. data/src/lexer/token.c +2 -2
  86. data/src/parser/dot_notation.c +15 -5
  87. data/src/parser/parser_helpers.c +1 -2
  88. data/src/parser.c +9 -8
  89. data/src/parser_options_defaults.c +1 -0
  90. data/src/prism/prism_helpers.c +84 -50
  91. data/src/prism/ruby_parser.c +20 -20
  92. data/templates/ext/herb/nodes.c.erb +5 -5
  93. data/templates/ext/herb/parser_options_helpers.c.erb +33 -0
  94. data/templates/java/nodes.c.erb +6 -6
  95. data/templates/java/parser_options_helpers.c.erb +41 -2
  96. data/templates/java/parser_options_helpers.h.erb +2 -1
  97. data/templates/javascript/packages/node/extension/nodes.cpp.erb +5 -5
  98. data/templates/javascript/packages/node/extension/parser_options_helpers.cpp.erb +34 -2
  99. data/templates/javascript/packages/node/extension/parser_options_helpers.h.erb +1 -1
  100. data/templates/lib/herb/parser_options.rb.erb +1 -1
  101. data/templates/rust/src/prism/generated_deserialize.rs.erb +90 -44
  102. data/templates/rust/src/prism/generated_prettyprint.rs.erb +18 -27
  103. data/templates/src/analyze/action_view/generated_handlers.c.erb +23 -22
  104. data/templates/src/diff/herb_diff_nodes.c.erb +1 -9
  105. data/templates/src/diff/herb_hash_tree.c.erb +1 -1
  106. data/templates/src/errors.c.erb +2 -2
  107. data/templates/src/include/parser/parser_options.h.erb +10 -0
  108. data/templates/src/include/prism_version.h.erb +17 -0
  109. data/templates/src/parser_options_defaults.c.erb +1 -1
  110. data/templates/template.rb +17 -2
  111. data/templates/wasm/nodes.cpp.erb +5 -5
  112. data/templates/wasm/parser_options_helpers.cpp.erb +24 -0
  113. data/vendor/prism/Rakefile +76 -7
  114. data/vendor/prism/config.yml +174 -161
  115. data/vendor/prism/include/prism/arena.h +45 -0
  116. data/vendor/prism/include/prism/arena.hpp +42 -0
  117. data/vendor/prism/include/prism/ast.h +2738 -611
  118. data/vendor/prism/include/prism/ast.hpp +641 -0
  119. data/vendor/prism/include/prism/buffer.h +60 -0
  120. data/vendor/prism/include/prism/buffer.hpp +55 -0
  121. data/vendor/prism/include/prism/comments.h +72 -0
  122. data/vendor/prism/include/prism/compiler/accel.h +26 -0
  123. data/vendor/prism/include/prism/compiler/align.h +36 -0
  124. data/vendor/prism/include/prism/compiler/assume.h +25 -0
  125. data/vendor/prism/include/prism/compiler/branch.h +26 -0
  126. data/vendor/prism/include/prism/compiler/bswap.h +46 -0
  127. data/vendor/prism/include/prism/compiler/cplusplus.hpp +16 -0
  128. data/vendor/prism/include/prism/compiler/endianness.h +34 -0
  129. data/vendor/prism/include/prism/compiler/exceptions.hpp +17 -0
  130. data/vendor/prism/include/prism/compiler/exported.h +24 -0
  131. data/vendor/prism/include/prism/compiler/fallthrough.h +22 -0
  132. data/vendor/prism/include/prism/compiler/filesystem.h +32 -0
  133. data/vendor/prism/include/prism/compiler/flex_array.h +19 -0
  134. data/vendor/prism/include/prism/compiler/force_inline.h +21 -0
  135. data/vendor/prism/include/prism/compiler/format.h +27 -0
  136. data/vendor/prism/include/prism/compiler/inline.h +17 -0
  137. data/vendor/prism/include/prism/compiler/lifetimebound.hpp +25 -0
  138. data/vendor/prism/include/prism/compiler/nodiscard.h +22 -0
  139. data/vendor/prism/include/prism/compiler/nonnull.h +18 -0
  140. data/vendor/prism/include/prism/compiler/unused.h +18 -0
  141. data/vendor/prism/include/prism/constant_pool.h +106 -0
  142. data/vendor/prism/include/prism/diagnostic.h +55 -402
  143. data/vendor/prism/include/prism/errors_format.h +61 -0
  144. data/vendor/prism/include/prism/excludes.h +29 -0
  145. data/vendor/prism/include/prism/integer.h +41 -0
  146. data/vendor/prism/include/prism/internal/allocator.h +68 -0
  147. data/vendor/prism/include/prism/internal/allocator_debug.h +88 -0
  148. data/vendor/prism/include/prism/internal/arena.h +108 -0
  149. data/vendor/prism/include/prism/internal/bit.h +42 -0
  150. data/vendor/prism/include/prism/internal/buffer.h +94 -0
  151. data/vendor/prism/include/prism/internal/char.h +145 -0
  152. data/vendor/prism/include/prism/internal/comments.h +54 -0
  153. data/vendor/prism/include/prism/internal/constant_pool.h +152 -0
  154. data/vendor/prism/include/prism/internal/diagnostic.h +389 -0
  155. data/vendor/prism/include/prism/{encoding.h → internal/encoding.h} +27 -68
  156. data/vendor/prism/include/prism/internal/integer.h +68 -0
  157. data/vendor/prism/include/prism/internal/isinf.h +16 -0
  158. data/vendor/prism/include/prism/internal/line_offset_list.h +34 -0
  159. data/vendor/prism/include/prism/{util/pm_list.h → internal/list.h} +11 -52
  160. data/vendor/prism/include/prism/internal/magic_comments.h +23 -0
  161. data/vendor/prism/include/prism/internal/memchr.h +15 -0
  162. data/vendor/prism/include/prism/internal/node.h +42 -0
  163. data/vendor/prism/include/prism/internal/options.h +232 -0
  164. data/vendor/prism/include/prism/internal/parser.h +1015 -0
  165. data/vendor/prism/include/prism/internal/regexp.h +26 -0
  166. data/vendor/prism/include/prism/internal/serialize.h +39 -0
  167. data/vendor/prism/include/prism/internal/source.h +72 -0
  168. data/vendor/prism/include/prism/internal/static_literals.h +60 -0
  169. data/vendor/prism/include/prism/internal/stringy.h +30 -0
  170. data/vendor/prism/include/prism/{util/pm_strncasecmp.h → internal/strncasecmp.h} +3 -17
  171. data/vendor/prism/include/prism/{util/pm_strpbrk.h → internal/strpbrk.h} +7 -20
  172. data/vendor/prism/include/prism/internal/tokens.h +11 -0
  173. data/vendor/prism/include/prism/internal/xxh3.h +16 -0
  174. data/vendor/prism/include/prism/json.h +40 -0
  175. data/vendor/prism/include/prism/line_offset_list.h +69 -0
  176. data/vendor/prism/include/prism/magic_comments.h +53 -0
  177. data/vendor/prism/include/prism/node.h +59 -49
  178. data/vendor/prism/include/prism/node.hpp +272 -0
  179. data/vendor/prism/include/prism/node_type.hpp +38 -0
  180. data/vendor/prism/include/prism/options.h +154 -279
  181. data/vendor/prism/include/prism/options.hpp +43 -0
  182. data/vendor/prism/include/prism/parser.h +367 -870
  183. data/vendor/prism/include/prism/parser.hpp +274 -0
  184. data/vendor/prism/include/prism/prettyprint.h +14 -9
  185. data/vendor/prism/include/prism/serialize.h +123 -0
  186. data/vendor/prism/include/prism/source.h +163 -0
  187. data/vendor/prism/include/prism/stream.h +36 -0
  188. data/vendor/prism/include/prism/string_query.h +82 -0
  189. data/vendor/prism/include/prism/stringy.h +61 -0
  190. data/vendor/prism/include/prism/stringy.hpp +31 -0
  191. data/vendor/prism/include/prism/version.h +20 -3
  192. data/vendor/prism/include/prism.h +35 -320
  193. data/vendor/prism/include/prism.hpp +24 -0
  194. data/vendor/prism/src/arena.c +122 -0
  195. data/vendor/prism/src/{util/pm_buffer.c → buffer.c} +53 -21
  196. data/vendor/prism/src/{util/pm_char.c → char.c} +28 -57
  197. data/vendor/prism/src/comments.c +455 -0
  198. data/vendor/prism/src/constant_pool.c +406 -0
  199. data/vendor/prism/src/diagnostic.c +120 -68
  200. data/vendor/prism/src/encoding.c +8 -3
  201. data/vendor/prism/src/errors_format.c +519 -0
  202. data/vendor/prism/src/{util/pm_integer.c → integer.c} +38 -22
  203. data/vendor/prism/src/json.c +5733 -0
  204. data/vendor/prism/src/line_offset_list.c +100 -0
  205. data/vendor/prism/src/list.c +24 -0
  206. data/vendor/prism/src/{util/pm_memchr.c → memchr.c} +8 -6
  207. data/vendor/prism/src/node.c +3465 -7787
  208. data/vendor/prism/src/options.c +161 -54
  209. data/vendor/prism/src/parser.c +371 -0
  210. data/vendor/prism/src/prettyprint.c +421 -354
  211. data/vendor/prism/src/prism.c +8522 -7280
  212. data/vendor/prism/src/regexp.c +960 -45
  213. data/vendor/prism/src/serialize.c +2434 -2048
  214. data/vendor/prism/src/source.c +524 -0
  215. data/vendor/prism/src/static_literals.c +303 -360
  216. data/vendor/prism/src/string_query.c +180 -0
  217. data/vendor/prism/src/stringy.c +61 -0
  218. data/vendor/prism/src/{util/pm_strncasecmp.c → strncasecmp.c} +5 -4
  219. data/vendor/prism/src/strpbrk.c +447 -0
  220. data/vendor/prism/src/{token_type.c → tokens.c} +39 -18
  221. data/vendor/prism/src/xxh3.c +292 -0
  222. data/vendor/prism/templates/ext/prism/api_node.c.erb +58 -44
  223. data/vendor/prism/templates/include/prism/ast.h.erb +67 -17
  224. data/vendor/prism/templates/include/prism/ast.hpp.erb +31 -0
  225. data/vendor/prism/templates/include/prism/internal/diagnostic.h.erb +60 -0
  226. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/AbstractNodeVisitor.java.erb +1 -1
  227. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Loader.java.erb +232 -133
  228. data/vendor/prism/templates/java/{org → api/src/main/java-templates/org/ruby_lang}/prism/Nodes.java.erb +62 -23
  229. data/vendor/prism/templates/javascript/src/deserialize.js.erb +153 -146
  230. data/vendor/prism/templates/javascript/src/nodes.js.erb +4 -9
  231. data/vendor/prism/templates/lib/prism/compiler.rb.erb +14 -5
  232. data/vendor/prism/templates/lib/prism/dispatcher.rb.erb +20 -12
  233. data/vendor/prism/templates/lib/prism/dot_visitor.rb.erb +37 -11
  234. data/vendor/prism/templates/lib/prism/dsl.rb.erb +43 -4
  235. data/vendor/prism/templates/lib/prism/inspect_visitor.rb.erb +26 -10
  236. data/vendor/prism/templates/lib/prism/mutation_compiler.rb.erb +5 -2
  237. data/vendor/prism/templates/lib/prism/node.rb.erb +283 -105
  238. data/vendor/prism/templates/lib/prism/reflection.rb.erb +11 -2
  239. data/vendor/prism/templates/lib/prism/serialize.rb.erb +291 -134
  240. data/vendor/prism/templates/lib/prism/visitor.rb.erb +18 -0
  241. data/vendor/prism/templates/src/diagnostic.c.erb +114 -63
  242. data/vendor/prism/templates/src/json.c.erb +130 -0
  243. data/vendor/prism/templates/src/node.c.erb +79 -236
  244. data/vendor/prism/templates/src/prettyprint.c.erb +24 -13
  245. data/vendor/prism/templates/src/serialize.c.erb +369 -183
  246. data/vendor/prism/templates/src/{token_type.c.erb → tokens.c.erb} +22 -11
  247. data/vendor/prism/templates/template.rb +193 -91
  248. metadata +100 -42
  249. data/vendor/prism/include/prism/defines.h +0 -260
  250. data/vendor/prism/include/prism/pack.h +0 -163
  251. data/vendor/prism/include/prism/regexp.h +0 -43
  252. data/vendor/prism/include/prism/static_literals.h +0 -121
  253. data/vendor/prism/include/prism/util/pm_buffer.h +0 -236
  254. data/vendor/prism/include/prism/util/pm_char.h +0 -204
  255. data/vendor/prism/include/prism/util/pm_constant_pool.h +0 -218
  256. data/vendor/prism/include/prism/util/pm_integer.h +0 -130
  257. data/vendor/prism/include/prism/util/pm_memchr.h +0 -29
  258. data/vendor/prism/include/prism/util/pm_newline_list.h +0 -113
  259. data/vendor/prism/include/prism/util/pm_string.h +0 -200
  260. data/vendor/prism/src/pack.c +0 -509
  261. data/vendor/prism/src/util/pm_constant_pool.c +0 -342
  262. data/vendor/prism/src/util/pm_list.c +0 -49
  263. data/vendor/prism/src/util/pm_newline_list.c +0 -125
  264. data/vendor/prism/src/util/pm_string.c +0 -381
  265. data/vendor/prism/src/util/pm_strpbrk.c +0 -206
  266. data/vendor/prism/templates/include/prism/diagnostic.h.erb +0 -130
  267. data/vendor/prism/templates/rbi/prism/dsl.rbi.erb +0 -68
  268. data/vendor/prism/templates/rbi/prism/node.rbi.erb +0 -167
  269. data/vendor/prism/templates/rbi/prism/visitor.rbi.erb +0 -18
  270. data/vendor/prism/templates/sig/prism/_private/dot_visitor.rbs.erb +0 -45
  271. data/vendor/prism/templates/sig/prism/dsl.rbs.erb +0 -31
  272. data/vendor/prism/templates/sig/prism/mutation_compiler.rbs.erb +0 -7
  273. data/vendor/prism/templates/sig/prism/node.rbs.erb +0 -136
  274. data/vendor/prism/templates/sig/prism/visitor.rbs.erb +0 -17
  275. data/vendor/prism/templates/sig/prism.rbs.erb +0 -92
@@ -8,6 +8,7 @@
8
8
  #include "../include/lib/hb_array.h"
9
9
  #include "../include/lib/hb_string.h"
10
10
  #include "../include/prism/herb_prism_node.h"
11
+ #include "../include/prism/prism_helpers.h"
11
12
  #include "../include/visitor.h"
12
13
 
13
14
  #include <prism.h>
@@ -26,7 +27,7 @@ static pm_node_t* find_ternary_statement(analyzed_ruby_T* analyzed) {
26
27
  if (statement->type != PM_IF_NODE) { return NULL; }
27
28
  pm_if_node_t* if_node = (pm_if_node_t*) statement;
28
29
 
29
- if (if_node->if_keyword_loc.start == NULL && if_node->subsequent != NULL) { return statement; }
30
+ if (!herb_prism_location_assigned(if_node->if_keyword_loc) && if_node->subsequent != NULL) { return statement; }
30
31
 
31
32
  return NULL;
32
33
  }
@@ -49,11 +50,11 @@ static body_info_T extract_statements_body_info(
49
50
  pm_node_t* first = statements->body.nodes[0];
50
51
  pm_node_t* last = statements->body.nodes[statements->body.size - 1];
51
52
 
52
- const uint8_t* start = first->location.start;
53
- const uint8_t* end = last->location.end;
53
+ const uint8_t* parser_start = pm_parser_start(analyzed->parser);
54
+ size_t source_length = (size_t) (pm_parser_end(analyzed->parser) - parser_start);
54
55
 
55
- const uint8_t* parser_start = analyzed->parser.start;
56
- size_t source_length = (size_t) (analyzed->parser.end - parser_start);
56
+ const uint8_t* start = herb_prism_location_start_pointer(parser_start, first->location);
57
+ const uint8_t* end = herb_prism_location_end_pointer(parser_start, last->location);
57
58
 
58
59
  if (start < parser_start || end > parser_start + source_length) { return info; }
59
60
 
@@ -83,14 +84,16 @@ static body_info_T extract_statements_body_info(
83
84
  return info;
84
85
  }
85
86
 
86
- static char* extract_condition_source(pm_if_node_t* if_node, hb_allocator_T* allocator) {
87
+ static char* extract_condition_source(const uint8_t* source, pm_if_node_t* if_node, hb_allocator_T* allocator) {
87
88
  pm_node_t* predicate = if_node->predicate;
88
89
 
89
90
  if (!predicate) { return NULL; }
90
91
 
91
- size_t length = (size_t) (predicate->location.end - predicate->location.start);
92
-
93
- return hb_allocator_strndup(allocator, (const char*) predicate->location.start, length);
92
+ return hb_allocator_strndup(
93
+ allocator,
94
+ (const char*) (source + predicate->location.start),
95
+ predicate->location.length
96
+ );
94
97
  }
95
98
 
96
99
  static bool append_branch_statement(
@@ -156,7 +159,8 @@ AST_NODE_T* transform_ternary_expression(
156
159
  pm_else_node_t* else_node = (pm_else_node_t*) if_node->subsequent;
157
160
  if (!else_node) { return NULL; }
158
161
 
159
- char* condition_source = extract_condition_source(if_node, allocator);
162
+ char* condition_source =
163
+ extract_condition_source(pm_parser_start(erb_node->analyzed_ruby->parser), if_node, allocator);
160
164
  if (!condition_source) { return NULL; }
161
165
 
162
166
  position_T start = erb_node->base.location.start;
@@ -32,7 +32,7 @@ static size_t element_attribute_count(const AST_NODE_T* node) {
32
32
  if (node->type == AST_HTML_ELEMENT_NODE) {
33
33
  const AST_HTML_ELEMENT_NODE_T* element = (const AST_HTML_ELEMENT_NODE_T*) node;
34
34
 
35
- if (element->open_tag != NULL) {
35
+ if (element->open_tag != NULL && element->open_tag->type == AST_HTML_OPEN_TAG_NODE) {
36
36
  const AST_HTML_OPEN_TAG_NODE_T* open_tag = (const AST_HTML_OPEN_TAG_NODE_T*) element->open_tag;
37
37
 
38
38
  if (open_tag->children != NULL) { return hb_array_size(open_tag->children); }
@@ -37,15 +37,7 @@ static void diff_element_node(
37
37
  }
38
38
 
39
39
  if (old_element->open_tag != NULL && new_element->open_tag != NULL) {
40
- herb_hash_T old_open_hash = herb_hash_map_get(old_hashes, old_element->open_tag);
41
- herb_hash_T new_open_hash = herb_hash_map_get(new_hashes, new_element->open_tag);
42
-
43
- if (old_open_hash != new_open_hash) {
44
- const AST_HTML_OPEN_TAG_NODE_T* old_open_tag = (const AST_HTML_OPEN_TAG_NODE_T*) old_element->open_tag;
45
- const AST_HTML_OPEN_TAG_NODE_T* new_open_tag = (const AST_HTML_OPEN_TAG_NODE_T*) new_element->open_tag;
46
-
47
- herb_diff_attributes(old_open_tag->children, new_open_tag->children, path, old_hashes, new_hashes, result);
48
- }
40
+ herb_diff_node(old_element->open_tag, new_element->open_tag, path, old_hashes, new_hashes, preserve_whitespace, result);
49
41
  }
50
42
 
51
43
  if (old_element->body != NULL && new_element->body != NULL) {
@@ -729,7 +729,7 @@ herb_hash_T herb_hash_node_move_identity(const AST_NODE_T* node, const herb_hash
729
729
  const AST_HTML_ELEMENT_NODE_T* element = (const AST_HTML_ELEMENT_NODE_T*) node;
730
730
  hash = hash_token(hash, element->tag_name);
731
731
 
732
- if (element->open_tag != NULL) {
732
+ if (element->open_tag != NULL && element->open_tag->type == AST_HTML_OPEN_TAG_NODE) {
733
733
  const AST_HTML_OPEN_TAG_NODE_T* open_tag = (const AST_HTML_OPEN_TAG_NODE_T*) element->open_tag;
734
734
  hash = herb_hash_combine(hash, identity_hash_attributes(open_tag->children, hash_map));
735
735
  }
data/src/errors.c CHANGED
@@ -1264,7 +1264,7 @@ RENDER_AMBIGUOUS_LOCALS_ERROR_T* render_ambiguous_locals_error_init(hb_string_T
1264
1264
 
1265
1265
  error_init(&render_ambiguous_locals_error->base, RENDER_AMBIGUOUS_LOCALS_ERROR, start, end);
1266
1266
 
1267
- const char* message_template = "Did you mean `render partial: '%s', locals: { ... }`? Using `render '%s', locals: { ... }` passes a local variable named `locals` to the partial instead of setting the `locals:` option.";
1267
+ const char* message_template = "Did you mean `render partial: %s, locals: { ... }`? Using `render %s, locals: { ... }` passes a local variable named `locals` to the partial instead of setting the `locals:` option.";
1268
1268
 
1269
1269
  hb_string_T truncated_argument_0 = hb_string_truncate(partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
1270
1270
  char* truncated_c_string_0 = hb_string_to_c_string_using_malloc(truncated_argument_0);
@@ -1272,7 +1272,7 @@ RENDER_AMBIGUOUS_LOCALS_ERROR_T* render_ambiguous_locals_error_init(hb_string_T
1272
1272
  hb_string_T truncated_argument_1 = hb_string_truncate(partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
1273
1273
  char* truncated_c_string_1 = hb_string_to_c_string_using_malloc(truncated_argument_1);
1274
1274
 
1275
- char message[442];
1275
+ char message[438];
1276
1276
  snprintf(
1277
1277
  message,
1278
1278
  sizeof(message),
@@ -1297,48 +1297,43 @@ void append_render_ambiguous_locals_error(hb_string_T partial, position_T start,
1297
1297
  parser_options_increment_error_count(options);
1298
1298
  }
1299
1299
 
1300
- RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error_init(hb_string_T partial, hb_string_T keywords, position_T start, position_T end, hb_allocator_T* allocator) {
1300
+ RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error_init(hb_string_T keywords, hb_string_T suggestion, position_T start, position_T end, hb_allocator_T* allocator) {
1301
1301
  RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error = hb_allocator_alloc(allocator, sizeof(RENDER_MISSING_LOCALS_ERROR_T));
1302
1302
 
1303
1303
  if (!render_missing_locals_error) { return NULL; }
1304
1304
 
1305
1305
  error_init(&render_missing_locals_error->base, RENDER_MISSING_LOCALS_ERROR, start, end);
1306
1306
 
1307
- const char* message_template = "Wrap `%s` in `locals: { ... }` when using `partial:`. Use `render partial: '%s', locals: { %s }` instead. Without `locals:`, these keyword arguments are ignored.";
1307
+ const char* message_template = "Wrap `%s` in `locals: { ... }` when using `partial:`. Use `render %s` instead. Without `locals:`, these keyword arguments are ignored.";
1308
1308
 
1309
1309
  hb_string_T truncated_argument_0 = hb_string_truncate(keywords, ERROR_MESSAGES_TRUNCATED_LENGTH);
1310
1310
  char* truncated_c_string_0 = hb_string_to_c_string_using_malloc(truncated_argument_0);
1311
1311
 
1312
- hb_string_T truncated_argument_1 = hb_string_truncate(partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
1312
+ hb_string_T truncated_argument_1 = hb_string_truncate(suggestion, ERROR_MESSAGES_TRUNCATED_LENGTH);
1313
1313
  char* truncated_c_string_1 = hb_string_to_c_string_using_malloc(truncated_argument_1);
1314
1314
 
1315
- hb_string_T truncated_argument_2 = hb_string_truncate(keywords, ERROR_MESSAGES_TRUNCATED_LENGTH);
1316
- char* truncated_c_string_2 = hb_string_to_c_string_using_malloc(truncated_argument_2);
1317
-
1318
- char message[546];
1315
+ char message[391];
1319
1316
  snprintf(
1320
1317
  message,
1321
1318
  sizeof(message),
1322
1319
  message_template,
1323
1320
  truncated_c_string_0 ? truncated_c_string_0 : "",
1324
- truncated_c_string_1 ? truncated_c_string_1 : "",
1325
- truncated_c_string_2 ? truncated_c_string_2 : ""
1321
+ truncated_c_string_1 ? truncated_c_string_1 : ""
1326
1322
  );
1327
1323
 
1328
1324
  if (truncated_c_string_0) { free(truncated_c_string_0); }
1329
1325
  if (truncated_c_string_1) { free(truncated_c_string_1); }
1330
- if (truncated_c_string_2) { free(truncated_c_string_2); }
1331
1326
  render_missing_locals_error->base.message = hb_string_copy(hb_string(message), allocator);
1332
1327
 
1333
- render_missing_locals_error->partial = hb_string_copy(partial, allocator);
1334
1328
  render_missing_locals_error->keywords = hb_string_copy(keywords, allocator);
1329
+ render_missing_locals_error->suggestion = hb_string_copy(suggestion, allocator);
1335
1330
  return render_missing_locals_error;
1336
1331
  }
1337
1332
 
1338
- void append_render_missing_locals_error(hb_string_T partial, hb_string_T keywords, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T** errors, const struct PARSER_OPTIONS_STRUCT* options) {
1333
+ void append_render_missing_locals_error(hb_string_T keywords, hb_string_T suggestion, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T** errors, const struct PARSER_OPTIONS_STRUCT* options) {
1339
1334
  if (parser_options_errors_exceeded(options)) { return; }
1340
1335
 
1341
- hb_array_append_lazy(errors, render_missing_locals_error_init(partial, keywords, start, end, allocator), allocator);
1336
+ hb_array_append_lazy(errors, render_missing_locals_error_init(keywords, suggestion, start, end, allocator), allocator);
1342
1337
 
1343
1338
  parser_options_increment_error_count(options);
1344
1339
  }
@@ -1370,7 +1365,7 @@ RENDER_CONFLICTING_PARTIAL_ERROR_T* render_conflicting_partial_error_init(hb_str
1370
1365
 
1371
1366
  error_init(&render_conflicting_partial_error->base, RENDER_CONFLICTING_PARTIAL_ERROR, start, end);
1372
1367
 
1373
- const char* message_template = "Both a positional partial `'%s'` and a keyword `partial: '%s'` were passed to `render`. Use one form or the other, not both.";
1368
+ const char* message_template = "Both a positional partial `%s` and a keyword `partial: %s` were passed to `render`. Use one form or the other, not both.";
1374
1369
 
1375
1370
  hb_string_T truncated_argument_0 = hb_string_truncate(positional_partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
1376
1371
  char* truncated_c_string_0 = hb_string_to_c_string_using_malloc(truncated_argument_0);
@@ -1378,7 +1373,7 @@ RENDER_CONFLICTING_PARTIAL_ERROR_T* render_conflicting_partial_error_init(hb_str
1378
1373
  hb_string_T truncated_argument_1 = hb_string_truncate(keyword_partial, ERROR_MESSAGES_TRUNCATED_LENGTH);
1379
1374
  char* truncated_c_string_1 = hb_string_to_c_string_using_malloc(truncated_argument_1);
1380
1375
 
1381
- char message[381];
1376
+ char message[377];
1382
1377
  snprintf(
1383
1378
  message,
1384
1379
  sizeof(message),
@@ -1466,12 +1461,12 @@ RENDER_LAYOUT_WITHOUT_BLOCK_ERROR_T* render_layout_without_block_error_init(hb_s
1466
1461
 
1467
1462
  error_init(&render_layout_without_block_error->base, RENDER_LAYOUT_WITHOUT_BLOCK_ERROR, start, end);
1468
1463
 
1469
- const char* message_template = "Layout rendering needs a block. Use `render layout: '%s' do ... end` so the layout has content to wrap.";
1464
+ const char* message_template = "Layout rendering needs a block. Use `render layout: %s do ... end` so the layout has content to wrap.";
1470
1465
 
1471
1466
  hb_string_T truncated_argument_0 = hb_string_truncate(layout, ERROR_MESSAGES_TRUNCATED_LENGTH);
1472
1467
  char* truncated_c_string_0 = hb_string_to_c_string_using_malloc(truncated_argument_0);
1473
1468
 
1474
- char message[232];
1469
+ char message[230];
1475
1470
  snprintf(
1476
1471
  message,
1477
1472
  sizeof(message),
@@ -2254,8 +2249,8 @@ static void error_free_render_ambiguous_locals_error(RENDER_AMBIGUOUS_LOCALS_ERR
2254
2249
  }
2255
2250
 
2256
2251
  static void error_free_render_missing_locals_error(RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error, hb_allocator_T* allocator) {
2257
- if (!hb_string_is_empty(render_missing_locals_error->partial)) { hb_allocator_dealloc(allocator, render_missing_locals_error->partial.data); }
2258
2252
  if (!hb_string_is_empty(render_missing_locals_error->keywords)) { hb_allocator_dealloc(allocator, render_missing_locals_error->keywords.data); }
2253
+ if (!hb_string_is_empty(render_missing_locals_error->suggestion)) { hb_allocator_dealloc(allocator, render_missing_locals_error->suggestion.data); }
2259
2254
 
2260
2255
  error_free_base_error(&render_missing_locals_error->base, allocator);
2261
2256
  }
@@ -2974,8 +2969,8 @@ static void error_pretty_print_render_missing_locals_error(RENDER_MISSING_LOCALS
2974
2969
  hb_buffer_append(buffer, "\n");
2975
2970
 
2976
2971
  pretty_print_quoted_property(hb_string("message"), error->base.message, indent, relative_indent, false, buffer);
2977
- pretty_print_quoted_property(hb_string("partial"), error->partial, indent, relative_indent, false, buffer);
2978
- pretty_print_quoted_property(hb_string("keywords"), error->keywords, indent, relative_indent, true, buffer);
2972
+ pretty_print_quoted_property(hb_string("keywords"), error->keywords, indent, relative_indent, false, buffer);
2973
+ pretty_print_quoted_property(hb_string("suggestion"), error->suggestion, indent, relative_indent, true, buffer);
2979
2974
  }
2980
2975
 
2981
2976
  static void error_pretty_print_render_no_arguments_error(RENDER_NO_ARGUMENTS_ERROR_T* error, const size_t indent, const size_t relative_indent, hb_buffer_T* buffer) {
data/src/extract.c CHANGED
@@ -9,6 +9,7 @@
9
9
  #include "include/util/util.h"
10
10
 
11
11
  #include <assert.h>
12
+ #include <ctype.h>
12
13
  #include <stdlib.h>
13
14
  #include <string.h>
14
15
 
@@ -19,6 +20,39 @@ const herb_extract_ruby_options_T HERB_EXTRACT_RUBY_DEFAULT_OPTIONS = { .semicol
19
20
  .erb_openers = NULL,
20
21
  .erb_opener_count = 0 };
21
22
 
23
+ static bool ruby_comment_starts_line(const lexer_T* lexer, uint32_t tag_start) {
24
+ for (uint32_t position = tag_start; position > 0; position--) {
25
+ unsigned char character = (unsigned char) lexer->source.data[position - 1];
26
+
27
+ if (is_newline(character)) { return true; }
28
+ if (!isspace(character)) { return false; }
29
+ }
30
+
31
+ return true;
32
+ }
33
+
34
+ static bool ruby_comment_ends_line(const lexer_T* lexer) {
35
+ lexer_T lookahead = *lexer;
36
+ token_T* closing = lexer_next_token(&lookahead);
37
+ bool has_closing = closing->type == TOKEN_ERB_END;
38
+ token_free(closing, lookahead.allocator);
39
+
40
+ if (!has_closing) { return false; }
41
+
42
+ for (size_t position = lookahead.current_position; position < lookahead.source.length; position++) {
43
+ unsigned char character = (unsigned char) lookahead.source.data[position];
44
+
45
+ if (is_newline(character)) { return true; }
46
+ if (!isspace(character)) { return false; }
47
+ }
48
+
49
+ return true;
50
+ }
51
+
52
+ static bool ruby_comment_on_own_line(const lexer_T* lexer, uint32_t tag_start) {
53
+ return ruby_comment_starts_line(lexer, tag_start) && ruby_comment_ends_line(lexer);
54
+ }
55
+
22
56
  typedef struct {
23
57
  herb_extract_ruby_options_T options;
24
58
  hb_buffer_T* output;
@@ -26,6 +60,7 @@ typedef struct {
26
60
  bool is_comment_tag;
27
61
  bool is_erb_comment_tag;
28
62
  bool need_newline;
63
+ uint32_t tag_start;
29
64
  } extract_ruby_state_T;
30
65
 
31
66
  static void extract_ruby_data(extract_ruby_state_T* state, const char* data, uint32_t from, uint32_t to) {
@@ -44,7 +79,12 @@ static void extract_ruby_data(extract_ruby_state_T* state, const char* data, uin
44
79
  if (state->options.preserve_positions) { hb_buffer_append_whitespace(state->output, to - run_start); }
45
80
  }
46
81
 
47
- static void extract_ruby_token(extract_ruby_state_T* state, const token_T* token, const token_T* next) {
82
+ static void extract_ruby_token(
83
+ extract_ruby_state_T* state,
84
+ const token_T* token,
85
+ const token_T* next,
86
+ const lexer_T* lexer
87
+ ) {
48
88
  switch (token->type) {
49
89
  case TOKEN_NEWLINE: {
50
90
  hb_buffer_append_string(state->output, token->value);
@@ -53,6 +93,7 @@ static void extract_ruby_token(extract_ruby_state_T* state, const token_T* token
53
93
  }
54
94
 
55
95
  case TOKEN_ERB_START: {
96
+ state->tag_start = token->range.from;
56
97
  state->is_erb_comment_tag = hb_string_equals(token->value, hb_string("<%#"));
57
98
 
58
99
  if (state->is_erb_comment_tag) {
@@ -113,20 +154,19 @@ static void extract_ruby_token(extract_ruby_state_T* state, const token_T* token
113
154
  if (state->skip_erb_content == false) {
114
155
  bool is_inline_comment = false;
115
156
 
116
- if (!state->options.comments && !state->is_comment_tag && !hb_string_is_empty(token->value)) {
157
+ if (!state->options.comments && state->options.preserve_positions && !state->is_comment_tag
158
+ && !hb_string_is_empty(token->value)) {
117
159
  hb_string_T trimmed = hb_string_trim_start(token->value);
118
160
 
119
161
  if (!hb_string_is_empty(trimmed) && trimmed.data[0] == '#'
120
162
  && token->location.start.line == token->location.end.line) {
121
163
  state->is_comment_tag = true;
122
- is_inline_comment = true;
164
+ is_inline_comment = !ruby_comment_on_own_line(lexer, state->tag_start);
123
165
  }
124
166
  }
125
167
 
126
168
  if (is_inline_comment) {
127
- if (state->options.preserve_positions) {
128
- hb_buffer_append_whitespace(state->output, range_length(token->range));
129
- }
169
+ hb_buffer_append_whitespace(state->output, range_length(token->range));
130
170
  } else if (state->is_erb_comment_tag && !hb_string_is_null(token->value)) {
131
171
  const char* content = token->value.data;
132
172
  size_t content_remaining = token->value.length;
@@ -260,7 +300,7 @@ void herb_extract_ruby_to_buffer_with_options(
260
300
 
261
301
  if (token->type == TOKEN_ERB_START) { pending = lexer_next_token(&lexer); }
262
302
 
263
- extract_ruby_token(&state, token, pending);
303
+ extract_ruby_token(&state, token, pending, &lexer);
264
304
  token_free(token, allocator);
265
305
  }
266
306
  }
data/src/herb.c CHANGED
@@ -7,6 +7,7 @@
7
7
  #include "include/lib/hb_allocator.h"
8
8
  #include "include/lib/hb_array.h"
9
9
  #include "include/parser/parser.h"
10
+ #include "include/prism_version.h"
10
11
  #include "include/version.h"
11
12
  #include "include/visitor.h"
12
13
 
@@ -127,7 +128,7 @@ HERB_EXPORTED_FUNCTION const char* herb_version(void) {
127
128
  }
128
129
 
129
130
  HERB_EXPORTED_FUNCTION const char* herb_prism_version(void) {
130
- return PRISM_VERSION;
131
+ return HERB_PRISM_VERSION;
131
132
  }
132
133
 
133
134
  HERB_EXPORTED_FUNCTION herb_ruby_parse_result_T* herb_parse_ruby(const char* source, size_t length) {
@@ -136,9 +137,11 @@ HERB_EXPORTED_FUNCTION herb_ruby_parse_result_T* herb_parse_ruby(const char* sou
136
137
  herb_ruby_parse_result_T* result = malloc(sizeof(herb_ruby_parse_result_T));
137
138
  if (!result) { return NULL; }
138
139
 
139
- memset(&result->options, 0, sizeof(pm_options_t));
140
- pm_parser_init(&result->parser, (const uint8_t*) source, length, &result->options);
141
- result->root = pm_parse(&result->parser);
140
+ result->arena = pm_arena_new();
141
+ result->options = pm_options_new();
142
+ pm_options_line_set(result->options, 0);
143
+ result->parser = pm_parser_new(result->arena, (const uint8_t*) source, length, result->options);
144
+ result->root = pm_parse(result->parser);
142
145
 
143
146
  return result;
144
147
  }
@@ -146,9 +149,8 @@ HERB_EXPORTED_FUNCTION herb_ruby_parse_result_T* herb_parse_ruby(const char* sou
146
149
  HERB_EXPORTED_FUNCTION void herb_free_ruby_parse_result(herb_ruby_parse_result_T* result) {
147
150
  if (!result) { return; }
148
151
 
149
- if (result->root) { pm_node_destroy(&result->parser, result->root); }
150
-
151
- pm_parser_free(&result->parser);
152
- pm_options_free(&result->options);
152
+ pm_parser_free(result->parser);
153
+ pm_arena_free(result->arena);
154
+ pm_options_free(result->options);
153
155
  free(result);
154
156
  }
@@ -38,7 +38,7 @@ void tag_helper_info_free(tag_helper_info_T** info);
38
38
  const tag_helper_handler_T* const* get_tag_helper_handlers(void);
39
39
  size_t get_tag_helper_handlers_count(void);
40
40
 
41
- char* extract_inline_block_content(pm_call_node_t* call_node, hb_allocator_T* allocator);
41
+ char* extract_inline_block_content(pm_call_node_t* call_node, pm_parser_t* parser, hb_allocator_T* allocator);
42
42
 
43
43
  struct AST_NODE_STRUCT;
44
44
  bool wrap_javascript_tag_body_visitor(const struct AST_NODE_STRUCT* node, void* data);
@@ -58,6 +58,7 @@ AST_HTML_ATTRIBUTE_NODE_T* create_html_attribute_with_ruby_literal(
58
58
  AST_HTML_ATTRIBUTE_NODE_T* create_html_attribute_with_interpolated_value(
59
59
  const char* name_string,
60
60
  pm_interpolated_string_node_t* interpolated_node,
61
+ const uint8_t* source,
61
62
  position_T start_position,
62
63
  position_T end_position,
63
64
  hb_allocator_T* allocator
@@ -19,7 +19,7 @@ typedef struct {
19
19
  bool found;
20
20
  } tag_helper_search_data_T;
21
21
 
22
- bool search_tag_helper_node(const pm_node_t* node, void* data);
22
+ pm_visit_result_t search_tag_helper_node(const pm_node_t* node, void* data);
23
23
 
24
24
  position_T prism_location_to_position_with_offset(
25
25
  const pm_location_t* pm_location,
@@ -10,8 +10,9 @@
10
10
 
11
11
  typedef struct TAG_HELPER_SCOPE_STRUCT {
12
12
  hb_buffer_T buffer;
13
- pm_options_t options;
14
- pm_parser_t parser;
13
+ pm_arena_t* arena;
14
+ pm_options_t* options;
15
+ pm_parser_t* parser;
15
16
  pm_node_t* root;
16
17
  } tag_helper_scope_T;
17
18
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  #include "../lib/hb_array.h"
5
5
  #include "../lib/hb_string.h"
6
+ #include "../parser/parser_options.h"
6
7
 
7
8
  #include <prism.h>
8
9
  #include <stdbool.h>
@@ -30,7 +31,8 @@ typedef enum {
30
31
  } control_type_t;
31
32
 
32
33
  typedef struct ANALYZED_RUBY_STRUCT {
33
- pm_parser_t parser;
34
+ pm_arena_t* arena;
35
+ pm_parser_t* parser;
34
36
  pm_node_t* root;
35
37
  bool valid;
36
38
  bool parsed;
@@ -58,7 +60,7 @@ typedef struct ANALYZED_RUBY_STRUCT {
58
60
  bool control_type_detected;
59
61
  } analyzed_ruby_T;
60
62
 
61
- analyzed_ruby_T* init_analyzed_ruby(hb_string_T source);
63
+ analyzed_ruby_T* init_analyzed_ruby(hb_string_T source, const parser_options_T* options);
62
64
  void free_analyzed_ruby(analyzed_ruby_T* analyzed);
63
65
  hb_string_T erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed);
64
66
 
@@ -37,13 +37,13 @@ bool control_role_split_offset(const analyzed_ruby_T* analyzed, uint32_t* offset
37
37
 
38
38
  bool has_error_message(analyzed_ruby_T* anlayzed, const char* message);
39
39
 
40
- bool is_do_block(pm_location_t opening_location);
41
- bool is_brace_block(pm_location_t opening_location);
42
- bool is_closing_brace(pm_location_t location);
43
- bool has_valid_block_closing(pm_location_t opening_loc, pm_location_t closing_loc);
40
+ bool is_do_block(const uint8_t* source, pm_location_t opening_location);
41
+ bool is_brace_block(const uint8_t* source, pm_location_t opening_location);
42
+ bool is_closing_brace(const uint8_t* source, pm_location_t location);
43
+ bool has_valid_block_closing(const uint8_t* source, pm_location_t opening_loc, pm_location_t closing_loc);
44
44
 
45
- bool search_control_flow_nodes(const pm_node_t* node, void* data);
46
- bool search_unclosed_control_flows(const pm_node_t* node, void* data);
45
+ pm_visit_result_t search_control_flow_nodes(const pm_node_t* node, void* data);
46
+ pm_visit_result_t search_unclosed_control_flows(const pm_node_t* node, void* data);
47
47
  void search_unexpected_keyword_errors(analyzed_ruby_T* analyzed);
48
48
 
49
49
  void check_erb_node_for_missing_end(const AST_NODE_T* node, hb_allocator_T* allocator, const parser_options_T* options);
data/src/include/errors.h CHANGED
@@ -269,8 +269,8 @@ typedef struct {
269
269
 
270
270
  typedef struct {
271
271
  ERROR_T base;
272
- hb_string_T partial;
273
272
  hb_string_T keywords;
273
+ hb_string_T suggestion;
274
274
  } RENDER_MISSING_LOCALS_ERROR_T;
275
275
 
276
276
  typedef struct {
@@ -430,8 +430,8 @@ NESTED_ERB_TAG_ERROR_T* nested_erb_tag_error_init(token_T* opening_tag, size_t n
430
430
  void append_nested_erb_tag_error(token_T* opening_tag, size_t nested_tag_line, size_t nested_tag_column, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T** errors, const struct PARSER_OPTIONS_STRUCT* options);
431
431
  RENDER_AMBIGUOUS_LOCALS_ERROR_T* render_ambiguous_locals_error_init(hb_string_T partial, position_T start, position_T end, hb_allocator_T* allocator);
432
432
  void append_render_ambiguous_locals_error(hb_string_T partial, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T** errors, const struct PARSER_OPTIONS_STRUCT* options);
433
- RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error_init(hb_string_T partial, hb_string_T keywords, position_T start, position_T end, hb_allocator_T* allocator);
434
- void append_render_missing_locals_error(hb_string_T partial, hb_string_T keywords, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T** errors, const struct PARSER_OPTIONS_STRUCT* options);
433
+ RENDER_MISSING_LOCALS_ERROR_T* render_missing_locals_error_init(hb_string_T keywords, hb_string_T suggestion, position_T start, position_T end, hb_allocator_T* allocator);
434
+ void append_render_missing_locals_error(hb_string_T keywords, hb_string_T suggestion, position_T start, position_T end, hb_allocator_T* allocator, hb_array_T** errors, const struct PARSER_OPTIONS_STRUCT* options);
435
435
  RENDER_NO_ARGUMENTS_ERROR_T* render_no_arguments_error_init(position_T start, position_T end, hb_allocator_T* allocator);
436
436
  void append_render_no_arguments_error(position_T start, position_T end, hb_allocator_T* allocator, hb_array_T** errors, const struct PARSER_OPTIONS_STRUCT* options);
437
437
  RENDER_CONFLICTING_PARTIAL_ERROR_T* render_conflicting_partial_error_init(hb_string_T positional_partial, hb_string_T keyword_partial, position_T start, position_T end, hb_allocator_T* allocator);
data/src/include/herb.h CHANGED
@@ -36,9 +36,10 @@ HERB_EXPORTED_FUNCTION const char* herb_version(void);
36
36
  HERB_EXPORTED_FUNCTION const char* herb_prism_version(void);
37
37
 
38
38
  typedef struct {
39
- pm_parser_t parser;
39
+ pm_arena_t* arena;
40
+ pm_parser_t* parser;
40
41
  pm_node_t* root;
41
- pm_options_t options;
42
+ pm_options_t* options;
42
43
  } herb_ruby_parse_result_T;
43
44
 
44
45
  HERB_EXPORTED_FUNCTION herb_ruby_parse_result_T* herb_parse_ruby(const char* source, size_t length);
@@ -10,6 +10,8 @@
10
10
  #include <stddef.h>
11
11
  #include <stdint.h>
12
12
 
13
+ #define HERB_PARSER_OPTIONS_STRING_CAPACITY 16
14
+
13
15
  typedef struct PARSER_OPTIONS_STRUCT {
14
16
  bool action_view_helpers;
15
17
  bool analyze;
@@ -24,6 +26,7 @@ typedef struct PARSER_OPTIONS_STRUCT {
24
26
  bool prism_nodes_deep;
25
27
  bool prism_program;
26
28
  bool render_nodes;
29
+ char ruby_version[HERB_PARSER_OPTIONS_STRING_CAPACITY];
27
30
  bool strict;
28
31
  bool strict_locals;
29
32
  uint32_t timeout_ms;
@@ -38,4 +41,6 @@ typedef struct PARSER_OPTIONS_STRUCT {
38
41
 
39
42
  extern const parser_options_T HERB_DEFAULT_PARSER_OPTIONS;
40
43
 
44
+ bool herb_ruby_version_supported(const char* value, size_t length);
45
+
41
46
  #endif
@@ -7,14 +7,16 @@
7
7
  #include <stdbool.h>
8
8
 
9
9
  typedef struct {
10
- pm_parser_t parser;
11
- pm_options_t pm_opts;
10
+ pm_arena_t* arena;
11
+ pm_parser_t* parser;
12
+ pm_options_t* pm_opts;
12
13
  pm_node_t* root;
13
14
  hb_buffer_T ruby_buf;
14
15
 
15
16
  bool has_structural;
16
- pm_parser_t structural_parser;
17
- pm_options_t structural_pm_opts;
17
+ pm_arena_t* structural_arena;
18
+ pm_parser_t* structural_parser;
19
+ pm_options_t* structural_pm_opts;
18
20
  pm_node_t* structural_root;
19
21
  hb_buffer_T structural_buf;
20
22
 
@@ -24,17 +26,15 @@ typedef struct {
24
26
  static inline void herb_prism_context_free(herb_prism_context_T* context) {
25
27
  if (!context) { return; }
26
28
 
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);
29
+ if (context->parser) { pm_parser_free(context->parser); }
30
+ if (context->arena) { pm_arena_free(context->arena); }
31
+ if (context->pm_opts) { pm_options_free(context->pm_opts); }
31
32
  hb_buffer_free(&context->ruby_buf);
32
33
 
33
34
  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);
35
+ if (context->structural_parser) { pm_parser_free(context->structural_parser); }
36
+ if (context->structural_arena) { pm_arena_free(context->structural_arena); }
37
+ if (context->structural_pm_opts) { pm_options_free(context->structural_pm_opts); }
38
38
 
39
39
  if (context->structural_buf.value) { hb_buffer_free(&context->structural_buf); }
40
40
  }
@@ -7,9 +7,39 @@
7
7
  #include "../lib/hb_allocator.h"
8
8
  #include "../location/location.h"
9
9
  #include "../location/position.h"
10
+ #include "../parser/parser_options.h"
10
11
 
11
12
  #include <prism.h>
12
13
 
14
+ static inline bool herb_prism_location_present(pm_location_t location) {
15
+ return location.length > 0;
16
+ }
17
+
18
+ static inline bool herb_prism_location_assigned(pm_location_t location) {
19
+ return location.start != 0 || location.length != 0;
20
+ }
21
+
22
+ static inline uint32_t herb_prism_location_end(pm_location_t location) {
23
+ return location.start + location.length;
24
+ }
25
+
26
+ static inline const uint8_t* herb_prism_location_start_pointer(const uint8_t* base, pm_location_t location) {
27
+ return base + location.start;
28
+ }
29
+
30
+ static inline const uint8_t* herb_prism_location_end_pointer(const uint8_t* base, pm_location_t location) {
31
+ return base + location.start + location.length;
32
+ }
33
+
34
+ void herb_prism_options_set_ruby_version(pm_options_t* options, const parser_options_T* parser_options);
35
+
36
+ pm_parser_t* herb_prism_parser_new(
37
+ pm_arena_t* arena,
38
+ const uint8_t* source,
39
+ size_t length,
40
+ const parser_options_T* parser_options
41
+ );
42
+
13
43
  hb_string_T pm_error_level_to_string(pm_error_level_t level);
14
44
 
15
45
  RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
@@ -0,0 +1,11 @@
1
+ // NOTE: This file is generated by the templates/template.rb script and should not
2
+ // be modified manually. See templates/src/include/prism_version.h.erb
3
+
4
+ #ifndef HERB_PRISM_VERSION_H
5
+ #define HERB_PRISM_VERSION_H
6
+
7
+ #include <prism/version.h>
8
+
9
+ #define HERB_PRISM_VERSION PRISM_VERSION "+4691667"
10
+
11
+ #endif
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.11.1"
4
+ #define HERB_VERSION "0.11.3"
5
5
 
6
6
  #endif