In the .tmTheme file:
name
Entity name
It's not a regular expression; it's a scope selector borrowed from TextMate.
it's possible to AND, OR, and subtract scope selectors, e.g.:
(a | b) & c - dwould select the scope which is not matched by d, and matched by both c, and a or b.
In Sublime Text, you can find the scope of the character to the right of the cursor by going to Tools menu -> Developer -> Show Scope Name.
For testing selectors, you can use the view.match_selector or view.find_by_selector APIs in the Sublime Text console (View menu -> Show Console).
Example to see if the scope at the first cursor matches the selector from your first example:
view.match_selector(view.sel()[0].begin(), 'entity.name - (entity.name.filename | entity.name.section | entity.name.tag | entity.name.label)')
The following operators can be used:
-: without, anywhere in the scope (to be clear, this is a dash surrounded by spaces, as a dash can appear in the middle of a scope name)&: with, anywhere in the scope (in a .tmTheme file, which is XML, the & should be escaped to &, unless inside a CDATA node.) (space): with, must come after (i.e. to the right of) the preceding scope| and ,: or, anywhere in the scope(...) can be used to group selectors together.), therefore conflicts with the operators will never occur.string | comment is the same as string|comment.source.python using .python or *.python etc.| on it's own will fail, as will |source. source| works, however. - and source - will fail.In the following Python snippet, using the syntax test format, all the tests will pass, and thus it serves as a demonstration of how selectors work:
a = "hello world" # comment
# ^^^^^^^^^^^^^ string.quoted.double
# ^^^^^^^^^^^^^ string
# ^^^^^^^^^^^^^ string.quoted
# ^^^^^^^^^^^^^ string.quoted.
# ^^^^^^^^^^^^^ - quoted.double
# ^^^^^^^^^^^^^ string - comment
# ^^^^^^^^^^^^^ string, comment
# ^^^^^^^^^^^^^ string | comment
# ^^^^^^^^^^^^^ string & - comment
# ^^^^^^^^^^^^^ string & - comment
# ^^^^^^^^^^^^^ source string
# ^^^^^^^^^^^^^ source & (string - comment)
# ^^^^^^^^^^^^^ source - (string & comment)
# ^^^^^^^^^^^^^ string & source
# ^ source.python string.quoted.double.block.python punctuation.definition.string.begin.python
# ^ source & string & punctuation.definition.string.begin.python
# ^ string & punctuation & source
# ^ string punctuation & source
# ^ source punctuation & string
# ^ source string punctuation - (punctuation string)
# ^ string - source comment - punctuation source
# ^ string - source comment - comment
# ^ source - python
# ^ source - (source & python)
# ^ source - (source python)
# ^ source.python - source.python.string
# ^ source.python.. ..string..
# ^ comment - string
# ^ comment
# ^ comment, string
# ^^^^^^^^^^^^^^^^^^^ comment, string | source
# ^ (punctuation | string) & source.python - comment
# ^ (punctuation & string) & source.python - comment
Note that due to how scope selector specificity seems to ignore some of the more advanced constructs, you might find that .tmTheme rules you create with scope selectors apply or don't apply in cases you might not expect.