blob: 5b01d33aad7830405ec3084d8ad1a927531c060d [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
52syn region json5LineComment start=+\/\/+ end=+$+ keepend contains=@Spell
53syn region json5LineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend fold contains=@Spell
54syn region json5Comment start="/\*" end="\*/" fold contains=@Spell
55
56" Define the default highlighting
57hi def link json5String String
58hi def link json5Key Identifier
59hi def link json5Escape Special
60hi def link json5Number Number
61hi def link json5Delimiter Delimiter
62hi def link json5Operator Operator
63hi def link json5Braces Delimiter
64hi def link json5Null Keyword
65hi def link json5Boolean Boolean
66hi def link json5LineComment Comment
67hi def link json5Comment Comment
68hi def link json5NumError Error
69
70if !exists('b:current_syntax')
71 let b:current_syntax = 'json5'
72endif
73