zsh-workers
 help / color / mirror / code / Atom feed
* zstyle: "more specific" patterns and *-components
@ 2020-04-27 10:14 Daniel Shahaf
  2020-04-27 16:10 ` Roman Perepelitsa
  2020-04-27 18:54 ` dana
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Shahaf @ 2020-04-27 10:14 UTC (permalink / raw)
  To: zsh-workers

What would you expect
.
    zstyle ':foo:bar:*' lorem world
    zstyle ':foo:*:baz:*' lorem hello
    zstyle -s ':foo:bar:baz:qux' lorem REPLY && print $REPLY
.
to print?

For reference, the documentation specifies:

> A pattern is considered to be more specific
> than another if it contains more components (substrings separated by
> colons) or if the patterns for the components are more specific, where 
> simple strings are considered to be more specific than patterns and
> complex patterns are considered to be more specific than the pattern
> `tt(*)'.  A `tt(*)' in the pattern will match zero or more characters
> in the context; colons are not treated specially in this regard.
> If two patterns are equally specific, the tie is broken in favour of
> the pattern that was defined first.

(This part of the documentation was recently changed in users/24656, by
me, but I didn't intend to change its meaning, only to clarify it.)

---

Currently, that prints "world", and would print "hello" if the first
two lines were reordered.  That's because setstypat() gives a weight
of 0 to colon-separated pattern components that consist of a single
asterisk and nothing else: the two patterns are considered equally
specific, so the first one defined wins.

However, going by the documentation I expected ':foo:*:baz:*' to be
considered more specific than ':foo:bar:*' (because it contains more
components: 'three literal strings and two asterisks' is more than
'three literal strings and one asterisk'), and therefore, 'hello' to be
printed regardless of the order of the first two lines.

WDYT?

Cheers,

Daniel

P.S. The three literal strings are ("" "foo" "bar") in the first
pattern and ("" "foo" "baz") in the second pattern.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-28 20:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27 10:14 zstyle: "more specific" patterns and *-components Daniel Shahaf
2020-04-27 16:10 ` Roman Perepelitsa
2020-04-27 17:38   ` Mikael Magnusson
2020-04-28 19:06   ` Daniel Shahaf
2020-04-28 19:30     ` dana
2020-04-28 20:20       ` Daniel Shahaf
2020-04-27 18:54 ` dana

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).