Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #44 from humasect/master

Support Node.js >= 0.6.x

jbr: I haven't been able to test this because I'm on sabbatical in Panamá. It looks reasonable, though.
  • Loading branch information...
commit 38c863fa1f343d14d654c38a0d4a6bd101dec9ac 2 parents b89cbbb + 4504bda
@jbr authored
View
3  .gitignore
@@ -1,3 +1,4 @@
public/.sass-cache
lib/core.js
-tmp/*
+tmp/*
+*.swp
View
2  bin/sibilant
@@ -1,3 +1,3 @@
#!/usr/bin/env node
-require ('sibilant/lib/cli')
+require ('./../lib/cli')
View
14 include/functional.sibilant
@@ -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)
@@ -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
View
6 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();
@@ -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) {
View
6 lib/repl.js
@@ -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");;
@@ -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;;
View
11 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,
@@ -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"));
View
4 misc/sibilant-mode.el
@@ -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))
))
View
4 src/browser.sibilant
@@ -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
View
8 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))
@@ -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)
@@ -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
View
60 src/core.sibilant
@@ -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) "")))
@@ -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))))
@@ -97,9 +97,9 @@
(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)
@@ -107,7 +107,7 @@
(set macros 'return
(lambda (token)
(defvar default-return (concat "return " (translate token)))
-
+
(if (array? token)
(switch (first token)
('(return throw progn) (translate token))
@@ -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)
@@ -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)
@@ -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)
@@ -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) ": "
@@ -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)))))
View
8 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))
@@ -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 /^-+/ "")))
@@ -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)
@@ -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))
View
14 src/repl.sibilant
@@ -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))
@@ -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
@@ -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
View
18 src/sibilant.sibilant
@@ -1,11 +1,11 @@
(defvar sibilant exports
- sys (require 'sys)
+ util (require 'util)
path (require 'path)
fs (require 'fs)
- error (lambda (str) (throw str))
- inspect sys.inspect)
+ error (lambda (str) (throw (new (Error str))))
+ inspect util.inspect)
-(include "sibilant/include/functional")
+(include "../include/functional")
(defun sibilant.package-info ()
(defvar fs (require 'fs))
@@ -16,7 +16,7 @@
(defvar package (sibilant.package-info)
path (require 'path))
(concat package.name " version " package.version
- "\n(at " (path.join **dirname "..") ")"))
+ "\n(at " (path.join **dirname "..") ")"))
(defun sibilant.strip-shebang (data)
(data.replace /^#!.*\n/ ""))
@@ -68,13 +68,13 @@
(defvar resolved (require.resolve file))
(sibilant.translate-file resolved))
-
-(include "sibilant/src/core")
+
+(include "../src/core")
(defun macros.include (file)
(sibilant.include (eval (translate file))))
-(require.paths.unshift (concat **dirname "/../include"))
+;;(require.paths.unshift (concat **dirname "/../include"))
-(sibilant.include 'macros)
+(sibilant.include (concat process.env.NODE*PATH "/sibilant/include/macros"))
Please sign in to comment.
Something went wrong with that request. Please try again.