Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [Feature Request] Adding option to support triple quotes



On Thu, Aug 15, 2019 at 6:13 PM Aryn Starr <whereislelouch@xxxxxxxxxx> wrote:
>
> The only preventive measure I can think of is to tell users to check zsh’s version at the very start and exit noisily ...

This right here is exactly why we have traditionally never built new
syntax that is an ambiguous superset of an existing syntax.  If it's
not a syntax error in a version of the interpreter that doesn't
support it, it shouldn't be there at all.  I've been staying out of
this discussion because it's all been theoretical so far, but tripling
quotation marks is a nonstarter for me.

A good relatively recent example of this is that you're allowed to write

{ stuff } always
{ other stuff }

but not

{ stuff }
always { other stuff }

So if you really want to make progress with this, start looking for
something more akin to perl's q{} and qq{} as already mentioned.  The
difficult part is that the shell language uses "lexical pasting"
instead of a concatenation operator, so finding something that doesn't
already have another meaning is tricky.

One way around this is to introduce a new keyword.  A candidate that
occurs to me is "let", because it's already a builtin and it's been
decades since I saw anybody use it.  (Does anyone know of a program
named "let" with which this would collide, and that isn't already
basically unusable in zsh because of the builtin?)  The "let" builtin
expects math expressions, which already have a limited syntax, so it's
easier to find something that would break in an old shell.  For
example, a math expression can't begin with a colon, so that could
introduce a new quoting token.

This also means you can turn the syntax off with "disable" if you
don't want it, we don't have to create another setopt.

Qualification:  I'm not sure the following suggestions would actually
error soon enough to prevent some downstream syntax from being
interpreted/executed, so this probably still needs more thought.

Nevertheless you could have (just throwing out examples)

let :"( this is like a triple double quoted argument to the ":" builtin )
let :'{ similarly a triple single quote , and look we can choose our delimiter }
let foo=:"{{{ assign to foo, and quote } and { by having the delimiter
repeat }}}

There are other characters that can't begin a math expression that
could be given other meanings, such as ^ and @ and %

let list=@{ :"( string one ) :'< string two > :^[ string three ] }   #
no, I do not have any idea what :^ would mean ...
let hash=%{ key=:"( value ) }



Messages sorted by: Reverse Date, Date, Thread, Author