summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/alecthomas/chroma/lexers/g/genshi.go
blob: 0d3663a0a92a3274a27546beacd3ae2cf45755c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package g

import (
	. "github.com/alecthomas/chroma" // nolint
	"github.com/alecthomas/chroma/lexers/internal"
	. "github.com/alecthomas/chroma/lexers/p"
)

// Genshi Text lexer.
var GenshiText = internal.Register(MustNewLexer(
	&Config{
		Name:      "Genshi Text",
		Aliases:   []string{"genshitext"},
		Filenames: []string{},
		MimeTypes: []string{"application/x-genshi-text", "text/x-genshi"},
	},
	Rules{
		"root": {
			{`[^#$\s]+`, Other, nil},
			{`^(\s*)(##.*)$`, ByGroups(Text, Comment), nil},
			{`^(\s*)(#)`, ByGroups(Text, CommentPreproc), Push("directive")},
			Include("variable"),
			{`[#$\s]`, Other, nil},
		},
		"directive": {
			{`\n`, Text, Pop(1)},
			{`(?:def|for|if)\s+.*`, Using(Python), Pop(1)},
			{`(choose|when|with)([^\S\n]+)(.*)`, ByGroups(Keyword, Text, Using(Python)), Pop(1)},
			{`(choose|otherwise)\b`, Keyword, Pop(1)},
			{`(end\w*)([^\S\n]*)(.*)`, ByGroups(Keyword, Text, Comment), Pop(1)},
		},
		"variable": {
			{`(?<!\$)(\$\{)(.+?)(\})`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
			{`(?<!\$)(\$)([a-zA-Z_][\w.]*)`, NameVariable, nil},
		},
	},
))

// Html+Genshi lexer.
var GenshiHTMLTemplate = internal.Register(MustNewLexer(
	&Config{
		Name:         "Genshi HTML",
		Aliases:      []string{"html+genshi", "html+kid"},
		Filenames:    []string{},
		MimeTypes:    []string{"text/html+genshi"},
		NotMultiline: true,
		DotAll:       true,
	},
	genshiMarkupRules,
))

// Genshi lexer.
var Genshi = internal.Register(MustNewLexer(
	&Config{
		Name:         "Genshi",
		Aliases:      []string{"genshi", "kid", "xml+genshi", "xml+kid"},
		Filenames:    []string{"*.kid"},
		MimeTypes:    []string{"application/x-genshi", "application/x-kid"},
		NotMultiline: true,
		DotAll:       true,
	},
	genshiMarkupRules,
))

var genshiMarkupRules = Rules{
	"root": {
		{`[^<$]+`, Other, nil},
		{`(<\?python)(.*?)(\?>)`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
		{`<\s*(script|style)\s*.*?>.*?<\s*/\1\s*>`, Other, nil},
		{`<\s*py:[a-zA-Z0-9]+`, NameTag, Push("pytag")},
		{`<\s*[a-zA-Z0-9:.]+`, NameTag, Push("tag")},
		Include("variable"),
		{`[<$]`, Other, nil},
	},
	"pytag": {
		{`\s+`, Text, nil},
		{`[\w:-]+\s*=`, NameAttribute, Push("pyattr")},
		{`/?\s*>`, NameTag, Pop(1)},
	},
	"pyattr": {
		{`(")(.*?)(")`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)},
		{`(')(.*?)(')`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)},
		{`[^\s>]+`, LiteralString, Pop(1)},
	},
	"tag": {
		{`\s+`, Text, nil},
		{`py:[\w-]+\s*=`, NameAttribute, Push("pyattr")},
		{`[\w:-]+\s*=`, NameAttribute, Push("attr")},
		{`/?\s*>`, NameTag, Pop(1)},
	},
	"attr": {
		{`"`, LiteralString, Push("attr-dstring")},
		{`'`, LiteralString, Push("attr-sstring")},
		{`[^\s>]*`, LiteralString, Pop(1)},
	},
	"attr-dstring": {
		{`"`, LiteralString, Pop(1)},
		Include("strings"),
		{`'`, LiteralString, nil},
	},
	"attr-sstring": {
		{`'`, LiteralString, Pop(1)},
		Include("strings"),
		{`'`, LiteralString, nil},
	},
	"strings": {
		{`[^"'$]+`, LiteralString, nil},
		Include("variable"),
	},
	"variable": {
		{`(?<!\$)(\$\{)(.+?)(\})`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
		{`(?<!\$)(\$)([a-zA-Z_][\w\.]*)`, NameVariable, nil},
	},
}