Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Pattern matching seems to get confused, returns wrong offsets?
- X-seq: zsh-workers 43049
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Pattern matching seems to get confused, returns wrong offsets?
- Date: Mon, 18 Jun 2018 09:13:22 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=7IcKWkrLwpOdngshUB0FBsFVlJFcUEcx4jKHblggww8=; b=B6nWb/hWWw4f5/VXq0B9HC1cTiMCCVGzrUdvCL376KJr5RyqeSK6BBDv8qBMIb3XGX aFUhbB8FVDxRgow81B7rOWpxC73PhSo+dKmGN+2+bbM0fEMFkU82ZHsIc2RSTqVa0VTD iWIkZZQ5JAN07q4AdQVHEpukf1vtnjmlphvUrZ2e5PZYMgwHLAPiOeoT4c1rCCpOWj8f 4MOF00vA0QK/I0hazFgDRufyCyTmNhjJmpwXoiWtpxdO3FXATi/m+XLvlq5hIZ7orguh HEmvlCy7CXU//y63bJxcc1d/NDLaiHRYQgJOTJ/rhZ9TAjZWIO/OClqh5PCp9PNKXn6X vi8g==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Hello,
I will describe pattern below, but first, the debug code. Just note
that pattern is solely first line, the next is printing of
match-variables:
__ar="hello \"in this' test"; [[ "$__ar" =
(#b)[^\"\'\\]#(#B)([\\][\\])#((\")([^\"\']#)(\')(#c0,1)|(\')([^\'\"]#)(\")(#c0,1))(*)
]] && \
print "mbegin[2]: $mbegin[2] ($match[2]), MBEGIN[3]: $mbegin[3]
($match[3]), mbegin[4]: $mbegin[4] ($match[4]) ==== OR ==== mbegin[5]:
$mbegin[5] ($match[5]), MBEGIN[6]: $mbegin[6] ($match[6]),
mbegin[7]:$mbegin[7] ($match[7]) === NEXT: ${match[8]} / ${mbegin[8]}"
mbegin[2]: -1 (), MBEGIN[3]: -1 (), mbegin[4]: -1 () ==== OR ====
mbegin[5]: 6 ('), MBEGIN[6]: 7 ( ), mbegin[7]:8 (") === NEXT: in this'
test / 9
The pattern is:
- not " or ' or \ a few times
- then optional even number of backslashes \
- then double quote
- not " or ' a few times
- then optional apostrophe
- following part is identical except it swaps ' and "
The patern is to simply match ", optional ', so that it is known "
covers '. Or the opposite, ' covers ".
Now take a look at debug print:
mbegin[2]: -1 (), MBEGIN[3]: -1 (), mbegin[4]: -1 () ==== OR ====
mbegin[5]: 6 ('), MBEGIN[6]: 7 ( ), mbegin[7]:8 (") === NEXT: in this'
test / 9
First "-oriented pattern block isn't matched. That's weird because the
string is:
__ar="hello \"in this' test"
" is first in $__ar. Now after the "== OR ==", it says ' is matched
and followed by ". But that's impossible, the string has only one '
and " and the order is opposite. The indices returned in mbegin vars
are completely weird:
% print "|$__ar[6,-1]|" # ${match[5]} value, claims it is '
| "in this' test|
% print "|$__ar[8,-1]|" # ${match[7]} value, claims it is "
|in this' test|
None of the indices point what they're claimed to in $match fields,
i.e. bodies of matchings, claiming to have ' or ".
What is wrong? Such situations often end in "missing }", but I double checked.
--
Best regards,
Sebastian Gniazdowski
Messages sorted by:
Reverse Date,
Date,
Thread,
Author