Permalink
Browse files

beginnings of a build script

  • Loading branch information...
1 parent fa63288 commit 2f389f1d5197624e7e0b0ecad7b6c64ffd1943dd @jashkenas committed Feb 16, 2010
Showing with 47 additions and 20 deletions.
  1. +6 −1 README
  2. +24 −0 build.coffee
  3. +8 −0 lib/coffee_script/command_line.js
  4. +2 −10 lib/coffee_script/grammar.js
  5. +6 −0 src/command_line.coffee
  6. +1 −9 src/grammar.coffee
View
7 README
@@ -43,4 +43,9 @@
is in the works. Check out /src for the details. To try it out, use
bin/node_coffee. To have CoffeeScript recompile itself, run:
- bin/node_coffee -o lib/coffee_script src/*.coffee
+ build compiler
+
+ To rebuild the Jison parser (takes about 30 seconds), run:
+
+ build grammar
+
View
@@ -0,0 +1,24 @@
+# Custom build scripts, replacing the Rakefile. To invoke (for example):
+#
+# bin/node_coffee -r build.coffee -- parser
+
+fs: require 'fs'
+
+# Print the usage message for the build scripts.
+usage: ->
+ puts "build.coffee usage goes here..."
+
+# Rebuild the Jison parser from the compiled lib/grammar.js file.
+build_parser: ->
+ parser: require('grammar').parser
+ js: parser.generate()
+ parser_path: 'lib/coffee_script/parser.js'
+ fs.open(parser_path, process.O_CREAT | process.O_WRONLY | process.O_TRUNC, parseInt('0755', 8)).addCallback (fd) ->
+ fs.write(fd, js)
+
+switch process.ARGV[0]
+ when undefined then usage()
+ when 'compiler' then build_compiler()
+ when 'parser' then build_parser()
+ when 'highlighter' then build_highlighter()
+ when 'underscore' then build_underscore()
@@ -15,6 +15,7 @@
option_parser = null;
// The CommandLine handles all of the functionality of the `coffee` utility.
exports.run = function run() {
+ var flags, separator;
parse_options();
if (options.interactive) {
return require('./repl');
@@ -25,6 +26,13 @@
if (!(sources.length)) {
usage();
}
+ separator = sources.indexOf('--');
+ flags = [];
+ if (separator >= 0) {
+ flags = sources.slice((separator + 1), sources.length);
+ sources = sources.slice(0, separator);
+ }
+ process.ARGV = flags;
compile_scripts();
return this;
};
@@ -1,5 +1,5 @@
(function(){
- var Parser, _1, _2, _3, _4, _5, _6, bnf, fs, grammar, js, name, non_terminal, o, operators, option, parser, parser_path, part, tokens, unwrap;
+ var Parser, _1, _2, _3, _4, _5, _6, bnf, grammar, name, non_terminal, o, operators, option, part, tokens, unwrap;
var __hasProp = Object.prototype.hasOwnProperty;
Parser = require('jison').Parser;
// DSL ===================================================================
@@ -544,20 +544,12 @@
}).call(this);
}
tokens = tokens.join(" ");
- parser = new Parser({
+ exports.parser = new Parser({
tokens: tokens,
bnf: bnf,
operators: operators.reverse(),
startSymbol: 'Root'
}, {
debug: false
});
- js = parser.generate();
- // Save the parser to a file.
- // puts parser.generate()
- fs = require('fs');
- parser_path = 'lib/coffee_script/parser.js';
- fs.open(parser_path, process.O_CREAT | process.O_WRONLY | process.O_TRUNC, parseInt('0755', 8)).addCallback(function(fd) {
- return fs.write(fd, js);
- });
})();
View
@@ -36,6 +36,12 @@ exports.run: ->
return require './repl' if options.interactive
return puts coffee.compile sources[0] if options.eval
usage() unless sources.length
+ separator: sources.indexOf '--'
+ flags: []
+ if separator >= 0
+ flags: sources[(separator + 1)...sources.length]
+ sources: sources[0...separator]
+ process.ARGV = flags
compile_scripts()
this
View
@@ -450,12 +450,4 @@ for name, non_terminal of grammar
option[1] = "return " + option[1]
option
tokens: tokens.join(" ")
-parser: new Parser({tokens: tokens, bnf: bnf, operators: operators.reverse(), startSymbol: 'Root'}, {debug: false})
-js: parser.generate()
-
-# Save the parser to a file.
-# puts parser.generate()
-fs: require 'fs'
-parser_path: 'lib/coffee_script/parser.js'
-fs.open(parser_path, process.O_CREAT | process.O_WRONLY | process.O_TRUNC, parseInt('0755', 8)).addCallback (fd) ->
- fs.write(fd, js)
+exports.parser: new Parser({tokens: tokens, bnf: bnf, operators: operators.reverse(), startSymbol: 'Root'}, {debug: false})

0 comments on commit 2f389f1

Please sign in to comment.