summaryrefslogtreecommitdiffstats
path: root/syntax/jsonc.vim
blob: 059cd332419e1ebc987641cedcec86121cfca20b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
if polyglot#init#is_disabled(expand('<sfile>:p'), 'jsonc', 'syntax/jsonc.vim')
  finish
endif

" Syntax setup {{{1
if exists('b:current_syntax') && b:current_syntax == 'jsonc'
  finish
endif

" Syntax: Strings {{{1
syn region  jsoncString    start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=jsoncEscape
syn region  jsoncString    start=+'+  skip=+\\\\\|\\'+  end=+'+  contains=jsoncEscape

" Syntax: JSON Keywords {{{1
" Separated into a match and region because a region by itself is always greedy
syn match  jsoncKeywordMatch /"\([^"]\|\\\"\)\+"[[:blank:]\r\n]*\:/ contains=jsonKeyword

" Syntax: Escape sequences
syn match   jsoncEscape    "\\["\\/bfnrt]" contained
syn match   jsoncEscape    "\\u\x\{4}" contained

" Syntax: Numbers {{{1
syn match   jsoncNumber    "-\=\<\%(0\|[1-9]\d*\)\%(\.\d\+\)\=\%([eE][-+]\=\d\+\)\=\>"
syn keyword jsoncNumber    Infinity -Infinity

" Syntax: An integer part of 0 followed by other digits is not allowed.
syn match   jsoncNumError  "-\=\<0\d\.\d*\>"

" Syntax: Boolean {{{1
syn keyword jsoncBoolean   true false

" Syntax: Null {{{1
syn keyword jsoncNull      null

" Syntax: Braces {{{1
syn match   jsoncBraces	   "[{}\[\]]"
syn match   jsoncObjAssign /@\?\%(\I\|\$\)\%(\i\|\$\)*\s*\ze::\@!/

" Syntax: Comment {{{1
syn region  jsoncLineComment    start=+\/\/+ end=+$+ keepend
syn region  jsoncLineComment    start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend fold
syn region  jsoncComment        start="/\*"  end="\*/" fold

" Define the default highlighting. {{{1
hi def link jsoncString             String
hi def link jsoncObjAssign          Identifier
hi def link jsoncEscape             Special
hi def link jsoncNumber             Number
hi def link jsoncBraces             Operator
hi def link jsoncNull               Function
hi def link jsoncBoolean            Boolean
hi def link jsoncLineComment        Comment
hi def link jsoncComment            Comment
hi def link jsoncNumError           Error
hi def link jsoncKeywordMatch       Label

if !exists('b:current_syntax')
  let b:current_syntax = 'jsonc'
endif

" vim: fdm=marker