zsh-users
 help / color / mirror / code / Atom feed
From: "Daniel Shahaf" <d.s@daniel.shahaf.name>
To: "Ray Andrews" <rayandrews@eastlink.ca>, "Zsh Users" <zsh-users@zsh.org>
Subject: Re: here document within a switch fails to parse.
Date: Wed, 06 Jan 2021 16:20:00 +0000	[thread overview]
Message-ID: <2bc17f94-91c0-429d-bdea-e39926dc083d@www.fastmail.com> (raw)
In-Reply-To: <db51fbd9-20d4-9a52-1925-1a2c9115771c@eastlink.ca>

Ray Andrews wrote on Wed, 06 Jan 2021 15:13 +00:00:
> function test1 ()
> {
> : <<'ENDCOM'             # No problems here with either ending #1 or #2
> echo "Bad Idea!"         # Some commented code.
> ENDCOM                   # Ending #1: comment-out one line ok.
>      case ${1} in
>          n ) echo en ;;
> #: <<'ENDCOM'            # This pair: "parse error near `\n'"
> #ENDCOM
>      esac
> #ENDCOM                  # Ending #2: comment-out most of function ok.
> echo "What's goin' on?"
> }
> 
> ... So it seemed that a case statement won't tolerate a here document 
> within itself. But then there's this, which parses fine:
> 
> function test2 ()
> {
>      case ${1} in
>          n ) echo en ;;
> 
>          v )
> : <<'ENDCOM'            # But this pair works fine.
>             echo "BAD!"  # Some commented code
> ENDCOM
>             echo GOOD!:  # Much better.
>      ;;
>      esac
> }
> 
> ... So what am I missing?  Sometimes the here document is perfectly 
> ignored, other times it creates an error. Looks wrong.

The «;;» token must be followed by a pattern, but in your code, it is
followed by a command («:») (which happens to use a heredocument, yes,
but that's not actually relevant:

$ zsh -fc 'case foo in (bar) ;; pwd; esac' 
zsh:1: parse error near `;').

)

> So far I haven't found any comparable errors but this.

Perhaps because many a syntax that look weird are actually valid, but
in any case, here's another place where commands aren't allowed:

repeat foo
bar <<baz
baz
do pwd
done

Cheers,

Daniel


  reply	other threads:[~2021-01-06 16:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 15:13 Ray Andrews
2021-01-06 16:20 ` Daniel Shahaf [this message]
2021-01-06 17:17   ` Ray Andrews
2021-01-06 17:58     ` Lawrence Velázquez
2021-01-06 19:18     ` Bart Schaefer
2021-01-07  7:55       ` Ray Andrews
2021-01-07 15:32         ` Daniel Shahaf
2021-01-07 20:16           ` Ray Andrews
2021-01-08 15:27             ` Karsten Borgwaldt
2021-01-08 15:53               ` Lawrence Velázquez
2021-01-08 17:13                 ` Ray Andrews
2021-01-08 18:06                   ` Peter Stephenson
2021-01-08 19:39                     ` Ray Andrews
2021-01-08 19:56                       ` Bart Schaefer
2021-01-09  0:45                         ` Ray Andrews
2021-01-09 17:28                         ` Ray Andrews
2021-01-12 13:28             ` Daniel Shahaf
2021-01-12 14:45               ` Ray Andrews
2021-01-13 16:17                 ` Daniel Shahaf
2021-01-13 21:57                   ` Pier Paolo Grassi
2021-01-13 23:39                     ` Ray Andrews
2021-01-13 23:54                       ` Lawrence Velázquez

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=2bc17f94-91c0-429d-bdea-e39926dc083d@www.fastmail.com \
    --to=d.s@daniel.shahaf.name \
    --cc=rayandrews@eastlink.ca \
    --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).