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