Merge pull request #13572 from overleaf/mj-bibtex-grammar

[cm6] Add support for bibtex

GitOrigin-RevId: 28bc8e47c53df1612c1e30cf690e893b0bbf500c
This commit is contained in:
Mathias Jakobsen
2023-07-17 10:47:59 +00:00
committed by Copybot
parent e5d6777211
commit 67e7621633
15 changed files with 413 additions and 101 deletions
@@ -0,0 +1,85 @@
@top Bibliography {
(Declaration | StringDeclaration)*
}
@tokens {
whiteSpace { @whitespace+ }
Identifier { $[a-zA-Z:_0-9-]+ }
StringName { $[a-zA-Z:_] $[a-zA-Z:_0-9-]* }
FieldName {$[a-zA-Z-_0-9]+}
LiteralString {
'"' (!["] | "\\" _)* '"'?
}
EntryTypeName { $[a-zA-Z]+ }
Number { @digit+ }
StringKeyword {"@"$[Ss]$[Tt]$[Rr]$[Ii]$[Nn]$[Gg]}
"@" "{" "}" "\"" "," "#" "@string"
Comment { "%" ![\n]* }
}
// FIXME: Technically skipping comments is wrong here. They can only appear
// alone on a line, but I'm not sure how to express that easily in Lezer
@skip {whiteSpace | Comment}
StringDeclaration {
StringKeyword "{"
Field<StringName>*
"}"
}
Declaration {
EntryName { "@" EntryTypeName } "{"
Identifier
fieldEntry {
("," Field<FieldName> )
}*
("," )?
"}"
}
Field<Name> {
Name "=" Expression
}
Expression {
BracedString |
Number |
StringConcatenation
}
@local tokens {
openBracedContents {"{"}
closeBracedContents {"}"}
@else nonClosingBracedContents
}
@skip {}{
bracedStringContents {
(
nonClosingBracedContents |
nestedBracedString {
openBracedContents
bracedStringContents
closeBracedContents
}
)*
}
BracedString {
"{"
bracedStringContents closeBracedContents
}
}
// TODO: Implement this
@precedence { concatenation @left }
StringConcatenation {
StringConcatenation !concatenation "#" StringConcatenation |
LiteralString |
StringName
}
@external propSource highlighting from "./highlight.mjs"
@@ -0,0 +1,15 @@
import { styleTags, tags as t } from '@lezer/highlight'
export const highlighting = styleTags({
LiteralString: t.string,
'BracedString/...': t.string,
Number: t.number,
Identifier: t.name,
'EntryName/...': t.keyword,
FieldName: t.attributeName,
Expression: t.attributeValue,
'#': t.operator,
StringKeyword: t.keyword,
StringName: t.variableName,
Comment: t.comment,
})