Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Node.js >= 0.6.x #44

Merged
merged 7 commits into from Mar 13, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
public/.sass-cache
lib/core.js
tmp/*
tmp/*
*.swp
2 changes: 1 addition & 1 deletion bin/sibilant
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require ('sibilant/lib/cli')
require ('./../lib/cli')
14 changes: 7 additions & 7 deletions include/functional.sibilant
Expand Up @@ -5,8 +5,8 @@

(while (< index arr.length)
(send ret-arr push
(apply fn (send arr slice
index (+ index group-size))))
(apply fn (send arr slice
index (+ index group-size))))
(incr-by index group-size))
ret-arr)

Expand All @@ -19,15 +19,15 @@

(defun map (items fn)
(inject [] items
(lambda (collector item index)
(lambda (collector item index)
(collector.concat (fn item index)))))

(defun select (items fn)
(inject [] items
(lambda (collector item index)
(when (fn item index)
(send collector push item))
collector)))
(lambda (collector item index)
(when (fn item index)
(send collector push item))
collector)))

(defun detect (items fn)
(defvar return-item undefined
Expand Down
6 changes: 3 additions & 3 deletions lib/cli.js
@@ -1,6 +1,6 @@
var sibilant = require("sibilant"),
var sibilant = require("./sibilant"),
path = require("path"),
options = require("sibilant/lib/options"),
options = require("../lib/options"),
fs = require("fs"),
vm = require("vm"),
context = vm.createContext();
Expand Down Expand Up @@ -59,7 +59,7 @@ cli.repl = (function(args) {
// args:rest
var args = Array.prototype.slice.call(arguments, 0);

return require("sibilant/lib/repl");
return require("../lib/repl");
});

cli.eval = (function(args) {
Expand Down
6 changes: 3 additions & 3 deletions lib/repl.js
Expand Up @@ -2,10 +2,10 @@ var input = process.openStdin(),
output = process.stdout,
vm = require("vm"),
readline = require("readline").createInterface(input, output),
sibilant = require("sibilant"),
sibilant = require("./sibilant"),
context = undefined,
cmdBuffer = "",
sys = require("sys");
util = require("util");
var createContext = (function() {
var context = vm.createContext();;
(module)["filename"] = (process.cwd() + "/exec");;
Expand Down Expand Up @@ -51,7 +51,7 @@ readline.on("line", (function(cmd) {
(readline.history)[0] = cmdBuffer;;
(function() {
if (typeof(result) !== 'undefined') {
return output.write(("result: " + sys.inspect(result) + "\n"));
return output.write(("result: " + util.inspect(result) + "\n"));
};
})();
(context)["_"] = result;;
Expand Down
11 changes: 5 additions & 6 deletions lib/sibilant.js
@@ -1,12 +1,12 @@
var sibilant = exports,
sys = require("sys"),
util = require("util"),
path = require("path"),
fs = require("fs"),
error = (function(str) {
// str:required
throw new Error (str);
throw new Error ((new Error(str)));
}),
inspect = sys.inspect;
inspect = util.inspect;
var bulkMap = (function(arr, fn) {
// arr:required fn:required
var index = 0,
Expand Down Expand Up @@ -671,7 +671,6 @@ macros.include = (function(file) {
return sibilant.include(eval(translate(file)));
});

require.paths.unshift((__dirname + "/../include"));

sibilant.include("macros");
//(require.paths.unshift (concat **dirname "/../include"))
sibilant.include((process.env.NODE_PATH + "/sibilant/include/macros"));

4 changes: 2 additions & 2 deletions misc/sibilant-mode.el
Expand Up @@ -65,10 +65,10 @@
(1 font-lock-keyword-face)
(2 font-lock-variable-name-face))
("(\\(thunk\\|if\\|when\\|apply\\|concat\\|throw\\|switch\\|each\\|chain\\|try\\|progn\\|call\\|default\\)[ \t\r\n)]+"
(1 font-lock-keyword-face))
(1 font-lock-builtin-face))
("&[[:alnum:]]+" . font-lock-keyword-face)
("'[[:alnum:].-]+[?!]?" . font-lock-string-face)
("(\\([[:alnum:].-]+[?!]?\\)" (1 font-lock-function-name-face nil t))
("(\\([[:alnum:].-]+[?!]?\\)" (1 font-lock-constant-face nil t))
))


Expand Down
4 changes: 2 additions & 2 deletions src/browser.sibilant
Expand Up @@ -5,8 +5,8 @@
(set window 'sibilant sibilant)

(defvar exports {})
(include "sibilant/include/functional")
(include "sibilant/src/core")
(include "../include/functional")
(include "../src/core")

($ (thunk
(defvar sibilant window.sibilant
Expand Down
8 changes: 4 additions & 4 deletions src/cli.sibilant
@@ -1,6 +1,6 @@
(defvar sibilant (require 'sibilant)
(defvar sibilant (require "./sibilant")
path (require 'path)
options (require "sibilant/lib/options")
options (require "../lib/options")
fs (require 'fs)
vm (require 'vm)
context (vm.create-context))
Expand Down Expand Up @@ -35,7 +35,7 @@
(defun cli.version (&rest args)
(console.log (sibilant.version-string)))

(defun cli.repl (&rest args) (require "sibilant/lib/repl"))
(defun cli.repl (&rest args) (require "../lib/repl"))

(defun cli.eval (&rest args)
(if (empty? args)
Expand Down Expand Up @@ -130,7 +130,7 @@ $ sibilant --repl
(each (input-file) (or cli-options.input [])
(defvar input-path (path.join (process.cwd) input-file)
translated (sibilant.translate-file input-path))

(if output-dir
(progn
(defvar
Expand Down
60 changes: 30 additions & 30 deletions src/core.sibilant
Expand Up @@ -60,7 +60,7 @@

("{" (increase-nesting) (accept-token 'hash))
("[" (increase-nesting) (accept-token 'list))

(default
(if (token.match (regex (concat "^" sibilant.tokens.number "$")))
(accept-token (parse-float (token.replace (regex "," 'g) "")))
Expand All @@ -79,7 +79,7 @@
(chain string
(match master-regex)
(for-each handle-token))

(when (> parse-stack.length 1)
(error "unexpected EOF, probably missing a )\n"
(call inspect (first parse-stack))))
Expand All @@ -97,17 +97,17 @@

(defun construct-hash (array-of-arrays)
(inject {} array-of-arrays
(lambda (object item)
(set object (first item) (get object (second item)))
object)))
(lambda (object item)
(set object (first item) (get object (second item)))
object)))

(defvar macros (hash))
(set sibilant 'macros macros)

(set macros 'return
(lambda (token)
(defvar default-return (concat "return " (translate token)))

(if (array? token)
(switch (first token)
('(return throw progn) (translate token))
Expand All @@ -127,15 +127,15 @@
(if (< token.length 5) default-return
(progn
(defvar obj (second token)
non-return-part (token.slice 2 (- token.length 2))
return-part (token.slice -2))
non-return-part (token.slice 2 (- token.length 2))
return-part (token.slice -2))
(non-return-part.unshift obj)
(return-part.unshift obj)
(concat (apply macros.set non-return-part)
"\nreturn "
(apply macros.set return-part)))))
(default default-return))
default-return)))
default-return)))


(defun macros.statement (&rest args)
Expand All @@ -147,26 +147,26 @@
(set body last-index ['return (get body last-index)])

(join "\n"
(map body (lambda (arg)
(concat (translate arg) ";")))))
(map body (lambda (arg)
(concat (translate arg) ";")))))

(defun macros.call (fn-name &rest args)
(concat (translate fn-name)
"(" (join ", " (map args translate)) ")"))
"(" (join ", " (map args translate)) ")"))

(defun macros.defun (fn-name &rest args-and-body)
(defvar fn-name-tr (translate fn-name)
start (if (match? /\./ fn-name-tr) "" "var "))
(concat start fn-name-tr " = "
(apply macros.lambda args-and-body)
";\n"))
(apply macros.lambda args-and-body)
";\n"))

(defun macros.defmacro (name &rest args-and-body)
(defvar js (apply macros.lambda args-and-body)
name (translate name))
(try (set macros name (eval js))
(error (concat "error in parsing macro "
name ":\n" (indent js))))
name ":\n" (indent js))))
undefined)

(defun macros.concat (&rest args)
Expand Down Expand Up @@ -249,23 +249,23 @@
[ 'return (get body (- body.length 1)) ])

(when (and (= (typeof (first body)) 'string)
(send (first body) match /^".*"$/))
(send (first body) match /^".*"$/))
(setf doc-string
(concat "/* " (eval (body.shift)) " */\n")))
(concat "/* " (eval (body.shift)) " */\n")))

(defvar no-rest-args (if rest (args.slice 0 -1) args)
args-string (build-args-string no-rest-args rest)
comment-string (build-comment-string args))

(concat "(function("
(join ", " (map args (lambda (arg) (translate (second arg)))))
") {"
(indent comment-string doc-string args-string
(join "\n"
(map body
(lambda (stmt)
(concat (translate stmt) ";")))))
"})"))
(join ", " (map args (lambda (arg) (translate (second arg)))))
") {"
(indent comment-string doc-string args-string
(join "\n"
(map body
(lambda (stmt)
(concat (translate stmt) ";")))))
"})"))


(defun macros.quote (item)
Expand All @@ -277,8 +277,8 @@
(defun macros.hash (&rest pairs)
(when (odd? pairs.length)
(error (concat
"odd number of key-value pairs in hash: "
(call inspect pairs))))
"odd number of key-value pairs in hash: "
(call inspect pairs))))
(defvar pair-strings
(bulk-map pairs (lambda (key value)
(concat (translate key) ": "
Expand All @@ -293,9 +293,9 @@
(replace /\*/g "_")
(replace /\?$/ "__QUERY")
(replace /!$/ "__BANG"))
(string.match /-(.)/g)
(lambda (return-string match)
(return-string.replace match
(string.match /-(.)/g)
(lambda (return-string match)
(return-string.replace match
(send (second match) to-upper-case)))))


Expand Down
8 changes: 4 additions & 4 deletions src/options.sibilant
@@ -1,4 +1,4 @@
(include "sibilant/include/functional")
(include "../include/functional")

(defun extract-options (config &optional args)
(defvar args (or args (process.argv.slice 2))
Expand All @@ -20,7 +20,7 @@
(!= false (get config (label-for item))))

(setf default-label (synonym-lookup default-label)
current-label default-label)
current-label default-label)

(defun label-for (item)
(synonym-lookup (item.replace /^-+/ "")))
Expand All @@ -37,7 +37,7 @@
(setf current-label default-label))

(inject {} args
(lambda (return-hash item index)
(lambda (return-hash item index)
(if (= "--" item) (setf after-break true)
(if after-break
(add-value return-hash 'after-break item)
Expand All @@ -49,7 +49,7 @@
(progn
(add-value return-hash current-label item)
(reset-label)))))
return-hash)))
return-hash)))

(defun process-options (&optional config)
(defvar options (extract-options config))
Expand Down
14 changes: 7 additions & 7 deletions src/repl.sibilant
Expand Up @@ -2,10 +2,10 @@
output process.stdout
vm (require 'vm)
readline (send (require 'readline) create-interface input output)
sibilant (require 'sibilant)
context undefined
cmd-buffer ""
sys (require 'sys))
sibilant (require "./sibilant")
context undefined
cmd-buffer ""
util (require 'util))

(defun create-context ()
(defvar context (vm.create-context))
Expand All @@ -22,8 +22,8 @@
(readline.set-prompt
(concat (if (> cmd-buffer.length 10)
(concat "..." (cmd-buffer.slice -10))
(if (> cmd-buffer.length 0) cmd-buffer "sibilant"))
"> "))
(if (> cmd-buffer.length 0) cmd-buffer "sibilant"))
"> "))
(readline.prompt))

(readline.on 'line
Expand All @@ -40,7 +40,7 @@
(set readline.history 0 cmd-buffer)
(when (defined? result)
(output.write (concat "result: "
(sys.inspect result) "\n")))
(util.inspect result) "\n")))
(set context "_" result)
(setf cmd-buffer ""))
(progn
Expand Down