Permalink
Browse files

Merging cadorn's stuff

  • Loading branch information...
1 parent 27b49bf commit 308d4a7769dc3981c8cde36eebba7d9d9176a571 @kriszyp kriszyp committed Nov 18, 2009
View
@@ -19,6 +19,22 @@ Bleeding Edge
Releases
--------
-<div id="releases-list">Loading...</div>
-<script type="text/javascript" charset="utf-8" src="js/releases.js"></script>
-<script type="text/javascript" charset="utf-8" src="http://github.com/api/v2/json/repos/show/tlrobinson/narwhal/tags?callback=showreleases"></script>
+<div id="releases">Loading...</div>
+<script type="text/javascript" charset="utf-8">
+ function showreleases(response) {
+ var releases = [];
+ for (var tag in response.tags) {
+ var tar = "http://github.com/tlrobinson/narwhal/tarball/"+tag,
+ zip = "http://github.com/tlrobinson/narwhal/zipball/"+tag;
+ commit = "http://github.com/tlrobinson/narwhal/commit/"+response.tags[tag],
+ tree = "http://github.com/tlrobinson/narwhal/tree/"+response.tags[tag];
+ releases.push('<li>'+tag+': [<a href="'+zip+'">zip</a>][<a href="'+tar+'">tar</a>][<a href="'+tree+'">tree</a>][<a href="'+commit+'">commit</a>]</li>');
+ }
+ releases = releases.sort();
+ var reversed = [];
+ while (releases.length) reversed.push(releases.pop());
+
+ document.getElementById("releases").innerHTML = "<ul>" + reversed.join("\n") + "</ul>";
+ }
+</script>
+<script type="text/javascript" charset="utf-8" src="http://github.com/api/v2/json/repos/show/tlrobinson/narwhal/tags?callback=showreleases"></script>
View
@@ -163,6 +163,10 @@ Environment Variables
`SHLVL` (shell level) that is the number of instances
of `sea` the present shell is running in.
+* `NARWHAL_JS_VERSION` refers to the JavaScript version,
+ that defaults to `"170"` for "1.7.0", and is used by
+ Rhino on Java to determine the valid JavaScript syntax.
+
Configuration Files
-------------------
View
@@ -0,0 +1,13 @@
+# Ignore all
+
+/*
+
+# except for
+
+!/.gitignore
+
+!/browser
+!/default
+!/rhino
+!/secure
+!/template
@@ -570,7 +570,15 @@ ByteArray.prototype.pop = function() {
// push(...variadic Numbers...)-> count Number
ByteArray.prototype.push = function() {
- throw "NYI";
+ var length, newLength = this.length += length = arguments.length;
+ try {
+ for (var i = 0; i < length; i++)
+ this.set(newLength - length + i, arguments[i]);
+ } catch (e) {
+ this.length -= length;
+ throw e;
+ }
+ return newLength;
};
// extendRight(...variadic Numbers / Arrays / ByteArrays / ByteStrings ...)
@@ -591,7 +599,17 @@ ByteArray.prototype.shift = function() {
// unshift(...variadic Numbers...) -> count Number
ByteArray.prototype.unshift = function() {
- throw "NYI";
+ var copy = this.slice();
+ this.length = 0;
+ try {
+ this.push.apply(this, arguments);
+ this.push.apply(this, copy.toArray());
+ return this.length;
+ } catch(e) {
+ B_COPY(copy._bytes, copy._offset, this._bytes, this._offset, copy.length);
+ this.length = copy.length;
+ throw e;
+ }
};
// extendLeft(...variadic Numbers / Arrays / ByteArrays / ByteStrings ...)
@@ -638,8 +656,18 @@ ByteArray.prototype.sort = function(compareFunction) {
};
// splice()
-ByteArray.prototype.splice = function() {
- throw "NYI";
+ByteArray.prototype.splice = function(index, howMany /*, elem1, elem2 */) {
+ if (index === undefined) return;
+ if (index < 0) index += this.length;
+ if (howMany === undefined) howMany = this._length - index;
+ var end = index + howMany;
+ var remove = this.slice(index, end);
+ var keep = this.slice(end);
+ var inject = Array.prototype.slice.call(arguments, 2);
+ this._length = index;
+ this.push.apply(this, inject);
+ this.push.apply(this, keep.toArray());
+ return remove;
};
// indexOf() - implemented on Binary
@@ -33,6 +33,10 @@ if [ "$(which cygpath 2>/dev/null)" ]; then
export NARWHAL_ENGINE_HOME=$(cygpath -wa -- "$NARWHAL_ENGINE_HOME")
fi
+if [ -z "$NARWHAL_JS_VERSION" ]; then
+ NARWHAL_JS_VERSION=170
+fi
+
if [ -z "$NARWHAL_DEBUGGER" ] || [ "$NARWHAL_DEBUGGER" -eq 0 ]; then
JAVA_MAIN=org.mozilla.javascript.tools.shell.Main
else
@@ -59,6 +63,6 @@ if [ $# -lt 1 ]; then
fi
$RLWRAP java $NARWHAL_JAVA_ARGUMENTS -cp "$BOOTCLASSPATH:$CLASSPATH" "$JAVA_MAIN" -f "$BOOTSTRAP" -f -
else
- java $NARWHAL_JAVA_ARGUMENTS -cp "$BOOTCLASSPATH:$CLASSPATH" "$JAVA_MAIN" "$BOOTSTRAP" "$0" "$@"
+ java $NARWHAL_JAVA_ARGUMENTS -cp "$BOOTCLASSPATH:$CLASSPATH" "$JAVA_MAIN" -version "$NARWHAL_JS_VERSION" "$BOOTSTRAP" "$0" "$@"
fi
@@ -18,10 +18,10 @@ if not "%NARWHAL_CLASSPATH%" == "" (
set CLASSPATH=%NARWHAL_CLASSPATH%;%CLASSPATH%
)
-if not "%NARWHAL_DEBUGGER%" == "" (
+if "%NARWHAL_DEBUGGER%" == "" (
set JAVA_MAIN=org.mozilla.javascript.tools.shell.Main
)
-if "%NARWHAL_DEBUGGER%" == "" (
+if not "%NARWHAL_DEBUGGER%" == "" (
set JAVA_MAIN=org.mozilla.javascript.tools.debugger.Main
)
@@ -5,6 +5,7 @@
var isFile = /*TODO*/; // function(path:string):boolean
var prefix = "/path/to/narwhal"; /*TODO*/
+ var enginePrefix = "/path/to/engine"; /*TODO*/
eval(read(prefix + "/narwhal.js"))({
global: this,
@@ -29,6 +30,7 @@
isFile: isFile
},
prefix: prefix,
+ prefixes: [prefix, enginePrefix],
debug: false,
verbose: false
});
View
@@ -28,15 +28,15 @@ var transaction = (function () {
function HttpClient (settings) {
if (!(this instanceof HttpClient)) return new HttpClient(settings);
if (!this.txId) this.create();
- if (settings) this.set(settings);
+ if (settings) this.setOptions(settings);
};
HttpClient.prototype = {
create : function HttpClient_create () {
// clean up, set up defaults.
transaction(this.txId, true);
this.txId = newTransactionId();
- this.set({
+ this.setOptions({
"method" : "GET",
"headers" : {},
"body" : []
@@ -53,10 +53,10 @@ HttpClient.prototype = {
var guts = transaction(this.txId);
switch (key) {
case "headers":
- if (typeof settings.headers !== 'object') throw new Error(
+ if (typeof val !== 'object') throw new Error(
"HttpClient: headers must be a simple object."
);
- return this.setHeaders(settings.headers);
+ return this.setHeaders(val);
case "body":
if (typeof val.forEach !== 'function') throw new Error(
"HttpClient: body must be iterable."
@@ -2,5 +2,5 @@ var Q = require("ref-send");
Q.when(require.async("util"), function (util) {
print("Hello, World!");
print(util.keys({"a": 10, "b": 20}).join(', '));
- //alert(util.upper('hi'));
+ alert(util.upper('hi'));
});
View
@@ -47,7 +47,7 @@ exports.Bundler = function (system) {
var depends = [];
loader.fetch(baseId).replace(
// TODO proper recursive descent parser
- /require\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
+ /(?:^|\s+|;)require\s*\(\s*(['"])([^'"]+)\1\s*\)/g,
function (all, quote, id) {
depends.push(loader.resolve(id, baseId));
return all;
View
@@ -27,8 +27,7 @@ parser.command('remove', null)
parser.command('update', module.id + '/update');
-parser.command('search', null)
- .help('searches the package catalog');
+parser.command('search', module.id + '/search');
parser.command('init', module.id + '/init');
@@ -89,6 +88,7 @@ exports.readCatalog = function () {
var catalog = json.decode(catalogPath.read({charset: 'utf-8'}));
if (catalog.version === undefined || +catalog.version < minCatalogVersion)
throw new Error("catalog is out of date. use tusk update or create-catalog");
+ packages.normalize(catalog.packages);
return catalog;
};
@@ -11,7 +11,7 @@ parser.action(function (options) {
var self = this;
if (!tusk.getCatalogPath().isFile())
require('./update').update.call(this, options);
- util.forEachApply(util.items(tusk.readCatalog().packages), function (name, info) {
+ util.forEachApply(tusk.readCatalog().packages, function (name, info) {
name = info.name || name;
self.print(
"\0green(" + name + "\0)" +
View
@@ -0,0 +1,145 @@
+
+var tusk = require("../tusk");
+var util = require("util");
+var http = require("http");
+var packages = require("packages");
+var stream = require("term").stream;
+
+var Parser = exports.Parser = function () {
+};
+
+Parser.prototype.act = function (args, options) {
+ this._action(args, options);
+};
+
+Parser.prototype._action = function (args, options) {
+ var command = args.shift();
+ var packages = tusk.readCatalog().packages;
+ index(packages);
+ var predicate = Or(args);
+ var results = util.values(packages).map(function (info) {
+ return [predicate(info), info];
+ }).filter(function (pair) {
+ return pair[0] != 0;
+ });
+ util.sort(results);
+ util.forEachApply(results, function (score, info) {
+ stream.print(
+ "\0green(" + info.name + "\0)" +
+ (info.description ? ": " + info.description : "")
+ );
+ });
+ options.acted = true;
+};
+
+var index = function (packages) {
+ util.forEachApply(packages, function (name, info) {
+ if (!info.name) {
+ info.name = name;
+ }
+ if (!info.fullText) {
+ info.fullText = [
+ info.name
+ ].concat(info.keywords).concat([
+ info.description
+ ]).join(" ");
+ }
+ });
+ return packages;
+}
+
+var Text = function (args) {
+ args = args.map(function (arg) {
+ return new RegExp(
+ "\\b" + RegExp.escape(arg) + "\\b",
+ "i"
+ );
+ });
+ return function (info) {
+ var accumulator = undefined;
+ return Math.min.apply(this, args.map(function (arg) {
+ return info.fullText.search(arg) + 1;
+ }));
+ }
+};
+
+var Terms = function (args) {
+ for (var length = 0; length < args.length; length++)
+ if (args[length] == "--")
+ break;
+ if (length) {
+ if (/^--/.test(args[0])) {
+ var pattern = args.shift().match(/^--([^=]+)(?:=(.*))?/).slice(1);
+ var key = pattern[0];
+ var value = pattern[1];
+ if (!!value) {
+ args.unshift(value);
+ }
+ var parts = key.split(".");
+ return function (info) {
+ parts.forEach(function (part) {
+ if (Array.isArray(info)) {
+ info = info.map(function (node) {
+ if (node)
+ return node[part];
+ });
+ } else if (info) {
+ info = info[part];
+ }
+ });
+ var value = args[0];
+ if (Array.isArray(info)) {
+ return util.has(info, value);
+ } else {
+ return info == value;
+ }
+ }
+ } else if (/^-/.test(args[0])) {
+ throw new Error("Option " + args[0] + " not recognized.");
+ } else {
+ return Text(args);
+ }
+ } else {
+ return Text(args);
+ }
+};
+
+// - recursive descent scanner
+// - divide and conquor
+
+var BinaryOperator = function (Low, High, _, __) {
+ return function Self(args) {
+ var length = args.length;
+ for (var i = 0; i < length; i++)
+ if (args[i] == "--")
+ break;
+ while (i >= 0) {
+ i--;
+ var arg = args[i];
+ if (arg == _ || arg == __) {
+ var left = Self(args.slice(0, i));
+ var right = High(args.slice(i + 1));
+ return function () {
+ return Low(
+ left.apply(this, arguments),
+ right.apply(this, arguments)
+ );
+ }
+ }
+ }
+ return High(args);
+ }
+}
+
+var And = BinaryOperator(function (lhs, rhs) {
+ return lhs * rhs;
+}, Terms, '-a', '--and');
+
+var Or = BinaryOperator(function (lhs, rhs) {
+ return lhs || rhs ? lhs + rhs : 0;
+}, And, '-o', '--or');
+
+Parser.prototype._help = "{keyword}, --and, --or, --{key} {value}";
+
+exports.parser = new Parser();
+
Oops, something went wrong.

0 comments on commit 308d4a7

Please sign in to comment.