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: use separate lexer symbols for the di...
details: https://anonhg.NetBSD.org/src/rev/e8b9d22de225
branches: trunk
changeset: 376194:e8b9d22de225
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jun 04 11:33:36 2023 +0000
description:
indent: use separate lexer symbols for the different kinds of ':'
diffstat:
usr.bin/indent/debug.c | 8 ++++--
usr.bin/indent/indent.c | 58 +++++++++++++++++++++++++++---------------------
usr.bin/indent/indent.h | 9 +++++-
usr.bin/indent/lexi.c | 14 +++++++++--
4 files changed, 56 insertions(+), 33 deletions(-)
diffs (190 lines):
diff -r 0b877c880e91 -r e8b9d22de225 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Sun Jun 04 11:09:18 2023 +0000
+++ b/usr.bin/indent/debug.c Sun Jun 04 11:33:36 2023 +0000
@@ -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",
diff -r 0b877c880e91 -r e8b9d22de225 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sun Jun 04 11:09:18 2023 +0000
+++ b/usr.bin/indent/indent.c Sun Jun 04 11:33:36 2023 +0000
@@ -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 (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;
+}
- if (ps.init_or_struct) { /* bit-field */
- buf_add_char(&code, ':');
- ps.want_blank = false;
- return;
- }
-
- 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:
diff -r 0b877c880e91 -r e8b9d22de225 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Sun Jun 04 11:09:18 2023 +0000
+++ b/usr.bin/indent/indent.h Sun Jun 04 11:33:36 2023 +0000
@@ -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,
diff -r 0b877c880e91 -r e8b9d22de225 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Sun Jun 04 11:09:18 2023 +0000
+++ b/usr.bin/indent/lexi.c Sun Jun 04 11:33:36 2023 +0000
@@ -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;
Home |
Main Index |
Thread Index |
Old Index