@@ -455,16 +455,22 @@ rb_class_new_instance_freeze(int argc, const VALUE *argv, VALUE klass, bool free
455455 * Create a new Location instance from the given parser and bounds.
456456 */
457457static inline VALUE
458- parser_location (const pm_parser_t * parser , VALUE source , bool freeze , uint32_t start , uint32_t length ) {
458+ parser_location (VALUE source , bool freeze , uint32_t start , uint32_t length ) {
459459 VALUE argv [] = { source , LONG2FIX (start ), LONG2FIX (length ) };
460460 return rb_class_new_instance_freeze (3 , argv , rb_cPrismLocation , freeze );
461461}
462462
463+ /**
464+ * Create a new Location instance from the given parser and slice.
465+ */
466+ #define PARSER_LOCATION_SLICE (parser , source , freeze , slice ) \
467+ parser_location(source, freeze, slice.start, slice.length)
468+
463469/**
464470 * Create a new Location instance from the given parser and location.
465471 */
466472#define PARSER_LOCATION_LOC (parser , source , freeze , loc ) \
467- parser_location(parser, source, freeze, (uint32_t) (loc.start - parser->start), (uint32_t) (loc.end - loc.start))
473+ parser_location(source, freeze, (uint32_t) (loc.start - parser->start), (uint32_t) (loc.end - loc.start))
468474
469475/**
470476 * Build a new Comment instance from the given parser and comment.
@@ -500,9 +506,9 @@ parser_comments(const pm_parser_t *parser, VALUE source, bool freeze) {
500506 * Build a new MagicComment instance from the given parser and magic comment.
501507 */
502508static inline VALUE
503- parser_magic_comment (const pm_parser_t * parser , VALUE source , bool freeze , const pm_magic_comment_t * magic_comment ) {
504- VALUE key_loc = parser_location (parser , source , freeze , magic_comment -> key .start , magic_comment -> key .length );
505- VALUE value_loc = parser_location (parser , source , freeze , magic_comment -> value .start , magic_comment -> value .length );
509+ parser_magic_comment (VALUE source , bool freeze , const pm_magic_comment_t * magic_comment ) {
510+ VALUE key_loc = parser_location (source , freeze , magic_comment -> key .start , magic_comment -> key .length );
511+ VALUE value_loc = parser_location (source , freeze , magic_comment -> value .start , magic_comment -> value .length );
506512 VALUE argv [] = { key_loc , value_loc };
507513 return rb_class_new_instance_freeze (2 , argv , rb_cPrismMagicComment , freeze );
508514}
@@ -519,7 +525,7 @@ parser_magic_comments(const pm_parser_t *parser, VALUE source, bool freeze) {
519525 magic_comment != NULL ;
520526 magic_comment = (const pm_magic_comment_t * ) magic_comment -> node .next
521527 ) {
522- VALUE value = parser_magic_comment (parser , source , freeze , magic_comment );
528+ VALUE value = parser_magic_comment (source , freeze , magic_comment );
523529 rb_ary_push (magic_comments , value );
524530 }
525531
@@ -536,7 +542,7 @@ parser_data_loc(const pm_parser_t *parser, VALUE source, bool freeze) {
536542 if (parser -> data_loc .length == 0 ) {
537543 return Qnil ;
538544 } else {
539- return parser_location (parser , source , freeze , parser -> data_loc .start , parser -> data_loc .length );
545+ return parser_location (source , freeze , parser -> data_loc .start , parser -> data_loc .length );
540546 }
541547}
542548
@@ -554,7 +560,7 @@ parser_errors(const pm_parser_t *parser, rb_encoding *encoding, VALUE source, bo
554560 ) {
555561 VALUE type = ID2SYM (rb_intern (pm_diagnostic_id_human (error -> diag_id )));
556562 VALUE message = rb_obj_freeze (rb_enc_str_new_cstr (error -> message , encoding ));
557- VALUE location = PARSER_LOCATION_LOC (parser , source , freeze , error -> location );
563+ VALUE location = PARSER_LOCATION_SLICE (parser , source , freeze , error -> location );
558564
559565 VALUE level = Qnil ;
560566 switch (error -> level ) {
@@ -594,7 +600,7 @@ parser_warnings(const pm_parser_t *parser, rb_encoding *encoding, VALUE source,
594600 ) {
595601 VALUE type = ID2SYM (rb_intern (pm_diagnostic_id_human (warning -> diag_id )));
596602 VALUE message = rb_obj_freeze (rb_enc_str_new_cstr (warning -> message , encoding ));
597- VALUE location = PARSER_LOCATION_LOC (parser , source , freeze , warning -> location );
603+ VALUE location = PARSER_LOCATION_SLICE (parser , source , freeze , warning -> location );
598604
599605 VALUE level = Qnil ;
600606 switch (warning -> level ) {
0 commit comments