Skip to content

Commit

Permalink
[JSON] Fix comment punctuation scopes (#3870)
Browse files Browse the repository at this point in the history
This commit ...

1. fixes missing closing `punctuation.definition` scopes
2. renames a `.js` final scope to `.json`
3. adjusts leading asterisk scoping according to #3855 and #3856.
4. refactors comment related contexts to use only named contexts.
  • Loading branch information
deathaxe authored Nov 17, 2023
1 parent 40d269d commit 636539f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 25 deletions.
61 changes: 43 additions & 18 deletions JSON/JSON.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,53 @@ contexts:
scope: invalid.illegal.expected-sequence-separator.json

comments:
- match: /\*\*(?!/)
scope: punctuation.definition.comment.json
push:
- meta_scope: comment.block.documentation.json
- meta_include_prototype: false
- match: \*/
pop: 1
- match: ^\s*(\*)(?!/)
captures:
1: punctuation.definition.comment.json
- include: block-comments
- include: line-comments

block-comments:
# empty block comments
- match: /\*\*+/
scope: comment.block.empty.json punctuation.definition.comment.json
# documentation block comments
- match: /\*\*+
scope: punctuation.definition.comment.begin.json
push: block-comment-documentation-body
# normal block comments
- match: /\*
scope: punctuation.definition.comment.json
push:
- meta_scope: comment.block.json
- meta_include_prototype: false
- match: \*/
pop: 1
- match: (//).*$\n?
scope: comment.line.double-slash.js
scope: punctuation.definition.comment.begin.json
push: block-comment-body

block-comment-documentation-body:
- meta_include_prototype: false
- meta_scope: comment.block.documentation.json
- match: \*+/
scope: punctuation.definition.comment.end.json
pop: 1
- match: ^\s*(\*)(?![*/])
captures:
1: punctuation.definition.comment.json

block-comment-body:
- meta_include_prototype: false
- meta_scope: comment.block.json
- match: \*/
scope: punctuation.definition.comment.end.json
pop: 1
- match: ^\s*(\*)(?![*/])
captures:
1: punctuation.definition.comment.json

line-comments:
- match: //
scope: punctuation.definition.comment.json
push: line-comment-body

line-comment-body:
- meta_include_prototype: false
- meta_scope: comment.line.double-slash.json
- match: $\n?
pop: 1

constant:
- match: \b(?:false|true)\b
scope: constant.language.boolean.json
Expand Down
39 changes: 32 additions & 7 deletions JSON/syntax_test_json.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
// SYNTAX TEST "Packages/JSON/JSON.sublime-syntax"

/* comment */
// ^^^^^^^^^^^^^ comment.block.json
// ^^ punctuation.definition.comment.begin.json
// ^^ punctuation.definition.comment.end.json

/**
*
// ^ comment.block.documentation.json punctuation.definition.comment.json
*/
// <- comment.block.documentation.json
//^^ comment.block.documentation.json punctuation.definition.comment.end.json

/**/
// <- comment.block.empty.json punctuation.definition.comment.json
//^^ comment.block.empty.json punctuation.definition.comment.json

/********/
// <- comment.block.empty.json punctuation.definition.comment.json
//^^^^^^^^ comment.block.empty.json punctuation.definition.comment.json

/**************
// <- comment.block.documentation.json punctuation.definition.comment.begin.json
//^^^^^^^^^^^^^ comment.block.documentation.json punctuation.definition.comment.begin.json
**************/
// <- comment.block.documentation.json punctuation.definition.comment.end.json
//^^^^^^^^^^^^^ comment.block.documentation.json punctuation.definition.comment.end.json

{
// <- meta.mapping.json punctuation.section.mapping.begin.json
"bool": false,
Expand Down Expand Up @@ -32,7 +59,7 @@
"array": [ /**/ ],
// ^^^^^^^^ meta.mapping.value.json meta.sequence.json
// ^ punctuation.section.sequence.begin.json
// ^^^^ comment.block.json
// ^^^^ comment.block.empty.json punctuation.definition.comment.json
// ^ punctuation.section.sequence.end.json

"dict": {"foo": },
Expand All @@ -52,13 +79,15 @@
"foo": "bar"
// comment
// ^ - invalid
// ^^^^^^^^^^ comment.line.double-slash.js
// ^^^^^^^^^^ comment.line.double-slash.json
,
// ^ punctuation.separator.sequence.json
"foo": "bar"
/* comment */
// ^ - invalid
// ^^^^^^^^^^^^^ comment.block.json
// ^^ punctuation.definition.comment.begin.json
// ^^ punctuation.definition.comment.end.json
},
//^ punctuation.section.mapping.end.json
// ^ punctuation.separator.sequence.json
Expand Down Expand Up @@ -96,7 +125,7 @@
// <- - string

/**/: "test",
// ^ meta.mapping.json comment.block.json
// ^ meta.mapping.json comment.block.empty.json
// ^ punctuation.separator.key-value.json - comment
// ^^^^^^ meta.mapping.value.json string.quoted.double.json

Expand All @@ -116,8 +145,4 @@
"ke//y": "value"
//^^^^^^^ meta.mapping.key.json string.quoted.double.json - comment

/**
*
// ^ meta.mapping.json comment.block.documentation.json punctuation.definition.comment.json
*/
}

0 comments on commit 636539f

Please sign in to comment.