cheetah.go

 1package c
 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// Cheetah lexer.
10var Cheetah = internal.Register(MustNewLexer(
11	&Config{
12		Name:      "Cheetah",
13		Aliases:   []string{"cheetah", "spitfire"},
14		Filenames: []string{"*.tmpl", "*.spt"},
15		MimeTypes: []string{"application/x-cheetah", "application/x-spitfire"},
16	},
17	Rules{
18		"root": {
19			{`(##[^\n]*)$`, ByGroups(Comment), nil},
20			{`#[*](.|\n)*?[*]#`, Comment, nil},
21			{`#end[^#\n]*(?:#|$)`, CommentPreproc, nil},
22			{`#slurp$`, CommentPreproc, nil},
23			{`(#[a-zA-Z]+)([^#\n]*)(#|$)`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
24			{`(\$)([a-zA-Z_][\w.]*\w)`, ByGroups(CommentPreproc, Using(Python)), nil},
25			{`(\$\{!?)(.*?)(\})(?s)`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
26			{`(?sx)
27                (.+?)               # anything, followed by:
28                (?:
29                 (?=\#[#a-zA-Z]*) | # an eval comment
30                 (?=\$[a-zA-Z_{]) | # a substitution
31                 \Z                 # end of string
32                )
33            `, Other, nil},
34			{`\s+`, Text, nil},
35		},
36	},
37))