Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TLDR;
src/cmd/ksh93/include/shlex.h Implement yet another lex state funcalias, set to 1 when
function keyword is an alias expansion.
src/cmd/ksh93/sh/lex.c Allow alias expansion on word following a 'function ' expansion.
src/cmd/ksh93/tests/alias.sh Update alias.sh to catch alias x='function ' failure.
Explanations:
Alias allows aliases to be chained while expanded alias value have a trailing space.
Assuming
alias 'x=function ' y=f
Parsing
x y { echo :); }
x is a simple cmd, a check for alias is done and is successfull we got 'function '
The parser then then enter funct() for parsing a function, the next token fetch is not a simple cmd anymore, no check for alias will be done, next token is then y and become the function name.
To fix this, when expanding to 'function ' we need to setup a lexer state, I called it funcalias in shlex.c, it is then set to 1 in sh_lex()
When funct() parse y { ... the funcalias==1 allows a check for alias, we then get the 'f' expansion and reset funcalias. At this point other alias expansion are permitted, though hard to follow.
$ alias 'x=function ' y=f z='{ ' t='echo ' u='AA ' v='}' $ x y z t u v
$ f
AA