1 package t
2
3 import (
4 . "github.com/alecthomas/chroma"
5 "github.com/alecthomas/chroma/lexers/internal"
6 )
7
8
9 var Twig = internal.Register(MustNewLazyLexer(
10 &Config{
11 Name: "Twig",
12 Aliases: []string{"twig"},
13 Filenames: []string{},
14 MimeTypes: []string{"application/x-twig"},
15 DotAll: true,
16 },
17 twigRules,
18 ))
19
20 func twigRules() Rules {
21 return Rules{
22 "root": {
23 {`[^{]+`, Other, nil},
24 {`\{\{`, CommentPreproc, Push("var")},
25 {`\{\#.*?\#\}`, Comment, nil},
26 {`(\{%)(-?\s*)(raw)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endraw)(\s*-?)(%\})`, ByGroups(CommentPreproc, Text, Keyword, Text, CommentPreproc, Other, CommentPreproc, Text, Keyword, Text, CommentPreproc), nil},
27 {`(\{%)(-?\s*)(verbatim)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endverbatim)(\s*-?)(%\})`, ByGroups(CommentPreproc, Text, Keyword, Text, CommentPreproc, Other, CommentPreproc, Text, Keyword, Text, CommentPreproc), nil},
28 {`(\{%)(-?\s*)(filter)(\s+)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*)`, ByGroups(CommentPreproc, Text, Keyword, Text, NameFunction), Push("tag")},
29 {`(\{%)(-?\s*)([a-zA-Z_]\w*)`, ByGroups(CommentPreproc, Text, Keyword), Push("tag")},
30 {`\{`, Other, nil},
31 },
32 "varnames": {
33 {`(\|)(\s*)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*)`, ByGroups(Operator, Text, NameFunction), nil},
34 {`(is)(\s+)(not)?(\s*)((?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*)`, ByGroups(Keyword, Text, Keyword, Text, NameFunction), nil},
35 {`(?i)(true|false|none|null)\b`, KeywordPseudo, nil},
36 {`(in|not|and|b-and|or|b-or|b-xor|isif|elseif|else|importconstant|defined|divisibleby|empty|even|iterable|odd|sameasmatches|starts\s+with|ends\s+with)\b`, Keyword, nil},
37 {`(loop|block|parent)\b`, NameBuiltin, nil},
38 {`(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*`, NameVariable, nil},
39 {`\.(?:[\\_a-z]|[^\x00-\x7f])(?:[\\\w-]|[^\x00-\x7f])*`, NameVariable, nil},
40 {`\.[0-9]+`, LiteralNumber, nil},
41 {`:?"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
42 {`:?'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
43 {`([{}()\[\]+\-*/,:~%]|\.\.|\?|:|\*\*|\/\/|!=|[><=]=?)`, Operator, nil},
44 {`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
45 },
46 "var": {
47 {`\s+`, Text, nil},
48 {`(-?)(\}\})`, ByGroups(Text, CommentPreproc), Pop(1)},
49 Include("varnames"),
50 },
51 "tag": {
52 {`\s+`, Text, nil},
53 {`(-?)(%\})`, ByGroups(Text, CommentPreproc), Pop(1)},
54 Include("varnames"),
55 {`.`, Punctuation, nil},
56 },
57 }
58 }
59
View as plain text