Permalink
Browse files

Simplify bin/canopy.

  • Loading branch information...
1 parent 95364ba commit 98fc9409d3ecb795115f26513e5a85e240536bd6 @jcoglan committed May 1, 2012
Showing with 15 additions and 20 deletions.
  1. +15 −20 bin/canopy
View
@@ -3,25 +3,20 @@
var Canopy = require('../lib/canopy'),
fs = require('fs');
-var startTime = Number(new Date()),
- inputFile = process.argv[2],
- outputFile = inputFile.replace(/\.peg$/, '.js');
-
-fs.readFile(inputFile, function(err, grammar) {
- if (err) return console.error('Could not read source file: ' + inputFile);
-
- try {
- var parser = Canopy.compile(grammar.toString()),
- endTime = Number(new Date());
-
- fs.writeFile(outputFile, parser, function(err) {
- if (err) return console.error('Could not write to output file: ' + outputFile);
+try {
+ var startTime = new Date().getTime(),
+ inputFile = process.argv[2],
+ outputFile = inputFile.replace(/\.peg$/, '.js'),
- console.log('Generated parser in ' + outputFile);
- console.log('Completed in ' + ((endTime - startTime) / 1000) + 's');
- });
- } catch (e) {
- console.error(e.message);
- }
-});
+ grammar = fs.readFileSync(inputFile).toString(),
+ parser = Canopy.compile(grammar),
+ endTime = new Date().getTime();
+
+ fs.writeFileSync(outputFile, parser);
+ console.log('Generated parser in ' + outputFile);
+ console.log('Completed in ' + ((endTime - startTime) / 1000) + 's');
+
+} catch (e) {
+ console.error(e.message);
+}

0 comments on commit 98fc940

Please sign in to comment.