Merged
Conversation
## Summary
This version introduces **Specificity** — an ordering and tie-breaking concept for selectors and expressions that allows our runtime to determine which module wins when multiple modules compete for a resource. The idea is borrowed from CSS, where more specific selectors take precedence, and adapted here for globs, selectors, and expressions in ZRX.
### Background
ZRX uses **selectors** to query and subscribe to resources. Selectors can be combined into **expressions** using `ANY`, `ALL`, and `NOT` operators. Each selector has 6 components, each of which can be a glob pattern:
```
zrs:<provider>:<resource>:<variant>:<context>:<location>:<fragment>
```
### How Specificity works
Each component contributes to a 4-tuple `(A, B, C, L)`:
- **A** — literal segments (most specific)
- **B** — single-wildcard segments (`*`, `?`)
- **C** — double-wildcard segments (`**`)
- **L** — literal character count (tiebreaker)
Tuples are compared lexicographically — higher is more specific. Expressions combine specificities according to their operator: `ALL` sums them (constraints stack), `ANY` takes the minimum (only as specific as the broadest arm), and `NOT` contributes nothing (it filters, but doesn't select).
### Examples
```sh
zrs:{git,file}:::{docs}:index.md: # (3, 0, 0, 15)
zrs::::docs:{index,about}.md: # (2, 0, 0, 12)
zrs:::::index.{md,rst}: # (1, 0, 0, 8)
zrs:::::{*}: # (0, 1, 0, 0)
```
This is an early alpha — documentation on using specificity in the router and other modules will follow. This release includes the core implementation for selectors and expressions.
Signed-off-by: squidfunk <martin.donath@squidfunk.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This version introduces Specificity — an ordering and tie-breaking concept for selectors and expressions that allows our runtime to determine which module wins when multiple modules compete for a resource. The idea is borrowed from CSS, where more specific selectors take precedence, and adapted here for globs, selectors, and expressions in ZRX.
Background
ZRX uses selectors to query and subscribe to resources. Selectors can be combined into expressions using
ANY,ALL, andNOToperators. Each selector has 6 components, each of which can be a glob pattern:How Specificity works
Each component contributes to a 4-tuple
(A, B, C, L):*,?)**)Tuples are compared lexicographically — higher is more specific. Expressions combine specificities according to their operator:
ALLsums them (constraints stack),ANYtakes the minimum (only as specific as the broadest arm), andNOTcontributes nothing (it filters, but doesn't select).Examples
zrs:{git,file}:::{docs}:index.md: # (3, 0, 0, 15) zrs::::docs:{index,about}.md: # (2, 0, 0, 12) zrs:::::index.{md,rst}: # (1, 0, 0, 8) zrs:::::{*}: # (0, 1, 0, 0)This is an early alpha — documentation on using specificity in the router and other modules will follow. This release includes the core implementation for selectors and expressions.