codekingpro/portable-devtools
115k
1" Vim syntax file2" Language: JSON3" Maintainer: Vito <vito.blog@gmail.com>4" Previous Maintainer: Eli Parra <eli@elzr.com>5" Last Change: 2019 Sep 176" Version: 0.127 8if !exists("main_syntax")9 " quit when a syntax file was already loaded10 if exists("b:current_syntax")11 finish12 endif13 let main_syntax = 'json'14endif15 16syntax match jsonNoise /\%(:\|,\)/17 18" NOTE that for the concealing to work your conceallevel should be set to 219 20" Syntax: JSON Keywords21" Separated into a match and region because a region by itself is always greedy22syn match jsonKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword23if has('conceal') && (!exists("g:vim_json_conceal") || g:vim_json_conceal==1)24 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ concealends contained25else26 syn region jsonKeyword matchgroup=jsonQuote start=/"/ end=/"\ze[[:blank:]\r\n]*\:/ contained27endif28 29" Syntax: Strings30" Separated into a match and region because a region by itself is always greedy31" Needs to come after keywords or else a json encoded string will break the32" syntax33syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze[[:blank:]\r\n]*[,}\]]/ contains=jsonString34if has('conceal') && (!exists("g:vim_json_conceal") || g:vim_json_conceal==1)35 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ concealends contains=jsonEscape contained36else37 syn region jsonString oneline matchgroup=jsonQuote start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=jsonEscape contained38endif39 40" Syntax: JSON does not allow strings with single quotes, unlike JavaScript.41syn region jsonStringSQError oneline start=+'+ skip=+\\\\\|\\"+ end=+'+42 43 44" Syntax: Escape sequences45syn match jsonEscape "\\["\\/bfnrt]" contained46syn match jsonEscape "\\u\x\{4}" contained47 48" Syntax: Numbers49syn match jsonNumber "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>\ze[[:blank:]\r\n]*[,}\]]"50 51" ERROR WARNINGS **********************************************52if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1)53 " Syntax: Strings should always be enclosed with quotes.54 syn match jsonNoQuotesError "\<[[:alpha:]][[:alnum:]]*\>"55 syn match jsonTripleQuotesError /"""/56 57 " Syntax: An integer part of 0 followed by other digits is not allowed.58 syn match jsonNumError "-\=\<0\d\.\d*\>"59 60 " Syntax: Decimals smaller than one should begin with 0 (so .1 should be 0.1).61 syn match jsonNumError "\:\@<=[[:blank:]\r\n]*\zs\.\d\+"62 63 " Syntax: No comments in JSON, see http://stackoverflow.com/questions/244777/can-i-comment-a-json-file64 syn match jsonCommentError "//.*"65 syn match jsonCommentError "\(/\*\)\|\(\*/\)"66 67 " Syntax: No semicolons in JSON68 syn match jsonSemicolonError ";"69 70 " Syntax: No trailing comma after the last element of arrays or objects71 syn match jsonTrailingCommaError ",\_s*[}\]]"72 73 " Syntax: Watch out for missing commas between elements74 syn match jsonMissingCommaError /\("\|\]\|\d\)\zs\_s\+\ze"/75 syn match jsonMissingCommaError /\(\]\|\}\)\_s\+\ze"/ "arrays/objects as values76 syn match jsonMissingCommaError /}\_s\+\ze{/ "objects as elements in an array77 syn match jsonMissingCommaError /\(true\|false\)\_s\+\ze"/ "true/false as value78endif79 80" ********************************************** END OF ERROR WARNINGS81" Allowances for JSONP: function call at the beginning of the file,82" parenthesis and semicolon at the end.83" Function name validation based on84" http://stackoverflow.com/questions/2008279/validate-a-javascript-function-name/2008444#200844485syn match jsonPadding "\%^[[:blank:]\r\n]*[_$[:alpha:]][_$[:alnum:]]*[[:blank:]\r\n]*("86syn match jsonPadding ");[[:blank:]\r\n]*\%$"87 88" Syntax: Boolean89syn match jsonBoolean /\(true\|false\)\(\_s\+\ze"\)\@!/90 91" Syntax: Null92syn keyword jsonNull null93 94" Syntax: Braces95syn region jsonFold matchgroup=jsonBraces start="{" end=/}\(\_s\+\ze\("\|{\)\)\@!/ transparent fold96syn region jsonFold matchgroup=jsonBraces start="\[" end=/]\(\_s\+\ze"\)\@!/ transparent fold97 98" Define the default highlighting.99" Only when an item doesn't have highlighting yet100hi def link jsonPadding Operator101hi def link jsonString String102hi def link jsonTest Label103hi def link jsonEscape Special104hi def link jsonNumber Number105hi def link jsonBraces Delimiter106hi def link jsonNull Function107hi def link jsonBoolean Boolean108hi def link jsonKeyword Label109 110if (!exists("g:vim_json_warnings") || g:vim_json_warnings==1)111hi def link jsonNumError Error112hi def link jsonCommentError Error113hi def link jsonSemicolonError Error114hi def link jsonTrailingCommaError Error115hi def link jsonMissingCommaError Error116hi def link jsonStringSQError Error117hi def link jsonNoQuotesError Error118hi def link jsonTripleQuotesError Error119endif120hi def link jsonQuote Quote121hi def link jsonNoise Noise122 123let b:current_syntax = "json"124if main_syntax == 'json'125 unlet main_syntax126endif127 128" Vim settings129" vim: ts=8 fdm=marker130 131" MIT License132" Copyright (c) 2013, Jeroen Ruigrok van der Werven, Eli Parra133"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:134"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.135"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.136"See https://twitter.com/elzr/status/294964017926119424137 