Module Name:    src
Committed By:   rillig
Date:           Sun Jun  4 22:57:18 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: lsym_binary_op.c
        src/usr.bin/indent: lexi.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/lsym_binary_op.c
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/indent/lexi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/lsym_binary_op.c
diff -u src/tests/usr.bin/indent/lsym_binary_op.c:1.10 src/tests/usr.bin/indent/lsym_binary_op.c:1.11
--- src/tests/usr.bin/indent/lsym_binary_op.c:1.10	Sun Jun  4 22:36:10 2023
+++ src/tests/usr.bin/indent/lsym_binary_op.c	Sun Jun  4 22:57:18 2023
@@ -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
 
 
 /*

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.213 src/usr.bin/indent/lexi.c:1.214
--- src/usr.bin/indent/lexi.c:1.213	Sun Jun  4 22:36:10 2023
+++ src/usr.bin/indent/lexi.c	Sun Jun  4 22:57:18 2023
@@ -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;
+
 		next_unary = true;
 	}
 

Reply via email to