1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

First draft of switching the CoffeeScript Compiler over to camelCase. Pour one on the ground for underscores...

This commit is contained in:
Jeremy Ashkenas 2010-06-12 19:05:13 -04:00
parent 1948b0c7c7
commit e14f4c5db1
57 changed files with 1243 additions and 1243 deletions

View file

@ -1,13 +1,13 @@
(function(){
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, build_rule, build_rules, normalize_arguments;
var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments;
// A simple **OptionParser** class to parse option flags from the command-line.
// Use it like so:
// parser: new OptionParser switches, help_banner
// parser: new OptionParser switches, helpBanner
// options: parser.parse process.argv
exports.OptionParser = (function() {
OptionParser = function(rules, banner) {
this.banner = banner;
this.rules = build_rules(rules);
this.rules = buildRules(rules);
return this;
};
// Initialize with a list of valid options, in the form:
@ -19,27 +19,27 @@
// many option parsers that allow you to attach callback actions for every
// flag. Instead, you're responsible for interpreting the options object.
OptionParser.prototype.parse = function(args) {
var _a, _b, _c, arg, is_option, matched_rule, options, rule;
var _a, _b, _c, arg, isOption, matchedRule, options, rule;
options = {
arguments: []
};
args = normalize_arguments(args);
args = normalizeArguments(args);
while ((arg = args.shift())) {
is_option = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
matched_rule = false;
isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
matchedRule = false;
_b = this.rules;
for (_a = 0, _c = _b.length; _a < _c; _a++) {
rule = _b[_a];
if (rule.short_flag === arg || rule.long_flag === arg) {
options[rule.name] = rule.has_argument ? args.shift() : true;
matched_rule = true;
if (rule.shortFlag === arg || rule.longFlag === arg) {
options[rule.name] = rule.hasArgument ? args.shift() : true;
matchedRule = true;
break;
}
}
if (is_option && !matched_rule) {
if (isOption && !matchedRule) {
throw new Error(("unrecognized option: " + arg));
}
if (!(is_option)) {
if (!(isOption)) {
options.arguments.push(arg);
}
}
@ -48,7 +48,7 @@
// Return the help text for this **OptionParser**, listing and describing all
// of the valid options, for `--help` and such.
OptionParser.prototype.help = function() {
var _a, _b, _c, _d, i, let_part, lines, rule, spaces;
var _a, _b, _c, _d, i, letPart, lines, rule, spaces;
lines = ['Available options:'];
if (this.banner) {
lines.unshift(("" + this.banner + "\n"));
@ -56,7 +56,7 @@
_b = this.rules;
for (_a = 0, _c = _b.length; _a < _c; _a++) {
rule = _b[_a];
spaces = 15 - rule.long_flag.length;
spaces = 15 - rule.longFlag.length;
spaces = spaces > 0 ? (function() {
_d = [];
for (i = 0; i <= spaces; i += 1) {
@ -64,8 +64,8 @@
}
return _d;
})().join('') : '';
let_part = rule.short_flag ? rule.short_flag + ', ' : ' ';
lines.push((" " + let_part + rule.long_flag + spaces + rule.description));
letPart = rule.shortFlag ? rule.shortFlag + ', ' : ' ';
lines.push((" " + letPart + rule.longFlag + spaces + rule.description));
}
return "\n" + (lines.join('\n')) + "\n";
};
@ -80,7 +80,7 @@
OPTIONAL = /\[(.+)\]/;
// Build and return the list of option rules. If the optional *short-flag* is
// unspecified, leave it out by padding with `null`.
build_rules = function(rules) {
buildRules = function(rules) {
var _a, _b, _c, _d, tuple;
_a = []; _c = rules;
for (_b = 0, _d = _c.length; _b < _d; _b++) {
@ -89,28 +89,28 @@
if (tuple.length < 3) {
tuple.unshift(null);
}
return build_rule.apply(this, tuple);
return buildRule.apply(this, tuple);
})());
}
return _a;
};
// Build a rule from a `-o` short flag, a `--output [DIR]` long flag, and the
// description of what the option does.
build_rule = function(short_flag, long_flag, description) {
buildRule = function(shortFlag, longFlag, description) {
var match;
match = long_flag.match(OPTIONAL);
long_flag = long_flag.match(LONG_FLAG)[1];
match = longFlag.match(OPTIONAL);
longFlag = longFlag.match(LONG_FLAG)[1];
return {
name: long_flag.substr(2),
short_flag: short_flag,
long_flag: long_flag,
name: longFlag.substr(2),
shortFlag: shortFlag,
longFlag: longFlag,
description: description,
has_argument: !!(match && match[1])
hasArgument: !!(match && match[1])
};
};
// Normalize arguments by expanding merged flags into multiple flags. This allows
// you to have `-wl` be the same as `--watch --lint`.
normalize_arguments = function(args) {
normalizeArguments = function(args) {
var _a, _b, _c, _d, _e, _f, arg, l, match, result;
args = args.slice(0);
result = [];