Sublime Forum

Repeated nesting of scopes resulting in wrong syntax highlighting?

#1

I’ve been trying to make my own syntax file but i’ve seem to run into some kind of problem when it comes to nesting blocks and the color they have applied to them. Specifically they don’t seem to get the correct color if their scope is both the ‘deepest’ one and if it also exists further up in the chain.
This might either be due to me not having understood the syntax/behaviour correctly or it’s some kind of bug.

I’ve made a test syntax specifically for this, it only contains three words followed by brace blocks. It also has rules as to how the blocks can be inside each other, alpha <-> beta <-> charlie.

Here is a screenshot of the problem

The upper block chain is the correct colors for each block, ie. purple for ‘alpha’, blue for ‘beta’ and green for 'charlie.
Notice how the middle one starts with the correct colors for alpha and beta but then for the first repeat of alpha the color keeps on being blue (beta’s color) until reaching the charlie block.

The scope tooltip http://i.imgur.com/lpXxnUz.png indicates that the scopes are in the correct order however.

I’ve uploaded all the files i’ve used here

Am I missing something or is this some kind of erroneous behaviour?

1 Like

#2

I have an issue which is similar to this too. I do not know how to deal with it since the nested structure could be complicated.


An interesting fact,

  • sublime.score_selector('s a b a b a', 'a') = 64
  • sublime.score_selector('s a b a b a', 'b') = 512

which means s a b a b a is preferred to be colored as b.

But people may expect it to be colored as a.


Ref: API doc https://www.sublimetext.com/docs/3/api_reference.html

1 Like

Problem with clear_scopes and BracketHighlighter
New rule in color scheme doesn't match what I expected
#3

That is interesting, i wasn’t aware of that command but it sheds some light of what is happening i think.
It appears like it scores based on 8^(depth)
for example
sublime.score_selector(‘a’, ‘a’) = 8
sublime.score_selector(‘a b’, ‘b’) = 64 = 8^2
sublime.score_selector(‘a b c’ , ‘c’) = 512 = 8^3
sublime.score_selector(‘a b c d’, ‘d’) = 4096 = 8^4
It also appears like the scoring completes when it first matches the correct scope
sublime.score_selector(‘a b b a a’, ‘a’) = 8

So i guess i would have to go about trying to override this behaviour?
What i’m looking for is basically just to give it the score of the last occurance of the character instead of the first occurance.

edit:
I manually edited my theme file to show how i would want it to look like

I also realized i probably can’t override the scoring since the sublime module with the score_selector function just calls the api and it makes sense that the executable would just directly use that rather than go through the api. :frowning:

0 Likes

[RFC] Specific scopes for punctuations
#4

There is an older report of this on the forum (I think late 2015) that I can’t seem to find right now. Just FYI.

0 Likes

#5

This one Repeated scopes and syntax highlighting seems to be the one you’re thinking of.
But nothing seemed to come of it and i wasn’t sure what people think of reviving old threads here so i made a new one.

1 Like

#6

That’s fine. I just wanted to reference another report for relevancy that could be of interest, but it appears you found that already. All good. :smile:

0 Likes

#7

I wonder if it could be the same bug or related to this one reported for JavaScript: https://github.com/sublimehq/Packages/issues/403

in which case, it will be fixed in the next build

0 Likes