blob: dc0d11b2a1e3f047b22c0ea6c057ca0680296902 [file] [log] [blame]
Rolf Vidar Mazunki Hoksaas5a33ce22023-10-17 11:13:06 +02001" Vim syntax file
2" Language: JSON5
3" Maintainer: Mazunki Hoksaas rolferen@gmail.com
4" Previous Maintainer: Guten Ye <ywzhaifei@gmail.com>
5" Last Change: 2019 Apr 1
6" Version: vim9.0-1
7" URL: https://github.com/json5/json5
8
9" Syntax setup
10if exists('b:current_syntax') && b:current_syntax == 'json5'
11 finish
12endif
13
14" Numbers
15syn match json5Number "[-+]\=\%(0\|[1-9]\d*\)\%(\.\d*\)\=\%([eE][-+]\=\d\+\)\="
16syn match json5Number "[-+]\=\%(\.\d\+\)\%([eE][-+]\=\d\+\)\="
17syn match json5Number "[-+]\=0[xX]\x*"
18syn match json5Number "[-+]\=Infinity\|NaN"
19
20" An integer part of 0 followed by other digits is not allowed
21syn match json5NumError "[-+]\=0\d\(\d\|\.\)*"
22
23" A hexadecimal number cannot have a fractional part
24syn match json5NumError "[-+]\=0x\x*\.\x*"
25
26" Strings
27syn region json5String start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=json5Escape,@Spell
28syn region json5String start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=json5Escape,@Spell
29
30" Escape sequences
31syn match json5Escape "\\['\"\\bfnrtv]" contained
32syn match json5Escape "\\u\x\{4}" contained
33
34" Boolean
35syn keyword json5Boolean true false
36
37" Null
38syn keyword json5Null null
39
40" Delimiters and Operators
41syn match json5Delimiter ","
42syn match json5Operator ":"
43
44" Braces
45syn match json5Braces "[{}\[\]]"
46
47" Keys
48syn match json5Key /@\?\%(\I\|\$\)\%(\i\|\$\)*\s*\ze::\@!/ contains=@Spell
49syn match json5Key /"\([^"]\|\\"\)\{-}"\ze\s*:/ contains=json5Escape,@Spell
50
51" Comment
Danek Duvallcc944b12023-12-21 07:44:19 -080052syn region json5LineComment start=+\/\/+ end=+$+ keepend contains=@Spell,json5Todo
53syn region json5LineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend fold contains=@Spell,json5Todo
54syn region json5Comment start="/\*" end="\*/" fold contains=@Spell,json5Todo
55
56syn keyword json5Todo contained TODO FIXME XXX
Rolf Vidar Mazunki Hoksaas5a33ce22023-10-17 11:13:06 +020057
58" Define the default highlighting
59hi def link json5String String
60hi def link json5Key Identifier
61hi def link json5Escape Special
62hi def link json5Number Number
63hi def link json5Delimiter Delimiter
64hi def link json5Operator Operator
65hi def link json5Braces Delimiter
66hi def link json5Null Keyword
67hi def link json5Boolean Boolean
68hi def link json5LineComment Comment
69hi def link json5Comment Comment
70hi def link json5NumError Error
Danek Duvallcc944b12023-12-21 07:44:19 -080071hi def link json5Todo Todo
Rolf Vidar Mazunki Hoksaas5a33ce22023-10-17 11:13:06 +020072
73if !exists('b:current_syntax')
74 let b:current_syntax = 'json5'
75endif
76