43 # |
44 # |
44 # elfun: Elementary math functions |
45 # elfun: Elementary math functions |
45 # specfun: Special Math functions |
46 # specfun: Special Math functions |
46 # elmat: Elementary matrices and matrix manipulation |
47 # elmat: Elementary matrices and matrix manipulation |
47 # |
48 # |
48 # taken from Matlab version 7.4.0.336 (R2007a) |
49 # taken from Matlab version 9.4 (R2018a) |
49 # |
50 # |
50 elfun = ("sin", "sind", "sinh", "asin", "asind", "asinh", "cos", "cosd", "cosh", |
51 elfun = ("sin", "sind", "sinh", "asin", "asind", "asinh", "cos", "cosd", "cosh", |
51 "acos", "acosd", "acosh", "tan", "tand", "tanh", "atan", "atand", "atan2", |
52 "acos", "acosd", "acosh", "tan", "tand", "tanh", "atan", "atand", "atan2", |
52 "atanh", "sec", "secd", "sech", "asec", "asecd", "asech", "csc", "cscd", |
53 "atan2d", "atanh", "sec", "secd", "sech", "asec", "asecd", "asech", "csc", "cscd", |
53 "csch", "acsc", "acscd", "acsch", "cot", "cotd", "coth", "acot", "acotd", |
54 "csch", "acsc", "acscd", "acsch", "cot", "cotd", "coth", "acot", "acotd", |
54 "acoth", "hypot", "exp", "expm1", "log", "log1p", "log10", "log2", "pow2", |
55 "acoth", "hypot", "deg2rad", "rad2deg", "exp", "expm1", "log", "log1p", "log10", "log2", "pow2", |
55 "realpow", "reallog", "realsqrt", "sqrt", "nthroot", "nextpow2", "abs", |
56 "realpow", "reallog", "realsqrt", "sqrt", "nthroot", "nextpow2", "abs", |
56 "angle", "complex", "conj", "imag", "real", "unwrap", "isreal", "cplxpair", |
57 "angle", "complex", "conj", "imag", "real", "unwrap", "isreal", "cplxpair", |
57 "fix", "floor", "ceil", "round", "mod", "rem", "sign") |
58 "fix", "floor", "ceil", "round", "mod", "rem", "sign") |
58 specfun = ("airy", "besselj", "bessely", "besselh", "besseli", "besselk", "beta", |
59 specfun = ("airy", "besselj", "bessely", "besselh", "besseli", "besselk", "beta", |
59 "betainc", "betaln", "ellipj", "ellipke", "erf", "erfc", "erfcx", |
60 "betainc", "betaincinv", "betaln", "ellipj", "ellipke", "erf", "erfc", "erfcx", |
60 "erfinv", "expint", "gamma", "gammainc", "gammaln", "psi", "legendre", |
61 "erfinv", "erfcinv", "expint", "gamma", "gammainc", "gammaincinv", "gammaln", "psi", "legendre", |
61 "cross", "dot", "factor", "isprime", "primes", "gcd", "lcm", "rat", |
62 "cross", "dot", "factor", "isprime", "primes", "gcd", "lcm", "rat", |
62 "rats", "perms", "nchoosek", "factorial", "cart2sph", "cart2pol", |
63 "rats", "perms", "nchoosek", "factorial", "cart2sph", "cart2pol", |
63 "pol2cart", "sph2cart", "hsv2rgb", "rgb2hsv") |
64 "pol2cart", "sph2cart", "hsv2rgb", "rgb2hsv") |
64 elmat = ("zeros", "ones", "eye", "repmat", "rand", "randn", "linspace", "logspace", |
65 elmat = ("zeros", "ones", "eye", "repmat", "repelem", "linspace", "logspace", |
65 "freqspace", "meshgrid", "accumarray", "size", "length", "ndims", "numel", |
66 "freqspace", "meshgrid", "accumarray", "size", "length", "ndims", "numel", |
66 "disp", "isempty", "isequal", "isequalwithequalnans", "cat", "reshape", |
67 "disp", "isempty", "isequal", "isequaln", "cat", "reshape", |
67 "diag", "blkdiag", "tril", "triu", "fliplr", "flipud", "flipdim", "rot90", |
68 "diag", "blkdiag", "tril", "triu", "fliplr", "flipud", "flip", "rot90", |
68 "find", "end", "sub2ind", "ind2sub", "bsxfun", "ndgrid", "permute", |
69 "find", "end", "sub2ind", "ind2sub", "bsxfun", "ndgrid", "permute", |
69 "ipermute", "shiftdim", "circshift", "squeeze", "isscalar", "isvector", |
70 "ipermute", "shiftdim", "circshift", "squeeze", "isscalar", "isvector", |
70 "ans", "eps", "realmax", "realmin", "pi", "i", "inf", "nan", "isnan", |
71 "isrow", "iscolumn", "ismatrix", "eps", "realmax", "realmin", "intmax", "intmin", "flintmax", "pi", "i", "inf", "nan", "isnan", |
71 "isinf", "isfinite", "j", "why", "compan", "gallery", "hadamard", "hankel", |
72 "isinf", "isfinite", "j", "true", "false", "compan", "gallery", "hadamard", "hankel", |
72 "hilb", "invhilb", "magic", "pascal", "rosser", "toeplitz", "vander", |
73 "hilb", "invhilb", "magic", "pascal", "rosser", "toeplitz", "vander", |
73 "wilkinson") |
74 "wilkinson") |
74 |
75 |
75 _operators = r'-|==|~=|<=|>=|<|>|&&|&|~|\|\|?|\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\' |
76 _operators = r'-|==|~=|<=|>=|<|>|&&|&|~|\|\|?|\.\*|\*|\+|\.\^|\.\\|\./|/|\\' |
76 |
77 |
77 tokens = { |
78 tokens = { |
78 'root': [ |
79 'root': [ |
79 # line starting with '!' is sent as a system command. not sure what |
80 # line starting with '!' is sent as a system command. not sure what |
80 # label to use... |
81 # label to use... |
81 (r'^!.*', String.Other), |
82 (r'^!.*', String.Other), |
82 (r'%\{\s*\n', Comment.Multiline, 'blockcomment'), |
83 (r'%\{\s*\n', Comment.Multiline, 'blockcomment'), |
83 (r'%.*$', Comment), |
84 (r'%.*$', Comment), |
84 (r'^\s*function\b', Keyword, 'deffunc'), |
85 (r'^\s*function\b', Keyword, 'deffunc'), |
85 |
86 |
86 # from 'iskeyword' on version 7.11 (R2010): |
87 # from 'iskeyword' on version 9.4 (R2018a): |
87 # Check that there is no preceding dot, as keywords are valid field |
88 # Check that there is no preceding dot, as keywords are valid field |
88 # names. |
89 # names. |
89 (words(('break', 'case', 'catch', 'classdef', 'continue', 'else', |
90 (words(('break', 'case', 'catch', 'classdef', 'continue', 'else', |
90 'elseif', 'end', 'enumerated', 'events', 'for', 'function', |
91 'elseif', 'end', 'for', 'function', |
91 'global', 'if', 'methods', 'otherwise', 'parfor', |
92 'global', 'if', 'otherwise', 'parfor', |
92 'persistent', 'properties', 'return', 'spmd', 'switch', |
93 'persistent', 'return', 'spmd', 'switch', |
93 'try', 'while'), |
94 'try', 'while'), |
94 prefix=r'(?<!\.)', suffix=r'\b'), |
95 prefix=r'(?<!\.)', suffix=r'\b'), |
95 Keyword), |
96 Keyword), |
96 |
97 |
97 ("(" + "|".join(elfun + specfun + elmat) + r')\b', Name.Builtin), |
98 ("(" + "|".join(elfun + specfun + elmat) + r')\b', Name.Builtin), |
98 |
99 |
99 # line continuation with following comment: |
100 # line continuation with following comment: |
100 (r'\.\.\..*$', Comment), |
101 (r'(\.\.\.)(.*)$', bygroups(Keyword, Comment)), |
101 |
102 |
102 # command form: |
103 # command form: |
103 # "How MATLAB Recognizes Command Syntax" specifies that an operator |
104 # "How MATLAB Recognizes Command Syntax" specifies that an operator |
104 # is recognized if it is either surrounded by spaces or by no |
105 # is recognized if it is either surrounded by spaces or by no |
105 # spaces on both sides; only the former case matters for us. (This |
106 # spaces on both sides; only the former case matters for us. (This |
106 # allows distinguishing `cd ./foo` from `cd ./ foo`.) |
107 # allows distinguishing `cd ./foo` from `cd ./ foo`.) |
107 (r'(?:^|(?<=;))(\s*)(\w+)(\s+)(?!=|\(|(%s)\s+)' % _operators, |
108 (r'(?:^|(?<=;))(\s*)(\w+)(\s+)(?!=|\(|(?:%s)\s+)' % _operators, |
108 bygroups(Text, Name, Text), 'commandargs'), |
109 bygroups(Text, Name, Text), 'commandargs'), |
109 |
110 |
110 # operators: |
111 # operators: |
111 (_operators, Operator), |
112 (_operators, Operator), |
112 |
113 |