Module Name:    src
Committed By:   rillig
Date:           Fri May 12 22:36:15 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: psym_semicolon.c
        src/usr.bin/indent: parse.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/psym_semicolon.c
cvs rdiff -u -r1.51 -r1.52 src/usr.bin/indent/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/psym_semicolon.c
diff -u src/tests/usr.bin/indent/psym_semicolon.c:1.3 src/tests/usr.bin/indent/psym_semicolon.c:1.4
--- src/tests/usr.bin/indent/psym_semicolon.c:1.3	Sun Apr 24 09:04:12 2022
+++ src/tests/usr.bin/indent/psym_semicolon.c	Fri May 12 22:36:15 2023
@@ -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-equals-input
+//indent run
+void
+func(void)
+{
+	stmt();
+}
+//indent end
+
+//indent run -npsl
+void func(void)
+{
+	stmt();
+}
+//indent end
+
+//indent run -nfbs
+void
+func(void) {
+	stmt();
+}
+//indent end

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.51 src/usr.bin/indent/parse.c:1.52
--- src/usr.bin/indent/parse.c:1.51	Fri May 12 08:40:54 2023
+++ src/usr.bin/indent/parse.c	Fri May 12 22:36:15 2023
@@ -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");
 }
 
 /*

Reply via email to