7
|
1 " Vim syntax file
|
2581
|
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>
|
6741
|
5 " Latest Revision: 2015-03-28
|
7
|
6
|
2581
|
7 if exists('b:current_syntax')
|
|
8 finish
|
7
|
9 endif
|
|
10
|
375
|
11 let s:cpo_save = &cpo
|
|
12 set cpo&vim
|
7
|
13
|
6741
|
14 " Choose the schema to use
|
|
15 " TODO: Validate schema
|
|
16 if !exists('b:yaml_schema')
|
|
17 if exists('g:yaml_schema')
|
|
18 let b:yaml_schema = g:yaml_schema
|
|
19 else
|
|
20 let b:yaml_schema = 'core'
|
|
21 endif
|
|
22 endif
|
|
23
|
|
24 let s:ns_char = '\%([\n\r\uFEFF \t]\@!\p\)'
|
|
25 let s:ns_word_char = '[[:alnum:]_\-]'
|
|
26 let s:ns_uri_char = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$,.!~*''()[\]]\)'
|
2581
|
27 let s:ns_tag_char = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$.~*''()]\)'
|
6741
|
28 let s:c_ns_anchor_char = '\%([\n\r\uFEFF \t,[\]{}]\@!\p\)'
|
|
29 let s:c_indicator = '[\-?:,[\]{}#&*!|>''"%@`]'
|
|
30 let s:c_flow_indicator = '[,[\]{}]'
|
|
31
|
|
32 let s:ns_char_without_c_indicator = substitute(s:ns_char, '\v\C[\zs', '\=s:c_indicator[1:-2]', '')
|
|
33
|
|
34 let s:_collection = '[^\@!\(\%(\\\.\|\[^\\\]]\)\+\)]'
|
|
35 let s:_neg_collection = '[^\(\%(\\\.\|\[^\\\]]\)\+\)]'
|
|
36 function s:SimplifyToAssumeAllPrintable(p)
|
|
37 return substitute(a:p, '\V\C\\%('.s:_collection.'\\@!\\p\\)', '[^\1]', '')
|
|
38 endfunction
|
|
39 let s:ns_char = s:SimplifyToAssumeAllPrintable(s:ns_char)
|
|
40 let s:ns_char_without_c_indicator = s:SimplifyToAssumeAllPrintable(s:ns_char_without_c_indicator)
|
|
41 let s:c_ns_anchor_char = s:SimplifyToAssumeAllPrintable(s:c_ns_anchor_char)
|
|
42
|
|
43 function s:SimplifyAdjacentCollections(p)
|
|
44 return substitute(a:p, '\V\C'.s:_collection.'\\|'.s:_collection, '[\1\2]', 'g')
|
|
45 endfunction
|
|
46 let s:ns_uri_char = s:SimplifyAdjacentCollections(s:ns_uri_char)
|
|
47 let s:ns_tag_char = s:SimplifyAdjacentCollections(s:ns_tag_char)
|
2581
|
48
|
|
49 let s:c_verbatim_tag = '!<'.s:ns_uri_char.'\+>'
|
|
50 let s:c_named_tag_handle = '!'.s:ns_word_char.'\+!'
|
|
51 let s:c_secondary_tag_handle = '!!'
|
|
52 let s:c_primary_tag_handle = '!'
|
|
53 let s:c_tag_handle = '\%('.s:c_named_tag_handle.
|
|
54 \ '\|'.s:c_secondary_tag_handle.
|
|
55 \ '\|'.s:c_primary_tag_handle.'\)'
|
|
56 let s:c_ns_shorthand_tag = s:c_tag_handle . s:ns_tag_char.'\+'
|
|
57 let s:c_non_specific_tag = '!'
|
|
58 let s:c_ns_tag_property = s:c_verbatim_tag.
|
|
59 \ '\|'.s:c_ns_shorthand_tag.
|
|
60 \ '\|'.s:c_non_specific_tag
|
|
61
|
|
62 let s:c_ns_anchor_name = s:c_ns_anchor_char.'\+'
|
|
63 let s:c_ns_anchor_property = '&'.s:c_ns_anchor_name
|
|
64 let s:c_ns_alias_node = '\*'.s:c_ns_anchor_name
|
|
65
|
|
66 let s:ns_directive_name = s:ns_char.'\+'
|
|
67
|
|
68 let s:ns_local_tag_prefix = '!'.s:ns_uri_char.'*'
|
|
69 let s:ns_global_tag_prefix = s:ns_tag_char.s:ns_uri_char.'*'
|
|
70 let s:ns_tag_prefix = s:ns_local_tag_prefix.
|
|
71 \ '\|'.s:ns_global_tag_prefix
|
|
72
|
|
73 let s:ns_plain_safe_out = s:ns_char
|
|
74 let s:ns_plain_safe_in = '\%('.s:c_flow_indicator.'\@!'.s:ns_char.'\)'
|
|
75
|
6741
|
76 let s:ns_plain_safe_in = substitute(s:ns_plain_safe_in, '\V\C\\%('.s:_collection.'\\@!'.s:_neg_collection.'\\)', '[^\1\2]', '')
|
|
77 let s:ns_plain_safe_in_without_colhash = substitute(s:ns_plain_safe_in, '\V\C'.s:_neg_collection, '[^\1:#]', '')
|
|
78 let s:ns_plain_safe_out_without_colhash = substitute(s:ns_plain_safe_out, '\V\C'.s:_neg_collection, '[^\1:#]', '')
|
2581
|
79
|
6741
|
80 let s:ns_plain_first_in = '\%('.s:ns_char_without_c_indicator.'\|[?:\-]\%('.s:ns_plain_safe_in.'\)\@=\)'
|
|
81 let s:ns_plain_first_out = '\%('.s:ns_char_without_c_indicator.'\|[?:\-]\%('.s:ns_plain_safe_out.'\)\@=\)'
|
|
82
|
|
83 let s:ns_plain_char_in = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_in.'\|'.s:ns_plain_safe_in_without_colhash.'\)'
|
|
84 let s:ns_plain_char_out = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_out.'\|'.s:ns_plain_safe_out_without_colhash.'\)'
|
2581
|
85
|
|
86 let s:ns_plain_out = s:ns_plain_first_out . s:ns_plain_char_out.'*'
|
|
87 let s:ns_plain_in = s:ns_plain_first_in . s:ns_plain_char_in.'*'
|
|
88
|
|
89
|
1698
|
90 syn keyword yamlTodo contained TODO FIXME XXX NOTE
|
7
|
91
|
2581
|
92 syn region yamlComment display oneline start='\%\(^\|\s\)#' end='$'
|
|
93 \ contains=yamlTodo
|
7
|
94
|
2581
|
95 execute 'syn region yamlDirective oneline start='.string('^\ze%'.s:ns_directive_name.'\s\+').' '.
|
|
96 \ 'end="$" '.
|
|
97 \ 'contains=yamlTAGDirective,'.
|
|
98 \ 'yamlYAMLDirective,'.
|
|
99 \ 'yamlReservedDirective '.
|
|
100 \ 'keepend'
|
1698
|
101
|
2581
|
102 syn match yamlTAGDirective '%TAG\s\+' contained nextgroup=yamlTagHandle
|
|
103 execute 'syn match yamlTagHandle contained nextgroup=yamlTagPrefix '.string(s:c_tag_handle.'\s\+')
|
|
104 execute 'syn match yamlTagPrefix contained nextgroup=yamlComment ' . string(s:ns_tag_prefix)
|
7
|
105
|
2581
|
106 syn match yamlYAMLDirective '%YAML\s\+' contained nextgroup=yamlYAMLVersion
|
|
107 syn match yamlYAMLVersion '\d\+\.\d\+' contained nextgroup=yamlComment
|
|
108
|
|
109 execute 'syn match yamlReservedDirective contained nextgroup=yamlComment '.
|
|
110 \string('%\%(\%(TAG\|YAML\)\s\)\@!'.s:ns_directive_name)
|
7
|
111
|
2581
|
112 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"'
|
|
113 \ contains=yamlEscape
|
|
114 \ nextgroup=yamlKeyValueDelimiter
|
|
115 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'"
|
|
116 \ contains=yamlSingleEscape
|
|
117 \ nextgroup=yamlKeyValueDelimiter
|
|
118 syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)'
|
|
119 syn match yamlSingleEscape contained "''"
|
|
120
|
|
121 syn match yamlBlockScalarHeader contained '\s\+\zs[|>]\%([+-]\=[1-9]\|[1-9]\=[+-]\)\='
|
|
122
|
6741
|
123 syn cluster yamlConstant contains=yamlBool,yamlNull
|
|
124
|
2581
|
125 syn cluster yamlFlow contains=yamlFlowString,yamlFlowMapping,yamlFlowCollection
|
|
126 syn cluster yamlFlow add=yamlFlowMappingKey,yamlFlowMappingMerge
|
6741
|
127 syn cluster yamlFlow add=@yamlConstant,yamlPlainScalar,yamlFloat
|
2581
|
128 syn cluster yamlFlow add=yamlTimestamp,yamlInteger,yamlMappingKeyStart
|
|
129 syn cluster yamlFlow add=yamlComment
|
|
130 syn region yamlFlowMapping matchgroup=yamlFlowIndicator start='{' end='}' contains=@yamlFlow
|
|
131 syn region yamlFlowCollection matchgroup=yamlFlowIndicator start='\[' end='\]' contains=@yamlFlow
|
|
132
|
|
133 execute 'syn match yamlPlainScalar /'.s:ns_plain_out.'/'
|
|
134 execute 'syn match yamlPlainScalar contained /'.s:ns_plain_in.'/'
|
|
135
|
|
136 syn match yamlMappingKeyStart '?\ze\s'
|
|
137 syn match yamlMappingKeyStart '?' contained
|
|
138
|
6741
|
139 execute 'syn match yamlFlowMappingKey /\%#=1'.s:ns_plain_in.'\%(\s\+'.s:ns_plain_in.'\)*\ze\s*:/ contained '.
|
2581
|
140 \'nextgroup=yamlKeyValueDelimiter'
|
|
141 syn match yamlFlowMappingMerge /<<\ze\s*:/ contained nextgroup=yamlKeyValueDelimiter
|
|
142
|
|
143 syn match yamlBlockCollectionItemStart '^\s*\zs-\%(\s\+-\)*\s' nextgroup=yamlBlockMappingKey,yamlBlockMappingMerge
|
5340
|
144 " Use the old regexp engine, the NFA engine doesn't like all the \@ items.
|
6741
|
145 execute 'syn match yamlBlockMappingKey /\%#=1^\s*\zs'.s:ns_plain_out.'\%(\s\+'.s:ns_plain_out.'\)*\ze\s*:\%(\s\|$\)/ '.
|
2581
|
146 \'nextgroup=yamlKeyValueDelimiter'
|
6741
|
147 execute 'syn match yamlBlockMappingKey /\%#=1\s*\zs'.s:ns_plain_out.'\%(\s\+'.s:ns_plain_out.'\)*\ze\s*:\%(\s\|$\)/ contained '.
|
2581
|
148 \'nextgroup=yamlKeyValueDelimiter'
|
|
149 syn match yamlBlockMappingMerge /^\s*\zs<<\ze:\%(\s\|$\)/ nextgroup=yamlKeyValueDelimiter
|
|
150 syn match yamlBlockMappingMerge /<<\ze\s*:\%(\s\|$\)/ nextgroup=yamlKeyValueDelimiter contained
|
7
|
151
|
2581
|
152 syn match yamlKeyValueDelimiter /\s*:/ contained
|
|
153 syn match yamlKeyValueDelimiter /\s*:/ contained
|
|
154
|
6741
|
155 syn cluster yamlScalarWithSpecials contains=yamlPlainScalar,yamlBlockMappingKey,yamlFlowMappingKey
|
2581
|
156
|
6741
|
157 let s:_bounder = s:SimplifyToAssumeAllPrintable('\%([[\]{}, \t]\@!\p\)')
|
|
158 if b:yaml_schema is# 'json'
|
|
159 syn keyword yamlNull null contained containedin=@yamlScalarWithSpecials
|
|
160 syn keyword yamlBool true false
|
|
161 exe 'syn match yamlInteger /'.s:_bounder.'\@1<!\%(0\|-\=[1-9][0-9]*\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials'
|
|
162 exe 'syn match yamlFloat /'.s:_bounder.'\@1<!\%(-\=[1-9][0-9]*\%(\.[0-9]*\)\=\(e[-+]\=[0-9]\+\)\=\|0\|-\=\.inf\|\.nan\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials'
|
|
163 elseif b:yaml_schema is# 'core'
|
|
164 syn keyword yamlNull null Null NULL contained containedin=@yamlScalarWithSpecials
|
|
165 syn keyword yamlBool true True TRUE false False FALSE contained containedin=@yamlScalarWithSpecials
|
|
166 exe 'syn match yamlNull /'.s:_bounder.'\@1<!\~'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials'
|
|
167 exe 'syn match yamlInteger /'.s:_bounder.'\@1<!\%([+-]\=\%(0\%(b[0-1_]\+\|[0-7_]\+\|x[0-9a-fA-F_]\+\)\=\|\%([1-9][0-9_]*\%(:[0-5]\=\d\)\+\)\)\|[1-9][0-9_]*\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials'
|
|
168 exe 'syn match yamlFloat /'.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'
|
|
169 elseif b:yaml_schema is# 'pyyaml'
|
|
170 syn keyword yamlNull null Null NULL contained containedin=@yamlScalarWithSpecials
|
|
171 syn keyword yamlBool true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF contained containedin=@yamlScalarWithSpecials
|
|
172 exe 'syn match yamlNull /'.s:_bounder.'\@1<!\~'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials'
|
|
173 exe 'syn match yamlFloat /'.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'
|
|
174 exe 'syn match yamlInteger /'.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'
|
|
175 exe 'syn match yamlTimestamp /'.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'
|
|
176 elseif b:yaml_schema is# 'failsafe'
|
|
177 " Nothing
|
|
178 endif
|
|
179 unlet s:_bounder
|
2581
|
180
|
7
|
181
|
2581
|
182 execute 'syn match yamlNodeTag '.string(s:c_ns_tag_property)
|
|
183 execute 'syn match yamlAnchor '.string(s:c_ns_anchor_property)
|
|
184 execute 'syn match yamlAlias '.string(s:c_ns_alias_node)
|
|
185
|
|
186 syn match yamlDocumentStart '^---\ze\%(\s\|$\)'
|
|
187 syn match yamlDocumentEnd '^\.\.\.\ze\%(\s\|$\)'
|
7
|
188
|
2581
|
189 hi def link yamlTodo Todo
|
|
190 hi def link yamlComment Comment
|
|
191
|
|
192 hi def link yamlDocumentStart PreProc
|
|
193 hi def link yamlDocumentEnd PreProc
|
7
|
194
|
2581
|
195 hi def link yamlDirectiveName Keyword
|
7
|
196
|
2581
|
197 hi def link yamlTAGDirective yamlDirectiveName
|
|
198 hi def link yamlTagHandle String
|
|
199 hi def link yamlTagPrefix String
|
7
|
200
|
2581
|
201 hi def link yamlYAMLDirective yamlDirectiveName
|
|
202 hi def link yamlReservedDirective Error
|
|
203 hi def link yamlYAMLVersion Number
|
|
204
|
|
205 hi def link yamlString String
|
|
206 hi def link yamlFlowString yamlString
|
|
207 hi def link yamlFlowStringDelimiter yamlString
|
|
208 hi def link yamlEscape SpecialChar
|
|
209 hi def link yamlSingleEscape SpecialChar
|
|
210
|
|
211 hi def link yamlBlockCollectionItemStart Label
|
|
212 hi def link yamlBlockMappingKey Identifier
|
|
213 hi def link yamlBlockMappingMerge Special
|
|
214
|
|
215 hi def link yamlFlowMappingKey Identifier
|
|
216 hi def link yamlFlowMappingMerge Special
|
|
217
|
|
218 hi def link yamlMappingKeyStart Special
|
|
219 hi def link yamlFlowIndicator Special
|
|
220 hi def link yamlKeyValueDelimiter Special
|
|
221
|
|
222 hi def link yamlConstant Constant
|
|
223
|
6741
|
224 hi def link yamlNull yamlConstant
|
|
225 hi def link yamlBool yamlConstant
|
|
226
|
2581
|
227 hi def link yamlAnchor Type
|
|
228 hi def link yamlAlias Type
|
|
229 hi def link yamlNodeTag Type
|
|
230
|
|
231 hi def link yamlInteger Number
|
|
232 hi def link yamlFloat Float
|
|
233 hi def link yamlTimestamp Number
|
7
|
234
|
|
235 let b:current_syntax = "yaml"
|
|
236
|
6741
|
237 unlet s:ns_word_char s:ns_uri_char s:c_verbatim_tag s:c_named_tag_handle s:c_secondary_tag_handle s:c_primary_tag_handle s:c_tag_handle s:ns_tag_char s:c_ns_shorthand_tag s:c_non_specific_tag s:c_ns_tag_property s:c_ns_anchor_char s:c_ns_anchor_name s:c_ns_anchor_property s:c_ns_alias_node s:ns_char s:ns_directive_name s:ns_local_tag_prefix s:ns_global_tag_prefix s:ns_tag_prefix s:c_indicator s:ns_plain_safe_out s:c_flow_indicator s:ns_plain_safe_in 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 s:ns_char_without_c_indicator s:ns_plain_safe_in_without_colhash s:ns_plain_safe_out_without_colhash
|
|
238 unlet s:_collection s:_neg_collection
|
|
239 delfunction s:SimplifyAdjacentCollections
|
|
240 delfunction s:SimplifyToAssumeAllPrintable
|
2581
|
241
|
375
|
242 let &cpo = s:cpo_save
|
|
243 unlet s:cpo_save
|