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