Skip to content

Commit

Permalink
Single line method bodies should not be marked as newline
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Jul 23, 2024
1 parent 3d39b79 commit 18a8597
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 67 deletions.
32 changes: 16 additions & 16 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -1886,7 +1886,7 @@ static pm_statements_node_t *
pm_statements_node_create(pm_parser_t *parser);

static void
pm_statements_node_body_append(pm_parser_t *parser, pm_statements_node_t *node, pm_node_t *statement);
pm_statements_node_body_append(pm_parser_t *parser, pm_statements_node_t *node, pm_node_t *statement, bool newline);

static size_t
pm_statements_node_body_length(pm_statements_node_t *node);
Expand Down Expand Up @@ -4721,7 +4721,7 @@ pm_if_node_modifier_create(pm_parser_t *parser, pm_node_t *statement, const pm_t
pm_if_node_t *node = PM_NODE_ALLOC(parser, pm_if_node_t);

pm_statements_node_t *statements = pm_statements_node_create(parser);
pm_statements_node_body_append(parser, statements, statement);
pm_statements_node_body_append(parser, statements, statement, true);

*node = (pm_if_node_t) {
{
Expand Down Expand Up @@ -4753,10 +4753,10 @@ pm_if_node_ternary_create(pm_parser_t *parser, pm_node_t *predicate, const pm_to
pm_conditional_predicate(parser, predicate, PM_CONDITIONAL_PREDICATE_TYPE_CONDITIONAL);

pm_statements_node_t *if_statements = pm_statements_node_create(parser);
pm_statements_node_body_append(parser, if_statements, true_expression);
pm_statements_node_body_append(parser, if_statements, true_expression, true);

pm_statements_node_t *else_statements = pm_statements_node_create(parser);
pm_statements_node_body_append(parser, else_statements, false_expression);
pm_statements_node_body_append(parser, else_statements, false_expression, true);

pm_token_t end_keyword = not_provided(parser);
pm_else_node_t *else_node = pm_else_node_create(parser, colon, else_statements, &end_keyword);
Expand Down Expand Up @@ -6959,7 +6959,7 @@ pm_statements_node_body_update(pm_statements_node_t *node, pm_node_t *statement)
* Append a new node to the given StatementsNode node's body.
*/
static void
pm_statements_node_body_append(pm_parser_t *parser, pm_statements_node_t *node, pm_node_t *statement) {
pm_statements_node_body_append(pm_parser_t *parser, pm_statements_node_t *node, pm_node_t *statement, bool newline) {
pm_statements_node_body_update(node, statement);

if (node->body.size > 0) {
Expand All @@ -6979,7 +6979,7 @@ pm_statements_node_body_append(pm_parser_t *parser, pm_statements_node_t *node,
}

pm_node_list_append(&node->body, statement);
pm_node_flag_set(statement, PM_NODE_FLAG_NEWLINE);
if (newline) pm_node_flag_set(statement, PM_NODE_FLAG_NEWLINE);
}

/**
Expand Down Expand Up @@ -7597,7 +7597,7 @@ pm_unless_node_modifier_create(pm_parser_t *parser, pm_node_t *statement, const
pm_unless_node_t *node = PM_NODE_ALLOC(parser, pm_unless_node_t);

pm_statements_node_t *statements = pm_statements_node_create(parser);
pm_statements_node_body_append(parser, statements, statement);
pm_statements_node_body_append(parser, statements, statement, true);

*node = (pm_unless_node_t) {
{
Expand Down Expand Up @@ -13754,7 +13754,7 @@ parse_statements(pm_parser_t *parser, pm_context_t context) {

while (true) {
pm_node_t *node = parse_expression(parser, PM_BINDING_POWER_STATEMENT, true, PM_ERR_CANNOT_PARSE_EXPRESSION);
pm_statements_node_body_append(parser, statements, node);
pm_statements_node_body_append(parser, statements, node, true);

// If we're recovering from a syntax error, then we need to stop parsing
// the statements now.
Expand Down Expand Up @@ -17940,7 +17940,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
// and we didn't return a multiple assignment node, then we can return a
// regular parentheses node now.
pm_statements_node_t *statements = pm_statements_node_create(parser);
pm_statements_node_body_append(parser, statements, statement);
pm_statements_node_body_append(parser, statements, statement, true);

return (pm_node_t *) pm_parentheses_node_create(parser, &opening, (pm_node_t *) statements, &parser->previous);
}
Expand All @@ -17950,7 +17950,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
// We'll do that here.
context_push(parser, PM_CONTEXT_PARENS);
pm_statements_node_t *statements = pm_statements_node_create(parser);
pm_statements_node_body_append(parser, statements, statement);
pm_statements_node_body_append(parser, statements, statement, true);

// If we didn't find a terminator and we didn't find a right
// parenthesis, then this is a syntax error.
Expand All @@ -17961,7 +17961,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
// Parse each statement within the parentheses.
while (true) {
pm_node_t *node = parse_expression(parser, PM_BINDING_POWER_STATEMENT, true, PM_ERR_CANNOT_PARSE_EXPRESSION);
pm_statements_node_body_append(parser, statements, node);
pm_statements_node_body_append(parser, statements, node, true);

// If we're recovering from a syntax error, then we need to stop
// parsing the statements now.
Expand Down Expand Up @@ -19123,7 +19123,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
statement = (pm_node_t *) pm_rescue_modifier_node_create(parser, statement, &rescue_keyword, value);
}

pm_statements_node_body_append(parser, (pm_statements_node_t *) statements, statement);
pm_statements_node_body_append(parser, (pm_statements_node_t *) statements, statement, false);
pm_do_loop_stack_pop(parser);
context_pop(parser);
end_keyword = not_provided(parser);
Expand Down Expand Up @@ -21190,15 +21190,15 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
case PM_TOKEN_KEYWORD_UNTIL_MODIFIER: {
parser_lex(parser);
pm_statements_node_t *statements = pm_statements_node_create(parser);
pm_statements_node_body_append(parser, statements, node);
pm_statements_node_body_append(parser, statements, node, true);

pm_node_t *predicate = parse_value_expression(parser, binding_power, true, PM_ERR_CONDITIONAL_UNTIL_PREDICATE);
return (pm_node_t *) pm_until_node_modifier_create(parser, &token, predicate, statements, PM_NODE_TYPE_P(node, PM_BEGIN_NODE) ? PM_LOOP_FLAGS_BEGIN_MODIFIER : 0);
}
case PM_TOKEN_KEYWORD_WHILE_MODIFIER: {
parser_lex(parser);
pm_statements_node_t *statements = pm_statements_node_create(parser);
pm_statements_node_body_append(parser, statements, node);
pm_statements_node_body_append(parser, statements, node, true);

pm_node_t *predicate = parse_value_expression(parser, binding_power, true, PM_ERR_CONDITIONAL_WHILE_PREDICATE);
return (pm_node_t *) pm_while_node_modifier_create(parser, &token, predicate, statements, PM_NODE_TYPE_P(node, PM_BEGIN_NODE) ? PM_LOOP_FLAGS_BEGIN_MODIFIER : 0);
Expand Down Expand Up @@ -21566,7 +21566,7 @@ wrap_statements(pm_parser_t *parser, pm_statements_node_t *statements) {
parser,
arguments,
pm_parser_constant_id_constant(parser, "print", 5)
));
), true);
}

if (PM_PARSER_COMMAND_LINE_OPTION_N(parser)) {
Expand Down Expand Up @@ -21612,7 +21612,7 @@ wrap_statements(pm_parser_t *parser, pm_statements_node_t *statements) {
parser,
(pm_node_t *) pm_call_node_fcall_synthesized_create(parser, arguments, pm_parser_constant_id_constant(parser, "gets", 4)),
statements
));
), true);

statements = wrapped_statements;
}
Expand Down
2 changes: 1 addition & 1 deletion test/prism/snapshots/command_method_call.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/prism/snapshots/endless_methods.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions test/prism/snapshots/methods.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/regex.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defn_endless_command.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defn_oneliner.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defn_oneliner_eq2.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defn_oneliner_noargs.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defn_oneliner_rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defs_endless_command.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defs_oneliner.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defs_oneliner_eq2.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/prism/snapshots/seattlerb/defs_oneliner_rescue.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 18a8597

Please sign in to comment.