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.

bibtex.go 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package b
  2. import (
  3. . "github.com/alecthomas/chroma" // nolint
  4. "github.com/alecthomas/chroma/lexers/internal"
  5. )
  6. // Bibtex lexer.
  7. var Bibtex = internal.Register(MustNewLexer(
  8. &Config{
  9. Name: "BibTeX",
  10. Aliases: []string{"bib", "bibtex"},
  11. Filenames: []string{"*.bib"},
  12. MimeTypes: []string{"text/x-bibtex"},
  13. NotMultiline: true,
  14. CaseInsensitive: true,
  15. },
  16. Rules{
  17. "root": {
  18. Include("whitespace"),
  19. {`@comment`, Comment, nil},
  20. {`@preamble`, NameClass, Push("closing-brace", "value", "opening-brace")},
  21. {`@string`, NameClass, Push("closing-brace", "field", "opening-brace")},
  22. {"@[a-z_@!$&*+\\-./:;<>?\\[\\\\\\]^`|~][\\w@!$&*+\\-./:;<>?\\[\\\\\\]^`|~]*", NameClass, Push("closing-brace", "command-body", "opening-brace")},
  23. {`.+`, Comment, nil},
  24. },
  25. "opening-brace": {
  26. Include("whitespace"),
  27. {`[{(]`, Punctuation, Pop(1)},
  28. },
  29. "closing-brace": {
  30. Include("whitespace"),
  31. {`[})]`, Punctuation, Pop(1)},
  32. },
  33. "command-body": {
  34. Include("whitespace"),
  35. {`[^\s\,\}]+`, NameLabel, Push("#pop", "fields")},
  36. },
  37. "fields": {
  38. Include("whitespace"),
  39. {`,`, Punctuation, Push("field")},
  40. Default(Pop(1)),
  41. },
  42. "field": {
  43. Include("whitespace"),
  44. {"[a-z_@!$&*+\\-./:;<>?\\[\\\\\\]^`|~][\\w@!$&*+\\-./:;<>?\\[\\\\\\]^`|~]*", NameAttribute, Push("value", "=")},
  45. Default(Pop(1)),
  46. },
  47. "=": {
  48. Include("whitespace"),
  49. {`=`, Punctuation, Pop(1)},
  50. },
  51. "value": {
  52. Include("whitespace"),
  53. {"[a-z_@!$&*+\\-./:;<>?\\[\\\\\\]^`|~][\\w@!$&*+\\-./:;<>?\\[\\\\\\]^`|~]*", NameVariable, nil},
  54. {`"`, LiteralString, Push("quoted-string")},
  55. {`\{`, LiteralString, Push("braced-string")},
  56. {`[\d]+`, LiteralNumber, nil},
  57. {`#`, Punctuation, nil},
  58. Default(Pop(1)),
  59. },
  60. "quoted-string": {
  61. {`\{`, LiteralString, Push("braced-string")},
  62. {`"`, LiteralString, Pop(1)},
  63. {`[^\{\"]+`, LiteralString, nil},
  64. },
  65. "braced-string": {
  66. {`\{`, LiteralString, Push()},
  67. {`\}`, LiteralString, Pop(1)},
  68. {`[^\{\}]+`, LiteralString, nil},
  69. },
  70. "whitespace": {
  71. {`\s+`, Text, nil},
  72. },
  73. },
  74. ))