]> git.kianting.info Git - clo/blobdiff - src/index.js
english breakline, and generate try to count the text size
[clo] / src / index.js
index fb887701725ab7261a7bda6b47b78fa15babc3a5..a5fb1329e1e6758a271cfc3c3048d42e901de979 100644 (file)
@@ -23,39 +23,57 @@ var __importStar = (this && this.__importStar) || function (mod) {
     return result;
 };
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.match1token = void 0;
+exports.processArgv = exports.helpDesc = 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"));
 /**
- * @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`.
+ * help for inputing `--help` parameter.
  */
-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" };
-        }
-    };
+exports.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
+
+
+Report bugs to: clo@kianting.info
+clo home page: <https://kianting.info/wiki/w/Project:Clo>
+`;
+processArgv(argv, exports.helpDesc);
+/**
+ * processing the passed `argv` (arguments)
+ */
+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])));
+exports.processArgv = processArgv;