diff options
| author | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-06 15:08:20 +0200 | 
|---|---|---|
| committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-06 15:08:20 +0200 | 
| commit | d9ee362537a34473b32ad3b4a1d7feb56a6b6811 (patch) | |
| tree | 5d0cf440bb0893f679f21963e79f866ad3a73d35 | |
| parent | 57badea2dc9aff361d528aeeeb22ac2e85da1435 (diff) | |
| download | vim-polyglot-d9ee362537a34473b32ad3b4a1d7feb56a6b6811.tar.gz vim-polyglot-d9ee362537a34473b32ad3b4a1d7feb56a6b6811.zip | |
Fix weird indentation issue of yaml
Diffstat (limited to '')
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | after/ftplugin/yaml.vim | 2 | ||||
| -rw-r--r-- | after/syntax/yaml.vim | 2 | ||||
| -rw-r--r-- | ftdetect/polyglot.vim | 3 | ||||
| -rw-r--r-- | ftplugin/yaml.vim | 29 | ||||
| -rw-r--r-- | indent/yaml.vim | 159 | ||||
| -rw-r--r-- | packages.yaml | 9 | ||||
| -rwxr-xr-x | scripts/build | 9 | ||||
| -rw-r--r-- | syntax/yaml.vim | 247 | 
9 files changed, 455 insertions, 10 deletions
| @@ -7,7 +7,7 @@ A collection of language packs for Vim.  > One to rule them all, one to find them, one to bring them all and in the darkness bind them.  - It **won't affect your startup time**, as scripts are loaded only on demand\*. -- It **installs and updates 120+ times faster** than the <!--Package Count-->191<!--/Package Count--> packages it consists of. +- It **installs and updates 120+ times faster** than the <!--Package Count-->192<!--/Package Count--> packages it consists of.  - It is more secure because scripts loaded for all extensions are generated by vim-polyglot (ftdetect).  - Solid syntax and indentation support (other features skipped). Only the best language packs.  - All unnecessary files are ignored (like enormous documentation from php support). @@ -229,7 +229,8 @@ If you need full functionality of any plugin, please use it directly with your p  - [xdc](https://github.com/amal-khailtash/vim-xdc-syntax)  - [xml](https://github.com/amadeus/vim-xml)  - [xsl](https://github.com/vim-scripts/XSLT-syntax) -- [yaml](https://github.com/stephpy/vim-yaml) +- [yaml-extras](https://github.com/stephpy/vim-yaml) +- [yaml](https://github.com/vim/vim/tree/df44a27b53586fccfc6a3aedc89061fdd9a515ff/runtime)  - [yard](https://github.com/sheerun/vim-yardoc)  - [zephir](https://github.com/xwsoul/vim-zephir)  - [zig](https://github.com/ziglang/zig.vim) diff --git a/after/ftplugin/yaml.vim b/after/ftplugin/yaml.vim index db608fa4..69785fc2 100644 --- a/after/ftplugin/yaml.vim +++ b/after/ftplugin/yaml.vim @@ -1,4 +1,4 @@ -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml') == -1 +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml-extras') == -1  " Vim indent file  " Language: Yaml diff --git a/after/syntax/yaml.vim b/after/syntax/yaml.vim index 097d1535..3a1e89a2 100644 --- a/after/syntax/yaml.vim +++ b/after/syntax/yaml.vim @@ -1,4 +1,4 @@ -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml') == -1 +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml-extras') == -1  " To make this file do stuff, add something like the following (without the  " leading ") to your ~/.vimrc: diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 186ba9da..792c2432 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -1677,6 +1677,9 @@ if !has_key(s:disabled_packages, 'xsl')    au BufNewFile,BufRead *.xslt setf xsl  endif +if !has_key(s:disabled_packages, 'yaml-extras') +endif +  if !has_key(s:disabled_packages, 'ansible')    au BufNewFile,BufRead group_vars/* setf yaml.ansible    au BufNewFile,BufRead handlers.*.y{a,}ml setf yaml.ansible diff --git a/ftplugin/yaml.vim b/ftplugin/yaml.vim new file mode 100644 index 00000000..2e9728bd --- /dev/null +++ b/ftplugin/yaml.vim @@ -0,0 +1,29 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml') == -1 + +" Vim filetype plugin file +" Language:             YAML (YAML Ain't Markup Language) +" Previous Maintainer:  Nikolai Weibull <now@bitwi.se> (inactive) +" Last Change:      	2020 Mar 02 + +if exists("b:did_ftplugin") +  finish +endif +let b:did_ftplugin = 1 + +let s:cpo_save = &cpo +set cpo&vim + +let b:undo_ftplugin = "setl com< cms< et< fo<" + +setlocal comments=:# commentstring=#\ %s expandtab +setlocal formatoptions-=t formatoptions+=croql + +if !exists("g:yaml_recommended_style") || g:yaml_recommended_style != 0 +  let b:undo_ftplugin ..= " sw< sts<" +  setlocal shiftwidth=2 softtabstop=2 +endif + +let &cpo = s:cpo_save +unlet s:cpo_save + +endif diff --git a/indent/yaml.vim b/indent/yaml.vim new file mode 100644 index 00000000..c7fdebcf --- /dev/null +++ b/indent/yaml.vim @@ -0,0 +1,159 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml') == -1 + +" Vim indent file +" Language:         YAML +" Maintainer:       Nikolai Pavlov <zyx.vim@gmail.com> +" Last Change:	    2019 Sep 28 + +" Only load this indent file when no other was loaded. +if exists('b:did_indent') +  finish +endif + +let s:save_cpo = &cpo +set cpo&vim + +let b:did_indent = 1 + +setlocal indentexpr=GetYAMLIndent(v:lnum) +setlocal indentkeys=!^F,o,O,0#,0},0],<:>,0- +setlocal nosmartindent + +let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent<' + +" Only define the function once. +if exists('*GetYAMLIndent') +    finish +endif + +function s:FindPrevLessIndentedLine(lnum, ...) +    let prevlnum = prevnonblank(a:lnum-1) +    let curindent = a:0 ? a:1 : indent(a:lnum) +    while           prevlnum +                \&&  indent(prevlnum) >=  curindent +                \&& getline(prevlnum) !~# '^\s*#' +        let prevlnum = prevnonblank(prevlnum-1) +    endwhile +    return prevlnum +endfunction + +function s:FindPrevLEIndentedLineMatchingRegex(lnum, regex) +    let plilnum = s:FindPrevLessIndentedLine(a:lnum, indent(a:lnum)+1) +    while plilnum && getline(plilnum) !~# a:regex +        let plilnum = s:FindPrevLessIndentedLine(plilnum) +    endwhile +    return plilnum +endfunction + +let s:mapkeyregex='\v^\s*\#@!\S@=%(\''%([^'']|\''\'')*\'''. +                \                 '|\"%([^"\\]|\\.)*\"'. +                \                 '|%(%(\:\ )@!.)*)\:%(\ |$)' +let s:liststartregex='\v^\s*%(\-%(\ |$))' + +let s:c_ns_anchor_char = '\v%([\n\r\uFEFF \t,[\]{}]@!\p)' +let s:c_ns_anchor_name = s:c_ns_anchor_char.'+' +let s:c_ns_anchor_property =  '\v\&'.s:c_ns_anchor_name + +let s:ns_word_char = '\v[[:alnum:]_\-]' +let s:ns_tag_char  = '\v%(%\x\x|'.s:ns_word_char.'|[#/;?:@&=+$.~*''()])' +let s:c_named_tag_handle     = '\v\!'.s:ns_word_char.'+\!' +let s:c_secondary_tag_handle = '\v\!\!' +let s:c_primary_tag_handle   = '\v\!' +let s:c_tag_handle = '\v%('.s:c_named_tag_handle. +            \            '|'.s:c_secondary_tag_handle. +            \            '|'.s:c_primary_tag_handle.')' +let s:c_ns_shorthand_tag = '\v'.s:c_tag_handle . s:ns_tag_char.'+' +let s:c_non_specific_tag = '\v\!' +let s:ns_uri_char  = '\v%(%\x\x|'.s:ns_word_char.'\v|[#/;?:@&=+$,.!~*''()[\]])' +let s:c_verbatim_tag = '\v\!\<'.s:ns_uri_char.'+\>' +let s:c_ns_tag_property = '\v'.s:c_verbatim_tag. +            \               '\v|'.s:c_ns_shorthand_tag. +            \               '\v|'.s:c_non_specific_tag + +let s:block_scalar_header = '\v[|>]%([+-]?[1-9]|[1-9]?[+-])?' + +function GetYAMLIndent(lnum) +    if a:lnum == 1 || !prevnonblank(a:lnum-1) +        return 0 +    endif + +    let prevlnum = prevnonblank(a:lnum-1) +    let previndent = indent(prevlnum) + +    let line = getline(a:lnum) +    if line =~# '^\s*#' && getline(a:lnum-1) =~# '^\s*#' +        " Comment blocks should have identical indent +        return previndent +    elseif line =~# '^\s*[\]}]' +        " Lines containing only closing braces should have previous indent +        return indent(s:FindPrevLessIndentedLine(a:lnum)) +    endif + +    " Ignore comment lines when calculating indent +    while getline(prevlnum) =~# '^\s*#' +        let prevlnum = prevnonblank(prevlnum-1) +        if !prevlnum +            return previndent +        endif +    endwhile + +    let prevline = getline(prevlnum) +    let previndent = indent(prevlnum) + +    " Any examples below assume that shiftwidth=2 +    if prevline =~# '\v[{[:]$|[:-]\ [|>][+\-]?%(\s+\#.*|\s*)$' +        " Mapping key: +        "     nested mapping: ... +        " +        " - { +        "     key: [ +        "         list value +        "     ] +        " } +        " +        " - |- +        "     Block scalar without indentation indicator +        return previndent+shiftwidth() +    elseif prevline =~# '\v[:-]\ [|>]%(\d+[+\-]?|[+\-]?\d+)%(\#.*|\s*)$' +        " - |+2 +        "   block scalar with indentation indicator +        "#^^ indent+2, not indent+shiftwidth +        return previndent + str2nr(matchstr(prevline, +                    \'\v([:-]\ [|>])@<=[+\-]?\d+%([+\-]?%(\s+\#.*|\s*)$)@=')) +    elseif prevline =~# '\v\"%([^"\\]|\\.)*\\$' +        "    "Multiline string \ +        "     with escaped end" +        let qidx = match(prevline, '\v\"%([^"\\]|\\.)*\\') +        return virtcol([prevlnum, qidx+1]) +    elseif line =~# s:liststartregex +        " List line should have indent equal to previous list line unless it was  +        " caught by one of the previous rules +        return indent(s:FindPrevLEIndentedLineMatchingRegex(a:lnum, +                    \                                       s:liststartregex)) +    elseif line =~# s:mapkeyregex +        " Same for line containing mapping key +        let prevmapline = s:FindPrevLEIndentedLineMatchingRegex(a:lnum, +                    \                                           s:mapkeyregex) +        if getline(prevmapline) =~# '^\s*- ' +            return indent(prevmapline) + 2 +        else +            return indent(prevmapline) +        endif +    elseif prevline =~# '^\s*- ' +        " - List with +        "   multiline scalar +        return previndent+2 +    elseif prevline =~# s:mapkeyregex . '\v\s*%(%('.s:c_ns_tag_property. +                \                              '\v|'.s:c_ns_anchor_property. +                \                              '\v|'.s:block_scalar_header. +                \                             '\v)%(\s+|\s*%(\#.*)?$))*' +        " Mapping with: value +        "     that is multiline scalar +        return previndent+shiftwidth() +    endif +    return previndent +endfunction + +let &cpo = s:save_cpo + +endif diff --git a/packages.yaml b/packages.yaml index f757cf99..65df8369 100644 --- a/packages.yaml +++ b/packages.yaml @@ -1650,7 +1650,9 @@ filetypes:    linguist: XSLT  ---  name: yaml -remote: stephpy/vim-yaml +# Fixes indentation issue: https://github.com/vim/vim/issues/6417 +remote: vim/vim@df44a27b53586fccfc6a3aedc89061fdd9a515ff:runtime +glob: '**/yaml.vim'  filetypes:  - name: yaml    linguist: YAML @@ -1659,6 +1661,11 @@ filetypes:    - fish_read_history    ignored_filenames:    - '~/.config/fish/fish_{read_,}history' +--- +name: yaml-extras +remote: stephpy/vim-yaml +after: yaml +filetypes: []  # Ansible needs to be after YAML  ---  name: ansible diff --git a/scripts/build b/scripts/build index 79a1cfe7..c9a12743 100755 --- a/scripts/build +++ b/scripts/build @@ -155,7 +155,8 @@ end  def parse_remote(remote)    match = remote.match(/(?<repo>[^@:]+)(?:@(?<branch>[^:]+))?(?::(?<path>.*))?/) -  [match[:repo], match[:branch] || "master", match[:path]] +  dir = "tmp/" + match[:repo] + (match[:branch] ? "-#{match[:branch]}" : "") +  [match[:repo], match[:branch] || "master", match[:path], dir]  end  def copy_file(package, src, dest) @@ -179,8 +180,7 @@ def download(packages)    packages.map { |p| p["remote"] or raise "No remote for: " + p["name"] }.uniq.each_slice(20) do |remotes|      remotes.map do |remote|        Thread.new do -        repo, branch, path = parse_remote(remote) -        dir = "tmp/" + repo +        repo, branch, path, dir = parse_remote(remote)          unless File.exist?(dir)            FileUtils.mkdir_p(dir)            url = "https://codeload.github.com/#{repo}/tar.gz/#{branch}" @@ -321,8 +321,7 @@ def extract(packages)    output = []    packages.map do |package| -    repo, branch, path = parse_remote(package["remote"]) -    dir = "tmp/" + repo +    repo, branch, path, dir = parse_remote(package["remote"])      dirs = package.fetch("dirs", default_dirs)      ignored_dirs = package.fetch("ignored_dirs", [])      if ignored_dirs.size > 0 diff --git a/syntax/yaml.vim b/syntax/yaml.vim new file mode 100644 index 00000000..53e60684 --- /dev/null +++ b/syntax/yaml.vim @@ -0,0 +1,247 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'yaml') == -1 + +" Vim syntax file +" Language:         YAML (YAML Ain't Markup Language) 1.2 +" Maintainer:       Nikolai Pavlov <zyx.vim@gmail.com> +" First author:     Nikolai Weibull <now@bitwi.se> +" Latest Revision:  2015-03-28 +" 		    removed duplicate yamlKeyValueDelimiter (pull #4799) + +if exists('b:current_syntax') +    finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +" Choose the schema to use +" TODO: Validate schema +if !exists('b:yaml_schema') +  if exists('g:yaml_schema') +    let b:yaml_schema = g:yaml_schema +  else +    let b:yaml_schema = 'core' +  endif +endif + +let s:ns_char = '\%([\n\r\uFEFF \t]\@!\p\)' +let s:ns_word_char = '[[:alnum:]_\-]' +let s:ns_uri_char  = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$,.!~*''()[\]]\)' +let s:ns_tag_char  = '\%(%\x\x\|'.s:ns_word_char.'\|[#/;?:@&=+$.~*''()]\)' +let s:c_ns_anchor_char = '\%([\n\r\uFEFF \t,[\]{}]\@!\p\)' +let s:c_indicator      = '[\-?:,[\]{}#&*!|>''"%@`]' +let s:c_flow_indicator = '[,[\]{}]' + +let s:ns_char_without_c_indicator = substitute(s:ns_char, '\v\C[\zs', '\=s:c_indicator[1:-2]', '') + +let s:_collection = '[^\@!\(\%(\\\.\|\[^\\\]]\)\+\)]' +let s:_neg_collection = '[^\(\%(\\\.\|\[^\\\]]\)\+\)]' +function s:SimplifyToAssumeAllPrintable(p) +    return substitute(a:p, '\V\C\\%('.s:_collection.'\\@!\\p\\)', '[^\1]', '') +endfunction +let s:ns_char = s:SimplifyToAssumeAllPrintable(s:ns_char) +let s:ns_char_without_c_indicator = s:SimplifyToAssumeAllPrintable(s:ns_char_without_c_indicator) +let s:c_ns_anchor_char = s:SimplifyToAssumeAllPrintable(s:c_ns_anchor_char) + +function s:SimplifyAdjacentCollections(p) +    return substitute(a:p, '\V\C'.s:_collection.'\\|'.s:_collection, '[\1\2]', 'g') +endfunction +let s:ns_uri_char = s:SimplifyAdjacentCollections(s:ns_uri_char) +let s:ns_tag_char = s:SimplifyAdjacentCollections(s:ns_tag_char) + +let s:c_verbatim_tag = '!<'.s:ns_uri_char.'\+>' +let s:c_named_tag_handle     = '!'.s:ns_word_char.'\+!' +let s:c_secondary_tag_handle = '!!' +let s:c_primary_tag_handle   = '!' +let s:c_tag_handle = '\%('.s:c_named_tag_handle. +            \         '\|'.s:c_secondary_tag_handle. +            \         '\|'.s:c_primary_tag_handle.'\)' +let s:c_ns_shorthand_tag = s:c_tag_handle . s:ns_tag_char.'\+' +let s:c_non_specific_tag = '!' +let s:c_ns_tag_property = s:c_verbatim_tag. +            \        '\|'.s:c_ns_shorthand_tag. +            \        '\|'.s:c_non_specific_tag + +let s:c_ns_anchor_name = s:c_ns_anchor_char.'\+' +let s:c_ns_anchor_property =  '&'.s:c_ns_anchor_name +let s:c_ns_alias_node      = '\*'.s:c_ns_anchor_name + +let s:ns_directive_name = s:ns_char.'\+' + +let s:ns_local_tag_prefix  = '!'.s:ns_uri_char.'*' +let s:ns_global_tag_prefix = s:ns_tag_char.s:ns_uri_char.'*' +let s:ns_tag_prefix = s:ns_local_tag_prefix. +            \    '\|'.s:ns_global_tag_prefix + +let s:ns_plain_safe_out = s:ns_char +let s:ns_plain_safe_in  = '\%('.s:c_flow_indicator.'\@!'.s:ns_char.'\)' + +let s:ns_plain_safe_in = substitute(s:ns_plain_safe_in, '\V\C\\%('.s:_collection.'\\@!'.s:_neg_collection.'\\)', '[^\1\2]', '') +let s:ns_plain_safe_in_without_colhash = substitute(s:ns_plain_safe_in, '\V\C'.s:_neg_collection, '[^\1:#]', '') +let s:ns_plain_safe_out_without_colhash = substitute(s:ns_plain_safe_out, '\V\C'.s:_neg_collection, '[^\1:#]', '') + +let s:ns_plain_first_in  = '\%('.s:ns_char_without_c_indicator.'\|[?:\-]\%('.s:ns_plain_safe_in.'\)\@=\)' +let s:ns_plain_first_out = '\%('.s:ns_char_without_c_indicator.'\|[?:\-]\%('.s:ns_plain_safe_out.'\)\@=\)' + +let s:ns_plain_char_in  = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_in.'\|'.s:ns_plain_safe_in_without_colhash.'\)' +let s:ns_plain_char_out = '\%('.s:ns_char.'#\|:'.s:ns_plain_safe_out.'\|'.s:ns_plain_safe_out_without_colhash.'\)' + +let s:ns_plain_out = s:ns_plain_first_out . s:ns_plain_char_out.'*' +let s:ns_plain_in  = s:ns_plain_first_in  . s:ns_plain_char_in.'*' + + +syn keyword yamlTodo            contained TODO FIXME XXX NOTE + +syn region  yamlComment         display oneline start='\%\(^\|\s\)#' end='$' +            \                   contains=yamlTodo + +execute 'syn region yamlDirective oneline start='.string('^\ze%'.s:ns_directive_name.'\s\+').' '. +            \                            'end="$" '. +            \                            'contains=yamlTAGDirective,'. +            \                                     'yamlYAMLDirective,'. +            \                                     'yamlReservedDirective '. +            \                            'keepend' + +syn match yamlTAGDirective '%TAG\s\+' contained nextgroup=yamlTagHandle +execute 'syn match yamlTagHandle contained nextgroup=yamlTagPrefix '.string(s:c_tag_handle.'\s\+') +execute 'syn match yamlTagPrefix contained nextgroup=yamlComment ' . string(s:ns_tag_prefix) + +syn match yamlYAMLDirective '%YAML\s\+'  contained nextgroup=yamlYAMLVersion +syn match yamlYAMLVersion   '\d\+\.\d\+' contained nextgroup=yamlComment + +execute 'syn match yamlReservedDirective contained nextgroup=yamlComment '. +            \string('%\%(\%(TAG\|YAML\)\s\)\@!'.s:ns_directive_name) + +syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start='"' skip='\\"' end='"' +            \ contains=yamlEscape +            \ nextgroup=yamlKeyValueDelimiter +syn region yamlFlowString matchgroup=yamlFlowStringDelimiter start="'" skip="''"  end="'" +            \ contains=yamlSingleEscape +            \ nextgroup=yamlKeyValueDelimiter +syn match  yamlEscape contained '\\\%([\\"abefnrtv\^0_ NLP\n]\|x\x\x\|u\x\{4}\|U\x\{8}\)' +syn match  yamlSingleEscape contained "''" + +syn match yamlBlockScalarHeader contained '\s\+\zs[|>]\%([+-]\=[1-9]\|[1-9]\=[+-]\)\=' + +syn cluster yamlConstant contains=yamlBool,yamlNull + +syn cluster yamlFlow contains=yamlFlowString,yamlFlowMapping,yamlFlowCollection +syn cluster yamlFlow      add=yamlFlowMappingKey,yamlFlowMappingMerge +syn cluster yamlFlow      add=@yamlConstant,yamlPlainScalar,yamlFloat +syn cluster yamlFlow      add=yamlTimestamp,yamlInteger,yamlMappingKeyStart +syn cluster yamlFlow      add=yamlComment +syn region yamlFlowMapping    matchgroup=yamlFlowIndicator start='{' end='}' contains=@yamlFlow +syn region yamlFlowCollection matchgroup=yamlFlowIndicator start='\[' end='\]' contains=@yamlFlow + +execute 'syn match yamlPlainScalar /'.s:ns_plain_out.'/' +execute 'syn match yamlPlainScalar contained /'.s:ns_plain_in.'/' + +syn match yamlMappingKeyStart '?\ze\s' +syn match yamlMappingKeyStart '?' contained + +execute 'syn match yamlFlowMappingKey /\%#=1'.s:ns_plain_in.'\%(\s\+'.s:ns_plain_in.'\)*\ze\s*:/ contained '. +            \'nextgroup=yamlKeyValueDelimiter' +syn match yamlFlowMappingMerge /<<\ze\s*:/ contained nextgroup=yamlKeyValueDelimiter + +syn match yamlBlockCollectionItemStart '^\s*\zs-\%(\s\+-\)*\s' nextgroup=yamlBlockMappingKey,yamlBlockMappingMerge +" Use the old regexp engine, the NFA engine doesn't like all the \@ items. +execute 'syn match yamlBlockMappingKey /\%#=1^\s*\zs'.s:ns_plain_out.'\%(\s\+'.s:ns_plain_out.'\)*\ze\s*:\%(\s\|$\)/ '. +            \'nextgroup=yamlKeyValueDelimiter' +execute 'syn match yamlBlockMappingKey /\%#=1\s*\zs'.s:ns_plain_out.'\%(\s\+'.s:ns_plain_out.'\)*\ze\s*:\%(\s\|$\)/ contained '. +            \'nextgroup=yamlKeyValueDelimiter' +syn match yamlBlockMappingMerge /^\s*\zs<<\ze:\%(\s\|$\)/ nextgroup=yamlKeyValueDelimiter +syn match yamlBlockMappingMerge /<<\ze\s*:\%(\s\|$\)/ nextgroup=yamlKeyValueDelimiter contained + +syn match   yamlKeyValueDelimiter /\s*:/ contained + +syn cluster yamlScalarWithSpecials contains=yamlPlainScalar,yamlBlockMappingKey,yamlFlowMappingKey + +let s:_bounder = s:SimplifyToAssumeAllPrintable('\%([[\]{}, \t]\@!\p\)') +if b:yaml_schema is# 'json' +    syn keyword yamlNull null contained containedin=@yamlScalarWithSpecials +    syn keyword yamlBool true false +    exe 'syn match   yamlInteger /'.s:_bounder.'\@1<!\%(0\|-\=[1-9][0-9]*\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' +    exe 'syn match   yamlFloat   /'.s:_bounder.'\@1<!\%(-\=[1-9][0-9]*\%(\.[0-9]*\)\=\(e[-+]\=[0-9]\+\)\=\|0\|-\=\.inf\|\.nan\)'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' +elseif b:yaml_schema is# 'core' +    syn keyword yamlNull null Null NULL contained containedin=@yamlScalarWithSpecials +    syn keyword yamlBool true True TRUE false False FALSE contained containedin=@yamlScalarWithSpecials +    exe 'syn match   yamlNull /'.s:_bounder.'\@1<!\~'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' +    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' +    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' +elseif b:yaml_schema is# 'pyyaml' +    syn keyword yamlNull null Null NULL contained containedin=@yamlScalarWithSpecials +    syn keyword yamlBool true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF contained containedin=@yamlScalarWithSpecials +    exe 'syn match   yamlNull /'.s:_bounder.'\@1<!\~'.s:_bounder.'\@!/ contained containedin=@yamlScalarWithSpecials' +    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' +    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' +    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' +elseif b:yaml_schema is# 'failsafe' +    " Nothing +endif +unlet s:_bounder + + +execute 'syn match yamlNodeTag '.string(s:c_ns_tag_property) +execute 'syn match yamlAnchor  '.string(s:c_ns_anchor_property) +execute 'syn match yamlAlias   '.string(s:c_ns_alias_node) + +syn match yamlDocumentStart '^---\ze\%(\s\|$\)' +syn match yamlDocumentEnd   '^\.\.\.\ze\%(\s\|$\)' + +hi def link yamlTodo                     Todo +hi def link yamlComment                  Comment + +hi def link yamlDocumentStart            PreProc +hi def link yamlDocumentEnd              PreProc + +hi def link yamlDirectiveName            Keyword + +hi def link yamlTAGDirective             yamlDirectiveName +hi def link yamlTagHandle                String +hi def link yamlTagPrefix                String + +hi def link yamlYAMLDirective            yamlDirectiveName +hi def link yamlReservedDirective        Error +hi def link yamlYAMLVersion              Number + +hi def link yamlString                   String +hi def link yamlFlowString               yamlString +hi def link yamlFlowStringDelimiter      yamlString +hi def link yamlEscape                   SpecialChar +hi def link yamlSingleEscape             SpecialChar + +hi def link yamlBlockCollectionItemStart Label +hi def link yamlBlockMappingKey          Identifier +hi def link yamlBlockMappingMerge        Special + +hi def link yamlFlowMappingKey           Identifier +hi def link yamlFlowMappingMerge         Special + +hi def link yamlMappingKeyStart          Special +hi def link yamlFlowIndicator            Special +hi def link yamlKeyValueDelimiter        Special + +hi def link yamlConstant                 Constant + +hi def link yamlNull                     yamlConstant +hi def link yamlBool                     yamlConstant + +hi def link yamlAnchor                   Type +hi def link yamlAlias                    Type +hi def link yamlNodeTag                  Type + +hi def link yamlInteger                  Number +hi def link yamlFloat                    Float +hi def link yamlTimestamp                Number + +let b:current_syntax = "yaml" + +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 +unlet s:_collection s:_neg_collection +delfunction s:SimplifyAdjacentCollections +delfunction s:SimplifyToAssumeAllPrintable + +let &cpo = s:cpo_save +unlet s:cpo_save + +endif | 
