zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: "Lawrence Velázquez" <vq@larryv.me>
Cc: Bart Schaefer <schaefer@brasslantern.com>, zsh-workers@zsh.org
Subject: Re: Block comments ala Ray
Date: Fri, 12 Feb 2021 21:02:36 +0000	[thread overview]
Message-ID: <20210212210236.rsmrs65lmtxzoqzc@chazelas.org> (raw)
In-Reply-To: <B2B62C95-EEDF-442A-9ACA-75EE653CEB72@larryv.me>

2021-02-12 13:16:28 -0500, Lawrence Velázquez:
[...]
> This was me, addressing someone with shaky shell fundamentals who
> was aliasing the here-document idiom and expecting it to behave
> identically to real comments (discarded during lexing, no further
> impact on the script).
[...]

Thanks all for the clarifications.

About "discarding during lexing", I did find these btw:

$ ksh93 -c $'f() {\n# whatever\necho  x\n}; typeset -f f'
f() {
# whatever
echo  x
}

It appears as if they're not discarded(though it looks like it's
rather that ksh stores the raw text content (probably only for
the "typeset -f" output) in addition to "compiling"/"wordcoding"
or however you want to call it (which probably still discards
comments)).

But see also (as that construct was mentioned in that thread):

$ zsh -c 'f() { echo `echo x # comment`; }; typeset -f f; f'
f () {
        echo `echo x # comment`
}
x
$ mksh -c 'f() { echo `echo x # comment`; }; typeset -f f; f'
f() {
        \echo $(echo x # comment)
}
x
$ bash -c 'f() { echo `echo x # comment`; }; typeset -f f; f'
f ()
{
    echo `echo x # comment`
}
x

as the parsing of the inside of `...` is deferred in all shells
except ash-based ones; see $shell -c ':||echo `for`'. A bit like
in eval 'echo x # comment'.

It's also deferred with the $(...) form in bash (but bash only
AFAICT):

$ bash -c $'f() { echo $(echo x # comment\n); }; typeset -f f'
f ()
{
    echo $(echo x # comment
)
}

That newline is necessary in all shells though there, and that
makes the replacing of `...` with $(...) in the typeset -f
output by mksh above incorrect:

~$ mksh -c 'f() { echo `echo x # comment`; }; typeset -f f' | mksh
mksh: <stdin>[3]: syntax error: unexpected '}'

-- 
Stephane


  reply	other threads:[~2021-02-12 21:03 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10  6:05 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210212210236.rsmrs65lmtxzoqzc@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=schaefer@brasslantern.com \
    --cc=vq@larryv.me \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).