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

Re: here document within a switch fails to parse.

Ray Andrews wrote on Wed, Jan 06, 2021 at 23:55:59 -0800:
> On 2021-01-06 11:18 a.m., Bart Schaefer wrote:
> > On Wed, Jan 6, 2021 at 9:17 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> > > Still I'd expect the here document
> > > to be simply removed before parsing.
> > Think again about what you just wrote?
> > 
> > The parser is what determines where the here document begins and ends;
> > parsing IS what removes it.
> > 
> Well yes.  I should have said that I'd expect it to be removed at the same
> level that comments are removed. Perhaps as Lawrence says this is not a good
> way to make comment blocks but apart from the one issue above, it seems
> entirely workable.

Do consider treating the language as the independent variable and your
expectations as the dependent one, rather than the other way around.

The syntax means what it means, not what you wish it meant.  Heredocs
are string literals and input redirections, not comments.  They don't
get "removed".  (Just try «:() { nl "$@" }».)

The syntax is stateful.  Heredocs aren't valid everywhere in the shell
grammar, just like the contraction "aren't" aren't valid everywhere in
English grammar.

The construct you use has side-effects you've overlooked, which mean
your fashion of comments will backfire in a way that you don't see yet.
You really should stick to writing idiomatic code.  (-workers@: Ray's
fashion of comments resets lastval.)

Do you see why the error message I quoted upthread complained about the
semicolon and not about something else?  And why «repeat dpkg-query
--list zsh» does what it does?

By the way, I wonder if the reason we're having this thread is that it
hasn't occurred to you that your $EDITOR may have facilities for
commenting or uncommenting multiple lines.


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