Permalink
Browse files

Examples.

  • Loading branch information...
1 parent 21f68e1 commit 1cfb9f0edb8133db6292c613bf7be00a286ab263 @zaach committed Jul 22, 2010
Showing with 69 additions and 0 deletions.
  1. +52 −0 README.md
  2. +17 −0 examples/function-decl.js
View
52 README.md
@@ -1,4 +1,56 @@
+Welcome to the café
+===================
+We feature the most exquisite compilers to brew your JavaScript just the way you like it.
+There is much work to be done but a few recipes are ready for you to try and help improve.
+No refunds if you grow a third arm!
+
+Install
+-------
+Clone the repository with git.
+
js.js
+-----
+Here's an example of callbacks from the examples directory:
+
+ var
+ sys = require("sys"),
+ cafe = require("../lib/cafe"),
+ compiler = new cafe.js.Compiler();
+
+ compiler.on("parse:FunctionDecl", function () {
+ sys.puts(sys.inspect(this));
+
+ // rewrite the function name
+ this.children[0].name = 'zomg';
+ });
+
+ var source = "function foo (bar) { return this; }";
+
+ var ast = compiler.parse(source);
+
+ sys.puts(ast.toJS(0));
+
+Run with node:
+
+ node ./examples/function-decl.js
+
+The script is parsed in AST form, which you can modify, and then converted back to JavaScript.
+I'm not sure what kind of API cafe will have, really, but this seemed like something cool and easy to show. There are more tricks possible.
+
objj.js
+-------
+There's also an Objective-J to JavaScript compiler. It doesn't contain the Objective-J runtime or anything, but could help catch syntactic errors. It probably needs an official once over from 280North to make sure it's correct, but when it is it should be better at catching syntax errors than the official Objective-J parser.
+
harmony.js (soon)
+----------------
+I plan to have a Simple Modules to JavaScript and CommonJS module compilation and other syntactic goodies.
+
+(your js here).js
+-----------------
+Whatever, let's go wild and add stuff.
+
+
+To be continued...
+
+-Zach
View
17 examples/function-decl.js
@@ -0,0 +1,17 @@
+var
+ sys = require("sys"),
+ cafe = require("../lib/cafe"),
+ compiler = new cafe.js.Compiler();
+
+compiler.on("parse:FunctionDecl", function () {
+ sys.puts(sys.inspect(this));
+
+ // rewrite the function name
+ this.children[0].name = 'zomg';
+});
+
+var source = "function foo (bar) { return this; }";
+
+var ast = compiler.parse(source);
+
+sys.puts(ast.toJS(0));

0 comments on commit 1cfb9f0

Please sign in to comment.