1package d
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Django/Jinja lexer.
9var DjangoJinja = internal.Register(MustNewLexer(
10 &Config{
11 Name: "Django/Jinja",
12 Aliases: []string{"django", "jinja"},
13 Filenames: []string{},
14 MimeTypes: []string{"application/x-django-templating", "application/x-jinja"},
15 DotAll: true,
16 },
17 Rules{
18 "root": {
19 {`[^{]+`, Other, nil},
20 {`\{\{`, CommentPreproc, Push("var")},
21 {`\{[*#].*?[*#]\}`, Comment, nil},
22 {`(\{%)(-?\s*)(comment)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endcomment)(\s*-?)(%\})`, ByGroups(CommentPreproc, Text, Keyword, Text, CommentPreproc, Comment, CommentPreproc, Text, Keyword, Text, CommentPreproc), nil},
23 {`(\{%)(-?\s*)(raw)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endraw)(\s*-?)(%\})`, ByGroups(CommentPreproc, Text, Keyword, Text, CommentPreproc, Text, CommentPreproc, Text, Keyword, Text, CommentPreproc), nil},
24 {`(\{%)(-?\s*)(filter)(\s+)([a-zA-Z_]\w*)`, ByGroups(CommentPreproc, Text, Keyword, Text, NameFunction), Push("block")},
25 {`(\{%)(-?\s*)([a-zA-Z_]\w*)`, ByGroups(CommentPreproc, Text, Keyword), Push("block")},
26 {`\{`, Other, nil},
27 },
28 "varnames": {
29 {`(\|)(\s*)([a-zA-Z_]\w*)`, ByGroups(Operator, Text, NameFunction), nil},
30 {`(is)(\s+)(not)?(\s+)?([a-zA-Z_]\w*)`, ByGroups(Keyword, Text, Keyword, Text, NameFunction), nil},
31 {`(_|true|false|none|True|False|None)\b`, KeywordPseudo, nil},
32 {`(in|as|reversed|recursive|not|and|or|is|if|else|import|with(?:(?:out)?\s*context)?|scoped|ignore\s+missing)\b`, Keyword, nil},
33 {`(loop|block|super|forloop)\b`, NameBuiltin, nil},
34 {`[a-zA-Z_][\w-]*`, NameVariable, nil},
35 {`\.\w+`, NameVariable, nil},
36 {`:?"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
37 {`:?'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
38 {`([{}()\[\]+\-*/,:~]|[><=]=?)`, Operator, nil},
39 {`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
40 },
41 "var": {
42 {`\s+`, Text, nil},
43 {`(-?)(\}\})`, ByGroups(Text, CommentPreproc), Pop(1)},
44 Include("varnames"),
45 },
46 "block": {
47 {`\s+`, Text, nil},
48 {`(-?)(%\})`, ByGroups(Text, CommentPreproc), Pop(1)},
49 Include("varnames"),
50 {`.`, Punctuation, nil},
51 },
52 },
53))