Selectors Version:
Syntax definitions in Sublime Text use of scope names to provide metadata abouttokens. Scopes are dotted strings, specified from least-to-most specific. Forexample, theif keyword in PHP could be specified via the scope namekeyword.control.php. Tokens may have one or more scope names associatedwith them. Multiple scope names are associated with a token in an orderedmanner.
This document covers selectors, which are the means to match scope names. Colorschemes, key bindings, the API and even some settings all deal with selectorsin one way or another. For information about standardized scope names, pleasesee theScope Naming documentation.
Basic Matching🔗
A basic selector specifies one or more scope names, and is matched against atoken‘s scope names starting with the left-most scope. For a selector to matcha token‘s scope name, all of its labels must be present in the same order.
Scope Name | Selector | Matches |
|---|---|---|
keyword.control.php | keyword | yes |
keyword.control.php | keyword.control | yes |
keyword.control.php | control | no, |
keyword.control.php | keyword.cont | no, |
keyword.control.php | keyword.control.php.embedded | no, |
When a selector has multiple scope names, each must match one of the token‘sscope names, in order.
Scope Name | Selector | Matches |
|---|---|---|
source.php meta.block.php keyword.control.php | keyword | yes |
source.php meta.block.php keyword.control.php | meta keyword | yes |
source.php meta.block.php keyword.control.php | keyword meta | no, |
Logical Operators🔗
In addition to matching scope names based of label prefix matches, selectors mayalso specify logical operators.
Logical OR🔗
The logical OR operator is| or,. If either the selector to the rightor left of the operator is matched, the expression will be a match.
Scope Name | Selector | Matches |
|---|---|---|
source.php meta.block.php | text | meta | yes |
source.php | text, meta | no |
Logical AND🔗
The logical AND operator is&. It will require the selector to the right andleft of the operator are both matched for the expression to be a match. This isdifferent than a space between selectors, since that denoted hierarchy.
Scope Name | Selector | Matches |
|---|---|---|
source.php meta.block.php keyword.control.php | keyword & meta | yes |
source.php meta.block.php | keyword & meta | no |
Logical NOT🔗
The logical NOT operator is-. It will require the selector to the right tonot match for the expression to be a match.
Scope Name | Selector | Matches |
|---|---|---|
source.php meta.block.php | source - keyword | yes |
source.php meta.block.php keyword.control.php | source - keyword | no |
Grouping🔗
When working with logical operators, parentheses may be used to group selectors.
Scope Name | Selector | Matches |
|---|---|---|
source.php meta.block.php | source - (keyword | storage) | yes |
source.php meta.block.php | (source - source.php) | text | no |
Order of Operations🔗
Operators have the following precedence:
()Grouping-Logical NOT&Logical AND|Logical OR,Logical OR
Otherwise they are ordered left-to-right. So the following are equivalent:
a,b&-c|d,e(a,((b&(-c))|d)),e