@herb-tools/node 0.7.4 → 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 (131) hide show
  1. package/binding.gyp +8 -5
  2. package/dist/herb-node.esm.js +6 -6
  3. package/dist/herb-node.esm.js.map +1 -1
  4. package/extension/error_helpers.cpp +67 -9
  5. package/extension/error_helpers.h +4 -2
  6. package/extension/extension_helpers.cpp +20 -31
  7. package/extension/extension_helpers.h +7 -5
  8. package/extension/herb.cpp +10 -42
  9. package/extension/libherb/analyze.c +461 -249
  10. package/extension/libherb/analyze.h +10 -2
  11. package/extension/libherb/analyze_helpers.c +5 -0
  12. package/extension/libherb/analyze_helpers.h +3 -0
  13. package/extension/libherb/analyze_missing_end.c +147 -0
  14. package/extension/libherb/analyze_transform.c +196 -0
  15. package/extension/libherb/analyzed_ruby.c +23 -2
  16. package/extension/libherb/analyzed_ruby.h +4 -2
  17. package/extension/libherb/ast_node.c +14 -17
  18. package/extension/libherb/ast_node.h +4 -4
  19. package/extension/libherb/ast_nodes.c +180 -182
  20. package/extension/libherb/ast_nodes.h +69 -68
  21. package/extension/libherb/ast_pretty_print.c +233 -233
  22. package/extension/libherb/ast_pretty_print.h +3 -3
  23. package/extension/libherb/element_source.c +7 -6
  24. package/extension/libherb/element_source.h +3 -1
  25. package/extension/libherb/errors.c +273 -153
  26. package/extension/libherb/errors.h +43 -27
  27. package/extension/libherb/extract.c +92 -34
  28. package/extension/libherb/extract.h +4 -4
  29. package/extension/libherb/herb.c +37 -49
  30. package/extension/libherb/herb.h +6 -7
  31. package/extension/libherb/html_util.c +34 -96
  32. package/extension/libherb/html_util.h +4 -5
  33. package/extension/libherb/include/analyze.h +10 -2
  34. package/extension/libherb/include/analyze_helpers.h +3 -0
  35. package/extension/libherb/include/analyzed_ruby.h +4 -2
  36. package/extension/libherb/include/ast_node.h +4 -4
  37. package/extension/libherb/include/ast_nodes.h +69 -68
  38. package/extension/libherb/include/ast_pretty_print.h +3 -3
  39. package/extension/libherb/include/element_source.h +3 -1
  40. package/extension/libherb/include/errors.h +43 -27
  41. package/extension/libherb/include/extract.h +4 -4
  42. package/extension/libherb/include/herb.h +6 -7
  43. package/extension/libherb/include/html_util.h +4 -5
  44. package/extension/libherb/include/lexer.h +1 -3
  45. package/extension/libherb/include/lexer_peek_helpers.h +21 -19
  46. package/extension/libherb/include/lexer_struct.h +12 -10
  47. package/extension/libherb/include/location.h +10 -13
  48. package/extension/libherb/include/macros.h +4 -0
  49. package/extension/libherb/include/parser.h +12 -6
  50. package/extension/libherb/include/parser_helpers.h +26 -16
  51. package/extension/libherb/include/position.h +3 -14
  52. package/extension/libherb/include/pretty_print.h +38 -28
  53. package/extension/libherb/include/prism_helpers.h +1 -1
  54. package/extension/libherb/include/range.h +4 -13
  55. package/extension/libherb/include/token.h +5 -11
  56. package/extension/libherb/include/token_struct.h +2 -2
  57. package/extension/libherb/include/utf8.h +3 -2
  58. package/extension/libherb/include/util/hb_arena.h +31 -0
  59. package/extension/libherb/include/util/hb_arena_debug.h +8 -0
  60. package/extension/libherb/include/util/hb_array.h +33 -0
  61. package/extension/libherb/include/util/hb_buffer.h +34 -0
  62. package/extension/libherb/include/util/hb_string.h +29 -0
  63. package/extension/libherb/include/util/hb_system.h +9 -0
  64. package/extension/libherb/include/util.h +3 -14
  65. package/extension/libherb/include/version.h +1 -1
  66. package/extension/libherb/include/visitor.h +1 -1
  67. package/extension/libherb/io.c +7 -4
  68. package/extension/libherb/lexer.c +62 -88
  69. package/extension/libherb/lexer.h +1 -3
  70. package/extension/libherb/lexer_peek_helpers.c +42 -38
  71. package/extension/libherb/lexer_peek_helpers.h +21 -19
  72. package/extension/libherb/lexer_struct.h +12 -10
  73. package/extension/libherb/location.c +9 -37
  74. package/extension/libherb/location.h +10 -13
  75. package/extension/libherb/macros.h +4 -0
  76. package/extension/libherb/main.c +19 -23
  77. package/extension/libherb/parser.c +373 -313
  78. package/extension/libherb/parser.h +12 -6
  79. package/extension/libherb/parser_helpers.c +60 -54
  80. package/extension/libherb/parser_helpers.h +26 -16
  81. package/extension/libherb/parser_match_tags.c +316 -0
  82. package/extension/libherb/position.h +3 -14
  83. package/extension/libherb/pretty_print.c +88 -117
  84. package/extension/libherb/pretty_print.h +38 -28
  85. package/extension/libherb/prism_helpers.c +7 -7
  86. package/extension/libherb/prism_helpers.h +1 -1
  87. package/extension/libherb/range.c +2 -35
  88. package/extension/libherb/range.h +4 -13
  89. package/extension/libherb/token.c +36 -87
  90. package/extension/libherb/token.h +5 -11
  91. package/extension/libherb/token_struct.h +2 -2
  92. package/extension/libherb/utf8.c +4 -4
  93. package/extension/libherb/utf8.h +3 -2
  94. package/extension/libherb/util/hb_arena.c +179 -0
  95. package/extension/libherb/util/hb_arena.h +31 -0
  96. package/extension/libherb/util/hb_arena_debug.c +237 -0
  97. package/extension/libherb/util/hb_arena_debug.h +8 -0
  98. package/extension/libherb/{array.c → util/hb_array.c} +26 -27
  99. package/extension/libherb/util/hb_array.h +33 -0
  100. package/extension/libherb/util/hb_buffer.c +203 -0
  101. package/extension/libherb/util/hb_buffer.h +34 -0
  102. package/extension/libherb/util/hb_string.c +85 -0
  103. package/extension/libherb/util/hb_string.h +29 -0
  104. package/extension/libherb/util/hb_system.c +30 -0
  105. package/extension/libherb/util/hb_system.h +9 -0
  106. package/extension/libherb/util.c +29 -99
  107. package/extension/libherb/util.h +3 -14
  108. package/extension/libherb/version.h +1 -1
  109. package/extension/libherb/visitor.c +55 -55
  110. package/extension/libherb/visitor.h +1 -1
  111. package/extension/nodes.cpp +40 -40
  112. package/extension/nodes.h +2 -2
  113. package/extension/prism/include/prism/ast.h +31 -1
  114. package/extension/prism/include/prism/diagnostic.h +1 -0
  115. package/extension/prism/include/prism/version.h +3 -3
  116. package/extension/prism/src/diagnostic.c +3 -1
  117. package/extension/prism/src/prism.c +130 -71
  118. package/extension/prism/src/util/pm_string.c +6 -8
  119. package/package.json +3 -3
  120. package/extension/libherb/array.h +0 -33
  121. package/extension/libherb/buffer.c +0 -232
  122. package/extension/libherb/buffer.h +0 -39
  123. package/extension/libherb/include/array.h +0 -33
  124. package/extension/libherb/include/buffer.h +0 -39
  125. package/extension/libherb/include/json.h +0 -28
  126. package/extension/libherb/include/memory.h +0 -12
  127. package/extension/libherb/json.c +0 -205
  128. package/extension/libherb/json.h +0 -28
  129. package/extension/libherb/memory.c +0 -53
  130. package/extension/libherb/memory.h +0 -12
  131. package/extension/libherb/position.c +0 -33
@@ -1,22 +1,11 @@
1
1
  #ifndef HERB_POSITION_H
2
2
  #define HERB_POSITION_H
3
3
 
4
- #include <stdlib.h>
4
+ #include <stdint.h>
5
5
 
6
6
  typedef struct POSITION_STRUCT {
7
- size_t line;
8
- size_t column;
7
+ uint32_t line;
8
+ uint32_t column;
9
9
  } position_T;
10
10
 
11
- position_T* position_init(size_t line, size_t column);
12
-
13
- size_t position_line(const position_T* position);
14
- size_t position_column(const position_T* position);
15
-
16
- size_t position_sizeof(void);
17
-
18
- position_T* position_copy(position_T* position);
19
-
20
- void position_free(position_T* position);
21
-
22
11
  #endif
@@ -3,146 +3,149 @@
3
3
  #include "include/ast_node.h"
4
4
  #include "include/ast_nodes.h"
5
5
  #include "include/ast_pretty_print.h"
6
- #include "include/buffer.h"
7
6
  #include "include/errors.h"
8
7
  #include "include/token_struct.h"
9
8
  #include "include/util.h"
9
+ #include "include/util/hb_buffer.h"
10
+ #include "include/util/hb_string.h"
10
11
 
11
12
  #include <stdbool.h>
12
13
  #include <stdio.h>
13
14
  #include <stdlib.h>
14
15
 
15
- void pretty_print_indent(buffer_T* buffer, const size_t indent) {
16
+ void pretty_print_indent(hb_buffer_T* buffer, const size_t indent) {
16
17
  for (size_t i = 0; i < indent; i++) {
17
- buffer_append(buffer, " ");
18
+ hb_buffer_append(buffer, " ");
18
19
  }
19
20
  }
20
21
 
21
- void pretty_print_newline(const size_t indent, const size_t relative_indent, buffer_T* buffer) {
22
+ void pretty_print_newline(const size_t indent, const size_t relative_indent, hb_buffer_T* buffer) {
22
23
  pretty_print_indent(buffer, indent);
23
24
  pretty_print_indent(buffer, relative_indent);
24
- buffer_append(buffer, "\n");
25
+ hb_buffer_append(buffer, "\n");
25
26
  }
26
27
 
27
28
  void pretty_print_label(
28
- const char* name,
29
+ hb_string_T name,
29
30
  const size_t indent,
30
31
  const size_t relative_indent,
31
32
  const bool last_property,
32
- buffer_T* buffer
33
+ hb_buffer_T* buffer
33
34
  ) {
34
35
  pretty_print_indent(buffer, indent);
35
36
  pretty_print_indent(buffer, relative_indent);
36
37
 
37
38
  if (last_property) {
38
- buffer_append(buffer, "└── ");
39
+ hb_buffer_append(buffer, "└── ");
39
40
  } else {
40
- buffer_append(buffer, "├── ");
41
+ hb_buffer_append(buffer, "├── ");
41
42
  }
42
43
 
43
- buffer_append(buffer, name);
44
- buffer_append(buffer, ": ");
44
+ hb_buffer_append_string(buffer, name);
45
+ hb_buffer_append(buffer, ": ");
45
46
  }
46
47
 
47
48
  void pretty_print_quoted_property(
48
- const char* name,
49
- const char* value,
49
+ hb_string_T name,
50
+ hb_string_T value,
50
51
  const size_t indent,
51
52
  const size_t relative_indent,
52
53
  const bool last_property,
53
- buffer_T* buffer
54
+ hb_buffer_T* buffer
54
55
  ) {
55
- char* quoted = quoted_string(value);
56
+ hb_string_T quoted = quoted_string(value);
56
57
  pretty_print_property(name, quoted, indent, relative_indent, last_property, buffer);
57
- free(quoted);
58
+ free(quoted.data);
58
59
  }
59
60
 
60
61
  void pretty_print_boolean_property(
61
- const char* name,
62
+ hb_string_T name,
62
63
  bool value,
63
64
  const size_t indent,
64
65
  const size_t relative_indent,
65
66
  const bool last_property,
66
- buffer_T* buffer
67
+ hb_buffer_T* buffer
67
68
  ) {
68
- pretty_print_property(name, value ? "true" : "false", indent, relative_indent, last_property, buffer);
69
+ pretty_print_property(name, hb_string(value ? "true" : "false"), indent, relative_indent, last_property, buffer);
69
70
  }
70
71
 
71
72
  void pretty_print_property(
72
- const char* name,
73
- const char* value,
73
+ hb_string_T name,
74
+ hb_string_T value,
74
75
  const size_t indent,
75
76
  const size_t relative_indent,
76
77
  const bool last_property,
77
- buffer_T* buffer
78
+ hb_buffer_T* buffer
78
79
  ) {
79
80
  pretty_print_label(name, indent, relative_indent, last_property, buffer);
80
- buffer_append(buffer, value);
81
- buffer_append(buffer, "\n");
81
+ hb_buffer_append_string(buffer, value);
82
+ hb_buffer_append(buffer, "\n");
82
83
  }
83
84
 
84
85
  void pretty_print_size_t_property(
85
86
  size_t value,
86
- const char* name,
87
+ hb_string_T name,
87
88
  const size_t indent,
88
89
  const size_t relative_indent,
89
90
  const bool last_property,
90
- buffer_T* buffer
91
+ hb_buffer_T* buffer
91
92
  ) {
92
93
  pretty_print_label(name, indent, relative_indent, last_property, buffer);
93
- char* string = size_t_to_string(value);
94
- buffer_append(buffer, string);
95
- buffer_append(buffer, "\n");
96
- free(string);
94
+
95
+ char size_string[21];
96
+ snprintf(size_string, 21, "%zu", value);
97
+
98
+ hb_buffer_append(buffer, size_string);
99
+ hb_buffer_append(buffer, "\n");
97
100
  }
98
101
 
99
102
  void pretty_print_array(
100
- const char* name,
101
- array_T* array,
103
+ hb_string_T name,
104
+ hb_array_T* array,
102
105
  const size_t indent,
103
106
  const size_t relative_indent,
104
107
  const bool last_property,
105
- buffer_T* buffer
108
+ hb_buffer_T* buffer
106
109
  ) {
107
110
  if (array == NULL) {
108
- pretty_print_property(name, "∅", indent, relative_indent, last_property, buffer);
111
+ pretty_print_property(name, hb_string("∅"), indent, relative_indent, last_property, buffer);
109
112
 
110
113
  return;
111
114
  }
112
115
 
113
- if (array_size(array) == 0) {
114
- pretty_print_property(name, "[]", indent, relative_indent, last_property, buffer);
116
+ if (hb_array_size(array) == 0) {
117
+ pretty_print_property(name, hb_string("[]"), indent, relative_indent, last_property, buffer);
115
118
 
116
119
  return;
117
120
  }
118
121
 
119
122
  pretty_print_label(name, indent, relative_indent, last_property, buffer);
120
123
 
121
- buffer_append(buffer, "(");
124
+ hb_buffer_append(buffer, "(");
122
125
 
123
126
  char count[16];
124
- sprintf(count, "%zu", array_size(array));
125
- buffer_append(buffer, count);
126
- buffer_append(buffer, ")\n");
127
+ sprintf(count, "%zu", hb_array_size(array));
128
+ hb_buffer_append(buffer, count);
129
+ hb_buffer_append(buffer, ")\n");
127
130
 
128
131
  if (indent < 20) {
129
- for (size_t i = 0; i < array_size(array); i++) {
130
- AST_NODE_T* child = array_get(array, i);
132
+ for (size_t i = 0; i < hb_array_size(array); i++) {
133
+ AST_NODE_T* child = hb_array_get(array, i);
131
134
  pretty_print_indent(buffer, indent);
132
135
  pretty_print_indent(buffer, relative_indent + 1);
133
136
 
134
- if (i == array_size(array) - 1) {
135
- buffer_append(buffer, "└── ");
137
+ if (i == hb_array_size(array) - 1) {
138
+ hb_buffer_append(buffer, "└── ");
136
139
  } else {
137
- buffer_append(buffer, "├── ");
140
+ hb_buffer_append(buffer, "├── ");
138
141
  }
139
142
 
140
143
  ast_pretty_print_node(child, indent + 1, relative_indent + 1, buffer);
141
144
 
142
- if (i != array_size(array) - 1) { pretty_print_newline(indent + 1, relative_indent, buffer); }
145
+ if (i != hb_array_size(array) - 1) { pretty_print_newline(indent + 1, relative_indent, buffer); }
143
146
  }
144
147
  }
145
- buffer_append(buffer, "\n");
148
+ hb_buffer_append(buffer, "\n");
146
149
  }
147
150
 
148
151
  void pretty_print_errors(
@@ -150,97 +153,92 @@ void pretty_print_errors(
150
153
  const size_t indent,
151
154
  const size_t relative_indent,
152
155
  const bool last_property,
153
- buffer_T* buffer
156
+ hb_buffer_T* buffer
154
157
  ) {
155
- if (node->errors != NULL && array_size(node->errors) > 0) {
158
+ if (node->errors != NULL && hb_array_size(node->errors) > 0) {
156
159
  error_pretty_print_array("errors", node->errors, indent, relative_indent, last_property, buffer);
157
- buffer_append(buffer, "\n");
160
+ hb_buffer_append(buffer, "\n");
158
161
  }
159
162
  }
160
163
 
161
- void pretty_print_location(location_T* location, buffer_T* buffer) {
162
- buffer_append(buffer, "(location: (");
164
+ void pretty_print_location(location_T location, hb_buffer_T* buffer) {
165
+ hb_buffer_append(buffer, "(location: (");
163
166
  char location_string[128];
164
167
  sprintf(
165
168
  location_string,
166
- "%zu,%zu)-(%zu,%zu",
167
- (location->start && location->start->line) ? location->start->line : 0,
168
- (location->start && location->start->column) ? location->start->column : 0,
169
- (location->end && location->end->line) ? location->end->line : 0,
170
- (location->end && location->end->column) ? location->end->column : 0
169
+ "%u,%u)-(%u,%u",
170
+ location.start.line,
171
+ location.start.column,
172
+ location.end.line,
173
+ location.end.column
171
174
  );
172
- buffer_append(buffer, location_string);
173
- buffer_append(buffer, "))");
175
+ hb_buffer_append(buffer, location_string);
176
+ hb_buffer_append(buffer, "))");
174
177
  }
175
178
 
176
179
  void pretty_print_position_property(
177
180
  position_T* position,
178
- const char* name,
181
+ hb_string_T name,
179
182
  const size_t indent,
180
183
  const size_t relative_indent,
181
184
  const bool last_property,
182
- buffer_T* buffer
185
+ hb_buffer_T* buffer
183
186
  ) {
184
187
  pretty_print_label(name, indent, relative_indent, last_property, buffer);
185
188
 
186
189
  if (position != NULL) {
187
- buffer_append(buffer, "(");
190
+ hb_buffer_append(buffer, "(");
188
191
 
189
192
  char position_string[128];
190
193
 
191
- sprintf(
192
- position_string,
193
- "%zu:%zu",
194
- (position->line) ? position->line : 0,
195
- (position->column) ? position->column : 0
196
- );
194
+ sprintf(position_string, "%u:%u", (position->line) ? position->line : 0, (position->column) ? position->column : 0);
197
195
 
198
- buffer_append(buffer, position_string);
199
- buffer_append(buffer, ")");
196
+ hb_buffer_append(buffer, position_string);
197
+ hb_buffer_append(buffer, ")");
200
198
  } else {
201
- buffer_append(buffer, "∅");
199
+ hb_buffer_append(buffer, "∅");
202
200
  }
203
201
 
204
- buffer_append(buffer, "\n");
202
+ hb_buffer_append(buffer, "\n");
205
203
  }
206
204
 
207
205
  void pretty_print_token_property(
208
206
  token_T* token,
209
- const char* name,
207
+ hb_string_T name,
210
208
  const size_t indent,
211
209
  const size_t relative_indent,
212
210
  const bool last_property,
213
- buffer_T* buffer
211
+ hb_buffer_T* buffer
214
212
  ) {
215
213
  pretty_print_label(name, indent, relative_indent, last_property, buffer);
216
214
 
217
215
  if (token != NULL && token->value != NULL) {
218
- char* quoted = quoted_string(token->value);
219
- buffer_append(buffer, quoted);
220
- free(quoted);
216
+ hb_string_T quoted = quoted_string(hb_string(token->value));
217
+ hb_buffer_append_string(buffer, quoted);
218
+ free(quoted.data);
221
219
 
222
- buffer_append(buffer, " ");
220
+ hb_buffer_append(buffer, " ");
223
221
  pretty_print_location(token->location, buffer);
224
222
  } else {
225
- buffer_append(buffer, "∅");
223
+ hb_buffer_append(buffer, "∅");
226
224
  }
227
225
 
228
- buffer_append(buffer, "\n");
226
+ hb_buffer_append(buffer, "\n");
229
227
  }
230
228
 
231
229
  void pretty_print_string_property(
232
- const char* string,
233
- const char* name,
230
+ hb_string_T string,
231
+ hb_string_T name,
234
232
  const size_t indent,
235
233
  const size_t relative_indent,
236
234
  const bool last_property,
237
- buffer_T* buffer
235
+ hb_buffer_T* buffer
238
236
  ) {
239
- const char* value = "∅";
240
- char* escaped = NULL;
241
- char* quoted = NULL;
237
+ hb_string_T value = hb_string("∅");
238
+ hb_string_T escaped = { .data = NULL, .length = 0 };
239
+ hb_string_T quoted;
242
240
 
243
- if (string != NULL) {
241
+ if (!hb_string_is_empty(string)) {
244
242
  escaped = escape_newlines(string);
245
243
  quoted = quoted_string(escaped);
246
244
  value = quoted;
@@ -248,35 +246,8 @@ void pretty_print_string_property(
248
246
 
249
247
  pretty_print_property(name, value, indent, relative_indent, last_property, buffer);
250
248
 
251
- if (string != NULL) {
252
- if (escaped != NULL) { free(escaped); }
253
- if (quoted != NULL) { free(quoted); }
249
+ if (!hb_string_is_empty(string)) {
250
+ if (!hb_string_is_empty(escaped)) { free(escaped.data); }
251
+ if (!hb_string_is_empty(quoted)) { free(quoted.data); }
254
252
  }
255
253
  }
256
-
257
- void pretty_print_analyzed_ruby(analyzed_ruby_T* analyzed, const char* source) {
258
- printf(
259
- "------------------------\nanalyzed (%p)\n------------------------\n%s\n------------------------\n if: %i\n "
260
- " elsif: %i\n else: %i\n end: %i\n block: %i\n block_closing: %i\n case: %i\n when: %i\n for: "
261
- "%i\n while: %i\n "
262
- " until: %i\n begin: %i\n "
263
- "rescue: %i\n ensure: %i\n unless: %i\n==================\n\n",
264
- (void*) analyzed,
265
- source,
266
- analyzed->has_if_node,
267
- analyzed->has_elsif_node,
268
- analyzed->has_else_node,
269
- analyzed->has_end,
270
- analyzed->has_block_node,
271
- analyzed->has_block_closing,
272
- analyzed->has_case_node,
273
- analyzed->has_when_node,
274
- analyzed->has_for_node,
275
- analyzed->has_while_node,
276
- analyzed->has_until_node,
277
- analyzed->has_begin_node,
278
- analyzed->has_rescue_node,
279
- analyzed->has_ensure_node,
280
- analyzed->has_unless_node
281
- );
282
- }
@@ -3,91 +3,101 @@
3
3
 
4
4
  #include "analyzed_ruby.h"
5
5
  #include "ast_nodes.h"
6
- #include "buffer.h"
7
6
  #include "location.h"
7
+ #include "util/hb_buffer.h"
8
8
 
9
9
  #include <stdbool.h>
10
10
 
11
- void pretty_print_indent(buffer_T* buffer, size_t indent);
12
- void pretty_print_newline(size_t indent, size_t relative_indent, buffer_T* buffer);
13
- void pretty_print_label(const char* name, size_t indent, size_t relative_indent, bool last_property, buffer_T* buffer);
11
+ void pretty_print_indent(hb_buffer_T* buffer, size_t indent);
12
+ void pretty_print_newline(size_t indent, size_t relative_indent, hb_buffer_T* buffer);
13
+ void pretty_print_label(
14
+ hb_string_T name,
15
+ size_t indent,
16
+ size_t relative_indent,
17
+ bool last_property,
18
+ hb_buffer_T* buffer
19
+ );
14
20
 
15
21
  void pretty_print_position_property(
16
22
  position_T* position,
17
- const char* name,
23
+ hb_string_T name,
18
24
  size_t indent,
19
25
  size_t relative_indent,
20
26
  bool last_property,
21
- buffer_T* buffer
27
+ hb_buffer_T* buffer
22
28
  );
23
29
 
24
- void pretty_print_location(location_T* location, buffer_T* buffer);
30
+ void pretty_print_location(location_T location, hb_buffer_T* buffer);
25
31
 
26
32
  void pretty_print_property(
27
- const char* name,
28
- const char* value,
33
+ hb_string_T name,
34
+ hb_string_T value,
29
35
  size_t indent,
30
36
  size_t relative_indent,
31
37
  bool last_property,
32
- buffer_T* buffer
38
+ hb_buffer_T* buffer
33
39
  );
34
40
 
35
41
  void pretty_print_size_t_property(
36
42
  size_t value,
37
- const char* name,
43
+ hb_string_T name,
38
44
  size_t indent,
39
45
  size_t relative_indent,
40
46
  bool last_property,
41
- buffer_T* buffer
47
+ hb_buffer_T* buffer
42
48
  );
43
49
 
44
50
  void pretty_print_string_property(
45
- const char* string,
46
- const char* name,
51
+ hb_string_T string,
52
+ hb_string_T name,
47
53
  size_t indent,
48
54
  size_t relative_indent,
49
55
  bool last_property,
50
- buffer_T* buffer
56
+ hb_buffer_T* buffer
51
57
  );
52
58
 
53
59
  void pretty_print_quoted_property(
54
- const char* name,
55
- const char* value,
60
+ hb_string_T name,
61
+ hb_string_T value,
56
62
  size_t indent,
57
63
  size_t relative_indent,
58
64
  bool last_property,
59
- buffer_T* buffer
65
+ hb_buffer_T* buffer
60
66
  );
61
67
 
62
68
  void pretty_print_boolean_property(
63
- const char* name,
69
+ hb_string_T name,
64
70
  bool value,
65
71
  size_t indent,
66
72
  size_t relative_indent,
67
73
  bool last_property,
68
- buffer_T* buffer
74
+ hb_buffer_T* buffer
69
75
  );
70
76
 
71
77
  void pretty_print_token_property(
72
78
  token_T* token,
73
- const char* name,
79
+ hb_string_T name,
74
80
  size_t indent,
75
81
  size_t relative_indent,
76
82
  bool last_property,
77
- buffer_T* buffer
83
+ hb_buffer_T* buffer
78
84
  );
79
85
 
80
86
  void pretty_print_array(
81
- const char* name,
82
- array_T* array,
87
+ hb_string_T name,
88
+ hb_array_T* array,
83
89
  size_t indent,
84
90
  size_t relative_indent,
85
91
  bool last_property,
86
- buffer_T* buffer
92
+ hb_buffer_T* buffer
87
93
  );
88
94
 
89
- void pretty_print_errors(AST_NODE_T* node, size_t indent, size_t relative_indent, bool last_property, buffer_T* buffer);
90
-
91
- void pretty_print_analyzed_ruby(analyzed_ruby_T* analyzed, const char* source);
95
+ void pretty_print_errors(
96
+ AST_NODE_T* node,
97
+ size_t indent,
98
+ size_t relative_indent,
99
+ bool last_property,
100
+ hb_buffer_T* buffer
101
+ );
92
102
 
93
103
  #endif
@@ -16,15 +16,15 @@ const char* pm_error_level_to_string(pm_error_level_t level) {
16
16
  }
17
17
  }
18
18
 
19
- position_T* position_from_source_with_offset(const char* source, size_t offset) {
20
- position_T* position = position_init(1, 0);
19
+ position_T position_from_source_with_offset(const char* source, size_t offset) {
20
+ position_T position = { .line = 1, .column = 0 };
21
21
 
22
22
  for (size_t i = 0; i < offset; i++) {
23
23
  if (is_newline(source[i])) {
24
- position->line++;
25
- position->column = 0;
24
+ position.line++;
25
+ position.column = 0;
26
26
  } else {
27
- position->column++;
27
+ position.column++;
28
28
  }
29
29
  }
30
30
 
@@ -40,8 +40,8 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
40
40
  size_t start_offset = (size_t) (error->location.start - parser->start);
41
41
  size_t end_offset = (size_t) (error->location.end - parser->start);
42
42
 
43
- position_T* start = position_from_source_with_offset(source, start_offset);
44
- position_T* end = position_from_source_with_offset(source, end_offset);
43
+ position_T start = position_from_source_with_offset(source, start_offset);
44
+ position_T end = position_from_source_with_offset(source, end_offset);
45
45
 
46
46
  return ruby_parse_error_init(
47
47
  error->message,
@@ -16,6 +16,6 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
16
16
  pm_parser_t* parser
17
17
  );
18
18
 
19
- position_T* position_from_source_with_offset(const char* source, size_t offset);
19
+ position_T position_from_source_with_offset(const char* source, size_t offset);
20
20
 
21
21
  #endif
@@ -1,38 +1,5 @@
1
1
  #include "include/range.h"
2
2
 
3
- size_t range_sizeof(void) {
4
- return sizeof(range_T);
5
- }
6
-
7
- range_T* range_init(const size_t from, const size_t to) {
8
- range_T* range = calloc(1, range_sizeof());
9
-
10
- range->from = from;
11
- range->to = to;
12
-
13
- return range;
14
- }
15
-
16
- size_t range_from(const range_T* range) {
17
- return range->from;
18
- }
19
-
20
- size_t range_to(const range_T* range) {
21
- return range->to;
22
- }
23
-
24
- size_t range_length(range_T* range) {
25
- return range_to(range) - range_from(range);
26
- }
27
-
28
- range_T* range_copy(range_T* range) {
29
- if (!range) { return NULL; }
30
-
31
- return range_init(range_from(range), range_to(range));
32
- }
33
-
34
- void range_free(range_T* range) {
35
- if (range == NULL) { return; }
36
-
37
- free(range);
3
+ uint32_t range_length(range_T range) {
4
+ return range.to - range.from;
38
5
  }
@@ -1,23 +1,14 @@
1
1
  #ifndef HERB_RANGE_H
2
2
  #define HERB_RANGE_H
3
3
 
4
+ #include <stdint.h>
4
5
  #include <stdlib.h>
5
6
 
6
7
  typedef struct RANGE_STRUCT {
7
- size_t from;
8
- size_t to;
8
+ uint32_t from;
9
+ uint32_t to;
9
10
  } range_T;
10
11
 
11
- range_T* range_init(size_t from, size_t to);
12
-
13
- size_t range_from(const range_T* range);
14
- size_t range_to(const range_T* range);
15
- size_t range_length(range_T* range);
16
-
17
- range_T* range_copy(range_T* range);
18
-
19
- size_t range_sizeof(void);
20
-
21
- void range_free(range_T* range);
12
+ uint32_t range_length(range_T range);
22
13
 
23
14
  #endif