bibtex.grammar 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. @top Bibliography {
  2. (Declaration | StringDeclaration)*
  3. }
  4. @tokens {
  5. whiteSpace { @whitespace+ }
  6. Identifier { $[a-zA-Z:_0-9-]+ }
  7. StringName { $[a-zA-Z:_] $[a-zA-Z:_0-9-]* }
  8. FieldName {$[a-zA-Z-_0-9]+}
  9. LiteralString {
  10. '"' (!["] | "\\" _)* '"'?
  11. }
  12. EntryTypeName { $[a-zA-Z]+ }
  13. Number { @digit+ }
  14. StringKeyword {"@"$[Ss]$[Tt]$[Rr]$[Ii]$[Nn]$[Gg]}
  15. "@" "{" "}" "\"" "," "#" "@string"
  16. Comment { "%" ![\n]* }
  17. }
  18. // FIXME: Technically skipping comments is wrong here. They can only appear
  19. // alone on a line, but I'm not sure how to express that easily in Lezer
  20. @skip {whiteSpace | Comment}
  21. StringDeclaration {
  22. StringKeyword "{"
  23. Field<StringName>*
  24. "}"
  25. }
  26. Declaration {
  27. EntryName { "@" EntryTypeName } "{"
  28. Identifier
  29. fieldEntry {
  30. ("," Field<FieldName> )
  31. }*
  32. ("," )?
  33. "}"
  34. }
  35. Field<Name> {
  36. Name "=" Expression
  37. }
  38. Expression {
  39. BracedString |
  40. Number |
  41. StringConcatenation
  42. }
  43. @local tokens {
  44. openBracedContents {"{"}
  45. closeBracedContents {"}"}
  46. @else nonClosingBracedContents
  47. }
  48. @skip {}{
  49. bracedStringContents {
  50. (
  51. nonClosingBracedContents |
  52. nestedBracedString {
  53. openBracedContents
  54. bracedStringContents
  55. closeBracedContents
  56. }
  57. )*
  58. }
  59. BracedString {
  60. "{"
  61. bracedStringContents closeBracedContents
  62. }
  63. }
  64. // TODO: Implement this
  65. @precedence { concatenation @left }
  66. StringConcatenation {
  67. StringConcatenation !concatenation "#" StringConcatenation |
  68. LiteralString |
  69. StringName
  70. }
  71. @external propSource highlighting from "./highlight.mjs"