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