spade-packager 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (316) hide show
  1. data/.gitignore +2 -0
  2. data/.gitmodules +6 -0
  3. data/bin/spadepkg +8 -0
  4. data/lib/libgems_ext.rb +8 -0
  5. data/lib/libgems_ext/config_file.rb +33 -0
  6. data/lib/libgems_ext/dependency_installer.rb +150 -0
  7. data/lib/libgems_ext/installer.rb +39 -0
  8. data/lib/libgems_ext/libgems.rb +39 -0
  9. data/lib/libgems_ext/spec_fetcher.rb +11 -0
  10. data/lib/spade-packager.rb +1 -0
  11. data/lib/spade/packager.rb +18 -0
  12. data/lib/spade/packager/cli.rb +9 -0
  13. data/lib/spade/packager/cli/base.rb +196 -0
  14. data/lib/spade/packager/cli/owner.rb +46 -0
  15. data/lib/spade/packager/cli/project_generator.rb +117 -0
  16. data/lib/spade/packager/credentials.rb +38 -0
  17. data/lib/spade/packager/local.rb +50 -0
  18. data/lib/spade/packager/package.rb +160 -0
  19. data/lib/spade/packager/remote.rb +98 -0
  20. data/lib/spade/packager/repository.rb +18 -0
  21. data/lib/spade/packager/version.rb +5 -0
  22. data/packages/coffee-script/.gitignore +8 -0
  23. data/packages/coffee-script/.npmignore +11 -0
  24. data/packages/coffee-script/Cakefile +229 -0
  25. data/packages/coffee-script/LICENSE +22 -0
  26. data/packages/coffee-script/README +47 -0
  27. data/packages/coffee-script/Rakefile +78 -0
  28. data/packages/coffee-script/bin/cake +7 -0
  29. data/packages/coffee-script/bin/coffee +7 -0
  30. data/packages/coffee-script/documentation/coffee/aliases.coffee +11 -0
  31. data/packages/coffee-script/documentation/coffee/array_comprehensions.coffee +2 -0
  32. data/packages/coffee-script/documentation/coffee/block_comment.coffee +6 -0
  33. data/packages/coffee-script/documentation/coffee/cake_tasks.coffee +9 -0
  34. data/packages/coffee-script/documentation/coffee/classes.coffee +25 -0
  35. data/packages/coffee-script/documentation/coffee/comparisons.coffee +5 -0
  36. data/packages/coffee-script/documentation/coffee/conditionals.coffee +13 -0
  37. data/packages/coffee-script/documentation/coffee/default_args.coffee +8 -0
  38. data/packages/coffee-script/documentation/coffee/do.coffee +4 -0
  39. data/packages/coffee-script/documentation/coffee/embedded.coffee +5 -0
  40. data/packages/coffee-script/documentation/coffee/existence.coffee +10 -0
  41. data/packages/coffee-script/documentation/coffee/expressions.coffee +9 -0
  42. data/packages/coffee-script/documentation/coffee/expressions_assignment.coffee +3 -0
  43. data/packages/coffee-script/documentation/coffee/expressions_comprehension.coffee +3 -0
  44. data/packages/coffee-script/documentation/coffee/expressions_try.coffee +7 -0
  45. data/packages/coffee-script/documentation/coffee/fat_arrow.coffee +6 -0
  46. data/packages/coffee-script/documentation/coffee/functions.coffee +2 -0
  47. data/packages/coffee-script/documentation/coffee/heredocs.coffee +7 -0
  48. data/packages/coffee-script/documentation/coffee/heregexes.coffee +11 -0
  49. data/packages/coffee-script/documentation/coffee/interpolation.coffee +6 -0
  50. data/packages/coffee-script/documentation/coffee/multiple_return_values.coffee +7 -0
  51. data/packages/coffee-script/documentation/coffee/object_comprehensions.coffee +4 -0
  52. data/packages/coffee-script/documentation/coffee/object_extraction.coffee +13 -0
  53. data/packages/coffee-script/documentation/coffee/objects_and_arrays.coffee +19 -0
  54. data/packages/coffee-script/documentation/coffee/objects_reserved.coffee +5 -0
  55. data/packages/coffee-script/documentation/coffee/overview.coffee +28 -0
  56. data/packages/coffee-script/documentation/coffee/parallel_assignment.coffee +6 -0
  57. data/packages/coffee-script/documentation/coffee/patterns_and_splats.coffee +7 -0
  58. data/packages/coffee-script/documentation/coffee/prototypes.coffee +3 -0
  59. data/packages/coffee-script/documentation/coffee/range_comprehensions.coffee +2 -0
  60. data/packages/coffee-script/documentation/coffee/scope.coffee +5 -0
  61. data/packages/coffee-script/documentation/coffee/slices.coffee +7 -0
  62. data/packages/coffee-script/documentation/coffee/soaks.coffee +1 -0
  63. data/packages/coffee-script/documentation/coffee/splats.coffee +27 -0
  64. data/packages/coffee-script/documentation/coffee/splices.coffee +5 -0
  65. data/packages/coffee-script/documentation/coffee/strings.coffee +8 -0
  66. data/packages/coffee-script/documentation/coffee/switch.coffee +10 -0
  67. data/packages/coffee-script/documentation/coffee/try.coffee +8 -0
  68. data/packages/coffee-script/documentation/coffee/while.coffee +10 -0
  69. data/packages/coffee-script/documentation/css/docs.css +374 -0
  70. data/packages/coffee-script/documentation/css/idle.css +64 -0
  71. data/packages/coffee-script/documentation/docs/browser.html +25 -0
  72. data/packages/coffee-script/documentation/docs/cake.html +43 -0
  73. data/packages/coffee-script/documentation/docs/coffee-script.html +51 -0
  74. data/packages/coffee-script/documentation/docs/command.html +161 -0
  75. data/packages/coffee-script/documentation/docs/docco.css +186 -0
  76. data/packages/coffee-script/documentation/docs/grammar.html +399 -0
  77. data/packages/coffee-script/documentation/docs/helpers.html +31 -0
  78. data/packages/coffee-script/documentation/docs/index.html +3 -0
  79. data/packages/coffee-script/documentation/docs/lexer.html +490 -0
  80. data/packages/coffee-script/documentation/docs/nodes.html +1338 -0
  81. data/packages/coffee-script/documentation/docs/optparse.html +78 -0
  82. data/packages/coffee-script/documentation/docs/repl.html +24 -0
  83. data/packages/coffee-script/documentation/docs/rewriter.html +251 -0
  84. data/packages/coffee-script/documentation/docs/scope.html +54 -0
  85. data/packages/coffee-script/documentation/docs/underscore.html +295 -0
  86. data/packages/coffee-script/documentation/images/background.png +0 -0
  87. data/packages/coffee-script/documentation/images/banding.png +0 -0
  88. data/packages/coffee-script/documentation/images/button_bg.png +0 -0
  89. data/packages/coffee-script/documentation/images/button_bg_dark.gif +0 -0
  90. data/packages/coffee-script/documentation/images/button_bg_green.gif +0 -0
  91. data/packages/coffee-script/documentation/images/favicon.ico +0 -0
  92. data/packages/coffee-script/documentation/images/logo.png +0 -0
  93. data/packages/coffee-script/documentation/images/screenshadow.png +0 -0
  94. data/packages/coffee-script/documentation/index.html.erb +1607 -0
  95. data/packages/coffee-script/documentation/js/aliases.js +17 -0
  96. data/packages/coffee-script/documentation/js/array_comprehensions.js +6 -0
  97. data/packages/coffee-script/documentation/js/block_comment.js +4 -0
  98. data/packages/coffee-script/documentation/js/cake_tasks.js +10 -0
  99. data/packages/coffee-script/documentation/js/classes.js +44 -0
  100. data/packages/coffee-script/documentation/js/comparisons.js +3 -0
  101. data/packages/coffee-script/documentation/js/conditionals.js +12 -0
  102. data/packages/coffee-script/documentation/js/default_args.js +7 -0
  103. data/packages/coffee-script/documentation/js/do.js +10 -0
  104. data/packages/coffee-script/documentation/js/embedded.js +4 -0
  105. data/packages/coffee-script/documentation/js/existence.js +6 -0
  106. data/packages/coffee-script/documentation/js/expressions.js +15 -0
  107. data/packages/coffee-script/documentation/js/expressions_assignment.js +2 -0
  108. data/packages/coffee-script/documentation/js/expressions_comprehension.js +9 -0
  109. data/packages/coffee-script/documentation/js/expressions_try.js +7 -0
  110. data/packages/coffee-script/documentation/js/fat_arrow.js +9 -0
  111. data/packages/coffee-script/documentation/js/functions.js +7 -0
  112. data/packages/coffee-script/documentation/js/heredocs.js +2 -0
  113. data/packages/coffee-script/documentation/js/heregexes.js +2 -0
  114. data/packages/coffee-script/documentation/js/interpolation.js +4 -0
  115. data/packages/coffee-script/documentation/js/multiple_return_values.js +5 -0
  116. data/packages/coffee-script/documentation/js/object_comprehensions.js +15 -0
  117. data/packages/coffee-script/documentation/js/object_extraction.js +10 -0
  118. data/packages/coffee-script/documentation/js/objects_and_arrays.js +17 -0
  119. data/packages/coffee-script/documentation/js/objects_reserved.js +4 -0
  120. data/packages/coffee-script/documentation/js/overview.js +35 -0
  121. data/packages/coffee-script/documentation/js/parallel_assignment.js +4 -0
  122. data/packages/coffee-script/documentation/js/patterns_and_splats.js +4 -0
  123. data/packages/coffee-script/documentation/js/prototypes.js +3 -0
  124. data/packages/coffee-script/documentation/js/range_comprehensions.js +9 -0
  125. data/packages/coffee-script/documentation/js/scope.js +8 -0
  126. data/packages/coffee-script/documentation/js/slices.js +4 -0
  127. data/packages/coffee-script/documentation/js/soaks.js +2 -0
  128. data/packages/coffee-script/documentation/js/splats.js +15 -0
  129. data/packages/coffee-script/documentation/js/splices.js +3 -0
  130. data/packages/coffee-script/documentation/js/strings.js +2 -0
  131. data/packages/coffee-script/documentation/js/switch.js +23 -0
  132. data/packages/coffee-script/documentation/js/try.js +8 -0
  133. data/packages/coffee-script/documentation/js/while.js +18 -0
  134. data/packages/coffee-script/documentation/vendor/jquery-1.4.2.js +6240 -0
  135. data/packages/coffee-script/examples/beautiful_code/binary_search.coffee +16 -0
  136. data/packages/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +13 -0
  137. data/packages/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +34 -0
  138. data/packages/coffee-script/examples/blocks.coffee +54 -0
  139. data/packages/coffee-script/examples/code.coffee +167 -0
  140. data/packages/coffee-script/examples/computer_science/README +4 -0
  141. data/packages/coffee-script/examples/computer_science/binary_search.coffee +25 -0
  142. data/packages/coffee-script/examples/computer_science/bubble_sort.coffee +11 -0
  143. data/packages/coffee-script/examples/computer_science/linked_list.coffee +108 -0
  144. data/packages/coffee-script/examples/computer_science/luhn_algorithm.coffee +36 -0
  145. data/packages/coffee-script/examples/computer_science/merge_sort.coffee +19 -0
  146. data/packages/coffee-script/examples/computer_science/selection_sort.coffee +23 -0
  147. data/packages/coffee-script/examples/poignant.coffee +181 -0
  148. data/packages/coffee-script/examples/potion.coffee +206 -0
  149. data/packages/coffee-script/examples/underscore.coffee +682 -0
  150. data/packages/coffee-script/examples/web_server.coffee +12 -0
  151. data/packages/coffee-script/extras/EXTRAS +7 -0
  152. data/packages/coffee-script/extras/coffee-script.js +8 -0
  153. data/packages/coffee-script/extras/jsl.conf +44 -0
  154. data/packages/coffee-script/index.html +2515 -0
  155. data/packages/coffee-script/lib/browser.js +52 -0
  156. data/packages/coffee-script/lib/cake.js +76 -0
  157. data/packages/coffee-script/lib/coffee-script.js +82 -0
  158. data/packages/coffee-script/lib/command.js +263 -0
  159. data/packages/coffee-script/lib/grammar.js +581 -0
  160. data/packages/coffee-script/lib/helpers.js +66 -0
  161. data/packages/coffee-script/lib/index.js +8 -0
  162. data/packages/coffee-script/lib/lexer.js +633 -0
  163. data/packages/coffee-script/lib/nodes.js +2165 -0
  164. data/packages/coffee-script/lib/optparse.js +111 -0
  165. data/packages/coffee-script/lib/parser.js +649 -0
  166. data/packages/coffee-script/lib/repl.js +42 -0
  167. data/packages/coffee-script/lib/rewriter.js +353 -0
  168. data/packages/coffee-script/lib/scope.js +120 -0
  169. data/packages/coffee-script/lib/spade-format.js +45 -0
  170. data/packages/coffee-script/package.json +26 -0
  171. data/packages/coffee-script/src/browser.coffee +43 -0
  172. data/packages/coffee-script/src/cake.coffee +69 -0
  173. data/packages/coffee-script/src/coffee-script.coffee +92 -0
  174. data/packages/coffee-script/src/command.coffee +214 -0
  175. data/packages/coffee-script/src/grammar.coffee +590 -0
  176. data/packages/coffee-script/src/helpers.coffee +56 -0
  177. data/packages/coffee-script/src/index.coffee +2 -0
  178. data/packages/coffee-script/src/lexer.coffee +653 -0
  179. data/packages/coffee-script/src/nodes.coffee +1754 -0
  180. data/packages/coffee-script/src/optparse.coffee +99 -0
  181. data/packages/coffee-script/src/repl.coffee +42 -0
  182. data/packages/coffee-script/src/rewriter.coffee +326 -0
  183. data/packages/coffee-script/src/scope.coffee +94 -0
  184. data/packages/coffee-script/test/arguments.coffee +127 -0
  185. data/packages/coffee-script/test/assignment.coffee +98 -0
  186. data/packages/coffee-script/test/break.coffee +18 -0
  187. data/packages/coffee-script/test/comments.coffee +201 -0
  188. data/packages/coffee-script/test/conditionals.coffee +181 -0
  189. data/packages/coffee-script/test/exception_handling.coffee +90 -0
  190. data/packages/coffee-script/test/helpers.coffee +96 -0
  191. data/packages/coffee-script/test/importing.coffee +18 -0
  192. data/packages/coffee-script/test/operators.coffee +225 -0
  193. data/packages/coffee-script/test/ranges_slices_and_splices.coffee +186 -0
  194. data/packages/coffee-script/test/regular_expressions.coffee +56 -0
  195. data/packages/coffee-script/test/test.html +123 -0
  196. data/packages/coffee-script/test/test_chaining.coffee +77 -0
  197. data/packages/coffee-script/test/test_classes.coffee +372 -0
  198. data/packages/coffee-script/test/test_compilation.coffee +26 -0
  199. data/packages/coffee-script/test/test_comprehensions.coffee +318 -0
  200. data/packages/coffee-script/test/test_existence.coffee +165 -0
  201. data/packages/coffee-script/test/test_functions.coffee +379 -0
  202. data/packages/coffee-script/test/test_heredocs.coffee +111 -0
  203. data/packages/coffee-script/test/test_literals.coffee +270 -0
  204. data/packages/coffee-script/test/test_option_parser.coffee +27 -0
  205. data/packages/coffee-script/test/test_pattern_matching.coffee +162 -0
  206. data/packages/coffee-script/test/test_returns.coffee +63 -0
  207. data/packages/coffee-script/test/test_splats.coffee +102 -0
  208. data/packages/coffee-script/test/test_strings.coffee +118 -0
  209. data/packages/coffee-script/test/test_switch.coffee +103 -0
  210. data/packages/coffee-script/test/test_while.coffee +71 -0
  211. data/packages/ivory/LICENSE.txt +1 -0
  212. data/packages/ivory/README.md +19 -0
  213. data/packages/ivory/lib/buffer.js +111 -0
  214. data/packages/ivory/lib/events.js +137 -0
  215. data/packages/ivory/lib/fs.js +266 -0
  216. data/packages/ivory/lib/main.js +13 -0
  217. data/packages/ivory/lib/path.js +158 -0
  218. data/packages/ivory/lib/ruby/buffer.rb +145 -0
  219. data/packages/ivory/lib/ruby/constants.rb +585 -0
  220. data/packages/ivory/lib/ruby/events.rb +32 -0
  221. data/packages/ivory/lib/ruby/fs.rb +245 -0
  222. data/packages/ivory/lib/ruby/process.rb +28 -0
  223. data/packages/ivory/lib/stream.js +115 -0
  224. data/packages/ivory/lib/util.js +414 -0
  225. data/packages/ivory/package.json +11 -0
  226. data/packages/ivory/spade-boot.js +78 -0
  227. data/packages/jquery/main.js +7179 -0
  228. data/packages/jquery/package.json +10 -0
  229. data/packages/json/lib/main.js +14 -0
  230. data/packages/json/package.json +8 -0
  231. data/packages/lproj/README.md +77 -0
  232. data/packages/lproj/examples/demo-app/en.lproj/localized.strings +2 -0
  233. data/packages/lproj/examples/demo-app/fr.lproj/localized.strings +3 -0
  234. data/packages/lproj/examples/demo-app/index.html +8 -0
  235. data/packages/lproj/examples/demo-app/lib/main.js +7 -0
  236. data/packages/lproj/examples/demo-app/package.json +9 -0
  237. data/packages/lproj/lib/main.js +78 -0
  238. data/packages/lproj/lib/strings-format.js +6 -0
  239. data/packages/lproj/package.json +9 -0
  240. data/packages/optparse/README.md +161 -0
  241. data/packages/optparse/TODO +1 -0
  242. data/packages/optparse/examples/browser-test.html +75 -0
  243. data/packages/optparse/examples/nodejs-test.js +90 -0
  244. data/packages/optparse/lib/optparse.js +309 -0
  245. data/packages/optparse/package.json +13 -0
  246. data/packages/optparse/seed.yml +5 -0
  247. data/packages/text/lib/main.js +8 -0
  248. data/packages/text/package.json +9 -0
  249. data/packages/web-file/README.md +7 -0
  250. data/packages/web-file/lib/errors.js +32 -0
  251. data/packages/web-file/lib/file-reader.js +10 -0
  252. data/packages/web-file/lib/file-system.js +234 -0
  253. data/packages/web-file/lib/file-writer.js +10 -0
  254. data/packages/web-file/lib/file.js +9 -0
  255. data/packages/web-file/lib/main.js +34 -0
  256. data/packages/web-file/lib/platform.js +25 -0
  257. data/packages/web-file/lib/ruby/file.rb +252 -0
  258. data/packages/web-file/lib/ruby/file_reader.rb +69 -0
  259. data/packages/web-file/lib/ruby/file_system.rb +134 -0
  260. data/packages/web-file/lib/ruby/file_writer.rb +78 -0
  261. data/packages/web-file/package.json +12 -0
  262. data/packages/web-typed-array/README.md +7 -0
  263. data/packages/web-typed-array/lib/array-buffer-view.js +9 -0
  264. data/packages/web-typed-array/lib/array-buffer.js +7 -0
  265. data/packages/web-typed-array/lib/main.js +33 -0
  266. data/packages/web-typed-array/lib/platform.js +20 -0
  267. data/packages/web-typed-array/lib/ruby/array_buffer.rb +31 -0
  268. data/packages/web-typed-array/lib/ruby/array_buffer_view.rb +130 -0
  269. data/packages/web-typed-array/lib/ruby/typed_array.rb +133 -0
  270. data/packages/web-typed-array/lib/typed-array.js +26 -0
  271. data/packages/web-typed-array/package.json +9 -0
  272. data/spade-packager.gemspec +39 -0
  273. data/spec/cli/build_spec.rb +57 -0
  274. data/spec/cli/install_spec.rb +119 -0
  275. data/spec/cli/installed_spec.rb +55 -0
  276. data/spec/cli/list_spec.rb +74 -0
  277. data/spec/cli/login_spec.rb +75 -0
  278. data/spec/cli/new_spec.rb +5 -0
  279. data/spec/cli/owner_spec.rb +114 -0
  280. data/spec/cli/push_spec.rb +73 -0
  281. data/spec/cli/uninstall_spec.rb +58 -0
  282. data/spec/cli/unpack_spec.rb +72 -0
  283. data/spec/cli/unyank_spec.rb +73 -0
  284. data/spec/cli/yank_spec.rb +73 -0
  285. data/spec/credentials_spec.rb +23 -0
  286. data/spec/fixtures/badrake-0.8.7.spd +0 -0
  287. data/spec/fixtures/builder-3.0.0.spd +0 -0
  288. data/spec/fixtures/bundler-1.1.pre.spd +0 -0
  289. data/spec/fixtures/coffee-1.0.1.pre.spd +0 -0
  290. data/spec/fixtures/core-test-0.4.3.spd +0 -0
  291. data/spec/fixtures/core-test/bin/cot +3 -0
  292. data/spec/fixtures/core-test/lib/main.js +1 -0
  293. data/spec/fixtures/core-test/resources/runner.css +0 -0
  294. data/spec/fixtures/core-test/tests/test.js +1 -0
  295. data/spec/fixtures/highline-1.6.1.spd +0 -0
  296. data/spec/fixtures/ivory-0.0.1.spd +0 -0
  297. data/spec/fixtures/jquery-1.4.3.spd +0 -0
  298. data/spec/fixtures/optparse-1.0.1.spd +0 -0
  299. data/spec/fixtures/package.json +30 -0
  300. data/spec/fixtures/rake-0.8.6.spd +0 -0
  301. data/spec/fixtures/rake-0.8.7.spd +0 -0
  302. data/spec/gauntlet_spec.rb +27 -0
  303. data/spec/package_spec.rb +267 -0
  304. data/spec/spec_helper.rb +32 -0
  305. data/spec/support/cli.rb +103 -0
  306. data/spec/support/fake.rb +48 -0
  307. data/spec/support/fake_gem_server.rb +67 -0
  308. data/spec/support/fake_gemcutter.rb +50 -0
  309. data/spec/support/matchers.rb +32 -0
  310. data/spec/support/path.rb +61 -0
  311. data/templates/project/LICENSE +19 -0
  312. data/templates/project/README.md +21 -0
  313. data/templates/project/lib/main.js +9 -0
  314. data/templates/project/project.json +31 -0
  315. data/templates/project/tests/main-test.js +8 -0
  316. metadata +484 -0
@@ -0,0 +1,56 @@
1
+ # This file contains the common helper functions that we'd like to share among
2
+ # the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten
3
+ # arrays, count characters, that sort of thing.
4
+
5
+ # Peek at the beginning of a given string to see if it matches a sequence.
6
+ exports.starts = (string, literal, start) ->
7
+ literal is string.substr start, literal.length
8
+
9
+ # Peek at the end of a given string to see if it matches a sequence.
10
+ exports.ends = (string, literal, back) ->
11
+ len = literal.length
12
+ literal is string.substr string.length - len - (back or 0), len
13
+
14
+ # Trim out all falsy values from an array.
15
+ exports.compact = (array) ->
16
+ item for item in array when item
17
+
18
+ # Count the number of occurrences of a string in a string.
19
+ exports.count = (string, substr) ->
20
+ num = pos = 0
21
+ return 1/0 unless substr.length
22
+ num++ while pos = 1 + string.indexOf substr, pos
23
+ num
24
+
25
+ # Merge objects, returning a fresh copy with attributes from both sides.
26
+ # Used every time `Base#compile` is called, to allow properties in the
27
+ # options hash to propagate down the tree without polluting other branches.
28
+ exports.merge = (options, overrides) ->
29
+ extend (extend {}, options), overrides
30
+
31
+ # Extend a source object with the properties of another object (shallow copy).
32
+ extend = exports.extend = (object, properties) ->
33
+ for key, val of properties
34
+ object[key] = val
35
+ object
36
+
37
+ # Return a flattened version of an array.
38
+ # Handy for getting a list of `children` from the nodes.
39
+ exports.flatten = flatten = (array) ->
40
+ flattened = []
41
+ for element in array
42
+ if element instanceof Array
43
+ flattened = flattened.concat flatten element
44
+ else
45
+ flattened.push element
46
+ flattened
47
+
48
+ # Delete a key from an object, returning the value. Useful when a node is
49
+ # looking for a particular method in an options hash.
50
+ exports.del = (obj, key) ->
51
+ val = obj[key]
52
+ delete obj[key]
53
+ val
54
+
55
+ # Gets the last item of an array(-like) object.
56
+ exports.last = (array, back) -> array[array.length - (back or 0) - 1]
@@ -0,0 +1,2 @@
1
+ # Loader for CoffeeScript as a Node.js library.
2
+ exports[key] = val for key, val of require './coffee-script'
@@ -0,0 +1,653 @@
1
+ # The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
2
+ # matches against the beginning of the source code. When a match is found,
3
+ # a token is produced, we consume the match, and start again. Tokens are in the
4
+ # form:
5
+ #
6
+ # [tag, value, lineNumber]
7
+ #
8
+ # Which is a format that can be fed directly into [Jison](http://github.com/zaach/jison).
9
+
10
+ {Rewriter} = require './rewriter'
11
+
12
+ # Import the helpers we need.
13
+ {count, starts, compact, last} = require './helpers'
14
+
15
+ # The Lexer Class
16
+ # ---------------
17
+
18
+ # The Lexer class reads a stream of CoffeeScript and divvies it up into tagged
19
+ # tokens. Some potential ambiguity in the grammar has been avoided by
20
+ # pushing some extra smarts into the Lexer.
21
+ exports.Lexer = class Lexer
22
+
23
+ # **tokenize** is the Lexer's main method. Scan by attempting to match tokens
24
+ # one at a time, using a regular expression anchored at the start of the
25
+ # remaining code, or a custom recursive token-matching method
26
+ # (for interpolations). When the next token has been recorded, we move forward
27
+ # within the code past the token, and begin again.
28
+ #
29
+ # Each tokenizing method is responsible for returning the number of characters
30
+ # it has consumed.
31
+ #
32
+ # Before returning the token stream, run it through the [Rewriter](rewriter.html)
33
+ # unless explicitly asked not to.
34
+ tokenize: (code, opts = {}) ->
35
+ code = code.replace(/\r/g, '').replace TRAILING_SPACES, ''
36
+
37
+ @code = code # The remainder of the source code.
38
+ @line = opts.line or 0 # The current line.
39
+ @indent = 0 # The current indentation level.
40
+ @indebt = 0 # The over-indentation at the current level.
41
+ @outdebt = 0 # The under-outdentation at the current level.
42
+ @indents = [] # The stack of all current indentation levels.
43
+ @tokens = [] # Stream of parsed tokens in the form `['TYPE', value, line]`.
44
+
45
+ # At every position, run through this list of attempted matches,
46
+ # short-circuiting if any of them succeed. Their order determines precedence:
47
+ # `@literalToken` is the fallback catch-all.
48
+ i = 0
49
+ while @chunk = code.slice i
50
+ i += @identifierToken() or
51
+ @commentToken() or
52
+ @whitespaceToken() or
53
+ @lineToken() or
54
+ @heredocToken() or
55
+ @stringToken() or
56
+ @numberToken() or
57
+ @regexToken() or
58
+ @jsToken() or
59
+ @literalToken()
60
+
61
+ @closeIndentation()
62
+ return @tokens if opts.rewrite is off
63
+ (new Rewriter).rewrite @tokens
64
+
65
+ # Tokenizers
66
+ # ----------
67
+
68
+ # Matches identifying literals: variables, keywords, method names, etc.
69
+ # Check to ensure that JavaScript reserved words aren't being used as
70
+ # identifiers. Because CoffeeScript reserves a handful of keywords that are
71
+ # allowed in JavaScript, we're careful not to tag them as keywords when
72
+ # referenced as property names here, so you can still do `jQuery.is()` even
73
+ # though `is` means `===` otherwise.
74
+ identifierToken: ->
75
+ return 0 unless match = IDENTIFIER.exec @chunk
76
+ [input, id, colon] = match
77
+
78
+ if id is 'own' and @tag() is 'FOR'
79
+ @token 'OWN', id
80
+ return id.length
81
+ forcedIdentifier = colon or
82
+ (prev = last @tokens) and not prev.spaced and prev[0] in ['.', '?.', '@', '::']
83
+ tag = 'IDENTIFIER'
84
+
85
+ if id in JS_KEYWORDS or
86
+ not forcedIdentifier and id in COFFEE_KEYWORDS
87
+ tag = id.toUpperCase()
88
+ if tag is 'WHEN' and @tag() in LINE_BREAK
89
+ tag = 'LEADING_WHEN'
90
+ else if tag is 'FOR'
91
+ @seenFor = yes
92
+ else if tag is 'UNLESS'
93
+ tag = 'IF'
94
+ else if tag in UNARY
95
+ tag = 'UNARY'
96
+ else if tag in RELATION
97
+ if tag isnt 'INSTANCEOF' and @seenFor
98
+ tag = 'FOR' + tag
99
+ @seenFor = no
100
+ else
101
+ tag = 'RELATION'
102
+ if @value() is '!'
103
+ @tokens.pop()
104
+ id = '!' + id
105
+
106
+ if id in JS_FORBIDDEN
107
+ if forcedIdentifier
108
+ tag = 'IDENTIFIER'
109
+ id = new String id
110
+ id.reserved = yes
111
+ else if id in RESERVED
112
+ @identifierError id
113
+
114
+ unless forcedIdentifier
115
+ id = COFFEE_ALIASES[id] if COFFEE_ALIASES.hasOwnProperty id
116
+ tag = switch id
117
+ when '!' then 'UNARY'
118
+ when '==', '!=' then 'COMPARE'
119
+ when '&&', '||' then 'LOGIC'
120
+ when 'true', 'false', 'null', 'undefined' then 'BOOL'
121
+ when 'break', 'continue', 'debugger' then 'STATEMENT'
122
+ else tag
123
+
124
+ @token tag, id
125
+ @token ':', ':' if colon
126
+ input.length
127
+
128
+ # Matches numbers, including decimals, hex, and exponential notation.
129
+ # Be careful not to interfere with ranges-in-progress.
130
+ numberToken: ->
131
+ return 0 unless match = NUMBER.exec @chunk
132
+ number = match[0]
133
+ @token 'NUMBER', number
134
+ number.length
135
+
136
+ # Matches strings, including multi-line strings. Ensures that quotation marks
137
+ # are balanced within the string's contents, and within nested interpolations.
138
+ stringToken: ->
139
+ switch @chunk.charAt 0
140
+ when "'"
141
+ return 0 unless match = SIMPLESTR.exec @chunk
142
+ @token 'STRING', (string = match[0]).replace MULTILINER, '\\\n'
143
+ when '"'
144
+ return 0 unless string = @balancedString @chunk, '"'
145
+ if 0 < string.indexOf '#{', 1
146
+ @interpolateString string.slice 1, -1
147
+ else
148
+ @token 'STRING', @escapeLines string
149
+ else
150
+ return 0
151
+ @line += count string, '\n'
152
+ string.length
153
+
154
+ # Matches heredocs, adjusting indentation to the correct level, as heredocs
155
+ # preserve whitespace, but ignore indentation to the left.
156
+ heredocToken: ->
157
+ return 0 unless match = HEREDOC.exec @chunk
158
+ heredoc = match[0]
159
+ quote = heredoc.charAt 0
160
+ doc = @sanitizeHeredoc match[2], quote: quote, indent: null
161
+ if quote is '"' and 0 <= doc.indexOf '#{'
162
+ @interpolateString doc, heredoc: yes
163
+ else
164
+ @token 'STRING', @makeString doc, quote, yes
165
+ @line += count heredoc, '\n'
166
+ heredoc.length
167
+
168
+ # Matches and consumes comments.
169
+ commentToken: ->
170
+ return 0 unless match = @chunk.match COMMENT
171
+ [comment, here] = match
172
+ @line += count comment, '\n'
173
+ if here
174
+ @token 'HERECOMMENT', @sanitizeHeredoc here,
175
+ herecomment: true, indent: Array(@indent + 1).join(' ')
176
+ @token 'TERMINATOR', '\n'
177
+ comment.length
178
+
179
+ # Matches JavaScript interpolated directly into the source via backticks.
180
+ jsToken: ->
181
+ return 0 unless @chunk.charAt(0) is '`' and match = JSTOKEN.exec @chunk
182
+ @token 'JS', (script = match[0]).slice 1, -1
183
+ script.length
184
+
185
+ # Matches regular expression literals. Lexing regular expressions is difficult
186
+ # to distinguish from division, so we borrow some basic heuristics from
187
+ # JavaScript and Ruby.
188
+ regexToken: ->
189
+ return 0 if @chunk.charAt(0) isnt '/'
190
+ return @heregexToken match if match = HEREGEX.exec @chunk
191
+ prev = last @tokens
192
+ return 0 if prev and (prev[0] in (if prev.spaced then NOT_REGEX else NOT_SPACED_REGEX))
193
+ return 0 unless match = REGEX.exec @chunk
194
+ [regex] = match
195
+ @token 'REGEX', if regex is '//' then '/(?:)/' else regex
196
+ regex.length
197
+
198
+ # Matches multiline extended regular expressions.
199
+ heregexToken: (match) ->
200
+ [heregex, body, flags] = match
201
+ if 0 > body.indexOf '#{'
202
+ re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/')
203
+ @token 'REGEX', "/#{ re or '(?:)' }/#{flags}"
204
+ return heregex.length
205
+ @token 'IDENTIFIER', 'RegExp'
206
+ @tokens.push ['CALL_START', '(']
207
+ tokens = []
208
+ for [tag, value] in @interpolateString(body, regex: yes)
209
+ if tag is 'TOKENS'
210
+ tokens.push value...
211
+ else
212
+ continue unless value = value.replace HEREGEX_OMIT, ''
213
+ value = value.replace /\\/g, '\\\\'
214
+ tokens.push ['STRING', @makeString(value, '"', yes)]
215
+ tokens.push ['+', '+']
216
+ tokens.pop()
217
+ @tokens.push ['STRING', '""'], ['+', '+'] unless tokens[0]?[0] is 'STRING'
218
+ @tokens.push tokens...
219
+ @tokens.push [',', ','], ['STRING', '"' + flags + '"'] if flags
220
+ @token ')', ')'
221
+ heregex.length
222
+
223
+ # Matches newlines, indents, and outdents, and determines which is which.
224
+ # If we can detect that the current line is continued onto the the next line,
225
+ # then the newline is suppressed:
226
+ #
227
+ # elements
228
+ # .each( ... )
229
+ # .map( ... )
230
+ #
231
+ # Keeps track of the level of indentation, because a single outdent token
232
+ # can close multiple indents, so we need to know how far in we happen to be.
233
+ lineToken: ->
234
+ return 0 unless match = MULTI_DENT.exec @chunk
235
+ indent = match[0]
236
+ @line += count indent, '\n'
237
+ prev = last @tokens, 1
238
+ size = indent.length - 1 - indent.lastIndexOf '\n'
239
+ noNewlines = @unfinished()
240
+ if size - @indebt is @indent
241
+ if noNewlines then @suppressNewlines() else @newlineToken()
242
+ return indent.length
243
+ if size > @indent
244
+ if noNewlines
245
+ @indebt = size - @indent
246
+ @suppressNewlines()
247
+ return indent.length
248
+ diff = size - @indent + @outdebt
249
+ @token 'INDENT', diff
250
+ @indents.push diff
251
+ @outdebt = @indebt = 0
252
+ else
253
+ @indebt = 0
254
+ @outdentToken @indent - size, noNewlines
255
+ @indent = size
256
+ indent.length
257
+
258
+ # Record an outdent token or multiple tokens, if we happen to be moving back
259
+ # inwards past several recorded indents.
260
+ outdentToken: (moveOut, noNewlines, close) ->
261
+ while moveOut > 0
262
+ len = @indents.length - 1
263
+ if @indents[len] is undefined
264
+ moveOut = 0
265
+ else if @indents[len] is @outdebt
266
+ moveOut -= @outdebt
267
+ @outdebt = 0
268
+ else if @indents[len] < @outdebt
269
+ @outdebt -= @indents[len]
270
+ moveOut -= @indents[len]
271
+ else
272
+ dent = @indents.pop() - @outdebt
273
+ moveOut -= dent
274
+ @outdebt = 0
275
+ @token 'OUTDENT', dent
276
+ @outdebt -= moveOut if dent
277
+ @token 'TERMINATOR', '\n' unless @tag() is 'TERMINATOR' or noNewlines
278
+ this
279
+
280
+ # Matches and consumes non-meaningful whitespace. Tag the previous token
281
+ # as being "spaced", because there are some cases where it makes a difference.
282
+ whitespaceToken: ->
283
+ return 0 unless (match = WHITESPACE.exec @chunk) or
284
+ (nline = @chunk.charAt(0) is '\n')
285
+ prev = last @tokens
286
+ prev[if match then 'spaced' else 'newLine'] = true if prev
287
+ if match then match[0].length else 0
288
+
289
+ # Generate a newline token. Consecutive newlines get merged together.
290
+ newlineToken: ->
291
+ @token 'TERMINATOR', '\n' unless @tag() is 'TERMINATOR'
292
+ this
293
+
294
+ # Use a `\` at a line-ending to suppress the newline.
295
+ # The slash is removed here once its job is done.
296
+ suppressNewlines: ->
297
+ @tokens.pop() if @value() is '\\'
298
+ this
299
+
300
+ # We treat all other single characters as a token. E.g.: `( ) , . !`
301
+ # Multi-character operators are also literal tokens, so that Jison can assign
302
+ # the proper order of operations. There are some symbols that we tag specially
303
+ # here. `;` and newlines are both treated as a `TERMINATOR`, we distinguish
304
+ # parentheses that indicate a method call from regular parentheses, and so on.
305
+ literalToken: ->
306
+ if match = OPERATOR.exec @chunk
307
+ [value] = match
308
+ @tagParameters() if CODE.test value
309
+ else
310
+ value = @chunk.charAt 0
311
+ tag = value
312
+ prev = last @tokens
313
+ if value is '=' and prev
314
+ @assignmentError() if not prev[1].reserved and prev[1] in JS_FORBIDDEN
315
+ if prev[1] in ['||', '&&']
316
+ prev[0] = 'COMPOUND_ASSIGN'
317
+ prev[1] += '='
318
+ return value.length
319
+ if value is ';' then tag = 'TERMINATOR'
320
+ else if value in MATH then tag = 'MATH'
321
+ else if value in COMPARE then tag = 'COMPARE'
322
+ else if value in COMPOUND_ASSIGN then tag = 'COMPOUND_ASSIGN'
323
+ else if value in UNARY then tag = 'UNARY'
324
+ else if value in SHIFT then tag = 'SHIFT'
325
+ else if value in LOGIC or value is '?' and prev?.spaced then tag = 'LOGIC'
326
+ else if prev and not prev.spaced
327
+ if value is '(' and prev[0] in CALLABLE
328
+ prev[0] = 'FUNC_EXIST' if prev[0] is '?'
329
+ tag = 'CALL_START'
330
+ else if value is '[' and prev[0] in INDEXABLE
331
+ tag = 'INDEX_START'
332
+ switch prev[0]
333
+ when '?' then prev[0] = 'INDEX_SOAK'
334
+ when '::' then prev[0] = 'INDEX_PROTO'
335
+ @token tag, value
336
+ value.length
337
+
338
+ # Token Manipulators
339
+ # ------------------
340
+
341
+ # Sanitize a heredoc or herecomment by
342
+ # erasing all external indentation on the left-hand side.
343
+ sanitizeHeredoc: (doc, options) ->
344
+ {indent, herecomment} = options
345
+ return doc if herecomment and 0 > doc.indexOf '\n'
346
+ unless herecomment
347
+ while match = HEREDOC_INDENT.exec doc
348
+ attempt = match[1]
349
+ indent = attempt if indent is null or 0 < attempt.length < indent.length
350
+ doc = doc.replace /// \n #{indent} ///g, '\n' if indent
351
+ doc = doc.replace /^\n/, '' unless herecomment
352
+ doc
353
+
354
+ # A source of ambiguity in our grammar used to be parameter lists in function
355
+ # definitions versus argument lists in function calls. Walk backwards, tagging
356
+ # parameters specially in order to make things easier for the parser.
357
+ tagParameters: ->
358
+ return this if @tag() isnt ')'
359
+ stack = []
360
+ {tokens} = this
361
+ i = tokens.length
362
+ tokens[--i][0] = 'PARAM_END'
363
+ while tok = tokens[--i]
364
+ switch tok[0]
365
+ when ')'
366
+ stack.push tok
367
+ when '(', 'CALL_START'
368
+ if stack.length then stack.pop()
369
+ else
370
+ tok[0] = 'PARAM_START'
371
+ return this
372
+ this
373
+
374
+ # Close up all remaining open blocks at the end of the file.
375
+ closeIndentation: ->
376
+ @outdentToken @indent
377
+
378
+ # The error for when you try to use a forbidden word in JavaScript as
379
+ # an identifier.
380
+ identifierError: (word) ->
381
+ throw SyntaxError "Reserved word \"#{word}\" on line #{@line + 1}"
382
+
383
+ # The error for when you try to assign to a reserved word in JavaScript,
384
+ # like "function" or "default".
385
+ assignmentError: ->
386
+ throw SyntaxError "Reserved word \"#{@value()}\" on line #{@line + 1} can't be assigned"
387
+
388
+ # Matches a balanced group such as a single or double-quoted string. Pass in
389
+ # a series of delimiters, all of which must be nested correctly within the
390
+ # contents of the string. This method allows us to have strings within
391
+ # interpolations within strings, ad infinitum.
392
+ balancedString: (str, end) ->
393
+ stack = [end]
394
+ for i in [1...str.length]
395
+ switch letter = str.charAt i
396
+ when '\\'
397
+ i++
398
+ continue
399
+ when end
400
+ stack.pop()
401
+ unless stack.length
402
+ return str.slice 0, i + 1
403
+ end = stack[stack.length - 1]
404
+ continue
405
+ if end is '}' and letter in ['"', "'"]
406
+ stack.push end = letter
407
+ else if end is '}' and letter is '{'
408
+ stack.push end = '}'
409
+ else if end is '"' and prev is '#' and letter is '{'
410
+ stack.push end = '}'
411
+ prev = letter
412
+ throw new Error "missing #{ stack.pop() }, starting on line #{ @line + 1 }"
413
+
414
+
415
+ # Expand variables and expressions inside double-quoted strings using
416
+ # Ruby-like notation for substitution of arbitrary expressions.
417
+ #
418
+ # "Hello #{name.capitalize()}."
419
+ #
420
+ # If it encounters an interpolation, this method will recursively create a
421
+ # new Lexer, tokenize the interpolated contents, and merge them into the
422
+ # token stream.
423
+ interpolateString: (str, options = {}) ->
424
+ {heredoc, regex} = options
425
+ tokens = []
426
+ pi = 0
427
+ i = -1
428
+ while letter = str.charAt i += 1
429
+ if letter is '\\'
430
+ i += 1
431
+ continue
432
+ unless letter is '#' and str.charAt(i+1) is '{' and
433
+ (expr = @balancedString str.slice(i + 1), '}')
434
+ continue
435
+ tokens.push ['NEOSTRING', str.slice(pi, i)] if pi < i
436
+ inner = expr.slice(1, -1)
437
+ if inner.length
438
+ nested = new Lexer().tokenize inner, line: @line, rewrite: off
439
+ nested.pop()
440
+ nested.shift() if nested[0]?[0] is 'TERMINATOR'
441
+ if nested.length > 1
442
+ nested.unshift ['(', '(']
443
+ nested.push [')', ')']
444
+ tokens.push ['TOKENS', nested]
445
+ i += expr.length
446
+ pi = i + 1
447
+ tokens.push ['NEOSTRING', str.slice pi] if i > pi < str.length
448
+ return tokens if regex
449
+ return @token 'STRING', '""' unless tokens.length
450
+ tokens.unshift ['', ''] unless tokens[0][0] is 'NEOSTRING'
451
+ @token '(', '(' if interpolated = tokens.length > 1
452
+ for [tag, value], i in tokens
453
+ @token '+', '+' if i
454
+ if tag is 'TOKENS'
455
+ @tokens.push value...
456
+ else
457
+ @token 'STRING', @makeString value, '"', heredoc
458
+ @token ')', ')' if interpolated
459
+ tokens
460
+
461
+ # Helpers
462
+ # -------
463
+
464
+ # Add a token to the results, taking note of the line number.
465
+ token: (tag, value) ->
466
+ @tokens.push [tag, value, @line]
467
+
468
+ # Peek at a tag in the current token stream.
469
+ tag: (index, tag) ->
470
+ (tok = last @tokens, index) and if tag then tok[0] = tag else tok[0]
471
+
472
+ # Peek at a value in the current token stream.
473
+ value: (index, val) ->
474
+ (tok = last @tokens, index) and if val then tok[1] = val else tok[1]
475
+
476
+ # Are we in the midst of an unfinished expression?
477
+ unfinished: ->
478
+ LINE_CONTINUER.test(@chunk) or
479
+ (prev = last @tokens, 1) and prev[0] isnt '.' and
480
+ (value = @value()) and not value.reserved and
481
+ NO_NEWLINE.test(value) and not CODE.test(value) and not ASSIGNED.test(@chunk)
482
+
483
+ # Converts newlines for string literals.
484
+ escapeLines: (str, heredoc) ->
485
+ str.replace MULTILINER, if heredoc then '\\n' else ''
486
+
487
+ # Constructs a string token by escaping quotes and newlines.
488
+ makeString: (body, quote, heredoc) ->
489
+ return quote + quote unless body
490
+ body = body.replace /\\([\s\S])/g, (match, contents) ->
491
+ if contents in ['\n', quote] then contents else match
492
+ body = body.replace /// #{quote} ///g, '\\$&'
493
+ quote + @escapeLines(body, heredoc) + quote
494
+
495
+ # Constants
496
+ # ---------
497
+
498
+ # Keywords that CoffeeScript shares in common with JavaScript.
499
+ JS_KEYWORDS = [
500
+ 'true', 'false', 'null', 'this'
501
+ 'new', 'delete', 'typeof', 'in', 'instanceof'
502
+ 'return', 'throw', 'break', 'continue', 'debugger'
503
+ 'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally'
504
+ 'class', 'extends', 'super'
505
+ ]
506
+
507
+ # CoffeeScript-only keywords.
508
+ COFFEE_KEYWORDS = ['undefined', 'then', 'unless', 'until', 'loop', 'of', 'by', 'when']
509
+ COFFEE_KEYWORDS.push op for op of COFFEE_ALIASES =
510
+ and : '&&'
511
+ or : '||'
512
+ is : '=='
513
+ isnt : '!='
514
+ not : '!'
515
+ yes : 'true'
516
+ no : 'false'
517
+ on : 'true'
518
+ off : 'false'
519
+
520
+ # The list of keywords that are reserved by JavaScript, but not used, or are
521
+ # used by CoffeeScript internally. We throw an error when these are encountered,
522
+ # to avoid having a JavaScript error at runtime.
523
+ RESERVED = [
524
+ 'case', 'default', 'function', 'var', 'void', 'with'
525
+ 'const', 'let', 'enum', 'export', 'import', 'native'
526
+ '__hasProp', '__extends', '__slice', '__bind', '__indexOf'
527
+ ]
528
+
529
+ # The superset of both JavaScript keywords and reserved words, none of which may
530
+ # be used as identifiers or properties.
531
+ JS_FORBIDDEN = JS_KEYWORDS.concat RESERVED
532
+
533
+ exports.RESERVED = RESERVED.concat(JS_KEYWORDS).concat(COFFEE_KEYWORDS)
534
+
535
+ # Token matching regexes.
536
+ IDENTIFIER = /// ^
537
+ ( [$A-Za-z_][$\w]* )
538
+ ( [^\n\S]* : (?!:) )? # Is this a property name?
539
+ ///
540
+
541
+ NUMBER = ///
542
+ ^ 0x[\da-f]+ | # hex
543
+ ^ (?: \d+(\.\d+)? | \.\d+ ) (?:e[+-]?\d+)? # decimal
544
+ ///i
545
+
546
+ HEREDOC = /// ^ ("""|''') ([\s\S]*?) (?:\n[^\n\S]*)? \1 ///
547
+
548
+ OPERATOR = /// ^ (
549
+ ?: [-=]> # function
550
+ | [-+*/%<>&|^!?=]= # compound assign / compare
551
+ | >>>=? # zero-fill right shift
552
+ | ([-+:])\1 # doubles
553
+ | ([&|<>])\2=? # logic / shift
554
+ | \?\. # soak access
555
+ | \.{2,3} # range or splat
556
+ ) ///
557
+
558
+ WHITESPACE = /^[^\n\S]+/
559
+
560
+ COMMENT = /^###([^#][\s\S]*?)(?:###[^\n\S]*|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/
561
+
562
+ CODE = /^[-=]>/
563
+
564
+ MULTI_DENT = /^(?:\n[^\n\S]*)+/
565
+
566
+ SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/
567
+
568
+ JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/
569
+
570
+ # Regex-matching-regexes.
571
+ REGEX = /// ^
572
+ / (?! \s ) # disallow leading whitespace
573
+ [^ [ / \n \\ ]* # every other thing
574
+ (?:
575
+ (?: \\[\s\S] # anything escaped
576
+ | \[ # character class
577
+ [^ \] \n \\ ]*
578
+ (?: \\[\s\S] [^ \] \n \\ ]* )*
579
+ ]
580
+ ) [^ [ / \n \\ ]*
581
+ )*
582
+ / [imgy]{0,4} (?!\w)
583
+ ///
584
+
585
+ HEREGEX = /// ^ /{3} ([\s\S]+?) /{3} ([imgy]{0,4}) (?!\w) ///
586
+
587
+ HEREGEX_OMIT = /\s+(?:#.*)?/g
588
+
589
+ # Token cleaning regexes.
590
+ MULTILINER = /\n/g
591
+
592
+ HEREDOC_INDENT = /\n+([^\n\S]*)/g
593
+
594
+ ASSIGNED = /^\s*@?([$A-Za-z_][$\w]*|['"].*['"])[^\n\S]*?[:=][^:=>]/
595
+
596
+ LINE_CONTINUER = /// ^ \s* (?: , | \??\.(?!\.) | :: ) ///
597
+
598
+ TRAILING_SPACES = /\s+$/
599
+
600
+ NO_NEWLINE = /// ^ (?: # non-capturing group
601
+ [-+*&|/%=<>!.\\][<>=&|]* | # symbol operators
602
+ and | or | is(?:nt)? | n(?:ot|ew) | # word operators
603
+ delete | typeof | instanceof
604
+ ) $ ///
605
+
606
+ # Compound assignment tokens.
607
+ COMPOUND_ASSIGN = [
608
+ '-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='
609
+ ]
610
+
611
+ # Unary tokens.
612
+ UNARY = ['!', '~', 'NEW', 'TYPEOF', 'DELETE', 'DO']
613
+
614
+ # Logical tokens.
615
+ LOGIC = ['&&', '||', '&', '|', '^']
616
+
617
+ # Bit-shifting tokens.
618
+ SHIFT = ['<<', '>>', '>>>']
619
+
620
+ # Comparison tokens.
621
+ COMPARE = ['==', '!=', '<', '>', '<=', '>=']
622
+
623
+ # Mathematical tokens.
624
+ MATH = ['*', '/', '%']
625
+
626
+ # Relational tokens that are negatable with `not` prefix.
627
+ RELATION = ['IN', 'OF', 'INSTANCEOF']
628
+
629
+ # Boolean tokens.
630
+ BOOL = ['TRUE', 'FALSE', 'NULL', 'UNDEFINED']
631
+
632
+ # Tokens which a regular expression will never immediately follow, but which
633
+ # a division operator might.
634
+ #
635
+ # See: http://www.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions
636
+ #
637
+ # Our list is shorter, due to sans-parentheses method calls.
638
+ NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']']
639
+
640
+ # If the previous token is not spaced, there are more preceding tokens that
641
+ # force a division parse:
642
+ NOT_SPACED_REGEX = NOT_REGEX.concat ')', '}', 'THIS', 'IDENTIFIER', 'STRING'
643
+
644
+ # Tokens which could legitimately be invoked or indexed. A opening
645
+ # parentheses or bracket following these tokens will be recorded as the start
646
+ # of a function invocation or indexing operation.
647
+ CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER']
648
+ INDEXABLE = CALLABLE.concat 'NUMBER', 'BOOL'
649
+
650
+ # Tokens that, when immediately preceding a `WHEN`, indicate that the `WHEN`
651
+ # occurs at the start of a line. We disambiguate these from trailing whens to
652
+ # avoid an ambiguity in the grammar.
653
+ LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR']