Skip to content

Commit

Permalink
Merge pull request #816 from forkeith/json
Browse files Browse the repository at this point in the history
[JSON] strings can't span multiple lines, fix comment block detection
  • Loading branch information
wbond committed Mar 21, 2017
2 parents 13a9160 + 5e24e2b commit 2aa0e27
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
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

}

0 comments on commit 2aa0e27

Please sign in to comment.