prism-mata.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // https://www.stata.com/manuals/m.pdf
  2. (function (Prism) {
  3. var orgType = /\b(?:(?:col|row)?vector|matrix|scalar)\b/.source;
  4. var type = /\bvoid\b|<org>|\b(?:complex|numeric|pointer(?:\s*\([^()]*\))?|real|string|(?:class|struct)\s+\w+|transmorphic)(?:\s*<org>)?/.source
  5. .replace(/<org>/g, orgType);
  6. Prism.languages.mata = {
  7. 'comment': {
  8. pattern: /\/\/.*|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/)*\*\//,
  9. greedy: true
  10. },
  11. 'string': {
  12. pattern: /"[^"\r\n]*"|[‘`']".*?"[’`']/,
  13. greedy: true
  14. },
  15. 'class-name': {
  16. pattern: /(\b(?:class|extends|struct)\s+)\w+(?=\s*(?:\{|\bextends\b))/,
  17. lookbehind: true
  18. },
  19. 'type': {
  20. pattern: RegExp(type),
  21. alias: 'class-name',
  22. inside: {
  23. 'punctuation': /[()]/,
  24. 'keyword': /\b(?:class|function|struct|void)\b/
  25. }
  26. },
  27. 'keyword': /\b(?:break|class|continue|do|else|end|extends|external|final|for|function|goto|if|pragma|private|protected|public|return|static|struct|unset|unused|version|virtual|while)\b/,
  28. 'constant': /\bNULL\b/,
  29. 'number': {
  30. pattern: /(^|[^\w.])(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|\d[a-f0-9]*(?:\.[a-f0-9]+)?x[+-]?\d+)i?(?![\w.])/i,
  31. lookbehind: true
  32. },
  33. 'missing': {
  34. pattern: /(^|[^\w.])(?:\.[a-z]?)(?![\w.])/,
  35. lookbehind: true,
  36. alias: 'symbol'
  37. },
  38. 'function': /\b[a-z_]\w*(?=\s*\()/i,
  39. 'operator': /\.\.|\+\+|--|&&|\|\||:?(?:[!=<>]=|[+\-*/^<>&|:])|[!?=\\#’`']/,
  40. 'punctuation': /[()[\]{},;.]/
  41. };
  42. }(Prism));