mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-29 20:11:32 +02:00
Merge pull request #13572 from overleaf/mj-bibtex-grammar
[cm6] Add support for bibtex GitOrigin-RevId: 28bc8e47c53df1612c1e30cf690e893b0bbf500c
This commit is contained in:
committed by
Copybot
parent
e5d6777211
commit
67e7621633
@@ -2,23 +2,39 @@ const { buildParserFile } = require('@lezer/generator')
|
||||
const { writeFileSync, readFileSync } = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const options = {
|
||||
grammarPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-latex/latex.grammar'
|
||||
),
|
||||
parserOutputPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-latex/latex.mjs'
|
||||
),
|
||||
termsOutputPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-latex/latex.terms.mjs'
|
||||
),
|
||||
}
|
||||
const grammars = [
|
||||
{
|
||||
grammarPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-latex/latex.grammar'
|
||||
),
|
||||
parserOutputPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-latex/latex.mjs'
|
||||
),
|
||||
termsOutputPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-latex/latex.terms.mjs'
|
||||
),
|
||||
},
|
||||
{
|
||||
grammarPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-bibtex/bibtex.grammar'
|
||||
),
|
||||
parserOutputPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-bibtex/bibtex.mjs'
|
||||
),
|
||||
termsOutputPath: path.resolve(
|
||||
__dirname,
|
||||
'../../frontend/js/features/source-editor/lezer-bibtex/bibtex.terms.mjs'
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
function compile() {
|
||||
const { grammarPath, termsOutputPath, parserOutputPath } = options
|
||||
function compile(grammar) {
|
||||
const { grammarPath, termsOutputPath, parserOutputPath } = grammar
|
||||
const moduleStyle = 'es'
|
||||
console.info(`Compiling ${grammarPath}`)
|
||||
|
||||
@@ -40,11 +56,11 @@ function compile() {
|
||||
console.info('Done!')
|
||||
}
|
||||
|
||||
module.exports = { compile, options }
|
||||
module.exports = { compile, grammars }
|
||||
|
||||
if (require.main === module) {
|
||||
try {
|
||||
compile()
|
||||
grammars.forEach(compile)
|
||||
process.exit(0)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { readFileSync } from 'fs'
|
||||
import { logTree } from '../../frontend/js/features/source-editor/lezer-latex/print-tree.mjs'
|
||||
import { parser } from '../../frontend/js/features/source-editor/lezer-latex/latex.mjs'
|
||||
import { parser as LaTeXParser } from '../../frontend/js/features/source-editor/lezer-latex/latex.mjs'
|
||||
import { parser as BibTeXParser } from '../../frontend/js/features/source-editor/lezer-bibtex/bibtex.mjs'
|
||||
|
||||
// Runs the lezer-latex parser on a supplied file, and prints the resulting
|
||||
// Runs the lezer-latex or lezer-bibtex parser on a supplied file, and prints the resulting
|
||||
// parse tree to stdout
|
||||
//
|
||||
// show parse tree: lezer-latex-run.js test/frontend/shared/lezer-latex/examples/amsmath.tex
|
||||
// lezer-latex-run.js test/frontend/shared/lezer-latex/examples/overleaf.bib
|
||||
// show error summary: lezer-latex-run.js coverage test/frontend/shared/lezer-latex/examples/amsmath.tex
|
||||
|
||||
let files = process.argv.slice(2)
|
||||
@@ -27,6 +29,7 @@ function reportErrorCounts(output) {
|
||||
function parseFile(filename) {
|
||||
const text = readFileSync(filename).toString()
|
||||
const t0 = process.hrtime()
|
||||
const parser = filename.endsWith('.bib') ? BibTeXParser : LaTeXParser
|
||||
const tree = parser.parse(text)
|
||||
const dt = process.hrtime(t0)
|
||||
const timeTaken = dt[0] + dt[1] * 1e-9
|
||||
|
||||
Reference in New Issue
Block a user