Sublime Forum

Question(terminology): Scope vs. scope selector

#1

1. Summary

I’m don’t understand use of terms scope, scope selector. Do I use the correct terms in my article?

2. Links

3. Details

Excerpt from the TextMate documentation:

A scope selector is a pattern much like a CSS selector which is matched against the scope of the caret (i.e. current context) and the outcome is either a match or a non-match (see also: ranking matches further down).

Scope selector

Example:

'source.python meta.structure.list.python meta.structure.list.item.python string.quoted.single.single-line.python '
  1. source.python meta.structure.list.python meta.structure.list.item.python string.quoted.single.single-line.python — is “scope” or “scope selector”? As far as I understand from TextMate documentation, “scope selector” more correct term.
  2. source.python — as it is right to call? “Syntax scope”, “syntax scope selector” or something else?

Thanks.

1 Like

#2

I think the difference between the two terms would be that if you’re talking about the meaning of a particular point in the document, you’re talking about the scope, but if you’re doing something that is trying to match a specific scope, then you’re talking about a scope selector instead.

For example, the Python.sublime.syntax is applying one or more scopes to each character in the buffer based on the rules of the Python language.

On the other hand, if you’re crafting a key binding, command, snippet or completion that you only want to trigger in certain cases, then what you’re doing is using a scope selector; you’re writing an expression of sorts that is saying "How closely does the scope at the current cursor position match this scope that I’m interested in.

4 Likes

#3

this is a valid scope [stack] and a valid scope selector, but as @OdatNurd says, the correct term depends on the usage - it is unfortunate that .sublime-snippet files use the keyword scope to refer to a scope selector…

the first item in the scope stack can be referred to as the base scope of the syntax

3 Likes

#4

Scopes are dotted identifiers, e.g. source.python. A token can have multiple scopes, ordered from least specific to most specific, e.g. source.python entity.name.function.python.

.tmPreferences files, and some other settings use scope selectors to filter what scopes the preferences apply to. Selectors can use the operators ,, &, | and (). See http://textmate.1073791.n5.nabble.com/formal-definition-of-scope-selector-syntax-td12109.html#a12114 for a little more info. Unfortunately the operators were never really defined in TextMate documentation. Perhaps at some point I’ll write our own copy.

3 Likes

#5

Some info on the operators would indeed be appreciated. For example, is a & b equivalent to b & a? Same with the | operator. Also, do the | and , operators have the same meaning?

0 Likes

#6
  • source.python meta.structure.list.python meta.structure.list.item.python string.quoted.single.single-line.python — token,
  • source.python — scope,
  • meta.structure.list.python — scope.

All right?

Maybe better “syntax scope”, because it is shorter term?

Thanks.

0 Likes

#7

One clarification: The multiple scopes are applied to a token. A token is a series of characters in a text file. The syntax defines the tokens via the regular expressions and then applies one or more scopes to the token.

2 Likes

#8

@wbond, maybe “scope token” — is better? “Token” — multivalued term, I don’t think it’s successful.

Thanks.

0 Likes