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