Mercurial > ec-dotfiles
annotate vendor/vim-syntax/json.vim @ 614:70355e17653e
Use zlib which is more available
author | nanaya <me@nanaya.pro> |
---|---|
date | Mon, 02 Apr 2018 17:45:56 +0900 |
parents | 0e72765944d4 |
children | 035b23bb15da |
rev | line source |
---|---|
467 | 1 " Vim syntax file |
2 " Language: JSON | |
589 | 3 " Maintainer: Eli Parra <eli@elzr.com> |
4 " Last Change: 2014 Aug 23 | |
5 " Version: 0.12 | |
467 | 6 |
7 if !exists("main_syntax") | |
595 | 8 " quit when a syntax file was already loaded |
9 if exists("b:current_syntax") | |
467 | 10 finish |
11 endif | |
12 let main_syntax = 'json' | |
13 endif | |
14 | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
15 syntax match jsonNoise /\%(:\|,\)/ |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
16 |
467 | 17 " NOTE that for the concealing to work your conceallevel should be set to 2 |
18 | |
19 " Syntax: Strings | |
517 | 20 " Separated into a match and region because a region by itself is always greedy |
537 | 21 syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString |
589 | 22 if has('conceal') |
517 | 23 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained |
467 | 24 else |
517 | 25 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained |
467 | 26 endif |
27 | |
28 " Syntax: JSON does not allow strings with single quotes, unlike JavaScript. | |
517 | 29 syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+ |
467 | 30 |
31 " Syntax: JSON Keywords | |
32 " Separated into a match and region because a region by itself is always greedy | |
537 | 33 syn match jsonKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword |
589 | 34 if has('conceal') |
35 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contained | |
467 | 36 else |
589 | 37 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contained |
467 | 38 endif |
39 | |
40 " Syntax: Escape sequences | |
41 syn match jsonEscape "\\["\\/bfnrt]" contained | |
42 syn match jsonEscape "\\u\x\{4}" contained | |
43 | |
44 " Syntax: Numbers | |
517 | 45 syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]" |
467 | 46 |
47 " ERROR WARNINGS ********************************************** | |
519
a198065ff6e8
Even more update on json syntax.
edogawaconan <me@myconan.net>
parents:
517
diff
changeset
|
48 if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) |
517 | 49 " Syntax: Strings should always be enclosed with quotes. |
537 | 50 syn match jsonNoQuotesError "\<[[:alpha:]][[:alnum:]]*\>" |
51 syn match jsonTripleQuotesError /"""/ | |
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 |
537 | 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 | |
517 | 74 endif |
467 | 75 |
76 " ********************************************** END OF ERROR WARNINGS | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
77 " 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
|
78 " parenthesis and semicolon at the end. |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
79 " Function name validation based on |
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
80 " 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
|
81 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
|
82 syn match jsonPadding ");[[:blank:]\r\n]*\%$" |
467 | 83 |
84 " Syntax: Boolean | |
537 | 85 syn match jsonBoolean /\(true\|false\)\(\_s\+\ze"\)\@!/ |
467 | 86 |
87 " Syntax: Null | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
88 syn keyword jsonNull null |
467 | 89 |
90 " Syntax: Braces | |
537 | 91 syn region jsonFold matchgroup=jsonBraces start="{" end=/}\(\_s\+\ze\("\|{\)\)\@!/ transparent fold |
92 syn region jsonFold matchgroup=jsonBraces start="\[" end=/]\(\_s\+\ze"\)\@!/ transparent fold | |
467 | 93 |
94 " Define the default highlighting. | |
595 | 95 " Only when an item doesn't have highlighting yet |
96 hi def link jsonPadding Operator | |
97 hi def link jsonString String | |
98 hi def link jsonTest Label | |
99 hi def link jsonEscape Special | |
100 hi def link jsonNumber Number | |
101 hi def link jsonBraces Delimiter | |
102 hi def link jsonNull Function | |
103 hi def link jsonBoolean Boolean | |
104 hi def link jsonKeyword Label | |
467 | 105 |
595 | 106 if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1) |
107 hi def link jsonNumError Error | |
108 hi def link jsonCommentError Error | |
109 hi def link jsonSemicolonError Error | |
110 hi def link jsonTrailingCommaError Error | |
111 hi def link jsonMissingCommaError Error | |
112 hi def link jsonStringSQError Error | |
113 hi def link jsonNoQuotesError Error | |
114 hi def link jsonTripleQuotesError Error | |
467 | 115 endif |
595 | 116 hi def link jsonQuote Quote |
117 hi def link jsonNoise Noise | |
467 | 118 |
119 let b:current_syntax = "json" | |
120 if main_syntax == 'json' | |
121 unlet main_syntax | |
122 endif | |
123 | |
124 " Vim settings | |
125 " vim: ts=8 fdm=marker | |
126 | |
127 " MIT License | |
508
bbcffc594d1e
Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents:
467
diff
changeset
|
128 " Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra |
467 | 129 "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: |
130 "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
131 "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. | |
132 "See https://twitter.com/elzr/status/294964017926119424 |