You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[v1.1] Add ;;& control operator to 'case' statement
@tungstengmd asks:
> would ;;& a la bash be a good addition for case statements ?
> instead of just falling through like a ;& it tests any subsequent
> case and falls through upon a match
To add this, we need three things:
1. The lexer (lex.c) needs to learn to recognise ;;& as a symbol.
2. The parser (parse.c) needs to recognise that symbol and flag it
up in 'case' pattern nodes (struct regnod).
3. The executor (xec.c) needs to actually have the functionality.
src/cmd/ksh93/include/shlex.h,
src/cmd/ksh93/sh/lex.c:
- sh_lex():
- Add FALLMATCHSYM which is a repeated (SYMREP) ';' with a
trailing ampersand (SYMAMP).
- Recognise a trailing & after a SYMREP symbol and addthe
SYMAMP bit if found. Any repeated S_OP character (see
lexstates.c) can now be combined with a trailing & to make a
symbol, but for now we're only using this for FALLMATCHSYM.
- Set lex.incase flag also in case of FALLMATCHSYM.
- fmttoken():
- Support SYMAMP in combination with SYMREP to generate
repeated operators with trailing & for error messages. This
is for "syntax error: `;;&' unexpected" and the like.
src/cmd/ksh93/sh/parse.c:
- syncase():
- The regflag member of struct regnod is 1 for ;&. Add a new
value 2 for ;;& by increasing it twice in that case.
- Refactor a little for legibility using a switch statement.
This avoids the need to duplicate the recursive syncase call.
- inout():
- A side effect of the lex.c changes was that >>&foo and <<&foo
were no longer detected as a syntax error. To fix this in a
future-proof manner, check for unhandled SYM* bits in the
token and throw a syntax error if there are any.
src/cmd/ksh93/sh/xec.c: sh_exec(): case TSW:
- Implementing the functionality requires just a couple of tweaks
here. Detect ;& by checking for regflag==1 instead of nonzero.
Avoid breaking the outer loop if regflag is neither 0 nor 1, so
the pattern matching walk will resume upon encountering ;;&.
src/cmd/ksh93/sh/deparse.c: p_switch():
- Add support for ";;&" when generating code from a parse tree.
Resolves: #847
0 commit comments