First commit.

Signed-off-by: Chen Xiao <abigwc@gmail.com>
This commit is contained in:
Chen Xiao
2026-05-08 14:43:16 +08:00
commit 0b64e2de94
10989 changed files with 2253791 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
/**
* @param {string} targetFilePath - The path and file name to serialize to.
* @param {string} varName - The name of the global variable to expose the serialized contents/
* @param {chevrotain.Parser} parserInstance - A parser instance whose grammar will be serialized.
*/
function serializeGrammarToFile(targetFilePath, varName, parserInstance) {
var fs = require("fs");
var serializedGrammar = parserInstance.getSerializedGastProductions();
var serializedGrammarText = JSON.stringify(serializedGrammar, null, "\t");
// generated a JavaScript file which exports the serialized grammar on the global scope (Window)
fs.writeFileSync(
targetFilePath,
"var " + varName + " = " + serializedGrammarText,
);
}
module.exports = {
serializeGrammarToFile: serializeGrammarToFile,
};