Sublime Forum

Logical operators in selectors in sublime-syntax

#1

Are they supposed to work?

This seems to match more than I expect:

"scope": "(meta.parens | meta.brackets | meta.braces) (meta.parens | meta.brackets | meta.braces) punctuation.section"

E.g. it simply matches everything with just meta.parens.

I expect it to be equal to a permutation: any one of the three on the first place, any one of the three on the second, one nested inside another. If I list all the permutations manually, it does work:

"scope": "meta.parens meta.parens punctuation.section, meta.parens meta.brackets punctuation.section, meta.parens meta.braces punctuation.section, meta.brackets meta.parens punctuation.section, meta.brackets meta.brackets punctuation.section, meta.brackets meta.braces punctuation.section, meta.braces meta.parens punctuation.section, meta.braces meta.brackets punctuation.section, meta.braces meta.braces punctuation.section"

This doesn’t match meta.parens punctuation.section but does match meta.parens meta.parens punctuation.section, just as I expect.

Thanks!

0 Likes

#2

You can not perform operations on subscopes of a selector. Each operation can only combine an entire selector.

In short: (text, source) source does not expand to text source, source source and exhibits, afaik, undefined behavior.

2 Likes

#3

Any chance this could be changed? Seems like a nice to have feature, no?

0 Likes

#4

Seconded.

1 Like

#5

In what context are you utilizing the scope? You mention sublime-syntax, but I presume you are in fact using the API or a key binding?

1 Like

#6

No, it is syntax. I am building a paren/bracket/brace highlighter for Clojure, kind of rainbow highlighter (as you go deeper the color of brackets change). And it shouldn’t make a distinction between which type of bracket is used.

0 Likes

#7

I must be misunderstanding something. Can you post your example code with more context? The scope: key in syntax files is for setting the scope, so logical operators wouldn’t make sense there.

1 Like

#8

I may miss some important semantic distinction, but to me scope key in syntaxes looks like a selector and makes sense as a selector: if it matches, rule is applied.

Here’s the scheme I’m creating: https://github.com/tonsky/sublime-scheme-alabaster/blob/88b8241352ef059484ae9f664960f77cc5bdae72/Alabaster%20BG.sublime-color-scheme#L65-L71

The idea is to give topmost brackets/parens/braces different color than the inner ones. This works well for Lisps: if you see topmost color at the end of your form it means all brackets are perfectly balanced. This would be simpler if brackets/parens/braces share the same scope but according to https://www.sublimetext.com/docs/3/scope_naming.html they do not, so I am enumerating all possible combinations.

0 Likes

#9

Ok, so you are working on a color scheme (.sublime-color-scheme) whereas a syntax is defined with a .sublime-syntax file. Generally I think that selectors should work as you have given an example. I’ll look into reproducing the issue.

0 Likes

#10

OMG of course, sorry I messed this up. It is a color scheme, yes.

0 Likes

#11
>>> sublime.score_selector("a b c d", "(a | b)")
64
>>> sublime.score_selector("a b c d", "(a | b) (c | d)")
64
>>> sublime.score_selector("a b c d", "(a | b) (x | y)")
64

It seems that everything after the first closing parenthesis is ignored and that would match previous observations.

3 Likes

#12

It seems that everything after the first closing parenthesis is ignored and that would match previous observations.

It appears that according to the TextMate spec (https://macromates.com/textmate/manual/references), this is invalid syntax. The groups can only be “composited” with -, &, and |.

1 Like