robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1" Vim syntax file 2" Language: YAML (YAML Ain't Markup Language) 1.2 3" Maintainer: Nikolai Pavlov <zyx.vim@gmail.com> 4" First author: Nikolai Weibull <now@bitwi.se> 5" Latest Revision: 2024 Apr 01 6" 2026 Aug 28 by Vim project: force BT regexp engine to improve performance #21182 7 8if exists ( 'b:current_syntax' ) 9finish 10endif 11 12let s: cpo_save = & cpo 13set cpo & vim 14 15" Choose the schema to use 16" TODO: Validate schema 17if ! exists ( 'b:yaml_schema' ) 18if exists ( 'g:yaml_schema' ) 19let b: yaml_schema = g: yaml_schema 20else 21let b: yaml_schema = 'core' 22endif 23endif 24 25let s: ns_char = '\%([\n\r\uFEFF \t]\@!\p\)' 26let s: ns_word_char = '[[:alnum:]_\-]' 27let s: ns_uri_char = '\%(%\x\x\|' . s: ns_word_char . '\|[#/;?:@&=+$,.!~*''()[\]]\)' 28let s: ns_tag_char = '\%(%\x\x\|' . s: ns_word_char . '\|[#/;?:@&=+$.~*''()]\)' 29let s: c_indicator = '[\-?:,[\]{}#&*!|>''"%@`]' 30let s: c_flow_indicator = '[,[\]{}]' 31 32let s: ns_anchor_char = substitute ( s: ns_char , '\v\C[\zs' , '\=s:c_flow_indicator[1:-2]' , '' ) 33let s: ns_char_without_c_indicator = substitute ( s: ns_char , '\v\C[\zs' , '\=s:c_indicator[1:-2]' , '' ) 34 35let s: _collection = '[^\@!\(\%(\\\.\|\[^\\\]]\)\+\)]' 36let s: _neg_collection = '[^\(\%(\\\.\|\[^\\\]]\)\+\)]' 37function s: SimplifyToAssumeAllPrintable ( p ) 38return substitute ( a: p , '\V\C\\%(' . s: _collection . '\\@!\\p\\)' , '[^\1]' , '' ) 39endfunction 40let s: ns_char = s: SimplifyToAssumeAllPrintable ( s: ns_char ) 41let s: ns_anchor_char = s: SimplifyToAssumeAllPrintable ( s: ns_anchor_char ) 42let s: ns_char_without_c_indicator = s: SimplifyToAssumeAllPrintable ( s: ns_char_without_c_indicator ) 43 44function s: SimplifyAdjacentCollections ( p ) 45return substitute ( a: p , '\V\C' . s: _collection . '\\|' . s: _collection , '[\1\2]' , 'g' ) 46endfunction 47let s: ns_uri_char = s: SimplifyAdjacentCollections ( s: ns_uri_char ) 48let s: ns_tag_char = s: SimplifyAdjacentCollections ( s: ns_tag_char ) 49 50let s: c_verbatim_tag = '!<' . s: ns_uri_char . '\+>' 51let s: c_named_tag_handle = '!' . s: ns_word_char . '\+!' 52let s: c_secondary_tag_handle = '!!' 53let s: c_primary_tag_handle = '!' 54let s: c_tag_handle = '\%(' . s: c_named_tag_handle . 55 \'\|' . s: c_secondary_tag_handle . 56 \'\|' . s: c_primary_tag_handle . '\)' 57let s: c_ns_shorthand_tag = s: c_tag_handle . s: ns_tag_char . '\+' 58let s: c_non_specific_tag = '!' 59let s: c_ns_tag_property = s: c_verbatim_tag . 60 \'\|' . s: c_ns_shorthand_tag . 61 \'\|' . s: c_non_specific_tag 62 63let s: c_ns_anchor_name = s: ns_anchor_char . '\+' 64let s: c_ns_anchor_property = '&' . s: c_ns_anchor_name 65let s: c_ns_alias_node = '\*' . s: c_ns_anchor_name 66let s: c_ns_properties = '\%(\%(' . s: c_ns_tag_property . '\|' . s: c_ns_anchor_property . '\)\s\+\)\+' 67 68let s: ns_directive_name = s: ns_char . '\+' 69 70let s: ns_local_tag_prefix = '!' . s: ns_uri_char . '*' 71let s: ns_global_tag_prefix = s: ns_tag_char . s: ns_uri_char . '*' 72let s: ns_tag_prefix = s: ns_local_tag_prefix . 73 \'\|' . s: ns_global_tag_prefix 74 75let s: ns_plain_safe_out = s: ns_char 76let s: ns_plain_safe_in = '\%(' . s: c_flow_indicator . '\@!' . s: ns_char . '\)' 77 78let s: ns_plain_safe_in = substitute ( s: ns_plain_safe_in , '\V\C\\%(' . s: _collection . '\\@!' . s: _neg_collection . '\\)' , '[^\1\2]' , '' ) 79let s: ns_plain_safe_in_without_colhash = substitute ( s: ns_plain_safe_in , '\V\C' . s: _neg_collection , '[^\1:#]' , '' ) 80let s: ns_plain_safe_out_without_colhash = substitute ( s: ns_plain_safe_out , '\V\C' . s: _neg_collection , '[^\1:#]' , '' ) 81 82let s: ns_plain_first_in = '\%(' . s: ns_char_without_c_indicator . '\|[?:\-]\%(' . s: ns_plain_safe_in . '\)\@=\)' 83let s: ns_plain_first_out = '\%(' . s: ns_char_without_c_indicator . '\|[?:\-]\%(' . s: ns_plain_safe_out . '\)\@=\)' 84 85let s: ns_plain_char_in = '\%(' . s: ns_char . '#\|:' . s: ns_plain_safe_in . '\|' . s: ns_plain_safe_in_without_colhash . '\)' 86let s: ns_plain_char_out = '\%(' . s: ns_char . '#\|:' . s: ns_plain_safe_out . '\|' . s: ns_plain_safe_out_without_colhash . '\)' 87 88let s: ns_plain_out = s: ns_plain_first_out . s: ns_plain_char_out . '*' 89let s: ns_plain_in = s: ns_plain_first_in . s: ns_plain_char_in . '*' 90 91 92syn keyword yamlTodo contained TODO FIXME XXX NOTE 93 94syn region yamlComment display oneline start = '\%\(^\|\s\)# 'end = '$ ' 95 \contains = yamlTodo 96 97execute 'syn region yamlDirective oneline start=' . string ( '^\ze%' . s: ns_directive_name . '\s\+' ) . ' ' . 98 \'end="$" ' . 99 \'contains=yamlTAGDirective,' . 100 \'yamlYAMLDirective,' . 101 \'yamlReservedDirective ' . 102 \'keepend' 103 104syn match yamlTAGDirective /%TAG\ze\s /contained nextgroup = yamlTagHandle skipwhite 105execute 'syn match yamlTagHandle' string ( s: c_tag_handle ) 'contained nextgroup=yamlTagPrefix skipwhite' 106execute 'syn match yamlTagPrefix' string ( s: ns_tag_prefix ) 'contained nextgroup=yamlComment skipwhite' 107 108syn match yamlYAMLDirective /%YAML\ze\s /contained nextgroup = yamlYAMLVersion skipwhite 109syn match yamlYAMLVersion /\d\+\.\d\+ /contained nextgroup = yamlComment skipwhite 110 111execute 'syn match yamlReservedDirective contained nextgroup=yamlComment ' . 112 \string ( '%\%(\%(TAG\|YAML\)\s\)\@!' . s: ns_directive_name ) 113 114syn region yamlFlowString matchgroup = yamlFlowStringDelimiter start = '" 'skip = '\\" 'end = '" ' 115 \contains = yamlEscape contained nextgroup = yamlFlowMappingDelimiter , yamlComment skipwhite 116syn region yamlFlowString matchgroup = yamlFlowStringDelimiter start = "' "skip = "'' "end = "' " 117 \contains = yamlSingleEscape contained nextgroup = yamlFlowMappingDelimiter , yamlComment skipwhite 118syn match yamlEscape contained '\\\%( [ \\"abefnrtv\^0_ NLP\n ] \|x\x\x\|u\x\{4}\|U\x\{8}\) ' 119syn match yamlSingleEscape contained "'' " 120 121syn cluster yamlConstant contains = yamlBool , yamlNull 122 123syn cluster yamlFlowNode contains = yamlFlowString , yamlFlowMapping , yamlFlowCollection 124syn cluster yamlFlowNode add = yamlFlowMappingKey , yamlFlowMappingKeyStart , yamlFlowMappingMerge 125syn cluster yamlFlowNode add = @yamlConstant , yamlPlainScalar , yamlFloat , yamlComment 126syn cluster yamlFlowNode add = yamlTimestamp , yamlInteger , yamlAlias , yamlFlowNodeProperties 127syn region yamlFlowMapping matchgroup = yamlFlowIndicator start = '{\@<!{{\@! 'end = '} 'contains = @yamlFlowNode 128syn region yamlFlowCollection matchgroup = yamlFlowIndicator start = '\[ 'end = '\] 'contains = @yamlFlowNode 129 130execute 'syn match yamlPlainScalar /' . s: ns_plain_out . '/' 131execute 'syn match yamlPlainScalar contained /' . s: ns_plain_in . '/' 132 133execute 'syn match yamlFlowMappingKey /' . s: ns_plain_in . '\%(\s\+' . s: ns_plain_in . '\)*\ze\s*:\%(\s\|$\)/ contained ' . 134 \'nextgroup=yamlFlowMappingDelimiter skipwhite' 135syn match yamlFlowMappingKeyStart /? /contained nextgroup = @yamlFlowNode skipwhite 136syn match yamlFlowMappingMerge /<<\ze\s * : /contained nextgroup = yamlFlowMappingDelimiter skipwhite 137syn match yamlFlowMappingDelimiter /: /contained nextgroup = @yamlFlowNode skipwhite 138execute 'syn match yamlFlowNodeProperties' string ( s: c_ns_properties ) 139 \'contained contains=yamlNodeTag,yamlAnchor nextgroup=@yamlFlowNode skipwhite' 140 141execute 'syn match yamlBlockMappingKey /^\s*\zs' . s: ns_plain_out . '\%(\s\+' . s: ns_plain_out . '\)*\ze\s*:\%(\s\|$\)/ ' . 142 \'nextgroup=yamlBlockMappingDelimiter skipwhite' 143execute 'syn match yamlBlockMappingKey /' . s: ns_plain_out . '\%(\s\+' . s: ns_plain_out . '\)*\ze\s*:\%(\s\|$\)/ contained ' . 144 \'nextgroup=yamlBlockMappingDelimiter skipwhite' 145syn match yamlBlockMappingKeyString /^\s * \zs\%("\%( [ ^" ] \|\\"\) * "\|'\%( [ ^' ] \|''\) * '\)\ze\s * :\%(\s\|$\) / 146 \contains = yamlFlowString nextgroup = yamlBlockMappingDelimiter skipwhite 147syn match yamlBlockMappingKeyString /\%("\%( [ ^" ] \|\\"\) * "\|'\%( [ ^' ] \|''\) * '\)\ze\s * :\%(\s\|$\) /contained 148 \contains = yamlFlowString nextgroup = yamlBlockMappingDelimiter skipwhite 149syn match yamlBlockMappingMerge /^\s * \zs<<\ze\s * :\%(\s\|$\) /nextgroup = yamlBlockMappingDelimiter skipwhite 150syn match yamlBlockMappingMerge /<<\ze\s * :\%(\s\|$\) /contained nextgroup = yamlBlockMappingDelimiter skipwhite 151 152syn match yamlBlockMappingDelimiter /^\s * \zs:\ze\%(\s\|$\) /nextgroup = @yamlBlockNode skipwhite 153syn match yamlBlockMappingDelimiter /:\ze\%(\s\|$\) /contained nextgroup = @yamlBlockNode skipwhite 154syn match yamlBlockMappingKeyStart /^\s * \zs?\ze\%(\s\|$\) /nextgroup = @yamlBlockNode skipwhite 155syn match yamlBlockMappingKeyStart /?\ze\%(\s\|$\) /contained nextgroup = @yamlBlockNode skipwhite 156 157syn match yamlBlockCollectionItemStart /^\s * \zs-\ze\%(\s\|$\) /nextgroup = @yamlBlockNode skipwhite 158syn match yamlBlockCollectionItemStart /-\ze\%(\s\|$\) /contained nextgroup = @yamlBlockNode skipwhite 159 160execute 'syn match yamlBlockNodeProperties' string ( s: c_ns_properties ) 161 \'contained contains=yamlNodeTag,yamlAnchor nextgroup=@yamlFlowNode,yamlBlockScalarHeader skipwhite' 162syn match yamlBlockScalarHeader '[ |> ] \%( [ 1-9 ][ +- ] \| [ +- ] \? [ 1-9 ] \?\)\%(\s\+#. * \)\?$ 'contained 163 \contains = yamlComment nextgroup = yamlBlockString skipnl 164syn region yamlBlockString start = /^\z(\s\+\) /skip = /^$ /end = /^\%(\z1\)\@! /contained 165 166syn cluster yamlBlockNode contains = @yamlFlowNode , yamlBlockMappingKey , yamlBlockMappingKeyString , 167 \yamlBlockMappingMerge , yamlBlockMappingKeyStart , yamlBlockCollectionItemStart , 168 \yamlBlockNodeProperties , yamlBlockScalarHeader 169 170syn cluster yamlScalarWithSpecials contains = yamlPlainScalar , yamlBlockMappingKey , yamlFlowMappingKey 171 172let s: _bounder = s: SimplifyToAssumeAllPrintable ( '\%([[\]{}, \t]\@!\p\)' ) 173" These scalar patterns begin with a lookbehind, so the regexp engine cannot 174" derive a leading character to search for; the automatic engine then routes 175" them to the NFA engine, which is markedly slower for these short numeric 176" matches tried at every column. The leading "\%#=1" forces Vim's other 177" (backtracking) regexp engine instead, which yields identical matches but is 178" far faster here. See ":help /\%#=". Do NOT copy this to the plain scalar 179" and mapping-key patterns below: backtracking is far slower for those. 180if b: yaml_schema is# 'json' 181syn keyword yamlNull null contained containedin = @yamlScalarWithSpecials 182syn keyword yamlBool true false 183exe 'syn match yamlInteger /\%#=1' . s: _bounder . '\@1<!\%(0\|-\=[1-9][0-9]*\)' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 184exe 'syn match yamlFloat /\%#=1' . s: _bounder . '\@1<!\%(-\=[1-9][0-9]*\%(\.[0-9]*\)\=\(e[-+]\=[0-9]\+\)\=\|0\|-\=\.inf\|\.nan\)' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 185elseif b: yaml_schema is# 'core' 186syn keyword yamlNull null Null NULL contained containedin = @yamlScalarWithSpecials 187syn keyword yamlBool true True TRUE false False FALSE contained containedin = @yamlScalarWithSpecials 188exe 'syn match yamlNull /\%#=1' . s: _bounder . '\@1<!\~' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 189exe 'syn match yamlInteger /\%#=1' . s: _bounder . '\@1<!\%([-+]\=\%(\%(0\%(b[0-1_]\+\|o\?[0-7_]\+\|x[0-9a-fA-F_]\+\)\=\|\%([1-9][0-9_]*\%(:[0-5]\=\d\)\+\)\)\|[1-9][0-9_]*\)\)' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 190exe 'syn match yamlFloat /\%#=1' . s: _bounder . '\@1<!\%([-+]\=\%(\%(\d[0-9_]*\)\.[0-9_]*\%([eE][-+]\=\d\+\)\=\|\.[0-9_]\+\%([eE][-+]\=[0-9]\+\)\=\|\d[0-9_]*\%(:[0-5]\=\d\)\+\.[0-9_]*\|\.\%(inf\|Inf\|INF\)\)\|\%(\.\%(nan\|NaN\|NAN\)\)\)' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 191elseif b: yaml_schema is# 'pyyaml' 192syn keyword yamlNull null Null NULL contained containedin = @yamlScalarWithSpecials 193syn keyword yamlBool true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF contained containedin = @yamlScalarWithSpecials 194exe 'syn match yamlNull /\%#=1' . s: _bounder . '\@1<!\~' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 195exe 'syn match yamlFloat /\%#=1' . s: _bounder . '\@1<!\%(\v[-+]?%(\d[0-9_]*)\.[0-9_]*%([eE][-+]\d+)?|\.[0-9_]+%([eE][-+]\d+)?|[-+]?\d[0-9_]*%(\:[0-5]?\d)+\.[0-9_]*|[-+]?\.%(inf|Inf|INF)|\.%(nan|NaN|NAN)\m\)' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 196exe 'syn match yamlInteger /\%#=1' . s: _bounder . '\@1<!\%(\v[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?%(0|[1-9][0-9_]*)|[-+]?0x[0-9a-fA-F_]+|[-+]?[1-9][0-9_]*%(:[0-5]?\d)+\m\)' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 197exe 'syn match yamlTimestamp /\%#=1' . s: _bounder . '\@1<!\%(\v\d\d\d\d\-\d\d\-\d\d|\d\d\d\d \-\d\d? \-\d\d?%([Tt]|[ \t]+)\d\d?\:\d\d \:\d\d %(\.\d*)?%([ \t]*%(Z|[-+]\d\d?%(\:\d\d)?))?\m\)' . s: _bounder . '\@!/ contained containedin=@yamlScalarWithSpecials' 198elseif b: yaml_schema is# 'failsafe' 199" Nothing 200endif 201unlet s: _bounder 202 203 204execute 'syn match yamlNodeTag ' . string ( s: c_ns_tag_property ) 205execute 'syn match yamlAnchor ' . string ( s: c_ns_anchor_property ) 206execute 'syn match yamlAlias ' . string ( s: c_ns_alias_node ) 207 208syn match yamlDocumentStart '^---\ze\%(\s\|$\) ' 209syn match yamlDocumentEnd '^\.\.\.\ze\%(\s\|$\) ' 210 211hi def link yamlTodo Todo 212hi def link yamlComment Comment 213 214hi def link yamlDocumentStart PreProc 215hi def link yamlDocumentEnd PreProc 216 217hi def link yamlDirectiveName Keyword 218 219hi def link yamlTAGDirective yamlDirectiveName 220hi def link yamlTagHandle String 221hi def link yamlTagPrefix String 222 223hi def link yamlYAMLDirective yamlDirectiveName 224hi def link yamlReservedDirective Error 225hi def link yamlYAMLVersion Number 226 227hi def link yamlString String 228hi def link yamlFlowString yamlString 229hi def link yamlFlowStringDelimiter yamlString 230hi def link yamlEscape SpecialChar 231hi def link yamlSingleEscape SpecialChar 232 233hi def link yamlMappingKey Identifier 234hi def link yamlMappingKeyStart Special 235hi def link yamlMappingMerge Special 236hi def link yamlKeyValueDelimiter Special 237 238hi def link yamlFlowIndicator Special 239hi def link yamlFlowMappingKey yamlMappingKey 240hi def link yamlFlowMappingKeyStart yamlMappingKeyStart 241hi def link yamlFlowMappingMerge yamlMappingMerge 242hi def link yamlFlowMappingDelimiter yamlKeyValueDelimiter 243 244hi def link yamlBlockMappingKey yamlMappingKey 245hi def link yamlBlockMappingKeyStart yamlMappingKeyStart 246hi def link yamlBlockMappingMerge yamlMappingMerge 247hi def link yamlBlockMappingDelimiter yamlKeyValueDelimiter 248hi def link yamlBlockCollectionItemStart Label 249hi def link yamlBlockScalarHeader Special 250" We do not link yamlBlockString to yamlString, because yamlPlainScalar is 251" not highlighted as string neighter, and also due to historical reasons. 252" hi def link yamlBlockString yamlString 253 254hi def link yamlConstant Constant 255 256hi def link yamlNull yamlConstant 257hi def link yamlBool yamlConstant 258 259hi def link yamlAnchor Type 260hi def link yamlAlias Type 261hi def link yamlNodeTag Type 262 263hi def link yamlInteger Number 264hi def link yamlFloat Float 265hi def link yamlTimestamp Number 266 267let b: current_syntax = "yaml" 268 269unlet s: ns_char s: ns_word_char s: ns_uri_char s: ns_tag_char s: c_indicator s: c_flow_indicator 270 \s: ns_anchor_char s: ns_char_without_c_indicator s: _collection s: _neg_collection 271 \s: c_verbatim_tag s: c_named_tag_handle s: c_secondary_tag_handle s: c_primary_tag_handle 272 \s: c_tag_handle s: c_ns_shorthand_tag s: c_non_specific_tag s: c_ns_tag_property 273 \s: c_ns_anchor_name s: c_ns_anchor_property s: c_ns_alias_node s: c_ns_properties 274 \s: ns_directive_name s: ns_local_tag_prefix s: ns_global_tag_prefix s: ns_tag_prefix 275 \s: ns_plain_safe_out s: ns_plain_safe_in s: ns_plain_safe_in_without_colhash s: ns_plain_safe_out_without_colhash 276 \s: ns_plain_first_in s: ns_plain_first_out s: ns_plain_char_in s: ns_plain_char_out s: ns_plain_out s: ns_plain_in 277delfunction s:SimplifyAdjacentCollections 278delfunction s:SimplifyToAssumeAllPrintable 279 280let & cpo = s: cpo_save 281unlet s: cpo_save 282 283" vim: set et sw=4 sts=4 ts=8: