prism 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -1
- data/Makefile +2 -1
- data/README.md +1 -0
- data/config.yml +264 -37
- data/docs/parser_translation.md +8 -23
- data/docs/ripper_translation.md +1 -1
- data/ext/prism/api_node.c +2 -0
- data/ext/prism/extension.c +14 -1
- data/ext/prism/extension.h +1 -1
- data/include/prism/ast.h +275 -49
- data/include/prism/diagnostic.h +4 -0
- data/include/prism/options.h +43 -3
- data/include/prism/regexp.h +2 -2
- data/include/prism/util/pm_buffer.h +8 -0
- data/include/prism/util/pm_integer.h +4 -0
- data/include/prism/util/pm_list.h +6 -0
- data/include/prism/util/pm_string.h +12 -2
- data/include/prism/version.h +2 -2
- data/include/prism.h +39 -14
- data/lib/prism/compiler.rb +456 -151
- data/lib/prism/desugar_compiler.rb +1 -0
- data/lib/prism/dispatcher.rb +16 -0
- data/lib/prism/dot_visitor.rb +5 -1
- data/lib/prism/dsl.rb +3 -0
- data/lib/prism/ffi.rb +17 -7
- data/lib/prism/inspect_visitor.rb +3 -0
- data/lib/prism/lex_compat.rb +1 -0
- data/lib/prism/mutation_compiler.rb +3 -0
- data/lib/prism/node.rb +506 -335
- data/lib/prism/node_ext.rb +4 -1
- data/lib/prism/pack.rb +2 -0
- data/lib/prism/parse_result/comments.rb +1 -0
- data/lib/prism/parse_result/errors.rb +1 -0
- data/lib/prism/parse_result/newlines.rb +1 -0
- data/lib/prism/parse_result.rb +1 -0
- data/lib/prism/pattern.rb +1 -0
- data/lib/prism/polyfill/scan_byte.rb +14 -0
- data/lib/prism/polyfill/warn.rb +42 -0
- data/lib/prism/reflection.rb +3 -0
- data/lib/prism/relocation.rb +1 -0
- data/lib/prism/serialize.rb +24 -19
- data/lib/prism/string_query.rb +1 -0
- data/lib/prism/translation/parser/builder.rb +1 -0
- data/lib/prism/translation/parser/compiler.rb +47 -25
- data/lib/prism/translation/parser/lexer.rb +29 -21
- data/lib/prism/translation/parser.rb +13 -1
- data/lib/prism/translation/parser33.rb +1 -0
- data/lib/prism/translation/parser34.rb +1 -0
- data/lib/prism/translation/parser35.rb +1 -0
- data/lib/prism/translation/parser_current.rb +24 -0
- data/lib/prism/translation/ripper/sexp.rb +1 -0
- data/lib/prism/translation/ripper.rb +17 -1
- data/lib/prism/translation/ruby_parser.rb +286 -3
- data/lib/prism/translation.rb +2 -0
- data/lib/prism/visitor.rb +457 -152
- data/lib/prism.rb +2 -0
- data/prism.gemspec +5 -1
- data/rbi/prism/dsl.rbi +3 -3
- data/rbi/prism/node.rbi +21 -9
- data/sig/prism/dispatcher.rbs +3 -0
- data/sig/prism/dsl.rbs +3 -3
- data/sig/prism/node.rbs +444 -30
- data/sig/prism/node_ext.rbs +84 -17
- data/sig/prism/parse_result/comments.rbs +38 -0
- data/sig/prism/parse_result.rbs +4 -0
- data/sig/prism/reflection.rbs +1 -1
- data/src/diagnostic.c +7 -1
- data/src/node.c +2 -0
- data/src/options.c +2 -2
- data/src/prettyprint.c +2 -0
- data/src/prism.c +252 -130
- data/src/serialize.c +2 -0
- data/src/token_type.c +36 -34
- metadata +6 -2
data/include/prism/options.h
CHANGED
@@ -82,14 +82,20 @@ typedef void (*pm_options_shebang_callback_t)(struct pm_options *options, const
|
|
82
82
|
* parse in the same way as a specific version of CRuby would have.
|
83
83
|
*/
|
84
84
|
typedef enum {
|
85
|
-
/**
|
86
|
-
|
85
|
+
/** If an explicit version is not provided, the current version of prism will be used. */
|
86
|
+
PM_OPTIONS_VERSION_UNSET = 0,
|
87
87
|
|
88
88
|
/** The vendored version of prism in CRuby 3.3.x. */
|
89
89
|
PM_OPTIONS_VERSION_CRUBY_3_3 = 1,
|
90
90
|
|
91
91
|
/** The vendored version of prism in CRuby 3.4.x. */
|
92
|
-
PM_OPTIONS_VERSION_CRUBY_3_4 = 2
|
92
|
+
PM_OPTIONS_VERSION_CRUBY_3_4 = 2,
|
93
|
+
|
94
|
+
/** The vendored version of prism in CRuby 3.5.x. */
|
95
|
+
PM_OPTIONS_VERSION_CRUBY_3_5 = 3,
|
96
|
+
|
97
|
+
/** The current version of prism. */
|
98
|
+
PM_OPTIONS_VERSION_LATEST = PM_OPTIONS_VERSION_CRUBY_3_5
|
93
99
|
} pm_options_version_t;
|
94
100
|
|
95
101
|
/**
|
@@ -231,6 +237,8 @@ static const uint8_t PM_OPTIONS_COMMAND_LINE_X = 0x20;
|
|
231
237
|
* @param shebang_callback The shebang callback to set.
|
232
238
|
* @param shebang_callback_data Any additional data that should be passed along
|
233
239
|
* to the callback.
|
240
|
+
*
|
241
|
+
* \public \memberof pm_options
|
234
242
|
*/
|
235
243
|
PRISM_EXPORTED_FUNCTION void pm_options_shebang_callback_set(pm_options_t *options, pm_options_shebang_callback_t shebang_callback, void *shebang_callback_data);
|
236
244
|
|
@@ -239,6 +247,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_shebang_callback_set(pm_options_t *optio
|
|
239
247
|
*
|
240
248
|
* @param options The options struct to set the filepath on.
|
241
249
|
* @param filepath The filepath to set.
|
250
|
+
*
|
251
|
+
* \public \memberof pm_options
|
242
252
|
*/
|
243
253
|
PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, const char *filepath);
|
244
254
|
|
@@ -247,6 +257,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_filepath_set(pm_options_t *options, cons
|
|
247
257
|
*
|
248
258
|
* @param options The options struct to set the line on.
|
249
259
|
* @param line The line to set.
|
260
|
+
*
|
261
|
+
* \public \memberof pm_options
|
250
262
|
*/
|
251
263
|
PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t line);
|
252
264
|
|
@@ -255,6 +267,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_line_set(pm_options_t *options, int32_t
|
|
255
267
|
*
|
256
268
|
* @param options The options struct to set the encoding on.
|
257
269
|
* @param encoding The encoding to set.
|
270
|
+
*
|
271
|
+
* \public \memberof pm_options
|
258
272
|
*/
|
259
273
|
PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, const char *encoding);
|
260
274
|
|
@@ -263,6 +277,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, cons
|
|
263
277
|
*
|
264
278
|
* @param options The options struct to set the encoding_locked value on.
|
265
279
|
* @param encoding_locked The encoding_locked value to set.
|
280
|
+
*
|
281
|
+
* \public \memberof pm_options
|
266
282
|
*/
|
267
283
|
PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *options, bool encoding_locked);
|
268
284
|
|
@@ -271,6 +287,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_encoding_locked_set(pm_options_t *option
|
|
271
287
|
*
|
272
288
|
* @param options The options struct to set the frozen string literal value on.
|
273
289
|
* @param frozen_string_literal The frozen string literal value to set.
|
290
|
+
*
|
291
|
+
* \public \memberof pm_options
|
274
292
|
*/
|
275
293
|
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal);
|
276
294
|
|
@@ -279,6 +297,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *
|
|
279
297
|
*
|
280
298
|
* @param options The options struct to set the command line option on.
|
281
299
|
* @param command_line The command_line value to set.
|
300
|
+
*
|
301
|
+
* \public \memberof pm_options
|
282
302
|
*/
|
283
303
|
PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options, uint8_t command_line);
|
284
304
|
|
@@ -291,6 +311,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_command_line_set(pm_options_t *options,
|
|
291
311
|
* @param version The version to set.
|
292
312
|
* @param length The length of the version string.
|
293
313
|
* @return Whether or not the version was parsed successfully.
|
314
|
+
*
|
315
|
+
* \public \memberof pm_options
|
294
316
|
*/
|
295
317
|
PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const char *version, size_t length);
|
296
318
|
|
@@ -299,6 +321,8 @@ PRISM_EXPORTED_FUNCTION bool pm_options_version_set(pm_options_t *options, const
|
|
299
321
|
*
|
300
322
|
* @param options The options struct to set the main script value on.
|
301
323
|
* @param main_script The main script value to set.
|
324
|
+
*
|
325
|
+
* \public \memberof pm_options
|
302
326
|
*/
|
303
327
|
PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, bool main_script);
|
304
328
|
|
@@ -307,6 +331,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_main_script_set(pm_options_t *options, b
|
|
307
331
|
*
|
308
332
|
* @param options The options struct to set the partial script value on.
|
309
333
|
* @param partial_script The partial script value to set.
|
334
|
+
*
|
335
|
+
* \public \memberof pm_options
|
310
336
|
*/
|
311
337
|
PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options, bool partial_script);
|
312
338
|
|
@@ -315,6 +341,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_partial_script_set(pm_options_t *options
|
|
315
341
|
*
|
316
342
|
* @param options The options struct to set the freeze value on.
|
317
343
|
* @param freeze The freeze value to set.
|
344
|
+
*
|
345
|
+
* \public \memberof pm_options
|
318
346
|
*/
|
319
347
|
PRISM_EXPORTED_FUNCTION void pm_options_freeze_set(pm_options_t *options, bool freeze);
|
320
348
|
|
@@ -324,6 +352,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_freeze_set(pm_options_t *options, bool f
|
|
324
352
|
* @param options The options struct to initialize the scopes array on.
|
325
353
|
* @param scopes_count The number of scopes to allocate.
|
326
354
|
* @return Whether or not the scopes array was initialized successfully.
|
355
|
+
*
|
356
|
+
* \public \memberof pm_options
|
327
357
|
*/
|
328
358
|
PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_t scopes_count);
|
329
359
|
|
@@ -333,6 +363,8 @@ PRISM_EXPORTED_FUNCTION bool pm_options_scopes_init(pm_options_t *options, size_
|
|
333
363
|
* @param options The options struct to get the scope from.
|
334
364
|
* @param index The index of the scope to get.
|
335
365
|
* @return A pointer to the scope at the given index.
|
366
|
+
*
|
367
|
+
* \public \memberof pm_options
|
336
368
|
*/
|
337
369
|
PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope_get(const pm_options_t *options, size_t index);
|
338
370
|
|
@@ -343,6 +375,8 @@ PRISM_EXPORTED_FUNCTION const pm_options_scope_t * pm_options_scope_get(const pm
|
|
343
375
|
* @param scope The scope struct to initialize.
|
344
376
|
* @param locals_count The number of locals to allocate.
|
345
377
|
* @return Whether or not the scope was initialized successfully.
|
378
|
+
*
|
379
|
+
* \public \memberof pm_options
|
346
380
|
*/
|
347
381
|
PRISM_EXPORTED_FUNCTION bool pm_options_scope_init(pm_options_scope_t *scope, size_t locals_count);
|
348
382
|
|
@@ -352,6 +386,8 @@ PRISM_EXPORTED_FUNCTION bool pm_options_scope_init(pm_options_scope_t *scope, si
|
|
352
386
|
* @param scope The scope struct to get the local from.
|
353
387
|
* @param index The index of the local to get.
|
354
388
|
* @return A pointer to the local at the given index.
|
389
|
+
*
|
390
|
+
* \public \memberof pm_options
|
355
391
|
*/
|
356
392
|
PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local_get(const pm_options_scope_t *scope, size_t index);
|
357
393
|
|
@@ -360,6 +396,8 @@ PRISM_EXPORTED_FUNCTION const pm_string_t * pm_options_scope_local_get(const pm_
|
|
360
396
|
*
|
361
397
|
* @param scope The scope struct to set the forwarding on.
|
362
398
|
* @param forwarding The forwarding value to set.
|
399
|
+
*
|
400
|
+
* \public \memberof pm_options
|
363
401
|
*/
|
364
402
|
PRISM_EXPORTED_FUNCTION void pm_options_scope_forwarding_set(pm_options_scope_t *scope, uint8_t forwarding);
|
365
403
|
|
@@ -367,6 +405,8 @@ PRISM_EXPORTED_FUNCTION void pm_options_scope_forwarding_set(pm_options_scope_t
|
|
367
405
|
* Free the internal memory associated with the options.
|
368
406
|
*
|
369
407
|
* @param options The options struct whose internal memory should be freed.
|
408
|
+
*
|
409
|
+
* \public \memberof pm_options
|
370
410
|
*/
|
371
411
|
PRISM_EXPORTED_FUNCTION void pm_options_free(pm_options_t *options);
|
372
412
|
|
data/include/prism/regexp.h
CHANGED
@@ -17,12 +17,12 @@
|
|
17
17
|
#include <string.h>
|
18
18
|
|
19
19
|
/**
|
20
|
-
* This callback is called when a named capture group is found.
|
20
|
+
* This callback is called by pm_regexp_parse() when a named capture group is found.
|
21
21
|
*/
|
22
22
|
typedef void (*pm_regexp_name_callback_t)(const pm_string_t *name, void *data);
|
23
23
|
|
24
24
|
/**
|
25
|
-
* This callback is called when a parse error is found.
|
25
|
+
* This callback is called by pm_regexp_parse() when a parse error is found.
|
26
26
|
*/
|
27
27
|
typedef void (*pm_regexp_error_callback_t)(const uint8_t *start, const uint8_t *end, const char *message, void *data);
|
28
28
|
|
@@ -51,6 +51,8 @@ bool pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity);
|
|
51
51
|
*
|
52
52
|
* @param buffer The buffer to initialize.
|
53
53
|
* @returns True if the buffer was initialized successfully, false otherwise.
|
54
|
+
*
|
55
|
+
* \public \memberof pm_buffer_t
|
54
56
|
*/
|
55
57
|
PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer);
|
56
58
|
|
@@ -59,6 +61,8 @@ PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer);
|
|
59
61
|
*
|
60
62
|
* @param buffer The buffer to get the value of.
|
61
63
|
* @returns The value of the buffer.
|
64
|
+
*
|
65
|
+
* \public \memberof pm_buffer_t
|
62
66
|
*/
|
63
67
|
PRISM_EXPORTED_FUNCTION char * pm_buffer_value(const pm_buffer_t *buffer);
|
64
68
|
|
@@ -67,6 +71,8 @@ PRISM_EXPORTED_FUNCTION char * pm_buffer_value(const pm_buffer_t *buffer);
|
|
67
71
|
*
|
68
72
|
* @param buffer The buffer to get the length of.
|
69
73
|
* @returns The length of the buffer.
|
74
|
+
*
|
75
|
+
* \public \memberof pm_buffer_t
|
70
76
|
*/
|
71
77
|
PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(const pm_buffer_t *buffer);
|
72
78
|
|
@@ -222,6 +228,8 @@ void pm_buffer_insert(pm_buffer_t *buffer, size_t index, const char *value, size
|
|
222
228
|
* Free the memory associated with the buffer.
|
223
229
|
*
|
224
230
|
* @param buffer The buffer to free.
|
231
|
+
*
|
232
|
+
* \public \memberof pm_buffer_t
|
225
233
|
*/
|
226
234
|
PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer);
|
227
235
|
|
@@ -112,6 +112,8 @@ void pm_integers_reduce(pm_integer_t *numerator, pm_integer_t *denominator);
|
|
112
112
|
*
|
113
113
|
* @param buffer The buffer to append the string to.
|
114
114
|
* @param integer The integer to convert to a string.
|
115
|
+
*
|
116
|
+
* \public \memberof pm_integer_t
|
115
117
|
*/
|
116
118
|
PRISM_EXPORTED_FUNCTION void pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer);
|
117
119
|
|
@@ -120,6 +122,8 @@ PRISM_EXPORTED_FUNCTION void pm_integer_string(pm_buffer_t *buffer, const pm_int
|
|
120
122
|
* the integer exceeds the size of a single node in the linked list.
|
121
123
|
*
|
122
124
|
* @param integer The integer to free.
|
125
|
+
*
|
126
|
+
* \public \memberof pm_integer_t
|
123
127
|
*/
|
124
128
|
PRISM_EXPORTED_FUNCTION void pm_integer_free(pm_integer_t *integer);
|
125
129
|
|
@@ -68,6 +68,8 @@ typedef struct {
|
|
68
68
|
*
|
69
69
|
* @param list The list to check.
|
70
70
|
* @return True if the given list is empty, otherwise false.
|
71
|
+
*
|
72
|
+
* \public \memberof pm_list_t
|
71
73
|
*/
|
72
74
|
PRISM_EXPORTED_FUNCTION bool pm_list_empty_p(pm_list_t *list);
|
73
75
|
|
@@ -76,6 +78,8 @@ PRISM_EXPORTED_FUNCTION bool pm_list_empty_p(pm_list_t *list);
|
|
76
78
|
*
|
77
79
|
* @param list The list to check.
|
78
80
|
* @return The size of the list.
|
81
|
+
*
|
82
|
+
* \public \memberof pm_list_t
|
79
83
|
*/
|
80
84
|
PRISM_EXPORTED_FUNCTION size_t pm_list_size(pm_list_t *list);
|
81
85
|
|
@@ -91,6 +95,8 @@ void pm_list_append(pm_list_t *list, pm_list_node_t *node);
|
|
91
95
|
* Deallocate the internal state of the given list.
|
92
96
|
*
|
93
97
|
* @param list The list to free.
|
98
|
+
*
|
99
|
+
* \public \memberof pm_list_t
|
94
100
|
*/
|
95
101
|
PRISM_EXPORTED_FUNCTION void pm_list_free(pm_list_t *list);
|
96
102
|
|
@@ -45,11 +45,11 @@ typedef struct {
|
|
45
45
|
/** This is a slice of another string, and should not be freed. */
|
46
46
|
PM_STRING_SHARED,
|
47
47
|
|
48
|
-
/** This string owns its memory, and should be freed using `pm_string_free`. */
|
48
|
+
/** This string owns its memory, and should be freed using `pm_string_free()`. */
|
49
49
|
PM_STRING_OWNED,
|
50
50
|
|
51
51
|
#ifdef PRISM_HAS_MMAP
|
52
|
-
/** This string is a memory-mapped file, and should be freed using `pm_string_free`. */
|
52
|
+
/** This string is a memory-mapped file, and should be freed using `pm_string_free()`. */
|
53
53
|
PM_STRING_MAPPED
|
54
54
|
#endif
|
55
55
|
} type;
|
@@ -130,6 +130,8 @@ typedef enum {
|
|
130
130
|
* @param string The string to initialize.
|
131
131
|
* @param filepath The filepath to read.
|
132
132
|
* @return The success of the read, indicated by the value of the enum.
|
133
|
+
*
|
134
|
+
* \public \memberof pm_string_t
|
133
135
|
*/
|
134
136
|
PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_mapped_init(pm_string_t *string, const char *filepath);
|
135
137
|
|
@@ -141,6 +143,8 @@ PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_mapped_init(pm_string_
|
|
141
143
|
* @param string The string to initialize.
|
142
144
|
* @param filepath The filepath to read.
|
143
145
|
* @return The success of the read, indicated by the value of the enum.
|
146
|
+
*
|
147
|
+
* \public \memberof pm_string_t
|
144
148
|
*/
|
145
149
|
PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_file_init(pm_string_t *string, const char *filepath);
|
146
150
|
|
@@ -169,6 +173,8 @@ int pm_string_compare(const pm_string_t *left, const pm_string_t *right);
|
|
169
173
|
*
|
170
174
|
* @param string The string to get the length of.
|
171
175
|
* @return The length of the string.
|
176
|
+
*
|
177
|
+
* \public \memberof pm_string_t
|
172
178
|
*/
|
173
179
|
PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string);
|
174
180
|
|
@@ -177,6 +183,8 @@ PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string);
|
|
177
183
|
*
|
178
184
|
* @param string The string to get the start pointer of.
|
179
185
|
* @return The start pointer of the string.
|
186
|
+
*
|
187
|
+
* \public \memberof pm_string_t
|
180
188
|
*/
|
181
189
|
PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string);
|
182
190
|
|
@@ -184,6 +192,8 @@ PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *stri
|
|
184
192
|
* Free the associated memory of the given string.
|
185
193
|
*
|
186
194
|
* @param string The string to free.
|
195
|
+
*
|
196
|
+
* \public \memberof pm_string_t
|
187
197
|
*/
|
188
198
|
PRISM_EXPORTED_FUNCTION void pm_string_free(pm_string_t *string);
|
189
199
|
|
data/include/prism/version.h
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
/**
|
15
15
|
* The minor version of the Prism library as an int.
|
16
16
|
*/
|
17
|
-
#define PRISM_VERSION_MINOR
|
17
|
+
#define PRISM_VERSION_MINOR 5
|
18
18
|
|
19
19
|
/**
|
20
20
|
* The patch version of the Prism library as an int.
|
@@ -24,6 +24,6 @@
|
|
24
24
|
/**
|
25
25
|
* The version of the Prism library as a constant string.
|
26
26
|
*/
|
27
|
-
#define PRISM_VERSION "1.
|
27
|
+
#define PRISM_VERSION "1.5.0"
|
28
28
|
|
29
29
|
#endif
|
data/include/prism.h
CHANGED
@@ -49,10 +49,15 @@ PRISM_EXPORTED_FUNCTION const char * pm_version(void);
|
|
49
49
|
/**
|
50
50
|
* Initialize a parser with the given start and end pointers.
|
51
51
|
*
|
52
|
+
* The resulting parser must eventually be freed with `pm_parser_free()`.
|
53
|
+
*
|
52
54
|
* @param parser The parser to initialize.
|
53
55
|
* @param source The source to parse.
|
54
56
|
* @param size The size of the source.
|
55
|
-
* @param options The optional options to use when parsing.
|
57
|
+
* @param options The optional options to use when parsing. These options must
|
58
|
+
* live for the whole lifetime of this parser.
|
59
|
+
*
|
60
|
+
* \public \memberof pm_parser
|
56
61
|
*/
|
57
62
|
PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm_options_t *options);
|
58
63
|
|
@@ -62,13 +67,20 @@ PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *
|
|
62
67
|
*
|
63
68
|
* @param parser The parser to register the callback with.
|
64
69
|
* @param callback The callback to register.
|
70
|
+
*
|
71
|
+
* \public \memberof pm_parser
|
65
72
|
*/
|
66
73
|
PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback(pm_parser_t *parser, pm_encoding_changed_callback_t callback);
|
67
74
|
|
68
75
|
/**
|
69
76
|
* Free any memory associated with the given parser.
|
70
77
|
*
|
78
|
+
* This does not free the `pm_options_t` object that was used to initialize the
|
79
|
+
* parser.
|
80
|
+
*
|
71
81
|
* @param parser The parser to free.
|
82
|
+
*
|
83
|
+
* \public \memberof pm_parser
|
72
84
|
*/
|
73
85
|
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser);
|
74
86
|
|
@@ -77,16 +89,25 @@ PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser);
|
|
77
89
|
*
|
78
90
|
* @param parser The parser to use.
|
79
91
|
* @return The AST representing the source.
|
92
|
+
*
|
93
|
+
* \public \memberof pm_parser
|
80
94
|
*/
|
81
95
|
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser);
|
82
96
|
|
83
97
|
/**
|
84
|
-
* This function is used in pm_parse_stream to retrieve a line of input from a
|
98
|
+
* This function is used in pm_parse_stream() to retrieve a line of input from a
|
85
99
|
* stream. It closely mirrors that of fgets so that fgets can be used as the
|
86
100
|
* default implementation.
|
87
101
|
*/
|
88
102
|
typedef char * (pm_parse_stream_fgets_t)(char *string, int size, void *stream);
|
89
103
|
|
104
|
+
/**
|
105
|
+
* This function is used in pm_parse_stream to check whether a stream is EOF.
|
106
|
+
* It closely mirrors that of feof so that feof can be used as the
|
107
|
+
* default implementation.
|
108
|
+
*/
|
109
|
+
typedef int (pm_parse_stream_feof_t)(void *stream);
|
110
|
+
|
90
111
|
/**
|
91
112
|
* Parse a stream of Ruby source and return the tree.
|
92
113
|
*
|
@@ -94,10 +115,13 @@ typedef char * (pm_parse_stream_fgets_t)(char *string, int size, void *stream);
|
|
94
115
|
* @param buffer The buffer to use.
|
95
116
|
* @param stream The stream to parse.
|
96
117
|
* @param stream_fgets The function to use to read from the stream.
|
118
|
+
* @param stream_feof The function to use to determine if the stream has hit eof.
|
97
119
|
* @param options The optional options to use when parsing.
|
98
120
|
* @return The AST representing the source.
|
121
|
+
*
|
122
|
+
* \public \memberof pm_parser
|
99
123
|
*/
|
100
|
-
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse_stream(pm_parser_t *parser, pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *stream_fgets, const pm_options_t *options);
|
124
|
+
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse_stream(pm_parser_t *parser, pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *stream_fgets, pm_parse_stream_feof_t *stream_feof, const pm_options_t *options);
|
101
125
|
|
102
126
|
// We optionally support serializing to a binary string. For systems that don't
|
103
127
|
// want or need this functionality, it can be turned off with the
|
@@ -111,9 +135,10 @@ PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse_stream(pm_parser_t *parser, pm_buff
|
|
111
135
|
* @param buffer The buffer to serialize to.
|
112
136
|
* @param stream The stream to parse.
|
113
137
|
* @param stream_fgets The function to use to read from the stream.
|
138
|
+
* @param stream_feof The function to use to tell if the stream has hit eof.
|
114
139
|
* @param data The optional data to pass to the parser.
|
115
140
|
*/
|
116
|
-
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_stream(pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *stream_fgets, const char *data);
|
141
|
+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_stream(pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *stream_fgets, pm_parse_stream_feof_t *stream_feof, const char *data);
|
117
142
|
|
118
143
|
/**
|
119
144
|
* Serialize the given list of comments to the given buffer.
|
@@ -307,10 +332,10 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint
|
|
307
332
|
* to want to use and be aware of are:
|
308
333
|
*
|
309
334
|
* * `pm_parser_t` - the main parser structure
|
310
|
-
* * `pm_parser_init` - initialize a parser
|
311
|
-
* * `pm_parse` - parse and return the root node
|
312
|
-
* * `pm_node_destroy` - deallocate the root node returned by `pm_parse`
|
313
|
-
* * `pm_parser_free` - free the internal memory of the parser
|
335
|
+
* * `pm_parser_init()` - initialize a parser
|
336
|
+
* * `pm_parse()` - parse and return the root node
|
337
|
+
* * `pm_node_destroy()` - deallocate the root node returned by `pm_parse()`
|
338
|
+
* * `pm_parser_free()` - free the internal memory of the parser
|
314
339
|
*
|
315
340
|
* Putting all of this together would look something like:
|
316
341
|
*
|
@@ -327,8 +352,8 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint
|
|
327
352
|
* }
|
328
353
|
* ```
|
329
354
|
*
|
330
|
-
* All of the nodes "inherit" from `pm_node_t` by embedding those structures
|
331
|
-
* their first member. This means you can downcast and upcast any node in the
|
355
|
+
* All of the nodes "inherit" from `pm_node_t` by embedding those structures
|
356
|
+
* as their first member. This means you can downcast and upcast any node in the
|
332
357
|
* tree to a `pm_node_t`.
|
333
358
|
*
|
334
359
|
* @section serializing Serializing
|
@@ -340,9 +365,9 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint
|
|
340
365
|
* use and be aware of are:
|
341
366
|
*
|
342
367
|
* * `pm_buffer_t` - a small buffer object that will hold the serialized AST
|
343
|
-
* * `pm_buffer_free` - free the memory associated with the buffer
|
344
|
-
* * `pm_serialize` - serialize the AST into a buffer
|
345
|
-
* * `pm_serialize_parse` - parse and serialize the AST into a buffer
|
368
|
+
* * `pm_buffer_free()` - free the memory associated with the buffer
|
369
|
+
* * `pm_serialize()` - serialize the AST into a buffer
|
370
|
+
* * `pm_serialize_parse()` - parse and serialize the AST into a buffer
|
346
371
|
*
|
347
372
|
* Putting all of this together would look something like:
|
348
373
|
*
|
@@ -360,7 +385,7 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint
|
|
360
385
|
* @section inspecting Inspecting
|
361
386
|
*
|
362
387
|
* Prism provides the ability to inspect the AST by pretty-printing nodes. You
|
363
|
-
* can do this with the `pm_prettyprint` function, which you would use like:
|
388
|
+
* can do this with the `pm_prettyprint()` function, which you would use like:
|
364
389
|
*
|
365
390
|
* ```c
|
366
391
|
* void prettyprint(const uint8_t *source, size_t length) {
|