@@ -185,7 +185,16 @@ static rbs_lexer_t *alloc_lexer_from_buffer(rbs_allocator_t *allocator, VALUE st
185185 return lexer ;
186186}
187187
188- static rbs_parser_t * alloc_parser_from_buffer (VALUE buffer , int start_pos , int end_pos ) {
188+ // Build the parser options from the arguments the `_parse_*` entry points
189+ // receive. The optional syntax these enable is not part of the public
190+ // `RBS::Parser` API, so only the private entry points pass them through.
191+ static rbs_parser_options_t parser_options (VALUE enable_forwarding_params ) {
192+ return (rbs_parser_options_t ) {
193+ .enable_forwarding_params = RB_TEST (enable_forwarding_params ),
194+ };
195+ }
196+
197+ static rbs_parser_t * alloc_parser_from_buffer_with_options (VALUE buffer , int start_pos , int end_pos , rbs_parser_options_t options ) {
189198 VALUE string = rb_funcall (buffer , rb_intern ("content" ), 0 );
190199 StringValue (string );
191200
@@ -194,11 +203,12 @@ static rbs_parser_t *alloc_parser_from_buffer(VALUE buffer, int start_pos, int e
194203 rb_encoding * encoding = rb_enc_get (string );
195204 const char * encoding_name = rb_enc_name (encoding );
196205
197- rbs_parser_t * parser = rbs_parser_new (
206+ rbs_parser_t * parser = rbs_parser_new_with_options (
198207 rbs_string_from_ruby_string (string ),
199208 rbs_encoding_find ((const uint8_t * ) encoding_name , (const uint8_t * ) (encoding_name + strlen (encoding_name ))),
200209 start_pos ,
201- end_pos
210+ end_pos ,
211+ options
202212 );
203213
204214 if (parser == NULL ) {
@@ -208,6 +218,10 @@ static rbs_parser_t *alloc_parser_from_buffer(VALUE buffer, int start_pos, int e
208218 return parser ;
209219}
210220
221+ static rbs_parser_t * alloc_parser_from_buffer (VALUE buffer , int start_pos , int end_pos ) {
222+ return alloc_parser_from_buffer_with_options (buffer , start_pos , end_pos , (rbs_parser_options_t ) { 0 });
223+ }
224+
211225static VALUE rbsparser_parse_type (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos , VALUE variables , VALUE require_eof , VALUE void_allowed , VALUE self_allowed , VALUE classish_allowed ) {
212226 VALUE string = rb_funcall (buffer , rb_intern ("content" ), 0 );
213227 StringValue (string );
@@ -254,12 +268,12 @@ static VALUE parse_method_type_try(VALUE a) {
254268 return rbs_struct_to_ruby_value (ctx , (rbs_node_t * ) method_type );
255269}
256270
257- static VALUE rbsparser_parse_method_type (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos , VALUE variables , VALUE require_eof ) {
271+ static VALUE rbsparser_parse_method_type (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos , VALUE variables , VALUE require_eof , VALUE enable_forwarding_params ) {
258272 VALUE string = rb_funcall (buffer , rb_intern ("content" ), 0 );
259273 StringValue (string );
260274 rb_encoding * encoding = rb_enc_get (string );
261275
262- rbs_parser_t * parser = alloc_parser_from_buffer (buffer , FIX2INT (start_pos ), FIX2INT (end_pos ));
276+ rbs_parser_t * parser = alloc_parser_from_buffer_with_options (buffer , FIX2INT (start_pos ), FIX2INT (end_pos ), parser_options ( enable_forwarding_params ));
263277 declare_type_variables (parser , variables , buffer );
264278 struct parse_method_type_arg arg = {
265279 .buffer = buffer ,
@@ -293,12 +307,12 @@ static VALUE parse_signature_try(VALUE a) {
293307 return rbs_struct_to_ruby_value (ctx , (rbs_node_t * ) signature );
294308}
295309
296- static VALUE rbsparser_parse_signature (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos ) {
310+ static VALUE rbsparser_parse_signature (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos , VALUE enable_forwarding_params ) {
297311 VALUE string = rb_funcall (buffer , rb_intern ("content" ), 0 );
298312 StringValue (string );
299313 rb_encoding * encoding = rb_enc_get (string );
300314
301- rbs_parser_t * parser = alloc_parser_from_buffer (buffer , FIX2INT (start_pos ), FIX2INT (end_pos ));
315+ rbs_parser_t * parser = alloc_parser_from_buffer_with_options (buffer , FIX2INT (start_pos ), FIX2INT (end_pos ), parser_options ( enable_forwarding_params ));
302316 struct parse_signature_arg arg = {
303317 .buffer = buffer ,
304318 .encoding = encoding ,
@@ -386,12 +400,12 @@ static VALUE parse_method_type_to_bytes_try(VALUE a) {
386400 return serialized_node_to_string (parser , (rbs_node_t * ) method_type );
387401}
388402
389- static VALUE rbsparser_parse_method_type_to_bytes (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos , VALUE variables , VALUE require_eof ) {
403+ static VALUE rbsparser_parse_method_type_to_bytes (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos , VALUE variables , VALUE require_eof , VALUE enable_forwarding_params ) {
390404 VALUE string = rb_funcall (buffer , rb_intern ("content" ), 0 );
391405 StringValue (string );
392406 rb_encoding * encoding = rb_enc_get (string );
393407
394- rbs_parser_t * parser = alloc_parser_from_buffer (buffer , FIX2INT (start_pos ), FIX2INT (end_pos ));
408+ rbs_parser_t * parser = alloc_parser_from_buffer_with_options (buffer , FIX2INT (start_pos ), FIX2INT (end_pos ), parser_options ( enable_forwarding_params ));
395409 declare_type_variables (parser , variables , buffer );
396410 struct parse_method_type_arg arg = {
397411 .buffer = buffer ,
@@ -419,12 +433,12 @@ static VALUE parse_signature_to_bytes_try(VALUE a) {
419433 return serialized_node_to_string (parser , (rbs_node_t * ) signature );
420434}
421435
422- static VALUE rbsparser_parse_signature_to_bytes (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos ) {
436+ static VALUE rbsparser_parse_signature_to_bytes (VALUE self , VALUE buffer , VALUE start_pos , VALUE end_pos , VALUE enable_forwarding_params ) {
423437 VALUE string = rb_funcall (buffer , rb_intern ("content" ), 0 );
424438 StringValue (string );
425439 rb_encoding * encoding = rb_enc_get (string );
426440
427- rbs_parser_t * parser = alloc_parser_from_buffer (buffer , FIX2INT (start_pos ), FIX2INT (end_pos ));
441+ rbs_parser_t * parser = alloc_parser_from_buffer_with_options (buffer , FIX2INT (start_pos ), FIX2INT (end_pos ), parser_options ( enable_forwarding_params ));
428442 struct parse_signature_arg arg = {
429443 .buffer = buffer ,
430444 .encoding = encoding ,
@@ -609,11 +623,11 @@ void rbs__init_parser(void) {
609623 rb_gc_register_mark_object (EMPTY_HASH );
610624
611625 rb_define_singleton_method (RBS_Parser , "_parse_type" , rbsparser_parse_type , 8 );
612- rb_define_singleton_method (RBS_Parser , "_parse_method_type" , rbsparser_parse_method_type , 5 );
613- rb_define_singleton_method (RBS_Parser , "_parse_signature" , rbsparser_parse_signature , 3 );
626+ rb_define_singleton_method (RBS_Parser , "_parse_method_type" , rbsparser_parse_method_type , 6 );
627+ rb_define_singleton_method (RBS_Parser , "_parse_signature" , rbsparser_parse_signature , 4 );
614628 rb_define_singleton_method (RBS_Parser , "_parse_type_to_bytes" , rbsparser_parse_type_to_bytes , 8 );
615- rb_define_singleton_method (RBS_Parser , "_parse_method_type_to_bytes" , rbsparser_parse_method_type_to_bytes , 5 );
616- rb_define_singleton_method (RBS_Parser , "_parse_signature_to_bytes" , rbsparser_parse_signature_to_bytes , 3 );
629+ rb_define_singleton_method (RBS_Parser , "_parse_method_type_to_bytes" , rbsparser_parse_method_type_to_bytes , 6 );
630+ rb_define_singleton_method (RBS_Parser , "_parse_signature_to_bytes" , rbsparser_parse_signature_to_bytes , 4 );
617631 rb_define_singleton_method (RBS_Parser , "_parse_type_params" , rbsparser_parse_type_params , 4 );
618632 rb_define_singleton_method (RBS_Parser , "_parse_inline_leading_annotation" , rbsparser_parse_inline_leading_annotation , 4 );
619633 rb_define_singleton_method (RBS_Parser , "_parse_inline_trailing_annotation" , rbsparser_parse_inline_trailing_annotation , 4 );
0 commit comments