On 02/03/2018 16:28, Herbert Xu wrote:
On Fri, Mar 02, 2018 at 11:58:41AM +0100, Harald van Dijk wrote:

If we fix this in the parser then everything should just work.

Right, that's the approach FreeBSD sh has taken that I referred to in my
message from Feb 18, that I'd personally prefer as well. It basically
involves reverting 7cfd8be0dc83342b4a71f3a8e5b7efab4670e50c, setting syntax
to BASESYNTAX/DQSYNTAX (whichever is appropriate) when the parse of a
variable expansion starts, and finding a sensible way to change the syntax
back to BASESYNTAX/DQSYNTAX/ARISYNTAX when it ends. In FreeBSD sh, an
explicit stack of syntaxes is created for this, but that might be avoidable:
with slight modifications to what gets stored in the byte after
CTLVAR/CTLARI, it might be possible to go back through the parser output to
determine the syntax to revert to. I'll see if I can get that working.

Yes but that's overkill just to fix single quote within patterns.
We already support nested double-quotes in patterns correctly.  As
single quotes cannot nest, it should be an easy fix.

Single quotes indeed cannot nest, but you do need to reliably determine when a single quote is a special character, which gets very tricky very quickly with nested substitutions.

In "${x+''}", the ' is the literal ' character. In "${x#''}", the ' is a quote character. This part is easy, this part is just a matter of setting another variable when the parse of the substitution starts.

But in "${x+${y-}''}", the ' is the literal ' character. In "${x#${y-}''}", the ' is a quote character. This part is hard. If the above is done simply using another local variable, then the parse of the nested ${y-} would clobber that variable.

Harald van Dijk
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to