zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: $(...) and <<
Date: Mon, 04 Aug 2014 11:51:02 -0700	[thread overview]
Message-ID: <140804115102.ZM1058@torch.brasslantern.com> (raw)
In-Reply-To: <20140731174208.67f1b392@pwslap01u.europe.root.pri>

On Jul 31,  5:42pm, Peter Stephenson wrote:
} Subject: Re: $(...) and <<
}
} > } $ zsh -c 'echo $(cat << EOF
} > } blah)
} > } EOF
} > } ); echo test'
} > } zsh:4: parse error near `)'
} 
} - Check if it looks like $( ... ) or $(( ... ) ... ) but not $(( ... ))
} as before, in other words we have to guess if it's $( ... ) by looking
} for a stray ")" that might actually not be the end of the command
} substitution but probably implies it's not a $(( ... )) substitution.
} A bit icky but we've done worse.
} 
} - Re-enter the parser at this point within the lexer and keep going

I tried this a couple of different ways but always ended up with one or
more of the "make check" tests failing because I wasn't backtracking
properly after discovering that the first ")" wasn't a "))".  It's also
fairly ugly to discover that the first ")" in "$( ... ) ... )" is NOT
closing the expression unless you are already in the parser.

What it seems realy needs to happen is to always attempt to parse math
at "$((" and if that fails, back up to the second "(" and attempt to
parse shell code.  But that can require arbitrary lookahead ... which
is no worse than attempting to consume everything up to ")" as a string
and then parse it, but (as you mentioned) a bit harder to extract the
result because it's passing through the parser rather than lexer.


  parent reply	other threads:[~2014-08-04 18:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-31  9:27 Stephane Chazelas
2014-07-31 16:20 ` Bart Schaefer
2014-07-31 16:42   ` Peter Stephenson
2014-07-31 17:23     ` Stephane Chazelas
2014-08-01  0:34       ` Issue trackers (Re: $(...) and <<) Bart Schaefer
2014-08-04 18:51     ` Bart Schaefer [this message]
2014-08-06 21:25 ` $(...) and << 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=140804115102.ZM1058@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).