prism-groovy.js 2.1 KB

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