1package lexers
 2
 3import (
 4	. "github.com/alecthomas/chroma/v2" // nolint
 5)
 6
 7// Mako lexer.
 8var Mako = Register(MustNewLexer(
 9	&Config{
10		Name:      "Mako",
11		Aliases:   []string{"mako"},
12		Filenames: []string{"*.mao"},
13		MimeTypes: []string{"application/x-mako"},
14	},
15	makoRules,
16))
17
18func makoRules() Rules {
19	return Rules{
20		"root": {
21			{`(\s*)(%)(\s*end(?:\w+))(\n|\Z)`, ByGroups(Text, CommentPreproc, Keyword, Other), nil},
22			{`(\s*)(%)([^\n]*)(\n|\Z)`, ByGroups(Text, CommentPreproc, Using("Python"), Other), nil},
23			{`(\s*)(##[^\n]*)(\n|\Z)`, ByGroups(Text, CommentPreproc, Other), nil},
24			{`(?s)<%doc>.*?</%doc>`, CommentPreproc, nil},
25			{`(<%)([\w.:]+)`, ByGroups(CommentPreproc, NameBuiltin), Push("tag")},
26			{`(</%)([\w.:]+)(>)`, ByGroups(CommentPreproc, NameBuiltin, CommentPreproc), nil},
27			{`<%(?=([\w.:]+))`, CommentPreproc, Push("ondeftags")},
28			{`(<%(?:!?))(.*?)(%>)(?s)`, ByGroups(CommentPreproc, Using("Python"), CommentPreproc), nil},
29			{`(\$\{)(.*?)(\})`, ByGroups(CommentPreproc, Using("Python"), CommentPreproc), nil},
30			{`(?sx)
31                (.+?)                # anything, followed by:
32                (?:
33                 (?<=\n)(?=%|\#\#) | # an eval or comment line
34                 (?=\#\*) |          # multiline comment
35                 (?=</?%) |          # a python block
36                                     # call start or end
37                 (?=\$\{) |          # a substitution
38                 (?<=\n)(?=\s*%) |
39                                     # - don't consume
40                 (\\\n) |            # an escaped newline
41                 \Z                  # end of string
42                )
43            `, ByGroups(Other, Operator), nil},
44			{`\s+`, Text, nil},
45		},
46		"ondeftags": {
47			{`<%`, CommentPreproc, nil},
48			{`(?<=<%)(include|inherit|namespace|page)`, NameBuiltin, nil},
49			Include("tag"),
50		},
51		"tag": {
52			{`((?:\w+)\s*=)(\s*)(".*?")`, ByGroups(NameAttribute, Text, LiteralString), nil},
53			{`/?\s*>`, CommentPreproc, Pop(1)},
54			{`\s+`, Text, nil},
55		},
56		"attr": {
57			{`".*?"`, LiteralString, Pop(1)},
58			{`'.*?'`, LiteralString, Pop(1)},
59			{`[^\s>]+`, LiteralString, Pop(1)},
60		},
61	}
62}