...

Source file src/github.com/alecthomas/chroma/lexers/d/dtd.go

Documentation: github.com/alecthomas/chroma/lexers/d

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

View as plain text