1 package m
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Mathematica = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Mathematica",
12 Aliases: []string{"mathematica", "mma", "nb"},
13 Filenames: []string{"*.nb", "*.cdf", "*.nbp", "*.ma"},
14 MimeTypes: []string{"application/mathematica", "application/vnd.wolfram.mathematica", "application/vnd.wolfram.mathematica.package", "application/vnd.wolfram.cdf"},
15 },
16 mathematicaRules,
17 ))
18
19 func mathematicaRules() Rules {
20 return Rules{
21 "root": {
22 {`(?s)\(\*.*?\*\)`, Comment, nil},
23 {"([a-zA-Z]+[A-Za-z0-9]*`)", NameNamespace, nil},
24 {`([A-Za-z0-9]*_+[A-Za-z0-9]*)`, NameVariable, nil},
25 {`#\d*`, NameVariable, nil},
26 {`([a-zA-Z]+[a-zA-Z0-9]*)`, Name, nil},
27 {`-?\d+\.\d*`, LiteralNumberFloat, nil},
28 {`-?\d*\.\d+`, LiteralNumberFloat, nil},
29 {`-?\d+`, LiteralNumberInteger, nil},
30 {Words(``, ``, `;;`, `=`, `=.`, `!===`, `:=`, `->`, `:>`, `/.`, `+`, `-`, `*`, `/`, `^`, `&&`, `||`, `!`, `<>`, `|`, `/;`, `?`, `@`, `//`, `/@`, `@@`, `@@@`, `~~`, `===`, `&`, `<`, `>`, `<=`, `>=`), Operator, nil},
31 {Words(``, ``, `,`, `;`, `(`, `)`, `[`, `]`, `{`, `}`), Punctuation, nil},
32 {`".*?"`, LiteralString, nil},
33 {`\s+`, TextWhitespace, nil},
34 },
35 }
36 }
37
View as plain text