aboutsummaryrefslogtreecommitdiffstats
path: root/public/prism/prism-puppet.js
blob: 14aba545f85bd078d26ae279dd6aa98bff05f929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Gen
(function (Prism) {
  Prism.languages.puppet = {
    heredoc: [
      // Matches the content of a quoted heredoc string (subject to interpolation)
      {
        pattern:
          /(@\("([^"\r\n\/):]+)"(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r(?!\n)))*?[ \t]*(?:\|[ \t]*)?(?:-[ \t]*)?\2/,
        lookbehind: true,
        alias: 'string',
        inside: {
          // Matches the end tag
          punctuation: /(?=\S).*\S(?= *$)/,
          // See interpolation below
        },
      },
      // Matches the content of an unquoted heredoc string (no interpolation)
      {
        pattern:
          /(@\(([^"\r\n\/):]+)(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r(?!\n)))*?[ \t]*(?:\|[ \t]*)?(?:-[ \t]*)?\2/,
        lookbehind: true,
        greedy: true,
        alias: 'string',
        inside: {
          // Matches the end tag
          punctuation: /(?=\S).*\S(?= *$)/,
        },
      },
      // Matches the start tag of heredoc strings
      {
        pattern: /@\("?(?:[^"\r\n\/):]+)"?(?:\/[nrts$uL]*)?\)/,
        alias: 'string',
        inside: {
          punctuation: {
            pattern: /(\().+?(?=\))/,
            lookbehind: true,
          },
        },
      },
    ],
    'multiline-comment': {
      pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
      lookbehind: true,
      greedy: true,
      alias: 'comment',
    },
    regex: {
      // Must be prefixed with the keyword "node" or a non-word char
      pattern:
        /((?:\bnode\s+|[~=\(\[\{,]\s*|[=+]>\s*|^\s*))\/(?:[^\/\\]|\\[\s\S])+\/(?:[imx]+\b|\B)/,
      lookbehind: true,
      greedy: true,
      inside: {
        // Extended regexes must have the x flag. They can contain single-line comments.
        'extended-regex': {
          pattern: /^\/(?:[^\/\\]|\\[\s\S])+\/[im]*x[im]*$/,
          inside: {
            comment: /#.*/,
          },
        },
      },
    },
    comment: {
      pattern: /(^|[^\\])#.*/,
      lookbehind: true,
      greedy: true,
    },
    string: {
      // Allow for one nested level of double quotes inside interpolation
      pattern:
        /(["'])(?:\$\{(?:[^'"}]|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}|\$(?!\{)|(?!\1)[^\\$]|\\[\s\S])*\1/,
      greedy: true,
      inside: {
        'double-quoted': {
          pattern: /^"[\s\S]*"$/,
          inside: {
            // See interpolation below
          },
        },
      },
    },
    variable: {
      pattern: /\$(?:::)?\w+(?:::\w+)*/,
      inside: {
        punctuation: /::/,
      },
    },
    'attr-name': /(?:\b\w+|\*)(?=\s*=>)/,
    function: [
      {
        pattern: /(\.)(?!\d)\w+/,
        lookbehind: true,
      },
      /\b(?:contain|debug|err|fail|include|info|notice|realize|require|tag|warning)\b|\b(?!\d)\w+(?=\()/,
    ],
    number: /\b(?:0x[a-f\d]+|\d+(?:\.\d+)?(?:e-?\d+)?)\b/i,
    boolean: /\b(?:false|true)\b/,
    // Includes words reserved for future use
    keyword:
      /\b(?:application|attr|case|class|consumes|default|define|else|elsif|function|if|import|inherits|node|private|produces|type|undef|unless)\b/,
    datatype: {
      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/,
      alias: 'symbol',
    },
    operator:
      /=[=~>]?|![=~]?|<(?:<\|?|[=~|-])?|>[>=]?|->?|~>|\|>?>?|[*\/%+?]|\b(?:and|in|or)\b/,
    punctuation: /[\[\]{}().,;]|:+/,
  };

  var interpolation = [
    {
      // Allow for one nested level of braces inside interpolation
      pattern:
        /(^|[^\\])\$\{(?:[^'"{}]|\{[^}]*\}|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}/,
      lookbehind: true,
      inside: {
        'short-variable': {
          // Negative look-ahead prevent wrong highlighting of functions
          pattern: /(^\$\{)(?!\w+\()(?:::)?\w+(?:::\w+)*/,
          lookbehind: true,
          alias: 'variable',
          inside: {
            punctuation: /::/,
          },
        },
        delimiter: {
          pattern: /^\$/,
          alias: 'variable',
        },
        rest: Prism.languages.puppet,
      },
    },
    {
      pattern: /(^|[^\\])\$(?:::)?\w+(?:::\w+)*/,
      lookbehind: true,
      alias: 'variable',
      inside: {
        punctuation: /::/,
      },
    },
  ];
  Prism.languages.puppet['heredoc'][0].inside.interpolation = interpolation;
  Prism.languages.puppet['string'].inside[
    'double-quoted'
  ].inside.interpolation = interpolation;
})(Prism);