From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17205 invoked by alias); 31 Jul 2018 04:17:10 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23547 Received: (qmail 2444 invoked by uid 1010); 31 Jul 2018 04:17:09 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi0-f44.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.44):SA:0(-1.9/5.0):. Processed in 1.156452 secs); 31 Jul 2018 04:17:09 -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,RCVD_IN_MSPIKE_H2,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:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=bzGjJs5BvQSf3DCg42ByUiwYPF3lzZRLAyhr9p4kHvo=; b=KzJLpbB0WbexMp1j0neD3o6UI1By+Mps4l5OBHVhCe28EjoQ71io+/t2HYahn0CVJA Wy3d1P1Ppqjj9aCZKLcAcQmpJrCV4PFf0ga/vI4iifE5NBdui1WjrPzRbc42+l4rCTW8 AQYhxbGb6GU8LWoA1QElGot/wkX7rGhzl6lF7/aT2Xe3bhr3sJuUp35bxgIkPa+ZgBxv b9F6M4CvzL+To8w0R4F4cn3zaEEmiGV33EmuiRtLMdQ9+PpdkMQShCb40zEqRrxrOEiN TkbnbdFzDrI8SHRKDi+s3zYA/oSagfBDAoDKV5EuXsAaXidfM6BjA+U43A4lzCbvO3Yh VMTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=bzGjJs5BvQSf3DCg42ByUiwYPF3lzZRLAyhr9p4kHvo=; b=Rudakcl8YPJ95wWrp/As+PtRfh2YnBiLbaBZ53AMgi5HeXEUOKh3oZHpwnFSJVV9ww IJ/uput1DorSpBm+trR1Ux/PDP3jdV57zoaTFww+pEOWkhtLlyOgeuDH3Q7SqRF2CiyH 62vzYCrpiUq+iGuMwJ1DVpVmMAZrSZH65hcFvdC3Axk0FEZ7Su62X/zKglrvV96fMcJL jcE31gcE3KaU0A4nUmmBlh6Esv9FCbnsTlmgwmcLFfaJwo+MjorhZHeehd2g6qljyYmz vaqwwpmnIMdQ5KXLhw3R5QVhLfPZ2gwACepZ6y3ZttqB9Cba2++p7LS/jiPAoesshAE8 h7VQ== X-Gm-Message-State: AOUpUlEyIhs+XOats+wgpvyQGZt4euixo7hFrkaT9YlPJOYOaxDWHBzI bJNlJ/EPi/179TElswmQ/gJGZbAv67GVhEST6duGPFMY X-Google-Smtp-Source: AAOMgpeE2h3kijWVRdgaV4w4fIu0sYTEAHm+xR0J+6XGXYi1qaDd/zzLxy51oJxqjqCX5olnnethVzfv1B9x9neJXHU= X-Received: by 2002:aca:390a:: with SMTP id g10-v6mr22342645oia.145.1533010625814; Mon, 30 Jul 2018 21:17:05 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Sebastian Gniazdowski Date: Tue, 31 Jul 2018 06:16:45 +0200 Message-ID: Subject: Re: Discovered pattern that ideally parses any quoting. Brackets highlighting in FSH. To: Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable The brackets in the pattern obfuscate a little the idea, so here's minimal code that matches ABC instead, together with full ", ' handling. _mybuf=3D"A\AB'A'C"; while [[ $_mybuf =3D (#b)[^ABC\"\'\\]#(([ABC\"\'])|[\\](*))(*) ]]; do [[ -n "${match[3]}" ]] && { __idx+=3D${mbegin[1]}+1 _mybuf=3D"${match[3]:1}" # also skip 1 quoted char } || { [[ -z "$__quoting" ]] && { if [[ "${match[1]}" =3D [ABC] ]]; then echo "Got ${match[1]}" fi } [[ "${match[1]}" =3D \" && "$__quoting" !=3D \' ]] && { [[ "$__quoting" =3D '"' ]] && __quoting=3D"" || __quoting=3D'"'; } [[ "${match[1]}" =3D \' && "$__quoting" !=3D \" ]] && { [[ "$__quoting" =3D "'" ]] && __quoting=3D"" || __quoting=3D"'"; } _mybuf=3D"${match[4]}" # The last (*) in the pattern, i.e. remaining string, to become next input to while } done output: Got A Got B Got C On 30 July 2018 at 09:09, Sebastian Gniazdowski wr= ote: > Hello, > not only (z) can handle quoting, turns out regular pattern with while > loop can do it too: > > while [[ $_mybuf =3D (#b)[^"{}()[]\\\"'"]#((["({[]})\"'"])|[\\](*))(*= ) ]]; do > [[ -n "${match[3]}" ]] && { > __idx+=3D${mbegin[1]}+1 > _mybuf=3D"${match[3]:1}" # also skip 1 quoted char > } || { > > the main point is [\\](*). Parentheses are placed in ${match[3]} and > allow to restart processing skipping e.g. a quoted backslash. > > The rest is matching braces =E2=80=93 it's an example from > Fast-Syntax-Highlighting, it now has ideal brackets highlighting =E2=80= =93 AND > ALSO ", '. Simple handling of those two quotings allows to switch mode > "in quoting" "outside quoting". That's all. The effect: > > https://raw.githubusercontent.com/zdharma/fast-syntax-highlighting/master= /images/brackets.gif > > -- > Sebastian Gniazdowski > News: https://twitter.com/ZdharmaI > IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin --=20 Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin