* [PATCH 1/2] case: Implement fallthrough (;&) operator
@ 2026-11-25 22:09 Arav Verma
2026-11-25 22:09 ` [PATCH 2/2] man: Document the case " Arav Verma
0 siblings, 1 reply; 2+ messages in thread
From: Arav Verma @ 2026-11-25 22:09 UTC (permalink / raw)
To: herbert; +Cc: dash, Arav Verma
Add support for the fallthrough operator, as specified
in POSIX.1-2024, (defect 449). The ;& operator allows
execution to continue to the next case pattern without
re-evaluating the switch expression
A new node type, NCLISTFT, marks a case that falls through.
EV_EXIT is cleared for every body except the last one.
Signed-off-by: Arav Verma <svav2021@gmail.com>
---
src/eval.c | 9 +++++++++
src/jobs.c | 2 +-
src/mktokens | 1 +
src/nodetypes | 1 +
src/parser.c | 12 ++++++++----
5 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/eval.c b/src/eval.c
index 0f2a7ba..5b44030 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -462,6 +462,15 @@ evalcase(union node *n, int flags)
for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
if (casematch(patp, arglist.list->text)) {
+ while (cp->type == NCLISTFT && cp->nclist.next) {
+ if (cp->nclist.body)
+ status = evaltree(
+ cp->nclist.body,
+ flags & ~EV_EXIT);
+ if (evalskip)
+ goto out;
+ cp = cp->nclist.next;
+ }
/* Ensure body is non-empty as otherwise
* EV_EXIT may prevent us from setting the
* exit status.
diff --git a/src/jobs.c b/src/jobs.c
index 914b383..6c85461 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -1385,7 +1385,7 @@ dotail2:
cmdtxt(np->nclist.pattern);
cmdputs(") ");
cmdtxt(np->nclist.body);
- cmdputs(";; ");
+ cmdputs(np->type == NCLISTFT ? ";& " : ";; ");
}
p = "esac";
goto dotail2;
diff --git a/src/mktokens b/src/mktokens
index dcef676..d5ec795 100644
--- a/src/mktokens
+++ b/src/mktokens
@@ -51,6 +51,7 @@ TPIPE 0 "|"
TLP 0 "("
TRP 1 ")"
TENDCASE 1 ";;"
+TFALLTHRU 1 ";&"
TENDBQUOTE 1 "`"
TREDIR 0 redirection
TWORD 0 word
diff --git a/src/nodetypes b/src/nodetypes
index ceaf478..dcf9777 100644
--- a/src/nodetypes
+++ b/src/nodetypes
@@ -101,6 +101,7 @@ NCASE ncase # a case statement
cases nodeptr # the list of cases (NCLIST nodes)
NCLIST nclist # a case
+NCLISTFT nclist # a case that falls through
type int
next nodeptr # the next case in list
pattern nodeptr # list of patterns for this case
diff --git a/src/parser.c b/src/parser.c
index e44b3c3..f55a5b5 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -463,10 +463,11 @@ next_case:
checkkwd = CHKNL | CHKKWD;
if ((t = readtoken()) != TESAC) {
- if (t != TENDCASE)
+ if (t == TFALLTHRU)
+ cp->type = NCLISTFT;
+ else if (t != TENDCASE)
synexpect(TENDCASE);
- else
- goto next_case;
+ goto next_case;
}
}
*cpp = NULL;
@@ -834,8 +835,11 @@ xxreadtoken(void)
pungetc();
RETURN(TPIPE);
case ';':
- if (pgetc_eatbnl() == ';')
+ c = pgetc_eatbnl();
+ if (c == ';')
RETURN(TENDCASE);
+ if (c == '&')
+ RETURN(TFALLTHRU);
pungetc();
RETURN(TSEMI);
case '(':
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] man: Document the case fallthrough (;&) operator
2026-11-25 22:09 [PATCH 1/2] case: Implement fallthrough (;&) operator Arav Verma
@ 2026-11-25 22:09 ` Arav Verma
0 siblings, 0 replies; 2+ messages in thread
From: Arav Verma @ 2026-11-25 22:09 UTC (permalink / raw)
To: herbert; +Cc: dash, Arav Verma
Describe the ;& case clause terminator added in the previous patch.
Signed-off-by: Arav Verma <svav2021@gmail.com>
---
src/dash.1 | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/dash.1 b/src/dash.1
index e1031a5..c948309 100644
--- a/src/dash.1
+++ b/src/dash.1
@@ -682,6 +682,16 @@ The
(
.Dc
character before the pattern is optional.
+If a list is terminated by
+.Dq ;&
+instead of
+.Dq ;; ,
+execution continues with the list of the next clause without testing
+its patterns, and so on until a clause terminated by
+.Dq ;;
+or the end of the
+.Ic case
+command is reached.
.Ss Grouping Commands Together
Commands may be grouped by writing either
.Pp
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-25 22:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 22:09 [PATCH 1/2] case: Implement fallthrough (;&) operator Arav Verma
2026-11-25 22:09 ` [PATCH 2/2] man: Document the case " Arav Verma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox