blob: ba8906dfc41378ee4cb535456dfdb5acd6abc322 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +02002" 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: 2010-09-16
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +02007if exists('b:current_syntax')
8 finish
Bram Moolenaar071d4272004-06-13 20:20:40 +00009endif
10
Bram Moolenaar42eeac32005-06-29 22:40:58 +000011let s:cpo_save = &cpo
12set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000013
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020014let s:ns_char = '\%(\%([\n\r\uFEFF \t]\)\@!\p\)'
15let s:ns_word_char = '\%(\w\|-\)'
16let s:ns_uri_char = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$,.!~*''()\[\]]\)'
17let s:ns_tag_char = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$.~*''()]\)'
18let s:c_ns_anchor_char = '\%(\%([\n\r\uFEFF \t,\[\]{}]\)\@!\p\)'
19let s:c_indicator = '[\-?:,\[\]{}#&*!|>''"%@`]'
20let s:c_flow_indicator = '[,\[\]{}]'
21
22let s:c_verbatim_tag = '!<'.s:ns_uri_char.'\+>'
23let s:c_named_tag_handle = '!'.s:ns_word_char.'\+!'
24let s:c_secondary_tag_handle = '!!'
25let s:c_primary_tag_handle = '!'
26let s:c_tag_handle = '\%('.s:c_named_tag_handle.
27 \ '\|'.s:c_secondary_tag_handle.
28 \ '\|'.s:c_primary_tag_handle.'\)'
29let s:c_ns_shorthand_tag = s:c_tag_handle . s:ns_tag_char.'\+'
30let s:c_non_specific_tag = '!'
31let s:c_ns_tag_property = s:c_verbatim_tag.
32 \ '\|'.s:c_ns_shorthand_tag.
33 \ '\|'.s:c_non_specific_tag
34
35let s:c_ns_anchor_name = s:c_ns_anchor_char.'\+'
36let s:c_ns_anchor_property = '&'.s:c_ns_anchor_name
37let s:c_ns_alias_node = '\*'.s:c_ns_anchor_name
38
39let s:ns_directive_name = s:ns_char.'\+'
40
41let s:ns_local_tag_prefix = '!'.s:ns_uri_char.'*'
42let s:ns_global_tag_prefix = s:ns_tag_char.s:ns_uri_char.'*'
43let s:ns_tag_prefix = s:ns_local_tag_prefix.
44 \ '\|'.s:ns_global_tag_prefix
45
46let s:ns_plain_safe_out = s:ns_char
47let s:ns_plain_safe_in = '\%('.s:c_flow_indicator.'\@!'.s:ns_char.'\)'
48
49let s:ns_plain_first_in = '\%('.s:c_indicator.'\@!'.s:ns_char.'\|[?:\-]\%('.s:ns_plain_safe_in.'\)\@=\)'
50let s:ns_plain_first_out = '\%('.s:c_indicator.'\@!'.s:ns_char.'\|[?:\-]\%('.s:ns_plain_safe_out.'\)\@=\)'
51
52let s:ns_plain_char_in = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_in.'\|[:#]\@!'.s:ns_plain_safe_in.'\)'
53let s:ns_plain_char_out = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_out.'\|[:#]\@!'.s:ns_plain_safe_out.'\)'
54
55let s:ns_plain_out = s:ns_plain_first_out . s:ns_plain_char_out.'*'
56let s:ns_plain_in = s:ns_plain_first_in . s:ns_plain_char_in.'*'
57
58
Bram Moolenaare37d50a2008-08-06 17:06:04 +000059syn keyword yamlTodo contained TODO FIXME XXX NOTE
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020061syn region yamlComment display oneline start='\%\(^\|\s\)#' end='$'
62 \ contains=yamlTodo
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020064execute 'syn region yamlDirective oneline start='.string('^\ze%'.s:ns_directive_name.'\s\+').' '.
65 \ 'end="$" '.
66 \ 'contains=yamlTAGDirective,'.
67 \ 'yamlYAMLDirective,'.
68 \ 'yamlReservedDirective '.
69 \ 'keepend'
Bram Moolenaar071d4272004-06-13 20:20:40 +000070
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020071syn match yamlTAGDirective '%TAG\s\+' contained nextgroup=yamlTagHandle
72execute 'syn match yamlTagHandle contained nextgroup=yamlTagPrefix '.string(s:c_tag_handle.'\s\+')
73execute 'syn match yamlTagPrefix contained nextgroup=yamlComment ' . string(s:ns_tag_prefix)
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020075syn match yamlYAMLDirective '%YAML\s\+' contained nextgroup=yamlYAMLVersion
76syn match yamlYAMLVersion '\d\+\.\d\+' contained nextgroup=yamlComment
Bram Moolenaar071d4272004-06-13 20:20:40 +000077
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020078execute 'syn match yamlReservedDirective contained nextgroup=yamlComment '.
79 \string('%\%(\%(TAG\|YAML\)\s\)\@!'.s:ns_directive_name)
Bram Moolenaar42eeac32005-06-29 22:40:58 +000080
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020081syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"'
82 \ contains=yamlEscape
83 \ nextgroup=yamlKeyValueDelimiter
84syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'"
85 \ contains=yamlSingleEscape
86 \ nextgroup=yamlKeyValueDelimiter
87syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)'
88syn match yamlSingleEscape contained "''"
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020090syn match yamlBlockScalarHeader contained '\s\+\zs[|>]\%([+-]\=[1-9]\|[1-9]\=[+-]\)\='
Bram Moolenaar071d4272004-06-13 20:20:40 +000091
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +020092syn cluster yamlFlow contains=yamlFlowString,yamlFlowMapping,yamlFlowCollection
93syn cluster yamlFlow add=yamlFlowMappingKey,yamlFlowMappingMerge
94syn cluster yamlFlow add=yamlConstant,yamlPlainScalar,yamlFloat
95syn cluster yamlFlow add=yamlTimestamp,yamlInteger,yamlMappingKeyStart
96syn cluster yamlFlow add=yamlComment
97syn region yamlFlowMapping matchgroup=yamlFlowIndicator start='{' end='}' contains=@yamlFlow
98syn region yamlFlowCollection matchgroup=yamlFlowIndicator start='\[' end='\]' contains=@yamlFlow
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +0200100execute 'syn match yamlPlainScalar /'.s:ns_plain_out.'/'
101execute 'syn match yamlPlainScalar contained /'.s:ns_plain_in.'/'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +0200103syn match yamlMappingKeyStart '?\ze\s'
104syn match yamlMappingKeyStart '?' contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +0200106execute 'syn match yamlFlowMappingKey /'.s:ns_plain_in.'\ze\s*:/ contained '.
107 \'nextgroup=yamlKeyValueDelimiter'
108syn match yamlFlowMappingMerge /<<\ze\s*:/ contained nextgroup=yamlKeyValueDelimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +0200110syn match yamlBlockCollectionItemStart '^\s*\zs-\%(\s\+-\)*\s' nextgroup=yamlBlockMappingKey,yamlBlockMappingMerge
111execute 'syn match yamlBlockMappingKey /^\s*\zs'.s:ns_plain_out.'\ze\s*:\%(\s\|$\)/ '.
112 \'nextgroup=yamlKeyValueDelimiter'
113execute 'syn match yamlBlockMappingKey /\s*\zs'.s:ns_plain_out.'\ze\s*:\%(\s\|$\)/ contained '.
114 \'nextgroup=yamlKeyValueDelimiter'
115syn match yamlBlockMappingMerge /^\s*\zs<<\ze:\%(\s\|$\)/ nextgroup=yamlKeyValueDelimiter
116syn match yamlBlockMappingMerge /<<\ze\s*:\%(\s\|$\)/ nextgroup=yamlKeyValueDelimiter contained
117
118syn match yamlKeyValueDelimiter /\s*:/ contained
119syn match yamlKeyValueDelimiter /\s*:/ contained
120
121syn keyword yamlConstant true True TRUE false False FALSE
122syn keyword yamlConstant null Null NULL
123syn match yamlConstant '\<\~\>'
124
125syn match yamlTimestamp /\%([\[\]{}, \t]\@!\p\)\@<!\%(\d\{4}-\d\d\=-\d\d\=\%(\%([Tt]\|\s\+\)\%(\d\d\=\):\%(\d\d\):\%(\d\d\)\%(\.\%(\d*\)\)\=\%(\s*\%(Z\|[+-]\d\d\=\%(:\d\d\)\=\)\)\=\)\=\)\%([\[\]{}, \t]\@!\p\)\@!/
126
127syn match yamlInteger /\%([\[\]{}, \t]\@!\p\)\@<!\%([+-]\=\%(0\%(b[0-1_]\+\|[0-7_]\+\|x[0-9a-fA-F_]\+\)\=\|\%([1-9][0-9_]*\%(:[0-5]\=\d\)\+\)\)\)\%([\[\]{}, \t]\@!\p\)\@!/
128syn match yamlFloat /\%([\[\]{}, \t]\@!\p\)\@<!\%([+-]\=\%(\%(\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\)\)\)\%([\[\]{}, \t]\@!\p\)\@!/
129
130execute 'syn match yamlNodeTag '.string(s:c_ns_tag_property)
131execute 'syn match yamlAnchor '.string(s:c_ns_anchor_property)
132execute 'syn match yamlAlias '.string(s:c_ns_alias_node)
133
134syn match yamlDocumentStart '^---\ze\%(\s\|$\)'
135syn match yamlDocumentEnd '^\.\.\.\ze\%(\s\|$\)'
136
137hi def link yamlTodo Todo
138hi def link yamlComment Comment
139
140hi def link yamlDocumentStart PreProc
141hi def link yamlDocumentEnd PreProc
142
143hi def link yamlDirectiveName Keyword
144
145hi def link yamlTAGDirective yamlDirectiveName
146hi def link yamlTagHandle String
147hi def link yamlTagPrefix String
148
149hi def link yamlYAMLDirective yamlDirectiveName
150hi def link yamlReservedDirective Error
151hi def link yamlYAMLVersion Number
152
153hi def link yamlString String
154hi def link yamlFlowString yamlString
155hi def link yamlFlowStringDelimiter yamlString
156hi def link yamlEscape SpecialChar
157hi def link yamlSingleEscape SpecialChar
158
159hi def link yamlBlockCollectionItemStart Label
160hi def link yamlBlockMappingKey Identifier
161hi def link yamlBlockMappingMerge Special
162
163hi def link yamlFlowMappingKey Identifier
164hi def link yamlFlowMappingMerge Special
165
166hi def link yamlMappingKeyStart Special
167hi def link yamlFlowIndicator Special
168hi def link yamlKeyValueDelimiter Special
169
170hi def link yamlConstant Constant
171
172hi def link yamlAnchor Type
173hi def link yamlAlias Type
174hi def link yamlNodeTag Type
175
176hi def link yamlInteger Number
177hi def link yamlFloat Float
178hi def link yamlTimestamp Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179
180let b:current_syntax = "yaml"
181
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +0200182unlet 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
183
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000184let &cpo = s:cpo_save
185unlet s:cpo_save
Bram Moolenaar24ea3ba2010-09-19 19:01:21 +0200186