matlab.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. module.exports = /*
  2. Formal syntax is not published, helpful link:
  3. https://github.com/kornilova-l/matlab-IntelliJ-plugin/blob/master/src/main/grammar/Matlab.bnf
  4. */
  5. function(hljs) {
  6. var TRANSPOSE_RE = '(\'|\\.\')+';
  7. var TRANSPOSE = {
  8. relevance: 0,
  9. contains: [
  10. { begin: TRANSPOSE_RE }
  11. ]
  12. };
  13. return {
  14. keywords: {
  15. keyword:
  16. 'break case catch classdef continue else elseif end enumerated events for function ' +
  17. 'global if methods otherwise parfor persistent properties return spmd switch try while',
  18. built_in:
  19. 'sin sind sinh asin asind asinh cos cosd cosh acos acosd acosh tan tand tanh atan ' +
  20. 'atand atan2 atanh sec secd sech asec asecd asech csc cscd csch acsc acscd acsch cot ' +
  21. 'cotd coth acot acotd acoth hypot exp expm1 log log1p log10 log2 pow2 realpow reallog ' +
  22. 'realsqrt sqrt nthroot nextpow2 abs angle complex conj imag real unwrap isreal ' +
  23. 'cplxpair fix floor ceil round mod rem sign airy besselj bessely besselh besseli ' +
  24. 'besselk beta betainc betaln ellipj ellipke erf erfc erfcx erfinv expint gamma ' +
  25. 'gammainc gammaln psi legendre cross dot factor isprime primes gcd lcm rat rats perms ' +
  26. 'nchoosek factorial cart2sph cart2pol pol2cart sph2cart hsv2rgb rgb2hsv zeros ones ' +
  27. 'eye repmat rand randn linspace logspace freqspace meshgrid accumarray size length ' +
  28. 'ndims numel disp isempty isequal isequalwithequalnans cat reshape diag blkdiag tril ' +
  29. 'triu fliplr flipud flipdim rot90 find sub2ind ind2sub bsxfun ndgrid permute ipermute ' +
  30. 'shiftdim circshift squeeze isscalar isvector ans eps realmax realmin pi i inf nan ' +
  31. 'isnan isinf isfinite j why compan gallery hadamard hankel hilb invhilb magic pascal ' +
  32. 'rosser toeplitz vander wilkinson max min nanmax nanmin mean nanmean type table ' +
  33. 'readtable writetable sortrows sort figure plot plot3 scatter scatter3 cellfun ' +
  34. 'legend intersect ismember procrustes hold num2cell '
  35. },
  36. illegal: '(//|"|#|/\\*|\\s+/\\w+)',
  37. contains: [
  38. {
  39. className: 'function',
  40. beginKeywords: 'function', end: '$',
  41. contains: [
  42. hljs.UNDERSCORE_TITLE_MODE,
  43. {
  44. className: 'params',
  45. variants: [
  46. {begin: '\\(', end: '\\)'},
  47. {begin: '\\[', end: '\\]'}
  48. ]
  49. }
  50. ]
  51. },
  52. {
  53. className: 'built_in',
  54. begin: /true|false/,
  55. relevance: 0,
  56. starts: TRANSPOSE
  57. },
  58. {
  59. begin: '[a-zA-Z][a-zA-Z_0-9]*' + TRANSPOSE_RE,
  60. relevance: 0
  61. },
  62. {
  63. className: 'number',
  64. begin: hljs.C_NUMBER_RE,
  65. relevance: 0,
  66. starts: TRANSPOSE
  67. },
  68. {
  69. className: 'string',
  70. begin: '\'', end: '\'',
  71. contains: [
  72. hljs.BACKSLASH_ESCAPE,
  73. {begin: '\'\''}]
  74. },
  75. {
  76. begin: /\]|}|\)/,
  77. relevance: 0,
  78. starts: TRANSPOSE
  79. },
  80. {
  81. className: 'string',
  82. begin: '"', end: '"',
  83. contains: [
  84. hljs.BACKSLASH_ESCAPE,
  85. {begin: '""'}
  86. ],
  87. starts: TRANSPOSE
  88. },
  89. hljs.COMMENT('^\\s*\\%\\{\\s*$', '^\\s*\\%\\}\\s*$'),
  90. hljs.COMMENT('\\%', '$')
  91. ]
  92. };
  93. };