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: do not parse '&&&&&&&' as a single bi...



details:   https://anonhg.NetBSD.org/src/rev/3900a4a2f194
branches:  trunk
changeset: 376217:3900a4a2f194
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 04 22:57:18 2023 +0000

description:
indent: do not parse '&&&&&&&' as a single binary operator

diffstat:

 tests/usr.bin/indent/lsym_binary_op.c |  20 ++++++++++++++------
 usr.bin/indent/lexi.c                 |  15 ++++++++-------
 2 files changed, 22 insertions(+), 13 deletions(-)

diffs (78 lines):

diff -r e33753094ede -r 3900a4a2f194 tests/usr.bin/indent/lsym_binary_op.c
--- a/tests/usr.bin/indent/lsym_binary_op.c     Sun Jun 04 22:36:10 2023 +0000
+++ b/tests/usr.bin/indent/lsym_binary_op.c     Sun Jun 04 22:57:18 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_binary_op.c,v 1.10 2023/06/04 22:36:10 rillig Exp $ */
+/* $NetBSD: lsym_binary_op.c,v 1.11 2023/06/04 22:57:18 rillig Exp $ */
 
 /*
  * Tests for the token lsym_binary_op, which represents a binary operator in
@@ -77,10 +77,9 @@ int var = expr * *ptr;
 
 
 /*
- * When indent tokenizes some operators, it allows for
- * arbitrary repetitions of the operator character, followed by an
- * arbitrary amount of '='.  This is used for operators like '&&' or
- * '|||==='.
+ * Before 2023-06-04, indent allowed for arbitrary repetitions of some operator
+ * characters, followed by an arbitrary amount of '='.  This could be used for
+ * operators like '&&' or '|||==='.
  *
  * Before 2021-03-07 22:11:01, the comment '//' was treated as a binary
  * operator as well, and so was the comment '/////', leading to unexpected
@@ -99,7 +98,16 @@ long_run_of_operators(void)
 }
 //indent end
 
-//indent run-equals-input
+//indent run
+void
+long_run_of_operators(void)
+{
+       if (a && && && &b)
+               return;
+       if (a || |= == b)
+               return;
+}
+//indent end
 
 
 /*
diff -r e33753094ede -r 3900a4a2f194 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Sun Jun 04 22:36:10 2023 +0000
+++ b/usr.bin/indent/lexi.c     Sun Jun 04 22:57:18 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.213 2023/06/04 22:36:10 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.214 2023/06/04 22:57:18 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.213 2023/06/04 22:36:10 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.214 2023/06/04 22:57:18 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -667,12 +667,13 @@ lexi(void)
                        break;
                }
 
-               /* things like '||', '&&', '<<=', 'int *****i' */
-               while (inp_p[0] == token.s[token.len - 1]
-                   || inp_p[0] == '=')
-                       token_add_char(*inp_p++);
+               /* things like '||', '&&', '<<=' */
+               lsym = ps.next_unary ? lsym_unary_op : lsym_binary_op;
+               if (inp_p[0] == token.s[token.len - 1])
+                       token_add_char(*inp_p++), lsym = lsym_binary_op;
+               if (inp_p[0] == '=')
+                       token_add_char(*inp_p++), lsym = lsym_binary_op;
 
-               lsym = ps.next_unary ? lsym_unary_op : lsym_binary_op;
                next_unary = true;
        }
 



Home | Main Index | Thread Index | Old Index