Sublime Forum

Syntax definition test - Negative scope match

#1

Hello,
I’m trying to understand syntax definition testing, specifically the part with “negative scope matching”.
In docs (sublimetext.com/docs/syntax.html) it is briefly showed on final example…
“Hello, World! // not a comment”;
// ^ string.quoted.double
// ^ string.quoted.double - comment

… but unfortunately without any additional (textual) specification.

I figured that the ‘-’ token indicates negative match (following scope must not be present), but then I found out this test in official Package repository…
void Main(string[] args) {
/// ^^^^ storage.type
/// ^^^^^^^^^^^^^^^^^^^^^ meta.method
/// ^^^^^^^^^^^^^^^^^^^^^ - meta.method meta.method


… which kind of doesn’t work with my naïve understanding as this test would contradict itself, twice.

  1. How does the negative scope match actually work?
  2. Does the negative mark apply to only the immediately following scope or all following scopes in a give test line?
    Given following test line, does the negative match apply only to meta.B or to meta.C as well?
    /// ^^^ meta.A - meta.B meta.C
0 Likes

#2

https://www.sublimetext.com/docs/selectors.html

0 Likes

#3

Thank you for the link, it sheds a bit of light on the topic, tho I still have a hard time interpreting this test:
/// ^^^^^^^^^^^^^^^^^^^^^ - meta.method meta.method

To my understanding, this selector has two scope names/rules to match:
“- meta.method” -> Succeeds when there is no active scope that starts with “meta.method”
“meta.method” -> Succeeds when there is active scope that starts with “meta.method” after previous “rule”.

The first rule effectively guarantees that there is no “meta.method” scope active so the second rule can’t ever succeed in finding one, can it?

0 Likes