1 package m
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Matlab = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Matlab",
12 Aliases: []string{"matlab"},
13 Filenames: []string{"*.m"},
14 MimeTypes: []string{"text/matlab"},
15 },
16 matlabRules,
17 ))
18
19 func matlabRules() Rules {
20 return Rules{
21 "root": {
22 {`\n`, Text, nil},
23 {`^!.*`, LiteralStringOther, nil},
24 {`%\{\s*\n`, CommentMultiline, Push("blockcomment")},
25 {`%.*$`, Comment, nil},
26 {`^\s*function`, Keyword, Push("deffunc")},
27 {Words(``, `\b`, `break`, `case`, `catch`, `classdef`, `continue`, `else`, `elseif`, `end`, `enumerated`, `events`, `for`, `function`, `global`, `if`, `methods`, `otherwise`, `parfor`, `persistent`, `properties`, `return`, `spmd`, `switch`, `try`, `while`), Keyword, nil},
28 {`(sin|sind|sinh|asin|asind|asinh|cos|cosd|cosh|acos|acosd|acosh|tan|tand|tanh|atan|atand|atan2|atanh|sec|secd|sech|asec|asecd|asech|csc|cscd|csch|acsc|acscd|acsch|cot|cotd|coth|acot|acotd|acoth|hypot|exp|expm1|log|log1p|log10|log2|pow2|realpow|reallog|realsqrt|sqrt|nthroot|nextpow2|abs|angle|complex|conj|imag|real|unwrap|isreal|cplxpair|fix|floor|ceil|round|mod|rem|sign|airy|besselj|bessely|besselh|besseli|besselk|beta|betainc|betaln|ellipj|ellipke|erf|erfc|erfcx|erfinv|expint|gamma|gammainc|gammaln|psi|legendre|cross|dot|factor|isprime|primes|gcd|lcm|rat|rats|perms|nchoosek|factorial|cart2sph|cart2pol|pol2cart|sph2cart|hsv2rgb|rgb2hsv|zeros|ones|eye|repmat|rand|randn|linspace|logspace|freqspace|meshgrid|accumarray|size|length|ndims|numel|disp|isempty|isequal|isequalwithequalnans|cat|reshape|diag|blkdiag|tril|triu|fliplr|flipud|flipdim|rot90|find|end|sub2ind|ind2sub|bsxfun|ndgrid|permute|ipermute|shiftdim|circshift|squeeze|isscalar|isvector|ans|eps|realmax|realmin|pi|i|inf|nan|isnan|isinf|isfinite|j|why|compan|gallery|hadamard|hankel|hilb|invhilb|magic|pascal|rosser|toeplitz|vander|wilkinson)\b`, NameBuiltin, nil},
29 {`\.\.\..*$`, Comment, nil},
30 {`-|==|~=|<|>|<=|>=|&&|&|~|\|\|?`, Operator, nil},
31 {`\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\`, Operator, nil},
32 {`\[|\]|\(|\)|\{|\}|:|@|\.|,`, Punctuation, nil},
33 {`=|:|;`, Punctuation, nil},
34 {`(?<=[\w)\].])\'+`, Operator, nil},
35 {`(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?`, LiteralNumberFloat, nil},
36 {`\d+[eEf][+-]?[0-9]+`, LiteralNumberFloat, nil},
37 {`\d+`, LiteralNumberInteger, nil},
38 {`(?<![\w)\].])\'`, LiteralString, Push("string")},
39 {`[a-zA-Z_]\w*`, Name, nil},
40 {`.`, Text, nil},
41 },
42 "string": {
43 {`[^\']*\'`, LiteralString, Pop(1)},
44 },
45 "blockcomment": {
46 {`^\s*%\}`, CommentMultiline, Pop(1)},
47 {`^.*\n`, CommentMultiline, nil},
48 {`.`, CommentMultiline, nil},
49 },
50 "deffunc": {
51 {`(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)`, ByGroups(TextWhitespace, Text, TextWhitespace, Punctuation, TextWhitespace, NameFunction, Punctuation, Text, Punctuation, TextWhitespace), Pop(1)},
52 {`(\s*)([a-zA-Z_]\w*)`, ByGroups(Text, NameFunction), Pop(1)},
53 },
54 }
55 }
56
View as plain text