1package lexers
 2
 3import (
 4	. "github.com/alecthomas/chroma/v2" // nolint
 5)
 6
 7// Cheetah lexer.
 8var Cheetah = Register(MustNewLexer(
 9	&Config{
10		Name:      "Cheetah",
11		Aliases:   []string{"cheetah", "spitfire"},
12		Filenames: []string{"*.tmpl", "*.spt"},
13		MimeTypes: []string{"application/x-cheetah", "application/x-spitfire"},
14	},
15	cheetahRules,
16))
17
18func cheetahRules() Rules {
19	return Rules{
20		"root": {
21			{`(##[^\n]*)$`, ByGroups(Comment), nil},
22			{`#[*](.|\n)*?[*]#`, Comment, nil},
23			{`#end[^#\n]*(?:#|$)`, CommentPreproc, nil},
24			{`#slurp$`, CommentPreproc, nil},
25			{`(#[a-zA-Z]+)([^#\n]*)(#|$)`, ByGroups(CommentPreproc, Using("Python"), CommentPreproc), nil},
26			{`(\$)([a-zA-Z_][\w.]*\w)`, ByGroups(CommentPreproc, Using("Python")), nil},
27			{`(\$\{!?)(.*?)(\})(?s)`, ByGroups(CommentPreproc, Using("Python"), CommentPreproc), nil},
28			{`(?sx)
29                (.+?)               # anything, followed by:
30                (?:
31                 (?=\#[#a-zA-Z]*) | # an eval comment
32                 (?=\$[a-zA-Z_{]) | # a substitution
33                 \Z                 # end of string
34                )
35            `, Other, nil},
36			{`\s+`, Text, nil},
37		},
38	}
39}