Mercurial > ec-dotfiles
annotate vendor/vim-syntax/json.vim @ 536:d4e874f04bc6
Set tab space to 4. Just because.
author | edogawaconan <me@myconan.net> |
---|---|
date | Mon, 05 Jan 2015 21:33:35 +0900 |
parents | a198065ff6e8 |
children | 351bd965bc1f |
rev | line source |
---|---|
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 | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
16 syntax match jsonNoise /\%(:\|,\)/ |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
17 |
467 | 18 " NOTE that for the concealing to work your conceallevel should be set to 2 |
19 | |
20 " Syntax: Strings | |
517 | 21 " Separated into a match and region because a region by itself is always greedy |
22 syn match jsonStringMatch /"[^\"]\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString | |
467 | 23 if has('conceal') |
517 | 24 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained |
467 | 25 else |
517 | 26 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained |
467 | 27 endif |
28 | |
29 " Syntax: JSON does not allow strings with single quotes, unlike JavaScript. | |
517 | 30 syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+ |
467 | 31 |
32 " Syntax: JSON Keywords | |
33 " Separated into a match and region because a region by itself is always greedy | |
517 | 34 syn match jsonKeywordMatch /"[^\"]\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword |
467 | 35 if has('conceal') |
517 | 36 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contained |
467 | 37 else |
517 | 38 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contained |
467 | 39 endif |
40 | |
41 " Syntax: Escape sequences | |
42 syn match jsonEscape "\\["\\/bfnrt]" contained | |
43 syn match jsonEscape "\\u\x\{4}" contained | |
44 | |
45 " Syntax: Numbers | |
517 | 46 syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]" |
467 | 47 |
48 " ERROR WARNINGS ********************************************** | |
519
a198065ff6e8
Even more update on json syntax.
edogawaconan <me@myconan.net>
parents:
517
diff
changeset
|
49 if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) |
517 | 50 " Syntax: Strings should always be enclosed with quotes. |
51 syn match jsonNoQuotesError "\<[[:alpha:]]\+\>" | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
52 |
517 | 53 " Syntax: An integer part of 0 followed by other digits is not allowed. |
54 syn match jsonNumError "-\=\<0\d\.\d*\>" | |
467 | 55 |
517 | 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\+" | |
467 | 58 |
517 | 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 ";" | |
467 | 65 |
517 | 66 " Syntax: No trailing comma after the last element of arrays or objects |
67 syn match jsonTrailingCommaError ",\_s*[}\]]" | |
467 | 68 |
517 | 69 " Syntax: Watch out for missing commas between elements |
70 syn match jsonMissingCommaError /\("\|\d\)\zs\_s\+\ze"/ | |
71 endif | |
467 | 72 |
73 " ********************************************** END OF ERROR WARNINGS | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
74 " Allowances for JSONP: function call at the beginning of the file, |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
75 " parenthesis and semicolon at the end. |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
76 " Function name validation based on |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
77 " http://stackoverflow.com/questions/2008279/validate-a-javascript-function-name/2008444#2008444 |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
78 syn match jsonPadding "\%^[[:blank:]\r\n]*[_$[:alpha:]][_$[:alnum:]]*[[:blank:]\r\n]*(" |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
79 syn match jsonPadding ");[[:blank:]\r\n]*\%$" |
467 | 80 |
81 " Syntax: Boolean | |
517 | 82 syn keyword jsonBooleanTrue true |
83 syn keyword jsonBooleanFalse false | |
467 | 84 |
85 " Syntax: Null | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
86 syn keyword jsonNull null |
467 | 87 |
88 " Syntax: Braces | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
89 syn region jsonFold matchgroup=jsonBraces start="{" end="}" transparent fold |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
90 syn region jsonFold matchgroup=jsonBraces start="\[" end="]" transparent fold |
467 | 91 |
92 " Define the default highlighting. | |
93 " For version 5.7 and earlier: only when not done already | |
94 " For version 5.8 and later: only when an item doesn't have highlighting yet | |
95 if version >= 508 || !exists("did_json_syn_inits") | |
96 if version < 508 | |
97 let did_json_syn_inits = 1 | |
98 command -nargs=+ HiLink hi link <args> | |
99 else | |
100 command -nargs=+ HiLink hi def link <args> | |
101 endif | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
102 HiLink jsonPadding Operator |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
103 HiLink jsonString String |
517 | 104 HiLink jsonTest Label |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
105 HiLink jsonEscape Special |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
106 HiLink jsonNumber Number |
517 | 107 HiLink jsonBraces Delimiter |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
108 HiLink jsonNull Function |
517 | 109 HiLink jsonBooleanTrue jsonBoolean |
110 HiLink jsonBooleanFalse jsonBoolean | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
111 HiLink jsonBoolean Boolean |
517 | 112 HiLink jsonKeyword Label |
467 | 113 |
519
a198065ff6e8
Even more update on json syntax.
edogawaconan <me@myconan.net>
parents:
517
diff
changeset
|
114 if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) |
517 | 115 HiLink jsonNumError Error |
116 HiLink jsonCommentError Error | |
117 HiLink jsonSemicolonError Error | |
118 HiLink jsonTrailingCommaError Error | |
119 HiLink jsonMissingCommaError Error | |
120 HiLink jsonStringSQError Error | |
121 HiLink jsonNoQuotesError Error | |
122 endif | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
123 HiLink jsonQuote Quote |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
124 HiLink jsonNoise Noise |
467 | 125 delcommand HiLink |
126 endif | |
127 | |
128 let b:current_syntax = "json" | |
129 if main_syntax == 'json' | |
130 unlet main_syntax | |
131 endif | |
132 | |
133 " Vim settings | |
134 " vim: ts=8 fdm=marker | |
135 | |
136 " MIT License | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
137 " Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra |
467 | 138 "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: |
139 "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
140 "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. | |
141 "See https://twitter.com/elzr/status/294964017926119424 |