UNPKG

5.98 kBJavaScriptView Raw
1// Generated by LispyScript v0.2.9
2require("./node");
3var fs = require("fs");
4var ls = require("../lib/ls");
5var repl = require("./repl");
6var isValidFlag = /-h\b|-r\b|-v\b/;
7var error = function(err) {
8 console.error(err.message);
9 return process.exit(1);
10};
11var help_str = "\nUsage: lispy [-h] [-r] [<infile>] [<outfile>]\n\n Also compile stdin to stdout\n eg. $ echo '(console.log \"hello\")' | lispy\n\n <no arguments> Run REPL\n -h Show this help\n -r Compile and run\n -v Show Version\n <infile> Input file to compile\n <outfile> Output JS file. If not given\n <outfile> will be <infile> with .js extension\n";
12(function(___monad) {
13 var mBind = ___monad.mBind;
14 var mResult = ___monad.mResult;
15 var mZero = ___monad.mZero;
16 var mPlus = ___monad.mPlus;
17 var ____mResult = function(___arg) {
18 return (((typeof(___arg) === "undefined") && (!(typeof(mZero) === "undefined"))) ?
19 mZero :
20 mResult(___arg));
21 };
22 return mBind(process.argv.slice(2),function(args) {
23 return mBind(args.shift(),function(arg1) {
24 return mBind(((typeof(arg1) === "undefined") ?
25 (function() {
26 var input = process.stdin;
27 var output = process.stdout;
28 input.resume();
29 input.setEncoding("utf8");
30 var source = "";
31 input.on("data",function(chunck) {
32 source = (source + chunck.toString());
33 });
34 input.on("end",function() {
35 return (function() {
36 try {
37 return output.write(ls._compile(source,process.cwd));
38
39 } catch (e) {
40 return (error)(e);
41 }
42 })();
43 });
44 input.on("error",error);
45 output.on("error",error);
46 setTimeout(function() {
47 return ((input.bytesRead === 0) ?
48 (function() {
49 input.removeAllListeners("data");
50 return repl.runrepl();
51 })() :
52 undefined);
53 },20);
54 return null;
55 })() :
56 undefined),function(noargs) {
57 return mBind((("-" === arg1[0]) ?
58 (function() {
59 var flag = arg1;
60 arg1 = args.shift();
61 return (isValidFlag.test(flag) ?
62 flag :
63 error(new Error(("Error: Invalid flag " + flag))));
64 })() :
65 undefined),function(flag) {
66 return mBind((("-h" === flag) ?
67 (function() {
68 console.log(help_str);
69 return null;
70 })() :
71 (("-v" === flag) ?
72 (function() {
73 console.log(("Version " + ls.version));
74 return null;
75 })() :
76 (("-r" === flag) ?
77 true :
78 undefined))),function(run) {
79 return mBind((arg1 ?
80 arg1 :
81 error(new Error("Error: No Input file given"))),function(infile) {
82 return mBind((function() {
83 var outfile = args.shift();
84 ((!outfile) ?
85 (function() {
86 return (function() {
87 outfile = infile.replace(/\.ls$/,".js");
88 return ((outfile === infile) ?
89 error(new Error("Error: Input file must have extension '.ls'")) :
90 undefined);
91 })();
92 })() :
93 undefined);
94 return outfile;
95 })(),function(outfile) {
96 return mBind((function() {
97 try {
98 fs.writeFileSync(outfile,ls._compile(fs.readFileSync(infile,"utf8"),infile),"utf8");
99 return (run ?
100 run :
101 null);
102
103 } catch (e) {
104 return (function(err) {
105 error(err);
106 return null;
107 })(e);
108 }
109 })(),function(js) {
110 return (function() {
111 return ____mResult((require("child_process")).spawn("node",[outfile],{stdio: "inherit"}));
112 })();
113 });
114 });
115 });
116 });
117 });
118 });
119 });
120 });
121})((function() {
122 var _r = {};
123 for(var i=0,l=arguments.length;i<l;i+=2){_r[arguments[i]]=arguments[i+1];}
124 return _r;
125})("mBind",function(mv,mf) {
126 return ((mv === null) ?
127 null :
128 mf(mv));
129},"mResult",function(v) {
130 return v;
131},"mZero",null));