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: remove backslash line continuation ou...



details:   https://anonhg.NetBSD.org/src/rev/472f10ea636d
branches:  trunk
changeset: 375361:472f10ea636d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 15 17:28:14 2023 +0000

description:
indent: remove backslash line continuation outside preprocessing

The indenter did not handle these backslashes well, interpreting them as
unary operators, and they are an edge case anyway.  Line continuations
in string literals and character constants are kept.

diffstat:

 tests/usr.bin/indent/lex_ident.c |   6 ++----
 usr.bin/indent/lexi.c            |  17 ++++++++++++-----
 2 files changed, 14 insertions(+), 9 deletions(-)

diffs (58 lines):

diff -r a828609c3c04 -r 472f10ea636d tests/usr.bin/indent/lex_ident.c
--- a/tests/usr.bin/indent/lex_ident.c  Mon May 15 17:06:05 2023 +0000
+++ b/tests/usr.bin/indent/lex_ident.c  Mon May 15 17:28:14 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex_ident.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: lex_ident.c,v 1.6 2023/05/15 17:28:14 rillig Exp $ */
 
 /*
  * Test lexing of word-like tokens, such as keywords, identifiers, numeric
@@ -43,9 +43,7 @@ 1234567890123456789012345678901234567890
 //indent end
 
 //indent run
-/* $ XXX: The indentation of the backslash is one short of a tab. */
-int           \
-               variable;
+int            variable;
 
 int
                no_backslash;
diff -r a828609c3c04 -r 472f10ea636d usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Mon May 15 17:06:05 2023 +0000
+++ b/usr.bin/indent/lexi.c     Mon May 15 17:28:14 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.189 2023/05/15 13:37:16 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.190 2023/05/15 17:28:14 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.189 2023/05/15 13:37:16 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.190 2023/05/15 17:28:14 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -476,9 +476,16 @@ lexi(void)
     ps.curr_col_1 = ps.next_col_1;
     ps.next_col_1 = false;
 
-    while (ch_isblank(inp_peek())) {
-       ps.curr_col_1 = false;
-       inp_skip();
+    for (;;) {
+       if (ch_isblank(inp_peek())) {
+           ps.curr_col_1 = false;
+           inp_skip();
+       } else if (inp_peek() == '\\' && inp_lookahead(1) == '\n') {
+           inp_skip();
+           inp_skip();
+           line_no++;
+       } else
+           break;
     }
 
     lexer_symbol alnum_lsym = lexi_alnum();



Home | Main Index | Thread Index | Old Index