sublimehq / Packages

Syntax highlighting files shipped with Sublime Text and Sublime Merge
https://sublimetext.com
Other
2.95k stars 586 forks source link

RFC Scoping array sizes and indices #790

Open deathaxe opened 7 years ago

deathaxe commented 7 years ago

I am wondering how to correctly scope the several punctuations and their metas.

The Documentation wants us to use very general scopes like ...

    meta.brackets
    punctuation.section.brackets.begin
    punctuation.section.brackets.end

But there are several questions with it.

  1. When to use punctuation.definition. ... or punctuation.section. ...?
  2. How to distinguish brackets if a language uses them in several situations? It might be important for color scheme devs to know about the differences.
  3. Should/Must each scope begin with punctuation.definition.brackets or punctuation.section.brackets?

I can't find answers to these questions from the scopes being defined in the default packages. There seems to be no standard.

Considder a simple C array.

At the moment its begin and end is scoped with punctuation.section.brackets.begin/end. A color scheme can't therefore target an array definition or array usage in one syntax. It can't even use syntax independent colors for arrays at all as they might be defined using parentheses / '(...)' in other languages like VBasic. I have to ask the question whether it is a good idea to use too common scope names without reference to the context of an entity's usage?

I would rather prefer to scope common language entities instead of special characters. Just treat any language entities like you do with functions now.

One scope for definition meta.function. ... and one for usage meta.function-call. ...

Doing so with arrays as an example would help to show them with the same colors in all languages no matter whether an index is marked by [, ( or whatever.

Here is an example I would scope arrays like.

C++

int variable[10,10]
//          ^^^^^^^ meta.array.size.c++
//  ^ variable.other.c++
//          ^ punctuation.definition.array.size.begin.c++
//             ^ punctuation.separator.array.size
//                ^ punctuation.definition.array.size.end.c++

variable[0,0] = 0
//      ^^^^^ meta.array.index.c++
//      ^ punctuation.section.array.index.begin.c++
//        ^ punctuation.separator.index.c++
//          ^ punctuation.section.array.index.size.end.c++

VBScript

variable As Int(10,10)
'              ^^^^^^^ meta.array.size.vbscript
' <- variable.other.vbscript
'              ^ punctuation.definition.array.size.begin.vbscript
'                 ^ punctuation.separator.array.size.vbscript
'                    ^ punctuation.definition.array.size.end.vbscript

variable(0,0) = 0
'       ^^^^^ meta.array.index.vbscript
'       ^ punctuation.section.array.index.begin.vbscript
'         ^ punctuation.separator.index.vbscript
'          ^ punctuation.section.array.index.end.vbscript
Thom1729 commented 7 years ago

Are array literals (or dictionary literals, etc) within the scope of this question? The same section/definition distinction has been confusing me, and this confusion may be holding up #324. If they are within the scope of the question, it might be worth retitling it to clarify; if not, I can start a new issue.

FichteFoll commented 7 years ago

In https://github.com/sublimehq/Packages/pull/862, it has been proposed to use meta.sequence for array-like structures. For Python, that would most likley mean we use meta.sequence.tuple and meta.sequence.list to allow differentiation between the two sequence literal types. For JS, one could use meta.sequence.array, although this seems redudant since JS only has the array sequence type, afaik.

Note that this hasn't been pulled yet.

The section/definition distinction is a bit difficult and something that I keep wrapping my head around. For the moment, I mostly go by the rule of "if it is atomic (and can't span multiple lines), it's definition, otherwise section", but this isn't definitive.

Thom1729 commented 7 years ago

As an aside, is it even possible in Python to distinguish a tuple from a parenthesized expression? Or a set from a dictionary? The starting punctuation could be immediately followed by a newline.

FichteFoll commented 7 years ago

No, not really. Good observation. The example still works, though 👍