This commit is contained in:
Nick Guerrera 2021-03-11 14:28:42 -08:00 коммит произвёл GitHub
Родитель 0b491e6f2f
Коммит 0975c022fc
2 изменённых файлов: 25 добавлений и 9 удалений

Просмотреть файл

@ -1,8 +1,12 @@
// TextMate-based syntax highlighting is implemented in this file.
// adl.tmLanguage.json is generated by running this script.
import { writeFileSync } from "fs";
import { OnigRegExp } from "oniguruma";
import fs from "fs";
import { promisify } from "util";
import { loadWASM, OnigRegExp } from "onigasm";
const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
const schema = "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json";
@ -317,10 +321,12 @@ const grammar: Grammar = {
};
/** Entry point, write the grammar to disk. */
function main() {
async function main() {
const onigasm = await readFile("node_modules/onigasm/lib/onigasm.wasm");
await loadWASM(onigasm.buffer);
const filePath = "./dist/adl.tmlanguage.json";
const json = emit(grammar);
writeFileSync(filePath, json);
await writeFile(filePath, json);
}
/** Emit the grammar to a JSON string matching tmlanguage.json schema. */
@ -405,10 +411,17 @@ function processGrammar(grammar: Grammar): any {
function validateRegexp(regexp: string, node: any, prop: string) {
try {
new OnigRegExp(regexp);
new OnigRegExp(regexp).testSync("");
} catch (err) {
let message: string = err.message;
if (/^[0-9,]+/.test(message)) {
// Work around for https://github.com/NeekSandhu/onigasm/issues/26
const array = new Uint8Array(message.split(",").map((s: string) => Number(s)));
const buffer = Buffer.from(array);
message = buffer.toString("utf-8");
}
console.error(`Error: Bad regex: ${JSON.stringify({ [prop]: regexp })}`);
console.error(`Error: ${err.message}`);
console.error(`Error: ${message}`);
console.error();
console.error("Context:");
console.dir(node);
@ -418,4 +431,8 @@ function processGrammar(grammar: Grammar): any {
}
}
main();
main()
.then()
.catch((err) => {
console.log(err.stack);
});

Просмотреть файл

@ -24,8 +24,7 @@
},
"devDependencies": {
"@types/node": "14.0.27",
"@types/oniguruma": "~7.0.1",
"oniguruma": "~7.2.1",
"onigasm": "~2.2.5",
"typescript": "~4.1.5",
"vsce": "^1.85.1"
},