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

Re: Discovered pattern that ideally parses any quoting. Brackets highlighting in FSH.



On 1 August 2018 at 20:18, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Mon, Jul 30, 2018 at 12:09 AM, Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
>>
>> not only (z) can handle quoting, turns out regular pattern with while
>> loop can do it too:
>
> Yes, this is actually quite commonly done when writing ad-hoc parsers
> in perl via variations on
>
> while (s/^(the-leading-part)//g) {
>   do something with $1;
> }

I think my code is different. It matches distinct chars (not sure if
words are possible, sometimes  I think yes, sometimes it seems a no
go, I would have to write it) that we are interested in at the same
time handling backslash, " and '. So user can query for set of chars,
with their positions in buffer, without bothering with "are
backslashes even or odd" and other such problems. It turns out this
comes down to handling backslash, because of obvious "\\\A" problems
(parity of the slash), but also \" – it is also backslash that
controls whether double-quoting ends or begins. This is the [\\](*)
part of the pattern and restarting with ${match[3]}.

I realized that \', i.e. backslash and single quote, aren't special
within single quote. So the code needs update. But it is totally
possible, in the ${match[3]} block (the first one) one has to check if
state==in-single-quote, and decide to skip next char accordingly.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin



Messages sorted by: Reverse Date, Date, Thread, Author