mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
7f37ba737c
* Update Copybara options in preparation for open-sourcing the source editor * Move files * Update paths * Remove source-editor module and checks for its existence * Explicitly mention CM6 license in files that contain code adapted from CM6 GitOrigin-RevId: 89b7cc2b409db01ad103198ccbd1b126ab56349b
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
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'
|
|
),
|
|
}
|
|
|
|
function compile() {
|
|
const { grammarPath, termsOutputPath, parserOutputPath } = options
|
|
const moduleStyle = 'es'
|
|
console.info(`Compiling ${grammarPath}`)
|
|
|
|
const grammarText = readFileSync(grammarPath, 'utf8')
|
|
console.info(`Loaded grammar from ${grammarPath}`)
|
|
|
|
const { parser, terms } = buildParserFile(grammarText, {
|
|
fileName: grammarPath,
|
|
moduleStyle,
|
|
})
|
|
console.info(`Built parser`)
|
|
|
|
writeFileSync(parserOutputPath, parser)
|
|
console.info(`Wrote parser to ${parserOutputPath}`)
|
|
|
|
writeFileSync(termsOutputPath, terms)
|
|
console.info(`Wrote terms to ${termsOutputPath}`)
|
|
|
|
console.info('Done!')
|
|
}
|
|
|
|
module.exports = { compile, options }
|
|
|
|
if (require.main === module) {
|
|
try {
|
|
compile()
|
|
process.exit(0)
|
|
} catch (err) {
|
|
console.error(err)
|
|
process.exit(1)
|
|
}
|
|
}
|