You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dtd.go 2.0KB

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