annotate vendor/vim-syntax/json.vim @ 586:ecff9d2c0500

Simple random string generator
author nanaya <me@myconan.net>
date Mon, 16 May 2016 18:21:24 +0900
parents 6f57f959cc0b
children 7fbadf8bd22e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
1 " Vim syntax file
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
2 " Language: JSON
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
3 " Maintainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
4 " Last Change: 2014-12-20 Load ftplugin/json.vim
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
5
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
6 " Reload the definition of g:vim_json_syntax_conceal
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
7 " see https://github.com/elzr/vim-json/issues/42
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
8 runtime! ftplugin/json.vim
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
9
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
10 if !exists("main_syntax")
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
11 if version < 600
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
12 syntax clear
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
13 elseif exists("b:current_syntax")
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
14 finish
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
15 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
16 let main_syntax = 'json'
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
17 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
18
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
19 syntax match jsonNoise /\%(:\|,\)/
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
20
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
21 " NOTE that for the concealing to work your conceallevel should be set to 2
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
22
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
23 " Syntax: Strings
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
24 " Separated into a match and region because a region by itself is always greedy
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
25 syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
26 if has('conceal') && g:vim_json_syntax_conceal == 1
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
27 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
28 else
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
29 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
30 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
31
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
32 " Syntax: JSON does not allow strings with single quotes, unlike JavaScript.
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
33 syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
34
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
35 " Syntax: JSON Keywords
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
36 " Separated into a match and region because a region by itself is always greedy
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
37 syn match jsonKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
38 if has('conceal') && g:vim_json_syntax_conceal == 1
562
6f57f959cc0b Update vim syntaxes.
nanaya <me@myconan.net>
parents: 537
diff changeset
39 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contains=jsonEscape contained
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
40 else
562
6f57f959cc0b Update vim syntaxes.
nanaya <me@myconan.net>
parents: 537
diff changeset
41 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contains=jsonEscape contained
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
42 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
43
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
44 " Syntax: Escape sequences
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
45 syn match jsonEscape "\\["\\/bfnrt]" contained
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
46 syn match jsonEscape "\\u\x\{4}" contained
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
47
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
48 " Syntax: Numbers
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
49 syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]"
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
50
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
51 " ERROR WARNINGS **********************************************
519
a198065ff6e8 Even more update on json syntax.
edogawaconan <me@myconan.net>
parents: 517
diff changeset
52 if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1)
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
53 " Syntax: Strings should always be enclosed with quotes.
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
54 syn match jsonNoQuotesError "\<[[:alpha:]][[:alnum:]]*\>"
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
55 syn match jsonTripleQuotesError /"""/
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
56
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
57 " Syntax: An integer part of 0 followed by other digits is not allowed.
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
58 syn match jsonNumError "-\=\<0\d\.\d*\>"
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
59
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
60 " Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1).
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
61 syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+"
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
62
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
63 " Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
64 syn match jsonCommentError "//.*"
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
65 syn match jsonCommentError "\(/\*\)\|\(\*/\)"
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
66
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
67 " Syntax: No semicolons in JSON
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
68 syn match jsonSemicolonError ";"
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
69
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
70 " Syntax: No trailing comma after the last element of arrays or objects
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
71 syn match jsonTrailingCommaError ",\_s*[}\]]"
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
72
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
73 " Syntax: Watch out for missing commas between elements
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
74 syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
75 syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
76 syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
77 syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
78 endif
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
79
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
80 " ********************************************** END OF ERROR WARNINGS
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
81 " 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
82 " parenthesis and semicolon at the end.
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
83 " Function name validation based on
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
84 " 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
85 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
86 syn match jsonPadding ");[[:blank:]\r\n]*\%$"
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
87
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
88 " Syntax: Boolean
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
89 syn match jsonBoolean /\(true\|false\)\(\_s\+\ze"\)\@!/
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
90
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
91 " Syntax: Null
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
92 syn keyword jsonNull null
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
93
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
94 " Syntax: Braces
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
95 syn region jsonFold matchgroup=jsonBraces start="{" end=/}\(\_s\+\ze\("\|{\)\)\@!/ transparent fold
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
96 syn region jsonFold matchgroup=jsonBraces start="\[" end=/]\(\_s\+\ze"\)\@!/ transparent fold
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
97
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
98 " Define the default highlighting.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
99 if version >= 508 || !exists("did_json_syn_inits")
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
100 hi def link jsonPadding Operator
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
101 hi def link jsonString String
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
102 hi def link jsonTest Label
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
103 hi def link jsonEscape Special
562
6f57f959cc0b Update vim syntaxes.
nanaya <me@myconan.net>
parents: 537
diff changeset
104 hi def link jsonNumber Delimiter
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
105 hi def link jsonBraces Delimiter
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
106 hi def link jsonNull Function
562
6f57f959cc0b Update vim syntaxes.
nanaya <me@myconan.net>
parents: 537
diff changeset
107 hi def link jsonBoolean Delimiter
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
108 hi def link jsonKeyword Label
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
109
519
a198065ff6e8 Even more update on json syntax.
edogawaconan <me@myconan.net>
parents: 517
diff changeset
110 if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1)
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
111 hi def link jsonNumError Error
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
112 hi def link jsonCommentError Error
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
113 hi def link jsonSemicolonError Error
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
114 hi def link jsonTrailingCommaError Error
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
115 hi def link jsonMissingCommaError Error
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
116 hi def link jsonStringSQError Error
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
117 hi def link jsonNoQuotesError Error
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
118 hi def link jsonTripleQuotesError Error
517
14b645f67f7c Update vim-syntax.
edogawaconan <me@myconan.net>
parents: 508
diff changeset
119 endif
537
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
120 hi def link jsonQuote Quote
351bd965bc1f Update some syntax files.
edogawaconan <me@myconan.net>
parents: 519
diff changeset
121 hi def link jsonNoise Noise
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
122 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
123
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
124 let b:current_syntax = "json"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
125 if main_syntax == 'json'
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
126 unlet main_syntax
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
127 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
128
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
129 " Vim settings
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
130 " vim: ts=8 fdm=marker
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
131
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
132 " MIT License
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
133 " Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
134 "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:
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
135 "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
136 "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.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
137 "See https://twitter.com/elzr/status/294964017926119424