herb 0.7.5 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +8 -5
  3. data/config.yml +26 -6
  4. data/ext/herb/error_helpers.c +57 -3
  5. data/ext/herb/error_helpers.h +1 -1
  6. data/ext/herb/extconf.rb +1 -0
  7. data/ext/herb/extension.c +10 -24
  8. data/ext/herb/extension_helpers.c +3 -3
  9. data/ext/herb/extension_helpers.h +1 -1
  10. data/ext/herb/nodes.c +72 -37
  11. data/herb.gemspec +0 -2
  12. data/lib/herb/ast/helpers.rb +11 -0
  13. data/lib/herb/ast/node.rb +15 -6
  14. data/lib/herb/ast/nodes.rb +609 -392
  15. data/lib/herb/cli.rb +31 -0
  16. data/lib/herb/colors.rb +82 -0
  17. data/lib/herb/engine/compiler.rb +140 -14
  18. data/lib/herb/engine/debug_visitor.rb +1 -5
  19. data/lib/herb/engine/parser_error_overlay.rb +1 -1
  20. data/lib/herb/engine.rb +8 -14
  21. data/lib/herb/errors.rb +166 -56
  22. data/lib/herb/location.rb +2 -2
  23. data/lib/herb/project.rb +86 -21
  24. data/lib/herb/token.rb +14 -2
  25. data/lib/herb/version.rb +1 -1
  26. data/lib/herb.rb +1 -0
  27. data/sig/herb/ast/helpers.rbs +3 -0
  28. data/sig/herb/ast/node.rbs +12 -5
  29. data/sig/herb/ast/nodes.rbs +124 -62
  30. data/sig/herb/colors.rbs +35 -0
  31. data/sig/herb/engine/compiler.rbs +23 -1
  32. data/sig/herb/errors.rbs +74 -20
  33. data/sig/herb/token.rbs +8 -0
  34. data/sig/herb_c_extension.rbs +1 -1
  35. data/sig/serialized_ast_errors.rbs +8 -0
  36. data/src/analyze.c +420 -171
  37. data/src/analyze_helpers.c +5 -0
  38. data/src/analyze_missing_end.c +147 -0
  39. data/src/analyze_transform.c +196 -0
  40. data/src/analyzed_ruby.c +23 -2
  41. data/src/ast_node.c +5 -5
  42. data/src/ast_nodes.c +179 -179
  43. data/src/ast_pretty_print.c +232 -232
  44. data/src/element_source.c +7 -6
  45. data/src/errors.c +246 -126
  46. data/src/extract.c +92 -34
  47. data/src/herb.c +37 -49
  48. data/src/html_util.c +34 -96
  49. data/src/include/analyze.h +10 -2
  50. data/src/include/analyze_helpers.h +3 -0
  51. data/src/include/analyzed_ruby.h +4 -2
  52. data/src/include/ast_node.h +2 -2
  53. data/src/include/ast_nodes.h +67 -66
  54. data/src/include/ast_pretty_print.h +2 -2
  55. data/src/include/element_source.h +3 -1
  56. data/src/include/errors.h +30 -14
  57. data/src/include/extract.h +4 -4
  58. data/src/include/herb.h +6 -7
  59. data/src/include/html_util.h +4 -5
  60. data/src/include/lexer.h +1 -3
  61. data/src/include/lexer_peek_helpers.h +14 -14
  62. data/src/include/lexer_struct.h +3 -2
  63. data/src/include/macros.h +4 -0
  64. data/src/include/parser.h +12 -6
  65. data/src/include/parser_helpers.h +25 -15
  66. data/src/include/pretty_print.h +38 -28
  67. data/src/include/token.h +5 -8
  68. data/src/include/utf8.h +3 -2
  69. data/src/include/util/hb_arena.h +31 -0
  70. data/src/include/util/hb_arena_debug.h +8 -0
  71. data/src/include/util/hb_array.h +33 -0
  72. data/src/include/util/hb_buffer.h +34 -0
  73. data/src/include/util/hb_string.h +29 -0
  74. data/src/include/util/hb_system.h +9 -0
  75. data/src/include/util.h +3 -14
  76. data/src/include/version.h +1 -1
  77. data/src/include/visitor.h +1 -1
  78. data/src/io.c +7 -4
  79. data/src/lexer.c +61 -88
  80. data/src/lexer_peek_helpers.c +35 -37
  81. data/src/main.c +19 -23
  82. data/src/parser.c +282 -201
  83. data/src/parser_helpers.c +46 -40
  84. data/src/parser_match_tags.c +316 -0
  85. data/src/pretty_print.c +82 -106
  86. data/src/token.c +18 -65
  87. data/src/utf8.c +4 -4
  88. data/src/util/hb_arena.c +179 -0
  89. data/src/util/hb_arena_debug.c +237 -0
  90. data/src/{array.c → util/hb_array.c} +26 -27
  91. data/src/util/hb_buffer.c +203 -0
  92. data/src/util/hb_string.c +85 -0
  93. data/src/util/hb_system.c +30 -0
  94. data/src/util.c +29 -99
  95. data/src/visitor.c +54 -54
  96. data/templates/ext/herb/error_helpers.c.erb +3 -3
  97. data/templates/ext/herb/error_helpers.h.erb +1 -1
  98. data/templates/ext/herb/nodes.c.erb +11 -6
  99. data/templates/java/error_helpers.c.erb +75 -0
  100. data/templates/java/error_helpers.h.erb +20 -0
  101. data/templates/java/nodes.c.erb +97 -0
  102. data/templates/java/nodes.h.erb +23 -0
  103. data/templates/java/org/herb/ast/Errors.java.erb +121 -0
  104. data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
  105. data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
  106. data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
  107. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
  108. data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
  109. data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
  110. data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
  111. data/templates/lib/herb/ast/nodes.rb.erb +28 -16
  112. data/templates/lib/herb/errors.rb.erb +17 -12
  113. data/templates/rust/src/ast/nodes.rs.erb +220 -0
  114. data/templates/rust/src/errors.rs.erb +216 -0
  115. data/templates/rust/src/nodes.rs.erb +374 -0
  116. data/templates/src/analyze_missing_end.c.erb +36 -0
  117. data/templates/src/analyze_transform.c.erb +24 -0
  118. data/templates/src/ast_nodes.c.erb +14 -14
  119. data/templates/src/ast_pretty_print.c.erb +36 -36
  120. data/templates/src/errors.c.erb +31 -31
  121. data/templates/src/include/ast_nodes.h.erb +10 -9
  122. data/templates/src/include/ast_pretty_print.h.erb +2 -2
  123. data/templates/src/include/errors.h.erb +6 -6
  124. data/templates/src/parser_match_tags.c.erb +38 -0
  125. data/templates/src/visitor.c.erb +4 -4
  126. data/templates/template.rb +22 -3
  127. data/templates/wasm/error_helpers.cpp.erb +9 -9
  128. data/templates/wasm/error_helpers.h.erb +1 -1
  129. data/templates/wasm/nodes.cpp.erb +9 -9
  130. data/templates/wasm/nodes.h.erb +1 -1
  131. data/vendor/prism/Rakefile +4 -1
  132. data/vendor/prism/config.yml +2 -1
  133. data/vendor/prism/include/prism/ast.h +31 -1
  134. data/vendor/prism/include/prism/diagnostic.h +1 -0
  135. data/vendor/prism/include/prism/version.h +3 -3
  136. data/vendor/prism/src/diagnostic.c +3 -1
  137. data/vendor/prism/src/prism.c +130 -71
  138. data/vendor/prism/src/util/pm_string.c +6 -8
  139. data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
  140. data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
  141. data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
  142. data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
  143. data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
  144. data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
  145. metadata +34 -20
  146. data/lib/herb/libherb/array.rb +0 -51
  147. data/lib/herb/libherb/ast_node.rb +0 -50
  148. data/lib/herb/libherb/buffer.rb +0 -56
  149. data/lib/herb/libherb/extract_result.rb +0 -20
  150. data/lib/herb/libherb/lex_result.rb +0 -32
  151. data/lib/herb/libherb/libherb.rb +0 -52
  152. data/lib/herb/libherb/parse_result.rb +0 -20
  153. data/lib/herb/libherb/token.rb +0 -46
  154. data/lib/herb/libherb.rb +0 -35
  155. data/src/buffer.c +0 -241
  156. data/src/include/array.h +0 -33
  157. data/src/include/buffer.h +0 -39
  158. data/src/include/json.h +0 -28
  159. data/src/include/memory.h +0 -12
  160. data/src/json.c +0 -205
  161. data/src/memory.c +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daf68784d091fda194c7db0d5cd239a9b0fe02a8375b9eb0af68a4ede2958ff2
4
- data.tar.gz: 3468efc6fa083ef6f5b95846fc3710e33859bd867abe4db17fd18fdc943f4663
3
+ metadata.gz: 3b4c8e95b6e307626e3863ff7b7d0a94c3ffc9014ae8d57e63f8666b8d0fb456
4
+ data.tar.gz: bd08a1c804305f3100569afffbc0d03f76da1da3d47473fd317941ba9f1af856
5
5
  SHA512:
6
- metadata.gz: b2a6624e247903c6da818d8631baecbca87a29d515e711e6fa42f9827a02edccc663293b19b4172cc53452fac292cc427deab018b640bc0be5576b1428ac5697
7
- data.tar.gz: 3a8f2599c5cd88607b8d6016b45a3ccd9be1e6bb9912571b3b5768068494b6a63b5e746b158076a96c2d5f8d1daf0b2df2930e405f06f65cf66a87dfd794d8f9
6
+ metadata.gz: 6ae8c7ee7d1dfa14d6f171e0b48895aa1d4dc67c40fbac49c60683086ffdf77bc6958066552977f768a0389a5be82c93120a407bcc3e6aa5edeba73f5143a49f
7
+ data.tar.gz: c3f290cef78c668e4141e788d726fb5d2d6d8b7953effd999d589193d2e07ca81657f94507bcfd39daeff48c54471cf726753d407fb6cc8f61d36895178c93e8
data/Makefile CHANGED
@@ -61,22 +61,22 @@ shared_flags = $(production_flags) $(shared_library_flags) $(prism_flags)
61
61
  ifeq ($(os),Linux)
62
62
  test_cflags = $(test_flags) -I/usr/include/check
63
63
  test_ldflags = -L/usr/lib/x86_64-linux-gnu -lcheck -lm -lsubunit $(prism_ldflags)
64
- cc = clang-19
65
- clang_format = clang-format-19
66
- clang_tidy = clang-tidy-19
64
+ cc = clang-21
65
+ clang_format = clang-format-21
66
+ clang_tidy = clang-tidy-21
67
67
  endif
68
68
 
69
69
  ifeq ($(os),Darwin)
70
70
  brew_prefix := $(shell brew --prefix check)
71
71
  test_cflags = $(test_flags) -I$(brew_prefix)/include
72
72
  test_ldflags = -L$(brew_prefix)/lib -lcheck -lm $(prism_ldflags)
73
- llvm_path = $(shell brew --prefix llvm@19)
73
+ llvm_path = $(shell brew --prefix llvm@21)
74
74
  cc = $(llvm_path)/bin/clang
75
75
  clang_format = $(llvm_path)/bin/clang-format
76
76
  clang_tidy = $(llvm_path)/bin/clang-tidy
77
77
  endif
78
78
 
79
- all: templates prism $(exec) $(lib_name) $(static_lib_name) test wasm
79
+ all: templates prism $(exec) $(lib_name) $(static_lib_name) test wasm clangd_config
80
80
 
81
81
  $(exec): $(objects)
82
82
  $(cc) $(objects) $(flags) $(ldflags) $(prism_ldflags) -o $(exec)
@@ -122,5 +122,8 @@ lint:
122
122
  tidy:
123
123
  $(clang_tidy) $(project_files) -- $(flags)
124
124
 
125
+ clangd_config:
126
+ @echo "$(flags) $(test_cflags)" | tr ' ' '\n' | sort -u > compile_flags.txt
127
+
125
128
  wasm:
126
129
  cd wasm && make
data/config.yml CHANGED
@@ -30,7 +30,7 @@ errors:
30
30
 
31
31
  - name: UnexpectedTokenError
32
32
  message:
33
- template: "Found `%s` when expecting `%s` at (%zu:%zu)."
33
+ template: "Found `%s` when expecting `%s` at (%u:%u)."
34
34
  arguments:
35
35
  - token_type_to_string(found->type)
36
36
  - token_type_to_string(expected_type)
@@ -46,7 +46,7 @@ errors:
46
46
 
47
47
  - name: MissingOpeningTagError
48
48
  message:
49
- template: "Found closing tag `</%s>` at (%zu:%zu) without a matching opening tag."
49
+ template: "Found closing tag `</%s>` at (%u:%u) without a matching opening tag in the same scope."
50
50
  arguments:
51
51
  - closing_tag->value
52
52
  - closing_tag->location.start.line
@@ -58,7 +58,7 @@ errors:
58
58
 
59
59
  - name: MissingClosingTagError
60
60
  message:
61
- template: "Opening tag `<%s>` at (%zu:%zu) doesn't have a matching closing tag `</%s>`."
61
+ template: "Opening tag `<%s>` at (%u:%u) doesn't have a matching closing tag `</%s>` in the same scope."
62
62
  arguments:
63
63
  - opening_tag->value
64
64
  - opening_tag->location.start.line
@@ -71,7 +71,7 @@ errors:
71
71
 
72
72
  - name: TagNamesMismatchError
73
73
  message:
74
- template: "Opening tag `<%s>` at (%zu:%zu) closed with `</%s>` at (%zu:%zu)."
74
+ template: "Opening tag `<%s>` at (%u:%u) closed with `</%s>` at (%u:%u)."
75
75
  arguments:
76
76
  - opening_tag->value
77
77
  - opening_tag->location.start.line
@@ -89,7 +89,7 @@ errors:
89
89
 
90
90
  - name: QuotesMismatchError
91
91
  message:
92
- template: "String opened with %s but closed with %s at (%zu:%zu)."
92
+ template: "String opened with %s but closed with %s at (%u:%u)."
93
93
  arguments:
94
94
  - opening_quote->value
95
95
  - closing_quote->value
@@ -124,7 +124,7 @@ errors:
124
124
 
125
125
  - name: UnclosedElementError
126
126
  message:
127
- template: "Tag `<%s>` opened at (%zu:%zu) was never closed before the end of document."
127
+ template: "Tag `<%s>` opened at (%u:%u) was never closed before the end of document."
128
128
  arguments:
129
129
  - opening_tag->value
130
130
  - opening_tag->location.start.line
@@ -151,6 +151,26 @@ errors:
151
151
  - name: level
152
152
  type: string
153
153
 
154
+ - name: ERBControlFlowScopeError
155
+ message:
156
+ template: "%s appears outside its control flow block. Keep ERB control flow statements together within the same HTML scope (tag, attribute, or content)."
157
+ arguments:
158
+ - keyword
159
+
160
+ fields:
161
+ - name: keyword
162
+ type: string
163
+
164
+ - name: MissingERBEndTagError
165
+ message:
166
+ template: "%s started here but never closed with an end tag. The end tag may be in a different scope."
167
+ arguments:
168
+ - keyword
169
+
170
+ fields:
171
+ - name: keyword
172
+ type: string
173
+
154
174
  warnings:
155
175
  fields: []
156
176
  types: []
@@ -265,6 +265,58 @@ static VALUE rb_ruby_parse_error_from_c_struct(RUBY_PARSE_ERROR_T* ruby_parse_er
265
265
  return rb_class_new_instance(6, args, RubyParseError);
266
266
  };
267
267
 
268
+ static VALUE rb_erb_control_flow_scope_error_from_c_struct(ERB_CONTROL_FLOW_SCOPE_ERROR_T* erb_control_flow_scope_error) {
269
+ if (erb_control_flow_scope_error == NULL) { return Qnil; }
270
+
271
+ ERROR_T* error = &erb_control_flow_scope_error->base;
272
+
273
+ VALUE Herb = rb_define_module("Herb");
274
+ VALUE Errors = rb_define_module_under(Herb, "Errors");
275
+ VALUE Error = rb_define_class_under(Errors, "Error", rb_cObject);
276
+ VALUE ERBControlFlowScopeError = rb_define_class_under(Errors, "ERBControlFlowScopeError", Error);
277
+
278
+ VALUE type = rb_utf8_str_new_cstr(error_type_to_string(error));
279
+ VALUE location = rb_location_from_c_struct(error->location);
280
+ VALUE message = rb_utf8_str_new_cstr(error->message);
281
+
282
+ VALUE erb_control_flow_scope_error_keyword = rb_utf8_str_new_cstr(erb_control_flow_scope_error->keyword);
283
+
284
+ VALUE args[4] = {
285
+ type,
286
+ location,
287
+ message,
288
+ erb_control_flow_scope_error_keyword
289
+ };
290
+
291
+ return rb_class_new_instance(4, args, ERBControlFlowScopeError);
292
+ };
293
+
294
+ static VALUE rb_missingerb_end_tag_error_from_c_struct(MISSINGERB_END_TAG_ERROR_T* missingerb_end_tag_error) {
295
+ if (missingerb_end_tag_error == NULL) { return Qnil; }
296
+
297
+ ERROR_T* error = &missingerb_end_tag_error->base;
298
+
299
+ VALUE Herb = rb_define_module("Herb");
300
+ VALUE Errors = rb_define_module_under(Herb, "Errors");
301
+ VALUE Error = rb_define_class_under(Errors, "Error", rb_cObject);
302
+ VALUE MissingERBEndTagError = rb_define_class_under(Errors, "MissingERBEndTagError", Error);
303
+
304
+ VALUE type = rb_utf8_str_new_cstr(error_type_to_string(error));
305
+ VALUE location = rb_location_from_c_struct(error->location);
306
+ VALUE message = rb_utf8_str_new_cstr(error->message);
307
+
308
+ VALUE missingerb_end_tag_error_keyword = rb_utf8_str_new_cstr(missingerb_end_tag_error->keyword);
309
+
310
+ VALUE args[4] = {
311
+ type,
312
+ location,
313
+ message,
314
+ missingerb_end_tag_error_keyword
315
+ };
316
+
317
+ return rb_class_new_instance(4, args, MissingERBEndTagError);
318
+ };
319
+
268
320
 
269
321
  VALUE rb_error_from_c_struct(ERROR_T* error) {
270
322
  if (!error) { return Qnil; }
@@ -279,17 +331,19 @@ VALUE rb_error_from_c_struct(ERROR_T* error) {
279
331
  case VOID_ELEMENT_CLOSING_TAG_ERROR: return rb_void_element_closing_tag_error_from_c_struct((VOID_ELEMENT_CLOSING_TAG_ERROR_T*) error); break;
280
332
  case UNCLOSED_ELEMENT_ERROR: return rb_unclosed_element_error_from_c_struct((UNCLOSED_ELEMENT_ERROR_T*) error); break;
281
333
  case RUBY_PARSE_ERROR: return rb_ruby_parse_error_from_c_struct((RUBY_PARSE_ERROR_T*) error); break;
334
+ case ERB_CONTROL_FLOW_SCOPE_ERROR: return rb_erb_control_flow_scope_error_from_c_struct((ERB_CONTROL_FLOW_SCOPE_ERROR_T*) error); break;
335
+ case MISSINGERB_END_TAG_ERROR: return rb_missingerb_end_tag_error_from_c_struct((MISSINGERB_END_TAG_ERROR_T*) error); break;
282
336
  }
283
337
 
284
338
  return Qnil;
285
339
  }
286
340
 
287
- VALUE rb_errors_array_from_c_array(array_T* array) {
341
+ VALUE rb_errors_array_from_c_array(hb_array_T* array) {
288
342
  VALUE rb_array = rb_ary_new();
289
343
 
290
344
  if (array) {
291
- for (size_t i = 0; i < array_size(array); i++) {
292
- ERROR_T* child_node = (ERROR_T*) array_get(array, i);
345
+ for (size_t i = 0; i < hb_array_size(array); i++) {
346
+ ERROR_T* child_node = (ERROR_T*) hb_array_get(array, i);
293
347
 
294
348
  if (child_node) {
295
349
  VALUE rb_child = rb_error_from_c_struct(child_node);
@@ -10,6 +10,6 @@
10
10
  #include <ruby.h>
11
11
 
12
12
  VALUE rb_error_from_c_struct(ERROR_T* error);
13
- VALUE rb_errors_array_from_c_array(array_T* array);
13
+ VALUE rb_errors_array_from_c_array(hb_array_T* array);
14
14
 
15
15
  #endif
data/ext/herb/extconf.rb CHANGED
@@ -15,6 +15,7 @@ prism_src_path = "#{prism_path}/src"
15
15
  prism_include_path = "#{prism_path}/include"
16
16
 
17
17
  $VPATH << "$(srcdir)/../../src"
18
+ $VPATH << "$(srcdir)/../../src/util"
18
19
  $VPATH << prism_src_path
19
20
  $VPATH << "#{prism_src_path}/util"
20
21
 
data/ext/herb/extension.c CHANGED
@@ -19,7 +19,7 @@ VALUE cParseResult;
19
19
  static VALUE Herb_lex(VALUE self, VALUE source) {
20
20
  char* string = (char*) check_string(source);
21
21
 
22
- array_T* tokens = herb_lex(string);
22
+ hb_array_T* tokens = herb_lex(string);
23
23
 
24
24
  VALUE result = create_lex_result(tokens, source);
25
25
 
@@ -30,7 +30,7 @@ static VALUE Herb_lex(VALUE self, VALUE source) {
30
30
 
31
31
  static VALUE Herb_lex_file(VALUE self, VALUE path) {
32
32
  char* file_path = (char*) check_string(path);
33
- array_T* tokens = herb_lex_file(file_path);
33
+ hb_array_T* tokens = herb_lex_file(file_path);
34
34
 
35
35
  VALUE source_value = read_file_to_ruby_string(file_path);
36
36
  VALUE result = create_lex_result(tokens, source_value);
@@ -78,6 +78,8 @@ static VALUE Herb_parse_file(VALUE self, VALUE path) {
78
78
 
79
79
  AST_DOCUMENT_NODE_T* root = herb_parse(string, NULL);
80
80
 
81
+ herb_analyze_parse_tree(root, string);
82
+
81
83
  VALUE result = create_parse_result(root, source_value);
82
84
 
83
85
  ast_node_free((AST_NODE_T*) root);
@@ -85,45 +87,30 @@ static VALUE Herb_parse_file(VALUE self, VALUE path) {
85
87
  return result;
86
88
  }
87
89
 
88
- static VALUE Herb_lex_to_json(VALUE self, VALUE source) {
89
- char* string = (char*) check_string(source);
90
- buffer_T output;
91
-
92
- if (!buffer_init(&output)) { return Qnil; }
93
-
94
- herb_lex_json_to_buffer(string, &output);
95
-
96
- VALUE result = rb_str_new(output.value, output.length);
97
-
98
- buffer_free(&output);
99
-
100
- return result;
101
- }
102
-
103
90
  static VALUE Herb_extract_ruby(VALUE self, VALUE source) {
104
91
  char* string = (char*) check_string(source);
105
- buffer_T output;
92
+ hb_buffer_T output;
106
93
 
107
- if (!buffer_init(&output)) { return Qnil; }
94
+ if (!hb_buffer_init(&output, strlen(string))) { return Qnil; }
108
95
 
109
96
  herb_extract_ruby_to_buffer(string, &output);
110
97
 
111
98
  VALUE result = rb_utf8_str_new_cstr(output.value);
112
- buffer_free(&output);
99
+ free(output.value);
113
100
 
114
101
  return result;
115
102
  }
116
103
 
117
104
  static VALUE Herb_extract_html(VALUE self, VALUE source) {
118
105
  char* string = (char*) check_string(source);
119
- buffer_T output;
106
+ hb_buffer_T output;
120
107
 
121
- if (!buffer_init(&output)) { return Qnil; }
108
+ if (!hb_buffer_init(&output, strlen(string))) { return Qnil; }
122
109
 
123
110
  herb_extract_html_to_buffer(string, &output);
124
111
 
125
112
  VALUE result = rb_utf8_str_new_cstr(output.value);
126
- buffer_free(&output);
113
+ free(output.value);
127
114
 
128
115
  return result;
129
116
  }
@@ -151,7 +138,6 @@ void Init_herb(void) {
151
138
  rb_define_singleton_method(mHerb, "lex", Herb_lex, 1);
152
139
  rb_define_singleton_method(mHerb, "parse_file", Herb_parse_file, 1);
153
140
  rb_define_singleton_method(mHerb, "lex_file", Herb_lex_file, 1);
154
- rb_define_singleton_method(mHerb, "lex_to_json", Herb_lex_to_json, 1);
155
141
  rb_define_singleton_method(mHerb, "extract_ruby", Herb_extract_ruby, 1);
156
142
  rb_define_singleton_method(mHerb, "extract_html", Herb_extract_html, 1);
157
143
  rb_define_singleton_method(mHerb, "version", Herb_version, 0);
@@ -58,13 +58,13 @@ VALUE rb_token_from_c_struct(token_T* token) {
58
58
  return rb_class_new_instance(4, args, cToken);
59
59
  }
60
60
 
61
- VALUE create_lex_result(array_T* tokens, VALUE source) {
61
+ VALUE create_lex_result(hb_array_T* tokens, VALUE source) {
62
62
  VALUE value = rb_ary_new();
63
63
  VALUE warnings = rb_ary_new();
64
64
  VALUE errors = rb_ary_new();
65
65
 
66
- for (size_t i = 0; i < array_size(tokens); i++) {
67
- token_T* token = array_get(tokens, i);
66
+ for (size_t i = 0; i < hb_array_size(tokens); i++) {
67
+ token_T* token = hb_array_get(tokens, i);
68
68
  if (token != NULL) { rb_ary_push(value, rb_token_from_c_struct(token)); }
69
69
  }
70
70
 
@@ -18,7 +18,7 @@ VALUE rb_location_from_c_struct(location_T location);
18
18
  VALUE rb_token_from_c_struct(token_T* token);
19
19
  VALUE rb_range_from_c_struct(range_T range);
20
20
 
21
- VALUE create_lex_result(array_T* tokens, VALUE source);
21
+ VALUE create_lex_result(hb_array_T* tokens, VALUE source);
22
22
  VALUE create_parse_result(AST_DOCUMENT_NODE_T* root, VALUE source);
23
23
 
24
24
  #endif