zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: lexing
Date: Sun, 29 Nov 2015 10:07:35 -0800	[thread overview]
Message-ID: <151129100735.ZM24525@torch.brasslantern.com> (raw)
In-Reply-To: <565B18C6.6090707@eastlink.ca>

On Nov 29,  7:24am, Ray Andrews wrote:
}
} The people who write the highlighter are interested in fixing that
} for zsh, but they want a rigorous description of the rule. As far as
} I know the only rule there is that if the hash is preceded by an open
} parenthesis then it is not a comment. Is that sufficient or are there
} further subtleties?

I'll leave the following analysis of all the places where a "#" is NOT
a comment, because I went to the trouble of writing it all down, after
which I realized it's a whole lot easier to explain:

  The # character introduces a comment ONLY when it is immediately
  preceded by a command terminator (including start of line) or by
  whitespace that acts as a word separator.

Everywhere else, # is NOT a comment, in contexts such as:

$# is the obvious one, but they probably have that covered.  Also any
"#" that appears inside ${...} should not be treated as a comment,
except that inside $(...) the normal comment rules apply even if
that is also inside ${...}.

(Aside to zsh-workers:  $(...) is apparently NOT "interactive" even if
typed at the command line, for INTERACTIVE_COMMENTS purposes.)

In arithmetic expressions, digits followed by "#" are the base of the
number, e.g., 2#111 is 10#7.  Also open-bracket followed by "#" and
then digits and close-bracket specifies an output base, e.g. $[[#2]7]
substitutes 2#111 -- I'm deliberately using the $[...] alternative to
$(( [#2] 7 )) and squashing spaces).  Oh, and [#10_3] means output
base 10 with underscores between every group of 3 digits, and [##8]
means output in octal with no 8# prefix (works for any base).

Then (still in math context) there's ##Z which outputs the value of
the character Z, which can also be a sequence e.g. $(( ##\e )) is 27,
and (( #VAR )) is the same as ## except on the first character in
the value of $VAR.

The form you're using (#something), is only not-a-comment in pattern
or filename-generation context, so $(# this IS a comment).  And of
course once you have started a (#...) that is not a comment, any #
that is before the closing paren is also not a comment.

Lastly there's # and ## at the end of any string in pattern or name-
generation context, which is never a comment even if extended_glob is
not set.

Final note:  The one thing zsh borrowed from csh that I freely concede
is pretty horrible, is the ability to change the comment character by
changing the third character of $histchars.  Please never do this.


  parent reply	other threads:[~2015-11-29 18:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-29 15:24 lexing Ray Andrews
2015-11-29 17:13 ` lexing ZyX
2015-11-29 18:07 ` Bart Schaefer [this message]
2015-11-30  2:10   ` lexing Ray Andrews
2015-11-30  3:33     ` lexing Daniel Shahaf
2015-11-30  4:20       ` lexing Ray Andrews
2015-11-30  4:47         ` lexing Ray Andrews
2015-11-30 16:23           ` lexing Bart Schaefer
2015-11-30 16:50             ` lexing Ray Andrews
2015-12-04 19:15             ` master class Ray Andrews

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=151129100735.ZM24525@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@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).