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

[JSON] strings can't span multiple lines, fix comment block detection #816

Merged
merged 3 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions JavaScript/JSON.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contexts:
- match: '[^\s\]]'
scope: invalid.illegal.expected-array-separator.json
comments:
- match: /\*\*
- match: /\*\*(?!/)
scope: punctuation.definition.comment.json
push:
- meta_scope: comment.block.documentation.json
Expand Down Expand Up @@ -83,7 +83,11 @@ contexts:
- match: '\}'
scope: punctuation.definition.dictionary.end.json
pop: true
- include: string
- match: '"'
scope: punctuation.definition.string.begin.json
push:
- meta_scope: meta.structure.dictionary.key.json string.quoted.double.json
- include: inside-string
- include: comments
- match: ":"
scope: punctuation.separator.dictionary.key-value.json
Expand All @@ -101,24 +105,30 @@ contexts:
string:
- match: '"'
scope: punctuation.definition.string.begin.json
push:
- meta_scope: string.quoted.double.json
- match: '"'
scope: punctuation.definition.string.end.json
pop: true
- match: |-
(?x: # turn on extended mode
\\ # a literal backslash
(?: # ...followed by...
["\\/bfnrt] # one of these characters
| # ...or...
u # a u
[0-9a-fA-F]{4} # and four hex digits
)
)
scope: constant.character.escape.json
- match: \\.
scope: invalid.illegal.unrecognized-string-escape.json
push: inside-string
inside-string:
- meta_scope: string.quoted.double.json
- match: '"'
scope: punctuation.definition.string.end.json
pop: true
- include: string-escape
- match: $\n?
scope: invalid.illegal.unclosed-string.json
pop: true
string-escape:
- match: |-
(?x: # turn on extended mode
\\ # a literal backslash
(?: # ...followed by...
["\\/bfnrt] # one of these characters
| # ...or...
u # a u
[0-9a-fA-F]{4} # and four hex digits
)
)
scope: constant.character.escape.json
- match: \\.
scope: invalid.illegal.unrecognized-string-escape.json
value:
- include: constant
- include: number
Expand Down
21 changes: 21 additions & 0 deletions JavaScript/syntax_test_json.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,34 @@

"E": 20e10,
// ^^^^^ constant.numeric.json
//^^^ meta.structure.dictionary.key.json string.quoted.double.json
// ^ punctuation.separator.dictionary.key-value.json - meta.structure.dictionary.key.json

"escape": "\n",
// ^^ constant.character.escape.json
// ^^^^ meta.structure.dictionary.value.json string.quoted.double.json - meta.structure.dictionary.key.json

"illegal": "\.",
// ^^ invalid.illegal.unrecognized-string-escape.json

"unterminated string
//^^^^^^^^^^^^^^^^^^^^ string.quoted.double.json
// ^ string.quoted.double.json invalid.illegal.unclosed-string.json

// <- - string

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

"array2":
[
"foobar",
// ^^^^^^^^ meta.structure.array.json string.quoted.double.json - meta.structure.dictionary.key.json
],

[]
//^^ invalid.illegal.expected-dictionary-separator.json

}