@@ -17049,9 +17049,9 @@ parse_pattern(pm_parser_t *parser, pm_constant_id_list_t *captures, uint8_t flag
17049
17049
}
17050
17050
17051
17051
if ((flags & PM_PARSE_PATTERN_MULTI) && match1(parser, PM_TOKEN_COMMA)) {
17052
- // If we have a comma, then we are now parsing either an array pattern or a
17053
- // find pattern. We need to parse all of the patterns, put them into a big
17054
- // list, and then determine which type of node we have.
17052
+ // If we have a comma, then we are now parsing either an array pattern
17053
+ // or a find pattern. We need to parse all of the patterns, put them
17054
+ // into a big list, and then determine which type of node we have.
17055
17055
pm_node_list_t nodes = { 0 };
17056
17056
pm_node_list_append(&nodes, node);
17057
17057
@@ -17067,9 +17067,9 @@ parse_pattern(pm_parser_t *parser, pm_constant_id_list_t *captures, uint8_t flag
17067
17067
if (accept1(parser, PM_TOKEN_USTAR)) {
17068
17068
node = (pm_node_t *) parse_pattern_rest(parser, captures);
17069
17069
17070
- // If we have already parsed a splat pattern, then this is an error. We
17071
- // will continue to parse the rest of the patterns, but we will indicate
17072
- // it as an error.
17070
+ // If we have already parsed a splat pattern, then this is an
17071
+ // error. We will continue to parse the rest of the patterns,
17072
+ // but we will indicate it as an error.
17073
17073
if (trailing_rest) {
17074
17074
pm_parser_err_previous(parser, PM_ERR_PATTERN_REST);
17075
17075
}
@@ -17082,20 +17082,28 @@ parse_pattern(pm_parser_t *parser, pm_constant_id_list_t *captures, uint8_t flag
17082
17082
pm_node_list_append(&nodes, node);
17083
17083
}
17084
17084
17085
- // If the first pattern and the last pattern are rest patterns, then we will
17086
- // call this a find pattern, regardless of how many rest patterns are in
17087
- // between because we know we already added the appropriate errors.
17088
- // Otherwise we will create an array pattern.
17089
- if (PM_NODE_TYPE_P(nodes.nodes[0], PM_SPLAT_NODE) && PM_NODE_TYPE_P(nodes.nodes[nodes.size - 1], PM_SPLAT_NODE)) {
17085
+ // If the first pattern and the last pattern are rest patterns, then we
17086
+ // will call this a find pattern, regardless of how many rest patterns
17087
+ // are in between because we know we already added the appropriate
17088
+ // errors. Otherwise we will create an array pattern.
17089
+ if (leading_rest && PM_NODE_TYPE_P(nodes.nodes[nodes.size - 1], PM_SPLAT_NODE)) {
17090
17090
node = (pm_node_t *) pm_find_pattern_node_create(parser, &nodes);
17091
+
17092
+ if (nodes.size == 2) {
17093
+ pm_parser_err_node(parser, node, PM_ERR_PATTERN_FIND_MISSING_INNER);
17094
+ }
17091
17095
} else {
17092
17096
node = (pm_node_t *) pm_array_pattern_node_node_list_create(parser, &nodes);
17097
+
17098
+ if (leading_rest && trailing_rest) {
17099
+ pm_parser_err_node(parser, node, PM_ERR_PATTERN_ARRAY_MULTIPLE_RESTS);
17100
+ }
17093
17101
}
17094
17102
17095
17103
xfree(nodes.nodes);
17096
17104
} else if (leading_rest) {
17097
- // Otherwise, if we parsed a single splat pattern, then we know we have an
17098
- // array pattern, so we can go ahead and create that node.
17105
+ // Otherwise, if we parsed a single splat pattern, then we know we have
17106
+ // an array pattern, so we can go ahead and create that node.
17099
17107
node = (pm_node_t *) pm_array_pattern_node_rest_create(parser, node);
17100
17108
}
17101
17109
0 commit comments