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