annotate rc/vim-syntax-json @ 467:8ef5ddb9b54b

Support for json
author Edho Arief <edho@myconan.net>
date Fri, 24 May 2013 18:47:59 +0900
parents
children
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
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
16 " 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
17
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
18 " Syntax: Strings
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
19 if has('conceal')
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
20 syn region jsonString oneline matchgroup=Quote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
21 else
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
22 syn region jsonString oneline matchgroup=Quote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
23 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
24
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
25 " Syntax: JSON does not allow strings with single quotes, unlike JavaScript.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
26 syn region jsonStringSQ oneline start=+'+ skip=+\\\\\|\\"+ end=+'+
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
27
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
28 " Syntax: JSON Keywords
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
29 " Separated into a match and region because a region by itself is always greedy
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
30 syn match jsonKeywordMatch /"[^\"\:]\+"\:/ contains=jsonKeywordRegion
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
31 if has('conceal')
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
32 syn region jsonKeywordRegion matchgroup=Quote start=/"/ end=/"\ze\:/ concealends contained
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
33 else
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
34 syn region jsonKeywordRegion matchgroup=Quote start=/"/ end=/"\ze\:/ contained
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
35 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
36
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
37 " Syntax: Escape sequences
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
38 syn match jsonEscape "\\["\\/bfnrt]" contained
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
39 syn match jsonEscape "\\u\x\{4}" contained
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
40
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
41 " Syntax: Strings should always be enclosed with quotes.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
42 syn match jsonNoQuotes "\<\w\+\>"
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: Numbers
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
45 syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
46
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
47 " ERROR WARNINGS **********************************************
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
48 "
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
49 " 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
50 syn match jsonNumError "-\=\<0\d\.\d*\>"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
51
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
52 " Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1).
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
53 syn match jsonNumError "\:\@<=\s*\zs\.\d\+"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
54
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
55 " Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
56 syn match jsonCommentError "//.*"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
57 syn match jsonCommentError "\(/\*\)\|\(\*/\)"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
58
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
59 " Syntax: No semicolons in JSON
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
60 syn match jsonSemicolonError ";"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
61
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
62 " Syntax: No trailing comma after the last element of arrays or objects
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
63 syn match jsonCommaError ",\_s*[}\]]"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
64
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
65 " ********************************************** END OF ERROR WARNINGS
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 " Syntax: Boolean
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
68 syn keyword jsonBoolean true false
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
69
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
70 " Syntax: Null
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
71 syn keyword jsonNull null
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
72
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
73 " Syntax: Braces
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
74 syn region jsonFold matchgroup=jsonBraces start="{" end="}" transparent fold
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
75 syn region jsonFold matchgroup=jsonBraces start="\[" end="]" transparent fold
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
76
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
77 " Define the default highlighting.
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
78 " For version 5.7 and earlier: only when not done already
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
79 " 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
80 if version >= 508 || !exists("did_json_syn_inits")
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
81 if version < 508
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
82 let did_json_syn_inits = 1
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
83 command -nargs=+ HiLink hi link <args>
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
84 else
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
85 command -nargs=+ HiLink hi def link <args>
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
86 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
87 HiLink jsonString String
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
88 HiLink jsonEscape Special
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
89 HiLink jsonNumber Number
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
90 HiLink jsonBraces Operator
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
91 HiLink jsonNull Function
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
92 HiLink jsonBoolean Boolean
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
93 HiLink jsonKeywordRegion Label
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
94
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
95 HiLink jsonNumError Error
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
96 HiLink jsonCommentError Error
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
97 HiLink jsonSemicolonError Error
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
98 HiLink jsonCommaError Error
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
99 HiLink jsonStringSQ Error
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
100 HiLink jsonNoQuotes Error
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
101 delcommand HiLink
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
102 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
103
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
104 let b:current_syntax = "json"
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
105 if main_syntax == 'json'
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
106 unlet main_syntax
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
107 endif
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
108
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
109 " Vim settings
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
110 " vim: ts=8 fdm=marker
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
111
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
112 " MIT License
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
113 " Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra
8ef5ddb9b54b Support for json
Edho Arief <edho@myconan.net>
parents:
diff changeset
114 "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
115 "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
116 "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
117 "See https://twitter.com/elzr/status/294964017926119424