Skip to content

Commit

Permalink
[JSON] Rewrite syntax
Browse files Browse the repository at this point in the history
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON (Basic).sublime-syntax` with `scope:source.json.basic`
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
- 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:
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette
    - 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)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by Jon
      in #285)
    - highlight leading & multiple commas as invalid, trailing as valid
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (thanks to Thomas)
        - scoped as plain unquoted strings
    - line continuation in strings (with tests thanks to Keith)
- Objects:
    - Add `meta.toc-list` scope to top level object keys to add them to
      the symbol list (also add tests, see below)
    - 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)
- Syntaxes:
    - 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 Thomas)
- Tests:
    - Significantly extend tests to cover more parts of the syntaxes
      defined.
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `jsonc` & `json5`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - scope: `meta.toc-list.json | meta.toc-list.json5`
        - languages: `json`, `jsonc` & `json5`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `jsonc` & `json5` 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 target `JSONC.sublime-syntax` instead to have
  the same user experience as before.


- fix #285
- address #481 to remove incompatible regex patterns according to Will
- address #757 to fix line comments for `JSONC` (thanks to Keith)
- address #2430 using sort-order (as requested by deathaxe)
- address #2852 to fix scopes of curly braces & square brackets in
  `JSON` (thanks to Thomas)
- address sublimehq/sublime_text#3154 and add symbol tests


Co-authored-by: Ashwin Shenoy <Ultra-Instinct-05@users.noreply.github.com>
Co-authored-by: Jack Cherng <jfcherng@users.noreply.github.com>
Co-authored-by: Janos Wortmann <jwortmann@users.noreply.github.com>
Co-authored-by: Jon Skinner <jps@sublimetext.com>
Co-authored-by: FichteFoll <FichteFoll@users.noreply.github.com>
Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com>
Co-authored-by: Michael B. Lyons <michaelblyons@users.noreply.github.com>
Co-authored-by: Rafał Chłodnicki <rchl@users.noreply.github.com>
Co-authored-by: Thomas Smith <Thom1729@users.noreply.github.com>
Co-authored-by: Will Bond <wbond@users.noreply.github.com>
Co-authored-by: deathaxe <deathaxe@users.noreply.github.com>
  • Loading branch information
12 people committed Dec 2, 2021
1 parent 4adc549 commit 5f71a8e
Show file tree
Hide file tree
Showing 56 changed files with 4,140 additions and 359 deletions.
1 change: 1 addition & 0 deletions JSON/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
25 changes: 25 additions & 0 deletions JSON/Comments - JSON5.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>scope</key>
<string>source.json.json5</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key><string>TM_COMMENT_START</string>
<key>value</key><string>// </string>
</dict>
<dict>
<key>name</key><string>TM_COMMENT_START_2</string>
<key>value</key><string>/*</string>
</dict>
<dict>
<key>name</key><string>TM_COMMENT_END_2</string>
<key>value</key><string>*/</string>
</dict>
</array>
</dict>
</dict>
</plist>
25 changes: 25 additions & 0 deletions JSON/Comments - JSONC.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>scope</key>
<string>source.json.jsonc</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key><string>TM_COMMENT_START</string>
<key>value</key><string>// </string>
</dict>
<dict>
<key>name</key><string>TM_COMMENT_START_2</string>
<key>value</key><string>/*</string>
</dict>
<dict>
<key>name</key><string>TM_COMMENT_END_2</string>
<key>value</key><string>*/</string>
</dict>
</array>
</dict>
</dict>
</plist>
31 changes: 0 additions & 31 deletions JSON/Comments.tmPreferences

This file was deleted.

25 changes: 25 additions & 0 deletions JSON/Context.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Packages/JSON/Context.sublime-menu


// This file is being maintained at:
// https://github.com/sublimehq/Packages/blob/master/JSON/Context.sublime-menu


[
{
"caption": "JSON: Minify",
"command": "json_minify"
},
{
"caption": "JSON: Prettify",
"command": "json_prettify"
},
{
"caption": "JSONC: Minify",
"command": "jsonc_minify"
},
{
"caption": "JSONC: Prettify",
"command": "jsonc_prettify"
}
]
25 changes: 25 additions & 0 deletions JSON/Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Packages/JSON/Default.sublime-commands


// This file is being maintained at:
// https://github.com/sublimehq/Packages/blob/master/JSON/Default.sublime-commands


[
{
"caption": "JSON: Minify JSON",
"command": "json_minify"
},
{
"caption": "JSON: Prettify JSON",
"command": "json_prettify"
},
{
"caption": "JSONC: Minify JSONC",
"command": "jsonc_minify"
},
{
"caption": "JSONC: Prettify JSONC",
"command": "jsonc_prettify"
}
]
65 changes: 36 additions & 29 deletions JSON/Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,63 +1,70 @@
// Packages/JSON/Default.sublime-keymap


// This file is being maintained at:
// https://github.com/sublimehq/Packages/blob/master/JSON/Default.sublime-keymap


[
// Auto-pair quotations: "key": '|',
{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'$0'"}, "context":
[
{ "key": "setting.auto_match_enabled" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "['\\w]$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
{ "key": "setting.auto_match_enabled" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "['\\w]$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
]
},

// Auto-pair quotations: "key": "|",
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"$0\""}, "context":
[
{ "key": "setting.auto_match_enabled" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"\\w]$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
{ "key": "setting.auto_match_enabled" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"\\w]$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
]
},

// Auto-pair braces: "key": {|},
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0}"}, "context":
[
{ "key": "setting.auto_match_enabled" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
{ "key": "setting.auto_match_enabled" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
]
},

// Auto-pair square brackets: "key": [|],
{ "keys": ["["], "command": "insert_snippet", "args": {"contents": "[$0]"}, "context":
[
{ "key": "setting.auto_match_enabled" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
{ "key": "setting.auto_match_enabled" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
]
},

// Add indented line in square brackets
{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
[
{ "key": "setting.auto_indent" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\[$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
{ "key": "setting.auto_indent" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\[$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
]
},
{ "keys": ["shift+enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
[
{ "key": "setting.auto_indent" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\[$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
{ "key": "setting.auto_indent" },
{ "key": "selector", "operand": "source.json" },
{ "key": "selection_empty", "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\[$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
]
},
]
]
Loading

0 comments on commit 5f71a8e

Please sign in to comment.