zsh-workers
 help / color / mirror / code / Atom feed
* (z) flag little crazy when '((' closed with *single* ')'
@ 2018-05-28 14:43 Sebastian Gniazdowski
  2018-05-28 17:02 ` Jun T.
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Gniazdowski @ 2018-05-28 14:43 UTC (permalink / raw)
  To: Zsh hackers list

Hello,
so how is (( ... )) splitted by (z)?

~ buf='(( i = 1, i <= size, ++ i ))'; printf "|%s|\n" "${(z)buf}"
|(( i = 1, i <= size, ++ i ))|

~ buf='(( i = 1, i <= size, ++ i'; printf "|%s|\n" "${(z)buf}"
|(( i = 1, i <= size, ++ i|

OK, but look what happens when there is single ')', not 0, not 2, but
1 closing parenthesis:

~ buf='(( i = 1, i <= size, ++ i )'; printf "|%s|\n" "${(z)buf}"
|(|
|(|
|i|
|=|
|1,|
|i|
|<|
|=|
|size,|
|++|
|i|
|)|

It splits almost char by char. I wonder if this couldn't be fixed? So
that (z) would split this as:

|(( i = 1, i <= size, ++ i )|

-- 
Best regards,
Sebastian Gniazdowski


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

* Re: (z) flag little crazy when '((' closed with *single* ')'
  2018-05-28 14:43 (z) flag little crazy when '((' closed with *single* ')' Sebastian Gniazdowski
@ 2018-05-28 17:02 ` Jun T.
  2018-05-29  0:08   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Jun T. @ 2018-05-28 17:02 UTC (permalink / raw)
  To: zsh-workers


> 2018/05/28 23:43, Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> 
> ~ buf='(( i = 1, i <= size, ++ i )'; printf "|%s|\n" "${(z)buf}"
> |(|
> |(|
(snip)
> |)|
> 
> It splits almost char by char. I wonder if this couldn't be fixed? So
> that (z) would split this as:
> 
> |(( i = 1, i <= size, ++ i )|

If the lexer can't find the closing '))' on the command line, it tries
to interpret the opening '((' as '( (', i.e., nested subshells.

zsh% ((echo foo) )
foo
zsh% ((echo foo); echo bar)
foo
bar
zsh% ((echo foo)
subsh>

${(z)...} uses the same lexter, and even if it is OK to make it behave
differently from the command line, we may need to modify the lexer ...


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

* Re: (z) flag little crazy when '((' closed with *single* ')'
  2018-05-28 17:02 ` Jun T.
@ 2018-05-29  0:08   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2018-05-29  0:08 UTC (permalink / raw)
  To: Jun T.; +Cc: zsh-workers

On Mon, May 28, 2018 at 10:02 AM, Jun T. <takimoto-j@kba.biglobe.ne.jp> wrote:
>
> If the lexer can't find the closing '))' on the command line, it tries
> to interpret the opening '((' as '( (', i.e., nested subshells.

The right way to handle this is probably to extend the (Z:...:) flag
to have an option to start parsing in math context.


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

end of thread, other threads:[~2018-05-29  0:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-28 14:43 (z) flag little crazy when '((' closed with *single* ')' Sebastian Gniazdowski
2018-05-28 17:02 ` Jun T.
2018-05-29  0:08   ` Bart Schaefer

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).