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

zstyle: "more specific" patterns and *-components



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.



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