prism-groovy.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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': /("""|''')[\W\w]*?\1|("|'|\/)(?:\\?.)*?\2|(\$\/)(\$\/\$|[\W\w])*?\/\$/,
  4. 'number': /\b0b[01_]+\b|\b0x[\da-f_]+(\.[\da-f_p\-]+)?\b|\b[\d_]+(\.[\d_]+[e]?[\d]*)?[glidf]\b|[\d_]+(\.[\d_]+)?\b/i,
  5. 'operator': {
  6. pattern: /(^|[^.])(={0,2}~|\?\.|\*?\.@|\.&|\.{1,2}(?!\.)|\.{2}<?(?=\w)|->|\?:|[-+]{1,2}|!|<=>|>{1,3}|<{1,2}|={1,2}|&{1,2}|\|{1,2}|\?|\*{1,2}|\/|\^|%)/,
  7. lookbehind: true
  8. },
  9. 'punctuation': /\.+|[{}[\];(),:$]/
  10. });
  11. Prism.languages.insertBefore('groovy', 'string', {
  12. 'shebang': {
  13. pattern: /#!.+/,
  14. alias: 'comment'
  15. }
  16. });
  17. Prism.languages.insertBefore('groovy', 'punctuation', {
  18. 'spock-block': /\b(setup|given|when|then|and|cleanup|expect|where):/
  19. });
  20. Prism.languages.insertBefore('groovy', 'function', {
  21. 'annotation': {
  22. pattern: /(^|[^.])@\w+/,
  23. lookbehind: true
  24. }
  25. });
  26. Prism.hooks.add('wrap', function(env) {
  27. if (env.language === 'groovy' && env.type === 'string') {
  28. var delimiter = env.content[0];
  29. if (delimiter != "'") {
  30. var pattern = /([^\\])(\$(\{.*?\}|[\w\.]+))/;
  31. if (delimiter === '$') {
  32. pattern = /([^\$])(\$(\{.*?\}|[\w\.]+))/;
  33. }
  34. env.content = Prism.highlight(env.content, {
  35. 'expression': {
  36. pattern: pattern,
  37. lookbehind: true,
  38. inside: Prism.languages.groovy
  39. }
  40. });
  41. env.classes.push(delimiter === '/' ? 'regex' : 'gstring');
  42. }
  43. }
  44. });