spade 0.0.8.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.gitmodules +4 -4
- data/README.md +4 -0
- data/bin/spade +1 -1
- data/lib/spade.rb +0 -51
- data/lib/spade/cli.rb +10 -4
- data/lib/spade/version.rb +1 -1
- data/spade.gemspec +4 -21
- metadata +13 -482
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -40
- data/lib/index.js +0 -14
- data/lib/node/loader.js +0 -146
- data/lib/node/sandbox.js +0 -44
- data/lib/spade.js +0 -1130
- data/lib/spade/bundle.rb +0 -171
- data/lib/spade/cli/base.rb +0 -354
- data/lib/spade/cli/owner.rb +0 -45
- data/lib/spade/cli/project_generator.rb +0 -58
- data/lib/spade/compiler.rb +0 -34
- data/lib/spade/console.rb +0 -39
- data/lib/spade/context.rb +0 -116
- data/lib/spade/credentials.rb +0 -36
- data/lib/spade/dependency_installer.rb +0 -103
- data/lib/spade/environment.rb +0 -35
- data/lib/spade/exports.rb +0 -71
- data/lib/spade/installer.rb +0 -40
- data/lib/spade/loader.rb +0 -238
- data/lib/spade/local.rb +0 -46
- data/lib/spade/package.rb +0 -157
- data/lib/spade/reactor.rb +0 -159
- data/lib/spade/remote.rb +0 -99
- data/lib/spade/repository.rb +0 -18
- data/lib/spade/server.rb +0 -66
- data/lib/spade/shell.rb +0 -36
- data/lib/spade/templates/project/LICENSE +0 -19
- data/lib/spade/templates/project/README.md +0 -21
- data/lib/spade/templates/project/lib/main.js +0 -9
- data/lib/spade/templates/project/project.json +0 -31
- data/lib/spade/templates/project/tests/main-test.js +0 -8
- data/package.json +0 -27
- data/packages/coffee-script/.gitignore +0 -8
- data/packages/coffee-script/.npmignore +0 -11
- data/packages/coffee-script/Cakefile +0 -229
- data/packages/coffee-script/LICENSE +0 -22
- data/packages/coffee-script/README +0 -47
- data/packages/coffee-script/Rakefile +0 -78
- data/packages/coffee-script/bin/cake +0 -7
- data/packages/coffee-script/bin/coffee +0 -7
- data/packages/coffee-script/documentation/coffee/aliases.coffee +0 -11
- data/packages/coffee-script/documentation/coffee/array_comprehensions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/block_comment.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/cake_tasks.coffee +0 -9
- data/packages/coffee-script/documentation/coffee/classes.coffee +0 -25
- data/packages/coffee-script/documentation/coffee/comparisons.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/conditionals.coffee +0 -13
- data/packages/coffee-script/documentation/coffee/default_args.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/do.coffee +0 -4
- data/packages/coffee-script/documentation/coffee/embedded.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/existence.coffee +0 -10
- data/packages/coffee-script/documentation/coffee/expressions.coffee +0 -9
- data/packages/coffee-script/documentation/coffee/expressions_assignment.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/expressions_comprehension.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/expressions_try.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/fat_arrow.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/functions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/heredocs.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/heregexes.coffee +0 -11
- data/packages/coffee-script/documentation/coffee/interpolation.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/multiple_return_values.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/object_comprehensions.coffee +0 -4
- data/packages/coffee-script/documentation/coffee/object_extraction.coffee +0 -13
- data/packages/coffee-script/documentation/coffee/objects_and_arrays.coffee +0 -19
- data/packages/coffee-script/documentation/coffee/objects_reserved.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/overview.coffee +0 -28
- data/packages/coffee-script/documentation/coffee/parallel_assignment.coffee +0 -6
- data/packages/coffee-script/documentation/coffee/patterns_and_splats.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/prototypes.coffee +0 -3
- data/packages/coffee-script/documentation/coffee/range_comprehensions.coffee +0 -2
- data/packages/coffee-script/documentation/coffee/scope.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/slices.coffee +0 -7
- data/packages/coffee-script/documentation/coffee/soaks.coffee +0 -1
- data/packages/coffee-script/documentation/coffee/splats.coffee +0 -27
- data/packages/coffee-script/documentation/coffee/splices.coffee +0 -5
- data/packages/coffee-script/documentation/coffee/strings.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/switch.coffee +0 -10
- data/packages/coffee-script/documentation/coffee/try.coffee +0 -8
- data/packages/coffee-script/documentation/coffee/while.coffee +0 -10
- data/packages/coffee-script/documentation/css/docs.css +0 -374
- data/packages/coffee-script/documentation/css/idle.css +0 -64
- data/packages/coffee-script/documentation/docs/browser.html +0 -25
- data/packages/coffee-script/documentation/docs/cake.html +0 -43
- data/packages/coffee-script/documentation/docs/coffee-script.html +0 -51
- data/packages/coffee-script/documentation/docs/command.html +0 -161
- data/packages/coffee-script/documentation/docs/docco.css +0 -186
- data/packages/coffee-script/documentation/docs/grammar.html +0 -399
- data/packages/coffee-script/documentation/docs/helpers.html +0 -31
- data/packages/coffee-script/documentation/docs/index.html +0 -3
- data/packages/coffee-script/documentation/docs/lexer.html +0 -490
- data/packages/coffee-script/documentation/docs/nodes.html +0 -1338
- data/packages/coffee-script/documentation/docs/optparse.html +0 -78
- data/packages/coffee-script/documentation/docs/repl.html +0 -24
- data/packages/coffee-script/documentation/docs/rewriter.html +0 -251
- data/packages/coffee-script/documentation/docs/scope.html +0 -54
- data/packages/coffee-script/documentation/docs/underscore.html +0 -295
- data/packages/coffee-script/documentation/images/background.png +0 -0
- data/packages/coffee-script/documentation/images/banding.png +0 -0
- data/packages/coffee-script/documentation/images/button_bg.png +0 -0
- data/packages/coffee-script/documentation/images/button_bg_dark.gif +0 -0
- data/packages/coffee-script/documentation/images/button_bg_green.gif +0 -0
- data/packages/coffee-script/documentation/images/favicon.ico +0 -0
- data/packages/coffee-script/documentation/images/logo.png +0 -0
- data/packages/coffee-script/documentation/images/screenshadow.png +0 -0
- data/packages/coffee-script/documentation/index.html.erb +0 -1607
- data/packages/coffee-script/documentation/js/aliases.js +0 -17
- data/packages/coffee-script/documentation/js/array_comprehensions.js +0 -6
- data/packages/coffee-script/documentation/js/block_comment.js +0 -4
- data/packages/coffee-script/documentation/js/cake_tasks.js +0 -10
- data/packages/coffee-script/documentation/js/classes.js +0 -44
- data/packages/coffee-script/documentation/js/comparisons.js +0 -3
- data/packages/coffee-script/documentation/js/conditionals.js +0 -12
- data/packages/coffee-script/documentation/js/default_args.js +0 -7
- data/packages/coffee-script/documentation/js/do.js +0 -10
- data/packages/coffee-script/documentation/js/embedded.js +0 -4
- data/packages/coffee-script/documentation/js/existence.js +0 -6
- data/packages/coffee-script/documentation/js/expressions.js +0 -15
- data/packages/coffee-script/documentation/js/expressions_assignment.js +0 -2
- data/packages/coffee-script/documentation/js/expressions_comprehension.js +0 -9
- data/packages/coffee-script/documentation/js/expressions_try.js +0 -7
- data/packages/coffee-script/documentation/js/fat_arrow.js +0 -9
- data/packages/coffee-script/documentation/js/functions.js +0 -7
- data/packages/coffee-script/documentation/js/heredocs.js +0 -2
- data/packages/coffee-script/documentation/js/heregexes.js +0 -2
- data/packages/coffee-script/documentation/js/interpolation.js +0 -4
- data/packages/coffee-script/documentation/js/multiple_return_values.js +0 -5
- data/packages/coffee-script/documentation/js/object_comprehensions.js +0 -15
- data/packages/coffee-script/documentation/js/object_extraction.js +0 -10
- data/packages/coffee-script/documentation/js/objects_and_arrays.js +0 -17
- data/packages/coffee-script/documentation/js/objects_reserved.js +0 -4
- data/packages/coffee-script/documentation/js/overview.js +0 -35
- data/packages/coffee-script/documentation/js/parallel_assignment.js +0 -4
- data/packages/coffee-script/documentation/js/patterns_and_splats.js +0 -4
- data/packages/coffee-script/documentation/js/prototypes.js +0 -3
- data/packages/coffee-script/documentation/js/range_comprehensions.js +0 -9
- data/packages/coffee-script/documentation/js/scope.js +0 -8
- data/packages/coffee-script/documentation/js/slices.js +0 -4
- data/packages/coffee-script/documentation/js/soaks.js +0 -2
- data/packages/coffee-script/documentation/js/splats.js +0 -15
- data/packages/coffee-script/documentation/js/splices.js +0 -3
- data/packages/coffee-script/documentation/js/strings.js +0 -2
- data/packages/coffee-script/documentation/js/switch.js +0 -23
- data/packages/coffee-script/documentation/js/try.js +0 -8
- data/packages/coffee-script/documentation/js/while.js +0 -18
- data/packages/coffee-script/documentation/vendor/jquery-1.4.2.js +0 -6240
- data/packages/coffee-script/examples/beautiful_code/binary_search.coffee +0 -16
- data/packages/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +0 -13
- data/packages/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +0 -34
- data/packages/coffee-script/examples/blocks.coffee +0 -54
- data/packages/coffee-script/examples/code.coffee +0 -167
- data/packages/coffee-script/examples/computer_science/README +0 -4
- data/packages/coffee-script/examples/computer_science/binary_search.coffee +0 -25
- data/packages/coffee-script/examples/computer_science/bubble_sort.coffee +0 -11
- data/packages/coffee-script/examples/computer_science/linked_list.coffee +0 -108
- data/packages/coffee-script/examples/computer_science/luhn_algorithm.coffee +0 -36
- data/packages/coffee-script/examples/computer_science/merge_sort.coffee +0 -19
- data/packages/coffee-script/examples/computer_science/selection_sort.coffee +0 -23
- data/packages/coffee-script/examples/poignant.coffee +0 -181
- data/packages/coffee-script/examples/potion.coffee +0 -206
- data/packages/coffee-script/examples/underscore.coffee +0 -682
- data/packages/coffee-script/examples/web_server.coffee +0 -12
- data/packages/coffee-script/extras/EXTRAS +0 -7
- data/packages/coffee-script/extras/coffee-script.js +0 -8
- data/packages/coffee-script/extras/jsl.conf +0 -44
- data/packages/coffee-script/index.html +0 -2515
- data/packages/coffee-script/lib/browser.js +0 -52
- data/packages/coffee-script/lib/cake.js +0 -76
- data/packages/coffee-script/lib/coffee-script.js +0 -82
- data/packages/coffee-script/lib/command.js +0 -263
- data/packages/coffee-script/lib/grammar.js +0 -581
- data/packages/coffee-script/lib/helpers.js +0 -66
- data/packages/coffee-script/lib/index.js +0 -8
- data/packages/coffee-script/lib/lexer.js +0 -633
- data/packages/coffee-script/lib/nodes.js +0 -2165
- data/packages/coffee-script/lib/optparse.js +0 -111
- data/packages/coffee-script/lib/parser.js +0 -649
- data/packages/coffee-script/lib/repl.js +0 -42
- data/packages/coffee-script/lib/rewriter.js +0 -353
- data/packages/coffee-script/lib/scope.js +0 -120
- data/packages/coffee-script/lib/spade-format.js +0 -45
- data/packages/coffee-script/package.json +0 -26
- data/packages/coffee-script/src/browser.coffee +0 -43
- data/packages/coffee-script/src/cake.coffee +0 -69
- data/packages/coffee-script/src/coffee-script.coffee +0 -92
- data/packages/coffee-script/src/command.coffee +0 -214
- data/packages/coffee-script/src/grammar.coffee +0 -590
- data/packages/coffee-script/src/helpers.coffee +0 -56
- data/packages/coffee-script/src/index.coffee +0 -2
- data/packages/coffee-script/src/lexer.coffee +0 -653
- data/packages/coffee-script/src/nodes.coffee +0 -1754
- data/packages/coffee-script/src/optparse.coffee +0 -99
- data/packages/coffee-script/src/repl.coffee +0 -42
- data/packages/coffee-script/src/rewriter.coffee +0 -326
- data/packages/coffee-script/src/scope.coffee +0 -94
- data/packages/coffee-script/test/arguments.coffee +0 -127
- data/packages/coffee-script/test/assignment.coffee +0 -98
- data/packages/coffee-script/test/break.coffee +0 -18
- data/packages/coffee-script/test/comments.coffee +0 -201
- data/packages/coffee-script/test/conditionals.coffee +0 -181
- data/packages/coffee-script/test/exception_handling.coffee +0 -90
- data/packages/coffee-script/test/helpers.coffee +0 -96
- data/packages/coffee-script/test/importing.coffee +0 -18
- data/packages/coffee-script/test/operators.coffee +0 -225
- data/packages/coffee-script/test/ranges_slices_and_splices.coffee +0 -186
- data/packages/coffee-script/test/regular_expressions.coffee +0 -56
- data/packages/coffee-script/test/test.html +0 -123
- data/packages/coffee-script/test/test_chaining.coffee +0 -77
- data/packages/coffee-script/test/test_classes.coffee +0 -372
- data/packages/coffee-script/test/test_compilation.coffee +0 -26
- data/packages/coffee-script/test/test_comprehensions.coffee +0 -318
- data/packages/coffee-script/test/test_existence.coffee +0 -165
- data/packages/coffee-script/test/test_functions.coffee +0 -379
- data/packages/coffee-script/test/test_heredocs.coffee +0 -111
- data/packages/coffee-script/test/test_literals.coffee +0 -270
- data/packages/coffee-script/test/test_option_parser.coffee +0 -27
- data/packages/coffee-script/test/test_pattern_matching.coffee +0 -162
- data/packages/coffee-script/test/test_returns.coffee +0 -63
- data/packages/coffee-script/test/test_splats.coffee +0 -102
- data/packages/coffee-script/test/test_strings.coffee +0 -118
- data/packages/coffee-script/test/test_switch.coffee +0 -103
- data/packages/coffee-script/test/test_while.coffee +0 -71
- data/packages/ivory/LICENSE.txt +0 -1
- data/packages/ivory/README.md +0 -19
- data/packages/ivory/lib/buffer.js +0 -111
- data/packages/ivory/lib/events.js +0 -137
- data/packages/ivory/lib/fs.js +0 -266
- data/packages/ivory/lib/main.js +0 -13
- data/packages/ivory/lib/path.js +0 -158
- data/packages/ivory/lib/ruby/buffer.rb +0 -145
- data/packages/ivory/lib/ruby/constants.rb +0 -585
- data/packages/ivory/lib/ruby/events.rb +0 -32
- data/packages/ivory/lib/ruby/fs.rb +0 -245
- data/packages/ivory/lib/ruby/process.rb +0 -28
- data/packages/ivory/lib/stream.js +0 -115
- data/packages/ivory/lib/util.js +0 -414
- data/packages/ivory/package.json +0 -11
- data/packages/jquery/main.js +0 -7179
- data/packages/jquery/package.json +0 -10
- data/packages/json/lib/main.js +0 -14
- data/packages/json/package.json +0 -8
- data/packages/lproj/README.md +0 -77
- data/packages/lproj/examples/demo-app/en.lproj/localized.strings +0 -2
- data/packages/lproj/examples/demo-app/fr.lproj/localized.strings +0 -3
- data/packages/lproj/examples/demo-app/index.html +0 -8
- data/packages/lproj/examples/demo-app/lib/main.js +0 -7
- data/packages/lproj/examples/demo-app/package.json +0 -9
- data/packages/lproj/lib/main.js +0 -78
- data/packages/lproj/lib/strings-format.js +0 -6
- data/packages/lproj/package.json +0 -9
- data/packages/optparse/README.md +0 -161
- data/packages/optparse/TODO +0 -1
- data/packages/optparse/examples/browser-test.html +0 -75
- data/packages/optparse/examples/nodejs-test.js +0 -90
- data/packages/optparse/lib/optparse.js +0 -309
- data/packages/optparse/package.json +0 -13
- data/packages/optparse/seed.yml +0 -5
- data/packages/text/lib/main.js +0 -8
- data/packages/text/package.json +0 -9
- data/packages/web-file/README.md +0 -7
- data/packages/web-file/lib/errors.js +0 -32
- data/packages/web-file/lib/file-reader.js +0 -10
- data/packages/web-file/lib/file-system.js +0 -234
- data/packages/web-file/lib/file-writer.js +0 -10
- data/packages/web-file/lib/file.js +0 -9
- data/packages/web-file/lib/main.js +0 -34
- data/packages/web-file/lib/platform.js +0 -25
- data/packages/web-file/lib/ruby/file.rb +0 -252
- data/packages/web-file/lib/ruby/file_reader.rb +0 -69
- data/packages/web-file/lib/ruby/file_system.rb +0 -134
- data/packages/web-file/lib/ruby/file_writer.rb +0 -78
- data/packages/web-file/package.json +0 -12
- data/packages/web-typed-array/README.md +0 -7
- data/packages/web-typed-array/lib/array-buffer-view.js +0 -9
- data/packages/web-typed-array/lib/array-buffer.js +0 -7
- data/packages/web-typed-array/lib/main.js +0 -33
- data/packages/web-typed-array/lib/platform.js +0 -20
- data/packages/web-typed-array/lib/ruby/array_buffer.rb +0 -31
- data/packages/web-typed-array/lib/ruby/array_buffer_view.rb +0 -130
- data/packages/web-typed-array/lib/ruby/typed_array.rb +0 -133
- data/packages/web-typed-array/lib/typed-array.js +0 -26
- data/packages/web-typed-array/package.json +0 -9
- data/spec/cli/build_spec.rb +0 -59
- data/spec/cli/install_spec.rb +0 -120
- data/spec/cli/installed_spec.rb +0 -55
- data/spec/cli/list_spec.rb +0 -75
- data/spec/cli/login_spec.rb +0 -76
- data/spec/cli/new_spec.rb +0 -5
- data/spec/cli/owner_spec.rb +0 -115
- data/spec/cli/push_spec.rb +0 -74
- data/spec/cli/uninstall_spec.rb +0 -58
- data/spec/cli/unpack_spec.rb +0 -73
- data/spec/cli/unyank_spec.rb +0 -74
- data/spec/cli/update_spec.rb +0 -8
- data/spec/cli/yank_spec.rb +0 -74
- data/spec/credentials_spec.rb +0 -24
- data/spec/fixtures/coffee-1.0.1.pre.spd +0 -0
- data/spec/fixtures/core-test-0.4.3.spd +0 -0
- data/spec/fixtures/core-test/bin/cot +0 -3
- data/spec/fixtures/core-test/lib/main.js +0 -1
- data/spec/fixtures/core-test/resources/runner.css +0 -0
- data/spec/fixtures/core-test/tests/test.js +0 -1
- data/spec/fixtures/ivory-0.0.1.spd +0 -0
- data/spec/fixtures/jquery-1.4.3.spd +0 -0
- data/spec/fixtures/optparse-1.0.1.spd +0 -0
- data/spec/fixtures/package.json +0 -30
- data/spec/gauntlet_spec.rb +0 -27
- data/spec/javascript/async-test.js +0 -123
- data/spec/javascript/compiler/javascript.js +0 -13
- data/spec/javascript/compiler/ruby.js +0 -14
- data/spec/javascript/loader-test.js +0 -64
- data/spec/javascript/normalize-test.js +0 -73
- data/spec/javascript/packages-test.js +0 -44
- data/spec/javascript/relative-require-test.js +0 -72
- data/spec/javascript/require-test.js +0 -117
- data/spec/javascript/sandbox/compile.js +0 -37
- data/spec/javascript/sandbox/creation.js +0 -44
- data/spec/javascript/sandbox/format.js +0 -79
- data/spec/javascript/sandbox/misc.js +0 -57
- data/spec/javascript/sandbox/preprocessor.js +0 -81
- data/spec/javascript/sandbox/require.js +0 -48
- data/spec/javascript/sandbox/run-command.js +0 -21
- data/spec/javascript/spade/externs.js +0 -14
- data/spec/javascript/spade/load-factory.js +0 -15
- data/spec/javascript/spade/misc.js +0 -23
- data/spec/javascript/spade/ready.js +0 -12
- data/spec/javascript/spade/register.js +0 -13
- data/spec/javascript_spec.rb +0 -7
- data/spec/package_spec.rb +0 -267
- data/spec/spec_helper.rb +0 -30
- data/spec/support/cli.rb +0 -94
- data/spec/support/core_test.rb +0 -59
- data/spec/support/fake.rb +0 -44
- data/spec/support/fake_gem_server.rb +0 -66
- data/spec/support/fake_gemcutter.rb +0 -49
- data/spec/support/matchers.rb +0 -31
- data/spec/support/path.rb +0 -54
- data/test-spade.html +0 -8
@@ -1,66 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
var extend, flatten;
|
3
|
-
exports.starts = function(string, literal, start) {
|
4
|
-
return literal === string.substr(start, literal.length);
|
5
|
-
};
|
6
|
-
exports.ends = function(string, literal, back) {
|
7
|
-
var len;
|
8
|
-
len = literal.length;
|
9
|
-
return literal === string.substr(string.length - len - (back || 0), len);
|
10
|
-
};
|
11
|
-
exports.compact = function(array) {
|
12
|
-
var item, _i, _len, _results;
|
13
|
-
_results = [];
|
14
|
-
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
15
|
-
item = array[_i];
|
16
|
-
if (item) {
|
17
|
-
_results.push(item);
|
18
|
-
}
|
19
|
-
}
|
20
|
-
return _results;
|
21
|
-
};
|
22
|
-
exports.count = function(string, substr) {
|
23
|
-
var num, pos;
|
24
|
-
num = pos = 0;
|
25
|
-
if (!substr.length) {
|
26
|
-
return 1 / 0;
|
27
|
-
}
|
28
|
-
while (pos = 1 + string.indexOf(substr, pos)) {
|
29
|
-
num++;
|
30
|
-
}
|
31
|
-
return num;
|
32
|
-
};
|
33
|
-
exports.merge = function(options, overrides) {
|
34
|
-
return extend(extend({}, options), overrides);
|
35
|
-
};
|
36
|
-
extend = exports.extend = function(object, properties) {
|
37
|
-
var key, val;
|
38
|
-
for (key in properties) {
|
39
|
-
val = properties[key];
|
40
|
-
object[key] = val;
|
41
|
-
}
|
42
|
-
return object;
|
43
|
-
};
|
44
|
-
exports.flatten = flatten = function(array) {
|
45
|
-
var element, flattened, _i, _len;
|
46
|
-
flattened = [];
|
47
|
-
for (_i = 0, _len = array.length; _i < _len; _i++) {
|
48
|
-
element = array[_i];
|
49
|
-
if (element instanceof Array) {
|
50
|
-
flattened = flattened.concat(flatten(element));
|
51
|
-
} else {
|
52
|
-
flattened.push(element);
|
53
|
-
}
|
54
|
-
}
|
55
|
-
return flattened;
|
56
|
-
};
|
57
|
-
exports.del = function(obj, key) {
|
58
|
-
var val;
|
59
|
-
val = obj[key];
|
60
|
-
delete obj[key];
|
61
|
-
return val;
|
62
|
-
};
|
63
|
-
exports.last = function(array, back) {
|
64
|
-
return array[array.length - (back || 0) - 1];
|
65
|
-
};
|
66
|
-
}).call(this);
|
@@ -1,633 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, last, op, starts, _ref;
|
3
|
-
var __indexOf = Array.prototype.indexOf || function(item) {
|
4
|
-
for (var i = 0, l = this.length; i < l; i++) {
|
5
|
-
if (this[i] === item) return i;
|
6
|
-
}
|
7
|
-
return -1;
|
8
|
-
};
|
9
|
-
Rewriter = require('./rewriter').Rewriter;
|
10
|
-
_ref = require('./helpers'), count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last;
|
11
|
-
exports.Lexer = Lexer = (function() {
|
12
|
-
function Lexer() {}
|
13
|
-
Lexer.prototype.tokenize = function(code, opts) {
|
14
|
-
var i;
|
15
|
-
if (opts == null) {
|
16
|
-
opts = {};
|
17
|
-
}
|
18
|
-
code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
|
19
|
-
this.code = code;
|
20
|
-
this.line = opts.line || 0;
|
21
|
-
this.indent = 0;
|
22
|
-
this.indebt = 0;
|
23
|
-
this.outdebt = 0;
|
24
|
-
this.indents = [];
|
25
|
-
this.tokens = [];
|
26
|
-
i = 0;
|
27
|
-
while (this.chunk = code.slice(i)) {
|
28
|
-
i += this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
|
29
|
-
}
|
30
|
-
this.closeIndentation();
|
31
|
-
if (opts.rewrite === false) {
|
32
|
-
return this.tokens;
|
33
|
-
}
|
34
|
-
return (new Rewriter).rewrite(this.tokens);
|
35
|
-
};
|
36
|
-
Lexer.prototype.identifierToken = function() {
|
37
|
-
var colon, forcedIdentifier, id, input, match, prev, tag, _ref, _ref2;
|
38
|
-
if (!(match = IDENTIFIER.exec(this.chunk))) {
|
39
|
-
return 0;
|
40
|
-
}
|
41
|
-
input = match[0], id = match[1], colon = match[2];
|
42
|
-
if (id === 'own' && this.tag() === 'FOR') {
|
43
|
-
this.token('OWN', id);
|
44
|
-
return id.length;
|
45
|
-
}
|
46
|
-
forcedIdentifier = colon || (prev = last(this.tokens)) && !prev.spaced && ((_ref = prev[0]) === '.' || _ref === '?.' || _ref === '@' || _ref === '::');
|
47
|
-
tag = 'IDENTIFIER';
|
48
|
-
if (__indexOf.call(JS_KEYWORDS, id) >= 0 || !forcedIdentifier && __indexOf.call(COFFEE_KEYWORDS, id) >= 0) {
|
49
|
-
tag = id.toUpperCase();
|
50
|
-
if (tag === 'WHEN' && (_ref2 = this.tag(), __indexOf.call(LINE_BREAK, _ref2) >= 0)) {
|
51
|
-
tag = 'LEADING_WHEN';
|
52
|
-
} else if (tag === 'FOR') {
|
53
|
-
this.seenFor = true;
|
54
|
-
} else if (tag === 'UNLESS') {
|
55
|
-
tag = 'IF';
|
56
|
-
} else if (__indexOf.call(UNARY, tag) >= 0) {
|
57
|
-
tag = 'UNARY';
|
58
|
-
} else if (__indexOf.call(RELATION, tag) >= 0) {
|
59
|
-
if (tag !== 'INSTANCEOF' && this.seenFor) {
|
60
|
-
tag = 'FOR' + tag;
|
61
|
-
this.seenFor = false;
|
62
|
-
} else {
|
63
|
-
tag = 'RELATION';
|
64
|
-
if (this.value() === '!') {
|
65
|
-
this.tokens.pop();
|
66
|
-
id = '!' + id;
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}
|
70
|
-
}
|
71
|
-
if (__indexOf.call(JS_FORBIDDEN, id) >= 0) {
|
72
|
-
if (forcedIdentifier) {
|
73
|
-
tag = 'IDENTIFIER';
|
74
|
-
id = new String(id);
|
75
|
-
id.reserved = true;
|
76
|
-
} else if (__indexOf.call(RESERVED, id) >= 0) {
|
77
|
-
this.identifierError(id);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
if (!forcedIdentifier) {
|
81
|
-
if (COFFEE_ALIASES.hasOwnProperty(id)) {
|
82
|
-
id = COFFEE_ALIASES[id];
|
83
|
-
}
|
84
|
-
tag = (function() {
|
85
|
-
switch (id) {
|
86
|
-
case '!':
|
87
|
-
return 'UNARY';
|
88
|
-
case '==':
|
89
|
-
case '!=':
|
90
|
-
return 'COMPARE';
|
91
|
-
case '&&':
|
92
|
-
case '||':
|
93
|
-
return 'LOGIC';
|
94
|
-
case 'true':
|
95
|
-
case 'false':
|
96
|
-
case 'null':
|
97
|
-
case 'undefined':
|
98
|
-
return 'BOOL';
|
99
|
-
case 'break':
|
100
|
-
case 'continue':
|
101
|
-
case 'debugger':
|
102
|
-
return 'STATEMENT';
|
103
|
-
default:
|
104
|
-
return tag;
|
105
|
-
}
|
106
|
-
})();
|
107
|
-
}
|
108
|
-
this.token(tag, id);
|
109
|
-
if (colon) {
|
110
|
-
this.token(':', ':');
|
111
|
-
}
|
112
|
-
return input.length;
|
113
|
-
};
|
114
|
-
Lexer.prototype.numberToken = function() {
|
115
|
-
var match, number;
|
116
|
-
if (!(match = NUMBER.exec(this.chunk))) {
|
117
|
-
return 0;
|
118
|
-
}
|
119
|
-
number = match[0];
|
120
|
-
this.token('NUMBER', number);
|
121
|
-
return number.length;
|
122
|
-
};
|
123
|
-
Lexer.prototype.stringToken = function() {
|
124
|
-
var match, string;
|
125
|
-
switch (this.chunk.charAt(0)) {
|
126
|
-
case "'":
|
127
|
-
if (!(match = SIMPLESTR.exec(this.chunk))) {
|
128
|
-
return 0;
|
129
|
-
}
|
130
|
-
this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n'));
|
131
|
-
break;
|
132
|
-
case '"':
|
133
|
-
if (!(string = this.balancedString(this.chunk, '"'))) {
|
134
|
-
return 0;
|
135
|
-
}
|
136
|
-
if (0 < string.indexOf('#{', 1)) {
|
137
|
-
this.interpolateString(string.slice(1, -1));
|
138
|
-
} else {
|
139
|
-
this.token('STRING', this.escapeLines(string));
|
140
|
-
}
|
141
|
-
break;
|
142
|
-
default:
|
143
|
-
return 0;
|
144
|
-
}
|
145
|
-
this.line += count(string, '\n');
|
146
|
-
return string.length;
|
147
|
-
};
|
148
|
-
Lexer.prototype.heredocToken = function() {
|
149
|
-
var doc, heredoc, match, quote;
|
150
|
-
if (!(match = HEREDOC.exec(this.chunk))) {
|
151
|
-
return 0;
|
152
|
-
}
|
153
|
-
heredoc = match[0];
|
154
|
-
quote = heredoc.charAt(0);
|
155
|
-
doc = this.sanitizeHeredoc(match[2], {
|
156
|
-
quote: quote,
|
157
|
-
indent: null
|
158
|
-
});
|
159
|
-
if (quote === '"' && 0 <= doc.indexOf('#{')) {
|
160
|
-
this.interpolateString(doc, {
|
161
|
-
heredoc: true
|
162
|
-
});
|
163
|
-
} else {
|
164
|
-
this.token('STRING', this.makeString(doc, quote, true));
|
165
|
-
}
|
166
|
-
this.line += count(heredoc, '\n');
|
167
|
-
return heredoc.length;
|
168
|
-
};
|
169
|
-
Lexer.prototype.commentToken = function() {
|
170
|
-
var comment, here, match;
|
171
|
-
if (!(match = this.chunk.match(COMMENT))) {
|
172
|
-
return 0;
|
173
|
-
}
|
174
|
-
comment = match[0], here = match[1];
|
175
|
-
this.line += count(comment, '\n');
|
176
|
-
if (here) {
|
177
|
-
this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
|
178
|
-
herecomment: true,
|
179
|
-
indent: Array(this.indent + 1).join(' ')
|
180
|
-
}));
|
181
|
-
this.token('TERMINATOR', '\n');
|
182
|
-
}
|
183
|
-
return comment.length;
|
184
|
-
};
|
185
|
-
Lexer.prototype.jsToken = function() {
|
186
|
-
var match, script;
|
187
|
-
if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
|
188
|
-
return 0;
|
189
|
-
}
|
190
|
-
this.token('JS', (script = match[0]).slice(1, -1));
|
191
|
-
return script.length;
|
192
|
-
};
|
193
|
-
Lexer.prototype.regexToken = function() {
|
194
|
-
var match, prev, regex, _ref;
|
195
|
-
if (this.chunk.charAt(0) !== '/') {
|
196
|
-
return 0;
|
197
|
-
}
|
198
|
-
if (match = HEREGEX.exec(this.chunk)) {
|
199
|
-
return this.heregexToken(match);
|
200
|
-
}
|
201
|
-
prev = last(this.tokens);
|
202
|
-
if (prev && (_ref = prev[0], __indexOf.call((prev.spaced ? NOT_REGEX : NOT_SPACED_REGEX), _ref) >= 0)) {
|
203
|
-
return 0;
|
204
|
-
}
|
205
|
-
if (!(match = REGEX.exec(this.chunk))) {
|
206
|
-
return 0;
|
207
|
-
}
|
208
|
-
regex = match[0];
|
209
|
-
this.token('REGEX', regex === '//' ? '/(?:)/' : regex);
|
210
|
-
return regex.length;
|
211
|
-
};
|
212
|
-
Lexer.prototype.heregexToken = function(match) {
|
213
|
-
var body, flags, heregex, re, tag, tokens, value, _i, _len, _ref, _ref2, _ref3, _ref4;
|
214
|
-
heregex = match[0], body = match[1], flags = match[2];
|
215
|
-
if (0 > body.indexOf('#{')) {
|
216
|
-
re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
|
217
|
-
this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
|
218
|
-
return heregex.length;
|
219
|
-
}
|
220
|
-
this.token('IDENTIFIER', 'RegExp');
|
221
|
-
this.tokens.push(['CALL_START', '(']);
|
222
|
-
tokens = [];
|
223
|
-
_ref = this.interpolateString(body, {
|
224
|
-
regex: true
|
225
|
-
});
|
226
|
-
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
227
|
-
_ref2 = _ref[_i], tag = _ref2[0], value = _ref2[1];
|
228
|
-
if (tag === 'TOKENS') {
|
229
|
-
tokens.push.apply(tokens, value);
|
230
|
-
} else {
|
231
|
-
if (!(value = value.replace(HEREGEX_OMIT, ''))) {
|
232
|
-
continue;
|
233
|
-
}
|
234
|
-
value = value.replace(/\\/g, '\\\\');
|
235
|
-
tokens.push(['STRING', this.makeString(value, '"', true)]);
|
236
|
-
}
|
237
|
-
tokens.push(['+', '+']);
|
238
|
-
}
|
239
|
-
tokens.pop();
|
240
|
-
if (((_ref3 = tokens[0]) != null ? _ref3[0] : void 0) !== 'STRING') {
|
241
|
-
this.tokens.push(['STRING', '""'], ['+', '+']);
|
242
|
-
}
|
243
|
-
(_ref4 = this.tokens).push.apply(_ref4, tokens);
|
244
|
-
if (flags) {
|
245
|
-
this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
|
246
|
-
}
|
247
|
-
this.token(')', ')');
|
248
|
-
return heregex.length;
|
249
|
-
};
|
250
|
-
Lexer.prototype.lineToken = function() {
|
251
|
-
var diff, indent, match, noNewlines, prev, size;
|
252
|
-
if (!(match = MULTI_DENT.exec(this.chunk))) {
|
253
|
-
return 0;
|
254
|
-
}
|
255
|
-
indent = match[0];
|
256
|
-
this.line += count(indent, '\n');
|
257
|
-
prev = last(this.tokens, 1);
|
258
|
-
size = indent.length - 1 - indent.lastIndexOf('\n');
|
259
|
-
noNewlines = this.unfinished();
|
260
|
-
if (size - this.indebt === this.indent) {
|
261
|
-
if (noNewlines) {
|
262
|
-
this.suppressNewlines();
|
263
|
-
} else {
|
264
|
-
this.newlineToken();
|
265
|
-
}
|
266
|
-
return indent.length;
|
267
|
-
}
|
268
|
-
if (size > this.indent) {
|
269
|
-
if (noNewlines) {
|
270
|
-
this.indebt = size - this.indent;
|
271
|
-
this.suppressNewlines();
|
272
|
-
return indent.length;
|
273
|
-
}
|
274
|
-
diff = size - this.indent + this.outdebt;
|
275
|
-
this.token('INDENT', diff);
|
276
|
-
this.indents.push(diff);
|
277
|
-
this.outdebt = this.indebt = 0;
|
278
|
-
} else {
|
279
|
-
this.indebt = 0;
|
280
|
-
this.outdentToken(this.indent - size, noNewlines);
|
281
|
-
}
|
282
|
-
this.indent = size;
|
283
|
-
return indent.length;
|
284
|
-
};
|
285
|
-
Lexer.prototype.outdentToken = function(moveOut, noNewlines, close) {
|
286
|
-
var dent, len;
|
287
|
-
while (moveOut > 0) {
|
288
|
-
len = this.indents.length - 1;
|
289
|
-
if (this.indents[len] === void 0) {
|
290
|
-
moveOut = 0;
|
291
|
-
} else if (this.indents[len] === this.outdebt) {
|
292
|
-
moveOut -= this.outdebt;
|
293
|
-
this.outdebt = 0;
|
294
|
-
} else if (this.indents[len] < this.outdebt) {
|
295
|
-
this.outdebt -= this.indents[len];
|
296
|
-
moveOut -= this.indents[len];
|
297
|
-
} else {
|
298
|
-
dent = this.indents.pop() - this.outdebt;
|
299
|
-
moveOut -= dent;
|
300
|
-
this.outdebt = 0;
|
301
|
-
this.token('OUTDENT', dent);
|
302
|
-
}
|
303
|
-
}
|
304
|
-
if (dent) {
|
305
|
-
this.outdebt -= moveOut;
|
306
|
-
}
|
307
|
-
if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
|
308
|
-
this.token('TERMINATOR', '\n');
|
309
|
-
}
|
310
|
-
return this;
|
311
|
-
};
|
312
|
-
Lexer.prototype.whitespaceToken = function() {
|
313
|
-
var match, nline, prev;
|
314
|
-
if (!((match = WHITESPACE.exec(this.chunk)) || (nline = this.chunk.charAt(0) === '\n'))) {
|
315
|
-
return 0;
|
316
|
-
}
|
317
|
-
prev = last(this.tokens);
|
318
|
-
if (prev) {
|
319
|
-
prev[match ? 'spaced' : 'newLine'] = true;
|
320
|
-
}
|
321
|
-
if (match) {
|
322
|
-
return match[0].length;
|
323
|
-
} else {
|
324
|
-
return 0;
|
325
|
-
}
|
326
|
-
};
|
327
|
-
Lexer.prototype.newlineToken = function() {
|
328
|
-
if (this.tag() !== 'TERMINATOR') {
|
329
|
-
this.token('TERMINATOR', '\n');
|
330
|
-
}
|
331
|
-
return this;
|
332
|
-
};
|
333
|
-
Lexer.prototype.suppressNewlines = function() {
|
334
|
-
if (this.value() === '\\') {
|
335
|
-
this.tokens.pop();
|
336
|
-
}
|
337
|
-
return this;
|
338
|
-
};
|
339
|
-
Lexer.prototype.literalToken = function() {
|
340
|
-
var match, prev, tag, value, _ref, _ref2, _ref3, _ref4;
|
341
|
-
if (match = OPERATOR.exec(this.chunk)) {
|
342
|
-
value = match[0];
|
343
|
-
if (CODE.test(value)) {
|
344
|
-
this.tagParameters();
|
345
|
-
}
|
346
|
-
} else {
|
347
|
-
value = this.chunk.charAt(0);
|
348
|
-
}
|
349
|
-
tag = value;
|
350
|
-
prev = last(this.tokens);
|
351
|
-
if (value === '=' && prev) {
|
352
|
-
if (!prev[1].reserved && (_ref = prev[1], __indexOf.call(JS_FORBIDDEN, _ref) >= 0)) {
|
353
|
-
this.assignmentError();
|
354
|
-
}
|
355
|
-
if ((_ref2 = prev[1]) === '||' || _ref2 === '&&') {
|
356
|
-
prev[0] = 'COMPOUND_ASSIGN';
|
357
|
-
prev[1] += '=';
|
358
|
-
return value.length;
|
359
|
-
}
|
360
|
-
}
|
361
|
-
if (value === ';') {
|
362
|
-
tag = 'TERMINATOR';
|
363
|
-
} else if (__indexOf.call(MATH, value) >= 0) {
|
364
|
-
tag = 'MATH';
|
365
|
-
} else if (__indexOf.call(COMPARE, value) >= 0) {
|
366
|
-
tag = 'COMPARE';
|
367
|
-
} else if (__indexOf.call(COMPOUND_ASSIGN, value) >= 0) {
|
368
|
-
tag = 'COMPOUND_ASSIGN';
|
369
|
-
} else if (__indexOf.call(UNARY, value) >= 0) {
|
370
|
-
tag = 'UNARY';
|
371
|
-
} else if (__indexOf.call(SHIFT, value) >= 0) {
|
372
|
-
tag = 'SHIFT';
|
373
|
-
} else if (__indexOf.call(LOGIC, value) >= 0 || value === '?' && (prev != null ? prev.spaced : void 0)) {
|
374
|
-
tag = 'LOGIC';
|
375
|
-
} else if (prev && !prev.spaced) {
|
376
|
-
if (value === '(' && (_ref3 = prev[0], __indexOf.call(CALLABLE, _ref3) >= 0)) {
|
377
|
-
if (prev[0] === '?') {
|
378
|
-
prev[0] = 'FUNC_EXIST';
|
379
|
-
}
|
380
|
-
tag = 'CALL_START';
|
381
|
-
} else if (value === '[' && (_ref4 = prev[0], __indexOf.call(INDEXABLE, _ref4) >= 0)) {
|
382
|
-
tag = 'INDEX_START';
|
383
|
-
switch (prev[0]) {
|
384
|
-
case '?':
|
385
|
-
prev[0] = 'INDEX_SOAK';
|
386
|
-
break;
|
387
|
-
case '::':
|
388
|
-
prev[0] = 'INDEX_PROTO';
|
389
|
-
}
|
390
|
-
}
|
391
|
-
}
|
392
|
-
this.token(tag, value);
|
393
|
-
return value.length;
|
394
|
-
};
|
395
|
-
Lexer.prototype.sanitizeHeredoc = function(doc, options) {
|
396
|
-
var attempt, herecomment, indent, match, _ref;
|
397
|
-
indent = options.indent, herecomment = options.herecomment;
|
398
|
-
if (herecomment && 0 > doc.indexOf('\n')) {
|
399
|
-
return doc;
|
400
|
-
}
|
401
|
-
if (!herecomment) {
|
402
|
-
while (match = HEREDOC_INDENT.exec(doc)) {
|
403
|
-
attempt = match[1];
|
404
|
-
if (indent === null || (0 < (_ref = attempt.length) && _ref < indent.length)) {
|
405
|
-
indent = attempt;
|
406
|
-
}
|
407
|
-
}
|
408
|
-
}
|
409
|
-
if (indent) {
|
410
|
-
doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
|
411
|
-
}
|
412
|
-
if (!herecomment) {
|
413
|
-
doc = doc.replace(/^\n/, '');
|
414
|
-
}
|
415
|
-
return doc;
|
416
|
-
};
|
417
|
-
Lexer.prototype.tagParameters = function() {
|
418
|
-
var i, stack, tok, tokens;
|
419
|
-
if (this.tag() !== ')') {
|
420
|
-
return this;
|
421
|
-
}
|
422
|
-
stack = [];
|
423
|
-
tokens = this.tokens;
|
424
|
-
i = tokens.length;
|
425
|
-
tokens[--i][0] = 'PARAM_END';
|
426
|
-
while (tok = tokens[--i]) {
|
427
|
-
switch (tok[0]) {
|
428
|
-
case ')':
|
429
|
-
stack.push(tok);
|
430
|
-
break;
|
431
|
-
case '(':
|
432
|
-
case 'CALL_START':
|
433
|
-
if (stack.length) {
|
434
|
-
stack.pop();
|
435
|
-
} else {
|
436
|
-
tok[0] = 'PARAM_START';
|
437
|
-
return this;
|
438
|
-
}
|
439
|
-
}
|
440
|
-
}
|
441
|
-
return this;
|
442
|
-
};
|
443
|
-
Lexer.prototype.closeIndentation = function() {
|
444
|
-
return this.outdentToken(this.indent);
|
445
|
-
};
|
446
|
-
Lexer.prototype.identifierError = function(word) {
|
447
|
-
throw SyntaxError("Reserved word \"" + word + "\" on line " + (this.line + 1));
|
448
|
-
};
|
449
|
-
Lexer.prototype.assignmentError = function() {
|
450
|
-
throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
|
451
|
-
};
|
452
|
-
Lexer.prototype.balancedString = function(str, end) {
|
453
|
-
var i, letter, prev, stack, _ref;
|
454
|
-
stack = [end];
|
455
|
-
for (i = 1, _ref = str.length; (1 <= _ref ? i < _ref : i > _ref); (1 <= _ref ? i += 1 : i -= 1)) {
|
456
|
-
switch (letter = str.charAt(i)) {
|
457
|
-
case '\\':
|
458
|
-
i++;
|
459
|
-
continue;
|
460
|
-
case end:
|
461
|
-
stack.pop();
|
462
|
-
if (!stack.length) {
|
463
|
-
return str.slice(0, i + 1);
|
464
|
-
}
|
465
|
-
end = stack[stack.length - 1];
|
466
|
-
continue;
|
467
|
-
}
|
468
|
-
if (end === '}' && (letter === '"' || letter === "'")) {
|
469
|
-
stack.push(end = letter);
|
470
|
-
} else if (end === '}' && letter === '{') {
|
471
|
-
stack.push(end = '}');
|
472
|
-
} else if (end === '"' && prev === '#' && letter === '{') {
|
473
|
-
stack.push(end = '}');
|
474
|
-
}
|
475
|
-
prev = letter;
|
476
|
-
}
|
477
|
-
throw new Error("missing " + (stack.pop()) + ", starting on line " + (this.line + 1));
|
478
|
-
};
|
479
|
-
Lexer.prototype.interpolateString = function(str, options) {
|
480
|
-
var expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value, _len, _ref, _ref2, _ref3;
|
481
|
-
if (options == null) {
|
482
|
-
options = {};
|
483
|
-
}
|
484
|
-
heredoc = options.heredoc, regex = options.regex;
|
485
|
-
tokens = [];
|
486
|
-
pi = 0;
|
487
|
-
i = -1;
|
488
|
-
while (letter = str.charAt(i += 1)) {
|
489
|
-
if (letter === '\\') {
|
490
|
-
i += 1;
|
491
|
-
continue;
|
492
|
-
}
|
493
|
-
if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), '}')))) {
|
494
|
-
continue;
|
495
|
-
}
|
496
|
-
if (pi < i) {
|
497
|
-
tokens.push(['NEOSTRING', str.slice(pi, i)]);
|
498
|
-
}
|
499
|
-
inner = expr.slice(1, -1);
|
500
|
-
if (inner.length) {
|
501
|
-
nested = new Lexer().tokenize(inner, {
|
502
|
-
line: this.line,
|
503
|
-
rewrite: false
|
504
|
-
});
|
505
|
-
nested.pop();
|
506
|
-
if (((_ref = nested[0]) != null ? _ref[0] : void 0) === 'TERMINATOR') {
|
507
|
-
nested.shift();
|
508
|
-
}
|
509
|
-
if (nested.length > 1) {
|
510
|
-
nested.unshift(['(', '(']);
|
511
|
-
nested.push([')', ')']);
|
512
|
-
}
|
513
|
-
tokens.push(['TOKENS', nested]);
|
514
|
-
}
|
515
|
-
i += expr.length;
|
516
|
-
pi = i + 1;
|
517
|
-
}
|
518
|
-
if ((i > pi && pi < str.length)) {
|
519
|
-
tokens.push(['NEOSTRING', str.slice(pi)]);
|
520
|
-
}
|
521
|
-
if (regex) {
|
522
|
-
return tokens;
|
523
|
-
}
|
524
|
-
if (!tokens.length) {
|
525
|
-
return this.token('STRING', '""');
|
526
|
-
}
|
527
|
-
if (tokens[0][0] !== 'NEOSTRING') {
|
528
|
-
tokens.unshift(['', '']);
|
529
|
-
}
|
530
|
-
if (interpolated = tokens.length > 1) {
|
531
|
-
this.token('(', '(');
|
532
|
-
}
|
533
|
-
for (i = 0, _len = tokens.length; i < _len; i++) {
|
534
|
-
_ref2 = tokens[i], tag = _ref2[0], value = _ref2[1];
|
535
|
-
if (i) {
|
536
|
-
this.token('+', '+');
|
537
|
-
}
|
538
|
-
if (tag === 'TOKENS') {
|
539
|
-
(_ref3 = this.tokens).push.apply(_ref3, value);
|
540
|
-
} else {
|
541
|
-
this.token('STRING', this.makeString(value, '"', heredoc));
|
542
|
-
}
|
543
|
-
}
|
544
|
-
if (interpolated) {
|
545
|
-
this.token(')', ')');
|
546
|
-
}
|
547
|
-
return tokens;
|
548
|
-
};
|
549
|
-
Lexer.prototype.token = function(tag, value) {
|
550
|
-
return this.tokens.push([tag, value, this.line]);
|
551
|
-
};
|
552
|
-
Lexer.prototype.tag = function(index, tag) {
|
553
|
-
var tok;
|
554
|
-
return (tok = last(this.tokens, index)) && (tag ? tok[0] = tag : tok[0]);
|
555
|
-
};
|
556
|
-
Lexer.prototype.value = function(index, val) {
|
557
|
-
var tok;
|
558
|
-
return (tok = last(this.tokens, index)) && (val ? tok[1] = val : tok[1]);
|
559
|
-
};
|
560
|
-
Lexer.prototype.unfinished = function() {
|
561
|
-
var prev, value;
|
562
|
-
return LINE_CONTINUER.test(this.chunk) || (prev = last(this.tokens, 1)) && prev[0] !== '.' && (value = this.value()) && !value.reserved && NO_NEWLINE.test(value) && !CODE.test(value) && !ASSIGNED.test(this.chunk);
|
563
|
-
};
|
564
|
-
Lexer.prototype.escapeLines = function(str, heredoc) {
|
565
|
-
return str.replace(MULTILINER, heredoc ? '\\n' : '');
|
566
|
-
};
|
567
|
-
Lexer.prototype.makeString = function(body, quote, heredoc) {
|
568
|
-
if (!body) {
|
569
|
-
return quote + quote;
|
570
|
-
}
|
571
|
-
body = body.replace(/\\([\s\S])/g, function(match, contents) {
|
572
|
-
if (contents === '\n' || contents === quote) {
|
573
|
-
return contents;
|
574
|
-
} else {
|
575
|
-
return match;
|
576
|
-
}
|
577
|
-
});
|
578
|
-
body = body.replace(RegExp("" + quote, "g"), '\\$&');
|
579
|
-
return quote + this.escapeLines(body, heredoc) + quote;
|
580
|
-
};
|
581
|
-
return Lexer;
|
582
|
-
})();
|
583
|
-
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
|
584
|
-
COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
|
585
|
-
for (op in COFFEE_ALIASES = {
|
586
|
-
and: '&&',
|
587
|
-
or: '||',
|
588
|
-
is: '==',
|
589
|
-
isnt: '!=',
|
590
|
-
not: '!',
|
591
|
-
yes: 'true',
|
592
|
-
no: 'false',
|
593
|
-
on: 'true',
|
594
|
-
off: 'false'
|
595
|
-
}) {
|
596
|
-
COFFEE_KEYWORDS.push(op);
|
597
|
-
}
|
598
|
-
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice', '__bind', '__indexOf'];
|
599
|
-
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
|
600
|
-
exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS);
|
601
|
-
IDENTIFIER = /^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/;
|
602
|
-
NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i;
|
603
|
-
HEREDOC = /^("""|''')([\s\S]*?)(?:\n[^\n\S]*)?\1/;
|
604
|
-
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
|
605
|
-
WHITESPACE = /^[^\n\S]+/;
|
606
|
-
COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
|
607
|
-
CODE = /^[-=]>/;
|
608
|
-
MULTI_DENT = /^(?:\n[^\n\S]*)+/;
|
609
|
-
SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
|
610
|
-
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
|
611
|
-
REGEX = /^\/(?!\s)[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4}(?!\w)/;
|
612
|
-
HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?!\w)/;
|
613
|
-
HEREGEX_OMIT = /\s+(?:#.*)?/g;
|
614
|
-
MULTILINER = /\n/g;
|
615
|
-
HEREDOC_INDENT = /\n+([^\n\S]*)/g;
|
616
|
-
ASSIGNED = /^\s*@?([$A-Za-z_][$\w]*|['"].*['"])[^\n\S]*?[:=][^:=>]/;
|
617
|
-
LINE_CONTINUER = /^\s*(?:,|\??\.(?!\.)|::)/;
|
618
|
-
TRAILING_SPACES = /\s+$/;
|
619
|
-
NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/;
|
620
|
-
COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
|
621
|
-
UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO'];
|
622
|
-
LOGIC = ['&&', '||', '&', '|', '^'];
|
623
|
-
SHIFT = ['<<', '>>', '>>>'];
|
624
|
-
COMPARE = ['==', '!=', '<', '>', '<=', '>='];
|
625
|
-
MATH = ['*', '/', '%'];
|
626
|
-
RELATION = ['IN', 'OF', 'INSTANCEOF'];
|
627
|
-
BOOL = ['TRUE', 'FALSE', 'NULL', 'UNDEFINED'];
|
628
|
-
NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']'];
|
629
|
-
NOT_SPACED_REGEX = NOT_REGEX.concat(')', '}', 'THIS', 'IDENTIFIER', 'STRING');
|
630
|
-
CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
|
631
|
-
INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL');
|
632
|
-
LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
|
633
|
-
}).call(this);
|