Mercurial > vim
annotate runtime/syntax/json.vim @ 10048:43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 30 23:26:57 2016 +0200
Updated runtime files. Remove version checks for Vim older than 6.0.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 30 Aug 2016 23:30:09 +0200 |
parents | babc6a1d4c27 |
children | 46763b01cd9a |
rev | line source |
---|---|
6070
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1 " Vim syntax file |
6159 | 2 " Language: JSON |
3 " Maintainer: Eli Parra <eli@elzr.com> | |
4 " Last Change: 2014 Aug 23 | |
5 " Version: 0.12 | |
6 | |
7 if !exists("main_syntax") | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
8 " quit when a syntax file was already loaded |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
9 if exists("b:current_syntax") |
6159 | 10 finish |
11 endif | |
12 let main_syntax = 'json' | |
13 endif | |
14 | |
15 syntax match jsonNoise /\%(:\|,\)/ | |
16 | |
17 " NOTE that for the concealing to work your conceallevel should be set to 2 | |
6070
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
18 |
6159 | 19 " Syntax: Strings |
20 " Separated into a match and region because a region by itself is always greedy | |
21 syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString | |
22 if has('conceal') | |
23 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained | |
24 else | |
25 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained | |
26 endif | |
27 | |
28 " Syntax: JSON does not allow strings with single quotes, unlike JavaScript. | |
29 syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+ | |
30 | |
31 " Syntax: JSON Keywords | |
32 " Separated into a match and region because a region by itself is always greedy | |
33 syn match jsonKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword | |
34 if has('conceal') | |
35 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contained | |
36 else | |
37 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contained | |
6070
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
38 endif |
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
39 |
6159 | 40 " Syntax: Escape sequences |
41 syn match jsonEscape "\\["\\/bfnrt]" contained | |
42 syn match jsonEscape "\\u\x\{4}" contained | |
43 | |
44 " Syntax: Numbers | |
45 syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]" | |
46 | |
47 " ERROR WARNINGS ********************************************** | |
48 if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) | |
49 " Syntax: Strings should always be enclosed with quotes. | |
50 syn match jsonNoQuotesError "\<[[:alpha:]][[:alnum:]]*\>" | |
51 syn match jsonTripleQuotesError /"""/ | |
52 | |
53 " Syntax: An integer part of 0 followed by other digits is not allowed. | |
54 syn match jsonNumError "-\=\<0\d\.\d*\>" | |
55 | |
56 " Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1). | |
57 syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+" | |
58 | |
59 " Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file | |
60 syn match jsonCommentError "//.*" | |
61 syn match jsonCommentError "\(/\*\)\|\(\*/\)" | |
62 | |
63 " Syntax: No semicolons in JSON | |
64 syn match jsonSemicolonError ";" | |
65 | |
66 " Syntax: No trailing comma after the last element of arrays or objects | |
67 syn match jsonTrailingCommaError ",\_s*[}\]]" | |
68 | |
69 " Syntax: Watch out for missing commas between elements | |
70 syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/ | |
71 syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values | |
72 syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array | |
73 syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value | |
74 endif | |
75 | |
76 " ********************************************** END OF ERROR WARNINGS | |
77 " Allowances for JSONP: function call at the beginning of the file, | |
78 " parenthesis and semicolon at the end. | |
79 " Function name validation based on | |
80 " http://stackoverflow.com/questions/2008279/validate-a-javascript-function-name/2008444#2008444 | |
81 syn match jsonPadding "\%^[[:blank:]\r\n]*[_$[:alpha:]][_$[:alnum:]]*[[:blank:]\r\n]*(" | |
82 syn match jsonPadding ");[[:blank:]\r\n]*\%$" | |
83 | |
84 " Syntax: Boolean | |
85 syn match jsonBoolean /\(true\|false\)\(\_s\+\ze"\)\@!/ | |
86 | |
87 " Syntax: Null | |
88 syn keyword jsonNull null | |
6070
32a77cc160d9
Update runtime files. Make matchparen plugin backwards compatible.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
89 |
6159 | 90 " Syntax: Braces |
91 syn region jsonFold matchgroup=jsonBraces start="{" end=/}\(\_s\+\ze\("\|{\)\)\@!/ transparent fold | |
92 syn region jsonFold matchgroup=jsonBraces start="\[" end=/]\(\_s\+\ze"\)\@!/ transparent fold | |
93 | |
94 " Define the default highlighting. | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
95 " Only when an item doesn't have highlighting yet |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
96 command -nargs=+ HiLink hi def link <args> |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
97 HiLink jsonPadding Operator |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
98 HiLink jsonString String |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
99 HiLink jsonTest Label |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
100 HiLink jsonEscape Special |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
101 HiLink jsonNumber Number |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
102 HiLink jsonBraces Delimiter |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
103 HiLink jsonNull Function |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
104 HiLink jsonBoolean Boolean |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
105 HiLink jsonKeyword Label |
6159 | 106 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
107 if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
108 HiLink jsonNumError Error |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
109 HiLink jsonCommentError Error |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
110 HiLink jsonSemicolonError Error |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
111 HiLink jsonTrailingCommaError Error |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
112 HiLink jsonMissingCommaError Error |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
113 HiLink jsonStringSQError Error |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
114 HiLink jsonNoQuotesError Error |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
115 HiLink jsonTripleQuotesError Error |
6159 | 116 endif |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
117 HiLink jsonQuote Quote |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
118 HiLink jsonNoise Noise |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
6159
diff
changeset
|
119 delcommand HiLink |
6159 | 120 |
121 let b:current_syntax = "json" | |
122 if main_syntax == 'json' | |
123 unlet main_syntax | |
124 endif | |
125 | |
126 " Vim settings | |
127 " vim: ts=8 fdm=marker | |
128 | |
129 " MIT License | |
130 " Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra | |
131 "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: | |
132 "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
133 "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. | |
134 "See https://twitter.com/elzr/status/294964017926119424 |