1package g
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6 . "github.com/alecthomas/chroma/lexers/p"
7)
8
9// Genshi Text lexer.
10var GenshiText = internal.Register(MustNewLexer(
11 &Config{
12 Name: "Genshi Text",
13 Aliases: []string{"genshitext"},
14 Filenames: []string{},
15 MimeTypes: []string{"application/x-genshi-text", "text/x-genshi"},
16 },
17 Rules{
18 "root": {
19 {`[^#$\s]+`, Other, nil},
20 {`^(\s*)(##.*)$`, ByGroups(Text, Comment), nil},
21 {`^(\s*)(#)`, ByGroups(Text, CommentPreproc), Push("directive")},
22 Include("variable"),
23 {`[#$\s]`, Other, nil},
24 },
25 "directive": {
26 {`\n`, Text, Pop(1)},
27 {`(?:def|for|if)\s+.*`, Using(Python), Pop(1)},
28 {`(choose|when|with)([^\S\n]+)(.*)`, ByGroups(Keyword, Text, Using(Python)), Pop(1)},
29 {`(choose|otherwise)\b`, Keyword, Pop(1)},
30 {`(end\w*)([^\S\n]*)(.*)`, ByGroups(Keyword, Text, Comment), Pop(1)},
31 },
32 "variable": {
33 {`(?<!\$)(\$\{)(.+?)(\})`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
34 {`(?<!\$)(\$)([a-zA-Z_][\w.]*)`, NameVariable, nil},
35 },
36 },
37))
38
39// Html+Genshi lexer.
40var GenshiHTMLTemplate = internal.Register(MustNewLexer(
41 &Config{
42 Name: "Genshi HTML",
43 Aliases: []string{"html+genshi", "html+kid"},
44 Filenames: []string{},
45 MimeTypes: []string{"text/html+genshi"},
46 NotMultiline: true,
47 DotAll: true,
48 },
49 genshiMarkupRules,
50))
51
52// Genshi lexer.
53var Genshi = internal.Register(MustNewLexer(
54 &Config{
55 Name: "Genshi",
56 Aliases: []string{"genshi", "kid", "xml+genshi", "xml+kid"},
57 Filenames: []string{"*.kid"},
58 MimeTypes: []string{"application/x-genshi", "application/x-kid"},
59 NotMultiline: true,
60 DotAll: true,
61 },
62 genshiMarkupRules,
63))
64
65var genshiMarkupRules = Rules{
66 "root": {
67 {`[^<$]+`, Other, nil},
68 {`(<\?python)(.*?)(\?>)`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
69 {`<\s*(script|style)\s*.*?>.*?<\s*/\1\s*>`, Other, nil},
70 {`<\s*py:[a-zA-Z0-9]+`, NameTag, Push("pytag")},
71 {`<\s*[a-zA-Z0-9:.]+`, NameTag, Push("tag")},
72 Include("variable"),
73 {`[<$]`, Other, nil},
74 },
75 "pytag": {
76 {`\s+`, Text, nil},
77 {`[\w:-]+\s*=`, NameAttribute, Push("pyattr")},
78 {`/?\s*>`, NameTag, Pop(1)},
79 },
80 "pyattr": {
81 {`(")(.*?)(")`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)},
82 {`(')(.*?)(')`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)},
83 {`[^\s>]+`, LiteralString, Pop(1)},
84 },
85 "tag": {
86 {`\s+`, Text, nil},
87 {`py:[\w-]+\s*=`, NameAttribute, Push("pyattr")},
88 {`[\w:-]+\s*=`, NameAttribute, Push("attr")},
89 {`/?\s*>`, NameTag, Pop(1)},
90 },
91 "attr": {
92 {`"`, LiteralString, Push("attr-dstring")},
93 {`'`, LiteralString, Push("attr-sstring")},
94 {`[^\s>]*`, LiteralString, Pop(1)},
95 },
96 "attr-dstring": {
97 {`"`, LiteralString, Pop(1)},
98 Include("strings"),
99 {`'`, LiteralString, nil},
100 },
101 "attr-sstring": {
102 {`'`, LiteralString, Pop(1)},
103 Include("strings"),
104 {`'`, LiteralString, nil},
105 },
106 "strings": {
107 {`[^"'$]+`, LiteralString, nil},
108 Include("variable"),
109 },
110 "variable": {
111 {`(?<!\$)(\$\{)(.+?)(\})`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
112 {`(?<!\$)(\$)([a-zA-Z_][\w\.]*)`, NameVariable, nil},
113 },
114}