Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent tests/indent: test pushing the placeholder sy...



details:   https://anonhg.NetBSD.org/src/rev/d77d17bdf4ee
branches:  trunk
changeset: 374786:d77d17bdf4ee
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri May 12 22:36:15 2023 +0000

description:
tests/indent: test pushing the placeholder symbol to the parser stack

diffstat:

 tests/usr.bin/indent/psym_semicolon.c |  30 +++++++++++++++++++++++++-----
 usr.bin/indent/parse.c                |  30 +++++++++++++++++++-----------
 2 files changed, 44 insertions(+), 16 deletions(-)

diffs (102 lines):

diff -r 4a43bb7f7da5 -r d77d17bdf4ee tests/usr.bin/indent/psym_semicolon.c
--- a/tests/usr.bin/indent/psym_semicolon.c     Fri May 12 15:36:02 2023 +0000
+++ b/tests/usr.bin/indent/psym_semicolon.c     Fri May 12 22:36:15 2023 +0000
@@ -1,14 +1,34 @@
-/* $NetBSD: psym_semicolon.c,v 1.3 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: psym_semicolon.c,v 1.4 2023/05/12 22:36:15 rillig Exp $ */
 
 /*
- * Tests for the parser symbol psym_semicolon, which pushes a new statement on
- * the stack.
+ * Tests for the parser symbol psym_0 (formerly named psym_semicolon), which
+ * pushes a new statement on the stack.
  *
  * This token is never stored on the stack itself.
  */
 
 //indent input
-// TODO: add input
+void func(void) { stmt(); }
+//indent end
+
+//indent run
+void
+func(void)
+{
+       stmt();
+}
 //indent end
 
-//indent run-equals-input
+//indent run -npsl
+void func(void)
+{
+       stmt();
+}
+//indent end
+
+//indent run -nfbs
+void
+func(void) {
+       stmt();
+}
+//indent end
diff -r 4a43bb7f7da5 -r d77d17bdf4ee usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Fri May 12 15:36:02 2023 +0000
+++ b/usr.bin/indent/parse.c    Fri May 12 22:36:15 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.51 2023/05/12 08:40:54 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.52 2023/05/12 22:36:15 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)parse.c   8.1 
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: parse.c,v 1.51 2023/05/12 08:40:54 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.52 2023/05/12 22:36:15 rillig Exp $");
 #else
 __FBSDID("$FreeBSD: head/usr.bin/indent/parse.c 337651 2018-08-11 19:20:06Z pstef $");
 #endif
@@ -91,6 +91,21 @@ decl_level(void)
     return level;
 }
 
+#ifdef debug
+static void
+debug_parse_stack(const char *situation)
+{
+    printf("parse stack %s:", situation);
+    for (int i = 1; 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");
+}
+#else
+#define debug_parse_stack(situation) do { } while (false)
+#endif
+
 /*
  * Shift the token onto the parser stack, or reduce it by combining it with
  * previous tokens.
@@ -220,16 +235,9 @@ parse(parser_symbol psym)
     if (ps.tos >= STACKSIZE - 1)
        errx(1, "Parser stack overflow");
 
+    debug_parse_stack("before reduction");
     reduce();                  /* see if any reduction can be done */
-
-#ifdef debug
-    printf("parse stack:");
-    for (int i = 1; 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
+    debug_parse_stack("after reduction");
 }
 
 /*



Home | Main Index | Thread Index | Old Index