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: fix debug output of the parser symbol...



details:   https://anonhg.NetBSD.org/src/rev/a6c0bb8d7ae8
branches:  trunk
changeset: 376203:a6c0bb8d7ae8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 04 17:02:06 2023 +0000

description:
indent: fix debug output of the parser symbol stack

Even though the stack always contains a stmt_list as first element,
print it nevertheless to avoid confusion about starting at index 1, and
to provide the full picture.

diffstat:

 usr.bin/indent/debug.c  |   8 +++-----
 usr.bin/indent/indent.h |  10 +++++++---
 2 files changed, 10 insertions(+), 8 deletions(-)

diffs (56 lines):

diff -r 87e2021180e3 -r a6c0bb8d7ae8 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Sun Jun 04 16:53:59 2023 +0000
+++ b/usr.bin/indent/debug.c    Sun Jun 04 17:02:06 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.31 2023/06/04 14:20:00 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.32 2023/06/04 17:02:06 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.31 2023/06/04 14:20:00 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.32 2023/06/04 17:02:06 rillig Exp $");
 
 #include <stdarg.h>
 
@@ -348,10 +348,8 @@ void
 debug_parse_stack(const char *situation)
 {
        printf("parse stack %s:", situation);
-       for (int i = 1; i <= ps.tos; ++i)
+       for (int i = 0; i <= ps.tos; ++i)
                printf(" %s %d", psym_name[ps.s_sym[i]], ps.s_ind_level[i]);
-       if (ps.tos == 0)
-               printf(" empty");
        printf("\n");
 }
 #endif
diff -r 87e2021180e3 -r a6c0bb8d7ae8 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sun Jun 04 16:53:59 2023 +0000
+++ b/usr.bin/indent/indent.h   Sun Jun 04 17:02:06 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.168 2023/06/04 14:20:00 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.169 2023/06/04 17:02:06 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -112,10 +112,14 @@ typedef enum lexer_symbol {
        lsym_return,
 } lexer_symbol;
 
+/*
+ * Structure of the source code, in terms of declarations, statements and
+ * braces; used to determine the indentation level of these parts.
+ */
 typedef enum parser_symbol {
-       psym_0,                 /* a placeholder */
+       psym_0,                 /* a placeholder; not stored on the stack */
        psym_lbrace,
-       psym_rbrace,
+       psym_rbrace,            /* not stored on the stack */
        psym_decl,
        psym_stmt,
        psym_stmt_list,



Home | Main Index | Thread Index | Old Index