sublimehq / Packages

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

[RFC] Scopes for constant variables #458

Open FichteFoll opened 8 years ago

FichteFoll commented 8 years ago

(via #393)

It seems that the Ruby syntax defines entity.name.type.constant.ruby scopes for definitions to "constant variables". However, as with almost all other languages, this naming scheme is not enforced. Since this UPPER_CASE scheme is shared among almost all languages, it makes sense to unify this behavior for all languages. As such, I propose the following changes:

  1. Scope occurences of constants as variable.constant (sounds contradicting) or constant.other.user or similar.
  2. If desired, make assignments to constant variables receive a scope that will/can be indexed, i.e. entity.name.constant.

Opinions?

wbond commented 8 years ago

So far C uses entity.name.constant. I'll update Ruby to use this scope also since I imagine users will often want to highlight constants different than types.

Currently Ruby uses variable.other.constant for references to it. While C code usually uses uppercase for preprocessor macros, some classes are all uppercase also, and it would be odd to highlight those as constants. I feel like we will only be able to pull this off in languages that enforce formatting of variables versus constants, etc.

FichteFoll commented 8 years ago

Ruby emits warnings when re-assigning to uppercase identifiers, so I guess that counts? I don't know how it behaves with all-uppercase class names though.

Python only mentiones this in PEP8.

FichteFoll commented 6 years ago

For Python, via #1642, I made the minimum requirement of the identifier only consisting of upper-case letters, digits and underscores and having at least 2 consecutive letters. Imo this is heuristic is good enough, at least for Python code, but I believe this convention is followed among most languages that aren't C (or have macros in upper-case).

The scope name is variable.other.constant.python (#1242).