@@ -17407,9 +17407,21 @@ parse_yield(pm_parser_t *parser, const pm_node_t *node) {
17407
17407
* and the error callback.
17408
17408
*/
17409
17409
typedef struct {
17410
+ /** The parser that we are parsing the regular expression for. */
17410
17411
pm_parser_t *parser;
17412
+
17413
+ /** The start of the regular expression. */
17411
17414
const uint8_t *start;
17415
+
17416
+ /** The end of the regular expression. */
17412
17417
const uint8_t *end;
17418
+
17419
+ /**
17420
+ * Whether or not the source of the regular expression is shared. This
17421
+ * impacts the location of error messages, because if it is shared then we
17422
+ * can use the location directly and if it is not, then we use the bounds of
17423
+ * the regular expression itself.
17424
+ */
17413
17425
bool shared;
17414
17426
} parse_regular_expression_error_data_t;
17415
17427
@@ -20073,11 +20085,24 @@ parse_call_operator_write(pm_parser_t *parser, pm_call_node_t *call_node, const
20073
20085
* and the named capture callback.
20074
20086
*/
20075
20087
typedef struct {
20088
+ /** The parser that is parsing the regular expression. */
20076
20089
pm_parser_t *parser;
20077
- const pm_string_t *content;
20090
+
20091
+ /** The call node wrapping the regular expression node. */
20078
20092
pm_call_node_t *call;
20093
+
20094
+ /** The match write node that is being created. */
20079
20095
pm_match_write_node_t *match;
20096
+
20097
+ /** The list of names that have been parsed. */
20080
20098
pm_constant_id_list_t names;
20099
+
20100
+ /**
20101
+ * Whether the content of the regular expression is shared. This impacts
20102
+ * whether or not we used owned constants or shared constants in the
20103
+ * constant pool for the names of the captures.
20104
+ */
20105
+ bool shared;
20081
20106
} parse_regular_expression_named_capture_data_t;
20082
20107
20083
20108
/**
@@ -20089,7 +20114,6 @@ parse_regular_expression_named_capture(const pm_string_t *capture, void *data) {
20089
20114
parse_regular_expression_named_capture_data_t *callback_data = (parse_regular_expression_named_capture_data_t *) data;
20090
20115
20091
20116
pm_parser_t *parser = callback_data->parser;
20092
- const pm_string_t *content = callback_data->content;
20093
20117
pm_call_node_t *call = callback_data->call;
20094
20118
pm_constant_id_list_t *names = &callback_data->names;
20095
20119
@@ -20103,15 +20127,15 @@ parse_regular_expression_named_capture(const pm_string_t *capture, void *data) {
20103
20127
// not add it to the local table.
20104
20128
if (!pm_slice_is_valid_local(parser, source, source + length)) return;
20105
20129
20106
- if (content->type == PM_STRING_SHARED ) {
20130
+ if (callback_data->shared ) {
20107
20131
// If the unescaped string is a slice of the source, then we can
20108
20132
// copy the names directly. The pointers will line up.
20109
20133
location = (pm_location_t) { .start = source, .end = source + length };
20110
20134
name = pm_parser_constant_id_location(parser, location.start, location.end);
20111
20135
} else {
20112
20136
// Otherwise, the name is a slice of the malloc-ed owned string,
20113
20137
// in which case we need to copy it out into a new string.
20114
- location = call->receiver->location;
20138
+ location = (pm_location_t) { .start = call->receiver->location.start, .end = call->receiver->location.end } ;
20115
20139
20116
20140
void *memory = xmalloc(length);
20117
20141
if (memory == NULL) abort();
@@ -20157,9 +20181,9 @@ static pm_node_t *
20157
20181
parse_regular_expression_named_captures(pm_parser_t *parser, const pm_string_t *content, pm_call_node_t *call) {
20158
20182
parse_regular_expression_named_capture_data_t callback_data = {
20159
20183
.parser = parser,
20160
- .content = content,
20161
20184
.call = call,
20162
- .names = { 0 }
20185
+ .names = { 0 },
20186
+ .shared = content->type == PM_STRING_SHARED
20163
20187
};
20164
20188
20165
20189
parse_regular_expression_error_data_t error_data = {
0 commit comments