zsh-workers
 help / color / mirror / code / Atom feed
* Block comments ala Ray
@ 2021-02-10  6:05 Bart Schaefer
  2021-02-10  6:16 ` Roman Perepelitsa
                   ` (3 more replies)
  0 siblings, 4 replies; 39+ messages in thread
From: Bart Schaefer @ 2021-02-10  6:05 UTC (permalink / raw)
  To: Zsh hackers list

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.


^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2021-02-16 21:35 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10  6:05 Block comments ala Ray Bart Schaefer
2021-02-10  6:16 ` Roman Perepelitsa
2021-02-12  6:17   ` Bart Schaefer
2021-02-12  6:26     ` Bart Schaefer
2021-02-12  6:41     ` Roman Perepelitsa
2021-02-12  7:40       ` Stephane Chazelas
2021-02-12  7:46         ` Roman Perepelitsa
2021-02-12 15:30         ` Bart Schaefer
2021-02-12 15:45           ` Stephane Chazelas
2021-02-12 16:55             ` Bart Schaefer
2021-02-12 18:16               ` Lawrence Velázquez
2021-02-12 21:02                 ` Stephane Chazelas
2021-02-12 21:12                   ` Stephane Chazelas
2021-02-12 21:29                     ` Bart Schaefer
2021-02-13  7:37                       ` Stephane Chazelas
2021-02-15 22:28               ` Daniel Shahaf
2021-02-13  4:33       ` Bart Schaefer
2021-02-15  0:42       ` Greg Klanderman
2021-02-12 15:24     ` Matthew Martin
2021-02-12 16:18       ` Bart Schaefer
2021-02-15 21:30         ` Daniel Shahaf
2021-02-15 22:35           ` Bart Schaefer
2021-02-12 20:48 ` Bart Schaefer
2021-02-13  8:35 ` Stephane Chazelas
2021-02-13  8:53   ` Stephane Chazelas
2021-02-14 20:50     ` Bart Schaefer
2021-02-14 20:15   ` Bart Schaefer
2021-02-15  0:36     ` Vincent Lefevre
2021-02-15  1:07       ` Bart Schaefer
2021-02-15  1:38         ` Vincent Lefevre
2021-02-15 17:43     ` Stephane Chazelas
2021-02-15 22:06       ` Daniel Shahaf
2021-02-15 22:39         ` Bart Schaefer
2021-02-14 20:58   ` Bart Schaefer
2021-02-16 15:30 ` Juergen Christoffel
2021-02-16 17:21   ` Vincent Lefevre
2021-02-16 18:29     ` Bart Schaefer
2021-02-16 21:35     ` Juergen Christoffel
2021-02-16 18:21   ` pod documentation in zsh scripts (Was: Block comments ala Ray) Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).