Преглед изворни кода

grunt: move pegjs task into separate file

Manfred Kroehnert пре 11 година
родитељ
комит
279ed7aee9
2 измењених фајлова са 27 додато и 12 уклоњено
  1. 0 12
      grunt.js
  2. 27 0
      grunt/tasks/grunt-peg.js

+ 0 - 12
grunt.js

@@ -189,16 +189,4 @@ module.exports = function(grunt) {
 
     grunt.log.writeln('File "' + this.data.dest + '" created.');
   });
-
-  grunt.registerMultiTask('pegjs', 'Generate JavaScript parser from PEG.js description', function() {
-    var PEG = require('pegjs');
-    var pegOptions = {
-      cache: this.data.cache || false,
-      trackLineAndColumn: this.data.trackLineAndColumn || false
-    };
-    var export_var = this.data.export_var || 'module.exports';
-    var parser = PEG.buildParser(grunt.file.read(this.data.src), pegOptions);
-    var content = export_var + ' = ' + parser.toSource() + ';\n';
-    grunt.file.write(this.data.dest, content);
-  });
 };

+ 27 - 0
grunt/tasks/grunt-peg.js

@@ -0,0 +1,27 @@
+module.exports = function(grunt) {
+
+  var PEG = require('pegjs');
+
+  /**
+     Full config looks like this:
+    pegjs: {
+       my_parser: {
+         src: 'parser.pegjs',        // REQUIRED
+         dest: 'parser.js',          // REQUIRED
+         trackLineAndColumn: true,      // optional (default: false)
+         cache: true,                   // optional (default: false)
+         export_var: 'smalltalk.parser' // optional (default: module.exports)
+       }
+     },
+   */
+  grunt.registerMultiTask('pegjs', 'Generate JavaScript parser from PEG.js grammar description', function() {
+    var pegOptions = {
+      cache: this.data.cache || false,
+      trackLineAndColumn: this.data.trackLineAndColumn || false
+    };
+    var export_var = this.data.export_var || 'module.exports';
+    var parser = PEG.buildParser(grunt.file.read(this.data.src), pegOptions);
+    var content = export_var + ' = ' + parser.toSource() + ';\n';
+    grunt.file.write(this.data.dest, content);
+  });
+};