Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #49 from matthewp/defvar

Fixes issue #48, double semi-colons when defvar used within defun
  • Loading branch information...
commit dfe0c27e2807b328b99daaa82015db92a45c6c7c 2 parents de403c2 + 2a583b4
@jbr authored
Showing with 50 additions and 36 deletions.
  1. +42 −35 lib/sibilant.js
  2. +3 −1 src/core.sibilant
  3. +5 −0 test/defvar.sibilant
View
77 lib/sibilant.js
@@ -11,9 +11,9 @@ var bulkMap = (function(arr, fn) {
// arr:required fn:required
var index = 0,
groupSize = fn.length,
- retArr = [ ];;
+ retArr = [ ];
(function() {
- var __returnValue__ = undefined;;
+ var __returnValue__ = undefined;
while ((index < arr.length)) {
__returnValue__ = (function() {
retArr.push(fn.apply(undefined, arr.slice(index, (index + groupSize))));
@@ -27,7 +27,7 @@ var bulkMap = (function(arr, fn) {
var inject = (function(start, items, fn) {
// start:required items:required fn:required
- var value = start;;
+ var value = start;
(function() {
if ((items) && (items).constructor.name === "Array") {
return items.forEach((function(item, index) {
@@ -65,9 +65,9 @@ var detect = (function(items, fn) {
// items:required fn:required
var returnItem = undefined,
index = 0,
- items = items;;
+ items = items;
return (function() {
- var __returnValue__ = undefined;;
+ var __returnValue__ = undefined;
while ((!((items.length === index) || returnItem))) {
__returnValue__ = (function() {
(function() {
@@ -84,7 +84,7 @@ var detect = (function(items, fn) {
var reject = (function(items, fn) {
// items:required fn:required
- var args = [ items, fn ];;
+ var args = [ items, fn ];
return select(items, (function() {
return (!fn.apply(undefined, arguments));
}));
@@ -116,13 +116,13 @@ var flatten = (function(items) {
sibilant.packageInfo = (function() {
- var fs = require("fs");;
+ var fs = require("fs");
return JSON.parse(fs.readFileSync((__dirname + "/../package.json")));
});
sibilant.versionString = (function() {
var package = sibilant.packageInfo(),
- path = require("path");;
+ path = require("path");
return (package.name + " version " + package.version + "\n(at " + path.join(__dirname, "..") + ")");
});
@@ -138,12 +138,12 @@ var withDirAndFile = (function(dir, file, fn) {
var before = {
dir: sibilant.dir,
file: sibilant.file
- };;
+ };
(sibilant)["dir"] = dir;
- (sibilant)["file"] = file;;
- var retval = fn();;
+ (sibilant)["file"] = file;
+ var retval = fn();
(sibilant)["dir"] = before.dir;
- (sibilant)["file"] = before.file;;
+ (sibilant)["file"] = before.file;
return retval;
});
@@ -160,7 +160,7 @@ sibilant.version = (function() {
(require.extensions)[".sibilant"] = (function(module, filename) {
// module:required filename:required
- var content = sibilant.translateFile(filename);;
+ var content = sibilant.translateFile(filename);
return module._compile(content, filename);
});
sibilant.include = (function(file) {
@@ -175,7 +175,7 @@ sibilant.include = (function(file) {
return file = (sibilant.dir + "/" + file);
};
})();
- var resolved = require.resolve(file);;
+ var resolved = require.resolve(file);
return sibilant.translateFile(resolved);
});
@@ -197,14 +197,14 @@ var tokenize = sibilant.tokenize = (function(string) {
// string:required
var tokens = [ ],
parseStack = [ tokens ],
- specials = [ ];;
+ specials = [ ];
var acceptToken = (function(token) {
// token:required
return (parseStack)[0].push(token);
});
;
var increaseNesting = (function() {
- var newArr = [ ];;
+ var newArr = [ ];
acceptToken(newArr);
return parseStack.unshift(newArr);
});
@@ -222,7 +222,7 @@ var tokenize = sibilant.tokenize = (function(string) {
var handleToken = (function(token) {
// token:required
var special = (token)[0],
- token = token;;
+ token = token;
(function() {
if ((special === "'")) {
token = token.slice(1);
@@ -272,7 +272,7 @@ var tokenize = sibilant.tokenize = (function(string) {
// x:required
return (sibilant.tokens)[x];
})),
- masterRegex = (new RegExp((orderedRegexen).join("|"), "g"));;
+ masterRegex = (new RegExp((orderedRegexen).join("|"), "g"));
string // chain
.match(masterRegex)
.forEach(handleToken)
@@ -301,7 +301,7 @@ var constructHash = (function(arrayOfArrays) {
// arrayOfArrays:required
return inject({ }, arrayOfArrays, (function(object, item) {
// object:required item:required
- (object)[(item)[0]] = (object)[(item)[1]];;
+ (object)[(item)[0]] = (object)[(item)[1]];
return object;
}));
});
@@ -310,7 +310,7 @@ var macros = { };
(sibilant)["macros"] = macros;
(macros)["return"] = (function(token) {
// token:required
- var defaultReturn = ("return " + translate(token));;
+ var defaultReturn = ("return " + translate(token));
return (function() {
if ((token) && (token).constructor.name === "Array") {
return (function() {
@@ -373,8 +373,8 @@ macros.progn = (function(body) {
// body:rest
var body = Array.prototype.slice.call(arguments, 0);
- var lastIndex = Math.max(0, (body.length - 1));;
- (body)[lastIndex] = [ "return", (body)[lastIndex] ];;
+ var lastIndex = Math.max(0, (body.length - 1));
+ (body)[lastIndex] = [ "return", (body)[lastIndex] ];
return (map(body, (function(arg) {
// arg:required
return (translate(arg) + ";");
@@ -399,7 +399,7 @@ macros.defun = (function(fnName, argsAndBody) {
} else {
return "var ";
};
- })();;
+ })();
return (start + fnNameTr + " = " + macros.lambda.apply(undefined, argsAndBody) + ";\n");
});
@@ -408,7 +408,7 @@ macros.defmacro = (function(name, argsAndBody) {
var argsAndBody = Array.prototype.slice.call(arguments, 1);
var js = macros.lambda.apply(undefined, argsAndBody),
- name = translate(name);;
+ name = translate(name);
(function() {
try {
return (macros)[name] = eval(js);;
@@ -429,7 +429,7 @@ macros.concat = (function(args) {
var transformArgs = (function(arglist) {
// arglist:required
var last = undefined,
- args = [ ];;
+ args = [ ];
arglist.forEach((function(arg) {
// arg:required
return (function() {
@@ -451,7 +451,7 @@ var transformArgs = (function(arglist) {
macros.reverse = (function(arr) {
// arr:required
- var reversed = [ ];;
+ var reversed = [ ];
arr.forEach((function(item) {
// item:required
return reversed.unshift(item);
@@ -463,7 +463,7 @@ var reverse = macros.reverse;
var buildArgsString = (function(args, rest) {
// args:required rest:required
var argsString = "",
- optionalCount = 0;;
+ optionalCount = 0;
args.forEach((function(arg, optionIndex) {
// arg:required optionIndex:required
return (function() {
@@ -513,8 +513,8 @@ macros.lambda = (function(arglist, body) {
// arg:required
return ("rest" === (arg)[0]);
})))[0],
- docString = undefined;;
- (body)[(body.length - 1)] = [ "return", (body)[(body.length - 1)] ];;
+ docString = undefined;
+ (body)[(body.length - 1)] = [ "return", (body)[(body.length - 1)] ];
(function() {
if (((typeof((body)[0]) === "string") && (body)[0].match(/^".*"$/))) {
return docString = ("/* " + eval(body.shift()) + " */\n");
@@ -528,13 +528,20 @@ macros.lambda = (function(arglist, body) {
};
})(),
argsString = buildArgsString(noRestArgs, rest),
- commentString = buildCommentString(args);;
+ commentString = buildCommentString(args);
return ("(function(" + (map(args, (function(arg) {
// arg:required
return translate((arg)[1]);
}))).join(", ") + ") {" + indent(commentString, docString, argsString, (map(body, (function(stmt) {
// stmt:required
- return (translate(stmt) + ";");
+ var tstmt = translate(stmt);
+ return (tstmt + (function() {
+ if (((tstmt.slice(-1))[0] === ";")) {
+ return "";
+ } else {
+ return ";";
+ };
+ })());
}))).join("\n")) + "})");
});
@@ -567,7 +574,7 @@ macros.hash = (function(pairs) {
var pairStrings = bulkMap(pairs, (function(key, value) {
// key:required value:required
return (translate(key) + ": " + translate(value));
- }));;
+ }));
return (function() {
if ((1 >= pairStrings.length)) {
return ("{ " + (pairStrings).join(", ") + " }");
@@ -591,7 +598,7 @@ var literal = (function(string) {
var translate = (function(token, hint) {
// token:required hint:required
- var hint = hint;;
+ var hint = hint;
(function() {
if ((hint && typeof((macros)[hint]) === 'undefined')) {
return hint = undefined;
@@ -652,10 +659,10 @@ var translate = (function(token, hint) {
(sibilant)["translate"] = translate;
var translateAll = (function(contents) {
// contents:required
- var buffer = "";;
+ var buffer = "";
tokenize(contents).forEach((function(token) {
// token:required
- var line = translate(token, "statement");;
+ var line = translate(token, "statement");
return (function() {
if (line) {
return buffer = (buffer + line + "\n");
View
4 src/core.sibilant
@@ -264,7 +264,9 @@
(join "\n"
(map body
(lambda (stmt)
- (concat (translate stmt) ";")))))
+ (defvar tstmt (translate stmt))
+ (concat tstmt
+ (if (= (last tstmt) ";") "" ";"))))))
"})"))
View
5 test/defvar.sibilant
@@ -0,0 +1,5 @@
+(defun alert-hello (planet-name)
+ (defvar message (concat "hello " planet-name))
+ message)
+
+(defvar foo (concat "hi " "there"))
Please sign in to comment.
Something went wrong with that request. Please try again.