Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: fix duplicate space between comment a...



details:   https://anonhg.NetBSD.org/src/rev/9d38b5006397
branches:  trunk
changeset: 375369:9d38b5006397
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 15 20:30:20 2023 +0000

description:
indent: fix duplicate space between comment and binary operator

diffstat:

 tests/usr.bin/indent/lsym_comment.c |  21 ++++++++++++++++++++-
 usr.bin/indent/indent.c             |   6 +++---
 usr.bin/indent/indent.h             |   6 +++---
 3 files changed, 26 insertions(+), 7 deletions(-)

diffs (79 lines):

diff -r 6ca29fce2bf9 -r 9d38b5006397 tests/usr.bin/indent/lsym_comment.c
--- a/tests/usr.bin/indent/lsym_comment.c       Mon May 15 20:12:28 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comment.c       Mon May 15 20:30:20 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.11 2023/05/15 19:55:51 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.12 2023/05/15 20:30:20 rillig Exp $ */
 
 /*
  * Tests for the token lsym_comment, which starts a comment.
@@ -1078,3 +1078,22 @@ error*/
   * error
   */
 //indent end
+
+
+/*
+ * Ensure that there is exactly one space between the comment and the
+ * following binary operator.
+ */
+//indent input
+{
+a /* */ > b;
+a>b;
+}
+//indent end
+
+//indent run
+{
+       a /* */ > b;
+       a > b;
+}
+//indent end
diff -r 6ca29fce2bf9 -r 9d38b5006397 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon May 15 20:12:28 2023 +0000
+++ b/usr.bin/indent/indent.c   Mon May 15 20:30:20 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.281 2023/05/15 20:12:28 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.282 2023/05/15 20:30:20 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.281 2023/05/15 20:12:28 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.282 2023/05/15 20:30:20 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -539,7 +539,7 @@ process_unary_op(void)
 static void
 process_binary_op(void)
 {
-    if (code.len > 0)
+    if (code.len > 0 && ps.want_blank)
        buf_add_char(&code, ' ');
     buf_add_buf(&code, &token);
     ps.want_blank = true;
diff -r 6ca29fce2bf9 -r 9d38b5006397 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Mon May 15 20:12:28 2023 +0000
+++ b/usr.bin/indent/indent.h   Mon May 15 20:30:20 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.140 2023/05/15 20:12:28 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.141 2023/05/15 20:30:20 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -358,8 +358,8 @@ extern struct parser_state {
 
     /* Vertical spacing */
 
-    bool force_nl;             /* whether the next token is forced to go to
-                                * a new line; used after 'if (expr)' and
+    bool force_nl;             /* whether the next token is forced to go to a
+                                * new line; used after 'if (expr)' and in
                                 * similar situations; tokens like '{' may
                                 * ignore this */
 



Home | Main Index | Thread Index | Old Index