-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.js
28 lines (22 loc) · 1.14 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env node
'use strict';
import fs from "fs";
import path from "path";
import peggy from "peggy";
import tspegjs from "ts-pegjs";
const grammarPath = path.resolve('./src/grammars/latex.pegjs');
var parserCode = fs.readFile(grammarPath, 'utf8', function (err, data) {
let TSparser = peggy.generate(data, {
output: 'source',
cache: true,
//trace: true,
plugins: [tspegjs],
allowedStartRules: ["Root"],
tspegjs: {
customHeader: "import {MPNode, MPOperation, MPAtom, MPConstant, MPInteger, MPFloat, MPString, MPBoolean, MPIdentifier, MPAssignment, MPComment, MPFunctionCall, MPFunction, MPGroup, MPSet, MPList, MPPrefixOp, MPPostfixOp, MPIndexing, MPIf, MPLoop, MPLoopBit, MPEvaluationFlag, MPStatement, MPRoot, MPAnnotation, MPMacro, MPLimit, MPLogarithm, MPBinomial, MPSum, MPIntegral, MPTrigonometric, MPDifferential, MPArgument, MPMatrix, MPNthRoot} from \'./MP_classes.js\';" +
"import {CONSTANTS} from\'./constants.js\';"
}
});
const outputPath = path.resolve('./src/parser.ts');
fs.writeFile(outputPath, TSparser, 'utf8', (err) => {console.log(err);});
});