Mercurial > vim
annotate runtime/syntax/yaml.vim @ 34750:b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Commit: https://github.com/vim/vim/commit/cc7597c1edf478ad912d45b27f17175236f9791e
Author: itchyny <itchyny@cybozu.co.jp>
Date: Mon Apr 1 14:54:36 2024 +0200
runtime(yaml): improve syntax highlighting for YAML
- Recognize block scalar style to avoid unexpected highlighting by `yamlFlowString` (fix https://github.com/vim/vim/issues/11517)
- Improve performance of `yamlFlowMappingKey` by allowing execution by the NFA engine (fix https://github.com/vim/vim/issues/10730)
- It was intentionally disabled before patterns were optimized by `s:SimplifyToAssumeAllPrintable`.
- Fix detection of flow style mapping indicators (fix #8234).
- Enable highlighting of explicit mapping value indicators and node properties in flow style.
- Add syntax highlighting tests
closes: #14354
Signed-off-by: itchyny <itchyny@cybozu.co.jp>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 01 Apr 2024 15:00:10 +0200 |
parents | 8ac85adee561 |
children |
rev | line source |
---|---|
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> | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
5 " Latest Revision: 2024-04-01 |
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') | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
17 if exists('g:yaml_schema') |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
18 let b:yaml_schema = g:yaml_schema |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
19 else |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
20 let b:yaml_schema = 'core' |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
21 endif |
6741 | 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_indicator = '[\-?:,[\]{}#&*!|>''"%@`]' |
29 let s:c_flow_indicator = '[,[\]{}]' | |
30 | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
31 let s:ns_anchor_char = substitute(s:ns_char, '\v\C[\zs', '\=s:c_flow_indicator[1:-2]', '') |
6741 | 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) | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
40 let s:ns_anchor_char = s:SimplifyToAssumeAllPrintable(s:ns_anchor_char) |
6741 | 41 let s:ns_char_without_c_indicator = s:SimplifyToAssumeAllPrintable(s:ns_char_without_c_indicator) |
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 | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
62 let s:c_ns_anchor_name = s:ns_anchor_char.'\+' |
2581 | 63 let s:c_ns_anchor_property = '&'.s:c_ns_anchor_name |
64 let s:c_ns_alias_node = '\*'.s:c_ns_anchor_name | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
65 let s:c_ns_properties = '\%(\%('.s:c_ns_tag_property.'\|'.s:c_ns_anchor_property.'\)\s\+\)\+' |
2581 | 66 |
67 let s:ns_directive_name = s:ns_char.'\+' | |
68 | |
69 let s:ns_local_tag_prefix = '!'.s:ns_uri_char.'*' | |
70 let s:ns_global_tag_prefix = s:ns_tag_char.s:ns_uri_char.'*' | |
71 let s:ns_tag_prefix = s:ns_local_tag_prefix. | |
72 \ '\|'.s:ns_global_tag_prefix | |
73 | |
74 let s:ns_plain_safe_out = s:ns_char | |
75 let s:ns_plain_safe_in = '\%('.s:c_flow_indicator.'\@!'.s:ns_char.'\)' | |
76 | |
6741 | 77 let s:ns_plain_safe_in = substitute(s:ns_plain_safe_in, '\V\C\\%('.s:_collection.'\\@!'.s:_neg_collection.'\\)', '[^\1\2]', '') |
78 let s:ns_plain_safe_in_without_colhash = substitute(s:ns_plain_safe_in, '\V\C'.s:_neg_collection, '[^\1:#]', '') | |
79 let s:ns_plain_safe_out_without_colhash = substitute(s:ns_plain_safe_out, '\V\C'.s:_neg_collection, '[^\1:#]', '') | |
2581 | 80 |
6741 | 81 let s:ns_plain_first_in = '\%('.s:ns_char_without_c_indicator.'\|[?:\-]\%('.s:ns_plain_safe_in.'\)\@=\)' |
82 let s:ns_plain_first_out = '\%('.s:ns_char_without_c_indicator.'\|[?:\-]\%('.s:ns_plain_safe_out.'\)\@=\)' | |
83 | |
84 let s:ns_plain_char_in = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_in.'\|'.s:ns_plain_safe_in_without_colhash.'\)' | |
85 let s:ns_plain_char_out = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_out.'\|'.s:ns_plain_safe_out_without_colhash.'\)' | |
2581 | 86 |
87 let s:ns_plain_out = s:ns_plain_first_out . s:ns_plain_char_out.'*' | |
88 let s:ns_plain_in = s:ns_plain_first_in . s:ns_plain_char_in.'*' | |
89 | |
90 | |
1698 | 91 syn keyword yamlTodo contained TODO FIXME XXX NOTE |
7 | 92 |
2581 | 93 syn region yamlComment display oneline start='\%\(^\|\s\)#' end='$' |
94 \ contains=yamlTodo | |
7 | 95 |
2581 | 96 execute 'syn region yamlDirective oneline start='.string('^\ze%'.s:ns_directive_name.'\s\+').' '. |
97 \ 'end="$" '. | |
98 \ 'contains=yamlTAGDirective,'. | |
99 \ 'yamlYAMLDirective,'. | |
100 \ 'yamlReservedDirective '. | |
101 \ 'keepend' | |
1698 | 102 |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
103 syn match yamlTAGDirective /%TAG\ze\s/ contained nextgroup=yamlTagHandle skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
104 execute 'syn match yamlTagHandle' string(s:c_tag_handle) 'contained nextgroup=yamlTagPrefix skipwhite' |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
105 execute 'syn match yamlTagPrefix' string(s:ns_tag_prefix) 'contained nextgroup=yamlComment skipwhite' |
7 | 106 |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
107 syn match yamlYAMLDirective /%YAML\ze\s/ contained nextgroup=yamlYAMLVersion skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
108 syn match yamlYAMLVersion /\d\+\.\d\+/ contained nextgroup=yamlComment skipwhite |
2581 | 109 |
110 execute 'syn match yamlReservedDirective contained nextgroup=yamlComment '. | |
111 \string('%\%(\%(TAG\|YAML\)\s\)\@!'.s:ns_directive_name) | |
7 | 112 |
2581 | 113 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
114 \ contains=yamlEscape contained nextgroup=yamlFlowMappingDelimiter,yamlComment skipwhite |
2581 | 115 syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''" end="'" |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
116 \ contains=yamlSingleEscape contained nextgroup=yamlFlowMappingDelimiter,yamlComment skipwhite |
2581 | 117 syn match yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)' |
118 syn match yamlSingleEscape contained "''" | |
119 | |
6741 | 120 syn cluster yamlConstant contains=yamlBool,yamlNull |
121 | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
122 syn cluster yamlFlowNode contains=yamlFlowString,yamlFlowMapping,yamlFlowCollection |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
123 syn cluster yamlFlowNode add=yamlFlowMappingKey,yamlFlowMappingKeyStart,yamlFlowMappingMerge |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
124 syn cluster yamlFlowNode add=@yamlConstant,yamlPlainScalar,yamlFloat,yamlComment |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
125 syn cluster yamlFlowNode add=yamlTimestamp,yamlInteger,yamlAlias,yamlFlowNodeProperties |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
126 syn region yamlFlowMapping matchgroup=yamlFlowIndicator start='{\@<!{{\@!' end='}' contains=@yamlFlowNode |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
127 syn region yamlFlowCollection matchgroup=yamlFlowIndicator start='\[' end='\]' contains=@yamlFlowNode |
2581 | 128 |
129 execute 'syn match yamlPlainScalar /'.s:ns_plain_out.'/' | |
130 execute 'syn match yamlPlainScalar contained /'.s:ns_plain_in.'/' | |
131 | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
132 execute 'syn match yamlFlowMappingKey /'.s:ns_plain_in.'\%(\s\+'.s:ns_plain_in.'\)*\ze\s*:/ contained '. |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
133 \'nextgroup=yamlFlowMappingDelimiter skipwhite' |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
134 syn match yamlFlowMappingKeyStart /?/ contained nextgroup=@yamlFlowNode skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
135 syn match yamlFlowMappingMerge /<<\ze\s*:/ contained nextgroup=yamlFlowMappingDelimiter skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
136 syn match yamlFlowMappingDelimiter /:/ contained nextgroup=@yamlFlowNode skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
137 execute 'syn match yamlFlowNodeProperties' string(s:c_ns_properties) |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
138 \ 'contained contains=yamlNodeTag,yamlAnchor nextgroup=@yamlFlowNode skipwhite' |
2581 | 139 |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
140 execute 'syn match yamlBlockMappingKey /^\s*\zs'.s:ns_plain_out.'\%(\s\+'.s:ns_plain_out.'\)*\ze\s*:\%(\s\|$\)/ '. |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
141 \'nextgroup=yamlBlockMappingDelimiter skipwhite' |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
142 execute 'syn match yamlBlockMappingKey /'.s:ns_plain_out.'\%(\s\+'.s:ns_plain_out.'\)*\ze\s*:\%(\s\|$\)/ contained '. |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
143 \'nextgroup=yamlBlockMappingDelimiter skipwhite' |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
144 syn match yamlBlockMappingKeyString /^\s*\zs\%("\%([^"]\|\\"\)*"\|'\%([^']\|''\)*'\)\ze\s*:\%(\s\|$\)/ |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
145 \ contains=yamlFlowString nextgroup=yamlBlockMappingDelimiter skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
146 syn match yamlBlockMappingKeyString /\%("\%([^"]\|\\"\)*"\|'\%([^']\|''\)*'\)\ze\s*:\%(\s\|$\)/ contained |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
147 \ contains=yamlFlowString nextgroup=yamlBlockMappingDelimiter skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
148 syn match yamlBlockMappingMerge /^\s*\zs<<\ze\s*:\%(\s\|$\)/ nextgroup=yamlBlockMappingDelimiter skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
149 syn match yamlBlockMappingMerge /<<\ze\s*:\%(\s\|$\)/ contained nextgroup=yamlBlockMappingDelimiter skipwhite |
7 | 150 |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
151 syn match yamlBlockMappingDelimiter /^\s*\zs:\ze\%(\s\|$\)/ nextgroup=@yamlBlockNode skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
152 syn match yamlBlockMappingDelimiter /:\ze\%(\s\|$\)/ contained nextgroup=@yamlBlockNode skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
153 syn match yamlBlockMappingKeyStart /^\s*\zs?\ze\%(\s\|$\)/ nextgroup=@yamlBlockNode skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
154 syn match yamlBlockMappingKeyStart /?\ze\%(\s\|$\)/ contained nextgroup=@yamlBlockNode skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
155 |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
156 syn match yamlBlockCollectionItemStart /^\s*\zs-\ze\%(\s\|$\)/ nextgroup=@yamlBlockNode skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
157 syn match yamlBlockCollectionItemStart /-\ze\%(\s\|$\)/ contained nextgroup=@yamlBlockNode skipwhite |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
158 |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
159 execute 'syn match yamlBlockNodeProperties' string(s:c_ns_properties) |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
160 \ 'contained contains=yamlNodeTag,yamlAnchor nextgroup=@yamlFlowNode,yamlBlockScalarHeader skipwhite' |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
161 syn match yamlBlockScalarHeader '[|>]\%([1-9][+-]\|[+-]\?[1-9]\?\)\%(\s\+#.*\)\?$' contained |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
162 \ contains=yamlComment nextgroup=yamlBlockString skipnl |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
163 syn region yamlBlockString start=/^\z(\s\+\)/ skip=/^$/ end=/^\%(\z1\)\@!/ contained |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
164 |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
165 syn cluster yamlBlockNode contains=@yamlFlowNode,yamlBlockMappingKey,yamlBlockMappingKeyString, |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
166 \yamlBlockMappingMerge,yamlBlockMappingKeyStart,yamlBlockCollectionItemStart, |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
167 \yamlBlockNodeProperties,yamlBlockScalarHeader |
2581 | 168 |
6741 | 169 syn cluster yamlScalarWithSpecials contains=yamlPlainScalar,yamlBlockMappingKey,yamlFlowMappingKey |
2581 | 170 |
6741 | 171 let s:_bounder = s:SimplifyToAssumeAllPrintable('\%([[\]{}, \t]\@!\p\)') |
172 if b:yaml_schema is# 'json' | |
173 syn keyword yamlNull null contained containedin=@yamlScalarWithSpecials | |
174 syn keyword yamlBool true false | |
175 exe 'syn match yamlInteger /'.s:_bounder.'\@1<!\%(0\|-\=[1-9][0-9]*\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' | |
176 exe 'syn match yamlFloat /'.s:_bounder.'\@1<!\%(-\=[1-9][0-9]*\%(\.[0-9]*\)\=\(e[-+]\=[0-9]\+\)\=\|0\|-\=\.inf\|\.nan\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' | |
177 elseif b:yaml_schema is# 'core' | |
178 syn keyword yamlNull null Null NULL contained containedin=@yamlScalarWithSpecials | |
179 syn keyword yamlBool true True TRUE false False FALSE contained containedin=@yamlScalarWithSpecials | |
180 exe 'syn match yamlNull /'.s:_bounder.'\@1<!\~'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
181 exe 'syn match yamlInteger /'.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' |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
182 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' |
6741 | 183 elseif b:yaml_schema is# 'pyyaml' |
184 syn keyword yamlNull null Null NULL contained containedin=@yamlScalarWithSpecials | |
185 syn keyword yamlBool true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF contained containedin=@yamlScalarWithSpecials | |
186 exe 'syn match yamlNull /'.s:_bounder.'\@1<!\~'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' | |
187 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' | |
188 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' | |
189 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' | |
190 elseif b:yaml_schema is# 'failsafe' | |
191 " Nothing | |
192 endif | |
193 unlet s:_bounder | |
2581 | 194 |
7 | 195 |
2581 | 196 execute 'syn match yamlNodeTag '.string(s:c_ns_tag_property) |
197 execute 'syn match yamlAnchor '.string(s:c_ns_anchor_property) | |
198 execute 'syn match yamlAlias '.string(s:c_ns_alias_node) | |
199 | |
200 syn match yamlDocumentStart '^---\ze\%(\s\|$\)' | |
201 syn match yamlDocumentEnd '^\.\.\.\ze\%(\s\|$\)' | |
7 | 202 |
2581 | 203 hi def link yamlTodo Todo |
204 hi def link yamlComment Comment | |
205 | |
206 hi def link yamlDocumentStart PreProc | |
207 hi def link yamlDocumentEnd PreProc | |
7 | 208 |
2581 | 209 hi def link yamlDirectiveName Keyword |
7 | 210 |
2581 | 211 hi def link yamlTAGDirective yamlDirectiveName |
212 hi def link yamlTagHandle String | |
213 hi def link yamlTagPrefix String | |
7 | 214 |
2581 | 215 hi def link yamlYAMLDirective yamlDirectiveName |
216 hi def link yamlReservedDirective Error | |
217 hi def link yamlYAMLVersion Number | |
218 | |
219 hi def link yamlString String | |
220 hi def link yamlFlowString yamlString | |
221 hi def link yamlFlowStringDelimiter yamlString | |
222 hi def link yamlEscape SpecialChar | |
223 hi def link yamlSingleEscape SpecialChar | |
224 | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
225 hi def link yamlMappingKey Identifier |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
226 hi def link yamlMappingKeyStart Special |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
227 hi def link yamlMappingMerge Special |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
228 hi def link yamlKeyValueDelimiter Special |
2581 | 229 |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
230 hi def link yamlFlowIndicator Special |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
231 hi def link yamlFlowMappingKey yamlMappingKey |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
232 hi def link yamlFlowMappingKeyStart yamlMappingKeyStart |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
233 hi def link yamlFlowMappingMerge yamlMappingMerge |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
234 hi def link yamlFlowMappingDelimiter yamlKeyValueDelimiter |
2581 | 235 |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
236 hi def link yamlBlockMappingKey yamlMappingKey |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
237 hi def link yamlBlockMappingKeyStart yamlMappingKeyStart |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
238 hi def link yamlBlockMappingMerge yamlMappingMerge |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
239 hi def link yamlBlockMappingDelimiter yamlKeyValueDelimiter |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
240 hi def link yamlBlockCollectionItemStart Label |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
241 hi def link yamlBlockScalarHeader Special |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
242 " We do not link yamlBlockString to yamlString, because yamlPlainScalar is |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
243 " not highlighted as string neighter, and also due to historical reasons. |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
244 " hi def link yamlBlockString yamlString |
2581 | 245 |
246 hi def link yamlConstant Constant | |
247 | |
6741 | 248 hi def link yamlNull yamlConstant |
249 hi def link yamlBool yamlConstant | |
250 | |
2581 | 251 hi def link yamlAnchor Type |
252 hi def link yamlAlias Type | |
253 hi def link yamlNodeTag Type | |
254 | |
255 hi def link yamlInteger Number | |
256 hi def link yamlFloat Float | |
257 hi def link yamlTimestamp Number | |
7 | 258 |
259 let b:current_syntax = "yaml" | |
260 | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
261 unlet s:ns_char s:ns_word_char s:ns_uri_char s:ns_tag_char s:c_indicator s:c_flow_indicator |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
262 \ s:ns_anchor_char s:ns_char_without_c_indicator s:_collection s:_neg_collection |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
263 \ s:c_verbatim_tag s:c_named_tag_handle s:c_secondary_tag_handle s:c_primary_tag_handle |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
264 \ s:c_tag_handle s:c_ns_shorthand_tag s:c_non_specific_tag s:c_ns_tag_property |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
265 \ s:c_ns_anchor_name s:c_ns_anchor_property s:c_ns_alias_node s:c_ns_properties |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
266 \ s:ns_directive_name s:ns_local_tag_prefix s:ns_global_tag_prefix s:ns_tag_prefix |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
267 \ s:ns_plain_safe_out s:ns_plain_safe_in s:ns_plain_safe_in_without_colhash s:ns_plain_safe_out_without_colhash |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
268 \ 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 |
6741 | 269 delfunction s:SimplifyAdjacentCollections |
270 delfunction s:SimplifyToAssumeAllPrintable | |
2581 | 271 |
375 | 272 let &cpo = s:cpo_save |
273 unlet s:cpo_save | |
34750
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
274 |
b9b335997b26
runtime(yaml): improve syntax highlighting for YAML
Christian Brabandt <cb@256bit.org>
parents:
18053
diff
changeset
|
275 " vim: set et sw=4 sts=4 ts=8: |