X-Git-Url: https://git.kianting.info/?a=blobdiff_plain;f=src%2Findex.js;h=53df24ce362d0fb92676faf42d0b3ddf2debbddc;hb=4064e597019df41eabbe7bf662a8f2ba16bda44a;hp=fb887701725ab7261a7bda6b47b78fa15babc3a5;hpb=cda463d89022d09a5273b59bcd3e776f1127697a;p=clo diff --git a/src/index.js b/src/index.js index fb88770..53df24c 100644 --- a/src/index.js +++ b/src/index.js @@ -23,39 +23,48 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.match1token = void 0; var fs = require('fs'); -const tk = __importStar(require("./tokenize.js")); -let b = tk.tokenize("2+2"); +var argv = require('minimist')(process.argv.slice(2)); +const parser = __importStar(require("./parser.js")); +let helpDesc = ` +clo: clo INPUT_FILE --output-js OUTPUT_JS_FILE + +\ta little typesetter powered by TypeScript/Javascript. + +## Arguments +INPUT_FILE\tan input .clo file + +## Parameters +--- +--output-js\tgenerated the output middle JS file +`; +processArgv(argv, helpDesc); /** - * @description - * it returns a function which test if the first char of the `remained` part of - * the argument of the function is `c`, if it's true, update the `MatchedPair` wrapped - * in `Some`. Otherwise, it returns `None`. - * * @param t : the char to be test. - * @returns the updated `MatchedPair` wrapped in `Some(x)` or `None`. + * processing the passed `argv` (arguments) */ -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; + }); + }); + } } -exports.match1token = match1token; -; -let c = tk.toSome(b); -console.log(thenDo(c, match1token(tk.tokenize("+")[0])));