467
|
1 " Vim syntax file
|
|
2 " Language: JSON
|
|
3 " Maintainer: Eli Parra <eli@elzr.com>
|
|
4 " Last Change: 2013-02-01
|
|
5 " Version: 0.12
|
|
6
|
|
7 if !exists("main_syntax")
|
|
8 if version < 600
|
|
9 syntax clear
|
|
10 elseif exists("b:current_syntax")
|
|
11 finish
|
|
12 endif
|
|
13 let main_syntax = 'json'
|
|
14 endif
|
|
15
|
|
16 " NOTE that for the concealing to work your conceallevel should be set to 2
|
|
17
|
|
18 " Syntax: Strings
|
|
19 if has('conceal')
|
|
20 syn region jsonString oneline matchgroup=Quote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape
|
|
21 else
|
|
22 syn region jsonString oneline matchgroup=Quote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape
|
|
23 endif
|
|
24
|
|
25 " Syntax: JSON does not allow strings with single quotes, unlike JavaScript.
|
|
26 syn region jsonStringSQ oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
|
|
27
|
|
28 " Syntax: JSON Keywords
|
|
29 " Separated into a match and region because a region by itself is always greedy
|
|
30 syn match jsonKeywordMatch /"[^\"\:]\+"\:/ contains=jsonKeywordRegion
|
|
31 if has('conceal')
|
|
32 syn region jsonKeywordRegion matchgroup=Quote start=/"/ end=/"\ze\:/ concealends contained
|
|
33 else
|
|
34 syn region jsonKeywordRegion matchgroup=Quote start=/"/ end=/"\ze\:/ contained
|
|
35 endif
|
|
36
|
|
37 " Syntax: Escape sequences
|
|
38 syn match jsonEscape "\\["\\/bfnrt]" contained
|
|
39 syn match jsonEscape "\\u\x\{4}" contained
|
|
40
|
|
41 " Syntax: Strings should always be enclosed with quotes.
|
|
42 syn match jsonNoQuotes "\<\w\+\>"
|
|
43
|
|
44 " Syntax: Numbers
|
|
45 syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
|
|
46
|
|
47 " ERROR WARNINGS **********************************************
|
|
48 "
|
|
49 " Syntax: An integer part of 0 followed by other digits is not allowed.
|
|
50 syn match jsonNumError "-\=\<0\d\.\d*\>"
|
|
51
|
|
52 " Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1).
|
|
53 syn match jsonNumError "\:\@<=\s*\zs\.\d\+"
|
|
54
|
|
55 " Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file
|
|
56 syn match jsonCommentError "//.*"
|
|
57 syn match jsonCommentError "\(/\*\)\|\(\*/\)"
|
|
58
|
|
59 " Syntax: No semicolons in JSON
|
|
60 syn match jsonSemicolonError ";"
|
|
61
|
|
62 " Syntax: No trailing comma after the last element of arrays or objects
|
|
63 syn match jsonCommaError ",\_s*[}\]]"
|
|
64
|
|
65 " ********************************************** END OF ERROR WARNINGS
|
|
66
|
|
67 " Syntax: Boolean
|
|
68 syn keyword jsonBoolean true false
|
|
69
|
|
70 " Syntax: Null
|
|
71 syn keyword jsonNull null
|
|
72
|
|
73 " Syntax: Braces
|
|
74 syn region jsonFold matchgroup=jsonBraces start="{" end="}" transparent fold
|
|
75 syn region jsonFold matchgroup=jsonBraces start="\[" end="]" transparent fold
|
|
76
|
|
77 " Define the default highlighting.
|
|
78 " For version 5.7 and earlier: only when not done already
|
|
79 " For version 5.8 and later: only when an item doesn't have highlighting yet
|
|
80 if version >= 508 || !exists("did_json_syn_inits")
|
|
81 if version < 508
|
|
82 let did_json_syn_inits = 1
|
|
83 command -nargs=+ HiLink hi link <args>
|
|
84 else
|
|
85 command -nargs=+ HiLink hi def link <args>
|
|
86 endif
|
|
87 HiLink jsonString String
|
|
88 HiLink jsonEscape Special
|
|
89 HiLink jsonNumber Number
|
|
90 HiLink jsonBraces Operator
|
|
91 HiLink jsonNull Function
|
|
92 HiLink jsonBoolean Boolean
|
|
93 HiLink jsonKeywordRegion Label
|
|
94
|
|
95 HiLink jsonNumError Error
|
|
96 HiLink jsonCommentError Error
|
|
97 HiLink jsonSemicolonError Error
|
|
98 HiLink jsonCommaError Error
|
|
99 HiLink jsonStringSQ Error
|
|
100 HiLink jsonNoQuotes Error
|
|
101 delcommand HiLink
|
|
102 endif
|
|
103
|
|
104 let b:current_syntax = "json"
|
|
105 if main_syntax == 'json'
|
|
106 unlet main_syntax
|
|
107 endif
|
|
108
|
|
109 " Vim settings
|
|
110 " vim: ts=8 fdm=marker
|
|
111
|
|
112 " MIT License
|
|
113 " Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra
|
|
114 "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
115 "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
116 "THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
117 "See https://twitter.com/elzr/status/294964017926119424
|