Rolf Vidar Mazunki Hoksaas | 5a33ce2 | 2023-10-17 11:13:06 +0200 | [diff] [blame] | 1 | " 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 |
| 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 |
Danek Duvall | cc944b1 | 2023-12-21 07:44:19 -0800 | [diff] [blame] | 52 | syn region json5LineComment start=+\/\/+ end=+$+ keepend contains=@Spell,json5Todo |
| 53 | syn region json5LineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend fold contains=@Spell,json5Todo |
| 54 | syn region json5Comment start="/\*" end="\*/" fold contains=@Spell,json5Todo |
| 55 | |
| 56 | syn keyword json5Todo contained TODO FIXME XXX |
Rolf Vidar Mazunki Hoksaas | 5a33ce2 | 2023-10-17 11:13:06 +0200 | [diff] [blame] | 57 | |
| 58 | " Define the default highlighting |
| 59 | hi def link json5String String |
| 60 | hi def link json5Key Identifier |
| 61 | hi def link json5Escape Special |
| 62 | hi def link json5Number Number |
| 63 | hi def link json5Delimiter Delimiter |
| 64 | hi def link json5Operator Operator |
| 65 | hi def link json5Braces Delimiter |
| 66 | hi def link json5Null Keyword |
| 67 | hi def link json5Boolean Boolean |
| 68 | hi def link json5LineComment Comment |
| 69 | hi def link json5Comment Comment |
| 70 | hi def link json5NumError Error |
Danek Duvall | cc944b1 | 2023-12-21 07:44:19 -0800 | [diff] [blame] | 71 | hi def link json5Todo Todo |
Rolf Vidar Mazunki Hoksaas | 5a33ce2 | 2023-10-17 11:13:06 +0200 | [diff] [blame] | 72 | |
| 73 | if !exists('b:current_syntax') |
| 74 | let b:current_syntax = 'json5' |
| 75 | endif |
| 76 | |