bibtex.grammar 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. @tokens {
  2. whiteSpace { $[\t\n ]+ }
  3. // Anything outside of an entry at the top level is a BibTeX free-form comment
  4. Junk { ![@ \t\n%] ![@]* }
  5. // BibLaTeX supports comments starting with a % and extending to the end of
  6. // the line
  7. Comment { "%" ![\n]* }
  8. // See https://metacpan.org/release/AMBS/Text-BibTeX-0.91/view/btparse/doc/bt_language.pod
  9. identifierSymbol { $[!$&*+./:;<>?^`_|] | "[" | "]" | "-" }
  10. identifier {
  11. (@asciiLetter | identifierSymbol)
  12. (@asciiLetter | @digit | identifierSymbol)*
  13. }
  14. EntryType { identifier }
  15. // Citation keys can start with a digit
  16. CitationKey { (@asciiLetter | @digit | identifierSymbol)+ }
  17. NumberLiteral { @digit+ }
  18. "#" "="
  19. }
  20. @external specialize {EntryType} specializeEntryType from "./tokens.mjs" {
  21. stringKeyword,
  22. preambleKeyword,
  23. commentKeyword
  24. }
  25. @skip { whiteSpace | Comment }
  26. @top Bibliography {
  27. (Junk | Entry | CommentEntry | PreambleEntry | StringEntry)*
  28. }
  29. StringEntry { StringCommand StringBody }
  30. PreambleEntry { PreambleCommand PreambleBody }
  31. CommentEntry { CommentCommand CommentBody }
  32. Entry { EntryCommand EntryBody }
  33. EntryCommand { "@" EntryType }
  34. EntryBody { commandBody<entryContents> }
  35. StringCommand { "@" stringKeyword }
  36. StringBody { commandBody<fields> }
  37. PreambleCommand { "@" preambleKeyword }
  38. PreambleBody { commandBody<Value> }
  39. CommentCommand { "@" commentKeyword }
  40. commandBody<contents> {
  41. (
  42. BodyOpen[closedBy="BodyClose"] { "{" }
  43. contents
  44. BodyClose[openedBy="BodyOpen"] { "}" }
  45. ) | (
  46. BodyOpen[closedBy="BodyClose"] { "(" }
  47. contents
  48. BodyClose[openedBy="BodyOpen"] { ")" }
  49. )
  50. }
  51. entryContents { CitationKey ("," fields)? }
  52. fields { (Field ("," Field)* ","?)? }
  53. Field { FieldName "=" Value }
  54. FieldName { identifier }
  55. Value { simpleValue ("#" simpleValue)* }
  56. simpleValue { StringLiteral | NumberLiteral | StringName }
  57. StringName { identifier }
  58. @local tokens {
  59. strOpenBrace { "{" }
  60. strCloseBrace { "}" }
  61. strOpenParen { "(" }
  62. strCloseParen { ")" }
  63. strQuote { "\"" }
  64. @else strOther
  65. }
  66. @skip {} {
  67. StringLiteral {
  68. (
  69. StringOpen[closedBy="StringClose"] { "\"" }
  70. StringContents { quotedStringContents }
  71. StringClose[openedBy="StringOpen"] { strQuote }
  72. ) | (
  73. StringOpen[closedBy="StringClose"] { "{" }
  74. StringContents { bracedStringContents }
  75. StringClose[openedBy="StringOpen"] { strCloseBrace }
  76. )
  77. }
  78. CommentBody {
  79. (
  80. BodyOpen[closedBy="BodyClose"] { "{" }
  81. CommentContents { bracedStringContents }
  82. BodyClose[openedBy="BodyOpen"] { strCloseBrace }
  83. ) | (
  84. BodyOpen[closedBy="BodyClose"] { "(" }
  85. CommentContents { parenthesizedStringContents }
  86. BodyClose[openedBy="BodyOpen"] { strCloseParen }
  87. )
  88. }
  89. quotedStringContents {
  90. (
  91. strOpenBrace bracedStringContents strCloseBrace |
  92. strOpenParen |
  93. strCloseParen |
  94. strCloseBrace |
  95. strOther
  96. )*
  97. }
  98. parenthesizedStringContents {
  99. (
  100. strOpenBrace bracedStringContents strCloseBrace |
  101. strQuote |
  102. strOpenParen |
  103. strCloseBrace |
  104. strOther
  105. )*
  106. }
  107. bracedStringContents {
  108. (
  109. strOpenBrace bracedStringContents strCloseBrace |
  110. strQuote |
  111. strOpenParen |
  112. strCloseParen |
  113. strOther
  114. )*
  115. }
  116. }
  117. @external propSource highlighting from "./highlight.mjs"