Module Name: src Committed By: rillig Date: Sun Jun 4 11:33:36 UTC 2023
Modified Files: src/usr.bin/indent: debug.c indent.c indent.h lexi.c Log Message: indent: use separate lexer symbols for the different kinds of ':' To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/usr.bin/indent/debug.c cvs rdiff -u -r1.319 -r1.320 src/usr.bin/indent/indent.c cvs rdiff -u -r1.164 -r1.165 src/usr.bin/indent/indent.h cvs rdiff -u -r1.207 -r1.208 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/usr.bin/indent/debug.c diff -u src/usr.bin/indent/debug.c:1.27 src/usr.bin/indent/debug.c:1.28 --- src/usr.bin/indent/debug.c:1.27 Sun Jun 4 11:09:18 2023 +++ src/usr.bin/indent/debug.c Sun Jun 4 11:33:36 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.27 2023/06/04 11:09:18 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.28 2023/06/04 11:33:36 rillig Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: debug.c,v 1.27 2023/06/04 11:09:18 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.28 2023/06/04 11:33:36 rillig Exp $"); #include <stdarg.h> @@ -60,7 +60,9 @@ const char *const lsym_name[] = { "binary_op", "postfix_op", "question", - "colon", + "'?:' colon", + "label colon", + "other colon", "comma", "semicolon", "typedef", Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.319 src/usr.bin/indent/indent.c:1.320 --- src/usr.bin/indent/indent.c:1.319 Sun Jun 4 11:09:18 2023 +++ src/usr.bin/indent/indent.c Sun Jun 4 11:33:36 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.319 2023/06/04 11:09:18 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.320 2023/06/04 11:33:36 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: indent.c,v 1.319 2023/06/04 11:09:18 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.320 2023/06/04 11:33:36 rillig Exp $"); #include <sys/param.h> #include <err.h> @@ -685,30 +685,23 @@ process_question(void) } static void -process_colon(void) +process_colon_question(void) { - if (ps.quest_level > 0) { /* part of a '?:' operator */ - ps.quest_level--; - if (code.len == 0) { - ps.in_stmt_cont = true; - ps.in_stmt_or_decl = true; - ps.in_decl = false; - } - if (ps.want_blank) - buf_add_char(&code, ' '); - buf_add_char(&code, ':'); - ps.want_blank = true; - return; - } - - if (ps.init_or_struct) { /* bit-field */ - buf_add_char(&code, ':'); - ps.want_blank = false; - return; + if (code.len == 0) { + ps.in_stmt_cont = true; + ps.in_stmt_or_decl = true; + ps.in_decl = false; } + if (ps.want_blank) + buf_add_char(&code, ' '); + buf_add_char(&code, ':'); + ps.want_blank = true; +} - buf_add_buf(&lab, &code); /* 'case' or 'default' or named label - */ +static void +process_colon_label(void) +{ + buf_add_buf(&lab, &code); buf_add_char(&lab, ':'); code.len = 0; @@ -721,6 +714,13 @@ process_colon(void) } static void +process_colon_other(void) +{ + buf_add_char(&code, ':'); + ps.want_blank = false; +} + +static void process_semicolon(void) { if (ps.decl_level == 0) @@ -1138,8 +1138,16 @@ process_lsym(lexer_symbol lsym) ps.seen_case = true; goto copy_token; - case lsym_colon: - process_colon(); + case lsym_colon_question: + process_colon_question(); + break; + + case lsym_colon_label: + process_colon_label(); + break; + + case lsym_colon_other: + process_colon_other(); break; case lsym_semicolon: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.164 src/usr.bin/indent/indent.h:1.165 --- src/usr.bin/indent/indent.h:1.164 Sun Jun 4 11:09:18 2023 +++ src/usr.bin/indent/indent.h Sun Jun 4 11:33:36 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.164 2023/06/04 11:09:18 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.165 2023/06/04 11:33:36 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -84,7 +84,12 @@ typedef enum lexer_symbol { lsym_binary_op, /* e.g. '*', '&', '<<', '&&' or '/=' */ lsym_postfix_op, /* trailing '++' or '--' */ lsym_question, /* the '?' from a '?:' expression */ - lsym_colon, + lsym_colon_question, /* the ':' from a '?:' expression */ + lsym_colon_label, /* the ':' after a label */ + lsym_colon_other, /* bit-fields, generic-association (C11), + * enum-type-specifier (C23), + * attribute-prefixed-token (C23), + * pp-prefixed-parameter (C23 6.10)*/ lsym_comma, lsym_semicolon, lsym_typedef, Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.207 src/usr.bin/indent/lexi.c:1.208 --- src/usr.bin/indent/lexi.c:1.207 Sun Jun 4 10:23:36 2023 +++ src/usr.bin/indent/lexi.c Sun Jun 4 11:33:36 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.207 2023/06/04 10:23:36 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.208 2023/06/04 11:33:36 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: lexi.c,v 1.207 2023/06/04 10:23:36 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.208 2023/06/04 11:33:36 rillig Exp $"); #include <stdlib.h> #include <string.h> @@ -561,7 +561,6 @@ lexi(void) case ')': lsym = lsym_rparen; next_unary = false; break; case ']': lsym = lsym_rbracket; next_unary = false; break; case '?': lsym = lsym_question; next_unary = true; break; - case ':': lsym = lsym_colon; next_unary = true; break; case ';': lsym = lsym_semicolon; next_unary = true; break; case '{': lsym = lsym_lbrace; next_unary = true; break; case '}': lsym = lsym_rbrace; next_unary = true; break; @@ -569,6 +568,15 @@ lexi(void) case '.': lsym = lsym_period; next_unary = false; break; /* INDENT ON */ + case ':': + lsym = ps.quest_level > 0 + ? (ps.quest_level--, lsym_colon_question) + : ps.init_or_struct + ? lsym_colon_other + : lsym_colon_label; + next_unary = true; + break; + case '\n': /* if data has been exhausted, the '\n' is a dummy. */ lsym = had_eof ? lsym_eof : lsym_newline;