-function match1token(t) {
- return (m) => {
- if (m.remained.length == 0) {
- return { _tag: "None" };
- }
- const tokenToBeMatched = m.remained[0];
- if (tokenToBeMatched === t) {
- m.matched.push(tokenToBeMatched);
- return {
- _tag: "Some", value: {
- matched: m.matched,
- remained: m.remained.slice(1)
- }
- };
- }
- else {
- return { _tag: "None" };
- }
- };
+function processArgv(argv, helpDesc) {
+ let inputFile = argv['_'];
+ let outputJSFile = argv['output-js'];
+ let NoInputFile = (inputFile.length == 0);
+ let NoOutputJSFile = (outputJSFile === undefined || outputJSFile == true);
+ let helpTriggered = argv['help'];
+ if (inputFile.length > 1) {
+ console.log("Sorry, the input file should be only one.");
+ }
+ /** output --help */
+ if (helpTriggered || NoInputFile || NoOutputJSFile) {
+ console.log(helpDesc);
+ }
+ else {
+ fs.readFile(inputFile[0], 'utf8', (err, inputText) => {
+ if (err)
+ throw err;
+ let tree = parser.inputTextToTree(inputText);
+ let output = parser.treeToJS(tree);
+ fs.writeFile(outputJSFile, output, (err) => {
+ if (err)
+ throw err;
+ });
+ });
+ }