elm.go

 1package e
 2
 3import (
 4	. "github.com/alecthomas/chroma" // nolint
 5	"github.com/alecthomas/chroma/lexers/internal"
 6)
 7
 8// Elm lexer.
 9var Elm = internal.Register(MustNewLexer(
10	&Config{
11		Name:      "Elm",
12		Aliases:   []string{"elm"},
13		Filenames: []string{"*.elm"},
14		MimeTypes: []string{"text/x-elm"},
15	},
16	Rules{
17		"root": {
18			{`\{-`, CommentMultiline, Push("comment")},
19			{`--.*`, CommentSingle, nil},
20			{`\s+`, Text, nil},
21			{`"`, LiteralString, Push("doublequote")},
22			{`^\s*module\s*`, KeywordNamespace, Push("imports")},
23			{`^\s*import\s*`, KeywordNamespace, Push("imports")},
24			{`\[glsl\|.*`, NameEntity, Push("shader")},
25			{Words(``, `\b`, `alias`, `as`, `case`, `else`, `if`, `import`, `in`, `let`, `module`, `of`, `port`, `then`, `type`, `where`), KeywordReserved, nil},
26			{`[A-Z]\w*`, KeywordType, nil},
27			{`^main `, KeywordReserved, nil},
28			{Words(`\(`, `\)`, `~`, `||`, `|>`, `|`, "`", `^`, `\`, `'`, `>>`, `>=`, `>`, `==`, `=`, `<~`, `<|`, `<=`, `<<`, `<-`, `<`, `::`, `:`, `/=`, `//`, `/`, `..`, `.`, `->`, `-`, `++`, `+`, `*`, `&&`, `%`), NameFunction, nil},
29			{Words(``, ``, `~`, `||`, `|>`, `|`, "`", `^`, `\`, `'`, `>>`, `>=`, `>`, `==`, `=`, `<~`, `<|`, `<=`, `<<`, `<-`, `<`, `::`, `:`, `/=`, `//`, `/`, `..`, `.`, `->`, `-`, `++`, `+`, `*`, `&&`, `%`), NameFunction, nil},
30			Include("numbers"),
31			{`[a-z_][a-zA-Z_\']*`, NameVariable, nil},
32			{`[,()\[\]{}]`, Punctuation, nil},
33		},
34		"comment": {
35			{`-(?!\})`, CommentMultiline, nil},
36			{`\{-`, CommentMultiline, Push("comment")},
37			{`[^-}]`, CommentMultiline, nil},
38			{`-\}`, CommentMultiline, Pop(1)},
39		},
40		"doublequote": {
41			{`\\u[0-9a-fA-F]{4}`, LiteralStringEscape, nil},
42			{`\\[nrfvb\\"]`, LiteralStringEscape, nil},
43			{`[^"]`, LiteralString, nil},
44			{`"`, LiteralString, Pop(1)},
45		},
46		"imports": {
47			{`\w+(\.\w+)*`, NameClass, Pop(1)},
48		},
49		"numbers": {
50			{`_?\d+\.(?=\d+)`, LiteralNumberFloat, nil},
51			{`_?\d+`, LiteralNumberInteger, nil},
52		},
53		"shader": {
54			{`\|(?!\])`, NameEntity, nil},
55			{`\|\]`, NameEntity, Pop(1)},
56			{`.*\n`, NameEntity, nil},
57		},
58	},
59))