Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Block comments ala Ray
- X-seq: zsh-workers 47991
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Block comments ala Ray
- Date: Tue, 9 Feb 2021 22:05:13 -0800
- Archived-at: <https://zsh.org/workers/47991>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-02/CAH%2Bw%3D7YZREq7FbJCCoWoJ-vQ7%2BP5Z%3D_mKB-aStoMiBRupqD_wA%40mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
I've been noodling around with Ray Andrew's oft-repeated suggestion of
some kind of block comment syntax. After considerable prodding of
gettok() in lex.c, I came up with something that works like this:
A line beginning with !# introduces a block comment. This
(deliberately) means that NO_BANG_HIST must be in effect, so without
some hoop-jumping this only affects scripts.
I chose this because it seems unlikely to me that anyone would write in a script
!# this is just a silly way to mean false
The comment ends after a line containing #! anywhere in the line. So
a full block could be:
!# This begins a block comment.
This is merely rambling.
This #! is the last line of the block
Stylistically, of course, I'd recommend putting the #! either at the
beginning or the end of that third line, but tokenizing worked best
just consuming everything up through the newline once #! was
recognized. I experimented with allowing the block comment to start
or end in the middle of lines, but it was just too weird to be able to
do
print this !# part is a comment
but this part #! is not a comment
(which would print "this is not a comment"), and a solo "!" out of
command position may not be as rare as one at the start of a line.
I tried some other character combinations ... for example I can't find
any circumstance in which it is not a syntax error to write <# so if
it's appealing to match that with #> for symmetry, it's a small edit.
But I wasn't happy that those appear to be redirections.
Having told you all that ... there's one glitch with my
implementation. To detect whether !# is at the beginning of a line,
in gettok() I test the "isnewlin" boolean. This works everywhere
(that I've found) except when on the first character of a new script
file. That means you can't begin a script with a block comment ...
which perhaps is a good thing, since typo-ing "!#/bin/sh" may not be
all that uncommon, and having the entire script turn into a comment
would be a bit startling. However, I would like to know what (if
anything) can be tested to identify the first character of a new
script? I've tried combinations of of
isnewlin -- this is initialized to false
isfirstch -- this is true after any separator
isfirstln -- true throughout any single-line command
What else could be examined?
Any other thoughts about this? Too horrible to consider? It needs
turning off in emulation modes and I haven't gotten to that yet.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author