zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Pattern matching seems to get confused, returns wrong offsets?
Date: Mon, 18 Jun 2018 09:13:22 +0200	[thread overview]
Message-ID: <CAKc7PVB24gzPWLPdYPAOBEe903eO7kcjKKBesmefaBHa4BZyYg@mail.gmail.com> (raw)

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


                 reply	other threads:[~2018-06-18  7:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKc7PVB24gzPWLPdYPAOBEe903eO7kcjKKBesmefaBHa4BZyYg@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).