* Pattern matching seems to get confused, returns wrong offsets?
@ 2018-06-18 7:13 Sebastian Gniazdowski
0 siblings, 0 replies; only message in thread
From: Sebastian Gniazdowski @ 2018-06-18 7:13 UTC (permalink / raw)
To: Zsh hackers list
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-06-18 7:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-18 7:13 Pattern matching seems to get confused, returns wrong offsets? Sebastian Gniazdowski
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).