herb 0.7.4-aarch64-linux-gnu → 0.8.0-aarch64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +8 -5
  3. data/config.yml +40 -20
  4. data/ext/herb/error_helpers.c +57 -3
  5. data/ext/herb/error_helpers.h +1 -1
  6. data/ext/herb/extconf.rb +1 -0
  7. data/ext/herb/extension.c +10 -24
  8. data/ext/herb/extension_helpers.c +12 -18
  9. data/ext/herb/extension_helpers.h +4 -4
  10. data/ext/herb/nodes.c +72 -37
  11. data/herb.gemspec +0 -2
  12. data/lib/herb/3.0/herb.so +0 -0
  13. data/lib/herb/3.1/herb.so +0 -0
  14. data/lib/herb/3.2/herb.so +0 -0
  15. data/lib/herb/3.3/herb.so +0 -0
  16. data/lib/herb/3.4/herb.so +0 -0
  17. data/lib/herb/ast/helpers.rb +11 -0
  18. data/lib/herb/ast/node.rb +15 -6
  19. data/lib/herb/ast/nodes.rb +609 -392
  20. data/lib/herb/cli.rb +31 -0
  21. data/lib/herb/colors.rb +82 -0
  22. data/lib/herb/engine/compiler.rb +140 -14
  23. data/lib/herb/engine/debug_visitor.rb +1 -5
  24. data/lib/herb/engine/parser_error_overlay.rb +1 -1
  25. data/lib/herb/engine.rb +18 -20
  26. data/lib/herb/errors.rb +166 -56
  27. data/lib/herb/location.rb +2 -2
  28. data/lib/herb/project.rb +86 -21
  29. data/lib/herb/token.rb +14 -2
  30. data/lib/herb/version.rb +1 -1
  31. data/lib/herb.rb +1 -0
  32. data/sig/herb/ast/helpers.rbs +3 -0
  33. data/sig/herb/ast/node.rbs +12 -5
  34. data/sig/herb/ast/nodes.rbs +124 -62
  35. data/sig/herb/colors.rbs +35 -0
  36. data/sig/herb/engine/compiler.rbs +23 -1
  37. data/sig/herb/errors.rbs +74 -20
  38. data/sig/herb/token.rbs +8 -0
  39. data/sig/herb_c_extension.rbs +1 -1
  40. data/sig/serialized_ast_errors.rbs +8 -0
  41. data/src/analyze.c +461 -249
  42. data/src/analyze_helpers.c +5 -0
  43. data/src/analyze_missing_end.c +147 -0
  44. data/src/analyze_transform.c +196 -0
  45. data/src/analyzed_ruby.c +23 -2
  46. data/src/ast_node.c +14 -17
  47. data/src/ast_nodes.c +179 -181
  48. data/src/ast_pretty_print.c +232 -232
  49. data/src/element_source.c +7 -6
  50. data/src/errors.c +272 -152
  51. data/src/extract.c +92 -34
  52. data/src/herb.c +37 -49
  53. data/src/html_util.c +34 -96
  54. data/src/include/analyze.h +10 -2
  55. data/src/include/analyze_helpers.h +3 -0
  56. data/src/include/analyzed_ruby.h +4 -2
  57. data/src/include/ast_node.h +4 -4
  58. data/src/include/ast_nodes.h +68 -67
  59. data/src/include/ast_pretty_print.h +2 -2
  60. data/src/include/element_source.h +3 -1
  61. data/src/include/errors.h +42 -26
  62. data/src/include/extract.h +4 -4
  63. data/src/include/herb.h +6 -7
  64. data/src/include/html_util.h +4 -5
  65. data/src/include/lexer.h +1 -3
  66. data/src/include/lexer_peek_helpers.h +21 -19
  67. data/src/include/lexer_struct.h +12 -10
  68. data/src/include/location.h +10 -13
  69. data/src/include/macros.h +4 -0
  70. data/src/include/parser.h +12 -6
  71. data/src/include/parser_helpers.h +26 -16
  72. data/src/include/position.h +3 -14
  73. data/src/include/pretty_print.h +38 -28
  74. data/src/include/prism_helpers.h +1 -1
  75. data/src/include/range.h +4 -13
  76. data/src/include/token.h +5 -11
  77. data/src/include/token_struct.h +2 -2
  78. data/src/include/utf8.h +3 -2
  79. data/src/include/util/hb_arena.h +31 -0
  80. data/src/include/util/hb_arena_debug.h +8 -0
  81. data/src/include/util/hb_array.h +33 -0
  82. data/src/include/util/hb_buffer.h +34 -0
  83. data/src/include/util/hb_string.h +29 -0
  84. data/src/include/util/hb_system.h +9 -0
  85. data/src/include/util.h +3 -14
  86. data/src/include/version.h +1 -1
  87. data/src/include/visitor.h +1 -1
  88. data/src/io.c +7 -4
  89. data/src/lexer.c +62 -88
  90. data/src/lexer_peek_helpers.c +42 -38
  91. data/src/location.c +9 -37
  92. data/src/main.c +19 -23
  93. data/src/parser.c +373 -313
  94. data/src/parser_helpers.c +60 -54
  95. data/src/parser_match_tags.c +316 -0
  96. data/src/pretty_print.c +88 -117
  97. data/src/prism_helpers.c +7 -7
  98. data/src/range.c +2 -35
  99. data/src/token.c +36 -87
  100. data/src/utf8.c +4 -4
  101. data/src/util/hb_arena.c +179 -0
  102. data/src/util/hb_arena_debug.c +237 -0
  103. data/src/{array.c → util/hb_array.c} +26 -27
  104. data/src/util/hb_buffer.c +203 -0
  105. data/src/util/hb_string.c +85 -0
  106. data/src/util/hb_system.c +30 -0
  107. data/src/util.c +29 -99
  108. data/src/visitor.c +54 -54
  109. data/templates/ext/herb/error_helpers.c.erb +3 -3
  110. data/templates/ext/herb/error_helpers.h.erb +1 -1
  111. data/templates/ext/herb/nodes.c.erb +11 -6
  112. data/templates/java/error_helpers.c.erb +75 -0
  113. data/templates/java/error_helpers.h.erb +20 -0
  114. data/templates/java/nodes.c.erb +97 -0
  115. data/templates/java/nodes.h.erb +23 -0
  116. data/templates/java/org/herb/ast/Errors.java.erb +121 -0
  117. data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
  118. data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
  119. data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
  120. data/templates/javascript/packages/core/src/visitor.ts.erb +29 -1
  121. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
  122. data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
  123. data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
  124. data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
  125. data/templates/lib/herb/ast/nodes.rb.erb +28 -16
  126. data/templates/lib/herb/errors.rb.erb +17 -12
  127. data/templates/rust/src/ast/nodes.rs.erb +220 -0
  128. data/templates/rust/src/errors.rs.erb +216 -0
  129. data/templates/rust/src/nodes.rs.erb +374 -0
  130. data/templates/src/analyze_missing_end.c.erb +36 -0
  131. data/templates/src/analyze_transform.c.erb +24 -0
  132. data/templates/src/ast_nodes.c.erb +14 -16
  133. data/templates/src/ast_pretty_print.c.erb +36 -36
  134. data/templates/src/errors.c.erb +36 -38
  135. data/templates/src/include/ast_nodes.h.erb +11 -10
  136. data/templates/src/include/ast_pretty_print.h.erb +2 -2
  137. data/templates/src/include/errors.h.erb +9 -9
  138. data/templates/src/parser_match_tags.c.erb +38 -0
  139. data/templates/src/visitor.c.erb +4 -4
  140. data/templates/template.rb +22 -3
  141. data/templates/wasm/error_helpers.cpp.erb +9 -9
  142. data/templates/wasm/error_helpers.h.erb +1 -1
  143. data/templates/wasm/nodes.cpp.erb +9 -9
  144. data/templates/wasm/nodes.h.erb +1 -1
  145. data/vendor/prism/Rakefile +4 -1
  146. data/vendor/prism/config.yml +2 -1
  147. data/vendor/prism/include/prism/ast.h +31 -1
  148. data/vendor/prism/include/prism/diagnostic.h +1 -0
  149. data/vendor/prism/include/prism/version.h +3 -3
  150. data/vendor/prism/src/diagnostic.c +3 -1
  151. data/vendor/prism/src/prism.c +130 -71
  152. data/vendor/prism/src/util/pm_string.c +6 -8
  153. data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
  154. data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
  155. data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
  156. data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
  157. data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
  158. data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
  159. metadata +34 -21
  160. data/lib/herb/libherb/array.rb +0 -51
  161. data/lib/herb/libherb/ast_node.rb +0 -50
  162. data/lib/herb/libherb/buffer.rb +0 -56
  163. data/lib/herb/libherb/extract_result.rb +0 -20
  164. data/lib/herb/libherb/lex_result.rb +0 -32
  165. data/lib/herb/libherb/libherb.rb +0 -52
  166. data/lib/herb/libherb/parse_result.rb +0 -20
  167. data/lib/herb/libherb/token.rb +0 -46
  168. data/lib/herb/libherb.rb +0 -35
  169. data/src/buffer.c +0 -232
  170. data/src/include/array.h +0 -33
  171. data/src/include/buffer.h +0 -39
  172. data/src/include/json.h +0 -28
  173. data/src/include/memory.h +0 -12
  174. data/src/json.c +0 -205
  175. data/src/memory.c +0 -53
  176. data/src/position.c +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdac1e74fbf67c9fd2fbdfdeb2d379ae1093f0e1858860b66629a1f44ccefe57
4
- data.tar.gz: 6f514eee95be38a3e360a63c8ea199986ebc289f92a9817aa982129501aaa349
3
+ metadata.gz: 0b363f5d92afe92881c17ec763dc7bfc28ee6a8aac39e79ca7d101c3d1000f1c
4
+ data.tar.gz: ef2ec88c8c8adb3f28849ce10b59fdb4b312e2c413227a293696033a179620f5
5
5
  SHA512:
6
- metadata.gz: ca0fcdbeb1e4d903f935cf496a748612e9a6253c4381d77d716152d3fecf7778efb77b7e0a873e932dcbbf379fb7cc5bb3e11109d219ac06da67cda2265c19c1
7
- data.tar.gz: '097141c4f92f95478b55ca5b928b84b88073d50c9a601d25d903062d92fe7f84601ea0d72ff2c2ec02134a267d9c37a51710b305d08223040f75e9c4486215a4'
6
+ metadata.gz: 11ea667b4b365ba99fdcabf1250e82132bb7dcebe5c4daa5a68ad4b6cb129dc79fa4ee0c3f69b6312acaaa08b5d589b0d37542d1cfa10ae8bec48a5c5cc5e8d4
7
+ data.tar.gz: ffdf788c56319b72f96a096f85d64c0599bb3b97cca978daae00c9c4a8954044a46b237cdce1658ace4ca8b6c346daa4d52e224da0bcf8a265871ac241a1298e
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,12 +30,12 @@ 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)
37
- - found->location->start->line
38
- - found->location->start->column
37
+ - found->location.start.line
38
+ - found->location.start.column
39
39
 
40
40
  fields:
41
41
  - name: expected_type
@@ -46,11 +46,11 @@ 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
- - closing_tag->location->start->line
53
- - closing_tag->location->start->column
52
+ - closing_tag->location.start.line
53
+ - closing_tag->location.start.column
54
54
 
55
55
  fields:
56
56
  - name: closing_tag
@@ -58,11 +58,11 @@ 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
- - opening_tag->location->start->line
65
- - opening_tag->location->start->column
64
+ - opening_tag->location.start.line
65
+ - opening_tag->location.start.column
66
66
  - opening_tag->value
67
67
 
68
68
  fields:
@@ -71,14 +71,14 @@ 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
- - opening_tag->location->start->line
78
- - opening_tag->location->start->column
77
+ - opening_tag->location.start.line
78
+ - opening_tag->location.start.column
79
79
  - closing_tag->value
80
- - closing_tag->location->start->line
81
- - closing_tag->location->start->column
80
+ - closing_tag->location.start.line
81
+ - closing_tag->location.start.column
82
82
 
83
83
  fields:
84
84
  - name: opening_tag
@@ -89,12 +89,12 @@ 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
96
- - closing_quote->location->start->line
97
- - closing_quote->location->start->column
96
+ - closing_quote->location.start.line
97
+ - closing_quote->location.start.column
98
98
 
99
99
  fields:
100
100
  - name: opening_quote
@@ -124,11 +124,11 @@ 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
- - opening_tag->location->start->line
131
- - opening_tag->location->start->column
130
+ - opening_tag->location.start.line
131
+ - opening_tag->location.start.column
132
132
 
133
133
  fields:
134
134
  - name: opening_tag
@@ -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);
@@ -20,32 +20,26 @@ const char* check_string(VALUE value) {
20
20
  return RSTRING_PTR(value);
21
21
  }
22
22
 
23
- VALUE rb_position_from_c_struct(position_T* position) {
24
- if (!position) { return Qnil; }
25
-
23
+ VALUE rb_position_from_c_struct(position_T position) {
26
24
  VALUE args[2];
27
- args[0] = SIZET2NUM(position->line);
28
- args[1] = SIZET2NUM(position->column);
25
+ args[0] = UINT2NUM(position.line);
26
+ args[1] = UINT2NUM(position.column);
29
27
 
30
28
  return rb_class_new_instance(2, args, cPosition);
31
29
  }
32
30
 
33
- VALUE rb_location_from_c_struct(location_T* location) {
34
- if (!location) { return Qnil; }
35
-
31
+ VALUE rb_location_from_c_struct(location_T location) {
36
32
  VALUE args[2];
37
- args[0] = rb_position_from_c_struct(location->start);
38
- args[1] = rb_position_from_c_struct(location->end);
33
+ args[0] = rb_position_from_c_struct(location.start);
34
+ args[1] = rb_position_from_c_struct(location.end);
39
35
 
40
36
  return rb_class_new_instance(2, args, cLocation);
41
37
  }
42
38
 
43
- VALUE rb_range_from_c_struct(range_T* range) {
44
- if (!range) { return Qnil; }
45
-
39
+ VALUE rb_range_from_c_struct(range_T range) {
46
40
  VALUE args[2];
47
- args[0] = SIZET2NUM(range->from);
48
- args[1] = SIZET2NUM(range->to);
41
+ args[0] = UINT2NUM(range.from);
42
+ args[1] = UINT2NUM(range.to);
49
43
 
50
44
  return rb_class_new_instance(2, args, cRange);
51
45
  }
@@ -64,13 +58,13 @@ VALUE rb_token_from_c_struct(token_T* token) {
64
58
  return rb_class_new_instance(4, args, cToken);
65
59
  }
66
60
 
67
- VALUE create_lex_result(array_T* tokens, VALUE source) {
61
+ VALUE create_lex_result(hb_array_T* tokens, VALUE source) {
68
62
  VALUE value = rb_ary_new();
69
63
  VALUE warnings = rb_ary_new();
70
64
  VALUE errors = rb_ary_new();
71
65
 
72
- for (size_t i = 0; i < array_size(tokens); i++) {
73
- 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);
74
68
  if (token != NULL) { rb_ary_push(value, rb_token_from_c_struct(token)); }
75
69
  }
76
70
 
@@ -12,13 +12,13 @@
12
12
  const char* check_string(VALUE value);
13
13
  VALUE read_file_to_ruby_string(const char* file_path);
14
14
 
15
- VALUE rb_position_from_c_struct(position_T* position);
16
- VALUE rb_location_from_c_struct(location_T* location);
15
+ VALUE rb_position_from_c_struct(position_T position);
16
+ VALUE rb_location_from_c_struct(location_T location);
17
17
 
18
18
  VALUE rb_token_from_c_struct(token_T* token);
19
- VALUE rb_range_from_c_struct(range_T* range);
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