From 6bf97c9eba2c36c8e287d2244899fb2f1a03129f Mon Sep 17 00:00:00 2001 From: rillig Date: Sun, 4 Jun 2023 22:36:10 +0000 Subject: [PATCH] indent: fix '*=' to be a binary operator, not a unary one --- tests/usr.bin/indent/lsym_binary_op.c | 7 +++++-- usr.bin/indent/lexi.c | 17 ++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/usr.bin/indent/lsym_binary_op.c b/tests/usr.bin/indent/lsym_binary_op.c index c5b1587e0ae7..f73fbe502369 100644 --- a/tests/usr.bin/indent/lsym_binary_op.c +++ b/tests/usr.bin/indent/lsym_binary_op.c @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_binary_op.c,v 1.9 2023/06/04 22:20:04 rillig Exp $ */ +/* $NetBSD: lsym_binary_op.c,v 1.10 2023/06/04 22:36:10 rillig Exp $ */ /* * Tests for the token lsym_binary_op, which represents a binary operator in @@ -183,10 +183,13 @@ int x = arr[3] * y; //indent end +/* + * Ensure that after an assignment, a '*=' operator is properly spaced, like + * any other binary operator. + */ //indent input { a = a; -// $ FIXME: The first '*=' is categorized as 'unary_op token "*"'. a *= b *= c; } //indent end diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c index cf918c916d2d..62ea386fd776 100644 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.212 2023/06/04 20:51:19 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.213 2023/06/04 22:36:10 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include -__RCSID("$NetBSD: lexi.c,v 1.212 2023/06/04 20:51:19 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.213 2023/06/04 22:36:10 rillig Exp $"); #include #include @@ -643,16 +643,15 @@ lexi(void) break; case '*': - if (is_asterisk_unary()) { + if (inp_p[0] == '=') { + token_add_char(*inp_p++); + lsym = lsym_binary_op; + } else if (is_asterisk_unary()) { lex_asterisk_unary(); lsym = lsym_unary_op; - next_unary = true; - } else { - if (inp_p[0] == '=') - token_add_char(*inp_p++); + } else lsym = lsym_binary_op; - next_unary = true; - } + next_unary = true; break; default: