Skip to content

Instantly share code, notes, and snippets.

@pepa65
Created June 26, 2017 10:20
Show Gist options
  • Save pepa65/31cb9f445c0e5237c3740d160ed3825f to your computer and use it in GitHub Desktop.
Save pepa65/31cb9f445c0e5237c3740d160ed3825f to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const parser = require('./grammar.js').parse;
function main() {
const args = require('process').argv;
if (args.length != 3) {
console.error("Only 1 argument needed: file-path")
return 1;
}
const filename = args[2];
fs.readFile(filename, {encoding: 'utf8'}, function(err, data) {
if (err) {
console.log("Error reading file", filename);
console.error(err);
return 1;
}
try {
let output = parser(data);
console.log(output);
}
catch (e) {
console.error(e.message);
}
});
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment