Skip to content

Commit 9cbe6a9

Browse files
authored
Merge branch 'main' into zenspider__fix_ruby_parser_comments
2 parents bdf4269 + 6545f63 commit 9cbe6a9

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

src/prism.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,6 +3077,17 @@ pm_call_target_node_create(pm_parser_t *parser, pm_call_node_t *target) {
30773077
.message_loc = target->message_loc
30783078
};
30793079

3080+
/* It is possible to get here where we have parsed an invalid syntax tree
3081+
* where the call operator was not present. In that case we will have a
3082+
* problem because it is a required location. In this case we need to fill
3083+
* it in with a fake location so that the syntax tree remains valid. */
3084+
if (node->call_operator_loc.start == NULL) {
3085+
node->call_operator_loc = (pm_location_t) {
3086+
.start = target->base.location.start,
3087+
.end = target->base.location.start
3088+
};
3089+
}
3090+
30803091
// Here we're going to free the target, since it is no longer necessary.
30813092
// However, we don't want to call `pm_node_destroy` because we want to keep
30823093
// around all of its children since we just reused them.
@@ -4096,8 +4107,8 @@ pm_hash_pattern_node_node_list_create(pm_parser_t *parser, pm_node_list_t *eleme
40964107

40974108
if (elements->size > 0) {
40984109
if (rest) {
4099-
start = elements->nodes[0]->location.start;
4100-
end = rest->location.end;
4110+
start = MIN(rest->location.start, elements->nodes[0]->location.start);
4111+
end = MAX(rest->location.end, elements->nodes[elements->size - 1]->location.end);
41014112
} else {
41024113
start = elements->nodes[0]->location.start;
41034114
end = elements->nodes[elements->size - 1]->location.end;
@@ -4117,11 +4128,7 @@ pm_hash_pattern_node_node_list_create(pm_parser_t *parser, pm_node_list_t *eleme
41174128
.closing_loc = { 0 }
41184129
};
41194130

4120-
pm_node_t *element;
4121-
PM_NODE_LIST_FOREACH(elements, index, element) {
4122-
pm_node_list_append(&node->elements, element);
4123-
}
4124-
4131+
pm_node_list_concat(&node->elements, elements);
41254132
return node;
41264133
}
41274134

@@ -12024,7 +12031,10 @@ parser_lex(pm_parser_t *parser) {
1202412031
// string content.
1202512032
if (heredoc_lex_mode->indent == PM_HEREDOC_INDENT_TILDE) {
1202612033
const uint8_t *end = parser->current.end;
12027-
pm_newline_list_append(&parser->newline_list, end);
12034+
12035+
if (parser->heredoc_end == NULL) {
12036+
pm_newline_list_append(&parser->newline_list, end);
12037+
}
1202812038

1202912039
// Here we want the buffer to only
1203012040
// include up to the backslash.
@@ -12533,7 +12543,10 @@ pm_node_unreference_each(const pm_node_t *node, void *data) {
1253312543
);
1253412544
}
1253512545
parser->current_block_exits->size--;
12536-
return false;
12546+
12547+
/* Note returning true here because these nodes could have
12548+
* arguments that are themselves block exits. */
12549+
return true;
1253712550
}
1253812551

1253912552
index++;

0 commit comments

Comments
 (0)