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