bibtex.grammar 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. "{"[closedBy="}"]
  16. "}"[openedBy="{"]
  17. "@" "\"" "," "#" "@string"
  18. Comment { "%" ![\n]* }
  19. }
  20. // FIXME: Technically skipping comments is wrong here. They can only appear
  21. // alone on a line, but I'm not sure how to express that easily in Lezer
  22. @skip {whiteSpace | Comment}
  23. StringDeclaration {
  24. StringKeyword "{"
  25. Field<StringName>*
  26. "}"
  27. }
  28. Declaration {
  29. EntryName { "@" EntryTypeName } "{"
  30. Identifier
  31. fieldEntry {
  32. ("," Field<FieldName> )
  33. }*
  34. ("," )?
  35. "}"
  36. }
  37. Field<Name> {
  38. Name "=" Expression
  39. }
  40. Expression {
  41. BracedString |
  42. Number |
  43. StringConcatenation
  44. }
  45. @local tokens {
  46. OpenBracedContents[closedBy="}", @name="{"] {"{"}
  47. CloseBracedContents[openedBy="{", @name="}"] {"}"}
  48. @else nonClosingBracedContents
  49. }
  50. @skip {}{
  51. bracedStringContents {
  52. (
  53. nonClosingBracedContents |
  54. nestedBracedString {
  55. OpenBracedContents
  56. bracedStringContents
  57. CloseBracedContents
  58. }
  59. )*
  60. }
  61. BracedString {
  62. "{" bracedStringContents CloseBracedContents
  63. }
  64. }
  65. @precedence { concatenation @left }
  66. StringConcatenation {
  67. StringConcatenation !concatenation "#" StringConcatenation |
  68. LiteralString |
  69. StringName
  70. }
  71. @external propSource highlighting from "./highlight.mjs"