indent: fix line break between semicolon and brace

This commit is contained in:
rillig 2023-06-10 18:46:42 +00:00
parent 3d124ccbbf
commit bae713c412
3 changed files with 21 additions and 21 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: lsym_if.c,v 1.5 2023/06/10 16:43:56 rillig Exp $ */
/* $NetBSD: lsym_if.c,v 1.6 2023/06/10 18:46:42 rillig Exp $ */
/*
* Tests for the token lsym_if, which represents the keyword 'if' that starts
@ -38,8 +38,8 @@ function(void)
if (0)
if (1)
if (2)
// $ FIXME: The '{' must be on a separate line, with indentation 8.
stmt(); {
}
stmt();
{
}
}
//indent end

View File

@ -1,4 +1,4 @@
/* $NetBSD: debug.c,v 1.50 2023/06/10 16:43:55 rillig Exp $ */
/* $NetBSD: debug.c,v 1.51 2023/06/10 18:46:42 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: debug.c,v 1.50 2023/06/10 16:43:55 rillig Exp $");
__RCSID("$NetBSD: debug.c,v 1.51 2023/06/10 18:46:42 rillig Exp $");
#include <stdarg.h>
#include <string.h>
@ -395,6 +395,6 @@ debug_psyms_stack(const char *situation)
for (int i = 0; i <= psyms->top; ++i)
debug_printf(" %d %s",
psyms->ind_level[i], psym_name[psyms->sym[i]]);
debug_blank_line();
debug_println("");
}
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: indent.c,v 1.354 2023/06/10 16:43:55 rillig Exp $ */
/* $NetBSD: indent.c,v 1.355 2023/06/10 18:46:42 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: indent.c,v 1.354 2023/06/10 16:43:55 rillig Exp $");
__RCSID("$NetBSD: indent.c,v 1.355 2023/06/10 18:46:42 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@ -314,19 +314,16 @@ set_initial_indentation(void)
ps.ind_level = ps.ind_level_follow = ind / opt.indent_size;
}
static void
maybe_break_line(lexer_symbol lsym)
static bool
should_break_line(lexer_symbol lsym)
{
if (!ps.force_nl)
return;
if (lsym == lsym_semicolon)
return;
if (lsym == lsym_lbrace && opt.brace_same_line
&& ps.prev_lsym != lsym_lbrace)
return;
output_line();
ps.force_nl = false;
return false;
if (ps.prev_lsym == lsym_lbrace || ps.prev_lsym == lsym_semicolon)
return true;
if (lsym == lsym_lbrace && opt.brace_same_line)
return false;
return true;
}
static void
@ -1051,7 +1048,10 @@ indent(void)
else if (lsym == lsym_comment) {
/* no special processing */
} else {
maybe_break_line(lsym);
if (ps.force_nl && should_break_line(lsym)) {
ps.force_nl = false;
output_line();
}
ps.in_stmt_or_decl = true;
if (com.len > 0)
move_com_to_code(lsym);