haml-more 0.4.0.a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. data/README.md +79 -0
  2. data/lib/haml/more/coffee_script.rb +137 -0
  3. data/lib/haml/more/content_for.rb +25 -0
  4. data/lib/haml/more.rb +45 -0
  5. data/lib/haml-more.rb +1 -0
  6. data/lib/sass/more.rb +16 -0
  7. data/lib/sass-more.rb +1 -0
  8. data/spec/sass/more_spec.rb +21 -0
  9. data/vendor/coffee-script/Cakefile +57 -0
  10. data/vendor/coffee-script/LICENSE +22 -0
  11. data/vendor/coffee-script/README +41 -0
  12. data/vendor/coffee-script/Rakefile +20 -0
  13. data/vendor/coffee-script/bin/cake +7 -0
  14. data/vendor/coffee-script/bin/coffee +7 -0
  15. data/vendor/coffee-script/documentation/coffee/aliases.coffee +9 -0
  16. data/vendor/coffee-script/documentation/coffee/arguments.coffee +4 -0
  17. data/vendor/coffee-script/documentation/coffee/array_comprehensions.coffee +7 -0
  18. data/vendor/coffee-script/documentation/coffee/assignment.coffee +2 -0
  19. data/vendor/coffee-script/documentation/coffee/cake_tasks.coffee +5 -0
  20. data/vendor/coffee-script/documentation/coffee/comparisons.coffee +5 -0
  21. data/vendor/coffee-script/documentation/coffee/conditionals.coffee +9 -0
  22. data/vendor/coffee-script/documentation/coffee/embedded.coffee +5 -0
  23. data/vendor/coffee-script/documentation/coffee/existence.coffee +8 -0
  24. data/vendor/coffee-script/documentation/coffee/expressions.coffee +9 -0
  25. data/vendor/coffee-script/documentation/coffee/expressions_assignment.coffee +1 -0
  26. data/vendor/coffee-script/documentation/coffee/expressions_comprehension.coffee +3 -0
  27. data/vendor/coffee-script/documentation/coffee/expressions_try.coffee +6 -0
  28. data/vendor/coffee-script/documentation/coffee/fat_arrow.coffee +6 -0
  29. data/vendor/coffee-script/documentation/coffee/functions.coffee +2 -0
  30. data/vendor/coffee-script/documentation/coffee/heredocs.coffee +5 -0
  31. data/vendor/coffee-script/documentation/coffee/multiple_return_values.coffee +5 -0
  32. data/vendor/coffee-script/documentation/coffee/object_comprehensions.coffee +4 -0
  33. data/vendor/coffee-script/documentation/coffee/object_extraction.coffee +13 -0
  34. data/vendor/coffee-script/documentation/coffee/objects_and_arrays.coffee +13 -0
  35. data/vendor/coffee-script/documentation/coffee/overview.coffee +29 -0
  36. data/vendor/coffee-script/documentation/coffee/parallel_assignment.coffee +4 -0
  37. data/vendor/coffee-script/documentation/coffee/range_comprehensions.coffee +6 -0
  38. data/vendor/coffee-script/documentation/coffee/scope.coffee +5 -0
  39. data/vendor/coffee-script/documentation/coffee/slices.coffee +6 -0
  40. data/vendor/coffee-script/documentation/coffee/soaks.coffee +1 -0
  41. data/vendor/coffee-script/documentation/coffee/splats.coffee +25 -0
  42. data/vendor/coffee-script/documentation/coffee/splices.coffee +5 -0
  43. data/vendor/coffee-script/documentation/coffee/strings.coffee +8 -0
  44. data/vendor/coffee-script/documentation/coffee/super.coffee +34 -0
  45. data/vendor/coffee-script/documentation/coffee/switch.coffee +10 -0
  46. data/vendor/coffee-script/documentation/coffee/try.coffee +7 -0
  47. data/vendor/coffee-script/documentation/coffee/while.coffee +10 -0
  48. data/vendor/coffee-script/documentation/css/docs.css +213 -0
  49. data/vendor/coffee-script/documentation/css/idle.css +63 -0
  50. data/vendor/coffee-script/documentation/css/logo.png +0 -0
  51. data/vendor/coffee-script/documentation/index.html.erb +967 -0
  52. data/vendor/coffee-script/documentation/js/aliases.js +14 -0
  53. data/vendor/coffee-script/documentation/js/arguments.js +8 -0
  54. data/vendor/coffee-script/documentation/js/array_comprehensions.js +26 -0
  55. data/vendor/coffee-script/documentation/js/assignment.js +5 -0
  56. data/vendor/coffee-script/documentation/js/cake_tasks.js +14 -0
  57. data/vendor/coffee-script/documentation/js/comparisons.js +5 -0
  58. data/vendor/coffee-script/documentation/js/conditionals.js +12 -0
  59. data/vendor/coffee-script/documentation/js/embedded.js +6 -0
  60. data/vendor/coffee-script/documentation/js/existence.js +7 -0
  61. data/vendor/coffee-script/documentation/js/expressions.js +13 -0
  62. data/vendor/coffee-script/documentation/js/expressions_assignment.js +4 -0
  63. data/vendor/coffee-script/documentation/js/expressions_comprehension.js +12 -0
  64. data/vendor/coffee-script/documentation/js/expressions_try.js +9 -0
  65. data/vendor/coffee-script/documentation/js/fat_arrow.js +15 -0
  66. data/vendor/coffee-script/documentation/js/functions.js +9 -0
  67. data/vendor/coffee-script/documentation/js/heredocs.js +4 -0
  68. data/vendor/coffee-script/documentation/js/intro.js +7 -0
  69. data/vendor/coffee-script/documentation/js/multiple_return_values.js +11 -0
  70. data/vendor/coffee-script/documentation/js/object_comprehensions.js +17 -0
  71. data/vendor/coffee-script/documentation/js/object_extraction.js +17 -0
  72. data/vendor/coffee-script/documentation/js/objects_and_arrays.js +10 -0
  73. data/vendor/coffee-script/documentation/js/overview.js +43 -0
  74. data/vendor/coffee-script/documentation/js/parallel_assignment.js +8 -0
  75. data/vendor/coffee-script/documentation/js/punctuation.js +8 -0
  76. data/vendor/coffee-script/documentation/js/range_comprehensions.js +21 -0
  77. data/vendor/coffee-script/documentation/js/scope.js +10 -0
  78. data/vendor/coffee-script/documentation/js/slices.js +6 -0
  79. data/vendor/coffee-script/documentation/js/soaks.js +4 -0
  80. data/vendor/coffee-script/documentation/js/splats.js +16 -0
  81. data/vendor/coffee-script/documentation/js/splices.js +5 -0
  82. data/vendor/coffee-script/documentation/js/strings.js +9 -0
  83. data/vendor/coffee-script/documentation/js/super.js +37 -0
  84. data/vendor/coffee-script/documentation/js/switch.js +18 -0
  85. data/vendor/coffee-script/documentation/js/try.js +10 -0
  86. data/vendor/coffee-script/documentation/js/while.js +22 -0
  87. data/vendor/coffee-script/documentation/underscore.html +627 -0
  88. data/vendor/coffee-script/examples/beautiful_code/binary_search.coffee +16 -0
  89. data/vendor/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +13 -0
  90. data/vendor/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +34 -0
  91. data/vendor/coffee-script/examples/blocks.coffee +57 -0
  92. data/vendor/coffee-script/examples/code.coffee +173 -0
  93. data/vendor/coffee-script/examples/computer_science/README +4 -0
  94. data/vendor/coffee-script/examples/computer_science/binary_search.coffee +25 -0
  95. data/vendor/coffee-script/examples/computer_science/bubble_sort.coffee +11 -0
  96. data/vendor/coffee-script/examples/computer_science/linked_list.coffee +106 -0
  97. data/vendor/coffee-script/examples/computer_science/luhn_algorithm.coffee +36 -0
  98. data/vendor/coffee-script/examples/computer_science/merge_sort.coffee +19 -0
  99. data/vendor/coffee-script/examples/computer_science/selection_sort.coffee +23 -0
  100. data/vendor/coffee-script/examples/poignant.coffee +186 -0
  101. data/vendor/coffee-script/examples/potion.coffee +205 -0
  102. data/vendor/coffee-script/examples/underscore.coffee +603 -0
  103. data/vendor/coffee-script/examples/web_server.coffee +12 -0
  104. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences +24 -0
  105. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +361 -0
  106. data/vendor/coffee-script/extras/CoffeeScript.tmbundle/info.plist +10 -0
  107. data/vendor/coffee-script/extras/EXTRAS +20 -0
  108. data/vendor/coffee-script/extras/coffee.vim +117 -0
  109. data/vendor/coffee-script/index.html +1847 -0
  110. data/vendor/coffee-script/lib/bin/cake +7 -0
  111. data/vendor/coffee-script/lib/bin/coffee +7 -0
  112. data/vendor/coffee-script/lib/cake.js +80 -0
  113. data/vendor/coffee-script/lib/coffee-script.js +61 -0
  114. data/vendor/coffee-script/lib/command_line.js +201 -0
  115. data/vendor/coffee-script/lib/grammar.js +564 -0
  116. data/vendor/coffee-script/lib/lexer.js +405 -0
  117. data/vendor/coffee-script/lib/narwhal.js +44 -0
  118. data/vendor/coffee-script/lib/nodes.js +1328 -0
  119. data/vendor/coffee-script/lib/optparse.js +117 -0
  120. data/vendor/coffee-script/lib/parser.js +536 -0
  121. data/vendor/coffee-script/lib/repl.js +32 -0
  122. data/vendor/coffee-script/lib/rewriter.js +383 -0
  123. data/vendor/coffee-script/lib/scope.js +114 -0
  124. data/vendor/coffee-script/package.json +7 -0
  125. data/vendor/coffee-script/src/cake.coffee +45 -0
  126. data/vendor/coffee-script/src/coffee-script.coffee +45 -0
  127. data/vendor/coffee-script/src/command_line.coffee +130 -0
  128. data/vendor/coffee-script/src/grammar.coffee +456 -0
  129. data/vendor/coffee-script/src/lexer.coffee +327 -0
  130. data/vendor/coffee-script/src/narwhal.coffee +42 -0
  131. data/vendor/coffee-script/src/nodes.coffee +1045 -0
  132. data/vendor/coffee-script/src/optparse.coffee +79 -0
  133. data/vendor/coffee-script/src/repl.coffee +23 -0
  134. data/vendor/coffee-script/src/rewriter.coffee +253 -0
  135. data/vendor/coffee-script/src/scope.coffee +75 -0
  136. data/vendor/coffee-script/test/test_arguments.coffee +34 -0
  137. data/vendor/coffee-script/test/test_array_comprehension.coffee +42 -0
  138. data/vendor/coffee-script/test/test_assignment.coffee +26 -0
  139. data/vendor/coffee-script/test/test_blocks.coffee +4 -0
  140. data/vendor/coffee-script/test/test_calling_super.coffee +42 -0
  141. data/vendor/coffee-script/test/test_chained_calls.coffee +25 -0
  142. data/vendor/coffee-script/test/test_destructuring_assignment.coffee +62 -0
  143. data/vendor/coffee-script/test/test_everything.coffee +29 -0
  144. data/vendor/coffee-script/test/test_exceptions.coffee +2 -0
  145. data/vendor/coffee-script/test/test_existence.coffee +81 -0
  146. data/vendor/coffee-script/test/test_expressions.coffee +30 -0
  147. data/vendor/coffee-script/test/test_fancy_if_statement.coffee +26 -0
  148. data/vendor/coffee-script/test/test_functions.coffee +80 -0
  149. data/vendor/coffee-script/test/test_funky_comments.coffee +25 -0
  150. data/vendor/coffee-script/test/test_heredocs.coffee +46 -0
  151. data/vendor/coffee-script/test/test_lexical_scope.coffee +10 -0
  152. data/vendor/coffee-script/test/test_literals.coffee +56 -0
  153. data/vendor/coffee-script/test/test_nested_comprehensions.coffee +11 -0
  154. data/vendor/coffee-script/test/test_newline_escaping.coffee +6 -0
  155. data/vendor/coffee-script/test/test_operations.coffee +18 -0
  156. data/vendor/coffee-script/test/test_range_comprehension.coffee +20 -0
  157. data/vendor/coffee-script/test/test_ranges_and_slices.coffee +16 -0
  158. data/vendor/coffee-script/test/test_splats.coffee +47 -0
  159. data/vendor/coffee-script/test/test_splices.coffee +5 -0
  160. data/vendor/coffee-script/test/test_switch.coffee +64 -0
  161. data/vendor/coffee-script/test/test_while.coffee +30 -0
  162. data/vendor/coffee-script/vendor/jison/Jakefile +31 -0
  163. data/vendor/coffee-script/vendor/jison/README.md +347 -0
  164. data/vendor/coffee-script/vendor/jison/bin/jison +3 -0
  165. data/vendor/coffee-script/vendor/jison/bin/json2jison +3 -0
  166. data/vendor/coffee-script/vendor/jison/examples/ansic.jison +415 -0
  167. data/vendor/coffee-script/vendor/jison/examples/basic.json +8 -0
  168. data/vendor/coffee-script/vendor/jison/examples/basic2.json +9 -0
  169. data/vendor/coffee-script/vendor/jison/examples/basic2_lex.json +16 -0
  170. data/vendor/coffee-script/vendor/jison/examples/basic_lex.json +15 -0
  171. data/vendor/coffee-script/vendor/jison/examples/calculator.jison +38 -0
  172. data/vendor/coffee-script/vendor/jison/examples/calculator.jisonlex +14 -0
  173. data/vendor/coffee-script/vendor/jison/examples/calculator.json +42 -0
  174. data/vendor/coffee-script/vendor/jison/examples/classy.json +105 -0
  175. data/vendor/coffee-script/vendor/jison/examples/classy_ast.json +126 -0
  176. data/vendor/coffee-script/vendor/jison/examples/dism.json +25 -0
  177. data/vendor/coffee-script/vendor/jison/examples/dism_lr0.json +26 -0
  178. data/vendor/coffee-script/vendor/jison/examples/json.js +80 -0
  179. data/vendor/coffee-script/vendor/jison/examples/json_ast.js +83 -0
  180. data/vendor/coffee-script/vendor/jison/examples/precedence.json +26 -0
  181. data/vendor/coffee-script/vendor/jison/examples/reduce_conflict.json +13 -0
  182. data/vendor/coffee-script/vendor/jison/lib/jison/bnf.js +43 -0
  183. data/vendor/coffee-script/vendor/jison/lib/jison/jisonlex.js +18 -0
  184. data/vendor/coffee-script/vendor/jison/lib/jison/json2jison.js +146 -0
  185. data/vendor/coffee-script/vendor/jison/lib/jison/lexer.js +224 -0
  186. data/vendor/coffee-script/vendor/jison/lib/jison/util/bnf-parser.js +383 -0
  187. data/vendor/coffee-script/vendor/jison/lib/jison/util/lex-parser.js +407 -0
  188. data/vendor/coffee-script/vendor/jison/lib/jison/util/set.js +94 -0
  189. data/vendor/coffee-script/vendor/jison/lib/jison/util/typal.js +90 -0
  190. data/vendor/coffee-script/vendor/jison/lib/jison.js +1414 -0
  191. data/vendor/coffee-script/vendor/jison/package.json +14 -0
  192. data/vendor/coffee-script/vendor/jison/src/bnf.jison +110 -0
  193. data/vendor/coffee-script/vendor/jison/src/bnf.jisonlex +25 -0
  194. data/vendor/coffee-script/vendor/jison/src/bnf.lex.json +24 -0
  195. data/vendor/coffee-script/vendor/jison/src/jisonlex.jison +129 -0
  196. data/vendor/coffee-script/vendor/jison/src/jisonlex.jisonlex +31 -0
  197. data/vendor/coffee-script/vendor/jison/src/jisonlex.lex.json +30 -0
  198. data/vendor/coffee-script/vendor/jison/tests/all-tests.js +8 -0
  199. data/vendor/coffee-script/vendor/jison/tests/grammar/bnf.js +91 -0
  200. data/vendor/coffee-script/vendor/jison/tests/grammar/bnf_parse.js +65 -0
  201. data/vendor/coffee-script/vendor/jison/tests/grammar/grammar-tests.js +10 -0
  202. data/vendor/coffee-script/vendor/jison/tests/grammar/json2jison.js +24 -0
  203. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/ansic.jisonlex +115 -0
  204. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.jisonlex +25 -0
  205. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/bnf.lex.json +24 -0
  206. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.jisonlex +31 -0
  207. data/vendor/coffee-script/vendor/jison/tests/grammar/lex/lex_grammar.lex.json +30 -0
  208. data/vendor/coffee-script/vendor/jison/tests/grammar/lex.jison +119 -0
  209. data/vendor/coffee-script/vendor/jison/tests/grammar/lex.js +58 -0
  210. data/vendor/coffee-script/vendor/jison/tests/grammar/lex_parse.js +117 -0
  211. data/vendor/coffee-script/vendor/jison/tests/lexer/lexer-tests.js +6 -0
  212. data/vendor/coffee-script/vendor/jison/tests/lexer/regexplexer.js +417 -0
  213. data/vendor/coffee-script/vendor/jison/tests/parser/actions.js +311 -0
  214. data/vendor/coffee-script/vendor/jison/tests/parser/api.js +236 -0
  215. data/vendor/coffee-script/vendor/jison/tests/parser/generator.js +196 -0
  216. data/vendor/coffee-script/vendor/jison/tests/parser/lalr.js +183 -0
  217. data/vendor/coffee-script/vendor/jison/tests/parser/lr0.js +72 -0
  218. data/vendor/coffee-script/vendor/jison/tests/parser/lr1.js +119 -0
  219. data/vendor/coffee-script/vendor/jison/tests/parser/parser-tests.js +14 -0
  220. data/vendor/coffee-script/vendor/jison/tests/parser/precedence.js +237 -0
  221. data/vendor/coffee-script/vendor/jison/tests/parser/slr.js +52 -0
  222. data/vendor/coffee-script/vendor/jison/tests/parser/tables.js +126 -0
  223. data/vendor/coffee-script/vendor/jison/tests/performance.js +110 -0
  224. data/vendor/coffee-script/vendor/jison/tests/setup.js +3 -0
  225. metadata +324 -0
@@ -0,0 +1,32 @@
1
+ (function(){
2
+ var coffee, prompt, quit, readline;
3
+ // A CoffeeScript port/version of the Node.js REPL.
4
+ // Required modules.
5
+ coffee = require('coffee-script');
6
+ // Shortcut variables.
7
+ prompt = 'coffee> ';
8
+ quit = function quit() {
9
+ return process.exit(0);
10
+ };
11
+ // The main REPL function. Called everytime a line of code is entered.
12
+ // Attempt to evaluate the command. If there's an exception, print it.
13
+ readline = function readline(code) {
14
+ var val;
15
+ try {
16
+ val = eval(coffee.compile(code, {
17
+ no_wrap: true,
18
+ globals: true
19
+ }));
20
+ if (val !== undefined) {
21
+ p(val);
22
+ }
23
+ } catch (err) {
24
+ puts(err.stack || err.toString());
25
+ }
26
+ return print(prompt);
27
+ };
28
+ // Start up the REPL.
29
+ process.stdio.addListener('data', readline);
30
+ process.stdio.open();
31
+ print(prompt);
32
+ })();
@@ -0,0 +1,383 @@
1
+ (function(){
2
+ var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_START, EXPRESSION_TAIL, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, INVERSES, SINGLE_CLOSERS, SINGLE_LINERS, _a, _b, _c, _d, _e, _f, _g, _h, pair, re;
3
+ var __hasProp = Object.prototype.hasOwnProperty;
4
+ if (!((typeof process !== "undefined" && process !== null))) {
5
+ this.exports = this;
6
+ }
7
+ // In order to keep the grammar simple, the stream of tokens that the Lexer
8
+ // emits is rewritten by the Rewriter, smoothing out ambiguities, mis-nested
9
+ // indentation, and single-line flavors of expressions.
10
+ exports.Rewriter = (re = function re() { });
11
+ // Tokens that must be balanced.
12
+ BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['PARAM_START', 'PARAM_END'], ['CALL_START', 'CALL_END'], ['INDEX_START', 'INDEX_END'], ['SOAKED_INDEX_START', 'SOAKED_INDEX_END']];
13
+ // Tokens that signal the start of a balanced pair.
14
+ EXPRESSION_START = (function() {
15
+ _a = []; _b = BALANCED_PAIRS;
16
+ for (_c = 0; _c < _b.length; _c++) {
17
+ pair = _b[_c];
18
+ _a.push(pair[0]);
19
+ }
20
+ return _a;
21
+ }).call(this);
22
+ // Tokens that signal the end of a balanced pair.
23
+ EXPRESSION_TAIL = (function() {
24
+ _d = []; _e = BALANCED_PAIRS;
25
+ for (_f = 0; _f < _e.length; _f++) {
26
+ pair = _e[_f];
27
+ _d.push(pair[1]);
28
+ }
29
+ return _d;
30
+ }).call(this);
31
+ // Tokens that indicate the close of a clause of an expression.
32
+ EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_TAIL);
33
+ // Tokens pairs that, in immediate succession, indicate an implicit call.
34
+ IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END'];
35
+ IMPLICIT_BLOCK = ['->', '=>', '{', '[', ','];
36
+ IMPLICIT_END = ['IF', 'UNLESS', 'FOR', 'WHILE', 'TERMINATOR', 'INDENT', 'OUTDENT'];
37
+ IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'TRY', 'DELETE', 'TYPEOF', 'SWITCH', 'TRUE', 'FALSE', 'YES', 'NO', 'ON', 'OFF', '!', '!!', 'NOT', '@', '->', '=>', '[', '(', '{'];
38
+ // The inverse mappings of token pairs we're trying to fix up.
39
+ INVERSES = {};
40
+ _g = BALANCED_PAIRS;
41
+ for (_h = 0; _h < _g.length; _h++) {
42
+ pair = _g[_h];
43
+ INVERSES[pair[0]] = pair[1];
44
+ INVERSES[pair[1]] = pair[0];
45
+ }
46
+ // Single-line flavors of block expressions that have unclosed endings.
47
+ // The grammar can't disambiguate them, so we insert the implicit indentation.
48
+ SINGLE_LINERS = ['ELSE', "->", "=>", 'TRY', 'FINALLY', 'THEN'];
49
+ SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN', 'PARAM_START'];
50
+ // Rewrite the token stream in multiple passes, one logical filter at
51
+ // a time. This could certainly be changed into a single pass through the
52
+ // stream, with a big ol' efficient switch, but it's much nicer like this.
53
+ re.prototype.rewrite = function rewrite(tokens) {
54
+ this.tokens = tokens;
55
+ this.adjust_comments();
56
+ this.remove_leading_newlines();
57
+ this.remove_mid_expression_newlines();
58
+ this.move_commas_outside_outdents();
59
+ this.close_open_calls_and_indexes();
60
+ this.add_implicit_indentation();
61
+ this.add_implicit_parentheses();
62
+ this.ensure_balance(BALANCED_PAIRS);
63
+ this.rewrite_closing_parens();
64
+ return this.tokens;
65
+ };
66
+ // Rewrite the token stream, looking one token ahead and behind.
67
+ // Allow the return value of the block to tell us how many tokens to move
68
+ // forwards (or backwards) in the stream, to make sure we don't miss anything
69
+ // as the stream changes length under our feet.
70
+ re.prototype.scan_tokens = function scan_tokens(block) {
71
+ var i, move;
72
+ i = 0;
73
+ while (true) {
74
+ if (!(this.tokens[i])) {
75
+ break;
76
+ }
77
+ move = block(this.tokens[i - 1], this.tokens[i], this.tokens[i + 1], i);
78
+ i += move;
79
+ }
80
+ return true;
81
+ };
82
+ // Massage newlines and indentations so that comments don't have to be
83
+ // correctly indented, or appear on their own line.
84
+ re.prototype.adjust_comments = function adjust_comments() {
85
+ return this.scan_tokens((function(__this) {
86
+ var __func = function(prev, token, post, i) {
87
+ var after, before;
88
+ if (!(token[0] === 'COMMENT')) {
89
+ return 1;
90
+ }
91
+ before = this.tokens[i - 2];
92
+ after = this.tokens[i + 2];
93
+ if (before && after && ((before[0] === 'INDENT' && after[0] === 'OUTDENT') || (before[0] === 'OUTDENT' && after[0] === 'INDENT')) && before[1] === after[1]) {
94
+ this.tokens.splice(i + 2, 1);
95
+ this.tokens.splice(i - 2, 1);
96
+ return 0;
97
+ } else if (prev && prev[0] === 'TERMINATOR' && after && after[0] === 'INDENT') {
98
+ this.tokens.splice(i + 2, 1);
99
+ this.tokens[i - 1] = after;
100
+ return 1;
101
+ } else if (prev && prev[0] !== 'TERMINATOR' && prev[0] !== 'INDENT' && prev[0] !== 'OUTDENT') {
102
+ this.tokens.splice(i, 0, ['TERMINATOR', "\n", prev[2]]);
103
+ return 2;
104
+ } else {
105
+ return 1;
106
+ }
107
+ };
108
+ return (function() {
109
+ return __func.apply(__this, arguments);
110
+ });
111
+ })(this));
112
+ };
113
+ // Leading newlines would introduce an ambiguity in the grammar, so we
114
+ // dispatch them here.
115
+ re.prototype.remove_leading_newlines = function remove_leading_newlines() {
116
+ if (this.tokens[0][0] === 'TERMINATOR') {
117
+ return this.tokens.shift();
118
+ }
119
+ };
120
+ // Some blocks occur in the middle of expressions -- when we're expecting
121
+ // this, remove their trailing newlines.
122
+ re.prototype.remove_mid_expression_newlines = function remove_mid_expression_newlines() {
123
+ return this.scan_tokens((function(__this) {
124
+ var __func = function(prev, token, post, i) {
125
+ if (!(post && EXPRESSION_CLOSE.indexOf(post[0]) >= 0 && token[0] === 'TERMINATOR')) {
126
+ return 1;
127
+ }
128
+ this.tokens.splice(i, 1);
129
+ return 0;
130
+ };
131
+ return (function() {
132
+ return __func.apply(__this, arguments);
133
+ });
134
+ })(this));
135
+ };
136
+ // Make sure that we don't accidentally break trailing commas, which need
137
+ // to go on the outside of expression closers.
138
+ re.prototype.move_commas_outside_outdents = function move_commas_outside_outdents() {
139
+ return this.scan_tokens((function(__this) {
140
+ var __func = function(prev, token, post, i) {
141
+ if (token[0] === 'OUTDENT' && prev[0] === ',') {
142
+ this.tokens.splice(i, 1, token);
143
+ }
144
+ return 1;
145
+ };
146
+ return (function() {
147
+ return __func.apply(__this, arguments);
148
+ });
149
+ })(this));
150
+ };
151
+ // We've tagged the opening parenthesis of a method call, and the opening
152
+ // bracket of an indexing operation. Match them with their close.
153
+ re.prototype.close_open_calls_and_indexes = function close_open_calls_and_indexes() {
154
+ var brackets, parens;
155
+ parens = [0];
156
+ brackets = [0];
157
+ return this.scan_tokens((function(__this) {
158
+ var __func = function(prev, token, post, i) {
159
+ var _i;
160
+ if ((_i = token[0]) === 'CALL_START') {
161
+ parens.push(0);
162
+ } else if (_i === 'INDEX_START') {
163
+ brackets.push(0);
164
+ } else if (_i === '(') {
165
+ parens[parens.length - 1] += 1;
166
+ } else if (_i === '[') {
167
+ brackets[brackets.length - 1] += 1;
168
+ } else if (_i === ')') {
169
+ if (parens[parens.length - 1] === 0) {
170
+ parens.pop();
171
+ token[0] = 'CALL_END';
172
+ } else {
173
+ parens[parens.length - 1] -= 1;
174
+ }
175
+ } else if (_i === ']') {
176
+ if (brackets[brackets.length - 1] === 0) {
177
+ brackets.pop();
178
+ token[0] = 'INDEX_END';
179
+ } else {
180
+ brackets[brackets.length - 1] -= 1;
181
+ }
182
+ }
183
+ return 1;
184
+ };
185
+ return (function() {
186
+ return __func.apply(__this, arguments);
187
+ });
188
+ })(this));
189
+ };
190
+ // Methods may be optionally called without parentheses, for simple cases.
191
+ // Insert the implicit parentheses here, so that the parser doesn't have to
192
+ // deal with them.
193
+ re.prototype.add_implicit_parentheses = function add_implicit_parentheses() {
194
+ var stack;
195
+ stack = [0];
196
+ return this.scan_tokens((function(__this) {
197
+ var __func = function(prev, token, post, i) {
198
+ var _i, _j, _k, _l, idx, last, size, stack_pointer, tag, tmp;
199
+ tag = token[0];
200
+ if (tag === 'INDENT') {
201
+ stack.push(0);
202
+ }
203
+ if (tag === 'OUTDENT') {
204
+ last = stack.pop();
205
+ stack[stack.length - 1] += last;
206
+ }
207
+ if (IMPLICIT_END.indexOf(tag) >= 0 || !(typeof post !== "undefined" && post !== null)) {
208
+ if (tag === 'INDENT' && prev && IMPLICIT_BLOCK.indexOf(prev[0]) >= 0) {
209
+ return 1;
210
+ }
211
+ if (stack[stack.length - 1] > 0 || tag === 'INDENT') {
212
+ idx = tag === 'OUTDENT' ? i + 1 : i;
213
+ stack_pointer = tag === 'INDENT' ? 2 : 1;
214
+ _k = 0; _l = stack[stack.length - stack_pointer];
215
+ for (_j = 0, tmp=_k; (_k <= _l ? tmp < _l : tmp > _l); (_k <= _l ? tmp += 1 : tmp -= 1), _j++) {
216
+ this.tokens.splice(idx, 0, ['CALL_END', ')', token[2]]);
217
+ }
218
+ size = stack[stack.length - stack_pointer] + 1;
219
+ stack[stack.length - stack_pointer] = 0;
220
+ return size;
221
+ }
222
+ }
223
+ if (!(prev && IMPLICIT_FUNC.indexOf(prev[0]) >= 0 && IMPLICIT_CALL.indexOf(tag) >= 0)) {
224
+ return 1;
225
+ }
226
+ this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
227
+ stack[stack.length - 1] += 1;
228
+ return 2;
229
+ };
230
+ return (function() {
231
+ return __func.apply(__this, arguments);
232
+ });
233
+ })(this));
234
+ };
235
+ // Because our grammar is LALR(1), it can't handle some single-line
236
+ // expressions that lack ending delimiters. Use the lexer to add the implicit
237
+ // blocks, so it doesn't need to.
238
+ // ')' can close a single-line block, but we need to make sure it's balanced.
239
+ re.prototype.add_implicit_indentation = function add_implicit_indentation() {
240
+ return this.scan_tokens((function(__this) {
241
+ var __func = function(prev, token, post, i) {
242
+ var idx, insertion, parens, starter, tok;
243
+ if (!(SINGLE_LINERS.indexOf(token[0]) >= 0 && post[0] !== 'INDENT' && !(token[0] === 'ELSE' && post[0] === 'IF'))) {
244
+ return 1;
245
+ }
246
+ starter = token[0];
247
+ this.tokens.splice(i + 1, 0, ['INDENT', 2, token[2]]);
248
+ idx = i + 1;
249
+ parens = 0;
250
+ while (true) {
251
+ idx += 1;
252
+ tok = this.tokens[idx];
253
+ if ((!tok || (SINGLE_CLOSERS.indexOf(tok[0]) >= 0 && tok[1] !== ';') || (tok[0] === ')' && parens === 0)) && !(starter === 'ELSE' && tok[0] === 'ELSE')) {
254
+ insertion = this.tokens[idx - 1][0] === "," ? idx - 1 : idx;
255
+ this.tokens.splice(insertion, 0, ['OUTDENT', 2, token[2]]);
256
+ break;
257
+ }
258
+ if (tok[0] === '(') {
259
+ parens += 1;
260
+ }
261
+ if (tok[0] === ')') {
262
+ parens -= 1;
263
+ }
264
+ }
265
+ if (!(token[0] === 'THEN')) {
266
+ return 1;
267
+ }
268
+ this.tokens.splice(i, 1);
269
+ return 0;
270
+ };
271
+ return (function() {
272
+ return __func.apply(__this, arguments);
273
+ });
274
+ })(this));
275
+ };
276
+ // Ensure that all listed pairs of tokens are correctly balanced throughout
277
+ // the course of the token stream.
278
+ re.prototype.ensure_balance = function ensure_balance(pairs) {
279
+ var _i, _j, key, levels, unclosed, value;
280
+ levels = {};
281
+ this.scan_tokens((function(__this) {
282
+ var __func = function(prev, token, post, i) {
283
+ var _i, _j, _k, close, open;
284
+ _i = pairs;
285
+ for (_j = 0; _j < _i.length; _j++) {
286
+ pair = _i[_j];
287
+ _k = pair;
288
+ open = _k[0];
289
+ close = _k[1];
290
+ levels[open] = levels[open] || 0;
291
+ if (token[0] === open) {
292
+ levels[open] += 1;
293
+ }
294
+ if (token[0] === close) {
295
+ levels[open] -= 1;
296
+ }
297
+ if (levels[open] < 0) {
298
+ throw new Error("too many " + token[1]);
299
+ }
300
+ }
301
+ return 1;
302
+ };
303
+ return (function() {
304
+ return __func.apply(__this, arguments);
305
+ });
306
+ })(this));
307
+ unclosed = (function() {
308
+ _i = []; _j = levels;
309
+ for (key in _j) { if (__hasProp.call(_j, key)) {
310
+ value = _j[key];
311
+ if (value > 0) {
312
+ _i.push(key);
313
+ }
314
+ }}
315
+ return _i;
316
+ }).call(this);
317
+ if (unclosed.length) {
318
+ throw new Error("unclosed " + unclosed[0]);
319
+ }
320
+ };
321
+ // We'd like to support syntax like this:
322
+ // el.click((event) ->
323
+ // el.hide())
324
+ // In order to accomplish this, move outdents that follow closing parens
325
+ // inwards, safely. The steps to accomplish this are:
326
+ //
327
+ // 1. Check that all paired tokens are balanced and in order.
328
+ // 2. Rewrite the stream with a stack: if you see an '(' or INDENT, add it
329
+ // to the stack. If you see an ')' or OUTDENT, pop the stack and replace
330
+ // it with the inverse of what we've just popped.
331
+ // 3. Keep track of "debt" for tokens that we fake, to make sure we end
332
+ // up balanced in the end.
333
+ //
334
+ re.prototype.rewrite_closing_parens = function rewrite_closing_parens() {
335
+ var _i, debt, key, stack, val;
336
+ stack = [];
337
+ debt = {};
338
+ _i = INVERSES;
339
+ for (key in _i) { if (__hasProp.call(_i, key)) {
340
+ val = _i[key];
341
+ ((debt[key] = 0));
342
+ }}
343
+ return this.scan_tokens((function(__this) {
344
+ var __func = function(prev, token, post, i) {
345
+ var inv, match, mtag, tag;
346
+ tag = token[0];
347
+ inv = INVERSES[token[0]];
348
+ // Push openers onto the stack.
349
+ if (EXPRESSION_START.indexOf(tag) >= 0) {
350
+ stack.push(token);
351
+ return 1;
352
+ // The end of an expression, check stack and debt for a pair.
353
+ } else if (EXPRESSION_TAIL.indexOf(tag) >= 0) {
354
+ // If the tag is already in our debt, swallow it.
355
+ if (debt[inv] > 0) {
356
+ debt[inv] -= 1;
357
+ this.tokens.splice(i, 1);
358
+ return 0;
359
+ } else {
360
+ // Pop the stack of open delimiters.
361
+ match = stack.pop();
362
+ mtag = match[0];
363
+ // Continue onwards if it's the expected tag.
364
+ if (tag === INVERSES[mtag]) {
365
+ return 1;
366
+ } else {
367
+ // Unexpected close, insert correct close, adding to the debt.
368
+ debt[mtag] += 1;
369
+ val = mtag === 'INDENT' ? match[1] : INVERSES[mtag];
370
+ this.tokens.splice(i, 0, [INVERSES[mtag], val]);
371
+ return 1;
372
+ }
373
+ }
374
+ } else {
375
+ return 1;
376
+ }
377
+ };
378
+ return (function() {
379
+ return __func.apply(__this, arguments);
380
+ });
381
+ })(this));
382
+ };
383
+ })();
@@ -0,0 +1,114 @@
1
+ (function(){
2
+ var Scope;
3
+ var __hasProp = Object.prototype.hasOwnProperty;
4
+ if (!((typeof process !== "undefined" && process !== null))) {
5
+ this.exports = this;
6
+ }
7
+ // Scope objects form a tree corresponding to the shape of the function
8
+ // definitions present in the script. They provide lexical scope, to determine
9
+ // whether a variable has been seen before or if it needs to be declared.
10
+ //
11
+ // Initialize a scope with its parent, for lookups up the chain,
12
+ // as well as the Expressions body where it should declare its variables,
13
+ // and the function that it wraps.
14
+ Scope = (exports.Scope = function Scope(parent, expressions, method) {
15
+ var _a;
16
+ _a = [parent, expressions, method];
17
+ this.parent = _a[0];
18
+ this.expressions = _a[1];
19
+ this.method = _a[2];
20
+ this.variables = {};
21
+ this.temp_var = this.parent ? this.parent.temp_var : '_a';
22
+ return this;
23
+ });
24
+ // Look up a variable in lexical scope, or declare it if not found.
25
+ Scope.prototype.find = function find(name) {
26
+ if (this.check(name)) {
27
+ return true;
28
+ }
29
+ this.variables[name] = 'var';
30
+ return false;
31
+ };
32
+ // Define a local variable as originating from a parameter in current scope
33
+ // -- no var required.
34
+ Scope.prototype.parameter = function parameter(name) {
35
+ return this.variables[name] = 'param';
36
+ };
37
+ // Just check to see if a variable has already been declared.
38
+ Scope.prototype.check = function check(name) {
39
+ if (this.variables[name]) {
40
+ return true;
41
+ }
42
+ return !!(this.parent && this.parent.check(name));
43
+ };
44
+ // You can reset a found variable on the immediate scope.
45
+ Scope.prototype.reset = function reset(name) {
46
+ return delete this.variables[name];
47
+ };
48
+ // Find an available, short, name for a compiler-generated variable.
49
+ Scope.prototype.free_variable = function free_variable() {
50
+ var ordinal;
51
+ while (this.check(this.temp_var)) {
52
+ ordinal = 1 + parseInt(this.temp_var.substr(1), 36);
53
+ this.temp_var = '_' + ordinal.toString(36).replace(/\d/g, 'a');
54
+ }
55
+ this.variables[this.temp_var] = 'var';
56
+ return this.temp_var;
57
+ };
58
+ // Ensure that an assignment is made at the top of scope (or top-level
59
+ // scope, if requested).
60
+ Scope.prototype.assign = function assign(name, value, top_level) {
61
+ if (top_level && this.parent) {
62
+ return this.parent.assign(name, value, top_level);
63
+ }
64
+ return this.variables[name] = {
65
+ value: value,
66
+ assigned: true
67
+ };
68
+ };
69
+ // Does this scope reference any variables that need to be declared in the
70
+ // given function body?
71
+ Scope.prototype.has_declarations = function has_declarations(body) {
72
+ return body === this.expressions && this.declared_variables().length;
73
+ };
74
+ // Does this scope reference any assignments that need to be declared at the
75
+ // top of the given function body?
76
+ Scope.prototype.has_assignments = function has_assignments(body) {
77
+ return body === this.expressions && this.assigned_variables().length;
78
+ };
79
+ // Return the list of variables first declared in current scope.
80
+ Scope.prototype.declared_variables = function declared_variables() {
81
+ var _a, _b, key, val;
82
+ return (function() {
83
+ _a = []; _b = this.variables;
84
+ for (key in _b) { if (__hasProp.call(_b, key)) {
85
+ val = _b[key];
86
+ if (val === 'var') {
87
+ _a.push(key);
88
+ }
89
+ }}
90
+ return _a;
91
+ }).call(this).sort();
92
+ };
93
+ // Return the list of variables that are supposed to be assigned at the top
94
+ // of scope.
95
+ Scope.prototype.assigned_variables = function assigned_variables() {
96
+ var _a, _b, key, val;
97
+ _a = []; _b = this.variables;
98
+ for (key in _b) { if (__hasProp.call(_b, key)) {
99
+ val = _b[key];
100
+ if (val.assigned) {
101
+ _a.push(key + ' = ' + val.value);
102
+ }
103
+ }}
104
+ return _a;
105
+ };
106
+ // Compile the string representing all of the declared variables for this scope.
107
+ Scope.prototype.compiled_declarations = function compiled_declarations() {
108
+ return this.declared_variables().join(', ');
109
+ };
110
+ // Compile the string performing all of the variable assignments for this scope.
111
+ Scope.prototype.compiled_assignments = function compiled_assignments() {
112
+ return this.assigned_variables().join(', ');
113
+ };
114
+ })();
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "coffee-script",
3
+ "description": "Unfancy JavaScript",
4
+ "keywords": ["javascript", "language"],
5
+ "author": "Jeremy Ashkenas",
6
+ "version": "0.5.1"
7
+ }
@@ -0,0 +1,45 @@
1
+ # `cake` is a simplified version of Make (Rake, Jake) for CoffeeScript.
2
+
3
+ fs: require 'fs'
4
+ path: require 'path'
5
+ coffee: require 'coffee-script'
6
+
7
+ tasks: {}
8
+
9
+ no_such_task: (task) ->
10
+ process.stdio.writeError('No such task: "' + task + '"\n')
11
+ process.exit(1)
12
+
13
+ # Mixin the Cake functionality.
14
+ process.mixin {
15
+
16
+ # Define a task with a name, a description, and the action itself.
17
+ task: (name, description, action) ->
18
+ tasks[name]: {name: name, description: description, action: action}
19
+
20
+ # Invoke another task in the Cakefile.
21
+ invoke: (name) ->
22
+ no_such_task name unless tasks[name]
23
+ tasks[name].action()
24
+ }
25
+
26
+ # Display the list of Cake tasks.
27
+ print_tasks: ->
28
+ for name, task of tasks
29
+ spaces: 20 - name.length
30
+ spaces: if spaces > 0 then (' ' for i in [0..spaces]).join('') else ''
31
+ puts "cake " + name + spaces + ' # ' + task.description
32
+
33
+ # Running `cake` runs the tasks you pass asynchronously (node-style), or
34
+ # prints them out, with no arguments.
35
+ exports.run: ->
36
+ path.exists 'Cakefile', (exists) ->
37
+ throw new Error('Cakefile not found in ' + process.cwd()) unless exists
38
+ args: process.ARGV[2...process.ARGV.length]
39
+ fs.readFile 'Cakefile', (err, source) ->
40
+ eval coffee.compile source
41
+ return print_tasks() unless args.length
42
+ for arg in args
43
+ no_such_task arg unless tasks[arg]
44
+ tasks[arg].action()
45
+
@@ -0,0 +1,45 @@
1
+ # Set up for both the browser and the server.
2
+ if process?
3
+ process.mixin require 'nodes'
4
+ path: require 'path'
5
+ lexer: new (require('lexer').Lexer)()
6
+ parser: require('parser').parser
7
+ else
8
+ lexer: new Lexer()
9
+ parser: exports.parser
10
+ this.exports: this.CoffeeScript: {}
11
+
12
+ # Thin wrapper for Jison compatibility around the real lexer.
13
+ parser.lexer: {
14
+ lex: ->
15
+ token: @tokens[@pos] or [""]
16
+ @pos += 1
17
+ this.yylineno: token[2]
18
+ this.yytext: token[1]
19
+ token[0]
20
+ setInput: (tokens) ->
21
+ @tokens: tokens
22
+ @pos: 0
23
+ upcomingInput: -> ""
24
+ showPosition: -> @pos
25
+ }
26
+
27
+ exports.VERSION: '0.5.1'
28
+
29
+ # Compile CoffeeScript to JavaScript, using the Coffee/Jison compiler.
30
+ exports.compile: (code, options) ->
31
+ (parser.parse lexer.tokenize code).compile(options)
32
+
33
+ # Just the tokens.
34
+ exports.tokenize: (code) ->
35
+ lexer.tokenize code
36
+
37
+ # Just the nodes.
38
+ exports.tree: (code) ->
39
+ parser.parse lexer.tokenize code
40
+
41
+ # Pretty-print a token stream.
42
+ exports.print_tokens: (tokens) ->
43
+ strings: for token in tokens
44
+ '[' + token[0] + ' ' + token[1].toString().replace(/\n/, '\\n') + ']'
45
+ puts strings.join(' ')