annotate runtime/syntax/jsonc.vim @ 29248:6a718a4e17ce

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