X-Git-Url: https://git.kianting.info/?a=blobdiff_plain;f=src%2Findex.ts;h=44aa79282788f7f8fd28679017ceb114c49c3149;hb=c3dc58d74afa6b298d84bad90d63c027a32a954a;hp=405a1f0d465ffcf04867c6a2bb3c09c083c3b9b6;hpb=c13ca4ff34a66932ff73641a6da0418f1c4bc56d;p=clo diff --git a/src/index.ts b/src/index.ts index 405a1f0..44aa792 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,37 +1,68 @@ var fs = require('fs'); -import jsTokens from "js-tokens"; -import * as util from 'util'; +var argv : any = require('minimist')(process.argv.slice(2)); -/**inspect the inner of the representation. */ -let repr = (x : any)=>{return util.inspect(x, {depth: null})}; +import * as parser from "./parser.js"; /** - * like `m ==> f` in ocaml - * @param m matchee wrapped - * @param f matching function - * @returns wrapped result + * help for inputing `--help` parameter. */ -function thenDo(m : tk.Maybe, f : Function){ - if (m._tag == "None"){ - return m; +export 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 + + +Report bugs to: clo@kianting.info +clo home page: +` + +processArgv(argv, helpDesc); + +/** + * processing the passed `argv` (arguments) + */ + +export function processArgv(argv : any, helpDesc : string){ + let inputFile : string[] = argv['_']; + let outputJSFile : string | true = argv['output-js']; + + let NoInputFile : boolean = (inputFile.length == 0); + let NoOutputJSFile : boolean = (outputJSFile === undefined || outputJSFile == true); + let helpTriggered : boolean = 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{ - var a : tk.Maybe = f(m.value); - if (a._tag == "Some"){ - a.value.ast = concat(m.value.ast, a.value.ast); - } + fs.readFile(inputFile[0], 'utf8', (err : Error, inputText : string) => { + if (err) throw err; + + let tree = parser.inputTextToTree(inputText); - return a; + let output = parser.treeToJS(tree); + + fs.writeFile(outputJSFile, output , (err : Error) => { + if (err) throw err; + }); + + }); } -} -const tokens = Array.from(jsTokens(` -import foo from\t 'bar'; -import * as util from 'util'; +} -花非花,霧\\{非霧 。{{foo();}}下 -一句`)); -console.log("RESULT="+repr(tokens));