Permalink
Browse files

[ if compiles to ?: ]

  • Loading branch information...
1 parent 4ea3634 commit 392ff2d6c12e0ed66088dda96a33914a7dc9d1bd @jbr committed Dec 17, 2010
Showing with 377 additions and 403 deletions.
  1. +131 −160 lib/browser.js
  2. +19 −21 lib/cli.js
  3. +3 −5 lib/import.js
  4. +15 −1 lib/macros.lisp
  5. +28 −30 lib/options.js
  6. +22 −24 lib/repl.js
  7. +126 −153 lib/sibilant.js
  8. +33 −9 test/test.lisp
View
@@ -7,13 +7,11 @@
;
var inspect = (function(item) {
// item:required
- return (function() {
- if (item.toSource) {
- return item.toSource();
- } else {
- return item.toString();
- };
- })();
+ return (item.toSource ?
+ item.toSource()
+ : // if item.toSource is false
+ item.toString()
+ );
});
;
(window)["sibilant"] = sibilant;;
@@ -159,15 +157,17 @@
// token:required
var special = (token)[0],
token = token;;
- (function() {
- if ((special === "'")) {
+ ((special === "'") ?
+ (function() {
token = token.slice(1);;
increaseNesting();
return acceptToken("quote");;
- } else {
+ })()
+ : // if (special === "'") is false
+ (function() {
return special = false;;
- };
- })();
+ })()
+ );
specials.unshift((!!(special)));
(function() {
switch(token) {
@@ -188,13 +188,11 @@
return acceptToken("list");
default:
- return (function() {
- if (token.match((new RegExp(("^" + sibilant.tokens.number + "$"), undefined)))) {
- return acceptToken(parseFloat(token));
- } else {
- return acceptToken(token);
- };
- })();
+ return (token.match((new RegExp(("^" + sibilant.tokens.number + "$"), undefined))) ?
+ acceptToken(parseFloat(token))
+ : // if token.match((new RegExp(("^" + sibilant.tokens.number + "$"), undefined))) is false
+ acceptToken(token)
+ );
}
})();
return (function() {
@@ -247,56 +245,50 @@
(macros)["return"] = (function(token) {
// token:required
var defaultReturn = ("return " + translate(token));;
- return (function() {
- if ((token) && (token).constructor.name === "Array") {
- return (function() {
- switch((token)[0]) {
- case "return":
- case "throw":
- case "progn":
- return translate(token);
-
- case "delete":
- var deleteMacro = (macros)["delete"];;
- return (function() {
- if ((token.length < 3)) {
- return defaultReturn;
- } else {
- return (deleteMacro.apply(undefined, token.slice(1, -1)) + "\nreturn " + deleteMacro((token.slice(-1))[0]));
- };
- })();
-
- case "setf":
- return (function() {
- if ((token.length < 4)) {
- return defaultReturn;
- } else {
- return (macros.setf.apply(undefined, token.slice(1, (token.length - 2))) + "\nreturn " + macros.setf.apply(undefined, token.slice(-2)));
- };
- })();
-
- case "set":
- return (function() {
- if ((token.length < 5)) {
- return defaultReturn;
- } else {
- var obj = (token)[1],
- nonReturnPart = token.slice(2, (token.length - 2)),
- returnPart = token.slice(-2);;
- nonReturnPart.unshift(obj);
- returnPart.unshift(obj);
- return (macros.set.apply(undefined, nonReturnPart) + "\nreturn " + macros.set.apply(undefined, returnPart));;
- };
- })();
-
- default:
- return defaultReturn;
- }
- })();
- } else {
- return defaultReturn;
- };
- })();
+ return ((token) && (token).constructor.name === "Array" ?
+ (function() {
+ switch((token)[0]) {
+ case "return":
+ case "throw":
+ case "progn":
+ return translate(token);
+
+ case "delete":
+ var deleteMacro = (macros)["delete"];;
+ return ((token.length < 3) ?
+ defaultReturn
+ : // if (token.length < 3) is false
+ (deleteMacro.apply(undefined, token.slice(1, -1)) + "\nreturn " + deleteMacro((token.slice(-1))[0]))
+ );
+
+ case "setf":
+ return ((token.length < 4) ?
+ defaultReturn
+ : // if (token.length < 4) is false
+ (macros.setf.apply(undefined, token.slice(1, (token.length - 2))) + "\nreturn " + macros.setf.apply(undefined, token.slice(-2)))
+ );
+
+ case "set":
+ return ((token.length < 5) ?
+ defaultReturn
+ : // if (token.length < 5) is false
+ (function() {
+ var obj = (token)[1],
+ nonReturnPart = token.slice(2, (token.length - 2)),
+ returnPart = token.slice(-2);;
+ nonReturnPart.unshift(obj);
+ returnPart.unshift(obj);
+ return (macros.set.apply(undefined, nonReturnPart) + "\nreturn " + macros.set.apply(undefined, returnPart));;
+ })()
+ );
+
+ default:
+ return defaultReturn;
+ }
+ })()
+ : // if (token) && (token).constructor.name === "Array" is false
+ defaultReturn
+ );
});
macros.statement = (function(args) {
// args:rest
@@ -329,13 +321,11 @@
var argsAndBody = Array.prototype.slice.call(arguments, 1);
var fnNameTr = translate(fnName),
- start = (function() {
- if (/\./(fnNameTr)) {
- return "";
- } else {
- return "var ";
- };
- })();;
+ start = (/\./(fnNameTr) ?
+ ""
+ : // if /\./(fnNameTr) is false
+ "var "
+ );;
return (start + fnNameTr + " = " + macros.lambda.apply(undefined, argsAndBody) + ";\n");
});
@@ -368,14 +358,16 @@
args = [ ];;
arglist.forEach((function(arg) {
// arg:required
- return (function() {
- if (((arg)[0] === "&")) {
+ return (((arg)[0] === "&") ?
+ (function() {
return last = arg.slice(1);;
- } else {
+ })()
+ : // if ((arg)[0] === "&") is false
+ (function() {
args.push([ (last || "required"), arg ]);
return last = null;;;
- };
- })();
+ })()
+ );
}));
(function() {
if (last) {
@@ -416,27 +408,23 @@
};
})();
}));
- return (function() {
- if (typeof(rest) !== 'undefined') {
- return (argsString + "var " + translate((rest)[1]) + " = Array.prototype.slice.call(arguments, " + args.length + ");\n");
- } else {
- return argsString;
- };
- })();
+ return (typeof(rest) !== 'undefined' ?
+ (argsString + "var " + translate((rest)[1]) + " = Array.prototype.slice.call(arguments, " + args.length + ");\n")
+ : // if typeof(rest) !== 'undefined' is false
+ argsString
+ );
});
var buildCommentString = (function(args) {
// args:required
- return (function() {
- if (((args).length === 0)) {
- return "";
- } else {
- return ("// " + (map(args, (function(arg) {
- // arg:required
- return (translate((arg)[1]) + ":" + (arg)[0]);
- }))).join(" "));
- };
- })();
+ return (((args).length === 0) ?
+ ""
+ : // if ((args).length === 0) is false
+ ("// " + (map(args, (function(arg) {
+ // arg:required
+ return (translate((arg)[1]) + ":" + (arg)[0]);
+ }))).join(" "))
+ );
});
// brain 'splode
@@ -456,13 +444,11 @@
return docString = ("/* " + eval(body.shift()) + " */\n");;
};
})();
- var noRestArgs = (function() {
- if (rest) {
- return args.slice(0, -1);
- } else {
- return args;
- };
- })(),
+ var noRestArgs = (rest ?
+ args.slice(0, -1)
+ : // if rest is false
+ args
+ ),
argsString = buildArgsString(noRestArgs, rest),
commentString = buildCommentString(args);;
return ("(function(" + (map(args, (function(arg) {
@@ -476,19 +462,15 @@
macros.quote = (function(item) {
// item:required
- return (function() {
- if (("Array" === item.constructor.name)) {
- return ("[ " + (map(item, macros.quote)).join(", ") + " ]");
- } else {
- return (function() {
- if (("number" === typeof(item))) {
- return item;
- } else {
- return ("\"" + literal(item) + "\"");
- };
- })();
- };
- })();
+ return (("Array" === item.constructor.name) ?
+ ("[ " + (map(item, macros.quote)).join(", ") + " ]")
+ : // if ("Array" === item.constructor.name) is false
+ (("number" === typeof(item)) ?
+ item
+ : // if ("number" === typeof(item)) is false
+ ("\"" + literal(item) + "\"")
+ )
+ );
});
macros.hash = (function(pairs) {
@@ -504,13 +486,11 @@
// key:required value:required
return (translate(key) + ": " + translate(value));
}));;
- return (function() {
- if ((1 >= pairStrings.length)) {
- return ("{ " + (pairStrings).join(", ") + " }");
- } else {
- return ("{" + indent((pairStrings).join(",\n")) + "}");
- };
- })();
+ return ((1 >= pairStrings.length) ?
+ ("{ " + (pairStrings).join(", ") + " }")
+ : // if (1 >= pairStrings.length) is false
+ ("{" + indent((pairStrings).join(",\n")) + "}")
+ );
});
var literal = (function(string) {
@@ -542,41 +522,32 @@
})();
return (function() {
try {
- return (function() {
- if ((token) && (token).constructor.name === "Array") {
- return (function() {
- if (typeof((macros)[translate((token)[0])]) !== 'undefined') {
- return (macros)[translate((token)[0])].apply(undefined, token.slice(1));
- } else {
- return (macros)[(hint || "call")].apply(undefined, token);
- };
- })();
- } else {
- return (function() {
- if ((typeof(token) === "string" && token.match((new RegExp(("^" + sibilant.tokens.literal + "$"), undefined))))) {
- return literal(token);
- } else {
- return (function() {
- if ((typeof(token) === "string" && token.match((new RegExp("^;", undefined))))) {
- return token.replace((new RegExp("^;+", undefined)), "//");
- } else {
- return (function() {
- if ((typeof(token) === "string" && ("\"" === (token)[0] &&
- "\"" === (token.slice(-1))[0]))) {
- return token // chain
- .split("\n")
- .join("\\n\" +\n\"")
- ;
- } else {
- return token;
- };
- })();
- };
- })();
- };
- })();
- };
- })();
+ return ((token) && (token).constructor.name === "Array" ?
+ (typeof((macros)[translate((token)[0])]) !== 'undefined' ?
+ (macros)[translate((token)[0])].apply(undefined, token.slice(1))
+ : // if typeof((macros)[translate((token)[0])]) !== 'undefined' is false
+ (macros)[(hint || "call")].apply(undefined, token)
+ )
+ : // if (token) && (token).constructor.name === "Array" is false
+ ((typeof(token) === "string" && token.match((new RegExp(("^" + sibilant.tokens.literal + "$"), undefined)))) ?
+ literal(token)
+ : // if (typeof(token) === "string" && token.match((new RegExp(("^" + sibilant.tokens.literal + "$"), undefined)))) is false
+ ((typeof(token) === "string" && token.match((new RegExp("^;", undefined)))) ?
+ token.replace((new RegExp("^;+", undefined)), "//")
+ : // if (typeof(token) === "string" && token.match((new RegExp("^;", undefined)))) is false
+ ((typeof(token) === "string" && ("\"" === (token)[0] &&
+ "\"" === (token.slice(-1))[0])) ?
+ token // chain
+ .split("\n")
+ .join("\\n\" +\n\"")
+
+ : // if (typeof(token) === "string" && ("\"" === (token)[0] &&
+ // "\"" === (token.slice(-1))[0])) is false
+ token
+ )
+ )
+ )
+ );
} catch (e) {
return error((e.stack + "\n" + "Encountered when attempting to process:\n" + indent(inspect(token))));
}
Oops, something went wrong.

0 comments on commit 392ff2d

Please sign in to comment.