UNPKG

4 kBJavaScriptView Raw
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
103 var interpolation = [
104 {
105 // Allow for one nested level of braces inside interpolation
106 pattern: /(^|[^\\])\$\{(?:[^'"{}]|\{[^}]*\}|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}/,
107 lookbehind: true,
108 inside: {
109 'short-variable': {
110 // Negative look-ahead prevent wrong highlighting of functions
111 pattern: /(^\$\{)(?!\w+\()(?:::)?\w+(?:::\w+)*/,
112 lookbehind: true,
113 alias: 'variable',
114 inside: {
115 'punctuation': /::/
116 }
117 },
118 'delimiter': {
119 pattern: /^\$/,
120 alias: 'variable'
121 },
122 rest: Prism.languages.puppet
123 }
124 },
125 {
126 pattern: /(^|[^\\])\$(?:::)?\w+(?:::\w+)*/,
127 lookbehind: true,
128 alias: 'variable',
129 inside: {
130 'punctuation': /::/
131 }
132 }
133 ];
134 Prism.languages.puppet['heredoc'][0].inside.interpolation = interpolation;
135 Prism.languages.puppet['string'].inside['double-quoted'].inside.interpolation = interpolation;
136}(Prism));