Spaces:
Running
Running
File size: 606 Bytes
d605f27 |
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 28 29 30 31 32 33 34 35 |
import jison from "jison";
export class Parser {
parser: any;
constructor (grammar: string) {
// mute jison logs during grammar loading
const logs = [];
jison.print = log => logs.push(log);
this.parser = jison.Parser(grammar);
if (!this.parser) {
console.warn("jison logs:", logs);
throw new Error("jison parser loading failed");
}
jison.print = (...args) => console.log("[JISON]", ...args);
}
parse (source: string): object {
//console.log("parse:", source.length);
return this.parser.parse(source);
}
generate (): string {
return this.parser.generate();
}
};
|