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: treat L"string" as a single token



details:   https://anonhg.NetBSD.org/src/rev/f366794487fe
branches:  trunk
changeset: 1026546:f366794487fe
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 28 14:29:03 2021 +0000

description:
indent: treat L"string" as a single token

There is never whitespace between the 'L' and the string literal or the
character constant. There might be a backslash-newline between them, but
that case was not handled before either.

No functional change.

diffstat:

 distrib/sets/lists/tests/mi               |   4 ++--
 tests/usr.bin/indent/Makefile             |   3 +--
 tests/usr.bin/indent/lsym_string_prefix.c |  18 ------------------
 usr.bin/indent/indent.c                   |  15 ++-------------
 usr.bin/indent/indent.h                   |   3 +--
 usr.bin/indent/lexi.c                     |  21 ++++++++++++++-------
 6 files changed, 20 insertions(+), 44 deletions(-)

diffs (171 lines):

diff -r 65cda4ad7e68 -r f366794487fe distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Nov 28 11:49:10 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Nov 28 14:29:03 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1168 2021/11/18 21:19:18 rillig Exp $
+# $NetBSD: mi,v 1.1169 2021/11/28 14:29:03 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4823,7 +4823,7 @@
 ./usr/tests/usr.bin/indent/lsym_semicolon.c                            tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/lsym_sizeof.c                               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/lsym_storage_class.c                                tests-usr.bin-tests     compattestfile,atf
-./usr/tests/usr.bin/indent/lsym_string_prefix.c                                tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/indent/lsym_string_prefix.c                                tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/lsym_switch.c                               tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/lsym_tag.c                                  tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/lsym_type_in_parentheses.c                  tests-usr.bin-tests     compattestfile,atf
diff -r 65cda4ad7e68 -r f366794487fe tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile     Sun Nov 28 11:49:10 2021 +0000
+++ b/tests/usr.bin/indent/Makefile     Sun Nov 28 14:29:03 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.34 2021/11/18 21:19:19 rillig Exp $
+#      $NetBSD: Makefile,v 1.35 2021/11/28 14:29:03 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -43,7 +43,6 @@
 FILES+=                lsym_semicolon.c
 FILES+=                lsym_sizeof.c
 FILES+=                lsym_storage_class.c
-FILES+=                lsym_string_prefix.c
 FILES+=                lsym_switch.c
 FILES+=                lsym_tag.c
 FILES+=                lsym_type_in_parentheses.c
diff -r 65cda4ad7e68 -r f366794487fe tests/usr.bin/indent/lsym_string_prefix.c
--- a/tests/usr.bin/indent/lsym_string_prefix.c Sun Nov 28 11:49:10 2021 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-/* $NetBSD: lsym_string_prefix.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
-/* $FreeBSD$ */
-
-/*
- * Tests for the token lsym_string_prefix, which represents the prefix 'L' for
- * string literals of type wchar_t.
- *
- * TODO: Try to merge this token into lsym_word.
- *
- * See also:
- *     lsym_word.c             for string literals
- */
-
-#indent input
-// TODO: add input
-#indent end
-
-#indent run-equals-input
diff -r 65cda4ad7e68 -r f366794487fe usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sun Nov 28 11:49:10 2021 +0000
+++ b/usr.bin/indent/indent.c   Sun Nov 28 14:29:03 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.238 2021/11/28 11:49:10 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.239 2021/11/28 14:29:03 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.238 2021/11/28 11:49:10 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.239 2021/11/28 14:29:03 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -1120,13 +1120,6 @@
 }
 
 static void
-process_string_prefix(void)
-{
-    copy_token();
-    ps.want_blank = false;
-}
-
-static void
 process_period(void)
 {
     if (code.e > code.s && code.e[-1] == ',')
@@ -1440,10 +1433,6 @@
                ps.want_blank = true;
            break;
 
-       case lsym_string_prefix:
-           process_string_prefix();
-           break;
-
        case lsym_period:
            process_period();
            break;
diff -r 65cda4ad7e68 -r f366794487fe usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sun Nov 28 11:49:10 2021 +0000
+++ b/usr.bin/indent/indent.h   Sun Nov 28 14:29:03 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.106 2021/11/28 11:49:10 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.107 2021/11/28 14:29:03 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -96,7 +96,6 @@
     lsym_type_in_parentheses,
     lsym_tag,                  /* 'struct', 'union' or 'enum' */
     lsym_case_label,           /* 'case' or 'default' */
-    lsym_string_prefix,                /* 'L' */
     lsym_sizeof,
     lsym_offsetof,
     lsym_word,                 /* identifier, constant or string */
diff -r 65cda4ad7e68 -r f366794487fe usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Sun Nov 28 11:49:10 2021 +0000
+++ b/usr.bin/indent/lexi.c     Sun Nov 28 14:29:03 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.166 2021/11/27 20:58:16 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.167 2021/11/28 14:29:03 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.166 2021/11/27 20:58:16 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.167 2021/11/28 14:29:03 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -219,7 +219,6 @@
        "type_in_parentheses",
        "tag",
        "case_label",
-       "string_prefix",
        "sizeof",
        "offsetof",
        "word",
@@ -500,15 +499,23 @@
        lex_number();
     } else if (is_identifier_part(inp_peek())) {
        lex_word();
+
+       if (token.s[0] == 'L' && token.e - token.s == 1 &&
+               (inp_peek() == '"' || inp_peek() == '\'')) {
+           token_add_char(inp_next());
+           lex_char_or_string();
+           ps.next_unary = false;
+
+           check_size_token(1);
+           *token.e = '\0';
+
+           return lsym_word;
+       }
     } else
        return lsym_eof;        /* just as a placeholder */
 
     *token.e = '\0';
 
-    if (token.s[0] == 'L' && token.s[1] == '\0' &&
-           (inp_peek() == '"' || inp_peek() == '\''))
-       return lsym_string_prefix;
-
     while (ch_isblank(inp_peek()))
        inp_skip();
 



Home | Main Index | Thread Index | Old Index