annotate vendor/vim-syntax/json.vim @ 508:bbcffc594d1e

Vendor what should be vendored and add some more.
author edogawaconan <me@myconan.net>
date Mon, 17 Mar 2014 15:47:15 +0900
parents rc/vim-syntax-json@8ef5ddb9b54b
children 14b645f67f7c
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
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
3 " Maintainer: Eli Parra <eli@elzr.com>
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
4 " Last Change: 2013-02-01
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
5 " Version: 0.12
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
6
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
7 if !exists("main_syntax")
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
8 if version < 600
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
9 syntax clear
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
10 elseif exists("b:current_syntax")
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
11 finish
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
12 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
13 let main_syntax = 'json'
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
14 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
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
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
18 " 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
19
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
20 " Syntax: Strings
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
21 if has('conceal')
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
22 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
23 else
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
24 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
25 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
26
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
27 " Syntax: JSON does not allow strings with single quotes, unlike JavaScript.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
28 syn region jsonStringSQ oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
29
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
30 " Syntax: JSON Keywords
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
31 " Separated into a match and region because a region by itself is always greedy
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
32 syn match jsonKeywordMatch /"[^\"\:]\+"[[:blank:]\r\n]*\:/ contains=jsonKeywordRegion
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
33 if has('conceal')
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
34 syn region jsonKeywordRegion matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contained
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
35 else
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
36 syn region jsonKeywordRegion matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contained
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
37 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
38
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
39 " Syntax: Escape sequences
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
40 syn match jsonEscape "\\["\\/bfnrt]" contained
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
41 syn match jsonEscape "\\u\x\{4}" contained
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
42
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
43 " Syntax: Numbers
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
44 syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
45
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
46 " ERROR WARNINGS **********************************************
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
47 "
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
48 " Syntax: Strings should always be enclosed with quotes.
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
49 syn match jsonNoQuotes "\<[[:alpha:]]\+\>"
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
50
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
51 " Syntax: An integer part of 0 followed by other digits is not allowed.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
52 syn match jsonNumError "-\=\<0\d\.\d*\>"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
53
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
54 " Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1).
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
55 syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+"
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
56
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
57 " Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
58 syn match jsonCommentError "//.*"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
59 syn match jsonCommentError "\(/\*\)\|\(\*/\)"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
60
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
61 " Syntax: No semicolons in JSON
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
62 syn match jsonSemicolonError ";"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
63
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
64 " Syntax: No trailing comma after the last element of arrays or objects
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
65 syn match jsonCommaError ",\_s*[}\]]"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
66
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
67 " ********************************************** END OF ERROR WARNINGS
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
68 " 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
69 " parenthesis and semicolon at the end.
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
70 " Function name validation based on
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
71 " 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
72 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
73 syn match jsonPadding ");[[:blank:]\r\n]*\%$"
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
74
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
75 " Syntax: Boolean
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
76 syn keyword jsonBoolean true false
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
77
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
78 " Syntax: Null
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
79 syn keyword jsonNull null
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
80
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
81 " Syntax: Braces
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
82 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
83 syn region jsonFold matchgroup=jsonBraces start="\[" end="]" transparent fold
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
84
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
85 " Define the default highlighting.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
86 " For version 5.7 and earlier: only when not done already
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
87 " For version 5.8 and later: only when an item doesn't have highlighting yet
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
88 if version >= 508 || !exists("did_json_syn_inits")
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
89 if version < 508
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
90 let did_json_syn_inits = 1
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
91 command -nargs=+ HiLink hi link <args>
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
92 else
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
93 command -nargs=+ HiLink hi def link <args>
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
94 endif
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
95 HiLink jsonPadding Operator
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
96 HiLink jsonString String
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
97 HiLink jsonEscape Special
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
98 HiLink jsonNumber Number
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
99 HiLink jsonBraces Operator
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
100 HiLink jsonNull Function
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
101 HiLink jsonBoolean Boolean
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
102 HiLink jsonKeywordRegion Label
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
103
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
104 HiLink jsonNumError Error
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
105 HiLink jsonCommentError Error
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
106 HiLink jsonSemicolonError Error
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
107 HiLink jsonCommaError Error
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
108 HiLink jsonStringSQ Error
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
109 HiLink jsonNoQuotes Error
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
110 HiLink jsonQuote Quote
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
111 HiLink jsonNoise Noise
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
112 delcommand HiLink
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
113 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
114
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
115 let b:current_syntax = "json"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
116 if main_syntax == 'json'
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
117 unlet main_syntax
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
118 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
119
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
120 " Vim settings
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
121 " vim: ts=8 fdm=marker
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
122
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
123 " MIT License
508
bbcffc594d1e Vendor what should be vendored and add some more.
edogawaconan <me@myconan.net>
parents: 467
diff changeset
124 " Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra
467
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
125 "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
126 "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
127 "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
128 "See https://twitter.com/elzr/status/294964017926119424