puppet.vim 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. " puppet syntax file
  2. " Filename: puppet.vim
  3. " Language: puppet configuration file
  4. " Maintainer: Luke Kanies <luke@madstop.com>
  5. " URL:
  6. " Last Change:
  7. " Version:
  8. "
  9. " Copied from the cfengine, ruby, and perl syntax files
  10. " For version 5.x: Clear all syntax items
  11. " For version 6.x: Quit when a syntax file was already loaded
  12. if version < 600
  13. syntax clear
  14. elseif exists("b:current_syntax")
  15. finish
  16. endif
  17. " match class/definition/node declarations
  18. syn region puppetDefine start="^\s*\(class\|define\|node\)\s" end="{" contains=puppetDefType,puppetDefName,puppetDefArguments,puppetNodeRe,@NoSpell
  19. syn keyword puppetDefType class define node inherits contained
  20. syn region puppetDefArguments start="(" end=")" contained contains=puppetArgument,puppetString,puppetComment,puppetMultilineComment
  21. syn match puppetArgument "\w\+" contained
  22. syn match puppetArgument "\$\w\+" contained
  23. syn match puppetArgument "'[^']+'" contained
  24. syn match puppetArgument '"[^"]+"' contained
  25. syn match puppetDefName "\w\+" contained
  26. syn match puppetNodeRe "/.*/" contained
  27. " match 'foo' in 'class foo { ...'
  28. " match 'foo::bar' in 'class foo::bar { ...'
  29. " match 'Foo::Bar' in 'Foo::Bar["..."]
  30. "FIXME: "Foo-bar" doesn't get highlighted as expected, although "foo-bar" does.
  31. syn match puppetInstance "[A-Za-z0-9_-]\+\(::[A-Za-z0-9_-]\+\)*\s*{" contains=puppetTypeName,puppetTypeDefault,@NoSpell
  32. syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*[[{]" contains=puppetTypeName,puppetTypeDefault,@NoSpell
  33. syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*<\?<|" contains=puppetTypeName,puppetTypeDefault,@NoSpell
  34. syn match puppetTypeName "[a-z]\w*" contained
  35. syn match puppetTypeDefault "[A-Z]\w*" contained
  36. syn match puppetParam "\w\+\s*\(=\|+\)>" contains=puppetTypeRArrow,puppetParamName
  37. syn match puppetParamRArrow "\(=\|+\)>" contained
  38. syn match puppetParamName "\w\+" contained contains=@NoSpell
  39. syn match puppetVariable "$\(\(\(::\)\?\w\+\)\+\|{\(\(::\)\?\w\+\)\+}\)"
  40. syn match puppetParen "("
  41. syn match puppetParen ")"
  42. syn match puppetBrace "{"
  43. syn match puppetBrace "}"
  44. syn match puppetBrack "\["
  45. syn match puppetBrack "\]"
  46. syn match puppetBrack "<|"
  47. syn match puppetBrack "|>"
  48. " match 'present' in 'ensure => present'
  49. " match '2755' in 'mode => 2755'
  50. " don't match 'bar' in 'foo => bar'
  51. syn match puppetParam "\w\+\s*[=+]>\s*[a-z0-9]\+" contains=puppetParamString,puppetParamName
  52. syn match puppetParamString "[=+]>\s*\w\+" contains=puppetParamKeyword,puppetParamSpecial,puppetParamDigits contained
  53. syn keyword puppetParamKeyword present absent purged latest installed running stopped mounted unmounted role configured file directory link contained
  54. syn keyword puppetParamSpecial true false undef contained
  55. syn match puppetParamDigits "[0-9]\+"
  56. " match 'template' in 'content => template("...")'
  57. syn match puppetParam "\w\+\s*[=+]>\s*\w\+\s*(" contains=puppetFunction,puppetParamName
  58. " statements
  59. syn region puppetFunction start="^\s*\(alert\|crit\|debug\|emerg\|err\|fail\|include\|info\|notice\|realize\|require\|search\|tag\|warning\)\s*(" end=")" contained contains=puppetString
  60. " rvalues
  61. 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
  62. syn match puppetVariable "$[a-zA-Z0-9_:]\+" contains=@NoSpell
  63. syn match puppetVariable "${[a-zA-Z0-9_:]\+}" contains=@NoSpell
  64. " match anything between simple/double quotes.
  65. " don't match variables if preceded by a backslash.
  66. syn region puppetString start=+'+ skip=+\\\\\|\\'+ end=+'+
  67. syn region puppetString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=puppetVariable,puppetNotVariable
  68. syn match puppetNotVariable "\\$\w\+" contained
  69. syn match puppetNotVariable "\\${\w\+}" contained
  70. syn keyword puppetKeyword import inherits include require contain
  71. syn keyword puppetControl case default if else elsif
  72. syn keyword puppetSpecial true false undef
  73. syn match puppetClass "[A-Za-z0-9_-]\+\(::[A-Za-z0-9_-]\+\)\+" contains=@NoSpell
  74. " Match the Regular Expression type
  75. " XXX: Puppet does not currently support a few features available in the
  76. " full Ruby Regexp class, namely, interpolation, lookbehind and named
  77. " sub-expressions. Matches for these features are included in the
  78. " commented-out versions of puppetRegexParen and puppetRegexSubName,
  79. " plus the supporting groups puppetRegexAngBrack and puppetRegexTick.
  80. syn region puppetRegex start="/" skip="\\/" end="/" contains=puppetRegexParen,puppetRegexBrace,puppetRegexOrpuppetRegexBrack,puppetRegexComment
  81. syn match puppetRegexParen "(\(?\([imx]\{0,4}:\|[=!]\)\)\?" contains=puppetRegexSpecChar,puppetRegexSubName contained
  82. "syn match puppetRegexParen "(\(?\([imxo]\{0,4}:\|['<][[:alnum:]]\+[>']\|<?[=!]\)\)\?" contains=puppetRegexSpecChar,puppetRegexSubName contained
  83. syn match puppetRegexParen ")" contained
  84. syn match puppetRegexBrace "{" contained
  85. syn match puppetRegexBrace "}" contained
  86. syn match puppetRegexBrack "\[" contained
  87. syn match puppetRegexBrack "\]" contained
  88. "syn match puppetRegexAngBrack "<" contained
  89. "syn match puppetRegexAngBrack ">" contained
  90. "syn match puppetRegexTick +'+ contained
  91. syn match puppetRegexOr "|" contained
  92. "syn match puppetRegexSubName "['<][[:alnum:]]\+[>']" contains=puppetRegexAngBrack,puppetRegexTick contained
  93. syn match puppetRegexSpecialChar "[?:imx]\|\(<?[=!]\)" contained
  94. syn region puppetRegexComment start="(?#" skip="\\)" end=")" contained
  95. " comments last overriding everything else
  96. syn match puppetComment "\s*#.*$" contains=puppetTodo,@Spell
  97. syn region puppetMultilineComment start="/\*" end="\*/" contains=puppetTodo,@Spell
  98. syn keyword puppetTodo TODO NOTE FIXME XXX BUG HACK contained
  99. syn keyword puppetTodo TODO: NOTE: FIXME: XXX: BUG: HACK: contained
  100. " Define the default highlighting.
  101. " For version 5.7 and earlier: only when not done already
  102. " For version 5.8 and later: only when an item doesn't have highlighting yet
  103. if version >= 508 || !exists("did_puppet_syn_inits")
  104. if version < 508
  105. let did_puppet_syn_inits = 1
  106. command -nargs=+ HiLink hi link <args>
  107. else
  108. command -nargs=+ HiLink hi def link <args>
  109. endif
  110. HiLink puppetVariable Identifier
  111. HiLink puppetType Identifier
  112. HiLink puppetKeyword Keyword
  113. HiLink puppetComment Comment
  114. HiLink puppetMultilineComment Comment
  115. HiLink puppetString String
  116. HiLink puppetRegex Constant
  117. HiLink puppetRegexParen Delimiter
  118. HiLink puppetRegexBrace Delimiter
  119. HiLink puppetRegexBrack Delimiter
  120. HiLink puppetRegexAngBrack Delimiter
  121. HiLink puppetRegexTick Delimiter
  122. HiLink puppetRegexOr Delimiter
  123. HiLink puppetRegexSubName Identifier
  124. HiLink puppetRegexSpecChar SpecialChar
  125. HiLink puppetRegexComment Comment
  126. HiLink puppetParamKeyword Keyword
  127. HiLink puppetParamDigits String
  128. HiLink puppetNotVariable String
  129. HiLink puppetParamSpecial Boolean
  130. HiLink puppetSpecial Special
  131. HiLink puppetTodo Todo
  132. HiLink puppetBrack Delimiter
  133. HiLink puppetTypeBrack Delimiter
  134. HiLink puppetBrace Delimiter
  135. HiLink puppetTypeBrace Delimiter
  136. HiLink puppetParen Delimiter
  137. HiLink puppetDelimiter Delimiter
  138. HiLink puppetControl Statement
  139. HiLink puppetDefType Define
  140. HiLink puppetDefName Type
  141. HiLink puppetNodeRe Type
  142. HiLink puppetTypeName Statement
  143. HiLink puppetTypeDefault Type
  144. HiLink puppetParamName Identifier
  145. HiLink puppetArgument Identifier
  146. HiLink puppetFunction Function
  147. HiLink puppetClass Include
  148. delcommand HiLink
  149. endif
  150. let b:current_syntax = "puppet"