1 | Prism.languages.groovy = Prism.languages.extend('clike', {
|
2 | 'string': [
|
3 | {
|
4 |
|
5 | pattern: /("""|''')(?:[^\\]|\\[\s\S])*?\1|\$\/(?:[^/$]|\$(?:[/$]|(?![/$]))|\/(?!\$))*\/\$/,
|
6 | greedy: true
|
7 | },
|
8 | {
|
9 |
|
10 |
|
11 | pattern: /(["'/])(?:\\.|(?!\1)[^\\\r\n])*\1/,
|
12 | greedy: true
|
13 | }
|
14 | ],
|
15 | 'keyword': /\b(?:as|def|in|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|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/,
|
16 | 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?[\d]+)?)[glidf]?\b/i,
|
17 | 'operator': {
|
18 | pattern: /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
|
19 | lookbehind: true
|
20 | },
|
21 | 'punctuation': /\.+|[{}[\];(),:$]/
|
22 | });
|
23 |
|
24 | Prism.languages.insertBefore('groovy', 'string', {
|
25 | 'shebang': {
|
26 | pattern: /#!.+/,
|
27 | alias: 'comment'
|
28 | }
|
29 | });
|
30 |
|
31 | Prism.languages.insertBefore('groovy', 'punctuation', {
|
32 | 'spock-block': /\b(?:setup|given|when|then|and|cleanup|expect|where):/
|
33 | });
|
34 |
|
35 | Prism.languages.insertBefore('groovy', 'function', {
|
36 | 'annotation': {
|
37 | pattern: /(^|[^.])@\w+/,
|
38 | lookbehind: true,
|
39 | alias: 'punctuation'
|
40 | }
|
41 | });
|
42 |
|
43 |
|
44 | Prism.hooks.add('wrap', function(env) {
|
45 | if (env.language === 'groovy' && env.type === 'string') {
|
46 | var delimiter = env.content[0];
|
47 |
|
48 | if (delimiter != "'") {
|
49 | var pattern = /([^\\])(?:\$(?:\{.*?\}|[\w.]+))/;
|
50 | if (delimiter === '$') {
|
51 | pattern = /([^\$])(?:\$(?:\{.*?\}|[\w.]+))/;
|
52 | }
|
53 |
|
54 |
|
55 | env.content = env.content.replace(/</g, '<').replace(/&/g, '&');
|
56 |
|
57 | env.content = Prism.highlight(env.content, {
|
58 | 'expression': {
|
59 | pattern: pattern,
|
60 | lookbehind: true,
|
61 | inside: Prism.languages.groovy
|
62 | }
|
63 | });
|
64 |
|
65 | env.classes.push(delimiter === '/' ? 'regex' : 'gstring');
|
66 | }
|
67 | }
|
68 | });
|