matlab.js 3.6 KB

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