Skip to content

[RFC] Key-Value Separators #3228

@deathaxe

Description

@deathaxe

Relational

Several syntaxes such as Python, JavaScript or JSON support data objects in the form of arrays, lists or key-value pairs.

Those data objects can be grouped into:

  1. sequences
    • arrays (C, C++, ...)
    • lists (Python, JS, JSON, ...)
    • vectors (C++ std/boost library)
    • ...
  2. mappings (aka. key-value pairs)
    • dictionaries (VBScript)
    • maps (C++ std/boost library)
    • objects (JSON)
    • ...

That's pretty clearly expressed by meta scopes meta.sequence and meta.mapping.

List separators are commonly scoped punctuation.separator.sequence.

["item1", "item2", ...]
//      ^ punctuation.separator.sequence

The situation with mapping punctuations seems a bit more unclear at the moment which caused in several solutions having found their way into the wild.

{"key1": "value1", "key2": "value2", ...}
//     ^ punctuation.separator.???
//               ^ punctuation.separator.???

Motivation

The current situation is reflected by a couple of discussions started in pending PRs, such as #2682 (comment) or #2564 (comment) which re-introduces punctuation.separator.mapping to YAML, while it has been removed by 60e7c39.

If this topic has been discussed somewhere the related posts seem lost. Hence it may make sense to come up with a guideline how to commonly scope punctuations in data objects such as mappings or sequences in a (this) RFC issue.

Current Situation

The following table, started by @jwortmann, illustrates currently used scopes for separators of key-value pairs.

Syntax key-value separator, e.g. : or = entry separator, e.g. , or ; uses meta.mapping
BibTeX punctuation.separator.key-value punctuation.separator.mapping.pair ✔️
Cabal (PR) punctuation.separator.mapping.key-value - ✔️
CSS punctuation.separator.key-value punctuation.terminator.rule
D punctuation.separator.mapping.key-value punctuation.separator.sequence
Erlang punctuation.separator.mapping.key-value punctuation.separator.mapping.pair ✔️
JSON punctuation.separator.mapping.key-value punctuation.separator.mapping.pair ✔️
Java Properties punctuation.separator.mapping.key-value - ✔️
Git config keyword.operator.assignment - ✔️
JavaScript (object literal) punctuation.separator.key-value punctuation.separator.comma ✔️
Lua (table)* punctuation.separator.key-value punctuation.separator.field ✔️
Ruby punctuation.separator.key-value punctuation.separator.sequence
Perl punctuation.separator.key-value punctuation.separator.sequence
Python (dict) punctuation.separator.mapping.key-value punctuation.separator.mapping ✔️
YAML punctuation.separator.key-value.mapping -

Notes:

  • * not sure whether the Lua tables are directly comparable to the other mappings listed here
  • Some other syntaxes use punctuation.separator.key-value in non-data-object related expressions.

The concluding question is about priority of key-value vs. mapping or about which of both the more general part of a scope name is.

Both scope naming schemes punctuation.separator.key-value and punctuation.separator.mapping are both used with nearly the same amount, while the latter one found its way into syntaxes by being suggested by PackageDev's auto-completions.

Suggestion

We should probably condence those scopes to ...

  • punctuation.separator.key-value for key-value separaotrs
  • punctuation.separator.sequence for array items, list items and key-value-pairs

Reasons

  1. Not all syntaxes know about the concept of dictionaries/objects/mappings but still need a way to separate property keys from values.
  2. As a result of 1. punctuation.separator.key-value seems the more general scope which color schemes can use to target most possible tokens with just one simple selector.
  3. If it seems important to distinguish key-value separators of mappings from others meta.mapping punctuation.separator.key-value or ``punctuation.separator.key-value.mapping` may be used.
  4. A dictionary/object/mapping can be interpreted as a list of key-value pairs. Hence punctuation.separator.sequence seems suitable to separate key-value pairs.
  5. To further justify punctuation.separator.sequence - both, lists and objects often use the same character (e.g.: comma ,) to separate list items and key-value pairs (see: JSON). A common scope ensures both to be highlighted the same way by all color schemes. Further distinctions can be made by eighter meta.mapping punctuation.separator.sequence - meta.mapping meta.sequence or punctuation.separator.sequence.mapping if really needed.

Alternative

Distinguish between real data lists/objects and other kinds of key-value pairs, which means to keep punctuation.separator.mapping.key-value and punctuation.separator.key-value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions