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: merge duplicate code into is_identifi...



details:   https://anonhg.NetBSD.org/src/rev/668fc06b383f
branches:  trunk
changeset: 1026339:668fc06b383f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Nov 19 19:15:55 2021 +0000

description:
indent: merge duplicate code into is_identifier_part

No functional change.

diffstat:

 usr.bin/indent/lexi.c |  22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diffs (74 lines):

diff -r 988b86f7f21c -r 668fc06b383f usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Fri Nov 19 18:55:10 2021 +0000
+++ b/usr.bin/indent/lexi.c     Fri Nov 19 19:15:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.144 2021/11/19 18:52:32 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.145 2021/11/19 19:15:55 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.144 2021/11/19 18:52:32 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.145 2021/11/19 19:15:55 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -276,7 +276,7 @@
     debug_ps_bool(curr_col_1);
     debug_ps_bool(next_unary);
     if (strcmp(ps.procname, prev_ps.procname) != 0)
-       debug_println("    ps.procname = '%s'", ps.procname);
+       debug_println("    ps.procname = \"%s\"", ps.procname);
     debug_ps_bool(want_blank);
     debug_ps_int(paren_level);
     debug_ps_int(p_l_follow);
@@ -349,13 +349,16 @@
     }
 }
 
+static bool
+is_identifier_part(char ch)
+{
+    return isalnum((unsigned char)ch) || ch == '_' || ch == '$';
+}
+
 static void
 lex_word(void)
 {
-    while (isalnum((unsigned char)inp_peek()) ||
-           inp_peek() == '\\' ||
-           inp_peek() == '_' || inp_peek() == '$') {
-
+    while (is_identifier_part(inp_peek()) || inp_peek() == '\\' ) {
        if (inp_peek() == '\\') {
            if (inp_lookahead(1) == '\n') {
                inp_skip();
@@ -397,6 +400,7 @@
        return false;
     if (inp_peek() == '*' && inp_lookahead(1) != '=')
        goto maybe;
+    /* XXX: is_identifier_start */
     if (isalpha((unsigned char)inp_peek()))
        goto maybe;
     return false;
@@ -449,8 +453,7 @@
     if (isdigit((unsigned char)inp_peek()) ||
            (inp_peek() == '.' && isdigit((unsigned char)inp_lookahead(1)))) {
        lex_number();
-    } else if (isalnum((unsigned char)inp_peek()) ||
-           inp_peek() == '_' || inp_peek() == '$') {
+    } else if (is_identifier_part(inp_peek())) {
        lex_word();
     } else
        return lsym_eof;        /* just as a placeholder */
@@ -684,6 +687,7 @@
        if (ps.in_decl) {
            const char *tp = inp_p(), *e = inp_line_end();
 
+           /* XXX: is_identifier_start */
            while (tp < e && (isalpha((unsigned char)*tp) ||
                    isspace((unsigned char)*tp)))
                tp++;



Home | Main Index | Thread Index | Old Index