indent: fix spacing in for loop with declaration (since 2022-02-13)

This commit is contained in:
rillig 2023-05-15 08:56:39 +00:00
parent f382e6fe26
commit 89e0e636cf
2 changed files with 15 additions and 35 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: psym_for_exprs.c,v 1.5 2023/05/15 08:22:23 rillig Exp $ */
/* $NetBSD: psym_for_exprs.c,v 1.6 2023/05/15 08:56:39 rillig Exp $ */
/*
* Tests for the parser state psym_for_exprs, which represents the state after
@ -10,41 +10,20 @@
void
for_loops(void)
{
for (int i = 0; i < 10; i++)
printf("%d * %d = %d\n", i, 7, i * 7);
int i;
for (int i = 0; i < 10; i++) {
for (i = 0; i < 10; i++)
printf("%d * %d = %d\n", i, 7, i * 7);
for (i = 0; i < 10; i++) {
printf("%d * %d = %d\n", i, 7, i * 7);
}
for (int j = 0; j < 10; j++)
printf("%d * %d = %d\n", j, 7, j * 7);
for (int j = 0; j < 10; j++) {
printf("%d * %d = %d\n", j, 7, j * 7);
}
}
//indent end
//indent run
void
for_loops(void)
{
for (int i = 0; i < 10; i++)
printf("%d * %d = %d\n", i, 7, i * 7);
/* $ FIXME: Add space between ')' and '{'. */
for (int i = 0; i < 10; i++){
printf("%d * %d = %d\n", i, 7, i * 7);
}
}
//indent end
/*
* Since C99, the first expression of a 'for' loop may be a declaration, not
* only an expression.
*/
//indent input
void
small_scope(void)
{
for (int i = 0; i < 3; i++)
stmt();
}
//indent end
//indent run-equals-input
//indent run-equals-input -ldi0

View File

@ -1,4 +1,4 @@
/* $NetBSD: indent.c,v 1.271 2023/05/15 08:11:27 rillig Exp $ */
/* $NetBSD: indent.c,v 1.272 2023/05/15 08:56:39 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: indent.c,v 1.271 2023/05/15 08:11:27 rillig Exp $");
__RCSID("$NetBSD: indent.c,v 1.272 2023/05/15 08:56:39 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@ -483,6 +483,7 @@ unbalanced:
ps.in_stmt_or_decl = false;
parse(ps.spaced_expr_psym);
ps.spaced_expr_psym = psym_0;
ps.want_blank = true;
}
}