Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Pattern matching seems to get confused, returns wrong offsets?



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