prism-gradle.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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,
  13. },
  14. },
  15. };
  16. Prism.languages.gradle = Prism.languages.extend('clike', {
  17. 'string': {
  18. pattern: /'''(?:[^\\]|\\[\s\S])*?'''|'(?:\\.|[^\\'\r\n])*'/,
  19. greedy: true,
  20. },
  21. 'keyword':
  22. /\b(?:apply|def|dependencies|else|if|implementation|import|plugin|plugins|project|repositories|repository|sourceSets|tasks|val)\b/,
  23. 'number': /\b(?:0b[01_]+|0x[\da-f_]+(?:\.[\da-f_p\-]+)?|[\d_]+(?:\.[\d_]+)?(?:e[+-]?\d+)?)[glidf]?\b/i,
  24. 'operator': {
  25. pattern:
  26. /(^|[^.])(?:~|==?~?|\?[.:]?|\*(?:[.=]|\*=?)?|\.[@&]|\.\.<|\.\.(?!\.)|-[-=>]?|\+[+=]?|!=?|<(?:<=?|=>?)?|>(?:>>?=?|=)?|&[&=]?|\|[|=]?|\/=?|\^=?|%=?)/,
  27. lookbehind: true,
  28. },
  29. 'punctuation': /\.+|[{}[\];(),:$]/,
  30. });
  31. Prism.languages.insertBefore('gradle', 'string', {
  32. 'shebang': {
  33. pattern: /#!.+/,
  34. alias: 'comment',
  35. greedy: true,
  36. },
  37. 'interpolation-string': {
  38. pattern:
  39. /"""(?:[^\\]|\\[\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('gradle', 'punctuation', {
  48. 'spock-block': /\b(?:and|cleanup|expect|given|setup|then|when|where):/,
  49. });
  50. Prism.languages.insertBefore('gradle', 'function', {
  51. 'annotation': {
  52. pattern: /(^|[^.])@\w+/,
  53. lookbehind: true,
  54. alias: 'punctuation',
  55. },
  56. });
  57. interpolation.inside.expression.inside = Prism.languages.gradle;
  58. }(Prism));