From 933e42ea1f2d615c8ce5aa6daa2994e6369de3cf Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Wed, 4 Sep 2019 16:04:21 +0200 Subject: Change provider for puppet, closes #424 --- README.md | 2 +- after/ftplugin/puppet.vim | 13 +- autoload/puppet/align.vim | 72 ++++++ autoload/puppet/ctags.vim | 40 ++++ autoload/puppet/format.vim | 61 +++++ build | 2 +- ftdetect/polyglot.vim | 2 +- ftplugin/puppet_tagbar.vim | 48 ++++ indent/puppet.vim | 60 ++++- syntax/puppet.vim | 584 ++++++++++++--------------------------------- 10 files changed, 438 insertions(+), 446 deletions(-) create mode 100644 autoload/puppet/align.vim create mode 100644 autoload/puppet/ctags.vim create mode 100644 autoload/puppet/format.vim create mode 100644 ftplugin/puppet_tagbar.vim diff --git a/README.md b/README.md index c73aa1dd..019ae44e 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ If you need full functionality of any plugin, please use it directly with your p - [powershell](https://github.com/PProvost/vim-ps1) (syntax, indent, ftplugin) - [protobuf](https://github.com/uarun/vim-protobuf) (syntax, indent) - [pug](https://github.com/digitaltoad/vim-pug) (syntax, indent, ftplugin) -- [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin) +- [puppet](https://github.com/rodjek/vim-puppet) (syntax, indent, autoload, ftplugin) - [purescript](https://github.com/purescript-contrib/purescript-vim) (syntax, indent, ftplugin) - [python-compiler](https://github.com/aliev/vim-compiler-python) (compiler, autoload) - [python-indent](https://github.com/Vimjas/vim-python-pep8-indent) (indent) diff --git a/after/ftplugin/puppet.vim b/after/ftplugin/puppet.vim index 1265038b..934e4b03 100644 --- a/after/ftplugin/puppet.vim +++ b/after/ftplugin/puppet.vim @@ -6,15 +6,6 @@ if !exists('g:puppet_align_hashes') let g:puppet_align_hashes = 1 endif -if g:puppet_align_hashes && exists(':Tabularize') - inoremap > >:call puppetalign()a - function! s:puppetalign() - let p = '^\s*\w+\s*[=+]>.*$' - let column = strlen(substitute(getline('.')[0:col('.')],'\([^=]\|=[^>]\)','','g')) - let position = strlen(matchstr(getline('.')[0:col('.')],'.*=>\s*\zs.*')) - Tabularize /=>/l1 - normal! 0 - echo repeat('\([^=]\|=[^>]\)*=>',column).'\s\{-\}'.repeat('.',position) - call search(repeat('\([^=]\|=[^>]\)*=>',column).'\s\{-\}'.repeat('.',position),'ce',line('.')) - endfunction +if g:puppet_align_hashes + inoremap => =>:call puppet#align#AlignHashrockets()$a endif diff --git a/autoload/puppet/align.vim b/autoload/puppet/align.vim new file mode 100644 index 00000000..54a57599 --- /dev/null +++ b/autoload/puppet/align.vim @@ -0,0 +1,72 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'puppet') != -1 + finish +endif + +function! puppet#align#IndentLevel(lnum) + return indent(a:lnum) / &shiftwidth +endfunction + +function! puppet#align#LinesInBlock(lnum) + let lines = [] + let indent_level = puppet#align#IndentLevel(a:lnum) + + let marker = a:lnum - 1 + while marker >= 1 + let line_text = getline(marker) + let line_indent = puppet#align#IndentLevel(marker) + + if line_text =~? '\v\S' + if line_indent < indent_level + break + elseif line_indent == indent_level + call add(lines, marker) + endif + endif + + let marker -= 1 + endwhile + + let marker = a:lnum + while marker <= line('$') + let line_text = getline(marker) + let line_indent = puppet#align#IndentLevel(marker) + + if line_text =~? '\v\S' + if line_indent < indent_level + break + elseif line_indent == indent_level + call add(lines, marker) + endif + endif + + let marker += 1 + endwhile + + return lines +endfunction + +"" +" Format lines with hashrocket (=>) +" @param a:1 a line where function should search for first hashrocket +" expression, if param is not given, line with active cursor is used +function! puppet#align#AlignHashrockets(...) abort + let l:lnum = get(a:, 1, line('.')) + let lines_in_block = puppet#align#LinesInBlock(l:lnum) + let max_left_len = 0 + let indent_str = printf('%' . indent(l:lnum) . 's', '') + + for line_num in lines_in_block + let data = matchlist(getline(line_num), '^\s*\(.\{-}\S\)\s*=>\s*\(.*\)$') + if !empty(data) + let max_left_len = max([max_left_len, strlen(data[1])]) + endif + endfor + + for line_num in lines_in_block + let data = matchlist(getline(line_num), '^\s*\(.\{-}\S\)\s*=>\s*\(.*\)$') + if !empty(data) + let new_line = printf('%s%-' . max_left_len . 's => %s', indent_str, data[1], data[2]) + call setline(line_num, new_line) + endif + endfor +endfunction diff --git a/autoload/puppet/ctags.vim b/autoload/puppet/ctags.vim new file mode 100644 index 00000000..5547f42e --- /dev/null +++ b/autoload/puppet/ctags.vim @@ -0,0 +1,40 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'puppet') != -1 + finish +endif + + +if !exists('s:ctags_type') + let s:ctags_type = 0 +endif + +let s:ctags_options_dir = expand(':p:h:h:h') . '/ctags/' + +" Return full path to option file for ctags application +function! puppet#ctags#OptionFile() + + if puppet#ctags#Type() == 'universal' + let l:ctags_options = 'puppet_u.ctags' + else + let l:ctags_options = 'puppet.ctags' + endif + return s:ctags_options_dir . l:ctags_options +endfunction + +" Return type of installed ctags application, +" can be 'universal' or 'exuberant' +function! puppet#ctags#Type() + + if !s:ctags_type + let l:version = system('ctags --version') + if l:version =~ 'Universal Ctags' + let s:ctags_type = 'universal' + elseif l:version =~ 'Exuberant Ctags' + let s:ctags_type = 'exuberant' + else + echoerr 'Unknown version of Ctags' + endif + endif + + return s:ctags_type +endfunction + diff --git a/autoload/puppet/format.vim b/autoload/puppet/format.vim new file mode 100644 index 00000000..f60bd782 --- /dev/null +++ b/autoload/puppet/format.vim @@ -0,0 +1,61 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'puppet') != -1 + finish +endif + +" +" Simple format using puppet's l:indents and align hashrockets function +function! puppet#format#Format() abort + let l:start_lnum = v:lnum + let l:end_lnum = v:lnum + v:count - 1 + call puppet#format#Indention(l:start_lnum, l:end_lnum) + call puppet#format#Hashrocket(l:start_lnum, l:end_lnum) + call puppet#format#Fallback(l:start_lnum, l:end_lnum) +endfunction + +"" +" Format hashrockets expressions in every line in range start_lnum and +" end_lnum, both ends included +" +" TODO way of using AlignHashrockets function is ineffective, because it +" formats same lines again and again, find better way to do it +function! puppet#format#Hashrocket(start_lnum, end_lnum) abort + let l:lnum = a:start_lnum + while l:lnum <= a:end_lnum + call puppet#align#AlignHashrockets(l:lnum) + let l:lnum += 1 + endwhile +endfunction + +"" +" Format indention in every line in range start_lnum and end_lnum, both ends +" included +" +function! puppet#format#Indention(start_lnum, end_lnum) abort + execute 'normal! ' . a:start_lnum . 'gg=' . a:end_lnum . 'gg' +endfunction + +"" +" Use internal vim default autoformat method for every line in range, only +" lines which exeed &widthline are formated +" +function! puppet#format#Fallback(start_lnum, end_lnum) abort + " I'm using it to check if autoformat expand range + let l:eof_lnum = line('$') + let l:lnum = a:start_lnum + let l:end_lnum = a:end_lnum + while l:lnum <= l:end_lnum + if strlen(getline(l:lnum)) > &textwidth + call cursor(l:lnum) + execute 'normal! gww' + " Checking if autoformat expand number of lines if yes, I will extend + " range too + if l:eof_lnum < line('$') + let l:end_lnum += line('$') - l:eof_lnum + let l:eof_lnum = line('$') + endif + endif + let l:lnum += 1 + endwhile + +endfunction + diff --git a/build b/build index d7945c50..1361957d 100755 --- a/build +++ b/build @@ -247,7 +247,7 @@ PACKS=" powershell:PProvost/vim-ps1 protobuf:uarun/vim-protobuf pug:digitaltoad/vim-pug - puppet:voxpupuli/vim-puppet + puppet:rodjek/vim-puppet purescript:purescript-contrib/purescript-vim python-compiler:aliev/vim-compiler-python python-indent:Vimjas/vim-python-pep8-indent diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 2e0ffc69..61b9baba 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -1038,7 +1038,7 @@ endif if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'puppet') == -1 augroup filetypedetect - " puppet, from puppet.vim in voxpupuli/vim-puppet + " puppet, from puppet.vim in rodjek/vim-puppet au! BufRead,BufNewFile *.pp setfiletype puppet au! BufRead,BufNewFile Puppetfile setfiletype ruby augroup end diff --git a/ftplugin/puppet_tagbar.vim b/ftplugin/puppet_tagbar.vim new file mode 100644 index 00000000..b607ccb0 --- /dev/null +++ b/ftplugin/puppet_tagbar.vim @@ -0,0 +1,48 @@ +if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'puppet') != -1 + finish +endif + +" Puppet set up for Tagbar plugin +" (https://github.com/majutsushi/tagbar). + +if !exists(':Tagbar') + finish +endif + +let g:tagbar_type_puppet = { + \ 'ctagstype': 'puppet', + \ 'kinds': [ + \ 'c:Classes', + \ 's:Sites', + \ 'n:Nodes', + \ 'v:Variables', + \ 'i:Includes', + \ 'd:Definitions', + \ 'r:Resources', + \ 'f:Defaults', + \ 't:Types', + \ 'u:Functions', + \], +\} + +if puppet#ctags#Type() == 'universal' + " There no sense to split objects by colon + let g:tagbar_type_puppet.sro = '__' + let g:tagbar_type_puppet.kind2scope = { + \ 'd': 'definition', + \ 'c': 'class', + \ 'r': 'resource', + \ 'i': 'include', + \ 'v': 'variable', + \} + let g:tagbar_type_puppet.scope2kind = { + \ 'definition' : 'd', + \ 'class' : 'c', + \ 'resource' : 'r', + \ 'include' : 'i', + \ 'variable' : 'v', + \} +endif + +let g:tagbar_type_puppet.deffile = puppet#ctags#OptionFile() + diff --git a/indent/puppet.vim b/indent/puppet.vim index 31a4a505..977e8606 100644 --- a/indent/puppet.vim +++ b/indent/puppet.vim @@ -16,6 +16,7 @@ let b:did_indent = 1 setlocal autoindent smartindent setlocal indentexpr=GetPuppetIndent() setlocal indentkeys+=0],0) +setlocal formatexpr=puppet#format#Format() if exists("*GetPuppetIndent") finish @@ -33,7 +34,7 @@ function! s:PartOfInclude(lnum) if line !~ ',$' break endif - if line =~ '^\s*include\s\+[^,]\+,$' + if line =~ '^\s*include\s\+[^,]\+,$' && line !~ '[=>]>' return 1 endif endwhile @@ -42,24 +43,70 @@ endfunction function! s:OpenBrace(lnum) call cursor(a:lnum, 1) - return searchpair('{\|\[\|(', '', '}\|\]\|)', 'nbW') + return searchpair('{\|\[\|(', '', '}\|\]\|)', 'nbW', + \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "comment\\|string"') endfunction -function! GetPuppetIndent() - let pnum = prevnonblank(v:lnum - 1) +function! s:InsideMultilineString(lnum) + return synIDattr(synID(a:lnum, 1, 0), 'name') =~? 'string' +endfunction + +function! s:PrevNonMultilineString(lnum) + let l:lnum = a:lnum + while l:lnum > 0 && s:InsideMultilineString(lnum) + let l:lnum = l:lnum - 1 + endwhile + + return l:lnum +endfunction + +"" +" Get indent number for line, line can be given as params, otherwise function +" use line where cursor is +" @param a:1 (optional) line number in current buffer +" @return integer +function! GetPuppetIndent(...) + let l:lnum = get(a:, 1, v:lnum) + + let pnum = prevnonblank(l:lnum - 1) if pnum == 0 return 0 endif - let line = getline(v:lnum) + let line = getline(l:lnum) let pline = getline(pnum) let ind = indent(pnum) + " Avoid cases of closing braces or parens on the current line: returning + " the same indent here would be premature since for that particular case + " we want to instead get the indent level of the matching opening brace or + " parenthenses. + if pline =~ '^\s*#' && line !~ '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)' + return ind + endif + + " We are inside a multi-line string: if we interfere with indentation here + " we're actually changing the contents of of the string! + if s:InsideMultilineString(l:lnum) + return indent(l:lnum) + endif + + " Previous line was inside a multi-line string: we've lost the indent + " level. We need to find this value from the last line that was not inside + " of a multi-line string to restore proper alignment. + if s:InsideMultilineString(pnum) + if pnum - 1 == 0 + return ind + endif + + let ind = indent(s:PrevNonMultilineString(pnum - 1)) + endif + if pline =~ '\({\|\[\|(\|:\)\s*\(#.*\)\?$' let ind += &sw elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*' let ind -= &sw - elseif pline =~ '^\s*include\s\+.*,$' + elseif pline =~ '^\s*include\s\+.*,$' && pline !~ '[=+]>' let ind += &sw endif @@ -76,7 +123,6 @@ function! GetPuppetIndent() if line =~ '^\s*}\s*els\(e\|if\).*{\s*$' let ind -= &sw endif - " Don't indent resources that are one after another with a ->(ordering arrow) " file {'somefile': " ... diff --git a/syntax/puppet.vim b/syntax/puppet.vim index 3cc1746e..44f2f839 100644 --- a/syntax/puppet.vim +++ b/syntax/puppet.vim @@ -2,439 +2,173 @@ if exists('g:polyglot_disabled') && index(g:polyglot_disabled, 'puppet') != -1 finish endif -" Language: Puppet -" Maintainer: Voxpupuli -" URL: https://github.com/voxpupuli/vim-puppet +" puppet syntax file +" Filename: puppet.vim +" Language: puppet configuration file +" Maintainer: Luke Kanies +" URL: +" Last Change: +" Version: " -" Thanks to Doug Kearns who maintains the vim syntax file for Ruby. Many constructs, including interpolation -" and heredoc was copied from ruby and then modified to comply with Puppet syntax. -" Prelude {{{1 -if exists("b:current_syntax") +" Copied from the cfengine, ruby, and perl syntax files +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") finish endif -" this file uses line continuations -let s:cpo_sav = &cpo -set cpo&vim - -syn cluster puppetNotTop contains=@puppetExtendedStringSpecial,@puppetRegexpSpecial,@puppetDeclaration,puppetConditional,puppetExceptional,puppetMethodExceptional,puppetTodo - -syn match puppetSpaceError display excludenl "\s\+$" -syn match puppetSpaceError display " \+\t"me=e-1 - -" one character operators -syn match puppetOperator "[=><+/*%!.|@:,;?~-]" - -" two character operators -syn match puppetOperator "+=\|-=\|==\|!=\|=\~\|!\~\|>=\|<=\|<-\|<\~\|=>\|+>\|->\|\~>\|<<\||>\|@@" - -" three character operators -syn match puppetOperator "<<|\||>>" - -syn region puppetBracketOperator matchgroup=puppetDelimiter start="\[\s*" end="\s*]" contains=ALLBUT,@puppetNotTop -syn region puppetBraceOperator matchgroup=puppetDelimiter start="{\s*" end="\s*}" contains=ALLBUT,@puppetNotTop -syn region puppetParenOperator matchgroup=puppetDelimiter start="(\s*" end="\s*)" contains=ALLBUT,@puppetNotTop - -" Expression Substitution and Backslash Notation {{{1 -syn match puppetStringEscape "\\\\\|\\[abefnrstv]\|\\\o\{1,3}\|\\x\x\{1,2}" contained display -syn match puppetStringEscape "\%(\\M-\\C-\|\\C-\\M-\|\\M-\\c\|\\c\\M-\|\\c\|\\C-\|\\M-\)\%(\\\o\{1,3}\|\\x\x\{1,2}\|\\\=\S\)" contained display -syn match puppetQuoteEscape "\\[\\']" contained display - -syn region puppetInterpolation matchgroup=puppetInterpolationDelimiter start="${" end="}" contained contains=ALLBUT,@puppetNotTop -syn match puppetInterpolation "$\w\+" display contained contains=puppetInterpolationDelimiter,puppetVariable -syn match puppetInterpolationDelimiter "$\ze\$\w\+" display contained -syn match puppetInterpolation "$\$\%(-\w\|\W\)" display contained contains=puppetInterpolationDelimiter,puppetVariable,puppetInvalidVariable -syn match puppetInterpolationDelimiter "$\ze\$\%(-\w\|\W\)" display contained -syn region puppetNoInterpolation start="\\${" end="}" contained -syn match puppetNoInterpolation "\\${" display contained -syn match puppetNoInterpolation "\\$\w\+" display contained - -syn match puppetDelimiterEscape "\\[(<{\[)>}\]]" transparent display contained contains=NONE - -syn region puppetNestedParentheses start="(" skip="\\\\\|\\)" matchgroup=puppetString end=")" transparent contained -syn region puppetNestedCurlyBraces start="{" skip="\\\\\|\\}" matchgroup=puppetString end="}" transparent contained -syn region puppetNestedAngleBrackets start="<" skip="\\\\\|\\>" matchgroup=puppetString end=">" transparent contained -syn region puppetNestedSquareBrackets start="\[" skip="\\\\\|\\\]" matchgroup=puppetString end="\]" transparent contained - -" Regular Expression Metacharacters {{{1 -" These are mostly Oniguruma ready -syn region puppetRegexpComment matchgroup=puppetRegexpSpecial start="(?#" skip="\\)" end=")" contained -syn region puppetRegexpParens matchgroup=puppetRegexpSpecial start="(\(?:\|?<\=[=!]\|?>\|?<[a-z_]\w*>\|?[imx]*-[imx]*:\=\|\%(?#\)\@!\)" skip="\\)" end=")" contained transparent contains=@puppetRegexpSpecial -syn region puppetRegexpBrackets matchgroup=puppetRegexpCharClass start="\[\^\=" skip="\\\]" end="\]" contained transparent contains=puppetStringEscape,puppetRegexpEscape,puppetRegexpCharClass oneline -syn match puppetRegexpCharClass "\\[DdHhSsWw]" contained display -syn match puppetRegexpCharClass "\[:\^\=\%(alnum\|alpha\|ascii\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|xdigit\):\]" contained -syn match puppetRegexpEscape "\\[].*?+^$|\\/(){}[]" contained -syn match puppetRegexpQuantifier "[*?+][?+]\=" contained display -syn match puppetRegexpQuantifier "{\d\+\%(,\d*\)\=}?\=" contained display -syn match puppetRegexpAnchor "[$^]\|\\[ABbGZz]" contained display -syn match puppetRegexpDot "\." contained display -syn match puppetRegexpSpecial "|" contained display -syn match puppetRegexpSpecial "\\[1-9]\d\=\d\@!" contained display -syn match puppetRegexpSpecial "\\k<\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\=>" contained display -syn match puppetRegexpSpecial "\\k'\%([a-z_]\w*\|-\=\d\+\)\%([+-]\d\+\)\='" contained display -syn match puppetRegexpSpecial "\\g<\%([a-z_]\w*\|-\=\d\+\)>" contained display -syn match puppetRegexpSpecial "\\g'\%([a-z_]\w*\|-\=\d\+\)'" contained display - -syn cluster puppetStringSpecial contains=puppetInterpolation,puppetNoInterpolation,puppetStringEscape -syn cluster puppetExtendedStringSpecial contains=@puppetStringSpecial,puppetNestedParentheses,puppetNestedCurlyBraces,puppetNestedAngleBrackets,puppetNestedSquareBrackets -syn cluster puppetRegexpSpecial contains=puppetRegexpSpecial,puppetRegexpEscape,puppetRegexpBrackets,puppetRegexpCharClass,puppetRegexpDot,puppetRegexpQuantifier,puppetRegexpAnchor,puppetRegexpParens,puppetRegexpComment - -syn match puppetInteger "\%(\%(\w\|[]})\"']\s*\)\@" display -syn match puppetInteger "\%(\%(\w\|[]})\"']\s*\)\@" display -syn match puppetInteger "\%(\%(\w\|[]})\"']\s*\)\@" display -syn match puppetInteger "\%(\%(\w\|[]})\"']\s*\)\@" display -syn match puppetFloat "\%(\%(\w\|[]})\"']\s*\)\@" display -syn match puppetFloat "\%(\%(\w\|[]})\"']\s*\)\@" display - -syn match puppetVariable "$\%(::\)\=\w\+\%(::\w\+\)*" display -syn match puppetName "\%(::\)\=[a-z]\w*\%(::[a-z]\w*\)*" display -syn match puppetType "\%(::\)\=[A-Z]\w*\%(::[A-Z]\w*\)*" display -syn match puppetWord "\%(\%(::\)\=\%(_[\w-]*\w\+\)\|\%([a-z]\%(\w*-\)\+\w\+\)\)\+" display - -" bad name containing combinations of segment starting with lower case and segement starting with upper case (or vice versa) -syn match puppetNameBad "\%(::\)\=\%(\w\+::\)*\%(\%([a-z]\w*::[A-Z]\w*\)\|\%([A-Z]\w*::[a-z]\w*\)\)\%(::\w\+\)*" display -syn cluster puppetNameOrType contains=puppetVariable,puppetName,puppetType,puppetWord,puppetNameBad - -syn keyword puppetControl case and or in -syn keyword puppetKeyword class define inherits node undef function type attr private -syn keyword puppetKeyword application consumes produces site -syn keyword puppetKeyword present absent purged latest installed running stopped mounted unmounted role configured file directory link on_failure contained -syn keyword puppetConstant default undef -syn keyword puppetConditional if else elsif unless -syn keyword puppetBoolean true false - -" Core functions -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" -syn match puppetFunction "\" - -" Stdlib functions -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" -syn match puppetStdLibFunction "\" - -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" - -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" -syn match puppetType "\" - -" Normal String {{{1 -syn region puppetString matchgroup=puppetStringDelimiter start="\"" end="\"" skip="\\\\\|\\\"" contains=@puppetStringSpecial -syn region puppetString matchgroup=puppetStringDelimiter start="'" end="'" skip="\\\\\|\\'" contains=puppetQuoteEscape - -" Normal Regular Expression {{{1 -syn region puppetRegexp matchgroup=puppetRegexpDelimiter start="\%(\%(^\|\<\%(and\|or\|while\|until\|unless\|if\|elsif\|when\|not\|then\|else\)\|[;\~=!|&(,{[<>?:*+-]\)\s*\)\@<=/" end="/" skip="\\\\\|\\/" contains=@puppetRegexpSpecial -syn region puppetRegexp matchgroup=puppetRegexpDelimiter start="\%(\h\k*\s\+\)\@<=/[ \t=]\@!" end="/" skip="\\\\\|\\/" contains=@puppetRegexpSpecial - -" Here Document {{{1 -syn region puppetHeredocStart matchgroup=puppetStringDelimiter start=+@(\s*\%("[^"]\+"\|\w\+\)\%(/[nrtsuL$\\]*\)\=)+ end=+$+ oneline contains=ALLBUT,@puppetNotTop - -syn region puppetString start=+@(\s*"\z([^"]\+\)"\%(/[nrtsuL$\\]*\)\=+hs=s+2 matchgroup=puppetStringDelimiter end=+^\s*|\=\s*-\=\s*\zs\z1$+ contains=puppetHeredocStart,@puppetStringSpecial keepend -syn region puppetString start=+@(\s*\z(\w\+\)\%(/[nrtsuL$\\]*\)\=+hs=s+2 matchgroup=puppetStringDelimiter end=+^\s*|\=\s*-\=\s*\zs\z1$+ contains=puppetHeredocStart keepend +" match class/definition/node declarations +syn region puppetDefine start="^\s*\(class\|define\|node\)\s" end="{" contains=puppetDefType,puppetDefName,puppetDefArguments,puppetNodeRe,@NoSpell +syn keyword puppetDefType class define node inherits contained +syn region puppetDefArguments start="(" end=")" contained contains=puppetType,puppetArgument,puppetString,puppetComment,puppetMultilineComment +syn match puppetArgument "\w\+" contained +syn match puppetArgument "\$\w\+" contained +syn match puppetArgument "'[^']+'" contained +syn match puppetArgument '"[^"]+"' contained +syn keyword puppetType Any Array Boolean Callable Catalogentry Collection Data Default Enum Float Hash Integer Numeric Optional Pattern Regexp Scalar Sensitive String Struct Tuple Type Undef Variant +syn match puppetDefName "\w\+" contained +syn match puppetNodeRe "/.*/" contained + +" match 'foo' in 'class foo { ...' +" match 'foo::bar' in 'class foo::bar { ...' +" match 'Foo::Bar' in 'Foo::Bar["..."] +"FIXME: "Foo-bar" doesn't get highlighted as expected, although "foo-bar" does. +syn match puppetInstance "[A-Za-z0-9_-]\+\(::[A-Za-z0-9_-]\+\)*\s*{" contains=puppetTypeName,puppetTypeDefault,@NoSpell +syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*[[{]" contains=puppetTypeName,puppetTypeDefault,@NoSpell +syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*<\?<|" contains=puppetTypeName,puppetTypeDefault,@NoSpell +syn match puppetTypeName "[a-z]\w*" contained +syn match puppetTypeDefault "[A-Z]\w*" contained + +syn match puppetParam "\(\w\+\|\*\)\s*\(=\|+\)>" contains=puppetTypeRArrow,puppetParamName +syn match puppetParamRArrow "\(=\|+\)>" contained +syn match puppetParamName "\(\w\+\|\*\)" contained contains=@NoSpell +syn match puppetVariable "$\(\(\(::\)\?\w\+\)\+\|{\(\(::\)\?\w\+\)\+}\)" +syn match puppetParen "(" +syn match puppetParen ")" +syn match puppetBrace "{" +syn match puppetBrace "}" +syn match puppetBrack "\[" +syn match puppetBrack "\]" +syn match puppetBrack "<|" +syn match puppetBrack "|>" + +" match 'present' in 'ensure => present' +" match '2755' in 'mode => 2755' +" don't match 'bar' in 'foo => bar' +syn match puppetParam "\w\+\s*[=+]>\s*[a-z0-9]\+" contains=puppetParamString,puppetParamName +syn match puppetParamString "[=+]>\s*\w\+" contains=puppetParamKeyword,puppetParamSpecial,puppetParamDigits contained +syn keyword puppetParamKeyword present absent purged latest installed running stopped mounted unmounted role configured file directory link on_failure contained +syn keyword puppetParamSpecial true false undef contained +syn match puppetParamDigits "[0-9]\+" + +" match 'template' in 'content => template("...")' +syn match puppetParam "\w\+\s*[=+]>\s*\w\+\s*(" contains=puppetFunction,puppetParamName +" statements +syn region puppetFunction start="^\s*\(alert\|crit\|debug\|emerg\|err\|fail\|include\|info\|notice\|realize\|require\|search\|tag\|warning\)\s*(" end=")" contained contains=puppetString +" rvalues +syn region puppetFunction start="^\s*\(defined\|file\|fqdn_rand\|generate\|inline_template\|regsubst\|sha1\|shellquote\|split\|sprintf\|tagged\|template\|versioncmp\)\s*(" end=")" contained contains=puppetString + +syn match puppetVariable "$[a-zA-Z0-9_:]\+" contains=@NoSpell +syn match puppetVariable "${[a-zA-Z0-9_:'\[\]]\+}" contains=@NoSpell + +" match anything between simple/double quotes. +" don't match variables if preceded by a backslash. +syn region puppetString start=+'+ skip=+\\\\\|\\'+ end=+'+ +syn region puppetString start=+@(\z\([^/)]*\)\(/[\\nts$uL]*\)\?)$+ end=+|-\? *\z1 *$+ +syn region puppetString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=puppetVariable,puppetNotVariable +syn region puppetString start=+@("\z\([^/)]*\)"\(/[\\nts$uL]*\)\?)$+ end=+|-\? *\z1 *$+ contains=puppetVariable,puppetNotVariable +syn match puppetNotVariable "\\$\w\+" contained +syn match puppetNotVariable "\\${\w\+}" contained + +" match keywords and control words except when used as a parameter +syn match puppetKeyword "\(\\|\\|\\|\\|\\)\(\s*=>\)\@!" +syn match puppetControl "\(\\|\\|\\|\\|\\|\\)\(\s*=>\)\@!" +syn keyword puppetSpecial true false undef + +syn match puppetClass "[A-Za-z0-9_-]\+\(::[A-Za-z0-9_-]\+\)\+" contains=@NoSpell + +" Match the Regular Expression type +" XXX: Puppet does not currently support a few features available in the +" full Ruby Regexp class, namely, interpolation, lookbehind and named +" sub-expressions. Matches for these features are included in the +" commented-out versions of puppetRegexParen and puppetRegexSubName, +" plus the supporting groups puppetRegexAngBrack and puppetRegexTick. +syn region puppetRegex start="\(?']\|" contained +"syn match puppetRegexTick +'+ contained +syn match puppetRegexOr "|" contained +"syn match puppetRegexSubName "['<][[:alnum:]]\+[>']" contains=puppetRegexAngBrack,puppetRegexTick contained +syn match puppetRegexSpecialChar "[?:imx]\|\( - -HiLink puppetRegexp puppetConstant -HiLink puppetStdLibFunction puppetFunction -HiLink puppetNoInterpolation puppetString -HiLink puppetFunction Function -HiLink puppetOperator Operator -HiLink puppetString String -HiLink puppetWord String -HiLink puppetFloat Float -HiLink puppetInteger Number -HiLink puppetBoolean Boolean -HiLink puppetName puppetIdentifier -HiLink puppetNameBad Error -HiLink puppetVariable puppetIdentifier -HiLink puppetIdentifier Identifier -HiLink puppetType Type -HiLink puppetConditional Conditional -HiLink puppetConstant Constant -HiLink puppetControl Statement -HiLink puppetKeyword Keyword -HiLink puppetStringDelimiter Delimiter -HiLink puppetDelimiter Delimiter -HiLink puppetTodo Todo -HiLink puppetComment Comment - -delcommand HiLink +" For version 5.7 and earlier: only when not done already +" For version 5.8 and later: only when an item doesn't have highlighting yet +if version >= 508 || !exists("did_puppet_syn_inits") + if version < 508 + let did_puppet_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + HiLink puppetVariable Identifier + HiLink puppetType Type + HiLink puppetKeyword Keyword + HiLink puppetComment Comment + HiLink puppetMultilineComment Comment + HiLink puppetString String + HiLink puppetRegex Constant + HiLink puppetRegexParen Delimiter + HiLink puppetRegexBrace Delimiter + HiLink puppetRegexBrack Delimiter + HiLink puppetRegexAngBrack Delimiter + HiLink puppetRegexTick Delimiter + HiLink puppetRegexOr Delimiter + HiLink puppetRegexSubName Identifier + HiLink puppetRegexSpecChar SpecialChar + HiLink puppetRegexComment Comment + HiLink puppetParamKeyword Keyword + HiLink puppetParamDigits String + HiLink puppetNotVariable String + HiLink puppetParamSpecial Boolean + HiLink puppetSpecial Special + HiLink puppetTodo Todo + HiLink puppetBrack Delimiter + HiLink puppetTypeBrack Delimiter + HiLink puppetBrace Delimiter + HiLink puppetTypeBrace Delimiter + HiLink puppetParen Delimiter + HiLink puppetDelimiter Delimiter + HiLink puppetControl Statement + HiLink puppetDefType Define + HiLink puppetDefName Type + HiLink puppetNodeRe Type + HiLink puppetTypeName Statement + HiLink puppetTypeDefault Type + HiLink puppetParamName Identifier + HiLink puppetArgument Identifier + HiLink puppetFunction Function + HiLink puppetClass Include + + delcommand HiLink +endif let b:current_syntax = "puppet" -- cgit v1.2.3