summaryrefslogtreecommitdiffstats
path: root/public/prism/prism-groovy.js
blob: c6d1bbc1aa1a5a655d5cfc2d5d4c4399dd6d721a (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
Prism.languages.groovy = Prism.languages.extend('clike', {
  string: [
    {
      // https://groovy-lang.org/syntax.html#_dollar_slashy_string
      pattern:
        /("""|''')(?:[^\\]|\\[\s\S])*?\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
      greedy: true,
    },
    {
      // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
      // simple division (see JS regex), so find a fix maybe?
      pattern: /(["'/])(?:\\.|(?!\1)[^\\\r\n])*\1/,
      greedy: true,
    },
  ],
  keyword:
    /\b(?:abstract|as|assert|boolean|break|byte|case|catch|char|class|const|continue|def|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|in|instanceof|int|interface|long|native|new|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|trait|transient|try|void|volatile|while)\b/,
  number:
    /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
  operator: {
    pattern:
      /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
    lookbehind: true,
  },
  punctuation: /\.+|[{}[\];(),:$]/,
});

Prism.languages.insertBefore('groovy', 'string', {
  shebang: {
    pattern: /#!.+/,
    alias: 'comment',
  },
});

Prism.languages.insertBefore('groovy', 'punctuation', {
  'spock-block': /\b(?:and|cleanup|expect|given|setup|then|when|where):/,
});

Prism.languages.insertBefore('groovy', 'function', {
  annotation: {
    pattern: /(^|[^.])@\w+/,
    lookbehind: true,
    alias: 'punctuation',
  },
});

// Handle string interpolation
Prism.hooks.add('wrap', function (env) {
  if (env.language === 'groovy' && env.type === 'string') {
    var delimiter = env.content[0];

    if (delimiter != "'") {
      var pattern = /([^\\])(?:\$(?:\{.*?\}|[\w.]+))/;
      if (delimiter === '$') {
        pattern = /([^\$])(?:\$(?:\{.*?\}|[\w.]+))/;
      }

      // To prevent double HTML-encoding we have to decode env.content first
      env.content = env.content.replace(/&lt;/g, '<').replace(/&amp;/g, '&');

      env.content = Prism.highlight(env.content, {
        expression: {
          pattern: pattern,
          lookbehind: true,
          inside: Prism.languages.groovy,
        },
      });

      env.classes.push(delimiter === '/' ? 'regex' : 'gstring');
    }
  }
});
nt-matter': { pattern: /\S+(?:\s+\S+)*/, alias: ['yaml', 'language-yaml'], inside: s.languages.yaml, }, }, }, blockquote: { pattern: /^>(?:[\t ]*>)*/m, alias: 'punctuation' }, table: { pattern: RegExp('^' + t + a + '(?:' + t + ')*', 'm'), inside: { 'table-data-rows': { pattern: RegExp('^(' + t + a + ')(?:' + t + ')*$'), lookbehind: !0, inside: { 'table-data': { pattern: RegExp(e), inside: s.languages.markdown, }, punctuation: /\|/, }, }, 'table-line': { pattern: RegExp('^(' + t + ')' + a + '$'), lookbehind: !0, inside: { punctuation: /\||:?-{3,}:?/ }, }, 'table-header-row': { pattern: RegExp('^' + t + '$'), inside: { 'table-header': { pattern: RegExp(e), alias: 'important', inside: s.languages.markdown, }, punctuation: /\|/, }, }, }, }, code: [ { pattern: /((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/, lookbehind: !0, alias: 'keyword', }, { pattern: /^```[\s\S]*?^```$/m, greedy: !0, inside: { 'code-block': { pattern: /^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m, lookbehind: !0, }, 'code-language': { pattern: /^(```).+/, lookbehind: !0 }, punctuation: /```/, }, }, ], title: [ { pattern: /\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m, alias: 'important', inside: { punctuation: /==+$|--+$/ }, }, { pattern: /(^\s*)#.+/m, lookbehind: !0, alias: 'important', inside: { punctuation: /^#+|#+$/ }, }, ], hr: { pattern: /(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m, lookbehind: !0, alias: 'punctuation', }, list: { pattern: /(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m, lookbehind: !0, alias: 'punctuation', }, 'url-reference': { pattern: /!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/, inside: { variable: { pattern: /^(!?\[)[^\]]+/, lookbehind: !0 }, string: /(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/, punctuation: /^[\[\]!:]|[<>]/, }, alias: 'url', }, bold: { pattern: n( '\\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\\b|\\*\\*(?:(?!\\*)<inner>|\\*(?:(?!\\*)<inner>)+\\*)+\\*\\*' ), lookbehind: !0, greedy: !0, inside: { content: { pattern: /(^..)[\s\S]+(?=..$)/, lookbehind: !0, inside: {}, }, punctuation: /\*\*|__/, }, }, italic: { pattern: n( '\\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\\b|\\*(?:(?!\\*)<inner>|\\*\\*(?:(?!\\*)<inner>)+\\*\\*)+\\*' ), lookbehind: !0, greedy: !0, inside: { content: { pattern: /(^.)[\s\S]+(?=.$)/, lookbehind: !0, inside: {} }, punctuation: /[*_]/, }, }, strike: { pattern: n('(~~?)(?:(?!~)<inner>)+\\2'), lookbehind: !0, greedy: !0, inside: { content: { pattern: /(^~~?)[\s\S]+(?=\1$)/, lookbehind: !0, inside: {}, }, punctuation: /~~?/, }, }, 'code-snippet': { pattern: /(^|[^\\`])(?:``[^`\r\n]+(?:`[^`\r\n]+)*``(?!`)|`[^`\r\n]+`(?!`))/, lookbehind: !0, greedy: !0, alias: ['code', 'keyword'], }, url: { pattern: n( '!?\\[(?:(?!\\])<inner>)+\\](?:\\([^\\s)]+(?:[\t ]+"(?:\\\\.|[^"\\\\])*")?\\)|[ \t]?\\[(?:(?!\\])<inner>)+\\])' ), lookbehind: !0, greedy: !0, inside: { operator: /^!/, content: { pattern: /(^\[)[^\]]+(?=\])/, lookbehind: !0, inside: {} }, variable: { pattern: /(^\][ \t]?\[)[^\]]+(?=\]$)/, lookbehind: !0 }, url: { pattern: /(^\]\()[^\s)]+/, lookbehind: !0 }, string: { pattern: /(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/, lookbehind: !0, }, }, }, }), ['url', 'bold', 'italic', 'strike'].forEach(function (e) { ['url', 'bold', 'italic', 'strike', 'code-snippet'].forEach(function (n) { e !== n && (s.languages.markdown[e].inside.content.inside[n] = s.languages.markdown[n]); }); }), s.hooks.add('after-tokenize', function (n) { ('markdown' !== n.language && 'md' !== n.language) || !(function n(e) { if (e && 'string' != typeof e) for (var t = 0, a = e.length; t < a; t++) { var r = e[t]; if ('code' === r.type) { var i = r.content[1], o = r.content[3]; if ( i && o && 'code-language' === i.type && 'code-block' === o.type && 'string' == typeof i.content ) { var l = i.content .replace(/\b#/g, 'sharp') .replace(/\b\+\+/g, 'pp'), s = 'language-' + (l = (/[a-z][\w-]*/i.exec(l) || [''])[0].toLowerCase()); o.alias ? 'string' == typeof o.alias ? (o.alias = [o.alias, s]) : o.alias.push(s) : (o.alias = [s]); } } else n(r.content); } })(n.tokens); }), s.hooks.add('wrap', function (n) { if ('code-block' === n.type) { for (var e = '', t = 0, a = n.classes.length; t < a; t++) { var r = n.classes[t], i = /language-(.+)/.exec(r); if (i) { e = i[1]; break; } } var o = s.languages[e]; if (o) n.content = s.highlight( (function (n) { var e = n.replace(d, ''); return (e = e.replace( /&(\w{1,8}|#x?[\da-f]{1,8});/gi, function (n, e) { var t; if ('#' === (e = e.toLowerCase())[0]) return ( (t = 'x' === e[1] ? parseInt(e.slice(2), 16) : Number(e.slice(1))), u(t) ); var a = p[e]; return a || n; } )); })(n.content), o, e ); else if (e && 'none' !== e && s.plugins.autoloader) { var l = 'md-' + new Date().valueOf() + '-' + Math.floor(1e16 * Math.random()); (n.attributes.id = l), s.plugins.autoloader.loadLanguages(e, function () { var n = document.getElementById(l); n && (n.innerHTML = s.highlight(n.textContent, s.languages[e], e)); }); } } }); var d = RegExp(s.languages.markup.tag.pattern.source, 'gi'), p = { amp: '&', lt: '<', gt: '>', quot: '"' }, u = String.fromCodePoint || String.fromCharCode; s.languages.md = s.languages.markdown; })(Prism);