Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Key-Value Separators #3228

Open
deathaxe opened this issue Feb 3, 2022 · 4 comments
Open

[RFC] Key-Value Separators #3228

deathaxe opened this issue Feb 3, 2022 · 4 comments
Labels

Comments

@deathaxe
Copy link
Collaborator

deathaxe commented Feb 3, 2022

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.

@jrappen
Copy link
Contributor

jrappen commented Feb 13, 2022

I find your suggestion of using two scopes:

  • punctuation.separator.key-value
  • punctuation.separator.sequence

vs. three scopes:

  • punctuation.separator.mapping.key-value
  • punctuation.separator.mapping.pair
  • punctuation.separator.sequence

confusing when we have a situation within meta.mapping where:

  • we'd have a punctuation.separator.sequence as a replacement for punctuation.separator.mapping.pair
  • while making a difference between meta.sequence and meta.mapping

which would leave us with:

{ "key1": "value1", "key2": "value2", ... }
//      ^ meta.mapping punctuation.separator.key-value
//                ^ meta.mapping punctuation.separator.sequence

vs.:

{ "key1": "value1", "key2": "value2", ... }
//      ^ meta.mapping punctuation.separator.mapping.key-value
//                ^ meta.mapping punctuation.separator.mapping.pair

Or are you suggesting ❓

  • punctuation.separator.key-value.mapping
  • punctuation.separator.sequence.mapping
  • punctuation.separator.sequence

Is the main reason for this suggestion to limit scopes to three levels?


Random fact of the day: Emojis originate from Japan where they use a combination of ⭕ and ❌ vs. ✔️ and ❌.

@jwortmann
Copy link
Contributor

jwortmann commented Feb 14, 2022

Is the main reason for this suggestion to limit scopes to three levels?

From my point of view the main reason is to standardize a single scope name which can be used in all syntaxes, to make it easier for color schemes to target the key-value separators. As it was pointed out in the linked commit and previous discussions, "key-value" is more general than "mapping" at the third level of the scope name. The scope punctuation.separator.key-value is already used in a few syntaxes where it is not part of an actual mapping literal, for example in HTML:

<div class="foo">
<!--      ^ punctuation.separator.key-value - meta.mapping -->

For this reason we can't use punctuation.separator.mapping if we want to unify the scope names. And if you want to only target the separator punctuations which are inside of actual mapping literals, then it should be sufficient to use the selector meta.mapping punctuation.separator.key-value in color schemes.


When I looked at the Lua tables1 recently, I also had the idea about using punctuation.separator.sequence for the comma even inside of mappings, but I didn't suggest it because I thought it was too big of a change and might seem a bit confusing on first sight. But now I like it, because a mapping is just a sequence of key-value pairs (the meta.mapping scope is of course still kept to make this distinction possible). And it would make it even easier to target all the commas (or similar punctuation symbols) in both mappings and array structures at the same time, with only a single scope. If you want to target the commas in those two kind of structures differently, then you can use two separate rules and prepend the corresponding meta-scope for each rule.

The only drawback I see, is that the statement from the last sentence doesn't work for certain nested combinations of both mappings and arrays, because of the bug2 described in sublimehq/sublime_text#2152. This is probably only relevant for JSON, and I would think that the occasion that someone wants to target the commas in only one of mapping or array seems extremely unlikely and is negligible. Besides that, this "bug" should be fixed in ST core and shouldn't stop us from introducing consistent scope names.

Therefore I would say that appending a further mapping at the fourth level after key-value/sequence to the punctuation scope would be superfluous; we already have the meta.mapping.


(1) Afaik Lua tables are both mapping and array in one, you can use them like {"foo", "bar", "baz"} with normal array indexing (with consecutive index numbers assigned automatically for the keys), or add the keys yourself like {key1="foo", key2="bar", "baz", "foobar"}, even in mixed form.

(2)

>>> sublime.score_selector("meta.mapping meta.sequence meta.mapping punctuation.separator.sequence", "meta.mapping punctuation.separator.sequence")
12304
>>> sublime.score_selector("meta.mapping meta.sequence meta.mapping punctuation.separator.sequence", "meta.sequence punctuation.separator.sequence")
12416

@jrappen
Copy link
Contributor

jrappen commented Feb 16, 2022

Ok, I was confused for a bit because adding meta.mapping wasn't part of the suggestion.

@jrappen
Copy link
Contributor

jrappen commented Feb 16, 2022

I've added the requested changes to JSON. Will update #3097 soon accordingly.

jrappen added a commit to jrappen/sublime-json that referenced this issue Feb 16, 2022
FichteFoll pushed a commit to SublimeText/PackageDev that referenced this issue Feb 26, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit to deathaxe/sublime-packages that referenced this issue Mar 13, 2022
deathaxe added a commit that referenced this issue Mar 14, 2022
deathaxe added a commit that referenced this issue Mar 14, 2022
deathaxe added a commit that referenced this issue Mar 14, 2022
deathaxe added a commit that referenced this issue Mar 14, 2022
deathaxe added a commit that referenced this issue Apr 11, 2022
deathaxe added a commit that referenced this issue Apr 11, 2022
deathaxe added a commit that referenced this issue Apr 11, 2022
deathaxe added a commit that referenced this issue May 7, 2022
[Markdown] Refactor Syntax

Fixes #1930
Fixes #2542
Fixes #2857
Fixes #2942
Fixes #3073
Addresses #3154 (in ST3 compatible way)
Fixes #3157
Fixes #3170
Addresses #3228

This commit refactors Markdown syntax to 

1. improve compliance with CommonMark specification:
   https://spec.commonmark.org/0.30

   Many tests are added to proof compliance:
   https://spec.commonmark.org/0.30/spec.json

   Latest GFM syntax is based on CommonMark at the time writing,
   so those rules are included as well:
   https://github.github.com/gfm/

2. convert most anonymous to named contexts for better support
   of inheritance.

3. reorganize syntax into logical sections for better readability
   and maintainability.

4. address most Markdown related issues of sublimehq/Packages repo.
   
Main changes are:

- fix CommonMark compatibility of backslash escapes
- fix CommonMark compatibility of block quotes
- fix CommonMark compatibility of html entities
- fix CommonMark compatibility of fenced code blocks
- fix CommonMark compatibility of indented code blocks
  (mixed tabs/spaces)
- fix CommonMark compatibility of reference definitions
- fix CommonMark compatibility of thematic breaks
- update strike-through markup to use 2 tildes only
- reorganizing contexts in logical sections

Benchmarks:

This commit has no impact on parsing performance.

Notes: 

1. Some remaining CommonMark incompatibilities need further work
   using ST4's "branching" feature.
2. Main refactoring work was done in MarkdownEditing package and
   released with version 3.1.1. This commit contains the result
   of that work, except some features which rely on 3rd-party
   (syntax) packages.

   Removed features are:
   - coffee script support in front-matter
   - numerous code-block syntaxes (E.g.: Ada, Coffee Script, ...)
   - LaTex blocks
   - custom `<kbd>` tag highlighting as it doesn't meet 
     quality expectations
jrappen added a commit to jrappen/Packages that referenced this issue May 31, 2022
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
    - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet`
- Add many more file extensions for `JSON` & `JSONC`:
    - add doc links to extensions where applicable as a reference to be
      able to more quickly verify that they (still) use said syntax
      flavor
- JSON:
    - Make use of newer syntax features including those only available
      in `version: 2` syntaxes
    - Make use of `variables` (with optimizations provided by @deathaxe
      and regex patterns provided by @Thom1729)
    - Context names now more closely match the naming scheme of other
      (recently re-written) default syntaxes
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette. JSON code can
      optionally be auto-prettified on pre save events.
    - highlight leading, trailing & multiple commas as invalid
    - only allow exactly one structure (object, array) or value
      (constant, number, string) at top level (thanks to @keith-hall)
    - links (`meta.link.inet`) and email addresses (`meta.link.email`) are
      scoped the same as in Markdown (thanks to @deathaxe)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by
      @jskinner in sublimehq#285)
    - highlight leading & multiple commas as invalid, trailing as valid
    - scope empty block comments as such
    - support syntax based folding of ST4131+,
      compare sublimehq#3291
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (regexes thanks to @Thom1729)
        - scoped as plain unquoted strings (thanks to @Thom1729)
        - support string interpolation (thanks to @deathaxe)
    - line continuation in strings (with tests thanks to @keith-hall)
- JSON.NET:
    - support requested by @keith-hall,
      built with feedback from @michaelblyons
- Objects:
    - Highlighting speed improvements for empty objects (thanks to
      @FichteFoll)
    - Make `mapping.*` contexts more modular
- Arrays:
    - Highlighting speed improvements for empty arrays (thanks to
      @FichteFoll)
- Numbers:
    - Correctly scope number signs with `constant.numeric.sign` instead
      of `keyword.operator.arithmetic`
    - Significantly improve number highlighting (thanks to @deathaxe)
- Completions:
    - completions have been added for language constants, including kind info
      and details (with links to docs)
        - `null`, `false`, `true` for JSON
        - `Infinity` and `NaN` for JSON5
- Settings:
    - a `default_extension` is now set for all JSON flavors
- Symbol index:
    - with an object structure at the top-level, only top-level keys
      within now show up in the index (including tests for symbols and
      syntax)
- Tests:
    - test files now test the base scope
    - Significantly extend tests to cover more parts of the syntaxes
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `json5` & `jsonc`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - top-level keys of object structures (thanks to deathaxe)
        - languages: `json`, `json5` & `jsonc`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `json5` & `jsonc` to behave similarly to
  `GitHub Flavored Markdown`

BREAKING CHANGES:

- JSON does not have values that can be set via an inline calculation
  with the help of operators, but only simple number values. Scopes for
  number signs have changed from being `keyword.operator.arithmetic` to
  `constant.numeric.sign`. Color scheme authors should add this, should
  it be missing.
- The `JSON.sublime-syntax` now marks comments as `invalid`, third party
  plugin authors should instead target `JSONC.sublime-syntax` to keep
  the user experience as-is.
- Indexed symbols (i.e. top-level keys in JSON object structures) are
  scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`.
  Color scheme authors should add special highlighting to differentiate
  them from other keys.

- fix sublimehq#285
- address sublimehq#421 (thanks to @FichteFoll)
- address sublimehq#481 to remove incompatible regex patterns according
  to @wbond
- address sublimehq#757 to fix line comments for `JSONC` (thanks to
  @keith-hall)
- address sublimehq#2430 using sort-order (as requested by @deathaxe)
- address sublimehq#2711 with regards to `constant.language.null`
  vs. `constant.language.empty` (thanks to @FichteFoll)
- address sublimehq#2852 to fix scopes of curly braces & square
  brackets in `JSON` (thanks to @Thom1729)
- address sublimehq#3228 to fix `punctuation.separator` scopes,
  compare sublimehq#3270
- address sublimehq/sublime_text#3154 and add symbol tests

Co-authored-by: Ashwin Shenoy <[email protected]>
Co-authored-by: Jack Cherng <[email protected]>
Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Jon Skinner <[email protected]>
Co-authored-by: FichteFoll <[email protected]>
Co-authored-by: Keith Hall <[email protected]>
Co-authored-by: Michael B. Lyons <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Will Bond <[email protected]>
Co-authored-by: deathaxe <[email protected]>
jrappen added a commit to jrappen/Packages that referenced this issue May 31, 2022
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
    - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet`
- Add many more file extensions for `JSON` & `JSONC`:
    - add doc links to extensions where applicable as a reference to be
      able to more quickly verify that they (still) use said syntax
      flavor
- JSON:
    - Make use of newer syntax features including those only available
      in `version: 2` syntaxes
    - Make use of `variables` (with optimizations provided by @deathaxe
      and regex patterns provided by @Thom1729)
    - Context names now more closely match the naming scheme of other
      (recently re-written) default syntaxes
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette. JSON code can
      optionally be auto-prettified on pre save events.
    - highlight leading, trailing & multiple commas as invalid
    - only allow exactly one structure (object, array) or value
      (constant, number, string) at top level (thanks to @keith-hall)
    - links (`meta.link.inet`) and email addresses (`meta.link.email`) are
      scoped the same as in Markdown (thanks to @deathaxe)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by
      @jskinner in sublimehq#285)
    - highlight leading & multiple commas as invalid, trailing as valid
    - scope empty block comments as such
    - support syntax based folding of ST4131+,
      compare sublimehq#3291
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (regexes thanks to @Thom1729)
        - scoped as plain unquoted strings (thanks to @Thom1729)
        - support string interpolation (thanks to @deathaxe)
    - line continuation in strings (with tests thanks to @keith-hall)
- JSON.NET:
    - support requested by @keith-hall,
      built with feedback from @michaelblyons
- Objects:
    - Highlighting speed improvements for empty objects (thanks to
      @FichteFoll)
    - Make `mapping.*` contexts more modular
- Arrays:
    - Highlighting speed improvements for empty arrays (thanks to
      @FichteFoll)
- Numbers:
    - Correctly scope number signs with `constant.numeric.sign` instead
      of `keyword.operator.arithmetic`
    - Significantly improve number highlighting (thanks to @deathaxe)
- Completions:
    - completions have been added for language constants, including kind info
      and details (with links to docs)
        - `null`, `false`, `true` for JSON
        - `Infinity` and `NaN` for JSON5
- Settings:
    - a `default_extension` is now set for all JSON flavors
- Symbol index:
    - with an object structure at the top-level, only top-level keys
      within now show up in the index (including tests for symbols and
      syntax)
- Tests:
    - test files now test the base scope
    - Significantly extend tests to cover more parts of the syntaxes
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `json5` & `jsonc`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - top-level keys of object structures (thanks to deathaxe)
        - languages: `json`, `json5` & `jsonc`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `json5` & `jsonc` to behave similarly to
  `GitHub Flavored Markdown`

BREAKING CHANGES:

- JSON does not have values that can be set via an inline calculation
  with the help of operators, but only simple number values. Scopes for
  number signs have changed from being `keyword.operator.arithmetic` to
  `constant.numeric.sign`. Color scheme authors should add this, should
  it be missing.
- The `JSON.sublime-syntax` now marks comments as `invalid`, third party
  plugin authors should instead target `JSONC.sublime-syntax` to keep
  the user experience as-is.
- Indexed symbols (i.e. top-level keys in JSON object structures) are
  scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`.
  Color scheme authors should add special highlighting to differentiate
  them from other keys.

- fix sublimehq#285
- address sublimehq#421 (thanks to @FichteFoll)
- address sublimehq#481 to remove incompatible regex patterns according
  to @wbond
- address sublimehq#757 to fix line comments for `JSONC` (thanks to
  @keith-hall)
- address sublimehq#2430 using sort-order (as requested by @deathaxe)
- address sublimehq#2711 with regards to `constant.language.null`
  vs. `constant.language.empty` (thanks to @FichteFoll)
- address sublimehq#2852 to fix scopes of curly braces & square
  brackets in `JSON` (thanks to @Thom1729)
- address sublimehq#3228 to fix `punctuation.separator` scopes,
  compare sublimehq#3270
- address sublimehq/sublime_text#3154 and add symbol tests

Co-authored-by: Ashwin Shenoy <[email protected]>
Co-authored-by: Jack Cherng <[email protected]>
Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Jon Skinner <[email protected]>
Co-authored-by: FichteFoll <[email protected]>
Co-authored-by: Keith Hall <[email protected]>
Co-authored-by: Michael B. Lyons <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Will Bond <[email protected]>
Co-authored-by: deathaxe <[email protected]>
jrappen added a commit to jrappen/Packages that referenced this issue May 31, 2022
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
    - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet`
- Add many more file extensions for `JSON` & `JSONC`:
    - add doc links to extensions where applicable as a reference to be
      able to more quickly verify that they (still) use said syntax
      flavor
- JSON:
    - Make use of newer syntax features including those only available
      in `version: 2` syntaxes
    - Make use of `variables` (with optimizations provided by @deathaxe
      and regex patterns provided by @Thom1729)
    - Context names now more closely match the naming scheme of other
      (recently re-written) default syntaxes
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette. JSON code can
      optionally be auto-prettified on pre save events.
    - highlight leading, trailing & multiple commas as invalid
    - only allow exactly one structure (object, array) or value
      (constant, number, string) at top level (thanks to @keith-hall)
    - links (`meta.link.inet`) and email addresses (`meta.link.email`) are
      scoped the same as in Markdown (thanks to @deathaxe)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by
      @jskinner in sublimehq#285)
    - highlight leading & multiple commas as invalid, trailing as valid
    - scope empty block comments as such
    - support syntax based folding of ST4131+,
      compare sublimehq#3291
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (regexes thanks to @Thom1729)
        - scoped as plain unquoted strings (thanks to @Thom1729)
        - support string interpolation (thanks to @deathaxe)
    - line continuation in strings (with tests thanks to @keith-hall)
- JSON.NET:
    - support requested by @keith-hall,
      built with feedback from @michaelblyons
- Objects:
    - Highlighting speed improvements for empty objects (thanks to
      @FichteFoll)
    - Make `mapping.*` contexts more modular
- Arrays:
    - Highlighting speed improvements for empty arrays (thanks to
      @FichteFoll)
- Numbers:
    - Correctly scope number signs with `constant.numeric.sign` instead
      of `keyword.operator.arithmetic`
    - Significantly improve number highlighting (thanks to @deathaxe)
- Completions:
    - completions have been added for language constants, including kind info
      and details (with links to docs)
        - `null`, `false`, `true` for JSON
        - `Infinity` and `NaN` for JSON5
- Settings:
    - a `default_extension` is now set for all JSON flavors
- Symbol index:
    - with an object structure at the top-level, only top-level keys
      within now show up in the index (including tests for symbols and
      syntax)
- Tests:
    - test files now test the base scope
    - Significantly extend tests to cover more parts of the syntaxes
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `json5` & `jsonc`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - top-level keys of object structures (thanks to deathaxe)
        - languages: `json`, `json5` & `jsonc`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `json5` & `jsonc` to behave similarly to
  `GitHub Flavored Markdown`

BREAKING CHANGES:

- JSON does not have values that can be set via an inline calculation
  with the help of operators, but only simple number values. Scopes for
  number signs have changed from being `keyword.operator.arithmetic` to
  `constant.numeric.sign`. Color scheme authors should add this, should
  it be missing.
- The `JSON.sublime-syntax` now marks comments as `invalid`, third party
  plugin authors should instead target `JSONC.sublime-syntax` to keep
  the user experience as-is.
- Indexed symbols (i.e. top-level keys in JSON object structures) are
  scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`.
  Color scheme authors should add special highlighting to differentiate
  them from other keys.

- fix sublimehq#285
- address sublimehq#421 (thanks to @FichteFoll)
- address sublimehq#481 to remove incompatible regex patterns according
  to @wbond
- address sublimehq#757 to fix line comments for `JSONC` (thanks to
  @keith-hall)
- address sublimehq#2430 using sort-order (as requested by @deathaxe)
- address sublimehq#2711 with regards to `constant.language.null`
  vs. `constant.language.empty` (thanks to @FichteFoll)
- address sublimehq#2852 to fix scopes of curly braces & square
  brackets in `JSON` (thanks to @Thom1729)
- address sublimehq#3228 to fix `punctuation.separator` scopes,
  compare sublimehq#3270
- address sublimehq/sublime_text#3154 and add symbol tests

Co-authored-by: Ashwin Shenoy <[email protected]>
Co-authored-by: Jack Cherng <[email protected]>
Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Jon Skinner <[email protected]>
Co-authored-by: FichteFoll <[email protected]>
Co-authored-by: Keith Hall <[email protected]>
Co-authored-by: Michael B. Lyons <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Will Bond <[email protected]>
Co-authored-by: deathaxe <[email protected]>
jrappen added a commit to jrappen/Packages that referenced this issue Jun 1, 2022
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
    - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet`
- Add many more file extensions for `JSON` & `JSONC`:
    - add doc links to extensions where applicable as a reference to be
      able to more quickly verify that they (still) use said syntax
      flavor
- JSON:
    - Make use of newer syntax features including those only available
      in `version: 2` syntaxes
    - Make use of `variables` (with optimizations provided by @deathaxe
      and regex patterns provided by @Thom1729)
    - Context names now more closely match the naming scheme of other
      (recently re-written) default syntaxes
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette. JSON code can
      optionally be auto-prettified on pre save events.
    - highlight leading, trailing & multiple commas as invalid
    - only allow exactly one structure (object, array) or value
      (constant, number, string) at top level (thanks to @keith-hall)
    - links (`meta.link.inet`) and email addresses (`meta.link.email`) are
      scoped the same as in Markdown (thanks to @deathaxe)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by
      @jskinner in sublimehq#285)
    - highlight leading & multiple commas as invalid, trailing as valid
    - scope empty block comments as such
    - support syntax based folding of ST4131+,
      compare sublimehq#3291
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (regexes thanks to @Thom1729)
        - scoped as plain unquoted strings (thanks to @Thom1729)
        - support string interpolation (thanks to @deathaxe)
    - line continuation in strings (with tests thanks to @keith-hall)
- JSON.NET:
    - support requested by @keith-hall,
      built with feedback from @michaelblyons
- Objects:
    - Highlighting speed improvements for empty objects (thanks to
      @FichteFoll)
    - Make `mapping.*` contexts more modular
- Arrays:
    - Highlighting speed improvements for empty arrays (thanks to
      @FichteFoll)
- Numbers:
    - Correctly scope number signs with `constant.numeric.sign` instead
      of `keyword.operator.arithmetic`
    - Significantly improve number highlighting (thanks to @deathaxe)
- Completions:
    - completions have been added for language constants, including kind info
      and details (with links to docs)
        - `null`, `false`, `true` for JSON
        - `Infinity` and `NaN` for JSON5
- Settings:
    - a `default_extension` is now set for all JSON flavors
- Symbol index:
    - with an object structure at the top-level, only top-level keys
      within now show up in the index (including tests for symbols and
      syntax)
- Tests:
    - test files now test the base scope
    - Significantly extend tests to cover more parts of the syntaxes
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `json5` & `jsonc`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - top-level keys of object structures (thanks to deathaxe)
        - languages: `json`, `json5` & `jsonc`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `json5` & `jsonc` to behave similarly to
  `GitHub Flavored Markdown`

BREAKING CHANGES:

- JSON does not have values that can be set via an inline calculation
  with the help of operators, but only simple number values. Scopes for
  number signs have changed from being `keyword.operator.arithmetic` to
  `constant.numeric.sign`. Color scheme authors should add this, should
  it be missing.
- The `JSON.sublime-syntax` now marks comments as `invalid`, third party
  plugin authors should instead target `JSONC.sublime-syntax` to keep
  the user experience as-is.
- Indexed symbols (i.e. top-level keys in JSON object structures) are
  scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`.
  Color scheme authors should add special highlighting to differentiate
  them from other keys.

- fix sublimehq#285
- address sublimehq#421 (thanks to @FichteFoll)
- address sublimehq#481 to remove incompatible regex patterns according
  to @wbond
- address sublimehq#757 to fix line comments for `JSONC` (thanks to
  @keith-hall)
- address sublimehq#2430 using sort-order (as requested by @deathaxe)
- address sublimehq#2711 with regards to `constant.language.null`
  vs. `constant.language.empty` (thanks to @FichteFoll)
- address sublimehq#2852 to fix scopes of curly braces & square
  brackets in `JSON` (thanks to @Thom1729)
- address sublimehq#3228 to fix `punctuation.separator` scopes,
  compare sublimehq#3270
- address sublimehq/sublime_text#3154 and add symbol tests

Co-authored-by: Ashwin Shenoy <[email protected]>
Co-authored-by: Jack Cherng <[email protected]>
Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Jon Skinner <[email protected]>
Co-authored-by: FichteFoll <[email protected]>
Co-authored-by: Keith Hall <[email protected]>
Co-authored-by: Michael B. Lyons <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Will Bond <[email protected]>
Co-authored-by: deathaxe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants