mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 13:21:37 +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
@@ -4,45 +4,49 @@ const modulePath = path.resolve(__dirname, '../scripts/lezer-latex/generate.js')
|
||||
|
||||
try {
|
||||
fs.accessSync(modulePath, fs.constants.W_OK)
|
||||
const { compile, options } = require(modulePath)
|
||||
const { compile, grammars } = require(modulePath)
|
||||
const PLUGIN_NAME = 'lezer-grammar-compiler'
|
||||
class LezerGrammarCompilerPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.make.tap(PLUGIN_NAME, compilation => {
|
||||
// Add the grammar file to the file paths watched by webpack
|
||||
compilation.fileDependencies.add(options.grammarPath)
|
||||
})
|
||||
compiler.hooks.beforeCompile.tapAsync(
|
||||
PLUGIN_NAME,
|
||||
(_compilation, callback) => {
|
||||
// Check timestamps on grammar and parser files, and re-compile if needed.
|
||||
// (Note: the compiled parser file is watched by webpack, and so will trigger
|
||||
// a second compilation immediately after. This seems harmless.)
|
||||
if (
|
||||
!fs.existsSync(options.parserOutputPath) ||
|
||||
!fs.existsSync(options.termsOutputPath)
|
||||
) {
|
||||
console.log('Parser does not exist, compiling')
|
||||
compile()
|
||||
return callback()
|
||||
}
|
||||
fs.stat(options.grammarPath, (err, grammarStat) => {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
for (const grammar of grammars) {
|
||||
compiler.hooks.make.tap(PLUGIN_NAME, compilation => {
|
||||
// Add the grammar file to the file paths watched by webpack
|
||||
compilation.fileDependencies.add(grammar.grammarPath)
|
||||
})
|
||||
compiler.hooks.beforeCompile.tapAsync(
|
||||
PLUGIN_NAME,
|
||||
(_compilation, callback) => {
|
||||
// Check timestamps on grammar and parser files, and re-compile if needed.
|
||||
// (Note: the compiled parser file is watched by webpack, and so will trigger
|
||||
// a second compilation immediately after. This seems harmless.)
|
||||
if (
|
||||
!fs.existsSync(grammar.parserOutputPath) ||
|
||||
!fs.existsSync(grammar.termsOutputPath)
|
||||
) {
|
||||
console.log('Parser does not exist, compiling')
|
||||
compile(grammar)
|
||||
return callback()
|
||||
}
|
||||
fs.stat(options.parserOutputPath, (err, parserStat) => {
|
||||
fs.stat(grammar.grammarPath, (err, grammarStat) => {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
callback()
|
||||
if (grammarStat.mtime > parserStat.mtime) {
|
||||
console.log('Grammar file newer than parser file, re-compiling')
|
||||
compile()
|
||||
}
|
||||
fs.stat(grammar.parserOutputPath, (err, parserStat) => {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
callback()
|
||||
if (grammarStat.mtime > parserStat.mtime) {
|
||||
console.log(
|
||||
'Grammar file newer than parser file, re-compiling'
|
||||
)
|
||||
compile(grammar)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = { LezerGrammarCompilerPlugin }
|
||||
|
||||
Reference in New Issue
Block a user