This commit is contained in:
Sidharth Vinod
2022-09-01 23:38:13 +05:30
parent 01562528b7
commit 904eccc4fa
5 changed files with 136 additions and 6 deletions

31
jison.js Normal file
View File

@@ -0,0 +1,31 @@
import { Jison } from 'jison';
import { createFilter } from 'rollup-pluginutils';
export default (options = {}) => ({
name: 'jison',
transform(grammar, id) {
const { include = ['*.jison', '**/*.jison'], exclude, type = 'lalr' } = options;
const filter = createFilter(include, exclude);
if (!filter(id)) return null;
const parser = new Jison.Generator(grammar, {
moduleType: 'js',
type,
});
const source = parser.generate();
const exporter = `
const parse = parser.parse.bind(parser);
parser.parser = parse;
export { parser };
export default parser;
`;
console.log('helll');
return {
code: `${source} ${exporter}`,
map: { mappings: '' },
};
},
});