prism-puppet.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. (function (Prism) {
  2. Prism.languages.puppet = {
  3. 'heredoc': [
  4. // Matches the content of a quoted heredoc string (subject to interpolation)
  5. {
  6. pattern: /(@\("([^"\r\n\/):]+)"(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r(?!\n)))*?[ \t]*(?:\|[ \t]*)?(?:-[ \t]*)?\2/,
  7. lookbehind: true,
  8. alias: 'string',
  9. inside: {
  10. // Matches the end tag
  11. 'punctuation': /(?=\S).*\S(?= *$)/
  12. // See interpolation below
  13. }
  14. },
  15. // Matches the content of an unquoted heredoc string (no interpolation)
  16. {
  17. pattern: /(@\(([^"\r\n\/):]+)(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r(?!\n)))*?[ \t]*(?:\|[ \t]*)?(?:-[ \t]*)?\2/,
  18. lookbehind: true,
  19. greedy: true,
  20. alias: 'string',
  21. inside: {
  22. // Matches the end tag
  23. 'punctuation': /(?=\S).*\S(?= *$)/
  24. }
  25. },
  26. // Matches the start tag of heredoc strings
  27. {
  28. pattern: /@\("?(?:[^"\r\n\/):]+)"?(?:\/[nrts$uL]*)?\)/,
  29. alias: 'string',
  30. inside: {
  31. 'punctuation': {
  32. pattern: /(\().+?(?=\))/,
  33. lookbehind: true
  34. }
  35. }
  36. }
  37. ],
  38. 'multiline-comment': {
  39. pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
  40. lookbehind: true,
  41. greedy: true,
  42. alias: 'comment'
  43. },
  44. 'regex': {
  45. // Must be prefixed with the keyword "node" or a non-word char
  46. pattern: /((?:\bnode\s+|[~=\(\[\{,]\s*|[=+]>\s*|^\s*))\/(?:[^\/\\]|\\[\s\S])+\/(?:[imx]+\b|\B)/,
  47. lookbehind: true,
  48. greedy: true,
  49. inside: {
  50. // Extended regexes must have the x flag. They can contain single-line comments.
  51. 'extended-regex': {
  52. pattern: /^\/(?:[^\/\\]|\\[\s\S])+\/[im]*x[im]*$/,
  53. inside: {
  54. 'comment': /#.*/
  55. }
  56. }
  57. }
  58. },
  59. 'comment': {
  60. pattern: /(^|[^\\])#.*/,
  61. lookbehind: true,
  62. greedy: true,
  63. },
  64. 'string': {
  65. // Allow for one nested level of double quotes inside interpolation
  66. pattern: /(["'])(?:\$\{(?:[^'"}]|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}|\$(?!\{)|(?!\1)[^\\$]|\\[\s\S])*\1/,
  67. greedy: true,
  68. inside: {
  69. 'double-quoted': {
  70. pattern: /^"[\s\S]*"$/,
  71. inside: {
  72. // See interpolation below
  73. }
  74. }
  75. }
  76. },
  77. 'variable': {
  78. pattern: /\$(?:::)?\w+(?:::\w+)*/,
  79. inside: {
  80. 'punctuation': /::/
  81. }
  82. },
  83. 'attr-name': /(?:\b\w+|\*)(?=\s*=>)/,
  84. 'function': [
  85. {
  86. pattern: /(\.)(?!\d)\w+/,
  87. lookbehind: true
  88. },
  89. /\b(?:contain|debug|err|fail|include|info|notice|realize|require|tag|warning)\b|\b(?!\d)\w+(?=\()/
  90. ],
  91. 'number': /\b(?:0x[a-f\d]+|\d+(?:\.\d+)?(?:e-?\d+)?)\b/i,
  92. 'boolean': /\b(?:false|true)\b/,
  93. // Includes words reserved for future use
  94. 'keyword': /\b(?:application|attr|case|class|consumes|default|define|else|elsif|function|if|import|inherits|node|private|produces|type|undef|unless)\b/,
  95. 'datatype': {
  96. pattern: /\b(?:Any|Array|Boolean|Callable|Catalogentry|Class|Collection|Data|Default|Enum|Float|Hash|Integer|NotUndef|Numeric|Optional|Pattern|Regexp|Resource|Runtime|Scalar|String|Struct|Tuple|Type|Undef|Variant)\b/,
  97. alias: 'symbol'
  98. },
  99. 'operator': /=[=~>]?|![=~]?|<(?:<\|?|[=~|-])?|>[>=]?|->?|~>|\|>?>?|[*\/%+?]|\b(?:and|in|or)\b/,
  100. 'punctuation': /[\[\]{}().,;]|:+/
  101. };
  102. var interpolation = [
  103. {
  104. // Allow for one nested level of braces inside interpolation
  105. pattern: /(^|[^\\])\$\{(?:[^'"{}]|\{[^}]*\}|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}/,
  106. lookbehind: true,
  107. inside: {
  108. 'short-variable': {
  109. // Negative look-ahead prevent wrong highlighting of functions
  110. pattern: /(^\$\{)(?!\w+\()(?:::)?\w+(?:::\w+)*/,
  111. lookbehind: true,
  112. alias: 'variable',
  113. inside: {
  114. 'punctuation': /::/
  115. }
  116. },
  117. 'delimiter': {
  118. pattern: /^\$/,
  119. alias: 'variable'
  120. },
  121. rest: Prism.languages.puppet
  122. }
  123. },
  124. {
  125. pattern: /(^|[^\\])\$(?:::)?\w+(?:::\w+)*/,
  126. lookbehind: true,
  127. alias: 'variable',
  128. inside: {
  129. 'punctuation': /::/
  130. }
  131. }
  132. ];
  133. Prism.languages.puppet['heredoc'][0].inside.interpolation = interpolation;
  134. Prism.languages.puppet['string'].inside['double-quoted'].inside.interpolation = interpolation;
  135. }(Prism));