matlab.js 3.5 KB

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