1 | (function (Prism) {
|
---|
2 |
|
---|
3 | var interpolation = {
|
---|
4 | pattern: /((?:^|[^\\$])(?:\\{2})*)\$(?:\w+|\{[^{}]*\})/,
|
---|
5 | lookbehind: true,
|
---|
6 | inside: {
|
---|
7 | 'interpolation-punctuation': {
|
---|
8 | pattern: /^\$\{?|\}$/,
|
---|
9 | alias: 'punctuation'
|
---|
10 | },
|
---|
11 | 'expression': {
|
---|
12 | pattern: /[\s\S]+/,
|
---|
13 | inside: null // see below
|
---|
14 | }
|
---|
15 | }
|
---|
16 | };
|
---|
17 |
|
---|
18 | Prism.languages.groovy = Prism.languages.extend('clike', {
|
---|
19 | 'string': {
|
---|
20 | // https://groovy-lang.org/syntax.html#_dollar_slashy_string
|
---|
21 | pattern: /'''(?:[^\\]|\\[\s\S])*?'''|'(?:\\.|[^\\'\r\n])*'/,
|
---|
22 | greedy: true
|
---|
23 | },
|
---|
24 | '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/,
|
---|
25 | 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
|
---|
26 | 'operator': {
|
---|
27 | pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
|
---|
28 | lookbehind: true
|
---|
29 | },
|
---|
30 | 'punctuation': /\.+|[{}[\];(),:$]/
|
---|
31 | });
|
---|
32 |
|
---|
33 | Prism.languages.insertBefore('groovy', 'string', {
|
---|
34 | 'shebang': {
|
---|
35 | pattern: /#!.+/,
|
---|
36 | alias: 'comment',
|
---|
37 | greedy: true
|
---|
38 | },
|
---|
39 | 'interpolation-string': {
|
---|
40 | // TODO: Slash strings (e.g. /foo/) can contain line breaks but this will cause a lot of trouble with
|
---|
41 | // simple division (see JS regex), so find a fix maybe?
|
---|
42 | pattern: /"""(?:[^\\]|\\[\s\S])*?"""|(["/])(?:\\.|(?!\1)[^\\\r\n])*\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
|
---|
43 | greedy: true,
|
---|
44 | inside: {
|
---|
45 | 'interpolation': interpolation,
|
---|
46 | 'string': /[\s\S]+/
|
---|
47 | }
|
---|
48 | }
|
---|
49 | });
|
---|
50 |
|
---|
51 | Prism.languages.insertBefore('groovy', 'punctuation', {
|
---|
52 | 'spock-block': /\b(?:and|cleanup|expect|given|setup|then|when|where):/
|
---|
53 | });
|
---|
54 |
|
---|
55 | Prism.languages.insertBefore('groovy', 'function', {
|
---|
56 | 'annotation': {
|
---|
57 | pattern: /(^|[^.])@\w+/,
|
---|
58 | lookbehind: true,
|
---|
59 | alias: 'punctuation'
|
---|
60 | }
|
---|
61 | });
|
---|
62 |
|
---|
63 | interpolation.inside.expression.inside = Prism.languages.groovy;
|
---|
64 |
|
---|
65 | }(Prism));
|
---|