dtd.go

 1package d
 2
 3import (
 4	. "github.com/alecthomas/chroma" // nolint
 5	"github.com/alecthomas/chroma/lexers/internal"
 6)
 7
 8// Dtd lexer.
 9var Dtd = internal.Register(MustNewLexer(
10	&Config{
11		Name:      "DTD",
12		Aliases:   []string{"dtd"},
13		Filenames: []string{"*.dtd"},
14		MimeTypes: []string{"application/xml-dtd"},
15		DotAll:    true,
16	},
17	Rules{
18		"root": {
19			Include("common"),
20			{`(<!ELEMENT)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("element")},
21			{`(<!ATTLIST)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("attlist")},
22			{`(<!ENTITY)(\s+)(\S+)`, ByGroups(Keyword, Text, NameEntity), Push("entity")},
23			{`(<!NOTATION)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("notation")},
24			{`(<!\[)([^\[\s]+)(\s*)(\[)`, ByGroups(Keyword, NameEntity, Text, Keyword), nil},
25			{`(<!DOCTYPE)(\s+)([^>\s]+)`, ByGroups(Keyword, Text, NameTag), nil},
26			{`PUBLIC|SYSTEM`, KeywordConstant, nil},
27			{`[\[\]>]`, Keyword, nil},
28		},
29		"common": {
30			{`\s+`, Text, nil},
31			{`(%|&)[^;]*;`, NameEntity, nil},
32			{`<!--`, Comment, Push("comment")},
33			{`[(|)*,?+]`, Operator, nil},
34			{`"[^"]*"`, LiteralStringDouble, nil},
35			{`\'[^\']*\'`, LiteralStringSingle, nil},
36		},
37		"comment": {
38			{`[^-]+`, Comment, nil},
39			{`-->`, Comment, Pop(1)},
40			{`-`, Comment, nil},
41		},
42		"element": {
43			Include("common"),
44			{`EMPTY|ANY|#PCDATA`, KeywordConstant, nil},
45			{`[^>\s|()?+*,]+`, NameTag, nil},
46			{`>`, Keyword, Pop(1)},
47		},
48		"attlist": {
49			Include("common"),
50			{`CDATA|IDREFS|IDREF|ID|NMTOKENS|NMTOKEN|ENTITIES|ENTITY|NOTATION`, KeywordConstant, nil},
51			{`#REQUIRED|#IMPLIED|#FIXED`, KeywordConstant, nil},
52			{`xml:space|xml:lang`, KeywordReserved, nil},
53			{`[^>\s|()?+*,]+`, NameAttribute, nil},
54			{`>`, Keyword, Pop(1)},
55		},
56		"entity": {
57			Include("common"),
58			{`SYSTEM|PUBLIC|NDATA`, KeywordConstant, nil},
59			{`[^>\s|()?+*,]+`, NameEntity, nil},
60			{`>`, Keyword, Pop(1)},
61		},
62		"notation": {
63			Include("common"),
64			{`SYSTEM|PUBLIC`, KeywordConstant, nil},
65			{`[^>\s|()?+*,]+`, NameAttribute, nil},
66			{`>`, Keyword, Pop(1)},
67		},
68	},
69))