Skip to content

Commit 14779e2

Browse files
jrappenAshwin Shenoyjfcherngjwortmannjskinner
committed
[JSON] Rewrite syntax
- 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 #285) - highlight leading & multiple commas as invalid, trailing as valid - scope empty block comments as such - support syntax based folding of ST4131+, compare #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 #285 - address #421 (thanks to @FichteFoll) - address #481 to remove incompatible regex patterns according to @wbond - address #757 to fix line comments for `JSONC` (thanks to @keith-hall) - address #2430 using sort-order (as requested by @deathaxe) - address #2711 with regards to `constant.language.null` vs. `constant.language.empty` (thanks to @FichteFoll) - address #2852 to fix scopes of curly braces & square brackets in `JSON` (thanks to @Thom1729) - address #3228 to fix `punctuation.separator` scopes, compare #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]>
1 parent ee0146e commit 14779e2

File tree

74 files changed

+4725
-374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4725
-374
lines changed

HTML/syntax_test_html.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,23 @@
127127

128128
<script type=application/json>
129129
{
130-
## ^ source.json.embedded.html meta.mapping.json punctuation.section.mapping.begin.json
130+
## ^ source.json.embedded.html meta.mapping.json punctuation.definition.mapping.begin.json
131131
"key": "value",
132132
## ^^^^^ source.json.embedded.html meta.mapping.key.json
133133
## ^^^^^^^ source.json.embedded.html meta.mapping.value.json
134134
}
135-
## ^ source.json.embedded.html meta.mapping.json punctuation.section.mapping.end.json
135+
## ^ source.json.embedded.html meta.mapping.json punctuation.definition.mapping.end.json
136136
</script>
137137

138138
<script type="whatever+json">
139139
<![CDATA[
140140
{
141-
## ^ meta.tag.sgml.cdata.html source.json.embedded.html meta.mapping.json punctuation.section.mapping.begin.json
141+
## ^ meta.tag.sgml.cdata.html source.json.embedded.html meta.mapping.json punctuation.definition.mapping.begin.json
142142
"key": "value",
143143
## ^^^^^ meta.tag.sgml.cdata.html source.json.embedded.html meta.mapping.key.json
144144
## ^^^^^^^ meta.tag.sgml.cdata.html source.json.embedded.html meta.mapping.value.json
145145
}
146-
## ^ meta.tag.sgml.cdata.html source.json.embedded.html meta.mapping.json punctuation.section.mapping.end.json
146+
## ^ meta.tag.sgml.cdata.html source.json.embedded.html meta.mapping.json punctuation.definition.mapping.end.json
147147
]]>
148148
</script>
149149

JSON/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

JSON/Comments - JSON5.tmPreferences

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plist version="1.0">
3+
<dict>
4+
<key>scope</key>
5+
<string>source.json.json5</string>
6+
<key>settings</key>
7+
<dict>
8+
<key>shellVariables</key>
9+
<array>
10+
<dict>
11+
<key>name</key><string>TM_COMMENT_START</string>
12+
<key>value</key><string>// </string>
13+
</dict>
14+
<dict>
15+
<key>name</key><string>TM_COMMENT_START_2</string>
16+
<key>value</key><string>/*</string>
17+
</dict>
18+
<dict>
19+
<key>name</key><string>TM_COMMENT_END_2</string>
20+
<key>value</key><string>*/</string>
21+
</dict>
22+
</array>
23+
</dict>
24+
</dict>
25+
</plist>

JSON/Comments - JSONC.tmPreferences

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plist version="1.0">
3+
<dict>
4+
<key>scope</key>
5+
<string>source.json.jsonc</string>
6+
<key>settings</key>
7+
<dict>
8+
<key>shellVariables</key>
9+
<array>
10+
<dict>
11+
<key>name</key><string>TM_COMMENT_START</string>
12+
<key>value</key><string>// </string>
13+
</dict>
14+
<dict>
15+
<key>name</key><string>TM_COMMENT_START_2</string>
16+
<key>value</key><string>/*</string>
17+
</dict>
18+
<dict>
19+
<key>name</key><string>TM_COMMENT_END_2</string>
20+
<key>value</key><string>*/</string>
21+
</dict>
22+
</array>
23+
</dict>
24+
</dict>
25+
</plist>

JSON/Comments.tmPreferences

Lines changed: 0 additions & 31 deletions
This file was deleted.

JSON/Context.sublime-menu

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Packages/JSON/Context.sublime-menu
2+
3+
4+
// This file is being maintained at:
5+
// https://github.com/sublimehq/Packages/blob/master/JSON/Context.sublime-menu
6+
7+
8+
[
9+
// visible only with JSON syntax highlighting
10+
{
11+
"caption": "JSON: Minify",
12+
"command": "json_minify"
13+
},
14+
{
15+
"caption": "JSON: Prettify",
16+
"command": "json_prettify"
17+
},
18+
19+
20+
// visible only with JSONC syntax highlighting
21+
{
22+
"caption": "JSONC: Minify",
23+
"command": "jsonc_minify"
24+
},
25+
{
26+
"caption": "JSONC: Prettify",
27+
"command": "jsonc_prettify"
28+
}
29+
]

JSON/Default.sublime-commands

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Packages/JSON/Default.sublime-commands
2+
3+
4+
// This file is being maintained at:
5+
// https://github.com/sublimehq/Packages/blob/master/JSON/Default.sublime-commands
6+
7+
8+
[
9+
// visible only with JSON syntax highlighting
10+
{
11+
"caption": "JSON: Minify JSON",
12+
"command": "json_minify"
13+
},
14+
{
15+
"caption": "JSON: Prettify JSON",
16+
"command": "json_prettify"
17+
},
18+
19+
20+
// visible only with JSONC syntax highlighting
21+
{
22+
"caption": "JSONC: Minify JSONC",
23+
"command": "jsonc_minify"
24+
},
25+
{
26+
"caption": "JSONC: Prettify JSONC",
27+
"command": "jsonc_prettify"
28+
}
29+
]

JSON/Default.sublime-keymap

Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,70 @@
1+
// Packages/JSON/Default.sublime-keymap
2+
3+
4+
// This file is being maintained at:
5+
// https://github.com/sublimehq/Packages/blob/master/JSON/Default.sublime-keymap
6+
7+
18
[
2-
// Auto-pair quotations: "key": '|',
3-
{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'$0'"}, "context":
4-
[
5-
{ "key": "setting.auto_match_enabled" },
6-
{ "key": "selector", "operand": "source.json" },
7-
{ "key": "selection_empty", "match_all": true },
8-
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "['\\w]$", "match_all": true },
9-
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
10-
]
11-
},
12-
13-
// Auto-pair quotations: "key": "|",
14-
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"$0\""}, "context":
15-
[
16-
{ "key": "setting.auto_match_enabled" },
17-
{ "key": "selector", "operand": "source.json" },
18-
{ "key": "selection_empty", "match_all": true },
19-
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"\\w]$", "match_all": true },
20-
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
21-
]
22-
},
23-
24-
// Auto-pair braces: "key": {|},
25-
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0}"}, "context":
26-
[
27-
{ "key": "setting.auto_match_enabled" },
28-
{ "key": "selector", "operand": "source.json" },
29-
{ "key": "selection_empty", "match_all": true },
30-
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
31-
]
32-
},
33-
34-
// Auto-pair square brackets: "key": [|],
35-
{ "keys": ["["], "command": "insert_snippet", "args": {"contents": "[$0]"}, "context":
36-
[
37-
{ "key": "setting.auto_match_enabled" },
38-
{ "key": "selector", "operand": "source.json" },
39-
{ "key": "selection_empty", "match_all": true },
40-
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
41-
]
42-
},
43-
44-
// Add indented line in square brackets
45-
{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
46-
[
47-
{ "key": "setting.auto_indent" },
48-
{ "key": "selector", "operand": "source.json" },
49-
{ "key": "selection_empty", "match_all": true },
50-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\[$", "match_all": true },
51-
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
52-
]
53-
},
54-
{ "keys": ["shift+enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
55-
[
56-
{ "key": "setting.auto_indent" },
57-
{ "key": "selector", "operand": "source.json" },
58-
{ "key": "selection_empty", "match_all": true },
59-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\[$", "match_all": true },
60-
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
61-
]
62-
},
63-
]
9+
// Auto-pair quotations: "key": '|',
10+
{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'$0'"}, "context":
11+
[
12+
{ "key": "setting.auto_match_enabled" },
13+
{ "key": "selector", "operand": "source.json" },
14+
{ "key": "selection_empty", "match_all": true },
15+
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "['\\w]$", "match_all": true },
16+
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
17+
]
18+
},
19+
20+
// Auto-pair quotations: "key": "|",
21+
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"$0\""}, "context":
22+
[
23+
{ "key": "setting.auto_match_enabled" },
24+
{ "key": "selector", "operand": "source.json" },
25+
{ "key": "selection_empty", "match_all": true },
26+
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"\\w]$", "match_all": true },
27+
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
28+
]
29+
},
30+
31+
// Auto-pair braces: "key": {|},
32+
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0}"}, "context":
33+
[
34+
{ "key": "setting.auto_match_enabled" },
35+
{ "key": "selector", "operand": "source.json" },
36+
{ "key": "selection_empty", "match_all": true },
37+
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
38+
]
39+
},
40+
41+
// Auto-pair square brackets: "key": [|],
42+
{ "keys": ["["], "command": "insert_snippet", "args": {"contents": "[$0]"}, "context":
43+
[
44+
{ "key": "setting.auto_match_enabled" },
45+
{ "key": "selector", "operand": "source.json" },
46+
{ "key": "selection_empty", "match_all": true },
47+
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |]|,|:|\\}|$)", "match_all": true }
48+
]
49+
},
50+
51+
// Add indented line in square brackets
52+
{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
53+
[
54+
{ "key": "setting.auto_indent" },
55+
{ "key": "selector", "operand": "source.json" },
56+
{ "key": "selection_empty", "match_all": true },
57+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\[$", "match_all": true },
58+
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
59+
]
60+
},
61+
{ "keys": ["shift+enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
62+
[
63+
{ "key": "setting.auto_indent" },
64+
{ "key": "selector", "operand": "source.json" },
65+
{ "key": "selection_empty", "match_all": true },
66+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\[$", "match_all": true },
67+
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
68+
]
69+
},
70+
]

JSON/Fold.tmPreferences

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plist version="1.0">
3+
<dict>
4+
<key>scope</key>
5+
<string>source.json - (source.json.json-dotnet | source.json.json5 | source.json.jsonc)</string>
6+
<key>settings</key>
7+
<dict>
8+
<key>indentationFoldingEnabled</key>
9+
<false/>
10+
<key>foldScopes</key>
11+
<array>
12+
<dict>
13+
<key>begin</key>
14+
<string>punctuation.definition.mapping.begin</string>
15+
<key>end</key>
16+
<string>punctuation.definition.mapping.end</string>
17+
</dict>
18+
<dict>
19+
<key>begin</key>
20+
<string>punctuation.definition.sequence.begin</string>
21+
<key>end</key>
22+
<string>punctuation.definition.sequence.end</string>
23+
</dict>
24+
</array>
25+
</dict>
26+
</dict>
27+
</plist>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<plist version="1.0">
3+
<dict>
4+
<key>scope</key>
5+
<string>source.json.json5</string>
6+
<key>settings</key>
7+
<dict>
8+
<key>foldScopes</key>
9+
<array>
10+
<dict>
11+
<key>begin</key>
12+
<string>punctuation.definition.comment.begin</string>
13+
<key>end</key>
14+
<string>punctuation.definition.comment.end</string>
15+
</dict>
16+
<dict>
17+
<key>begin</key>
18+
<string>punctuation.definition.mapping.begin</string>
19+
<key>end</key>
20+
<string>punctuation.definition.mapping.end</string>
21+
</dict>
22+
<dict>
23+
<key>begin</key>
24+
<string>punctuation.definition.sequence.begin</string>
25+
<key>end</key>
26+
<string>punctuation.definition.sequence.end</string>
27+
</dict>
28+
</array>
29+
</dict>
30+
</dict>
31+
</plist>

0 commit comments

Comments
 (0)