zsh-workers
 help / color / mirror / code / Atom feed
* $match size limit, suspicious (#B) behavior
@ 2016-10-16  9:15 Sebastian Gniazdowski
  2016-10-16  9:40 ` Sebastian Gniazdowski
  2016-10-17 14:51 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Sebastian Gniazdowski @ 2016-10-16  9:15 UTC (permalink / raw)
  To: Zsh hackers list

Hello,
turns out $match has a size limit of 9:

% a='abcdefghijk'; [[ "$a" = (#b)(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k) ]]
&& echo "match[9]: $match[9], match[10]: $match[10]"
match[9]: i, match[10]:

Which can be to some extent worked around with (#B):

% a='abcdefghijk'; [[ "$a" =
(#b)(a)(b)(c)(d)(#B)(e)(#b)(f)(g)(h)(i)(j)(k) ]] && echo "match[9]:
$match[9], match[10]: $match[10]"
match[9]: j, match[10]:

Now the difficult part – but just count the parentheses before and
after (#B) – my input is:

mybuf='if [[ "$mybuf" =
(#b)(\$([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))(*)
]]; then : fi'

Now code that matches either $var, ${var}, \$:

while [[ "$mybuf" =
(#b)([^\$\\]#)((#B)(\$([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))|(\$[{](\([a-zA-Z0@%#]##\))(#c0,1)([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1)[}])|([\\][\'\"\$]))(#b)(*)
]]; do
    echo "Got: ${match[2]}"
    echo "Match 1: ${match[1]}"
    echo "Match 2: ${match[2]}"
    echo "Match 3: ${match[3]}"
    echo "Match 4: ${match[4]}"
    echo "Match 5: ${match[5]}"
    echo "Match 6: ${match[6]}"
    echo "Match 7: ${match[7]}"
    echo "Match 8: ${match[8]}"
    echo "Match 9: ${match[9]}"
    mybuf="${match[8]}"
  done

Output is:

Got: $mybuf
Match 1: if [[ "
Match 2: $mybuf
Match 3:
Match 4:
Match 5:
Match 6:
Match 7:
Match 8: " = (#b)(\$([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))(*)
]]; then : fi
Match 9:

Got: \$
Match 1: " = (#b)(
Match 2: \$
Match 3:
Match 4:
Match 5:
Match 6:
Match 7: \$
Match 8: ([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))(*)
]]; then : fi
Match 9:

"Match 8: .." is: "the rest", i.e. (*). "Match 1: .." is: "before".
"Match 2: .." is the $var, ${var} or \$.

The problem: (#B) should have disabled all parentheses from where it
is placed, and "Match 8: ..." should be at "Match 3: ..". Also, "Match
7: .." has the same value as "Match 2: ..", which seems to be a
problem.

Best regards,
Sebastian Gniazdowski


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

* Re: $match size limit, suspicious (#B) behavior
  2016-10-16  9:15 $match size limit, suspicious (#B) behavior Sebastian Gniazdowski
@ 2016-10-16  9:40 ` Sebastian Gniazdowski
  2016-10-17 14:51 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Sebastian Gniazdowski @ 2016-10-16  9:40 UTC (permalink / raw)
  To: Zsh hackers list

On 16 October 2016 at 11:15, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> Also, "Match
> 7: .." has the same value as "Match 2: ..", which seems to be a
> problem.

That turned out to not be a problem, there is outer parenthesis and
three inner parentheses: ( () | () | () ) and "Match 7" is apparently
repeated value of outer parenthesis (via inner parenthesis).

Best regards,
Sebastian Gniazdowski


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

* Re: $match size limit, suspicious (#B) behavior
  2016-10-16  9:15 $match size limit, suspicious (#B) behavior Sebastian Gniazdowski
  2016-10-16  9:40 ` Sebastian Gniazdowski
@ 2016-10-17 14:51 ` Bart Schaefer
  2016-10-17 15:00   ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-10-17 14:51 UTC (permalink / raw)
  To: Zsh hackers list; +Cc: Sebastian Gniazdowski

[Sebastian Cc'd in case the list is still having indigestion over gmail MTAs]

On Sun, Oct 16, 2016 at 2:15 AM, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Now code that matches either $var, ${var}, \$:
>
> while [[ "$mybuf" =
> (#b)([^\$\\]#)((#B)(\$([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1))|(\$[{](\([a-zA-Z0@%#]##\))(#c0,1)([[:alpha:]_][[:alnum:]_]#|[[:digit:]]##)(\[[^[:space:]]#\])(#c0,1)[}])|([\\][\'\"\$]))(#b)(*)
> ]]; do
>
> The problem: (#B) should have disabled all parentheses from where it
> is placed

What it looks like you're attempting to do is have
(#b)([^\$\\]#)((#B)....)(#b)(*) count as match[1] match[2] match[3]
without treating any of the more deeply nested parens inside the
match[2] pattern as backreferences?

That works with a very simple pattern:

% [[ 12345 = (#b)(?)((#B)(?)(?)(?))(#b)(?) ]]
% print -l :$^match
:1
:234
:5

The problem seems to be that the (#B) stops / (#b) implicitly resumes,
at the "|" in the second set of parens:

% [[ 12345 = (#b)(?)((#B)(?)|([[:alnum:]](#c0,1))(?))(#b)(*) ]]
% print -l :$^match
:1
:2
:
:
:345

If I add another set of parens around everything that follows (#B) up
to just before the close of the paren that opens before (#B), it looks
like what I expect:

% [[ 12345 = (#b)(?)((#B)((?)|([[:alnum:]](#c0,1))(?)))(#b)(*) ]]
% print -l :$^match
:1
:2
:345


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

* Re: $match size limit, suspicious (#B) behavior
  2016-10-17 14:51 ` Bart Schaefer
@ 2016-10-17 15:00   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2016-10-17 15:00 UTC (permalink / raw)
  To: Zsh hackers list; +Cc: Sebastian Gniazdowski

One other thing ...

On Mon, Oct 17, 2016 at 7:51 AM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> [Sebastian Cc'd in case the list is still having indigestion over gmail MTAs]
>
> If I add another set of parens around everything that follows (#B) up
> to just before the close of the paren that opens before (#B), it looks
> like what I expect:
>
> % [[ 12345 = (#b)(?)((#B)((?)|([[:alnum:]](#c0,1))(?)))(#b)(*) ]]
> % print -l :$^match
> :1
> :2
> :345

With (p1|p2) zsh always matches left-to-right, not longest.  So
reversing the order of the alternate subexpressions:

% [[ 12345 = (#b)(?)((#B)(([[:alnum:]](#c0,1))(?)|(?)))(#b)(*) ]]
% print -l :$^match
:1
:23
:45


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

end of thread, other threads:[~2016-10-17 15:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-16  9:15 $match size limit, suspicious (#B) behavior Sebastian Gniazdowski
2016-10-16  9:40 ` Sebastian Gniazdowski
2016-10-17 14:51 ` Bart Schaefer
2016-10-17 15:00   ` 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).