From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6680 invoked by alias); 18 Jun 2018 07:13:47 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43049 Received: (qmail 28223 invoked by uid 1010); 18 Jun 2018 07:13:46 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi0-f52.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.218.52):SA:0(-1.9/5.0):. Processed in 0.641583 secs); 18 Jun 2018 07:13:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=7IcKWkrLwpOdngshUB0FBsFVlJFcUEcx4jKHblggww8=; b=D8Y9KGKQgzetr6Qjj59qquHHXEIxni2MIpFGGMP3bf8kIa2+OKzDnu6YXOxdmkXyjC 2lEzTMFQDmHOKh4BlD8QDh8x1SsK6vOGsMtUxxbC1VTey4c+yLpTqXxrUX4DHUSUxByf 08nJg+YqzyzMuNMgpkjLSnotID7ROmJveUTcPXAZcKNaltv5SpvY8I1Acj5wN4goKb95 u4dEiPJn+Uq1RuYOm2wJY1MZm3GJ3miQllXDM6a4aypZ/k2GsUfCvWFIaNJLIb4Hjg5E c9bqU6tV1JGaCubi8qspZku+RFlL2bG2DqkFqe1ziqziN/o211RHQbMR+MmliAuXbD5T YRUA== X-Gm-Message-State: APt69E1ppbKYSGWBaIo+6dhGSJjIHYFB1pQUf9BlG0gho0nC1oYSLixp cm+Cc3Dbk7EU22VxcAWRZ9i9mu9b+yOKhjwWlFqKIg== X-Google-Smtp-Source: ADUXVKK70XmBmoR+ghaP9T1jlb2+mc5bv24vfNwFBA3oCafItwNNxkPqRv1bJYqP08kUbV5Q+viILbWU+frWUaOF0Kk= X-Received: by 2002:aca:4f92:: with SMTP id d140-v6mr6690709oib.169.1529306022862; Mon, 18 Jun 2018 00:13:42 -0700 (PDT) MIME-Version: 1.0 From: Sebastian Gniazdowski Date: Mon, 18 Jun 2018 09:13:22 +0200 Message-ID: Subject: Pattern matching seems to get confused, returns wrong offsets? To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" 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