zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: Zsh workers <zsh-workers@zsh.org>
Subject: Re: PATCH: complete ldap search filters
Date: Sun, 19 Feb 2023 17:12:55 +0100	[thread overview]
Message-ID: <78599-1676823175.147342@t7nh.QcFd.gdPV> (raw)
In-Reply-To: <89765-1676677636.286144@jiXR.VaXn.4CXW>

I wrote:
> This adds a helper function for completing LDAP search filters

> It still needs some adapting to work properly with backslash quoting.

This further patch gets the quoting right. The completion system will
sometimes remove backslash quoting on ! which isn't helpful with
bang-history enabled. Ideally, _regex_arguments would let you do
matching against the unquoted form by supporting some sort of compset
-q.

The function ignores & (AND) and | (OR) operators where you would be
nesting them directly. It occurred to me that it should also do the same
for ! (NOT) - it's even more obvious why that's pointless.

Oliver

diff --git a/Completion/Unix/Type/_ldap_filters b/Completion/Unix/Type/_ldap_filters
index 919f9e266..5e0e30f01 100644
--- a/Completion/Unix/Type/_ldap_filters
+++ b/Completion/Unix/Type/_ldap_filters
@@ -4,7 +4,7 @@
 
 local -a expl excl optype disp end pre
 local -i nest=0
-local open='(' close=')'
+local open='(' close=')' andop='&' orop='|'
 
 [[ -prefix - ]] && return 1
 
@@ -40,25 +40,25 @@ local -a classes=( # Sampled from real servers, arbitrary other values allowed
   shadowAccount simpleSecurityObject top
 )
 
-compquote open close
+compquote open close andop orop
 open=${(q)open} close=${(q)close}
 # default to double rather than backslash quoting
-[[ -z $compstate[quote] || -z $PREFIX ]] && pre='"('
+[[ -z $compstate[quote] && -z $PREFIX ]] && pre='"('
 
 zstyle -s ":completion:${curcontext}:operators" list-separator sep || sep=--
 print -v disp -f "%s $sep %s" \| or \& and \! not
 end=( ") $sep end" )
-excl=( \\\| \& ) # compadd -F uses globs: only | needs quoting
+excl=( ! \\\| \& ) # compadd -F uses globs: only | needs quoting
 
 local -a query=(
   \( /$'*\0[ \t\n]#'/ \) # strip off any preceding arguments
   \(
-    \( "/${open}!/" -'optype[++nest]=0;pre=""'
-    \| "/${open}\|/" -'optype[++nest]=1;pre=""'
-    \| "/${open}&/" -'optype[++nest]=2;pre=""'
-    \| '/[]/' ':operators:operator:compadd -F "( ${(q)excl[optype[nest]]} )" -d disp -P ${pre:-${(Q)open}} -S \( \| \& \!' \)
+    \( "/${open}!/" -'optype[++nest]=1;pre=""'
+    \| "/${open}${(q)orop}/" -'optype[++nest]=2;pre=""'
+    \| "/${open}${andop}/" -'optype[++nest]=3;pre=""'
+    \| '/[]/' ':operators:operator:compadd -F "( ${(q)excl[optype[nest]]} )" -d disp -P ${pre:-${(Q)open}} -S ${(Q)open} \| \& \!' \)
   \|
-    \( '/[^)]##/' '%\)%' # pass over whole var=value, needed due to lack of backtracking after the following
+    \( "/${open}[^\\)]##/" "%$close%" # pass over whole var=value, needed due to lack of backtracking after the following
     \| "/${open}(#i)homeDirectory=/" '/[]/' ':directories:directory:_directories -P / -W / -r ") \t\n\-"'
     \| "/${open}(#i)loginShell=/" '/[]/' ':shells:shell:compadd -S ${(Q)close} ${(f)^"$(</etc/shells)"}(N)'
     \| "/${open}(#i)mail=/" '/[]/' ':email-addresses:mail:_email_addresses -S ${(Q)close}'
@@ -74,7 +74,7 @@ local -a query=(
       \|
         '/([~<>]|)=/' ':operators:operator:compadd -S "" "<=" \>= \~='
       \)
-      '/[^)]##/' '%\)%' ': _message -e object-values "object value (* for presence check)"'
+      '/[^\\)]##/' "%$close%" ': _message -e object-values "object value (* for presence check)"'
     \)
     "/$close/" -'(( nest ))' ':brackets:bracket:compadd ${=query[nest]:+-S ""} \)'
     \(
@@ -83,7 +83,7 @@ local -a query=(
       "/$close/" ':operators:operator:compadd ${=query[nest-1]:+-S ""} -d end -P ${(Q)close} ""'
       \( // -'(( --nest ))' \| '//' -'((!nest))' '/[]/' ': compadd ""' \)
     \) \#
-    // -'(( nest && optype[nest] ))'
+    // -'(( nest && optype[nest] > 1 ))'
   \) \#
 )
 


      reply	other threads:[~2023-02-19 16:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-17 23:47 Oliver Kiddle
2023-02-19 16:12 ` Oliver Kiddle [this message]

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=78599-1676823175.147342@t7nh.QcFd.gdPV \
    --to=opk@zsh.org \
    --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).