prism-apex.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. (function (Prism) {
  2. var keywords = /\b(?:(?:after|before)(?=\s+[a-z])|abstract|activate|and|any|array|as|asc|autonomous|begin|bigdecimal|blob|boolean|break|bulk|by|byte|case|cast|catch|char|class|collect|commit|const|continue|currency|date|datetime|decimal|default|delete|desc|do|double|else|end|enum|exception|exit|export|extends|final|finally|float|for|from|get(?=\s*[{};])|global|goto|group|having|hint|if|implements|import|in|inner|insert|instanceof|int|integer|interface|into|join|like|limit|list|long|loop|map|merge|new|not|null|nulls|number|object|of|on|or|outer|override|package|parallel|pragma|private|protected|public|retrieve|return|rollback|select|set|short|sObject|sort|static|string|super|switch|synchronized|system|testmethod|then|this|throw|time|transaction|transient|trigger|try|undelete|update|upsert|using|virtual|void|webservice|when|where|while|(?:inherited|with|without)\s+sharing)\b/i;
  3. var className = /\b(?:(?=[a-z_]\w*\s*[<\[])|(?!<keyword>))[A-Z_]\w*(?:\s*\.\s*[A-Z_]\w*)*\b(?:\s*(?:\[\s*\]|<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>))*/.source
  4. .replace(/<keyword>/g, function () { return keywords.source; });
  5. /** @param {string} pattern */
  6. function insertClassName(pattern) {
  7. return RegExp(pattern.replace(/<CLASS-NAME>/g, function () { return className; }), 'i');
  8. }
  9. var classNameInside = {
  10. 'keyword': keywords,
  11. 'punctuation': /[()\[\]{};,:.<>]/
  12. };
  13. Prism.languages.apex = {
  14. 'comment': Prism.languages.clike.comment,
  15. 'string': Prism.languages.clike.string,
  16. 'sql': {
  17. pattern: /((?:[=,({:]|\breturn)\s*)\[[^\[\]]*\]/i,
  18. lookbehind: true,
  19. greedy: true,
  20. alias: 'language-sql',
  21. inside: Prism.languages.sql
  22. },
  23. 'annotation': {
  24. pattern: /@\w+\b/,
  25. alias: 'punctuation'
  26. },
  27. 'class-name': [
  28. {
  29. pattern: insertClassName(/(\b(?:class|enum|extends|implements|instanceof|interface|new|trigger\s+\w+\s+on)\s+)<CLASS-NAME>/.source),
  30. lookbehind: true,
  31. inside: classNameInside
  32. },
  33. {
  34. // cast
  35. pattern: insertClassName(/(\(\s*)<CLASS-NAME>(?=\s*\)\s*[\w(])/.source),
  36. lookbehind: true,
  37. inside: classNameInside
  38. },
  39. {
  40. // variable/parameter declaration and return types
  41. pattern: insertClassName(/<CLASS-NAME>(?=\s*\w+\s*[;=,(){:])/.source),
  42. inside: classNameInside
  43. }
  44. ],
  45. 'trigger': {
  46. pattern: /(\btrigger\s+)\w+\b/i,
  47. lookbehind: true,
  48. alias: 'class-name'
  49. },
  50. 'keyword': keywords,
  51. 'function': /\b[a-z_]\w*(?=\s*\()/i,
  52. 'boolean': /\b(?:false|true)\b/i,
  53. 'number': /(?:\B\.\d+|\b\d+(?:\.\d+|L)?)\b/i,
  54. 'operator': /[!=](?:==?)?|\?\.?|&&|\|\||--|\+\+|[-+*/^&|]=?|:|<<?=?|>{1,3}=?/,
  55. 'punctuation': /[()\[\]{};,.]/
  56. };
  57. }(Prism));