From 2f389f1d5197624e7e0b0ecad7b6c64ffd1943dd Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Tue, 16 Feb 2010 01:04:48 -0500 Subject: [PATCH] beginnings of a build script --- README | 7 ++++++- build.coffee | 24 ++++++++++++++++++++++++ lib/coffee_script/command_line.js | 8 ++++++++ lib/coffee_script/grammar.js | 12 ++---------- src/command_line.coffee | 6 ++++++ src/grammar.coffee | 10 +--------- 6 files changed, 47 insertions(+), 20 deletions(-) create mode 100755 build.coffee diff --git a/README b/README index 5ad335eb..23b910c1 100644 --- a/README +++ b/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 + \ No newline at end of file diff --git a/build.coffee b/build.coffee new file mode 100755 index 00000000..98b6067c --- /dev/null +++ b/build.coffee @@ -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() \ No newline at end of file diff --git a/lib/coffee_script/command_line.js b/lib/coffee_script/command_line.js index 786b5471..d17aa19a 100644 --- a/lib/coffee_script/command_line.js +++ b/lib/coffee_script/command_line.js @@ -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; }; diff --git a/lib/coffee_script/grammar.js b/lib/coffee_script/grammar.js index 37012813..0399e4e7 100644 --- a/lib/coffee_script/grammar.js +++ b/lib/coffee_script/grammar.js @@ -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,7 +544,7 @@ }).call(this); } tokens = tokens.join(" "); - parser = new Parser({ + exports.parser = new Parser({ tokens: tokens, bnf: bnf, operators: operators.reverse(), @@ -552,12 +552,4 @@ }, { 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); - }); })(); \ No newline at end of file diff --git a/src/command_line.coffee b/src/command_line.coffee index cba87fec..2c7ac7ff 100644 --- a/src/command_line.coffee +++ b/src/command_line.coffee @@ -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 diff --git a/src/grammar.coffee b/src/grammar.coffee index fe7cfb5f..39a21b9f 100644 --- a/src/grammar.coffee +++ b/src/grammar.coffee @@ -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})