25161
|
1 " Vim syntax file
|
|
2 " Language: JSONC (JSON with Comments)
|
|
3 " Original Author: Izhak Jakov <izhak724@gmail.com>
|
|
4 " Acknowledgement: Based off of vim-jsonc maintained by Kevin Locke <kevin@kevinlocke.name>
|
|
5 " https://github.com/kevinoid/vim-jsonc
|
|
6 " License: MIT
|
|
7 " Last Change: 2021-07-01
|
|
8
|
|
9 " Ensure syntax is loaded once, unless nested inside another (main) syntax
|
|
10 " For description of main_syntax, see https://stackoverflow.com/q/16164549
|
|
11 if !exists('g:main_syntax')
|
|
12 if exists('b:current_syntax') && b:current_syntax ==# 'jsonc'
|
|
13 finish
|
|
14 endif
|
|
15 let g:main_syntax = 'jsonc'
|
|
16 endif
|
|
17
|
|
18 " Based on vim-json syntax
|
|
19 runtime! syntax/json.vim
|
|
20
|
|
21 " Remove syntax group for comments treated as errors
|
|
22 if !exists("g:vim_json_warnings") || g:vim_json_warnings
|
|
23 syn clear jsonCommentError
|
|
24 endif
|
|
25
|
|
26 syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze\(\_s*\/\/.*\_s*\)*[}\]]/ contains=jsonString
|
|
27 syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze\_s*\/\*\_.*\*\/\_s*[}\]]/ contains=jsonString
|
|
28 syn match jsonTrailingCommaError /\(,\)\+\ze\(\_s*\/\/.*\_s*\)*[}\]]/
|
|
29 syn match jsonTrailingCommaError /\(,\)\+\ze\_s*\/\*\_.*\*\/\_s*[}\]]/
|
|
30
|
|
31 " Define syntax matching comments and their contents
|
|
32 syn keyword jsonCommentTodo FIXME NOTE TBD TODO XXX
|
|
33 syn region jsonLineComment start=+\/\/+ end=+$+ contains=@Spell,jsonCommentTodo keepend
|
|
34 syn region jsonComment start='/\*' end='\*/' contains=@Spell,jsonCommentTodo fold
|
|
35
|
|
36 " Link comment syntax comment to highlighting
|
|
37 hi! def link jsonLineComment Comment
|
|
38 hi! def link jsonComment Comment
|
|
39
|
|
40 " Set/Unset syntax to avoid duplicate inclusion and correctly handle nesting
|
|
41 let b:current_syntax = 'jsonc'
|
|
42 if g:main_syntax ==# 'jsonc'
|
|
43 unlet g:main_syntax
|
|
44 endif
|