From 41e8ba01ae644d10e6aebc832fc616e1af8e7159 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Mon, 31 Jul 2023 10:48:17 -0400 Subject: [PATCH] [ruby/yarp] Mark locations in the tree where newlines can occur https://github.com/ruby/yarp/commit/479e835756 --- yarp/yarp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/yarp/yarp.c b/yarp/yarp.c index 622da66fbc..f8301daa6b 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -2202,7 +2202,7 @@ yp_if_node_create(yp_parser_t *parser, *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE, + .type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE, .location = { .start = if_keyword->start, .end = end @@ -2228,7 +2228,7 @@ yp_if_node_modifier_create(yp_parser_t *parser, yp_node_t *statement, const yp_t *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE, + .type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE, .location = { .start = statement->location.start, .end = predicate->location.end @@ -2260,7 +2260,7 @@ yp_if_node_ternary_create(yp_parser_t *parser, yp_node_t *predicate, yp_node_t * *node = (yp_if_node_t) { { - .type = YP_NODE_IF_NODE, + .type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE, .location = { .start = predicate->location.start, .end = false_expression->location.end, @@ -3683,6 +3683,9 @@ yp_statements_node_body_append(yp_statements_node_t *node, yp_node_t *statement) yp_node_list_append(&node->body, statement); node->base.location.end = statement->location.end; + + // Every statement gets marked as a place where a newline can occur. + statement->type |= YP_NODE_FLAG_NEWLINE; } // Allocate a new StringConcatNode node. @@ -3913,7 +3916,7 @@ yp_unless_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_node_t *node = (yp_unless_node_t) { { - .type = YP_NODE_UNLESS_NODE, + .type = YP_NODE_UNLESS_NODE | YP_NODE_FLAG_NEWLINE, .location = { .start = keyword->start, .end = end @@ -3939,7 +3942,7 @@ yp_unless_node_modifier_create(yp_parser_t *parser, yp_node_t *statement, const *node = (yp_unless_node_t) { { - .type = YP_NODE_UNLESS_NODE, + .type = YP_NODE_UNLESS_NODE | YP_NODE_FLAG_NEWLINE, .location = { .start = statement->location.start, .end = predicate->location.end