prism 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +172 -0
  3. data/CODE_OF_CONDUCT.md +76 -0
  4. data/CONTRIBUTING.md +62 -0
  5. data/LICENSE.md +7 -0
  6. data/Makefile +84 -0
  7. data/README.md +89 -0
  8. data/config.yml +2481 -0
  9. data/docs/build_system.md +74 -0
  10. data/docs/building.md +22 -0
  11. data/docs/configuration.md +60 -0
  12. data/docs/design.md +53 -0
  13. data/docs/encoding.md +117 -0
  14. data/docs/fuzzing.md +93 -0
  15. data/docs/heredocs.md +36 -0
  16. data/docs/mapping.md +117 -0
  17. data/docs/ripper.md +36 -0
  18. data/docs/ruby_api.md +25 -0
  19. data/docs/serialization.md +181 -0
  20. data/docs/testing.md +55 -0
  21. data/ext/prism/api_node.c +4725 -0
  22. data/ext/prism/api_pack.c +256 -0
  23. data/ext/prism/extconf.rb +136 -0
  24. data/ext/prism/extension.c +626 -0
  25. data/ext/prism/extension.h +18 -0
  26. data/include/prism/ast.h +1932 -0
  27. data/include/prism/defines.h +45 -0
  28. data/include/prism/diagnostic.h +231 -0
  29. data/include/prism/enc/pm_encoding.h +95 -0
  30. data/include/prism/node.h +41 -0
  31. data/include/prism/pack.h +141 -0
  32. data/include/prism/parser.h +418 -0
  33. data/include/prism/regexp.h +19 -0
  34. data/include/prism/unescape.h +48 -0
  35. data/include/prism/util/pm_buffer.h +51 -0
  36. data/include/prism/util/pm_char.h +91 -0
  37. data/include/prism/util/pm_constant_pool.h +78 -0
  38. data/include/prism/util/pm_list.h +67 -0
  39. data/include/prism/util/pm_memchr.h +14 -0
  40. data/include/prism/util/pm_newline_list.h +61 -0
  41. data/include/prism/util/pm_state_stack.h +24 -0
  42. data/include/prism/util/pm_string.h +61 -0
  43. data/include/prism/util/pm_string_list.h +25 -0
  44. data/include/prism/util/pm_strpbrk.h +29 -0
  45. data/include/prism/version.h +4 -0
  46. data/include/prism.h +82 -0
  47. data/lib/prism/compiler.rb +465 -0
  48. data/lib/prism/debug.rb +157 -0
  49. data/lib/prism/desugar_compiler.rb +206 -0
  50. data/lib/prism/dispatcher.rb +2051 -0
  51. data/lib/prism/dsl.rb +750 -0
  52. data/lib/prism/ffi.rb +251 -0
  53. data/lib/prism/lex_compat.rb +838 -0
  54. data/lib/prism/mutation_compiler.rb +718 -0
  55. data/lib/prism/node.rb +14540 -0
  56. data/lib/prism/node_ext.rb +55 -0
  57. data/lib/prism/node_inspector.rb +68 -0
  58. data/lib/prism/pack.rb +185 -0
  59. data/lib/prism/parse_result/comments.rb +172 -0
  60. data/lib/prism/parse_result/newlines.rb +60 -0
  61. data/lib/prism/parse_result.rb +266 -0
  62. data/lib/prism/pattern.rb +239 -0
  63. data/lib/prism/ripper_compat.rb +174 -0
  64. data/lib/prism/serialize.rb +662 -0
  65. data/lib/prism/visitor.rb +470 -0
  66. data/lib/prism.rb +64 -0
  67. data/prism.gemspec +113 -0
  68. data/src/diagnostic.c +287 -0
  69. data/src/enc/pm_big5.c +52 -0
  70. data/src/enc/pm_euc_jp.c +58 -0
  71. data/src/enc/pm_gbk.c +61 -0
  72. data/src/enc/pm_shift_jis.c +56 -0
  73. data/src/enc/pm_tables.c +507 -0
  74. data/src/enc/pm_unicode.c +2324 -0
  75. data/src/enc/pm_windows_31j.c +56 -0
  76. data/src/node.c +2633 -0
  77. data/src/pack.c +493 -0
  78. data/src/prettyprint.c +2136 -0
  79. data/src/prism.c +14587 -0
  80. data/src/regexp.c +580 -0
  81. data/src/serialize.c +1899 -0
  82. data/src/token_type.c +349 -0
  83. data/src/unescape.c +637 -0
  84. data/src/util/pm_buffer.c +103 -0
  85. data/src/util/pm_char.c +272 -0
  86. data/src/util/pm_constant_pool.c +252 -0
  87. data/src/util/pm_list.c +41 -0
  88. data/src/util/pm_memchr.c +33 -0
  89. data/src/util/pm_newline_list.c +134 -0
  90. data/src/util/pm_state_stack.c +19 -0
  91. data/src/util/pm_string.c +200 -0
  92. data/src/util/pm_string_list.c +29 -0
  93. data/src/util/pm_strncasecmp.c +17 -0
  94. data/src/util/pm_strpbrk.c +66 -0
  95. metadata +138 -0
data/src/serialize.c ADDED
@@ -0,0 +1,1899 @@
1
+ /******************************************************************************/
2
+ /* This file is generated by the templates/template.rb script and should not */
3
+ /* be modified manually. See */
4
+ /* templates/src/serialize.c.erb */
5
+ /* if you are looking to modify the */
6
+ /* template */
7
+ /******************************************************************************/
8
+ #include "prism.h"
9
+
10
+ #include <stdio.h>
11
+
12
+ static inline uint32_t
13
+ pm_ptrdifft_to_u32(ptrdiff_t value) {
14
+ assert(value >= 0 && ((unsigned long) value) < UINT32_MAX);
15
+ return (uint32_t) value;
16
+ }
17
+
18
+ static inline uint32_t
19
+ pm_sizet_to_u32(size_t value) {
20
+ assert(value < UINT32_MAX);
21
+ return (uint32_t) value;
22
+ }
23
+
24
+ static void
25
+ pm_serialize_location(pm_parser_t *parser, pm_location_t *location, pm_buffer_t *buffer) {
26
+ assert(location->start);
27
+ assert(location->end);
28
+ assert(location->start <= location->end);
29
+
30
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(location->start - parser->start));
31
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(location->end - location->start));
32
+ }
33
+
34
+ static void
35
+ pm_serialize_string(pm_parser_t *parser, pm_string_t *string, pm_buffer_t *buffer) {
36
+ switch (string->type) {
37
+ case PM_STRING_SHARED: {
38
+ pm_buffer_append_u8(buffer, 1);
39
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(pm_string_source(string) - parser->start));
40
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(pm_string_length(string)));
41
+ break;
42
+ }
43
+ case PM_STRING_OWNED:
44
+ case PM_STRING_CONSTANT: {
45
+ uint32_t length = pm_sizet_to_u32(pm_string_length(string));
46
+ pm_buffer_append_u8(buffer, 2);
47
+ pm_buffer_append_u32(buffer, length);
48
+ pm_buffer_append_bytes(buffer, pm_string_source(string), length);
49
+ break;
50
+ }
51
+ case PM_STRING_MAPPED:
52
+ assert(false && "Cannot serialize mapped strings.");
53
+ break;
54
+ }
55
+ }
56
+
57
+ void
58
+ pm_serialize_node(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
59
+ pm_buffer_append_u8(buffer, (uint8_t) PM_NODE_TYPE(node));
60
+
61
+ size_t offset = buffer->length;
62
+
63
+ pm_serialize_location(parser, &node->location, buffer);
64
+
65
+ switch (PM_NODE_TYPE(node)) {
66
+ // We do not need to serialize a ScopeNode ever as
67
+ // it is not part of the AST
68
+ case PM_SCOPE_NODE:
69
+ return;
70
+ case PM_ALIAS_GLOBAL_VARIABLE_NODE: {
71
+ pm_serialize_node(parser, (pm_node_t *)((pm_alias_global_variable_node_t *)node)->new_name, buffer);
72
+ pm_serialize_node(parser, (pm_node_t *)((pm_alias_global_variable_node_t *)node)->old_name, buffer);
73
+ pm_serialize_location(parser, &((pm_alias_global_variable_node_t *)node)->keyword_loc, buffer);
74
+ break;
75
+ }
76
+ case PM_ALIAS_METHOD_NODE: {
77
+ pm_serialize_node(parser, (pm_node_t *)((pm_alias_method_node_t *)node)->new_name, buffer);
78
+ pm_serialize_node(parser, (pm_node_t *)((pm_alias_method_node_t *)node)->old_name, buffer);
79
+ pm_serialize_location(parser, &((pm_alias_method_node_t *)node)->keyword_loc, buffer);
80
+ break;
81
+ }
82
+ case PM_ALTERNATION_PATTERN_NODE: {
83
+ pm_serialize_node(parser, (pm_node_t *)((pm_alternation_pattern_node_t *)node)->left, buffer);
84
+ pm_serialize_node(parser, (pm_node_t *)((pm_alternation_pattern_node_t *)node)->right, buffer);
85
+ pm_serialize_location(parser, &((pm_alternation_pattern_node_t *)node)->operator_loc, buffer);
86
+ break;
87
+ }
88
+ case PM_AND_NODE: {
89
+ pm_serialize_node(parser, (pm_node_t *)((pm_and_node_t *)node)->left, buffer);
90
+ pm_serialize_node(parser, (pm_node_t *)((pm_and_node_t *)node)->right, buffer);
91
+ pm_serialize_location(parser, &((pm_and_node_t *)node)->operator_loc, buffer);
92
+ break;
93
+ }
94
+ case PM_ARGUMENTS_NODE: {
95
+ uint32_t arguments_size = pm_sizet_to_u32(((pm_arguments_node_t *)node)->arguments.size);
96
+ pm_buffer_append_u32(buffer, arguments_size);
97
+ for (uint32_t index = 0; index < arguments_size; index++) {
98
+ pm_serialize_node(parser, (pm_node_t *) ((pm_arguments_node_t *)node)->arguments.nodes[index], buffer);
99
+ }
100
+ break;
101
+ }
102
+ case PM_ARRAY_NODE: {
103
+ uint32_t elements_size = pm_sizet_to_u32(((pm_array_node_t *)node)->elements.size);
104
+ pm_buffer_append_u32(buffer, elements_size);
105
+ for (uint32_t index = 0; index < elements_size; index++) {
106
+ pm_serialize_node(parser, (pm_node_t *) ((pm_array_node_t *)node)->elements.nodes[index], buffer);
107
+ }
108
+ if (((pm_array_node_t *)node)->opening_loc.start == NULL) {
109
+ pm_buffer_append_u8(buffer, 0);
110
+ } else {
111
+ pm_buffer_append_u8(buffer, 1);
112
+ pm_serialize_location(parser, &((pm_array_node_t *)node)->opening_loc, buffer);
113
+ }
114
+ if (((pm_array_node_t *)node)->closing_loc.start == NULL) {
115
+ pm_buffer_append_u8(buffer, 0);
116
+ } else {
117
+ pm_buffer_append_u8(buffer, 1);
118
+ pm_serialize_location(parser, &((pm_array_node_t *)node)->closing_loc, buffer);
119
+ }
120
+ break;
121
+ }
122
+ case PM_ARRAY_PATTERN_NODE: {
123
+ if (((pm_array_pattern_node_t *)node)->constant == NULL) {
124
+ pm_buffer_append_u8(buffer, 0);
125
+ } else {
126
+ pm_serialize_node(parser, (pm_node_t *)((pm_array_pattern_node_t *)node)->constant, buffer);
127
+ }
128
+ uint32_t requireds_size = pm_sizet_to_u32(((pm_array_pattern_node_t *)node)->requireds.size);
129
+ pm_buffer_append_u32(buffer, requireds_size);
130
+ for (uint32_t index = 0; index < requireds_size; index++) {
131
+ pm_serialize_node(parser, (pm_node_t *) ((pm_array_pattern_node_t *)node)->requireds.nodes[index], buffer);
132
+ }
133
+ if (((pm_array_pattern_node_t *)node)->rest == NULL) {
134
+ pm_buffer_append_u8(buffer, 0);
135
+ } else {
136
+ pm_serialize_node(parser, (pm_node_t *)((pm_array_pattern_node_t *)node)->rest, buffer);
137
+ }
138
+ uint32_t posts_size = pm_sizet_to_u32(((pm_array_pattern_node_t *)node)->posts.size);
139
+ pm_buffer_append_u32(buffer, posts_size);
140
+ for (uint32_t index = 0; index < posts_size; index++) {
141
+ pm_serialize_node(parser, (pm_node_t *) ((pm_array_pattern_node_t *)node)->posts.nodes[index], buffer);
142
+ }
143
+ if (((pm_array_pattern_node_t *)node)->opening_loc.start == NULL) {
144
+ pm_buffer_append_u8(buffer, 0);
145
+ } else {
146
+ pm_buffer_append_u8(buffer, 1);
147
+ pm_serialize_location(parser, &((pm_array_pattern_node_t *)node)->opening_loc, buffer);
148
+ }
149
+ if (((pm_array_pattern_node_t *)node)->closing_loc.start == NULL) {
150
+ pm_buffer_append_u8(buffer, 0);
151
+ } else {
152
+ pm_buffer_append_u8(buffer, 1);
153
+ pm_serialize_location(parser, &((pm_array_pattern_node_t *)node)->closing_loc, buffer);
154
+ }
155
+ break;
156
+ }
157
+ case PM_ASSOC_NODE: {
158
+ pm_serialize_node(parser, (pm_node_t *)((pm_assoc_node_t *)node)->key, buffer);
159
+ if (((pm_assoc_node_t *)node)->value == NULL) {
160
+ pm_buffer_append_u8(buffer, 0);
161
+ } else {
162
+ pm_serialize_node(parser, (pm_node_t *)((pm_assoc_node_t *)node)->value, buffer);
163
+ }
164
+ if (((pm_assoc_node_t *)node)->operator_loc.start == NULL) {
165
+ pm_buffer_append_u8(buffer, 0);
166
+ } else {
167
+ pm_buffer_append_u8(buffer, 1);
168
+ pm_serialize_location(parser, &((pm_assoc_node_t *)node)->operator_loc, buffer);
169
+ }
170
+ break;
171
+ }
172
+ case PM_ASSOC_SPLAT_NODE: {
173
+ if (((pm_assoc_splat_node_t *)node)->value == NULL) {
174
+ pm_buffer_append_u8(buffer, 0);
175
+ } else {
176
+ pm_serialize_node(parser, (pm_node_t *)((pm_assoc_splat_node_t *)node)->value, buffer);
177
+ }
178
+ pm_serialize_location(parser, &((pm_assoc_splat_node_t *)node)->operator_loc, buffer);
179
+ break;
180
+ }
181
+ case PM_BACK_REFERENCE_READ_NODE: {
182
+ break;
183
+ }
184
+ case PM_BEGIN_NODE: {
185
+ if (((pm_begin_node_t *)node)->begin_keyword_loc.start == NULL) {
186
+ pm_buffer_append_u8(buffer, 0);
187
+ } else {
188
+ pm_buffer_append_u8(buffer, 1);
189
+ pm_serialize_location(parser, &((pm_begin_node_t *)node)->begin_keyword_loc, buffer);
190
+ }
191
+ if (((pm_begin_node_t *)node)->statements == NULL) {
192
+ pm_buffer_append_u8(buffer, 0);
193
+ } else {
194
+ pm_serialize_node(parser, (pm_node_t *)((pm_begin_node_t *)node)->statements, buffer);
195
+ }
196
+ if (((pm_begin_node_t *)node)->rescue_clause == NULL) {
197
+ pm_buffer_append_u8(buffer, 0);
198
+ } else {
199
+ pm_serialize_node(parser, (pm_node_t *)((pm_begin_node_t *)node)->rescue_clause, buffer);
200
+ }
201
+ if (((pm_begin_node_t *)node)->else_clause == NULL) {
202
+ pm_buffer_append_u8(buffer, 0);
203
+ } else {
204
+ pm_serialize_node(parser, (pm_node_t *)((pm_begin_node_t *)node)->else_clause, buffer);
205
+ }
206
+ if (((pm_begin_node_t *)node)->ensure_clause == NULL) {
207
+ pm_buffer_append_u8(buffer, 0);
208
+ } else {
209
+ pm_serialize_node(parser, (pm_node_t *)((pm_begin_node_t *)node)->ensure_clause, buffer);
210
+ }
211
+ if (((pm_begin_node_t *)node)->end_keyword_loc.start == NULL) {
212
+ pm_buffer_append_u8(buffer, 0);
213
+ } else {
214
+ pm_buffer_append_u8(buffer, 1);
215
+ pm_serialize_location(parser, &((pm_begin_node_t *)node)->end_keyword_loc, buffer);
216
+ }
217
+ break;
218
+ }
219
+ case PM_BLOCK_ARGUMENT_NODE: {
220
+ if (((pm_block_argument_node_t *)node)->expression == NULL) {
221
+ pm_buffer_append_u8(buffer, 0);
222
+ } else {
223
+ pm_serialize_node(parser, (pm_node_t *)((pm_block_argument_node_t *)node)->expression, buffer);
224
+ }
225
+ pm_serialize_location(parser, &((pm_block_argument_node_t *)node)->operator_loc, buffer);
226
+ break;
227
+ }
228
+ case PM_BLOCK_LOCAL_VARIABLE_NODE: {
229
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_block_local_variable_node_t *)node)->name));
230
+ break;
231
+ }
232
+ case PM_BLOCK_NODE: {
233
+ uint32_t locals_size = pm_sizet_to_u32(((pm_block_node_t *)node)->locals.size);
234
+ pm_buffer_append_u32(buffer, locals_size);
235
+ for (uint32_t index = 0; index < locals_size; index++) {
236
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_block_node_t *)node)->locals.ids[index]));
237
+ }
238
+ if (((pm_block_node_t *)node)->parameters == NULL) {
239
+ pm_buffer_append_u8(buffer, 0);
240
+ } else {
241
+ pm_serialize_node(parser, (pm_node_t *)((pm_block_node_t *)node)->parameters, buffer);
242
+ }
243
+ if (((pm_block_node_t *)node)->body == NULL) {
244
+ pm_buffer_append_u8(buffer, 0);
245
+ } else {
246
+ pm_serialize_node(parser, (pm_node_t *)((pm_block_node_t *)node)->body, buffer);
247
+ }
248
+ pm_serialize_location(parser, &((pm_block_node_t *)node)->opening_loc, buffer);
249
+ pm_serialize_location(parser, &((pm_block_node_t *)node)->closing_loc, buffer);
250
+ break;
251
+ }
252
+ case PM_BLOCK_PARAMETER_NODE: {
253
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_block_parameter_node_t *)node)->name));
254
+ if (((pm_block_parameter_node_t *)node)->name_loc.start == NULL) {
255
+ pm_buffer_append_u8(buffer, 0);
256
+ } else {
257
+ pm_buffer_append_u8(buffer, 1);
258
+ pm_serialize_location(parser, &((pm_block_parameter_node_t *)node)->name_loc, buffer);
259
+ }
260
+ pm_serialize_location(parser, &((pm_block_parameter_node_t *)node)->operator_loc, buffer);
261
+ break;
262
+ }
263
+ case PM_BLOCK_PARAMETERS_NODE: {
264
+ if (((pm_block_parameters_node_t *)node)->parameters == NULL) {
265
+ pm_buffer_append_u8(buffer, 0);
266
+ } else {
267
+ pm_serialize_node(parser, (pm_node_t *)((pm_block_parameters_node_t *)node)->parameters, buffer);
268
+ }
269
+ uint32_t locals_size = pm_sizet_to_u32(((pm_block_parameters_node_t *)node)->locals.size);
270
+ pm_buffer_append_u32(buffer, locals_size);
271
+ for (uint32_t index = 0; index < locals_size; index++) {
272
+ pm_serialize_node(parser, (pm_node_t *) ((pm_block_parameters_node_t *)node)->locals.nodes[index], buffer);
273
+ }
274
+ if (((pm_block_parameters_node_t *)node)->opening_loc.start == NULL) {
275
+ pm_buffer_append_u8(buffer, 0);
276
+ } else {
277
+ pm_buffer_append_u8(buffer, 1);
278
+ pm_serialize_location(parser, &((pm_block_parameters_node_t *)node)->opening_loc, buffer);
279
+ }
280
+ if (((pm_block_parameters_node_t *)node)->closing_loc.start == NULL) {
281
+ pm_buffer_append_u8(buffer, 0);
282
+ } else {
283
+ pm_buffer_append_u8(buffer, 1);
284
+ pm_serialize_location(parser, &((pm_block_parameters_node_t *)node)->closing_loc, buffer);
285
+ }
286
+ break;
287
+ }
288
+ case PM_BREAK_NODE: {
289
+ if (((pm_break_node_t *)node)->arguments == NULL) {
290
+ pm_buffer_append_u8(buffer, 0);
291
+ } else {
292
+ pm_serialize_node(parser, (pm_node_t *)((pm_break_node_t *)node)->arguments, buffer);
293
+ }
294
+ pm_serialize_location(parser, &((pm_break_node_t *)node)->keyword_loc, buffer);
295
+ break;
296
+ }
297
+ case PM_CALL_AND_WRITE_NODE: {
298
+ if (((pm_call_and_write_node_t *)node)->receiver == NULL) {
299
+ pm_buffer_append_u8(buffer, 0);
300
+ } else {
301
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_and_write_node_t *)node)->receiver, buffer);
302
+ }
303
+ if (((pm_call_and_write_node_t *)node)->call_operator_loc.start == NULL) {
304
+ pm_buffer_append_u8(buffer, 0);
305
+ } else {
306
+ pm_buffer_append_u8(buffer, 1);
307
+ pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->call_operator_loc, buffer);
308
+ }
309
+ if (((pm_call_and_write_node_t *)node)->message_loc.start == NULL) {
310
+ pm_buffer_append_u8(buffer, 0);
311
+ } else {
312
+ pm_buffer_append_u8(buffer, 1);
313
+ pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->message_loc, buffer);
314
+ }
315
+ if (((pm_call_and_write_node_t *)node)->opening_loc.start == NULL) {
316
+ pm_buffer_append_u8(buffer, 0);
317
+ } else {
318
+ pm_buffer_append_u8(buffer, 1);
319
+ pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->opening_loc, buffer);
320
+ }
321
+ if (((pm_call_and_write_node_t *)node)->arguments == NULL) {
322
+ pm_buffer_append_u8(buffer, 0);
323
+ } else {
324
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_and_write_node_t *)node)->arguments, buffer);
325
+ }
326
+ if (((pm_call_and_write_node_t *)node)->closing_loc.start == NULL) {
327
+ pm_buffer_append_u8(buffer, 0);
328
+ } else {
329
+ pm_buffer_append_u8(buffer, 1);
330
+ pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->closing_loc, buffer);
331
+ }
332
+ pm_buffer_append_u32(buffer, node->flags >> 2);
333
+ pm_serialize_string(parser, &((pm_call_and_write_node_t *)node)->read_name, buffer);
334
+ pm_serialize_string(parser, &((pm_call_and_write_node_t *)node)->write_name, buffer);
335
+ pm_serialize_location(parser, &((pm_call_and_write_node_t *)node)->operator_loc, buffer);
336
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_and_write_node_t *)node)->value, buffer);
337
+ break;
338
+ }
339
+ case PM_CALL_NODE: {
340
+ if (((pm_call_node_t *)node)->receiver == NULL) {
341
+ pm_buffer_append_u8(buffer, 0);
342
+ } else {
343
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_node_t *)node)->receiver, buffer);
344
+ }
345
+ if (((pm_call_node_t *)node)->call_operator_loc.start == NULL) {
346
+ pm_buffer_append_u8(buffer, 0);
347
+ } else {
348
+ pm_buffer_append_u8(buffer, 1);
349
+ pm_serialize_location(parser, &((pm_call_node_t *)node)->call_operator_loc, buffer);
350
+ }
351
+ if (((pm_call_node_t *)node)->message_loc.start == NULL) {
352
+ pm_buffer_append_u8(buffer, 0);
353
+ } else {
354
+ pm_buffer_append_u8(buffer, 1);
355
+ pm_serialize_location(parser, &((pm_call_node_t *)node)->message_loc, buffer);
356
+ }
357
+ if (((pm_call_node_t *)node)->opening_loc.start == NULL) {
358
+ pm_buffer_append_u8(buffer, 0);
359
+ } else {
360
+ pm_buffer_append_u8(buffer, 1);
361
+ pm_serialize_location(parser, &((pm_call_node_t *)node)->opening_loc, buffer);
362
+ }
363
+ if (((pm_call_node_t *)node)->arguments == NULL) {
364
+ pm_buffer_append_u8(buffer, 0);
365
+ } else {
366
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_node_t *)node)->arguments, buffer);
367
+ }
368
+ if (((pm_call_node_t *)node)->closing_loc.start == NULL) {
369
+ pm_buffer_append_u8(buffer, 0);
370
+ } else {
371
+ pm_buffer_append_u8(buffer, 1);
372
+ pm_serialize_location(parser, &((pm_call_node_t *)node)->closing_loc, buffer);
373
+ }
374
+ if (((pm_call_node_t *)node)->block == NULL) {
375
+ pm_buffer_append_u8(buffer, 0);
376
+ } else {
377
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_node_t *)node)->block, buffer);
378
+ }
379
+ pm_buffer_append_u32(buffer, node->flags >> 2);
380
+ pm_serialize_string(parser, &((pm_call_node_t *)node)->name, buffer);
381
+ break;
382
+ }
383
+ case PM_CALL_OPERATOR_WRITE_NODE: {
384
+ if (((pm_call_operator_write_node_t *)node)->receiver == NULL) {
385
+ pm_buffer_append_u8(buffer, 0);
386
+ } else {
387
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->receiver, buffer);
388
+ }
389
+ if (((pm_call_operator_write_node_t *)node)->call_operator_loc.start == NULL) {
390
+ pm_buffer_append_u8(buffer, 0);
391
+ } else {
392
+ pm_buffer_append_u8(buffer, 1);
393
+ pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->call_operator_loc, buffer);
394
+ }
395
+ if (((pm_call_operator_write_node_t *)node)->message_loc.start == NULL) {
396
+ pm_buffer_append_u8(buffer, 0);
397
+ } else {
398
+ pm_buffer_append_u8(buffer, 1);
399
+ pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->message_loc, buffer);
400
+ }
401
+ if (((pm_call_operator_write_node_t *)node)->opening_loc.start == NULL) {
402
+ pm_buffer_append_u8(buffer, 0);
403
+ } else {
404
+ pm_buffer_append_u8(buffer, 1);
405
+ pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->opening_loc, buffer);
406
+ }
407
+ if (((pm_call_operator_write_node_t *)node)->arguments == NULL) {
408
+ pm_buffer_append_u8(buffer, 0);
409
+ } else {
410
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->arguments, buffer);
411
+ }
412
+ if (((pm_call_operator_write_node_t *)node)->closing_loc.start == NULL) {
413
+ pm_buffer_append_u8(buffer, 0);
414
+ } else {
415
+ pm_buffer_append_u8(buffer, 1);
416
+ pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->closing_loc, buffer);
417
+ }
418
+ pm_buffer_append_u32(buffer, node->flags >> 2);
419
+ pm_serialize_string(parser, &((pm_call_operator_write_node_t *)node)->read_name, buffer);
420
+ pm_serialize_string(parser, &((pm_call_operator_write_node_t *)node)->write_name, buffer);
421
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_call_operator_write_node_t *)node)->operator));
422
+ pm_serialize_location(parser, &((pm_call_operator_write_node_t *)node)->operator_loc, buffer);
423
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_operator_write_node_t *)node)->value, buffer);
424
+ break;
425
+ }
426
+ case PM_CALL_OR_WRITE_NODE: {
427
+ if (((pm_call_or_write_node_t *)node)->receiver == NULL) {
428
+ pm_buffer_append_u8(buffer, 0);
429
+ } else {
430
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_or_write_node_t *)node)->receiver, buffer);
431
+ }
432
+ if (((pm_call_or_write_node_t *)node)->call_operator_loc.start == NULL) {
433
+ pm_buffer_append_u8(buffer, 0);
434
+ } else {
435
+ pm_buffer_append_u8(buffer, 1);
436
+ pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->call_operator_loc, buffer);
437
+ }
438
+ if (((pm_call_or_write_node_t *)node)->message_loc.start == NULL) {
439
+ pm_buffer_append_u8(buffer, 0);
440
+ } else {
441
+ pm_buffer_append_u8(buffer, 1);
442
+ pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->message_loc, buffer);
443
+ }
444
+ if (((pm_call_or_write_node_t *)node)->opening_loc.start == NULL) {
445
+ pm_buffer_append_u8(buffer, 0);
446
+ } else {
447
+ pm_buffer_append_u8(buffer, 1);
448
+ pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->opening_loc, buffer);
449
+ }
450
+ if (((pm_call_or_write_node_t *)node)->arguments == NULL) {
451
+ pm_buffer_append_u8(buffer, 0);
452
+ } else {
453
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_or_write_node_t *)node)->arguments, buffer);
454
+ }
455
+ if (((pm_call_or_write_node_t *)node)->closing_loc.start == NULL) {
456
+ pm_buffer_append_u8(buffer, 0);
457
+ } else {
458
+ pm_buffer_append_u8(buffer, 1);
459
+ pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->closing_loc, buffer);
460
+ }
461
+ pm_buffer_append_u32(buffer, node->flags >> 2);
462
+ pm_serialize_string(parser, &((pm_call_or_write_node_t *)node)->read_name, buffer);
463
+ pm_serialize_string(parser, &((pm_call_or_write_node_t *)node)->write_name, buffer);
464
+ pm_serialize_location(parser, &((pm_call_or_write_node_t *)node)->operator_loc, buffer);
465
+ pm_serialize_node(parser, (pm_node_t *)((pm_call_or_write_node_t *)node)->value, buffer);
466
+ break;
467
+ }
468
+ case PM_CAPTURE_PATTERN_NODE: {
469
+ pm_serialize_node(parser, (pm_node_t *)((pm_capture_pattern_node_t *)node)->value, buffer);
470
+ pm_serialize_node(parser, (pm_node_t *)((pm_capture_pattern_node_t *)node)->target, buffer);
471
+ pm_serialize_location(parser, &((pm_capture_pattern_node_t *)node)->operator_loc, buffer);
472
+ break;
473
+ }
474
+ case PM_CASE_NODE: {
475
+ if (((pm_case_node_t *)node)->predicate == NULL) {
476
+ pm_buffer_append_u8(buffer, 0);
477
+ } else {
478
+ pm_serialize_node(parser, (pm_node_t *)((pm_case_node_t *)node)->predicate, buffer);
479
+ }
480
+ uint32_t conditions_size = pm_sizet_to_u32(((pm_case_node_t *)node)->conditions.size);
481
+ pm_buffer_append_u32(buffer, conditions_size);
482
+ for (uint32_t index = 0; index < conditions_size; index++) {
483
+ pm_serialize_node(parser, (pm_node_t *) ((pm_case_node_t *)node)->conditions.nodes[index], buffer);
484
+ }
485
+ if (((pm_case_node_t *)node)->consequent == NULL) {
486
+ pm_buffer_append_u8(buffer, 0);
487
+ } else {
488
+ pm_serialize_node(parser, (pm_node_t *)((pm_case_node_t *)node)->consequent, buffer);
489
+ }
490
+ pm_serialize_location(parser, &((pm_case_node_t *)node)->case_keyword_loc, buffer);
491
+ pm_serialize_location(parser, &((pm_case_node_t *)node)->end_keyword_loc, buffer);
492
+ break;
493
+ }
494
+ case PM_CLASS_NODE: {
495
+ uint32_t locals_size = pm_sizet_to_u32(((pm_class_node_t *)node)->locals.size);
496
+ pm_buffer_append_u32(buffer, locals_size);
497
+ for (uint32_t index = 0; index < locals_size; index++) {
498
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->locals.ids[index]));
499
+ }
500
+ pm_serialize_location(parser, &((pm_class_node_t *)node)->class_keyword_loc, buffer);
501
+ pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->constant_path, buffer);
502
+ if (((pm_class_node_t *)node)->inheritance_operator_loc.start == NULL) {
503
+ pm_buffer_append_u8(buffer, 0);
504
+ } else {
505
+ pm_buffer_append_u8(buffer, 1);
506
+ pm_serialize_location(parser, &((pm_class_node_t *)node)->inheritance_operator_loc, buffer);
507
+ }
508
+ if (((pm_class_node_t *)node)->superclass == NULL) {
509
+ pm_buffer_append_u8(buffer, 0);
510
+ } else {
511
+ pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->superclass, buffer);
512
+ }
513
+ if (((pm_class_node_t *)node)->body == NULL) {
514
+ pm_buffer_append_u8(buffer, 0);
515
+ } else {
516
+ pm_serialize_node(parser, (pm_node_t *)((pm_class_node_t *)node)->body, buffer);
517
+ }
518
+ pm_serialize_location(parser, &((pm_class_node_t *)node)->end_keyword_loc, buffer);
519
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_node_t *)node)->name));
520
+ break;
521
+ }
522
+ case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
523
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_variable_and_write_node_t *)node)->name));
524
+ pm_serialize_location(parser, &((pm_class_variable_and_write_node_t *)node)->name_loc, buffer);
525
+ pm_serialize_location(parser, &((pm_class_variable_and_write_node_t *)node)->operator_loc, buffer);
526
+ pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_and_write_node_t *)node)->value, buffer);
527
+ break;
528
+ }
529
+ case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
530
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->name));
531
+ pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->name_loc, buffer);
532
+ pm_serialize_location(parser, &((pm_class_variable_operator_write_node_t *)node)->operator_loc, buffer);
533
+ pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_operator_write_node_t *)node)->value, buffer);
534
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_variable_operator_write_node_t *)node)->operator));
535
+ break;
536
+ }
537
+ case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
538
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_variable_or_write_node_t *)node)->name));
539
+ pm_serialize_location(parser, &((pm_class_variable_or_write_node_t *)node)->name_loc, buffer);
540
+ pm_serialize_location(parser, &((pm_class_variable_or_write_node_t *)node)->operator_loc, buffer);
541
+ pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_or_write_node_t *)node)->value, buffer);
542
+ break;
543
+ }
544
+ case PM_CLASS_VARIABLE_READ_NODE: {
545
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_variable_read_node_t *)node)->name));
546
+ break;
547
+ }
548
+ case PM_CLASS_VARIABLE_TARGET_NODE: {
549
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_variable_target_node_t *)node)->name));
550
+ break;
551
+ }
552
+ case PM_CLASS_VARIABLE_WRITE_NODE: {
553
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_class_variable_write_node_t *)node)->name));
554
+ pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->name_loc, buffer);
555
+ pm_serialize_node(parser, (pm_node_t *)((pm_class_variable_write_node_t *)node)->value, buffer);
556
+ if (((pm_class_variable_write_node_t *)node)->operator_loc.start == NULL) {
557
+ pm_buffer_append_u8(buffer, 0);
558
+ } else {
559
+ pm_buffer_append_u8(buffer, 1);
560
+ pm_serialize_location(parser, &((pm_class_variable_write_node_t *)node)->operator_loc, buffer);
561
+ }
562
+ break;
563
+ }
564
+ case PM_CONSTANT_AND_WRITE_NODE: {
565
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_constant_and_write_node_t *)node)->name));
566
+ pm_serialize_location(parser, &((pm_constant_and_write_node_t *)node)->name_loc, buffer);
567
+ pm_serialize_location(parser, &((pm_constant_and_write_node_t *)node)->operator_loc, buffer);
568
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_and_write_node_t *)node)->value, buffer);
569
+ break;
570
+ }
571
+ case PM_CONSTANT_OPERATOR_WRITE_NODE: {
572
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->name));
573
+ pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->name_loc, buffer);
574
+ pm_serialize_location(parser, &((pm_constant_operator_write_node_t *)node)->operator_loc, buffer);
575
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_operator_write_node_t *)node)->value, buffer);
576
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_constant_operator_write_node_t *)node)->operator));
577
+ break;
578
+ }
579
+ case PM_CONSTANT_OR_WRITE_NODE: {
580
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_constant_or_write_node_t *)node)->name));
581
+ pm_serialize_location(parser, &((pm_constant_or_write_node_t *)node)->name_loc, buffer);
582
+ pm_serialize_location(parser, &((pm_constant_or_write_node_t *)node)->operator_loc, buffer);
583
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_or_write_node_t *)node)->value, buffer);
584
+ break;
585
+ }
586
+ case PM_CONSTANT_PATH_AND_WRITE_NODE: {
587
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_and_write_node_t *)node)->target, buffer);
588
+ pm_serialize_location(parser, &((pm_constant_path_and_write_node_t *)node)->operator_loc, buffer);
589
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_and_write_node_t *)node)->value, buffer);
590
+ break;
591
+ }
592
+ case PM_CONSTANT_PATH_NODE: {
593
+ if (((pm_constant_path_node_t *)node)->parent == NULL) {
594
+ pm_buffer_append_u8(buffer, 0);
595
+ } else {
596
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_node_t *)node)->parent, buffer);
597
+ }
598
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_node_t *)node)->child, buffer);
599
+ pm_serialize_location(parser, &((pm_constant_path_node_t *)node)->delimiter_loc, buffer);
600
+ break;
601
+ }
602
+ case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
603
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->target, buffer);
604
+ pm_serialize_location(parser, &((pm_constant_path_operator_write_node_t *)node)->operator_loc, buffer);
605
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_operator_write_node_t *)node)->value, buffer);
606
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_constant_path_operator_write_node_t *)node)->operator));
607
+ break;
608
+ }
609
+ case PM_CONSTANT_PATH_OR_WRITE_NODE: {
610
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_or_write_node_t *)node)->target, buffer);
611
+ pm_serialize_location(parser, &((pm_constant_path_or_write_node_t *)node)->operator_loc, buffer);
612
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_or_write_node_t *)node)->value, buffer);
613
+ break;
614
+ }
615
+ case PM_CONSTANT_PATH_TARGET_NODE: {
616
+ if (((pm_constant_path_target_node_t *)node)->parent == NULL) {
617
+ pm_buffer_append_u8(buffer, 0);
618
+ } else {
619
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_target_node_t *)node)->parent, buffer);
620
+ }
621
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_target_node_t *)node)->child, buffer);
622
+ pm_serialize_location(parser, &((pm_constant_path_target_node_t *)node)->delimiter_loc, buffer);
623
+ break;
624
+ }
625
+ case PM_CONSTANT_PATH_WRITE_NODE: {
626
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_write_node_t *)node)->target, buffer);
627
+ pm_serialize_location(parser, &((pm_constant_path_write_node_t *)node)->operator_loc, buffer);
628
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_path_write_node_t *)node)->value, buffer);
629
+ break;
630
+ }
631
+ case PM_CONSTANT_READ_NODE: {
632
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_constant_read_node_t *)node)->name));
633
+ break;
634
+ }
635
+ case PM_CONSTANT_TARGET_NODE: {
636
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_constant_target_node_t *)node)->name));
637
+ break;
638
+ }
639
+ case PM_CONSTANT_WRITE_NODE: {
640
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_constant_write_node_t *)node)->name));
641
+ pm_serialize_location(parser, &((pm_constant_write_node_t *)node)->name_loc, buffer);
642
+ pm_serialize_node(parser, (pm_node_t *)((pm_constant_write_node_t *)node)->value, buffer);
643
+ pm_serialize_location(parser, &((pm_constant_write_node_t *)node)->operator_loc, buffer);
644
+ break;
645
+ }
646
+ case PM_DEF_NODE: {
647
+ // serialize length
648
+ // encoding of location u32s make us need to save this offset.
649
+ size_t length_offset = buffer->length;
650
+ pm_buffer_append_str(buffer, "\0\0\0\0", 4); /* consume 4 bytes, updated below */
651
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->name));
652
+ pm_serialize_location(parser, &((pm_def_node_t *)node)->name_loc, buffer);
653
+ if (((pm_def_node_t *)node)->receiver == NULL) {
654
+ pm_buffer_append_u8(buffer, 0);
655
+ } else {
656
+ pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->receiver, buffer);
657
+ }
658
+ if (((pm_def_node_t *)node)->parameters == NULL) {
659
+ pm_buffer_append_u8(buffer, 0);
660
+ } else {
661
+ pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->parameters, buffer);
662
+ }
663
+ if (((pm_def_node_t *)node)->body == NULL) {
664
+ pm_buffer_append_u8(buffer, 0);
665
+ } else {
666
+ pm_serialize_node(parser, (pm_node_t *)((pm_def_node_t *)node)->body, buffer);
667
+ }
668
+ uint32_t locals_size = pm_sizet_to_u32(((pm_def_node_t *)node)->locals.size);
669
+ pm_buffer_append_u32(buffer, locals_size);
670
+ for (uint32_t index = 0; index < locals_size; index++) {
671
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_def_node_t *)node)->locals.ids[index]));
672
+ }
673
+ pm_serialize_location(parser, &((pm_def_node_t *)node)->def_keyword_loc, buffer);
674
+ if (((pm_def_node_t *)node)->operator_loc.start == NULL) {
675
+ pm_buffer_append_u8(buffer, 0);
676
+ } else {
677
+ pm_buffer_append_u8(buffer, 1);
678
+ pm_serialize_location(parser, &((pm_def_node_t *)node)->operator_loc, buffer);
679
+ }
680
+ if (((pm_def_node_t *)node)->lparen_loc.start == NULL) {
681
+ pm_buffer_append_u8(buffer, 0);
682
+ } else {
683
+ pm_buffer_append_u8(buffer, 1);
684
+ pm_serialize_location(parser, &((pm_def_node_t *)node)->lparen_loc, buffer);
685
+ }
686
+ if (((pm_def_node_t *)node)->rparen_loc.start == NULL) {
687
+ pm_buffer_append_u8(buffer, 0);
688
+ } else {
689
+ pm_buffer_append_u8(buffer, 1);
690
+ pm_serialize_location(parser, &((pm_def_node_t *)node)->rparen_loc, buffer);
691
+ }
692
+ if (((pm_def_node_t *)node)->equal_loc.start == NULL) {
693
+ pm_buffer_append_u8(buffer, 0);
694
+ } else {
695
+ pm_buffer_append_u8(buffer, 1);
696
+ pm_serialize_location(parser, &((pm_def_node_t *)node)->equal_loc, buffer);
697
+ }
698
+ if (((pm_def_node_t *)node)->end_keyword_loc.start == NULL) {
699
+ pm_buffer_append_u8(buffer, 0);
700
+ } else {
701
+ pm_buffer_append_u8(buffer, 1);
702
+ pm_serialize_location(parser, &((pm_def_node_t *)node)->end_keyword_loc, buffer);
703
+ }
704
+ // serialize length
705
+ uint32_t length = pm_sizet_to_u32(buffer->length - offset - sizeof(uint32_t));
706
+ memcpy(buffer->value + length_offset, &length, sizeof(uint32_t));
707
+ break;
708
+ }
709
+ case PM_DEFINED_NODE: {
710
+ if (((pm_defined_node_t *)node)->lparen_loc.start == NULL) {
711
+ pm_buffer_append_u8(buffer, 0);
712
+ } else {
713
+ pm_buffer_append_u8(buffer, 1);
714
+ pm_serialize_location(parser, &((pm_defined_node_t *)node)->lparen_loc, buffer);
715
+ }
716
+ pm_serialize_node(parser, (pm_node_t *)((pm_defined_node_t *)node)->value, buffer);
717
+ if (((pm_defined_node_t *)node)->rparen_loc.start == NULL) {
718
+ pm_buffer_append_u8(buffer, 0);
719
+ } else {
720
+ pm_buffer_append_u8(buffer, 1);
721
+ pm_serialize_location(parser, &((pm_defined_node_t *)node)->rparen_loc, buffer);
722
+ }
723
+ pm_serialize_location(parser, &((pm_defined_node_t *)node)->keyword_loc, buffer);
724
+ break;
725
+ }
726
+ case PM_ELSE_NODE: {
727
+ pm_serialize_location(parser, &((pm_else_node_t *)node)->else_keyword_loc, buffer);
728
+ if (((pm_else_node_t *)node)->statements == NULL) {
729
+ pm_buffer_append_u8(buffer, 0);
730
+ } else {
731
+ pm_serialize_node(parser, (pm_node_t *)((pm_else_node_t *)node)->statements, buffer);
732
+ }
733
+ if (((pm_else_node_t *)node)->end_keyword_loc.start == NULL) {
734
+ pm_buffer_append_u8(buffer, 0);
735
+ } else {
736
+ pm_buffer_append_u8(buffer, 1);
737
+ pm_serialize_location(parser, &((pm_else_node_t *)node)->end_keyword_loc, buffer);
738
+ }
739
+ break;
740
+ }
741
+ case PM_EMBEDDED_STATEMENTS_NODE: {
742
+ pm_serialize_location(parser, &((pm_embedded_statements_node_t *)node)->opening_loc, buffer);
743
+ if (((pm_embedded_statements_node_t *)node)->statements == NULL) {
744
+ pm_buffer_append_u8(buffer, 0);
745
+ } else {
746
+ pm_serialize_node(parser, (pm_node_t *)((pm_embedded_statements_node_t *)node)->statements, buffer);
747
+ }
748
+ pm_serialize_location(parser, &((pm_embedded_statements_node_t *)node)->closing_loc, buffer);
749
+ break;
750
+ }
751
+ case PM_EMBEDDED_VARIABLE_NODE: {
752
+ pm_serialize_location(parser, &((pm_embedded_variable_node_t *)node)->operator_loc, buffer);
753
+ pm_serialize_node(parser, (pm_node_t *)((pm_embedded_variable_node_t *)node)->variable, buffer);
754
+ break;
755
+ }
756
+ case PM_ENSURE_NODE: {
757
+ pm_serialize_location(parser, &((pm_ensure_node_t *)node)->ensure_keyword_loc, buffer);
758
+ if (((pm_ensure_node_t *)node)->statements == NULL) {
759
+ pm_buffer_append_u8(buffer, 0);
760
+ } else {
761
+ pm_serialize_node(parser, (pm_node_t *)((pm_ensure_node_t *)node)->statements, buffer);
762
+ }
763
+ pm_serialize_location(parser, &((pm_ensure_node_t *)node)->end_keyword_loc, buffer);
764
+ break;
765
+ }
766
+ case PM_FALSE_NODE: {
767
+ break;
768
+ }
769
+ case PM_FIND_PATTERN_NODE: {
770
+ if (((pm_find_pattern_node_t *)node)->constant == NULL) {
771
+ pm_buffer_append_u8(buffer, 0);
772
+ } else {
773
+ pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->constant, buffer);
774
+ }
775
+ pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->left, buffer);
776
+ uint32_t requireds_size = pm_sizet_to_u32(((pm_find_pattern_node_t *)node)->requireds.size);
777
+ pm_buffer_append_u32(buffer, requireds_size);
778
+ for (uint32_t index = 0; index < requireds_size; index++) {
779
+ pm_serialize_node(parser, (pm_node_t *) ((pm_find_pattern_node_t *)node)->requireds.nodes[index], buffer);
780
+ }
781
+ pm_serialize_node(parser, (pm_node_t *)((pm_find_pattern_node_t *)node)->right, buffer);
782
+ if (((pm_find_pattern_node_t *)node)->opening_loc.start == NULL) {
783
+ pm_buffer_append_u8(buffer, 0);
784
+ } else {
785
+ pm_buffer_append_u8(buffer, 1);
786
+ pm_serialize_location(parser, &((pm_find_pattern_node_t *)node)->opening_loc, buffer);
787
+ }
788
+ if (((pm_find_pattern_node_t *)node)->closing_loc.start == NULL) {
789
+ pm_buffer_append_u8(buffer, 0);
790
+ } else {
791
+ pm_buffer_append_u8(buffer, 1);
792
+ pm_serialize_location(parser, &((pm_find_pattern_node_t *)node)->closing_loc, buffer);
793
+ }
794
+ break;
795
+ }
796
+ case PM_FLIP_FLOP_NODE: {
797
+ if (((pm_flip_flop_node_t *)node)->left == NULL) {
798
+ pm_buffer_append_u8(buffer, 0);
799
+ } else {
800
+ pm_serialize_node(parser, (pm_node_t *)((pm_flip_flop_node_t *)node)->left, buffer);
801
+ }
802
+ if (((pm_flip_flop_node_t *)node)->right == NULL) {
803
+ pm_buffer_append_u8(buffer, 0);
804
+ } else {
805
+ pm_serialize_node(parser, (pm_node_t *)((pm_flip_flop_node_t *)node)->right, buffer);
806
+ }
807
+ pm_serialize_location(parser, &((pm_flip_flop_node_t *)node)->operator_loc, buffer);
808
+ pm_buffer_append_u32(buffer, node->flags >> 2);
809
+ break;
810
+ }
811
+ case PM_FLOAT_NODE: {
812
+ break;
813
+ }
814
+ case PM_FOR_NODE: {
815
+ pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->index, buffer);
816
+ pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->collection, buffer);
817
+ if (((pm_for_node_t *)node)->statements == NULL) {
818
+ pm_buffer_append_u8(buffer, 0);
819
+ } else {
820
+ pm_serialize_node(parser, (pm_node_t *)((pm_for_node_t *)node)->statements, buffer);
821
+ }
822
+ pm_serialize_location(parser, &((pm_for_node_t *)node)->for_keyword_loc, buffer);
823
+ pm_serialize_location(parser, &((pm_for_node_t *)node)->in_keyword_loc, buffer);
824
+ if (((pm_for_node_t *)node)->do_keyword_loc.start == NULL) {
825
+ pm_buffer_append_u8(buffer, 0);
826
+ } else {
827
+ pm_buffer_append_u8(buffer, 1);
828
+ pm_serialize_location(parser, &((pm_for_node_t *)node)->do_keyword_loc, buffer);
829
+ }
830
+ pm_serialize_location(parser, &((pm_for_node_t *)node)->end_keyword_loc, buffer);
831
+ break;
832
+ }
833
+ case PM_FORWARDING_ARGUMENTS_NODE: {
834
+ break;
835
+ }
836
+ case PM_FORWARDING_PARAMETER_NODE: {
837
+ break;
838
+ }
839
+ case PM_FORWARDING_SUPER_NODE: {
840
+ if (((pm_forwarding_super_node_t *)node)->block == NULL) {
841
+ pm_buffer_append_u8(buffer, 0);
842
+ } else {
843
+ pm_serialize_node(parser, (pm_node_t *)((pm_forwarding_super_node_t *)node)->block, buffer);
844
+ }
845
+ break;
846
+ }
847
+ case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
848
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_global_variable_and_write_node_t *)node)->name));
849
+ pm_serialize_location(parser, &((pm_global_variable_and_write_node_t *)node)->name_loc, buffer);
850
+ pm_serialize_location(parser, &((pm_global_variable_and_write_node_t *)node)->operator_loc, buffer);
851
+ pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_and_write_node_t *)node)->value, buffer);
852
+ break;
853
+ }
854
+ case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
855
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->name));
856
+ pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->name_loc, buffer);
857
+ pm_serialize_location(parser, &((pm_global_variable_operator_write_node_t *)node)->operator_loc, buffer);
858
+ pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_operator_write_node_t *)node)->value, buffer);
859
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_global_variable_operator_write_node_t *)node)->operator));
860
+ break;
861
+ }
862
+ case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
863
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_global_variable_or_write_node_t *)node)->name));
864
+ pm_serialize_location(parser, &((pm_global_variable_or_write_node_t *)node)->name_loc, buffer);
865
+ pm_serialize_location(parser, &((pm_global_variable_or_write_node_t *)node)->operator_loc, buffer);
866
+ pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_or_write_node_t *)node)->value, buffer);
867
+ break;
868
+ }
869
+ case PM_GLOBAL_VARIABLE_READ_NODE: {
870
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_global_variable_read_node_t *)node)->name));
871
+ break;
872
+ }
873
+ case PM_GLOBAL_VARIABLE_TARGET_NODE: {
874
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_global_variable_target_node_t *)node)->name));
875
+ break;
876
+ }
877
+ case PM_GLOBAL_VARIABLE_WRITE_NODE: {
878
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_global_variable_write_node_t *)node)->name));
879
+ pm_serialize_location(parser, &((pm_global_variable_write_node_t *)node)->name_loc, buffer);
880
+ pm_serialize_node(parser, (pm_node_t *)((pm_global_variable_write_node_t *)node)->value, buffer);
881
+ pm_serialize_location(parser, &((pm_global_variable_write_node_t *)node)->operator_loc, buffer);
882
+ break;
883
+ }
884
+ case PM_HASH_NODE: {
885
+ pm_serialize_location(parser, &((pm_hash_node_t *)node)->opening_loc, buffer);
886
+ uint32_t elements_size = pm_sizet_to_u32(((pm_hash_node_t *)node)->elements.size);
887
+ pm_buffer_append_u32(buffer, elements_size);
888
+ for (uint32_t index = 0; index < elements_size; index++) {
889
+ pm_serialize_node(parser, (pm_node_t *) ((pm_hash_node_t *)node)->elements.nodes[index], buffer);
890
+ }
891
+ pm_serialize_location(parser, &((pm_hash_node_t *)node)->closing_loc, buffer);
892
+ break;
893
+ }
894
+ case PM_HASH_PATTERN_NODE: {
895
+ if (((pm_hash_pattern_node_t *)node)->constant == NULL) {
896
+ pm_buffer_append_u8(buffer, 0);
897
+ } else {
898
+ pm_serialize_node(parser, (pm_node_t *)((pm_hash_pattern_node_t *)node)->constant, buffer);
899
+ }
900
+ uint32_t assocs_size = pm_sizet_to_u32(((pm_hash_pattern_node_t *)node)->assocs.size);
901
+ pm_buffer_append_u32(buffer, assocs_size);
902
+ for (uint32_t index = 0; index < assocs_size; index++) {
903
+ pm_serialize_node(parser, (pm_node_t *) ((pm_hash_pattern_node_t *)node)->assocs.nodes[index], buffer);
904
+ }
905
+ if (((pm_hash_pattern_node_t *)node)->kwrest == NULL) {
906
+ pm_buffer_append_u8(buffer, 0);
907
+ } else {
908
+ pm_serialize_node(parser, (pm_node_t *)((pm_hash_pattern_node_t *)node)->kwrest, buffer);
909
+ }
910
+ if (((pm_hash_pattern_node_t *)node)->opening_loc.start == NULL) {
911
+ pm_buffer_append_u8(buffer, 0);
912
+ } else {
913
+ pm_buffer_append_u8(buffer, 1);
914
+ pm_serialize_location(parser, &((pm_hash_pattern_node_t *)node)->opening_loc, buffer);
915
+ }
916
+ if (((pm_hash_pattern_node_t *)node)->closing_loc.start == NULL) {
917
+ pm_buffer_append_u8(buffer, 0);
918
+ } else {
919
+ pm_buffer_append_u8(buffer, 1);
920
+ pm_serialize_location(parser, &((pm_hash_pattern_node_t *)node)->closing_loc, buffer);
921
+ }
922
+ break;
923
+ }
924
+ case PM_IF_NODE: {
925
+ if (((pm_if_node_t *)node)->if_keyword_loc.start == NULL) {
926
+ pm_buffer_append_u8(buffer, 0);
927
+ } else {
928
+ pm_buffer_append_u8(buffer, 1);
929
+ pm_serialize_location(parser, &((pm_if_node_t *)node)->if_keyword_loc, buffer);
930
+ }
931
+ pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->predicate, buffer);
932
+ if (((pm_if_node_t *)node)->statements == NULL) {
933
+ pm_buffer_append_u8(buffer, 0);
934
+ } else {
935
+ pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->statements, buffer);
936
+ }
937
+ if (((pm_if_node_t *)node)->consequent == NULL) {
938
+ pm_buffer_append_u8(buffer, 0);
939
+ } else {
940
+ pm_serialize_node(parser, (pm_node_t *)((pm_if_node_t *)node)->consequent, buffer);
941
+ }
942
+ if (((pm_if_node_t *)node)->end_keyword_loc.start == NULL) {
943
+ pm_buffer_append_u8(buffer, 0);
944
+ } else {
945
+ pm_buffer_append_u8(buffer, 1);
946
+ pm_serialize_location(parser, &((pm_if_node_t *)node)->end_keyword_loc, buffer);
947
+ }
948
+ break;
949
+ }
950
+ case PM_IMAGINARY_NODE: {
951
+ pm_serialize_node(parser, (pm_node_t *)((pm_imaginary_node_t *)node)->numeric, buffer);
952
+ break;
953
+ }
954
+ case PM_IMPLICIT_NODE: {
955
+ pm_serialize_node(parser, (pm_node_t *)((pm_implicit_node_t *)node)->value, buffer);
956
+ break;
957
+ }
958
+ case PM_IN_NODE: {
959
+ pm_serialize_node(parser, (pm_node_t *)((pm_in_node_t *)node)->pattern, buffer);
960
+ if (((pm_in_node_t *)node)->statements == NULL) {
961
+ pm_buffer_append_u8(buffer, 0);
962
+ } else {
963
+ pm_serialize_node(parser, (pm_node_t *)((pm_in_node_t *)node)->statements, buffer);
964
+ }
965
+ pm_serialize_location(parser, &((pm_in_node_t *)node)->in_loc, buffer);
966
+ if (((pm_in_node_t *)node)->then_loc.start == NULL) {
967
+ pm_buffer_append_u8(buffer, 0);
968
+ } else {
969
+ pm_buffer_append_u8(buffer, 1);
970
+ pm_serialize_location(parser, &((pm_in_node_t *)node)->then_loc, buffer);
971
+ }
972
+ break;
973
+ }
974
+ case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
975
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_instance_variable_and_write_node_t *)node)->name));
976
+ pm_serialize_location(parser, &((pm_instance_variable_and_write_node_t *)node)->name_loc, buffer);
977
+ pm_serialize_location(parser, &((pm_instance_variable_and_write_node_t *)node)->operator_loc, buffer);
978
+ pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_and_write_node_t *)node)->value, buffer);
979
+ break;
980
+ }
981
+ case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
982
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->name));
983
+ pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->name_loc, buffer);
984
+ pm_serialize_location(parser, &((pm_instance_variable_operator_write_node_t *)node)->operator_loc, buffer);
985
+ pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_operator_write_node_t *)node)->value, buffer);
986
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_instance_variable_operator_write_node_t *)node)->operator));
987
+ break;
988
+ }
989
+ case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
990
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_instance_variable_or_write_node_t *)node)->name));
991
+ pm_serialize_location(parser, &((pm_instance_variable_or_write_node_t *)node)->name_loc, buffer);
992
+ pm_serialize_location(parser, &((pm_instance_variable_or_write_node_t *)node)->operator_loc, buffer);
993
+ pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_or_write_node_t *)node)->value, buffer);
994
+ break;
995
+ }
996
+ case PM_INSTANCE_VARIABLE_READ_NODE: {
997
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_instance_variable_read_node_t *)node)->name));
998
+ break;
999
+ }
1000
+ case PM_INSTANCE_VARIABLE_TARGET_NODE: {
1001
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_instance_variable_target_node_t *)node)->name));
1002
+ break;
1003
+ }
1004
+ case PM_INSTANCE_VARIABLE_WRITE_NODE: {
1005
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_instance_variable_write_node_t *)node)->name));
1006
+ pm_serialize_location(parser, &((pm_instance_variable_write_node_t *)node)->name_loc, buffer);
1007
+ pm_serialize_node(parser, (pm_node_t *)((pm_instance_variable_write_node_t *)node)->value, buffer);
1008
+ pm_serialize_location(parser, &((pm_instance_variable_write_node_t *)node)->operator_loc, buffer);
1009
+ break;
1010
+ }
1011
+ case PM_INTEGER_NODE: {
1012
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1013
+ break;
1014
+ }
1015
+ case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
1016
+ pm_serialize_location(parser, &((pm_interpolated_match_last_line_node_t *)node)->opening_loc, buffer);
1017
+ uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_match_last_line_node_t *)node)->parts.size);
1018
+ pm_buffer_append_u32(buffer, parts_size);
1019
+ for (uint32_t index = 0; index < parts_size; index++) {
1020
+ pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_match_last_line_node_t *)node)->parts.nodes[index], buffer);
1021
+ }
1022
+ pm_serialize_location(parser, &((pm_interpolated_match_last_line_node_t *)node)->closing_loc, buffer);
1023
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1024
+ break;
1025
+ }
1026
+ case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
1027
+ pm_serialize_location(parser, &((pm_interpolated_regular_expression_node_t *)node)->opening_loc, buffer);
1028
+ uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_regular_expression_node_t *)node)->parts.size);
1029
+ pm_buffer_append_u32(buffer, parts_size);
1030
+ for (uint32_t index = 0; index < parts_size; index++) {
1031
+ pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_regular_expression_node_t *)node)->parts.nodes[index], buffer);
1032
+ }
1033
+ pm_serialize_location(parser, &((pm_interpolated_regular_expression_node_t *)node)->closing_loc, buffer);
1034
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1035
+ break;
1036
+ }
1037
+ case PM_INTERPOLATED_STRING_NODE: {
1038
+ if (((pm_interpolated_string_node_t *)node)->opening_loc.start == NULL) {
1039
+ pm_buffer_append_u8(buffer, 0);
1040
+ } else {
1041
+ pm_buffer_append_u8(buffer, 1);
1042
+ pm_serialize_location(parser, &((pm_interpolated_string_node_t *)node)->opening_loc, buffer);
1043
+ }
1044
+ uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_string_node_t *)node)->parts.size);
1045
+ pm_buffer_append_u32(buffer, parts_size);
1046
+ for (uint32_t index = 0; index < parts_size; index++) {
1047
+ pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_string_node_t *)node)->parts.nodes[index], buffer);
1048
+ }
1049
+ if (((pm_interpolated_string_node_t *)node)->closing_loc.start == NULL) {
1050
+ pm_buffer_append_u8(buffer, 0);
1051
+ } else {
1052
+ pm_buffer_append_u8(buffer, 1);
1053
+ pm_serialize_location(parser, &((pm_interpolated_string_node_t *)node)->closing_loc, buffer);
1054
+ }
1055
+ break;
1056
+ }
1057
+ case PM_INTERPOLATED_SYMBOL_NODE: {
1058
+ if (((pm_interpolated_symbol_node_t *)node)->opening_loc.start == NULL) {
1059
+ pm_buffer_append_u8(buffer, 0);
1060
+ } else {
1061
+ pm_buffer_append_u8(buffer, 1);
1062
+ pm_serialize_location(parser, &((pm_interpolated_symbol_node_t *)node)->opening_loc, buffer);
1063
+ }
1064
+ uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_symbol_node_t *)node)->parts.size);
1065
+ pm_buffer_append_u32(buffer, parts_size);
1066
+ for (uint32_t index = 0; index < parts_size; index++) {
1067
+ pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_symbol_node_t *)node)->parts.nodes[index], buffer);
1068
+ }
1069
+ if (((pm_interpolated_symbol_node_t *)node)->closing_loc.start == NULL) {
1070
+ pm_buffer_append_u8(buffer, 0);
1071
+ } else {
1072
+ pm_buffer_append_u8(buffer, 1);
1073
+ pm_serialize_location(parser, &((pm_interpolated_symbol_node_t *)node)->closing_loc, buffer);
1074
+ }
1075
+ break;
1076
+ }
1077
+ case PM_INTERPOLATED_X_STRING_NODE: {
1078
+ pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->opening_loc, buffer);
1079
+ uint32_t parts_size = pm_sizet_to_u32(((pm_interpolated_x_string_node_t *)node)->parts.size);
1080
+ pm_buffer_append_u32(buffer, parts_size);
1081
+ for (uint32_t index = 0; index < parts_size; index++) {
1082
+ pm_serialize_node(parser, (pm_node_t *) ((pm_interpolated_x_string_node_t *)node)->parts.nodes[index], buffer);
1083
+ }
1084
+ pm_serialize_location(parser, &((pm_interpolated_x_string_node_t *)node)->closing_loc, buffer);
1085
+ break;
1086
+ }
1087
+ case PM_KEYWORD_HASH_NODE: {
1088
+ uint32_t elements_size = pm_sizet_to_u32(((pm_keyword_hash_node_t *)node)->elements.size);
1089
+ pm_buffer_append_u32(buffer, elements_size);
1090
+ for (uint32_t index = 0; index < elements_size; index++) {
1091
+ pm_serialize_node(parser, (pm_node_t *) ((pm_keyword_hash_node_t *)node)->elements.nodes[index], buffer);
1092
+ }
1093
+ break;
1094
+ }
1095
+ case PM_KEYWORD_PARAMETER_NODE: {
1096
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_keyword_parameter_node_t *)node)->name));
1097
+ pm_serialize_location(parser, &((pm_keyword_parameter_node_t *)node)->name_loc, buffer);
1098
+ if (((pm_keyword_parameter_node_t *)node)->value == NULL) {
1099
+ pm_buffer_append_u8(buffer, 0);
1100
+ } else {
1101
+ pm_serialize_node(parser, (pm_node_t *)((pm_keyword_parameter_node_t *)node)->value, buffer);
1102
+ }
1103
+ break;
1104
+ }
1105
+ case PM_KEYWORD_REST_PARAMETER_NODE: {
1106
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_keyword_rest_parameter_node_t *)node)->name));
1107
+ if (((pm_keyword_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1108
+ pm_buffer_append_u8(buffer, 0);
1109
+ } else {
1110
+ pm_buffer_append_u8(buffer, 1);
1111
+ pm_serialize_location(parser, &((pm_keyword_rest_parameter_node_t *)node)->name_loc, buffer);
1112
+ }
1113
+ pm_serialize_location(parser, &((pm_keyword_rest_parameter_node_t *)node)->operator_loc, buffer);
1114
+ break;
1115
+ }
1116
+ case PM_LAMBDA_NODE: {
1117
+ uint32_t locals_size = pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.size);
1118
+ pm_buffer_append_u32(buffer, locals_size);
1119
+ for (uint32_t index = 0; index < locals_size; index++) {
1120
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_lambda_node_t *)node)->locals.ids[index]));
1121
+ }
1122
+ pm_serialize_location(parser, &((pm_lambda_node_t *)node)->operator_loc, buffer);
1123
+ pm_serialize_location(parser, &((pm_lambda_node_t *)node)->opening_loc, buffer);
1124
+ pm_serialize_location(parser, &((pm_lambda_node_t *)node)->closing_loc, buffer);
1125
+ if (((pm_lambda_node_t *)node)->parameters == NULL) {
1126
+ pm_buffer_append_u8(buffer, 0);
1127
+ } else {
1128
+ pm_serialize_node(parser, (pm_node_t *)((pm_lambda_node_t *)node)->parameters, buffer);
1129
+ }
1130
+ if (((pm_lambda_node_t *)node)->body == NULL) {
1131
+ pm_buffer_append_u8(buffer, 0);
1132
+ } else {
1133
+ pm_serialize_node(parser, (pm_node_t *)((pm_lambda_node_t *)node)->body, buffer);
1134
+ }
1135
+ break;
1136
+ }
1137
+ case PM_LOCAL_VARIABLE_AND_WRITE_NODE: {
1138
+ pm_serialize_location(parser, &((pm_local_variable_and_write_node_t *)node)->name_loc, buffer);
1139
+ pm_serialize_location(parser, &((pm_local_variable_and_write_node_t *)node)->operator_loc, buffer);
1140
+ pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_and_write_node_t *)node)->value, buffer);
1141
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_local_variable_and_write_node_t *)node)->name));
1142
+ pm_buffer_append_u32(buffer, ((pm_local_variable_and_write_node_t *)node)->depth);
1143
+ break;
1144
+ }
1145
+ case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
1146
+ pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->name_loc, buffer);
1147
+ pm_serialize_location(parser, &((pm_local_variable_operator_write_node_t *)node)->operator_loc, buffer);
1148
+ pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_operator_write_node_t *)node)->value, buffer);
1149
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->name));
1150
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_local_variable_operator_write_node_t *)node)->operator));
1151
+ pm_buffer_append_u32(buffer, ((pm_local_variable_operator_write_node_t *)node)->depth);
1152
+ break;
1153
+ }
1154
+ case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
1155
+ pm_serialize_location(parser, &((pm_local_variable_or_write_node_t *)node)->name_loc, buffer);
1156
+ pm_serialize_location(parser, &((pm_local_variable_or_write_node_t *)node)->operator_loc, buffer);
1157
+ pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_or_write_node_t *)node)->value, buffer);
1158
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_local_variable_or_write_node_t *)node)->name));
1159
+ pm_buffer_append_u32(buffer, ((pm_local_variable_or_write_node_t *)node)->depth);
1160
+ break;
1161
+ }
1162
+ case PM_LOCAL_VARIABLE_READ_NODE: {
1163
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_local_variable_read_node_t *)node)->name));
1164
+ pm_buffer_append_u32(buffer, ((pm_local_variable_read_node_t *)node)->depth);
1165
+ break;
1166
+ }
1167
+ case PM_LOCAL_VARIABLE_TARGET_NODE: {
1168
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_local_variable_target_node_t *)node)->name));
1169
+ pm_buffer_append_u32(buffer, ((pm_local_variable_target_node_t *)node)->depth);
1170
+ break;
1171
+ }
1172
+ case PM_LOCAL_VARIABLE_WRITE_NODE: {
1173
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_local_variable_write_node_t *)node)->name));
1174
+ pm_buffer_append_u32(buffer, ((pm_local_variable_write_node_t *)node)->depth);
1175
+ pm_serialize_location(parser, &((pm_local_variable_write_node_t *)node)->name_loc, buffer);
1176
+ pm_serialize_node(parser, (pm_node_t *)((pm_local_variable_write_node_t *)node)->value, buffer);
1177
+ pm_serialize_location(parser, &((pm_local_variable_write_node_t *)node)->operator_loc, buffer);
1178
+ break;
1179
+ }
1180
+ case PM_MATCH_LAST_LINE_NODE: {
1181
+ pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->opening_loc, buffer);
1182
+ pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->content_loc, buffer);
1183
+ pm_serialize_location(parser, &((pm_match_last_line_node_t *)node)->closing_loc, buffer);
1184
+ pm_serialize_string(parser, &((pm_match_last_line_node_t *)node)->unescaped, buffer);
1185
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1186
+ break;
1187
+ }
1188
+ case PM_MATCH_PREDICATE_NODE: {
1189
+ pm_serialize_node(parser, (pm_node_t *)((pm_match_predicate_node_t *)node)->value, buffer);
1190
+ pm_serialize_node(parser, (pm_node_t *)((pm_match_predicate_node_t *)node)->pattern, buffer);
1191
+ pm_serialize_location(parser, &((pm_match_predicate_node_t *)node)->operator_loc, buffer);
1192
+ break;
1193
+ }
1194
+ case PM_MATCH_REQUIRED_NODE: {
1195
+ pm_serialize_node(parser, (pm_node_t *)((pm_match_required_node_t *)node)->value, buffer);
1196
+ pm_serialize_node(parser, (pm_node_t *)((pm_match_required_node_t *)node)->pattern, buffer);
1197
+ pm_serialize_location(parser, &((pm_match_required_node_t *)node)->operator_loc, buffer);
1198
+ break;
1199
+ }
1200
+ case PM_MATCH_WRITE_NODE: {
1201
+ pm_serialize_node(parser, (pm_node_t *)((pm_match_write_node_t *)node)->call, buffer);
1202
+ uint32_t locals_size = pm_sizet_to_u32(((pm_match_write_node_t *)node)->locals.size);
1203
+ pm_buffer_append_u32(buffer, locals_size);
1204
+ for (uint32_t index = 0; index < locals_size; index++) {
1205
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_match_write_node_t *)node)->locals.ids[index]));
1206
+ }
1207
+ break;
1208
+ }
1209
+ case PM_MISSING_NODE: {
1210
+ break;
1211
+ }
1212
+ case PM_MODULE_NODE: {
1213
+ uint32_t locals_size = pm_sizet_to_u32(((pm_module_node_t *)node)->locals.size);
1214
+ pm_buffer_append_u32(buffer, locals_size);
1215
+ for (uint32_t index = 0; index < locals_size; index++) {
1216
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->locals.ids[index]));
1217
+ }
1218
+ pm_serialize_location(parser, &((pm_module_node_t *)node)->module_keyword_loc, buffer);
1219
+ pm_serialize_node(parser, (pm_node_t *)((pm_module_node_t *)node)->constant_path, buffer);
1220
+ if (((pm_module_node_t *)node)->body == NULL) {
1221
+ pm_buffer_append_u8(buffer, 0);
1222
+ } else {
1223
+ pm_serialize_node(parser, (pm_node_t *)((pm_module_node_t *)node)->body, buffer);
1224
+ }
1225
+ pm_serialize_location(parser, &((pm_module_node_t *)node)->end_keyword_loc, buffer);
1226
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_module_node_t *)node)->name));
1227
+ break;
1228
+ }
1229
+ case PM_MULTI_TARGET_NODE: {
1230
+ uint32_t targets_size = pm_sizet_to_u32(((pm_multi_target_node_t *)node)->targets.size);
1231
+ pm_buffer_append_u32(buffer, targets_size);
1232
+ for (uint32_t index = 0; index < targets_size; index++) {
1233
+ pm_serialize_node(parser, (pm_node_t *) ((pm_multi_target_node_t *)node)->targets.nodes[index], buffer);
1234
+ }
1235
+ if (((pm_multi_target_node_t *)node)->lparen_loc.start == NULL) {
1236
+ pm_buffer_append_u8(buffer, 0);
1237
+ } else {
1238
+ pm_buffer_append_u8(buffer, 1);
1239
+ pm_serialize_location(parser, &((pm_multi_target_node_t *)node)->lparen_loc, buffer);
1240
+ }
1241
+ if (((pm_multi_target_node_t *)node)->rparen_loc.start == NULL) {
1242
+ pm_buffer_append_u8(buffer, 0);
1243
+ } else {
1244
+ pm_buffer_append_u8(buffer, 1);
1245
+ pm_serialize_location(parser, &((pm_multi_target_node_t *)node)->rparen_loc, buffer);
1246
+ }
1247
+ break;
1248
+ }
1249
+ case PM_MULTI_WRITE_NODE: {
1250
+ uint32_t targets_size = pm_sizet_to_u32(((pm_multi_write_node_t *)node)->targets.size);
1251
+ pm_buffer_append_u32(buffer, targets_size);
1252
+ for (uint32_t index = 0; index < targets_size; index++) {
1253
+ pm_serialize_node(parser, (pm_node_t *) ((pm_multi_write_node_t *)node)->targets.nodes[index], buffer);
1254
+ }
1255
+ if (((pm_multi_write_node_t *)node)->lparen_loc.start == NULL) {
1256
+ pm_buffer_append_u8(buffer, 0);
1257
+ } else {
1258
+ pm_buffer_append_u8(buffer, 1);
1259
+ pm_serialize_location(parser, &((pm_multi_write_node_t *)node)->lparen_loc, buffer);
1260
+ }
1261
+ if (((pm_multi_write_node_t *)node)->rparen_loc.start == NULL) {
1262
+ pm_buffer_append_u8(buffer, 0);
1263
+ } else {
1264
+ pm_buffer_append_u8(buffer, 1);
1265
+ pm_serialize_location(parser, &((pm_multi_write_node_t *)node)->rparen_loc, buffer);
1266
+ }
1267
+ pm_serialize_location(parser, &((pm_multi_write_node_t *)node)->operator_loc, buffer);
1268
+ pm_serialize_node(parser, (pm_node_t *)((pm_multi_write_node_t *)node)->value, buffer);
1269
+ break;
1270
+ }
1271
+ case PM_NEXT_NODE: {
1272
+ if (((pm_next_node_t *)node)->arguments == NULL) {
1273
+ pm_buffer_append_u8(buffer, 0);
1274
+ } else {
1275
+ pm_serialize_node(parser, (pm_node_t *)((pm_next_node_t *)node)->arguments, buffer);
1276
+ }
1277
+ pm_serialize_location(parser, &((pm_next_node_t *)node)->keyword_loc, buffer);
1278
+ break;
1279
+ }
1280
+ case PM_NIL_NODE: {
1281
+ break;
1282
+ }
1283
+ case PM_NO_KEYWORDS_PARAMETER_NODE: {
1284
+ pm_serialize_location(parser, &((pm_no_keywords_parameter_node_t *)node)->operator_loc, buffer);
1285
+ pm_serialize_location(parser, &((pm_no_keywords_parameter_node_t *)node)->keyword_loc, buffer);
1286
+ break;
1287
+ }
1288
+ case PM_NUMBERED_REFERENCE_READ_NODE: {
1289
+ pm_buffer_append_u32(buffer, ((pm_numbered_reference_read_node_t *)node)->number);
1290
+ break;
1291
+ }
1292
+ case PM_OPTIONAL_PARAMETER_NODE: {
1293
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_optional_parameter_node_t *)node)->name));
1294
+ pm_serialize_location(parser, &((pm_optional_parameter_node_t *)node)->name_loc, buffer);
1295
+ pm_serialize_location(parser, &((pm_optional_parameter_node_t *)node)->operator_loc, buffer);
1296
+ pm_serialize_node(parser, (pm_node_t *)((pm_optional_parameter_node_t *)node)->value, buffer);
1297
+ break;
1298
+ }
1299
+ case PM_OR_NODE: {
1300
+ pm_serialize_node(parser, (pm_node_t *)((pm_or_node_t *)node)->left, buffer);
1301
+ pm_serialize_node(parser, (pm_node_t *)((pm_or_node_t *)node)->right, buffer);
1302
+ pm_serialize_location(parser, &((pm_or_node_t *)node)->operator_loc, buffer);
1303
+ break;
1304
+ }
1305
+ case PM_PARAMETERS_NODE: {
1306
+ uint32_t requireds_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->requireds.size);
1307
+ pm_buffer_append_u32(buffer, requireds_size);
1308
+ for (uint32_t index = 0; index < requireds_size; index++) {
1309
+ pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->requireds.nodes[index], buffer);
1310
+ }
1311
+ uint32_t optionals_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->optionals.size);
1312
+ pm_buffer_append_u32(buffer, optionals_size);
1313
+ for (uint32_t index = 0; index < optionals_size; index++) {
1314
+ pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->optionals.nodes[index], buffer);
1315
+ }
1316
+ if (((pm_parameters_node_t *)node)->rest == NULL) {
1317
+ pm_buffer_append_u8(buffer, 0);
1318
+ } else {
1319
+ pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->rest, buffer);
1320
+ }
1321
+ uint32_t posts_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->posts.size);
1322
+ pm_buffer_append_u32(buffer, posts_size);
1323
+ for (uint32_t index = 0; index < posts_size; index++) {
1324
+ pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->posts.nodes[index], buffer);
1325
+ }
1326
+ uint32_t keywords_size = pm_sizet_to_u32(((pm_parameters_node_t *)node)->keywords.size);
1327
+ pm_buffer_append_u32(buffer, keywords_size);
1328
+ for (uint32_t index = 0; index < keywords_size; index++) {
1329
+ pm_serialize_node(parser, (pm_node_t *) ((pm_parameters_node_t *)node)->keywords.nodes[index], buffer);
1330
+ }
1331
+ if (((pm_parameters_node_t *)node)->keyword_rest == NULL) {
1332
+ pm_buffer_append_u8(buffer, 0);
1333
+ } else {
1334
+ pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->keyword_rest, buffer);
1335
+ }
1336
+ if (((pm_parameters_node_t *)node)->block == NULL) {
1337
+ pm_buffer_append_u8(buffer, 0);
1338
+ } else {
1339
+ pm_serialize_node(parser, (pm_node_t *)((pm_parameters_node_t *)node)->block, buffer);
1340
+ }
1341
+ break;
1342
+ }
1343
+ case PM_PARENTHESES_NODE: {
1344
+ if (((pm_parentheses_node_t *)node)->body == NULL) {
1345
+ pm_buffer_append_u8(buffer, 0);
1346
+ } else {
1347
+ pm_serialize_node(parser, (pm_node_t *)((pm_parentheses_node_t *)node)->body, buffer);
1348
+ }
1349
+ pm_serialize_location(parser, &((pm_parentheses_node_t *)node)->opening_loc, buffer);
1350
+ pm_serialize_location(parser, &((pm_parentheses_node_t *)node)->closing_loc, buffer);
1351
+ break;
1352
+ }
1353
+ case PM_PINNED_EXPRESSION_NODE: {
1354
+ pm_serialize_node(parser, (pm_node_t *)((pm_pinned_expression_node_t *)node)->expression, buffer);
1355
+ pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->operator_loc, buffer);
1356
+ pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->lparen_loc, buffer);
1357
+ pm_serialize_location(parser, &((pm_pinned_expression_node_t *)node)->rparen_loc, buffer);
1358
+ break;
1359
+ }
1360
+ case PM_PINNED_VARIABLE_NODE: {
1361
+ pm_serialize_node(parser, (pm_node_t *)((pm_pinned_variable_node_t *)node)->variable, buffer);
1362
+ pm_serialize_location(parser, &((pm_pinned_variable_node_t *)node)->operator_loc, buffer);
1363
+ break;
1364
+ }
1365
+ case PM_POST_EXECUTION_NODE: {
1366
+ if (((pm_post_execution_node_t *)node)->statements == NULL) {
1367
+ pm_buffer_append_u8(buffer, 0);
1368
+ } else {
1369
+ pm_serialize_node(parser, (pm_node_t *)((pm_post_execution_node_t *)node)->statements, buffer);
1370
+ }
1371
+ pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->keyword_loc, buffer);
1372
+ pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->opening_loc, buffer);
1373
+ pm_serialize_location(parser, &((pm_post_execution_node_t *)node)->closing_loc, buffer);
1374
+ break;
1375
+ }
1376
+ case PM_PRE_EXECUTION_NODE: {
1377
+ if (((pm_pre_execution_node_t *)node)->statements == NULL) {
1378
+ pm_buffer_append_u8(buffer, 0);
1379
+ } else {
1380
+ pm_serialize_node(parser, (pm_node_t *)((pm_pre_execution_node_t *)node)->statements, buffer);
1381
+ }
1382
+ pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->keyword_loc, buffer);
1383
+ pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->opening_loc, buffer);
1384
+ pm_serialize_location(parser, &((pm_pre_execution_node_t *)node)->closing_loc, buffer);
1385
+ break;
1386
+ }
1387
+ case PM_PROGRAM_NODE: {
1388
+ uint32_t locals_size = pm_sizet_to_u32(((pm_program_node_t *)node)->locals.size);
1389
+ pm_buffer_append_u32(buffer, locals_size);
1390
+ for (uint32_t index = 0; index < locals_size; index++) {
1391
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_program_node_t *)node)->locals.ids[index]));
1392
+ }
1393
+ pm_serialize_node(parser, (pm_node_t *)((pm_program_node_t *)node)->statements, buffer);
1394
+ break;
1395
+ }
1396
+ case PM_RANGE_NODE: {
1397
+ if (((pm_range_node_t *)node)->left == NULL) {
1398
+ pm_buffer_append_u8(buffer, 0);
1399
+ } else {
1400
+ pm_serialize_node(parser, (pm_node_t *)((pm_range_node_t *)node)->left, buffer);
1401
+ }
1402
+ if (((pm_range_node_t *)node)->right == NULL) {
1403
+ pm_buffer_append_u8(buffer, 0);
1404
+ } else {
1405
+ pm_serialize_node(parser, (pm_node_t *)((pm_range_node_t *)node)->right, buffer);
1406
+ }
1407
+ pm_serialize_location(parser, &((pm_range_node_t *)node)->operator_loc, buffer);
1408
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1409
+ break;
1410
+ }
1411
+ case PM_RATIONAL_NODE: {
1412
+ pm_serialize_node(parser, (pm_node_t *)((pm_rational_node_t *)node)->numeric, buffer);
1413
+ break;
1414
+ }
1415
+ case PM_REDO_NODE: {
1416
+ break;
1417
+ }
1418
+ case PM_REGULAR_EXPRESSION_NODE: {
1419
+ pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->opening_loc, buffer);
1420
+ pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->content_loc, buffer);
1421
+ pm_serialize_location(parser, &((pm_regular_expression_node_t *)node)->closing_loc, buffer);
1422
+ pm_serialize_string(parser, &((pm_regular_expression_node_t *)node)->unescaped, buffer);
1423
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1424
+ break;
1425
+ }
1426
+ case PM_REQUIRED_DESTRUCTURED_PARAMETER_NODE: {
1427
+ uint32_t parameters_size = pm_sizet_to_u32(((pm_required_destructured_parameter_node_t *)node)->parameters.size);
1428
+ pm_buffer_append_u32(buffer, parameters_size);
1429
+ for (uint32_t index = 0; index < parameters_size; index++) {
1430
+ pm_serialize_node(parser, (pm_node_t *) ((pm_required_destructured_parameter_node_t *)node)->parameters.nodes[index], buffer);
1431
+ }
1432
+ pm_serialize_location(parser, &((pm_required_destructured_parameter_node_t *)node)->opening_loc, buffer);
1433
+ pm_serialize_location(parser, &((pm_required_destructured_parameter_node_t *)node)->closing_loc, buffer);
1434
+ break;
1435
+ }
1436
+ case PM_REQUIRED_PARAMETER_NODE: {
1437
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_required_parameter_node_t *)node)->name));
1438
+ break;
1439
+ }
1440
+ case PM_RESCUE_MODIFIER_NODE: {
1441
+ pm_serialize_node(parser, (pm_node_t *)((pm_rescue_modifier_node_t *)node)->expression, buffer);
1442
+ pm_serialize_location(parser, &((pm_rescue_modifier_node_t *)node)->keyword_loc, buffer);
1443
+ pm_serialize_node(parser, (pm_node_t *)((pm_rescue_modifier_node_t *)node)->rescue_expression, buffer);
1444
+ break;
1445
+ }
1446
+ case PM_RESCUE_NODE: {
1447
+ pm_serialize_location(parser, &((pm_rescue_node_t *)node)->keyword_loc, buffer);
1448
+ uint32_t exceptions_size = pm_sizet_to_u32(((pm_rescue_node_t *)node)->exceptions.size);
1449
+ pm_buffer_append_u32(buffer, exceptions_size);
1450
+ for (uint32_t index = 0; index < exceptions_size; index++) {
1451
+ pm_serialize_node(parser, (pm_node_t *) ((pm_rescue_node_t *)node)->exceptions.nodes[index], buffer);
1452
+ }
1453
+ if (((pm_rescue_node_t *)node)->operator_loc.start == NULL) {
1454
+ pm_buffer_append_u8(buffer, 0);
1455
+ } else {
1456
+ pm_buffer_append_u8(buffer, 1);
1457
+ pm_serialize_location(parser, &((pm_rescue_node_t *)node)->operator_loc, buffer);
1458
+ }
1459
+ if (((pm_rescue_node_t *)node)->reference == NULL) {
1460
+ pm_buffer_append_u8(buffer, 0);
1461
+ } else {
1462
+ pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->reference, buffer);
1463
+ }
1464
+ if (((pm_rescue_node_t *)node)->statements == NULL) {
1465
+ pm_buffer_append_u8(buffer, 0);
1466
+ } else {
1467
+ pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->statements, buffer);
1468
+ }
1469
+ if (((pm_rescue_node_t *)node)->consequent == NULL) {
1470
+ pm_buffer_append_u8(buffer, 0);
1471
+ } else {
1472
+ pm_serialize_node(parser, (pm_node_t *)((pm_rescue_node_t *)node)->consequent, buffer);
1473
+ }
1474
+ break;
1475
+ }
1476
+ case PM_REST_PARAMETER_NODE: {
1477
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_rest_parameter_node_t *)node)->name));
1478
+ if (((pm_rest_parameter_node_t *)node)->name_loc.start == NULL) {
1479
+ pm_buffer_append_u8(buffer, 0);
1480
+ } else {
1481
+ pm_buffer_append_u8(buffer, 1);
1482
+ pm_serialize_location(parser, &((pm_rest_parameter_node_t *)node)->name_loc, buffer);
1483
+ }
1484
+ pm_serialize_location(parser, &((pm_rest_parameter_node_t *)node)->operator_loc, buffer);
1485
+ break;
1486
+ }
1487
+ case PM_RETRY_NODE: {
1488
+ break;
1489
+ }
1490
+ case PM_RETURN_NODE: {
1491
+ pm_serialize_location(parser, &((pm_return_node_t *)node)->keyword_loc, buffer);
1492
+ if (((pm_return_node_t *)node)->arguments == NULL) {
1493
+ pm_buffer_append_u8(buffer, 0);
1494
+ } else {
1495
+ pm_serialize_node(parser, (pm_node_t *)((pm_return_node_t *)node)->arguments, buffer);
1496
+ }
1497
+ break;
1498
+ }
1499
+ case PM_SELF_NODE: {
1500
+ break;
1501
+ }
1502
+ case PM_SINGLETON_CLASS_NODE: {
1503
+ uint32_t locals_size = pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.size);
1504
+ pm_buffer_append_u32(buffer, locals_size);
1505
+ for (uint32_t index = 0; index < locals_size; index++) {
1506
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(((pm_singleton_class_node_t *)node)->locals.ids[index]));
1507
+ }
1508
+ pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->class_keyword_loc, buffer);
1509
+ pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->operator_loc, buffer);
1510
+ pm_serialize_node(parser, (pm_node_t *)((pm_singleton_class_node_t *)node)->expression, buffer);
1511
+ if (((pm_singleton_class_node_t *)node)->body == NULL) {
1512
+ pm_buffer_append_u8(buffer, 0);
1513
+ } else {
1514
+ pm_serialize_node(parser, (pm_node_t *)((pm_singleton_class_node_t *)node)->body, buffer);
1515
+ }
1516
+ pm_serialize_location(parser, &((pm_singleton_class_node_t *)node)->end_keyword_loc, buffer);
1517
+ break;
1518
+ }
1519
+ case PM_SOURCE_ENCODING_NODE: {
1520
+ break;
1521
+ }
1522
+ case PM_SOURCE_FILE_NODE: {
1523
+ pm_serialize_string(parser, &((pm_source_file_node_t *)node)->filepath, buffer);
1524
+ break;
1525
+ }
1526
+ case PM_SOURCE_LINE_NODE: {
1527
+ break;
1528
+ }
1529
+ case PM_SPLAT_NODE: {
1530
+ pm_serialize_location(parser, &((pm_splat_node_t *)node)->operator_loc, buffer);
1531
+ if (((pm_splat_node_t *)node)->expression == NULL) {
1532
+ pm_buffer_append_u8(buffer, 0);
1533
+ } else {
1534
+ pm_serialize_node(parser, (pm_node_t *)((pm_splat_node_t *)node)->expression, buffer);
1535
+ }
1536
+ break;
1537
+ }
1538
+ case PM_STATEMENTS_NODE: {
1539
+ uint32_t body_size = pm_sizet_to_u32(((pm_statements_node_t *)node)->body.size);
1540
+ pm_buffer_append_u32(buffer, body_size);
1541
+ for (uint32_t index = 0; index < body_size; index++) {
1542
+ pm_serialize_node(parser, (pm_node_t *) ((pm_statements_node_t *)node)->body.nodes[index], buffer);
1543
+ }
1544
+ break;
1545
+ }
1546
+ case PM_STRING_CONCAT_NODE: {
1547
+ pm_serialize_node(parser, (pm_node_t *)((pm_string_concat_node_t *)node)->left, buffer);
1548
+ pm_serialize_node(parser, (pm_node_t *)((pm_string_concat_node_t *)node)->right, buffer);
1549
+ break;
1550
+ }
1551
+ case PM_STRING_NODE: {
1552
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1553
+ if (((pm_string_node_t *)node)->opening_loc.start == NULL) {
1554
+ pm_buffer_append_u8(buffer, 0);
1555
+ } else {
1556
+ pm_buffer_append_u8(buffer, 1);
1557
+ pm_serialize_location(parser, &((pm_string_node_t *)node)->opening_loc, buffer);
1558
+ }
1559
+ pm_serialize_location(parser, &((pm_string_node_t *)node)->content_loc, buffer);
1560
+ if (((pm_string_node_t *)node)->closing_loc.start == NULL) {
1561
+ pm_buffer_append_u8(buffer, 0);
1562
+ } else {
1563
+ pm_buffer_append_u8(buffer, 1);
1564
+ pm_serialize_location(parser, &((pm_string_node_t *)node)->closing_loc, buffer);
1565
+ }
1566
+ pm_serialize_string(parser, &((pm_string_node_t *)node)->unescaped, buffer);
1567
+ break;
1568
+ }
1569
+ case PM_SUPER_NODE: {
1570
+ pm_serialize_location(parser, &((pm_super_node_t *)node)->keyword_loc, buffer);
1571
+ if (((pm_super_node_t *)node)->lparen_loc.start == NULL) {
1572
+ pm_buffer_append_u8(buffer, 0);
1573
+ } else {
1574
+ pm_buffer_append_u8(buffer, 1);
1575
+ pm_serialize_location(parser, &((pm_super_node_t *)node)->lparen_loc, buffer);
1576
+ }
1577
+ if (((pm_super_node_t *)node)->arguments == NULL) {
1578
+ pm_buffer_append_u8(buffer, 0);
1579
+ } else {
1580
+ pm_serialize_node(parser, (pm_node_t *)((pm_super_node_t *)node)->arguments, buffer);
1581
+ }
1582
+ if (((pm_super_node_t *)node)->rparen_loc.start == NULL) {
1583
+ pm_buffer_append_u8(buffer, 0);
1584
+ } else {
1585
+ pm_buffer_append_u8(buffer, 1);
1586
+ pm_serialize_location(parser, &((pm_super_node_t *)node)->rparen_loc, buffer);
1587
+ }
1588
+ if (((pm_super_node_t *)node)->block == NULL) {
1589
+ pm_buffer_append_u8(buffer, 0);
1590
+ } else {
1591
+ pm_serialize_node(parser, (pm_node_t *)((pm_super_node_t *)node)->block, buffer);
1592
+ }
1593
+ break;
1594
+ }
1595
+ case PM_SYMBOL_NODE: {
1596
+ if (((pm_symbol_node_t *)node)->opening_loc.start == NULL) {
1597
+ pm_buffer_append_u8(buffer, 0);
1598
+ } else {
1599
+ pm_buffer_append_u8(buffer, 1);
1600
+ pm_serialize_location(parser, &((pm_symbol_node_t *)node)->opening_loc, buffer);
1601
+ }
1602
+ if (((pm_symbol_node_t *)node)->value_loc.start == NULL) {
1603
+ pm_buffer_append_u8(buffer, 0);
1604
+ } else {
1605
+ pm_buffer_append_u8(buffer, 1);
1606
+ pm_serialize_location(parser, &((pm_symbol_node_t *)node)->value_loc, buffer);
1607
+ }
1608
+ if (((pm_symbol_node_t *)node)->closing_loc.start == NULL) {
1609
+ pm_buffer_append_u8(buffer, 0);
1610
+ } else {
1611
+ pm_buffer_append_u8(buffer, 1);
1612
+ pm_serialize_location(parser, &((pm_symbol_node_t *)node)->closing_loc, buffer);
1613
+ }
1614
+ pm_serialize_string(parser, &((pm_symbol_node_t *)node)->unescaped, buffer);
1615
+ break;
1616
+ }
1617
+ case PM_TRUE_NODE: {
1618
+ break;
1619
+ }
1620
+ case PM_UNDEF_NODE: {
1621
+ uint32_t names_size = pm_sizet_to_u32(((pm_undef_node_t *)node)->names.size);
1622
+ pm_buffer_append_u32(buffer, names_size);
1623
+ for (uint32_t index = 0; index < names_size; index++) {
1624
+ pm_serialize_node(parser, (pm_node_t *) ((pm_undef_node_t *)node)->names.nodes[index], buffer);
1625
+ }
1626
+ pm_serialize_location(parser, &((pm_undef_node_t *)node)->keyword_loc, buffer);
1627
+ break;
1628
+ }
1629
+ case PM_UNLESS_NODE: {
1630
+ pm_serialize_location(parser, &((pm_unless_node_t *)node)->keyword_loc, buffer);
1631
+ pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->predicate, buffer);
1632
+ if (((pm_unless_node_t *)node)->statements == NULL) {
1633
+ pm_buffer_append_u8(buffer, 0);
1634
+ } else {
1635
+ pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->statements, buffer);
1636
+ }
1637
+ if (((pm_unless_node_t *)node)->consequent == NULL) {
1638
+ pm_buffer_append_u8(buffer, 0);
1639
+ } else {
1640
+ pm_serialize_node(parser, (pm_node_t *)((pm_unless_node_t *)node)->consequent, buffer);
1641
+ }
1642
+ if (((pm_unless_node_t *)node)->end_keyword_loc.start == NULL) {
1643
+ pm_buffer_append_u8(buffer, 0);
1644
+ } else {
1645
+ pm_buffer_append_u8(buffer, 1);
1646
+ pm_serialize_location(parser, &((pm_unless_node_t *)node)->end_keyword_loc, buffer);
1647
+ }
1648
+ break;
1649
+ }
1650
+ case PM_UNTIL_NODE: {
1651
+ pm_serialize_location(parser, &((pm_until_node_t *)node)->keyword_loc, buffer);
1652
+ if (((pm_until_node_t *)node)->closing_loc.start == NULL) {
1653
+ pm_buffer_append_u8(buffer, 0);
1654
+ } else {
1655
+ pm_buffer_append_u8(buffer, 1);
1656
+ pm_serialize_location(parser, &((pm_until_node_t *)node)->closing_loc, buffer);
1657
+ }
1658
+ pm_serialize_node(parser, (pm_node_t *)((pm_until_node_t *)node)->predicate, buffer);
1659
+ if (((pm_until_node_t *)node)->statements == NULL) {
1660
+ pm_buffer_append_u8(buffer, 0);
1661
+ } else {
1662
+ pm_serialize_node(parser, (pm_node_t *)((pm_until_node_t *)node)->statements, buffer);
1663
+ }
1664
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1665
+ break;
1666
+ }
1667
+ case PM_WHEN_NODE: {
1668
+ pm_serialize_location(parser, &((pm_when_node_t *)node)->keyword_loc, buffer);
1669
+ uint32_t conditions_size = pm_sizet_to_u32(((pm_when_node_t *)node)->conditions.size);
1670
+ pm_buffer_append_u32(buffer, conditions_size);
1671
+ for (uint32_t index = 0; index < conditions_size; index++) {
1672
+ pm_serialize_node(parser, (pm_node_t *) ((pm_when_node_t *)node)->conditions.nodes[index], buffer);
1673
+ }
1674
+ if (((pm_when_node_t *)node)->statements == NULL) {
1675
+ pm_buffer_append_u8(buffer, 0);
1676
+ } else {
1677
+ pm_serialize_node(parser, (pm_node_t *)((pm_when_node_t *)node)->statements, buffer);
1678
+ }
1679
+ break;
1680
+ }
1681
+ case PM_WHILE_NODE: {
1682
+ pm_serialize_location(parser, &((pm_while_node_t *)node)->keyword_loc, buffer);
1683
+ if (((pm_while_node_t *)node)->closing_loc.start == NULL) {
1684
+ pm_buffer_append_u8(buffer, 0);
1685
+ } else {
1686
+ pm_buffer_append_u8(buffer, 1);
1687
+ pm_serialize_location(parser, &((pm_while_node_t *)node)->closing_loc, buffer);
1688
+ }
1689
+ pm_serialize_node(parser, (pm_node_t *)((pm_while_node_t *)node)->predicate, buffer);
1690
+ if (((pm_while_node_t *)node)->statements == NULL) {
1691
+ pm_buffer_append_u8(buffer, 0);
1692
+ } else {
1693
+ pm_serialize_node(parser, (pm_node_t *)((pm_while_node_t *)node)->statements, buffer);
1694
+ }
1695
+ pm_buffer_append_u32(buffer, node->flags >> 2);
1696
+ break;
1697
+ }
1698
+ case PM_X_STRING_NODE: {
1699
+ pm_serialize_location(parser, &((pm_x_string_node_t *)node)->opening_loc, buffer);
1700
+ pm_serialize_location(parser, &((pm_x_string_node_t *)node)->content_loc, buffer);
1701
+ pm_serialize_location(parser, &((pm_x_string_node_t *)node)->closing_loc, buffer);
1702
+ pm_serialize_string(parser, &((pm_x_string_node_t *)node)->unescaped, buffer);
1703
+ break;
1704
+ }
1705
+ case PM_YIELD_NODE: {
1706
+ pm_serialize_location(parser, &((pm_yield_node_t *)node)->keyword_loc, buffer);
1707
+ if (((pm_yield_node_t *)node)->lparen_loc.start == NULL) {
1708
+ pm_buffer_append_u8(buffer, 0);
1709
+ } else {
1710
+ pm_buffer_append_u8(buffer, 1);
1711
+ pm_serialize_location(parser, &((pm_yield_node_t *)node)->lparen_loc, buffer);
1712
+ }
1713
+ if (((pm_yield_node_t *)node)->arguments == NULL) {
1714
+ pm_buffer_append_u8(buffer, 0);
1715
+ } else {
1716
+ pm_serialize_node(parser, (pm_node_t *)((pm_yield_node_t *)node)->arguments, buffer);
1717
+ }
1718
+ if (((pm_yield_node_t *)node)->rparen_loc.start == NULL) {
1719
+ pm_buffer_append_u8(buffer, 0);
1720
+ } else {
1721
+ pm_buffer_append_u8(buffer, 1);
1722
+ pm_serialize_location(parser, &((pm_yield_node_t *)node)->rparen_loc, buffer);
1723
+ }
1724
+ break;
1725
+ }
1726
+ }
1727
+ }
1728
+
1729
+ static void
1730
+ pm_serialize_comment(pm_parser_t *parser, pm_comment_t *comment, pm_buffer_t *buffer) {
1731
+ // serialize type
1732
+ pm_buffer_append_u8(buffer, (uint8_t) comment->type);
1733
+
1734
+ // serialize location
1735
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(comment->start - parser->start));
1736
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(comment->end - comment->start));
1737
+ }
1738
+
1739
+ static void
1740
+ pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
1741
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(pm_list_size(list)));
1742
+
1743
+ pm_comment_t *comment;
1744
+ for (comment = (pm_comment_t *) list->head; comment != NULL; comment = (pm_comment_t *) comment->node.next) {
1745
+ pm_serialize_comment(parser, comment, buffer);
1746
+ }
1747
+ }
1748
+
1749
+ static void
1750
+ pm_serialize_diagnostic(pm_parser_t *parser, pm_diagnostic_t *diagnostic, pm_buffer_t *buffer) {
1751
+ // serialize message
1752
+ size_t message_length = strlen(diagnostic->message);
1753
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(message_length));
1754
+ pm_buffer_append_str(buffer, diagnostic->message, message_length);
1755
+
1756
+ // serialize location
1757
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(diagnostic->start - parser->start));
1758
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(diagnostic->end - diagnostic->start));
1759
+ }
1760
+
1761
+ static void
1762
+ pm_serialize_diagnostic_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer) {
1763
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(pm_list_size(list)));
1764
+
1765
+ pm_diagnostic_t *diagnostic;
1766
+ for (diagnostic = (pm_diagnostic_t *) list->head; diagnostic != NULL; diagnostic = (pm_diagnostic_t *) diagnostic->node.next) {
1767
+ pm_serialize_diagnostic(parser, diagnostic, buffer);
1768
+ }
1769
+ }
1770
+
1771
+ static void
1772
+ pm_serialize_encoding(pm_encoding_t *encoding, pm_buffer_t *buffer) {
1773
+ size_t encoding_length = strlen(encoding->name);
1774
+ pm_buffer_append_u32(buffer, pm_sizet_to_u32(encoding_length));
1775
+ pm_buffer_append_str(buffer, encoding->name, encoding_length);
1776
+ }
1777
+
1778
+ #line 179 "serialize.c.erb"
1779
+ void
1780
+ pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer) {
1781
+ pm_serialize_encoding(&parser->encoding, buffer);
1782
+ pm_serialize_comment_list(parser, &parser->comment_list, buffer);
1783
+ pm_serialize_diagnostic_list(parser, &parser->error_list, buffer);
1784
+ pm_serialize_diagnostic_list(parser, &parser->warning_list, buffer);
1785
+
1786
+ // Here we're going to leave space for the offset of the constant pool in
1787
+ // the buffer.
1788
+ size_t offset = buffer->length;
1789
+ pm_buffer_append_zeroes(buffer, 4);
1790
+
1791
+ // Next, encode the length of the constant pool.
1792
+ pm_buffer_append_u32(buffer, parser->constant_pool.size);
1793
+
1794
+ // Now we're going to serialize the content of the node.
1795
+ pm_serialize_node(parser, node, buffer);
1796
+
1797
+ // Now we're going to serialize the offset of the constant pool back where
1798
+ // we left space for it.
1799
+ uint32_t length = pm_sizet_to_u32(buffer->length);
1800
+ memcpy(buffer->value + offset, &length, sizeof(uint32_t));
1801
+
1802
+ // Now we're going to serialize the constant pool.
1803
+ offset = buffer->length;
1804
+ pm_buffer_append_zeroes(buffer, parser->constant_pool.size * 8);
1805
+
1806
+ for (uint32_t index = 0; index < parser->constant_pool.capacity; index++) {
1807
+ pm_constant_pool_bucket_t *bucket = &parser->constant_pool.buckets[index];
1808
+
1809
+ // If we find a constant at this index, serialize it at the correct
1810
+ // index in the buffer.
1811
+ if (bucket->id != 0) {
1812
+ pm_constant_t *constant = &parser->constant_pool.constants[bucket->id - 1];
1813
+ size_t buffer_offset = offset + ((((size_t)bucket->id) - 1) * 8);
1814
+
1815
+ if (bucket->owned) {
1816
+ // Since this is an owned constant, we are going to write its
1817
+ // contents into the buffer after the constant pool. So
1818
+ // effectively in place of the source offset, we have a buffer
1819
+ // offset. We will add a leading 1 to indicate that this is a
1820
+ // buffer offset.
1821
+ uint32_t content_offset = pm_sizet_to_u32(buffer->length);
1822
+ uint32_t owned_mask = (uint32_t) (1 << 31);
1823
+
1824
+ assert(content_offset < owned_mask);
1825
+ content_offset |= owned_mask;
1826
+
1827
+ memcpy(buffer->value + buffer_offset, &content_offset, 4);
1828
+ pm_buffer_append_bytes(buffer, constant->start, constant->length);
1829
+ } else {
1830
+ // Since this is a shared constant, we are going to write its
1831
+ // source offset directly into the buffer.
1832
+ uint32_t source_offset = pm_ptrdifft_to_u32(constant->start - parser->start);
1833
+ memcpy(buffer->value + buffer_offset, &source_offset, 4);
1834
+ }
1835
+
1836
+ // Now we can write the length of the constant into the buffer.
1837
+ uint32_t constant_length = pm_sizet_to_u32(constant->length);
1838
+ memcpy(buffer->value + buffer_offset + 4, &constant_length, 4);
1839
+ }
1840
+ }
1841
+ }
1842
+
1843
+ static void
1844
+ serialize_token(void *data, pm_parser_t *parser, pm_token_t *token) {
1845
+ pm_buffer_t *buffer = (pm_buffer_t *) data;
1846
+
1847
+ pm_buffer_append_u32(buffer, token->type);
1848
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(token->start - parser->start));
1849
+ pm_buffer_append_u32(buffer, pm_ptrdifft_to_u32(token->end - token->start));
1850
+ pm_buffer_append_u32(buffer, parser->lex_state);
1851
+ }
1852
+
1853
+ PRISM_EXPORTED_FUNCTION void
1854
+ pm_lex_serialize(const uint8_t *source, size_t size, const char *filepath, pm_buffer_t *buffer) {
1855
+ pm_parser_t parser;
1856
+ pm_parser_init(&parser, source, size, filepath);
1857
+
1858
+ pm_lex_callback_t lex_callback = (pm_lex_callback_t) {
1859
+ .data = (void *) buffer,
1860
+ .callback = serialize_token,
1861
+ };
1862
+
1863
+ parser.lex_callback = &lex_callback;
1864
+ pm_node_t *node = pm_parse(&parser);
1865
+
1866
+ // Append 0 to mark end of tokens
1867
+ pm_buffer_append_u8(buffer, 0);
1868
+
1869
+ pm_serialize_encoding(&parser.encoding, buffer);
1870
+ pm_serialize_comment_list(&parser, &parser.comment_list, buffer);
1871
+ pm_serialize_diagnostic_list(&parser, &parser.error_list, buffer);
1872
+ pm_serialize_diagnostic_list(&parser, &parser.warning_list, buffer);
1873
+
1874
+ pm_node_destroy(&parser, node);
1875
+ pm_parser_free(&parser);
1876
+ }
1877
+
1878
+ // Parse and serialize both the AST and the tokens represented by the given
1879
+ // source to the given buffer.
1880
+ PRISM_EXPORTED_FUNCTION void
1881
+ pm_parse_lex_serialize(const uint8_t *source, size_t size, pm_buffer_t *buffer, const char *metadata) {
1882
+ pm_parser_t parser;
1883
+ pm_parser_init(&parser, source, size, NULL);
1884
+ if (metadata) pm_parser_metadata(&parser, metadata);
1885
+
1886
+ pm_lex_callback_t lex_callback = (pm_lex_callback_t) {
1887
+ .data = (void *) buffer,
1888
+ .callback = serialize_token,
1889
+ };
1890
+
1891
+ parser.lex_callback = &lex_callback;
1892
+ pm_node_t *node = pm_parse(&parser);
1893
+
1894
+ pm_buffer_append_u8(buffer, 0);
1895
+ pm_serialize(&parser, node, buffer);
1896
+
1897
+ pm_node_destroy(&parser, node);
1898
+ pm_parser_free(&parser);
1899
+ }