2
0

grunt-peg.js 867 B

123456789101112131415161718192021222324
  1. module.exports = function (grunt) {
  2. var PEG = require('pegjs');
  3. /**
  4. Full config looks like this:
  5. pegjs: {
  6. my_parser: {
  7. options: { // optional
  8. cache: true, // default: false
  9. export_var: 'smalltalk.parser' // default: module.exports
  10. },
  11. */
  12. grunt.registerMultiTask('peg', 'Generate JavaScript parser from PEG.js grammar description', function () {
  13. var options = this.options({
  14. cache: false,
  15. output: 'source',
  16. export_var: 'module.exports'
  17. });
  18. var parser = PEG.buildParser(grunt.file.read(this.data.src), options);
  19. var content = "define(['./boot'], function($boot) {\nvar $globals = $boot.globals;\n" + options.export_var + " = " + parser + ";\n});";
  20. grunt.file.write(this.data.dest, content);
  21. });
  22. };