Browse files

vim: several improvements + cleanup

 * added highlighting for different type of keywords:
   * if/else
   * undef
   * puppet function names
   * parameters passed to "ensure"
   * unquoted digits

 * fixed regexps to match resources containing "::", "-" and "_"

 * handled escaped variables (variable which don't belong to puppet)

 * removed unused definitions and added comments
  • Loading branch information...
mfournier committed Jun 8, 2009
1 parent 721ca7a commit 58fdf49cad233629772ef410cfe995a3c1ca459c
Showing with 38 additions and 20 deletions.
  1. +38 −20 syntax/puppet.vim
@@ -16,42 +16,61 @@ elseif exists("b:current_syntax")
+" match class/definition/node declarations
syn region puppetDefine start="^\s*\(class\|define\|node\)" end="{" contains=puppetDefType,puppetDefName,puppetDefArguments
syn keyword puppetDefType class define node inherits contained
-syn keyword puppetInherits inherits contained
syn region puppetDefArguments start="(" end=")" contains=puppetArgument
syn match puppetArgument "\w\+" contained
syn match puppetArgument "\$\w\+" contained
syn match puppetArgument "'[^']+'" contained
syn match puppetArgument '"[^"]+"' contained
syn match puppetDefName "\w\+" contained
-syn match puppetInstance "\w\+\s*{" contains=puppetTypeBrace,puppetTypeName,puppetTypeDefault
-syn match puppetTypeBrace "{" 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
+syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*[[{]" contains=puppetTypeName,puppetTypeDefault
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
+" match 'foo' in 'foo => "bar"'
+syn match puppetParam "\w\+\s*[=+]>" contains=puppetParamName
syn match puppetParamName "\w\+" contained
+" 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 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
+syn keyword puppetFunction debug info notice warning err alert emerg crit
+syn keyword puppetFunction sprintf template fail tagged include generate search file tag versioncmp fqdn_rand realize split defined regsubst sha1 inline_template
syn match puppetVariable "$\w\+"
syn match puppetVariable "${\w\+}"
-syn match puppetParen "("
-syn match puppetParen ")"
-syn match puppetBrace "{"
-syn match puppetBrace "}"
+" 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=+"+ skip=+\\\\\|\\"+ end=+"+ contains=puppetVariable
+syn region puppetString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=puppetVariable,puppetNotVariable
+syn match puppetNotVariable "\\$\w\+" contained
+syn match puppetNotVariable "\\${\w\+}" contained
-syn keyword puppetBoolean true false
syn keyword puppetKeyword import inherits include
-syn keyword puppetControl case default
+syn keyword puppetControl case default if else
+syn keyword puppetSpecial true false undef
" comments last overriding everything else
syn match puppetComment "\s*#.*$" contains=puppetTodo
syn region puppetComment start="/\*" end="\*/" contains=puppetTodo extend
-syn keyword puppetTodo TODO NOTE FIXME XXX contained
+syn keyword puppetTodo TODO NOTE FIXME XXX BUG HACK contained
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
@@ -65,25 +84,24 @@ if version >= 508 || !exists("did_puppet_syn_inits")
HiLink puppetVariable Identifier
- HiLink puppetBoolean Boolean
HiLink puppetType Identifier
- HiLink puppetDefault Identifier
HiLink puppetKeyword Define
- HiLink puppetTypeDefs Define
HiLink puppetComment Comment
HiLink puppetString String
+ HiLink puppetParamKeyword String
+ HiLink puppetParamDigits String
+ HiLink puppetNotVariable String
+ HiLink puppetParamSpecial Special
+ HiLink puppetSpecial Special
HiLink puppetTodo Todo
-" HiLink puppetBrace Delimiter
-" HiLink puppetTypeBrace Delimiter
-" HiLink puppetParen Delimiter
- HiLink puppetDelimiter Delimiter
HiLink puppetControl Statement
HiLink puppetDefType Define
HiLink puppetDefName Type
HiLink puppetTypeName Statement
HiLink puppetTypeDefault Type
HiLink puppetParamName Identifier
HiLink puppetArgument Identifier
+ HiLink puppetFunction Function
delcommand HiLink

0 comments on commit 58fdf49

Please sign in to comment.