From: Arav Verma <svav2021@gmail.com>
To: herbert@gondor.apana.org.au
Cc: dash@vger.kernel.org, Arav Verma <svav2021@gmail.com>
Subject: [PATCH 1/2] case: Implement fallthrough (;&) operator
Date: Wed, 25 Nov 2026 16:09:30 -0600 [thread overview]
Message-ID: <20261125220931.849457-1-svav2021@gmail.com> (raw)
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
next reply other threads:[~2026-11-25 22:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 22:09 Arav Verma [this message]
2026-11-25 22:09 ` [PATCH 2/2] man: Document the case fallthrough (;&) operator Arav Verma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125220931.849457-1-svav2021@gmail.com \
--to=svav2021@gmail.com \
--cc=dash@vger.kernel.org \
--cc=herbert@gondor.apana.org.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox