blob: d0df16bbf1afd8e2d80c222acc0ede2cef3319fb [file] [log] [blame]
Bram Moolenaar90df4b92021-07-07 20:26:08 +02001" 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
11if !exists('g:main_syntax')
12 if exists('b:current_syntax') && b:current_syntax ==# 'jsonc'
13 finish
14 endif
15 let g:main_syntax = 'jsonc'
16endif
17
18" Based on vim-json syntax
19runtime! syntax/json.vim
20
21" Remove syntax group for comments treated as errors
22if !exists("g:vim_json_warnings") || g:vim_json_warnings
23 syn clear jsonCommentError
24endif
25
26syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze\(\_s*\/\/.*\_s*\)*[}\]]/ contains=jsonString
27syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze\_s*\/\*\_.*\*\/\_s*[}\]]/ contains=jsonString
28syn match jsonTrailingCommaError /\(,\)\+\ze\(\_s*\/\/.*\_s*\)*[}\]]/
29syn match jsonTrailingCommaError /\(,\)\+\ze\_s*\/\*\_.*\*\/\_s*[}\]]/
30
31" Define syntax matching comments and their contents
32syn keyword jsonCommentTodo FIXME NOTE TBD TODO XXX
33syn region jsonLineComment start=+\/\/+ end=+$+ contains=@Spell,jsonCommentTodo keepend
34syn region jsonComment start='/\*' end='\*/' contains=@Spell,jsonCommentTodo fold
35
36" Link comment syntax comment to highlighting
37hi! def link jsonLineComment Comment
38hi! def link jsonComment Comment
39
40" Set/Unset syntax to avoid duplicate inclusion and correctly handle nesting
41let b:current_syntax = 'jsonc'
42if g:main_syntax ==# 'jsonc'
43 unlet g:main_syntax
44endif