Compare commits

...

1268 Commits
0.5.3 ... 0.9.6

Author SHA1 Message Date
Jeremy Ashkenas
fa53a4c057 CoffeeScript 0.9.6 2010-12-07 00:21:34 -05:00
Jeremy Ashkenas
edd0c5af5a no-op. 2010-12-06 23:39:06 -05:00
Jeremy Ashkenas
2fb269a938 refactoring Scope. 2010-12-06 23:32:32 -05:00
Jeremy Ashkenas
3eac6aeb99 rebuilding browser coffee-script.js ... all tests pass. 2010-12-06 23:21:55 -05:00
Jeremy Ashkenas
ec64646fee Issue #901 ... allow constructor functions to maintain their position in the class body. 2010-12-06 01:01:57 -05:00
Jeremy Ashkenas
2decb30d4e Issue #897 ... fixed leaking direct-call-plucked comprehension variables, due to shared scope. 2010-12-05 21:18:30 -05:00
Jeremy Ashkenas
c0bbc609be Fixing direct construction splats. 2010-12-05 20:44:32 -05:00
Jeremy Ashkenas
f6be426aa0 utils -> util. 2010-12-05 17:51:52 -05:00
Jeremy Ashkenas
17b5c8ac6f Issue #887 and #893. Adding timestamps to --watch --compile. 2010-12-05 16:06:13 -05:00
Jeremy Ashkenas
b18d0d75fd adding newlines after error stacktrace in REPL. 2010-12-05 15:46:04 -05:00
Jeremy Ashkenas
77e13e459b Fixing the repl so that errors print properly, and async exceptions are logged instead of killing the session. 2010-12-05 15:40:49 -05:00
Jeremy Ashkenas
06647bdd0a Adding warning about accidentally-comprehended-functions. Issue #896. 2010-12-05 15:29:28 -05:00
Jeremy Ashkenas
24183d9a39 Issue #894: Strange interaction between class instantiation and splats 2010-12-05 15:08:41 -05:00
Michael Ficarra
dc5854689b fix for bug introduced in 63cbb643 2010-12-05 13:10:14 -05:00
Michael Ficarra
ed70b9d4d0 test for bug introduced in 63cbb643
discussion: 63cbb64341 (commitcomment-209643)
2010-12-05 13:08:14 -05:00
Jeremy Ashkenas
c7a9801db7 simplifying generated output for common-case splices. 2010-12-04 15:06:21 -05:00
Jeremy Ashkenas
85521f88b2 typo 2010-12-04 12:55:46 -05:00
Jeremy Ashkenas
75ca0f23ac redocumenting slices/splices ... issue #833 2010-12-04 12:52:51 -05:00
Jeremy Ashkenas
67c20c0715 style tweaks to previous patch. 2010-12-03 01:23:54 -05:00
Michael Ficarra
c50cb65019 Chained comparisons now properly apply DeMorgan's Laws. I couldn't
believe there wasn't a test to remind me to toggle the
{dis,con}junctions. Added that test.
2010-12-03 00:07:30 -05:00
Michael Ficarra
23b4d2fd1d Finally got !== and === back to inverting again (instead of wrapping in
`!()`)

Also, removed the `@inverted` kludge. It was gross to begin with, but I
didn't know the proper way to do it.
2010-12-02 23:03:21 -05:00
Michael Ficarra
dd18703b50 Issue #891: cannot safely invert < and > to >= and <= (or the
other way around). Proper fix this time.
2010-12-02 20:55:19 -05:00
Michael Ficarra
b1ba298ffc Reverted previous change to what was believed to be an errant test case.
Also added a test for NaN safety
2010-12-02 20:54:15 -05:00
Michael Ficarra
992324b425 fix for #891: incorrect inversion of chained comparisons 2010-12-02 12:55:53 -05:00
Michael Ficarra
56e10f9bce added test for #891: incorrect inversion of chained comparisons; fixed a
faulty test case in test/test_switch.coffee
2010-12-02 12:55:28 -05:00
Jeremy Ashkenas
69664a1bb3 Adding precedence change note to changelog 2010-12-01 14:17:10 -05:00
Jeremy Ashkenas
1f5727fe9d Coco 38aa762: rewriter: made addImplicitBraces consume multiple leading comments 2010-11-28 17:54:00 -08:00
Jeremy Ashkenas
b52a1ed60a disallow index mentions for range loops. 2010-11-28 15:54:39 -08:00
Jeremy Ashkenas
c3f1820ebc Issue #856. Invert 2010-11-28 15:33:43 -08:00
Jeremy Ashkenas
4afa6a2887 Issue #860. Nested classes. 2010-11-28 14:56:07 -08:00
Jeremy Ashkenas
1254efaddb Issue #878. Namespaced classes should not leak their function name. 2010-11-28 10:08:49 -08:00
Jeremy Ashkenas
adeace8f62 Merge branch 'issue/875' of git://github.com/StanAngeloff/coffee-script 2010-11-28 09:55:54 -08:00
Jeremy Ashkenas
4447180d5a Removing dynamic keys from objects. 2010-11-28 09:42:43 -08:00
Jeremy Ashkenas
41beccbe3c reverting Scope#temporary simplification. 2010-11-28 09:28:46 -08:00
Jeremy Ashkenas
a4958e76c1 whitespace 2010-11-28 09:27:06 -08:00
Stan Angeloff
a9e264dd84 console.{log,warn} → print{Line,Warn} 2010-11-28 16:04:52 +02:00
Jeremy Ashkenas
51988dba09 Removing unused garbage collection from Scope. 2010-11-27 18:04:40 -08:00
Jeremy Ashkenas
39c4c23200 nested shared scopes don't clobber variables. 2010-11-27 17:52:52 -08:00
Michael Ficarra
63cbb64341 fixes #855; fix partially inspired by satyr/coco 3e37cf32 2010-11-26 02:08:25 -05:00
Michael Ficarra
c0cb0c35e2 adding tests for #855 2010-11-26 02:06:10 -05:00
Jeremy Ashkenas
9db6d6f4ef Updating rake task to pull version number and date. 2010-11-21 22:33:27 -05:00
Jeremy Ashkenas
57bd6bc2cd Adding the coffee-script-source gem publisher to the Rakefile. 2010-11-21 21:42:15 -05:00
Jeremy Ashkenas
e5deb2b3c3 CoffeeScript 0.9.5 2010-11-21 21:21:07 -05:00
Jeremy Ashkenas
fc64fa49ac Switching default arguments to use an if instead of an and, more documentation. 2010-11-21 21:12:59 -05:00
Jeremy Ashkenas
5dfd36af6a removing some extra parens. 2010-11-21 19:59:22 -05:00
Jeremy Ashkenas
1778177195 continuing to document the homepage for 0.9.5 ... removing an optimization for local variables within loops. 2010-11-21 19:53:31 -05:00
Jeremy Ashkenas
ac9d36e444 adding Lucida Sans Unicode back in. 2010-11-21 12:59:21 -05:00
Jeremy Ashkenas
fcda00c3d8 tweaking coffeescript.org styles 2010-11-21 12:51:03 -05:00
Jeremy Ashkenas
28d5db3bca preparing documentation for 0.9.5 2010-11-21 12:38:27 -05:00
Jeremy Ashkenas
8fcd67e82f Updating examples for 0.9.5 2010-11-21 11:41:24 -05:00
Jeremy Ashkenas
710290ad1d Revert "Coco 5622aef: grammar: POST_IF now has the same precedence as FOR/WHILE, making work as expected"
This reverts commit aa262ecf0e.
2010-11-20 21:09:13 -05:00
Jeremy Ashkenas
aa262ecf0e Coco 5622aef: grammar: POST_IF now has the same precedence as FOR/WHILE, making work as expected 2010-11-20 20:59:38 -05:00
Jeremy Ashkenas
338e6d7f72 Coco 9a917bb: nodes: removed NUMBER 2010-11-20 20:51:43 -05:00
Jeremy Ashkenas
4ef9470466 Coco 16dcb4a: parenthesized expressions can now be indented 2010-11-20 20:47:43 -05:00
Jeremy Ashkenas
0e4d589d80 Coco ce2d08a: removed _argN temporaries for readability/consistency 2010-11-20 20:39:35 -05:00
Jeremy Ashkenas
835244f92d slight reformats to cake bench 2010-11-20 20:28:45 -05:00
Jeremy Ashkenas
2f498162b0 Coco f10291f: parens can now take a sequence of expressions: a = (b; c) 2010-11-20 20:22:05 -05:00
Jeremy Ashkenas
93cf3bd922 Coco ecd6aa4: Accessor -> Access 2010-11-20 20:09:36 -05:00
Jeremy Ashkenas
d3ae3525b8 reordering __extends. Issue #848 2010-11-20 19:17:09 -05:00
Jeremy Ashkenas
c8a2a78319 Issue #843. If a for-body ends in a pure-statement, no need to try and return results. 2010-11-20 19:12:39 -05:00
Jeremy Ashkenas
1f12642af2 Slice and Splice tests are back on master. 2010-11-20 18:49:17 -05:00
Jeremy Ashkenas
9111c2e702 All tests passing again. 2010-11-20 18:38:56 -05:00
Jeremy Ashkenas
0e388fd21c making empty loops compile newlineless 2010-11-20 18:37:19 -05:00
Jeremy Ashkenas
41c6364f6c removing an accidental double-method 2010-11-20 18:21:31 -05:00
Jeremy Ashkenas
12134d2043 Using pluckDirectCalls again 2010-11-20 18:14:05 -05:00
Jeremy Ashkenas
83c41c69be CoffeeScript lints cleanly again. 2010-11-20 17:46:44 -05:00
Jeremy Ashkenas
31f4214b5d first draft of range literals back... 2010-11-20 17:40:46 -05:00
Jeremy Ashkenas
9f708ad0c8 Merge branch 'master' of https://github.com/andrewschaaf/coffee-script 2010-11-20 14:32:19 -05:00
Jeremy Ashkenas
a2760c6ca3 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-11-20 14:22:44 -05:00
Jeremy Ashkenas
98a362136b rebuilding source docs with new version of Docco. 2010-11-20 14:22:28 -05:00
satyr
bcbf9f7dfd "cake bench" now shows total time spent 2010-11-18 21:33:56 +09:00
satyr
1a9a48c5f2 rewrote "cake bench" to time per parsing stage 2010-11-18 01:34:23 +09:00
satyr
32bd1dfd53 rewrote "cake bench" to see more consistent results 2010-11-17 23:53:39 +09:00
Andrew Schaaf
77cf992224 "sudo npm" -> "npm". npm calls "sudo npm"ing "HOLY COW NOT RECOMMENDED!!" 2010-11-16 14:44:24 -05:00
Jeremy Ashkenas
0c11267045 coco fd028a0: closes #13; leading comments/literals are now placed before variable declarations 2010-11-16 00:11:52 -05:00
Jeremy Ashkenas
ee6f24b48a coco c6cf38a: lexer: refactored @balancedString 2010-11-15 23:59:52 -05:00
Jeremy Ashkenas
eb959b3879 coco: cc71308 (partial) break continue debugger -> STATEMENT 2010-11-14 15:15:13 -05:00
Jeremy Ashkenas
f31798bbb4 coco 31ad9f0: nodes: made Op::invert more accurate 2010-11-14 15:07:43 -05:00
Jeremy Ashkenas
a1aaa4495c fixing Lexer#ASSIGNED 2010-11-14 15:00:20 -05:00
Jeremy Ashkenas
be17b8215c constructor: prefix is back for classes. punto. 2010-11-14 14:21:55 -05:00
Jeremy Ashkenas
15bdcf79e6 coco 63d607f: made deep destructuring compile nicer 2010-11-14 09:47:06 -05:00
Jeremy Ashkenas
09aa9e2a04 coco 19474b4: nodes: removed Base::collectChildren 2010-11-14 09:44:40 -05:00
Jeremy Ashkenas
c98fa8168b making levels start at one. 2010-11-13 21:08:42 -05:00
Jeremy Ashkenas
32a9c2ce49 moving up constructor definitions. 2010-11-13 21:05:59 -05:00
Jeremy Ashkenas
c7cd72c682 coco 02ee77c: nodes: fixed parenthesization in Op::compileNode 2010-11-13 18:27:05 -05:00
Jeremy Ashkenas
144b66c4da coco 2419207: coffee#840: fixed post-for precedence 2010-11-13 18:23:46 -05:00
Jeremy Ashkenas
7c7eccf1f2 removing an unused rule in Root. 2010-11-13 18:13:09 -05:00
Jeremy Ashkenas
5de73f6c25 coco 7222551: crushed __bind 2010-11-13 18:08:02 -05:00
Jeremy Ashkenas
6f47364392 done refactoring Class for now... 2010-11-13 18:02:50 -05:00
Jeremy Ashkenas
9a5546c8e9 further refactors to Class 2010-11-13 17:05:54 -05:00
Jeremy Ashkenas
f1972ff336 waypoint: part way through refactoring Class 2010-11-13 16:53:55 -05:00
Jeremy Ashkenas
cb6793f56b adding back '@static: value' syntax for classes 2010-11-13 15:52:30 -05:00
Jeremy Ashkenas
2aedbc2e42 Back to naked constructors. 2010-11-13 15:22:18 -05:00
Jeremy Ashkenas
f0b73dc9f5 Building with latest version of Jison. 2010-11-13 15:10:12 -05:00
Jeremy Ashkenas
354708dbc2 Putting 'constructor' back. Improving constructor definitions. 2010-11-13 12:17:09 -05:00
Jeremy Ashkenas
3059db8515 Merge branch 'master' into executable 2010-11-13 11:28:22 -05:00
Jason Davies
498e8124f6 Fix spelling 2010-11-13 10:37:55 +00:00
Jeremy Ashkenas
18afd2d84f merging in master 2010-11-12 20:18:52 -05:00
Jeremy Ashkenas
6d3e9df89f coco c39edf: braceless objects can now have trailing herecomments 2010-11-12 20:16:08 -05:00
Jeremy Ashkenas
d08cb20376 removing extended in favor of static method inheritance. 2010-11-12 00:20:08 -05:00
Jeremy Ashkenas
c778ef1004 merge 2010-11-12 00:07:32 -05:00
Jeremy Ashkenas
50c2226dd3 first draft of metaprogramming in class defn's. 2010-11-12 00:05:30 -05:00
satyr
9fa973debe dynakeys: work again on JScript 2010-11-11 23:10:32 -05:00
Jeremy Ashkenas
07e66dd2b4 Added back instance-bound functions to classes ... all tests pass again. 2010-11-11 23:04:58 -05:00
Jeremy Ashkenas
4d8434d1b6 a little further with the tests 2010-11-11 22:02:53 -05:00
Jeremy Ashkenas
ce4bf4aca5 a little further with the tests 2010-11-11 22:02:06 -05:00
Jeremy Ashkenas
21111755cf resolving merge 2010-11-11 21:55:20 -05:00
Jeremy Ashkenas
7fda0cd7d9 first draft of coco's executable class bodies ... cleanups and tests to follow. 2010-11-11 21:48:08 -05:00
satyr
a2d33112b8 dynakeys: work again on JScript 2010-11-11 16:17:56 +09:00
Jeremy Ashkenas
2c7f6d8bfe switching to UglifyJS for browser version of CoffeeScript. 2010-11-10 23:06:26 -05:00
Jeremy Ashkenas
5ec7e885f1 coco 8a8cc53: meta-heregex 2010-11-10 22:43:06 -05:00
Jeremy Ashkenas
3338cd073d better slash-w. 2010-11-10 22:41:14 -05:00
Jeremy Ashkenas
9a71bb17fd Adding IDENTIFIER and STRING to NOT_SPACED_REGEX 2010-11-09 22:46:37 -05:00
Jeremy Ashkenas
841463da8e Hewing closer to JS' syntactic resynchronization for regexp lexing. 2010-11-09 22:39:15 -05:00
Jeremy Ashkenas
71db1fc142 making REGEXP a bit stricter. 2010-11-09 22:22:02 -05:00
Jeremy Ashkenas
bc0cc34420 coco 03a9ac0: made tab characters consistent. 2010-11-09 08:25:48 -05:00
Jeremy Ashkenas
611174b0af Revert "coco b8039b9: merged @closeOpenCalls and @closeOpenIndexes into @closeOpenPairs"
This reverts commit a151ceccc6.
2010-11-09 08:20:09 -05:00
Jeremy Ashkenas
9c76c3ef8e Merge branch 'master' of github.com:jashkenas/coffee-script 2010-11-09 08:06:59 -05:00
Jeremy Ashkenas
8f8c4b44f1 it's attr, not css. 2010-11-09 08:06:54 -05:00
satyr
3ae818860b fixed a bug where postfix ? was incorrectly unwrapping its operand 2010-11-09 16:27:21 +09:00
Jeremy Ashkenas
188ad03c17 coco b615379: optimized @ensureBalance 2010-11-09 00:36:13 -05:00
Jeremy Ashkenas
a151ceccc6 coco b8039b9: merged @closeOpenCalls and @closeOpenIndexes into @closeOpenPairs 2010-11-09 00:31:11 -05:00
Jeremy Ashkenas
cb81f86434 coco 98271e6: made 'extends' chainable 2010-11-09 00:26:31 -05:00
Jeremy Ashkenas
d7f1193f22 coco 607fded: reinforced Op::INVERSIONS 2010-11-09 00:21:42 -05:00
Jeremy Ashkenas
9017b1ad3d _result -> _results 2010-11-09 00:17:08 -05:00
Jeremy Ashkenas
14f86043cf coco e8563db: tiny optimizations 2010-11-08 23:48:38 -05:00
Jeremy Ashkenas
042af51751 combination of satyr's three comment patches ... comments are now statements, not expressions... 2010-11-08 23:39:21 -05:00
Federico Builes
936abc381b Remove trailing whitespace from README. 2010-11-08 23:25:15 -05:00
Jeremy Ashkenas
e882af9f8d coco b82de20: removed Base::idt 2010-11-08 23:20:11 -05:00
Jeremy Ashkenas
9c5eca9131 coco dc8945c: less ternaries, more returns-from-ifs. More readable. 2010-11-08 23:07:51 -05:00
Jeremy Ashkenas
919596aba4 coco a503190 ... made postfix invertible 2010-11-08 22:47:13 -05:00
Jeremy Ashkenas
eb3a32e853 fixing coffee -s ... (jannehietamaki) 2010-11-08 21:58:13 -05:00
Janne Hietamäki
3af34d61d3 Do not pass invalid filename 'stdio' to compileScript when compiling from stdin because it breaks fs.realpathSync at run.
It would be nice to have a test for this but wasn't sure if there is a way to test stdin from cake.
2010-11-06 15:21:45 +02:00
Jeremy Ashkenas
bc8022f49f lexer refactors 2010-11-05 00:04:52 -04:00
Jeremy Ashkenas
4eee750d4c removing unused utilities.js 2010-11-04 23:15:58 -04:00
Jeremy Ashkenas
f6a8d4c074 round 2, light refactors. 2010-11-04 23:05:04 -04:00
Jeremy Ashkenas
bb05e07e4e light refactors + tweaks 2010-11-04 22:53:07 -04:00
Jeremy Ashkenas
8d30feaf88 Fixing jsl.conf to lint cleanly again (don't mind our void 0s) 2010-11-04 22:39:50 -04:00
Jeremy Ashkenas
76685e6e51 first draft of safe range comprehensions, upwards and downwards. 2010-11-04 21:53:23 -04:00
Jeremy Ashkenas
09b243e689 loosening the restrictions on functions that can be lifted out -- more tests. 2010-11-03 22:51:17 -04:00
Jeremy Ashkenas
a8b36b231c Adding back in the closed-comprehensions tests. 2010-11-03 22:29:05 -04:00
Jeremy Ashkenas
d5f639fc50 fixing unsafe unwrapAll in previous commit. 2010-11-03 22:11:38 -04:00
Jeremy Ashkenas
9fc3f8593e First draft at loop block scoping again ... works for functions that mention 'this' 2010-11-03 22:05:24 -04:00
Jeremy Ashkenas
58cac0ca39 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-11-03 21:40:11 -04:00
Jeremy Ashkenas
304a120429 satyr 4e39e2e -- efficient closures in loops -- pulling them out. 2010-11-03 21:39:54 -04:00
satyr
c418bca461 nodes: filled in missing LEVEL_* in In::compile*Test 2010-11-02 23:28:18 +09:00
satyr
0441d4a5d1 rewriter: no longer tries to include dynamic keys into braceless objects 2010-11-02 23:22:41 +09:00
Jeremy Ashkenas
5eb255a649 modified satyr: allowed temporary variables to share names with ones on upper scopes 2010-11-02 00:31:42 -04:00
Jeremy Ashkenas
605f362ab6 BY now closes implicit calls. 2010-11-02 00:25:04 -04:00
Jeremy Ashkenas
a257f5993a tweak to parser.lexer 2010-11-02 00:05:06 -04:00
Jeremy Ashkenas
987aaa0e19 modified satyr -- when now closes implicit calls. 2010-11-02 00:00:26 -04:00
Jeremy Ashkenas
b0e7c3e3e7 modified satyr -- made temp vars be declared later. 2010-11-01 23:58:03 -04:00
Jeremy Ashkenas
5aa21c363d satyr 1612b04 ... enabled break/continue in comprehensions. 2010-11-01 23:53:49 -04:00
Jeremy Ashkenas
6aaa2eb4d0 safer splats with __slice where necessary. 2010-11-01 23:41:05 -04:00
Jeremy Ashkenas
6163215bbe More indentation, less one-liners. 2010-11-01 23:29:54 -04:00
Jeremy Ashkenas
4788f842c0 satyr commit b2cf91 ... no more @tags 2010-11-01 23:25:28 -04:00
Jeremy Ashkenas
b94c15bdcc not-or to is-and ... positive side. 2010-11-01 23:11:25 -04:00
Jeremy Ashkenas
ebbe0babdb reverting ?= optimization, for the repl's sake. 2010-11-01 22:32:04 -04:00
Jeremy Ashkenas
187cda0c39 Using default arguments in one more spot. 2010-11-01 22:07:34 -04:00
Jeremy Ashkenas
f13e363a87 Now that ?= is optimized, reverting the expansion. 2010-11-01 22:04:22 -04:00
Jeremy Ashkenas
83e6955dce Optimizing default arguments and existential assignment. 2010-11-01 22:01:52 -04:00
Jeremy Ashkenas
749e056618 reindenting grammar.coffee to the shared column, as much as possible. 2010-11-01 21:37:42 -04:00
Jeremy Ashkenas
c17efcf422 merging satyr/defarg 2010-11-01 21:33:07 -04:00
Jeremy Ashkenas
3ede624759 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-11-01 20:57:45 -04:00
Jeremy Ashkenas
67f1e04f3b merging in Trevor's --no-wrap deprecation 2010-11-01 20:57:43 -04:00
Jeremy Ashkenas
a4be3bceec Merge branch 'master' of git://github.com/TrevorBurnham/coffee-script 2010-11-01 20:53:49 -04:00
satyr
56391df345 dynakeys: optimized and fixed a bug in caching 2010-11-02 02:51:46 +09:00
satyr
4f4032c053 fixed a bug that compound assignments were declaring variables 2010-11-01 10:42:42 +09:00
Jeremy Ashkenas
195ca70278 tweaks to eval-fix 2010-10-30 17:35:54 -04:00
Trevor Burnham
776b1b723e Fixing --eval; see issue 820 2010-10-28 22:18:11 -04:00
Trevor Burnham
baef719908 Accepting --no-wrap, with a warning 2010-10-28 12:22:33 -04:00
Jeremy Ashkenas
6d8126e498 Removing the last Jison hack. (Jison 0.1.25) 2010-10-28 01:39:35 -04:00
Jeremy Ashkenas
6b4e437c93 CoffeeScript now compiled 'undefined' as 'void 0' 2010-10-27 22:50:20 -04:00
Jeremy Ashkenas
853d28860a Issue #801 -- Empty catch statements immediately preceding outdents. 2010-10-27 22:21:47 -04:00
Jeremy Ashkenas
62a1824400 Removing one of the Jison patches, no longer needed with 0.1.24 2010-10-27 22:14:00 -04:00
Jeremy Ashkenas
b3a4ce4e98 merging in parity checks. 2010-10-27 22:07:21 -04:00
Jeremy Ashkenas
42812a8dc0 Merge branch 'master' of http://github.com/michaelficarra/coffee-script 2010-10-27 22:06:55 -04:00
Jeremy Ashkenas
6e9cb27e46 Patching Jison (again) to fix 'Unexpected 1' -> 'Unexpected EOF' 2010-10-27 22:04:32 -04:00
satyr
1aba75e3e8 destructuring within arguments is now allowed as in SpiderMonkey 2010-10-27 05:23:35 +09:00
Michael Ficarra
0f577e0c94 good practice for parity checks 2010-10-26 11:35:23 -04:00
Jeremy Ashkenas
7170536021 Revert "aligned up some ifelses using leading then"
This reverts commit b84063bc3f.
2010-10-26 08:42:31 -04:00
satyr
1cb6464948 optimized splatting assignment 2010-10-26 20:51:02 +09:00
satyr
e36746d367 made [a..., b...] = c throw syntax error 2010-10-26 19:32:59 +09:00
satyr
371282fe7a defarg: (options = {}) where possible 2010-10-26 19:14:03 +09:00
satyr
96f74f9da8 grammar: refactored Param 2010-10-26 19:08:01 +09:00
satyr
4eeab947dd defarg: removed Splat::compileParam in favor of using the normal array destructuring against arguments 2010-10-26 18:57:32 +09:00
satyr
e7cc4e4faf implemented default arguments 2010-10-26 13:34:56 +09:00
satyr
ecd4722b7c removed a redundancy in splatted assignment 2010-10-26 13:33:03 +09:00
satyr
5a92b339a4 lexer: removed unused UNARY tokens 2010-10-26 09:29:13 +09:00
satyr
cb5642945a test: merged "expressions" into "chaining" and "returns" 2010-10-26 09:08:16 +09:00
satyr
b84063bc3f aligned up some ifelses using leading then 2010-10-26 06:02:38 +09:00
satyr
426d71cb4f leading then is now valid 2010-10-26 05:36:32 +09:00
satyr
b2be475f93 tidied up formatting I broke at ad79e142 2010-10-26 04:57:20 +09:00
satyr
ad79e142ca refactored operator parsing 2010-10-26 03:58:11 +09:00
satyr
0d6d221568 dynakeys: {(x), y} now compiles correctly 2010-10-26 01:40:07 +09:00
satyr
863f3f6b47 rewriter: (a): (b): (c) is now allowed 2010-10-26 00:56:03 +09:00
satyr
ff82c59903 rewriter: a: b: c is now valid 2010-10-26 00:38:28 +09:00
satyr
27cdafb2d0 nodes: @soakNode -> @soak 2010-10-25 22:31:52 +09:00
satyr
2aa093b65c removed extra lines from the compilation of trailing then with if/switch 2010-10-25 22:19:02 +09:00
satyr
1e984e78ca grammar: improved formatting consistency, using single quotes unless interpolated and wrapping lines that are too long 2010-10-25 21:37:08 +09:00
Jeremy Ashkenas
520d6a9d93 Comments are statements also, not just pure statements. 2010-10-24 21:53:48 -04:00
Jeremy Ashkenas
00220a9f2c replacing mistakenly-deleted nodes.coffee 2010-10-24 21:52:18 -04:00
Jeremy Ashkenas
6faff7c344 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-24 21:50:37 -04:00
Jeremy Ashkenas
0e5dd3d557 First draft of recompiling examples for 0.9.9 2010-10-24 21:50:34 -04:00
Timothy Jones
2ddae698bb Using a typeof check in scope. 2010-10-25 14:42:37 +13:00
Jeremy Ashkenas
99c06b5cda All examples now compile and lint cleanly. 2010-10-24 21:37:27 -04:00
Jeremy Ashkenas
343c0fdef7 top-level examples now compile and lint cleanly. 2010-10-24 21:34:40 -04:00
Jeremy Ashkenas
017e3a156e Removing breaks from the last switch case, and just disabling the lint warning instead. 2010-10-24 21:30:26 -04:00
Jeremy Ashkenas
12b217c8ec Adding break to default switch clauses to pass lint. 2010-10-24 21:26:24 -04:00
Jeremy Ashkenas
6a9c4380f3 Fixing scope.coffee -- we can't use a JS object as a hash that has to contain the word 'hasOwnProperty' 2010-10-24 21:23:32 -04:00
Jeremy Ashkenas
a75368e2e8 Fixing the REPL. 2010-10-24 21:15:20 -04:00
Jeremy Ashkenas
13f6b037e2 Working towards new versions of the examples. 2010-10-24 21:11:15 -04:00
Jeremy Ashkenas
c2da8c2d54 Removing extraneous semicolon, adding back in final break -- src now lints cleanly. 2010-10-24 20:51:55 -04:00
Jeremy Ashkenas
5b16d4790c Removing/Reverting do -> 2010-10-24 20:34:50 -04:00
satyr
101a044219 nodes: reformatted 2010-10-25 08:55:42 +09:00
satyr
7bfb2e3a78 nodes: removed Value.wrap 2010-10-25 08:13:58 +09:00
satyr
ab2050dc59 nodes: added Base::unwrapAll 2010-10-25 08:00:12 +09:00
satyr
98d22f9510 assigning to bizarre things like [a()] = b now causes syntax error 2010-10-25 07:33:41 +09:00
satyr
e146b539f5 optimized switch compilation 2010-10-25 06:20:45 +09:00
Jeremy Ashkenas
d1094e11a0 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-24 15:50:22 -04:00
Jeremy Ashkenas
02e94cdb1c removing forgotten print's 2010-10-24 15:50:18 -04:00
satyr
c8d994a97d invalid destructuring assignments like {0} = x now causes syntax error 2010-10-25 04:46:28 +09:00
Jeremy Ashkenas
e007f69c71 Adding xqjs, CUP, and Congo to the resources section. 2010-10-24 14:29:47 -04:00
Jeremy Ashkenas
08527075b7 Expanding __filename and __dirname when running with the coffee command -- Issue #771 2010-10-24 14:19:47 -04:00
Jeremy Ashkenas
6347849cd0 Switching parenthesized side in comprehensions. 2010-10-24 14:11:09 -04:00
Jeremy Ashkenas
b32a75858a further reduce predecence levels. 2010-10-24 14:04:06 -04:00
Jeremy Ashkenas
d6d46697d0 Issue #795 -- clean up low precedence levels 2010-10-24 14:02:59 -04:00
Jeremy Ashkenas
3a64e6a711 Removing -> and => from precendece-having operators. 2010-10-24 13:55:47 -04:00
Jeremy Ashkenas
ca90af4fa5 Removing duplicate 'UNLESS' 2010-10-24 13:54:29 -04:00
Jeremy Ashkenas
e822b2d43b Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-24 13:38:03 -04:00
Jeremy Ashkenas
3a16677ebf typo 2010-10-24 13:38:00 -04:00
satyr
d60aa9a80c removed extra lines from trailing then compilations 2010-10-25 01:58:00 +09:00
Jeremy Ashkenas
26a115adcf Removing the mixed-in sys/util module. Switching from 'puts' to console.log 2010-10-24 12:48:42 -04:00
satyr
aed0e8790e nodes: continue while .. over while .. then 2010-10-25 01:05:37 +09:00
Jeremy Ashkenas
cecae0f965 ObjectLiteral -> Obj, ArrayLiteral -> Arr 2010-10-24 11:35:47 -04:00
Jeremy Ashkenas
55bf6450e7 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-24 11:32:29 -04:00
Jeremy Ashkenas
95be4a61ec Merging in dynakeys 2010-10-24 11:32:23 -04:00
satyr
abef3f59be rebuilt parser and rewrote the asserts wrapping loop in Cakefile using do => 2010-10-25 00:14:58 +09:00
Timothy Jones
9619fa66eb Altered bound functions with do to just use call(this) rather than binding. 2010-10-25 00:18:54 +13:00
Timothy Jones
d096f69c78 Implemented rescoping with the do keyword. 2010-10-25 00:02:39 +13:00
Timothy Jones
f52ef98cee Removing unnecessary parens and removing the sudo recommendation for npm in the readme. 2010-10-24 23:45:47 +13:00
satyr
a458c4a905 dynakeys: can now do destructuring assignments 2010-10-24 17:56:34 +09:00
satyr
85c8a6780a dynakeys: can now be braceless 2010-10-24 15:39:11 +09:00
Timothy Jones
99deb8c670 Wrapping only the last line of comprehensions, allowing pure statements anywhere in between. 2010-10-24 18:36:23 +13:00
satyr
331036f86d 786: implemented dynamic object keys 2010-10-24 14:20:20 +09:00
Timothy Jones
291f377d40 Correcting version regex. 2010-10-24 15:05:11 +13:00
Michael Ficarra
4d4e758bf3 node 0.3 compliance 2010-10-23 21:48:58 -04:00
satyr
bfc236fca3 grammar: removed a remnant of Slice 2010-10-24 05:35:35 +09:00
satyr
b648b392b6 removed an extra garbage 2010-10-24 04:16:49 +09:00
satyr
89516e6ee1 added/fixed/tweaked a few tests and merged test_compound_assignment into test_assignment 2010-10-24 04:09:13 +09:00
satyr
0c3093f331 quit using __temp__ as placeholder name for anon class 2010-10-24 03:43:06 +09:00
satyr
ebdcfb5227 merged == and != into COMPARE 2010-10-24 03:30:16 +09:00
Timothy Jones
fc332bcfbd Easing leniency on pure statements. 2010-10-24 06:53:10 +13:00
Jeremy Ashkenas
e96cdbf67c resolving merge conflict. 2010-10-23 11:11:49 -04:00
Jeremy Ashkenas
2287b06aeb Reverting LEVEL object. 2010-10-23 11:10:28 -04:00
satyr
1335aee54b 783: corrected chained comparison precedence 2010-10-24 00:01:30 +09:00
Jeremy Ashkenas
6058910b49 Making the LEVEL constants a bit more readable. 2010-10-23 10:34:22 -04:00
Timothy Jones
b60afdb619 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-24 02:17:44 +13:00
Timothy Jones
3834e7bc33 Revert "Passing the arguments object directly when generating a closure."
This reverts commit 7b887f065d.
2010-10-24 02:15:01 +13:00
satyr
0942071517 fixed a regression that for-in was failing to cache the source value 2010-10-23 22:04:58 +09:00
Timothy Jones
7b887f065d Passing the arguments object directly when generating a closure. 2010-10-24 01:20:16 +13:00
Timothy Jones
e6fb3bcffb Spacing only + and - and only in a row. 2010-10-24 00:13:48 +13:00
Timothy Jones
9448a477d2 Spacing multiple operators. 2010-10-24 00:01:26 +13:00
satyr
2bc2c4717e nodes: refactored and removed the notion of o.top in favor of LVL_TOP 2010-10-23 19:18:04 +09:00
satyr
b82f495ec7 nodes: introduced a notion of levels that streamlines parenthesizations 2010-10-23 19:17:56 +09:00
satyr
1130f4fef5 refactored and added a test for a8da321 2010-10-23 03:00:09 +09:00
satyr
a8da321883 fixed a bug where multiple trailing comments prevented returnification 2010-10-23 02:30:38 +09:00
satyr
32e63cd130 nodes: removed some redundancies and unused methods 2010-10-23 01:47:28 +09:00
satyr
3df28a8a6a reverted "lexer: simplified tokenizers' responsibility" with magic numbers removed
This reverts commit 10442239f1.
2010-10-22 23:50:44 +09:00
Jeremy Ashkenas
10442239f1 Revert "lexer: simplified tokenizers' responsibility"
This reverts commit a9e95fa43b.
2010-10-22 08:13:40 -04:00
satyr
a9e95fa43b lexer: simplified tokenizers' responsibility 2010-10-22 14:56:51 +09:00
Jeremy Ashkenas
c92fd79f35 normalizing loop declarations towards common JS practice. 2010-10-21 21:51:06 -04:00
Jeremy Ashkenas
0342b0a89f merging the range-killer to master 2010-10-21 21:27:45 -04:00
satyr
341de42692 removed extra parens around simple values 2010-10-22 09:35:15 +09:00
Timothy Jones
f43ee4075d Removing empty parens from the grammar. 2010-10-22 11:29:03 +13:00
satyr
79148d2940 refactored loop variable caching 2010-10-22 02:07:00 +09:00
satyr
bd10c2f828 implemented for-from-to and removed dotted ranges 2010-10-21 23:06:50 +09:00
satyr
2f7c076a50 fixed a bug where in malfunctioned in commaed lists 2010-10-21 22:13:59 +09:00
Timothy Jones
880c5c8083 Fixing destructor in magicked for. Also making destructors in range loops syntax errors. 2010-10-22 00:34:51 +13:00
Jeremy Ashkenas
7596e3a157 putting back arguments. 2010-10-21 00:07:21 -04:00
satyr
cb9683a7fd fixed/removed broken/redundant tests 2010-10-21 12:45:50 +09:00
Jeremy Ashkenas
0d4d7e0880 indentation 2010-10-20 23:16:46 -04:00
Jeremy Ashkenas
bb080130b9 tweaks to scope 2010-10-20 23:09:06 -04:00
Timothy Jones
f229f791a9 Proper testing, this time. 2010-10-21 14:37:58 +13:00
Timothy Jones
e694b41a94 Operators now respect new lines as being spaced. 2010-10-21 14:27:25 +13:00
satyr
31746ce692 made In node invertible 2010-10-21 09:19:52 +09:00
satyr
53fbfc7d15 removed extra parens from in/return compilations 2010-10-21 07:19:08 +09:00
satyr
78835073db removed extra parens from array/index compilations 2010-10-21 06:07:58 +09:00
satyr
c11ca94870 removed extra parens from soak compilations 2010-10-21 04:51:11 +09:00
satyr
c1dc74fc8b removed extra parens from compilations with assignments or conditional operators 2010-10-21 02:29:06 +09:00
satyr
e2a6f292a2 nodes: refactored to reduce parens 2010-10-20 19:53:41 +09:00
satyr
b0a4b7ab85 scope: refactored 2010-10-20 17:13:43 +09:00
Timothy Jones
8d6b909b93 Removing the utterly pointless splice in scope for the much more reasonable assignment. 2010-10-20 19:51:53 +13:00
Jeremy Ashkenas
303be86291 resolving merge conflict. 2010-10-19 23:31:19 -04:00
Jeremy Ashkenas
113d7ce98f let's try to merge these indexOf patches. 2010-10-19 23:27:15 -04:00
satyr
2c84f3ed1f removed helpers.{indexOf,include} in favor of in operator 2010-10-20 12:20:10 +09:00
Jeremy Ashkenas
c1d24944dc inArray -> indexOf ... 2010-10-19 23:06:51 -04:00
Jeremy Ashkenas
35b6a70724 going back to the Closure Compiler. 2010-10-19 21:59:13 -04:00
Jeremy Ashkenas
54d9b283fa Merge branch 'master' of http://github.com/stephank/coffee-script 2010-10-19 21:52:39 -04:00
satyr
90a13bd791 compound assignments are now represented as Assign nodes (rather than Op) and have the same precedence as = 2010-10-20 09:50:42 +09:00
Timothy Jones
15cfe8ebf1 Restoring garbage collection. 2010-10-20 12:58:59 +13:00
Timothy Jones
8c4a48d9d0 Adjusting refactor to better emulate map. 2010-10-20 12:51:34 +13:00
Timothy Jones
8fff6e9baf Refactoring scope to use an array instead of an object, to make the IE bugfix significantly tidier. 2010-10-20 12:36:50 +13:00
Timothy Jones
7342058e64 Comment fix. 2010-10-20 12:05:34 +13:00
Timothy Jones
083fc61dfb Fixing IE DontEnum bug in Scope. Ignoring everywhere else. 2010-10-20 12:02:38 +13:00
Timothy Jones
502d444ebd Reversing evaluation order of __inArray to reflect the ordering of the in operator. 2010-10-20 09:52:11 +13:00
Timothy Jones
c3582d4058 One character fix, for the sake of consistency. 2010-10-20 08:57:23 +13:00
Timothy Jones
37d9204ad9 Tidying inArray utility. 2010-10-20 08:47:34 +13:00
Timothy Jones
a3500e807a Avoids unnecessary temporary in comprehensions with pure statements in them. 2010-10-20 07:57:40 +13:00
Timothy Jones
1442262376 Merge branch 'master' of http://github.com/TrevorBurnham/coffee-script into trevor 2010-10-20 07:43:07 +13:00
Trevor Burnham
33ac70aec3 Whitespace fix for unstepPart (thanks, Tesco) 2010-10-19 14:24:38 -04:00
Trevor Burnham
5005cb606f Fixing inconsistencies for index variables
See the tests added to test_comprehensions.coffee. Previously, after
`for i in [1..3]`, i was 4. Also, index variables were never set to
any value in comprehensions containing both a closure and a break or
return.
2010-10-19 14:09:16 -04:00
Stéphan Kochen
c458346593 In compileScripts, run base through path.join.
Allows `path.join` to do some processing on the base path
that was also happening on the full path.
Fixes: `coffee -o ./ ./`
Still broken: `coffee -o . .`
2010-10-19 18:36:27 +02:00
Timothy Jones
c64e8d4b53 Added the __inArray helper to clean up code and speed up searches. 2010-10-20 05:34:03 +13:00
Stéphan Kochen
e5dfa19ec9 Report errors when writing files in coffee. 2010-10-19 18:30:29 +02:00
Timothy Jones
0e395569ee Fixing #761. p -1 now translates to p(-1), not p - 1. Same with +. 2010-10-20 04:52:07 +13:00
Timothy Jones
262d796356 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-20 04:11:25 +13:00
Timothy Jones
cf5a086263 Removing accidental superfluous temp variables. 2010-10-20 04:07:10 +13:00
Timothy Jones
d14ba6ac53 Fixed comprehension magic's scoping. 2010-10-20 03:59:01 +13:00
Timothy Jones
7b1902183c Just catch alls for inner scoping now. 2010-10-20 03:53:38 +13:00
Timothy Jones
cb6be74851 Fixing for magic scoping issues. Small steps at a time. 2010-10-20 02:51:52 +13:00
Jeremy Ashkenas
9e03c66529 Merge branch 'master' of git://github.com/Tesco/coffee-script 2010-10-19 09:13:41 -04:00
Jeremy Ashkenas
f6b190bb5a Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-19 09:13:21 -04:00
Jeremy Ashkenas
3f89fea65a fixing resig link 2010-10-19 09:13:09 -04:00
Timothy Jones
c8b9c5a54e Fixing #774. Strict equality operator, which wasn't supported in the grammar anyway, is removed from the lexer. 2010-10-19 20:56:55 +13:00
Timothy Jones
fd268a0479 Fixed #763. SimpleAssignables are now the only possible recepients of ++, -- and compound assignments. 2010-10-19 20:48:39 +13:00
Timothy Jones
648d6432eb Fixing #700. Block comment for constructor now appears above the constructor declaration. 2010-10-19 20:39:58 +13:00
Timothy Jones
df46fb8c68 Fixing #600. JS statements that must be expressions but contain pure statements cause syntax errors. 2010-10-19 20:02:21 +13:00
Timothy Jones
d9cd75c426 Fixing #773. Statements cannot be wrapped in parens (as in JS). 2010-10-19 19:32:23 +13:00
satyr
87560d943c lexer: made REGEX more efficient 2010-10-18 07:43:29 +09:00
satyr
8d0a0e8ab1 nodes: Value.unfoldSoak -> If.unfoldSoak 2010-10-17 13:53:02 +09:00
satyr
55794d9534 nodes: soaking Call now converts to If using the same logic as soaking Accessor 2010-10-17 13:19:51 +09:00
Jeremy Ashkenas
84dcd6fe2f Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-14 17:17:42 -04:00
satyr
88cc1ee35d 765: -b/--bare <- --no-wrap 2010-10-14 04:09:56 +09:00
Michael Ficarra
6e89ad3401 test case for #768 2010-10-13 12:12:24 -04:00
Michael Ficarra
1ea38d2f93 fixing #768, preserving execution order of in arguments when compiled
to an `or`.
2010-10-13 12:10:36 -04:00
satyr
1d4d7e96fa quit using sp?licing ranges 2010-10-13 05:47:45 +09:00
satyr
67eb966a75 stripped a line from __extends 2010-10-13 04:57:11 +09:00
Daniel J. Pritchett
ceef24834c spelling tweak to index.html 2010-10-12 14:54:02 -05:00
satyr
cb2a7f0820 simplified splatting new compilation 2010-10-12 21:48:25 +09:00
satyr
8f29574b16 764: made boolean/number/regex indexable 2010-10-12 19:30:10 +09:00
satyr
c0ec479e60 browser: exposed require for debugging 2010-10-12 17:10:39 +09:00
satyr
54101a1c9b lexer: reorganized JS_KEYWORDS 2010-10-12 16:25:33 +09:00
satyr
43613498db Merge branch '542' 2010-10-12 11:29:33 +09:00
satyr
ac841ca4e9 nodes: object literals are now parenthesized based on @tags.front (which indicates if the node leads an expression statement), fixing #542 2010-10-12 11:26:55 +09:00
satyr
95d86758ee test.html: string_interpolation -> strings 2010-10-12 10:34:31 +09:00
satyr
ed79715841 stripped out strings/regexes from test_literals; test_string_interpolation is now test_string 2010-10-12 09:35:59 +09:00
satyr
b01d7db409 merged test_blocks into test_functions 2010-10-12 08:54:36 +09:00
satyr
e5fe145f80 destructuring assignment no longer uses a temporary variable for simple LHS 2010-10-12 07:58:11 +09:00
Jeremy Ashkenas
2642fde0f8 merging in the browser test suite. 2010-10-11 18:22:01 -04:00
satyr
f682bf642f followup to #717; made new => actually work 2010-10-12 07:02:04 +09:00
satyr
5ed69a5a58 added test.html that runs most of test/*.coffee in browsers 2010-10-12 06:53:20 +09:00
Jeremy Ashkenas
a4b6b2464c merging in sstephenson's test:browser 2010-10-11 16:55:17 -04:00
Jeremy Ashkenas
4f89245570 NEXT_ELLPSIS.test 2010-10-11 16:34:16 -04:00
Sam Stephenson
5236bb279d Remove the window hack in test:browser. 2010-10-11 12:27:05 -05:00
Sam Stephenson
967fec2ae5 Merge branch 'master' into newline-splat
Conflicts:
	lib/lexer.js
	lib/parser.js
	src/lexer.coffee
2010-10-11 12:12:13 -05:00
Jeremy Ashkenas
d7052d09ff tweaking compileWithDeclarations 2010-10-11 12:27:57 -04:00
Jeremy Ashkenas
acc06d772a Back four commits ... Fixing named function expressions -> function declarations for IE. (grumble grumble) 2010-10-11 12:13:01 -04:00
Sam Stephenson
f360fba47f Add test:browser task for running the test suite against the merged browser script. 2010-10-11 09:42:13 -05:00
Jeremy Ashkenas
de0b93381c switching to YUI compressor for the time being... ticket #575 2010-10-11 08:40:15 -04:00
Jeremy Ashkenas
42d39d59dd rebuilding browser.js 2010-10-11 08:13:59 -04:00
Jeremy Ashkenas
bfed78a996 rebuilding lexer 2010-10-11 08:06:27 -04:00
satyr
9c55bd59a1 fixed a bug where while condition was compiling as statement 2010-10-11 20:29:08 +09:00
satyr
e89d7a7756 lexer: fixed a regression where assignmentError wasn't fired 2010-10-11 19:10:30 +09:00
satyr
41cd0c272b grouped TRUE/FALSE/NULL into BOOL 2010-10-11 17:05:50 +09:00
satyr
6506f6d99e grammar: removed extra arrays 2010-10-11 16:06:29 +09:00
satyr
fffa01933d fixed misdentation in a?.b = c 2010-10-11 12:31:54 +09:00
satyr
acafb1b53a nodes: no longer uses helpers.indexOf 2010-10-11 09:40:41 +09:00
satyr
c437f0b14b made until less parenful as well 2010-10-11 07:29:38 +09:00
Sam Stephenson
20a07c174c Fixing splats after newlines - #754. 2010-10-10 11:34:22 -05:00
Sam Stephenson
6e6165796c noWrap: true -> wrap: false 2010-10-10 11:55:01 -04:00
Jeremy Ashkenas
f6ca5d814c Issue #748 -- trailing reserved idenitifer. 2010-10-10 11:42:25 -04:00
Jeremy Ashkenas
45ed62931b #749 -- adding CoffeeApp mention 2010-10-10 11:33:03 -04:00
Jeremy Ashkenas
9c54291d04 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-10 11:29:29 -04:00
Jeremy Ashkenas
e8d592cdc6 Fixing issue #751 ... implicit number arguments within implicit object literals. 2010-10-10 11:29:14 -04:00
satyr
24a0015148 lexer: made REGEX more accurate 2010-10-10 07:32:49 +09:00
satyr
b0e34edf99 soak accesses no longer consume corresponding operators 2010-10-10 07:10:20 +09:00
satyr
c5f922c5db coffee-script: tokens/nodes can now take options as well 2010-10-09 04:27:05 +09:00
satyr
ebdd57a2fe rewriter: detectEnd no longer passes undefined as token, fixing #750 2010-10-09 04:00:07 +09:00
Jeremy Ashkenas
b21057d166 fixing issue #745 ... precedence of huh operator. 2010-10-07 22:22:33 -04:00
satyr
4f486bc444 removed YES/NO/ON/OFF from rewriter/parser 2010-10-08 00:56:01 +09:00
satyr
9447796d8e made unless less parenfull 2010-10-07 20:05:22 +09:00
satyr
c7157ca90c quit caching v in for all k of v 2010-10-07 15:31:40 +09:00
satyr
250ec12646 Parenthetical -> Parens 2010-10-07 12:59:36 +09:00
satyr
2d9cff3af6 nodes: removed literal helper 2010-10-07 12:41:09 +09:00
satyr
95bc4c5eeb reenabled stricter caching on For compilation as well as reduced a line from it 2010-10-07 12:31:05 +09:00
Jeremy Ashkenas
30a18fdaeb Removed the silly 'Node' suffix from everything. 2010-10-06 22:44:32 -04:00
Jeremy Ashkenas
13774cf48a empty returns no longer return null 2010-10-06 22:24:52 -04:00
Jeremy Ashkenas
69d2048ccc Re-enabling garbage collection of tempvars, only at function boundaries. 2010-10-06 21:19:05 -04:00
Jeremy Ashkenas
d4dac214ab optimizing comprehensions source references 2010-10-06 21:13:11 -04:00
Jeremy Ashkenas
5605ba32e3 merge conflict 2010-10-06 20:54:48 -04:00
Jeremy Ashkenas
59d6e59f97 Fixing Issue 730 -- and removing garbage collection of tempvars (which was totally unsafe.) 2010-10-06 20:54:08 -04:00
satyr
f90f1ef8e0 nodes: re{name,formatt}ed things 2010-10-07 09:28:53 +09:00
Jeremy Ashkenas
69b901a5b6 Fixing Issue #744 -- you can now use reserved words as static properties of a class. 2010-10-06 20:07:19 -04:00
Jeremy Ashkenas
af2e866947 rebuilding documentation 2010-10-05 21:05:57 -04:00
Jeremy Ashkenas
17eaf63c6d Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-05 21:02:05 -04:00
Jeremy Ashkenas
e2176a6521 whitespace 2010-10-05 21:02:03 -04:00
satyr
2e6b50335f lexer now distinguishes between IN/OF and FORIN/FOROF to help grammar, fixing #737 2010-10-06 04:46:17 +09:00
satyr
380bee97dd nagated relational operators are now grouped into NOT_RELATED, fixing #720 2010-10-06 00:43:44 +09:00
satyr
1e60c4c4d2 lexer: had some aligning fun 2010-10-05 23:31:48 +09:00
Jeremy Ashkenas
be0051ee69 s/lookahead/non-capturing 2010-10-05 00:34:49 -04:00
Jeremy Ashkenas
c79a7b5055 removing dollar-prefixed local vars (let's keep 'em for globals only) 2010-10-05 00:23:04 -04:00
Jeremy Ashkenas
08388fea5a testing issue 584 2010-10-05 00:16:55 -04:00
Jeremy Ashkenas
8bc706a94e Merging in heregexes 2010-10-05 00:11:28 -04:00
Jeremy Ashkenas
6f9ac01e71 redo-ing nodes.coffee with named classes. 2010-10-04 23:24:46 -04:00
Jeremy Ashkenas
19a92a4493 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-04 23:21:22 -04:00
Jeremy Ashkenas
2b66d5d6c0 First draft of named classes. 2010-10-04 23:21:16 -04:00
satyr
0ada1dfc3f follow-up to d1bca636; fixed unrolling of the single case ({@a} = o -> @a = o.a) 2010-10-05 12:04:44 +09:00
Timothy Jones
645075f910 All classes now named. 2010-10-05 15:52:33 +13:00
Jeremy Ashkenas
9fd031c896 tweaking the previous commit's test. 2010-10-04 22:12:30 -04:00
Jeremy Ashkenas
e14737dd88 tweaking the previous commit's test. 2010-10-04 22:12:22 -04:00
Jeremy Ashkenas
d1bca6364a Enchancing pattern matching with @vars ... issue #721 2010-10-04 22:10:10 -04:00
Jeremy Ashkenas
8eb283df2c Merge branch 'catchless' of http://github.com/satyr/coffee-script 2010-10-04 20:45:38 -04:00
Jeremy Ashkenas
b4d40c7501 Merge branch 'master' of github.com:jashkenas/coffee-script 2010-10-04 20:25:45 -04:00
Jeremy Ashkenas
ee8f53dd77 fixing @property = value typo. 2010-10-04 20:25:32 -04:00
satyr
d85910c17f made catch optional 2010-10-05 05:53:32 +09:00
satyr
42a91219cb fixed over-escaping in here documents and addressed Stan's comments 2010-10-05 03:47:50 +09:00
satyr
cdd033ffb0 disabled interpolations in normal regexes 2010-10-04 21:51:04 +09:00
satyr
493fa7d8fe heregex: now allows bare slashes and empty body 2010-10-04 11:55:49 +09:00
satyr
c605b3e232 first stub at heregex 2010-10-04 08:22:42 +09:00
satyr
ae55c70ac5 647: fixed quote/newline escaping in here documents 2010-10-03 07:50:41 +09:00
satyr
769870b493 [x] = [y] = [1] works again 2010-10-02 21:49:21 +09:00
satyr
765f57b658 refactored rewriter 2010-10-02 21:21:10 +09:00
satyr
a59d056ad2 [v] = a now compiles to v = a[0] 2010-10-02 20:53:29 +09:00
satyr
f7e6dabf6b fixed a regression where destructuring for miscompiles 2010-10-02 20:19:37 +09:00
Jeremy Ashkenas
baaec57d5c Fixing Issue #738 -- rewriter skips a token. 2010-10-01 21:02:48 -04:00
Jeremy Ashkenas
26de26f88f conditionals with no alternative now evaluate to 'undefined' instead of 'null' 2010-10-01 20:52:23 -04:00
satyr
4fd878447e nodes: removed o.chainRoot which went unused 2010-10-02 08:33:57 +09:00
satyr
8cdee9c0f4 ensured arguments in each scope 2010-10-02 08:21:34 +09:00
satyr
dafe6b09c5 removed remnant of 341f511b 2010-10-02 07:47:28 +09:00
satyr
2ea549ce5f made ForNode avoid needless cachings 2010-10-02 07:26:37 +09:00
satyr
341f511bbd #733: streamlined soak compilations and improved reference cachings 2010-10-02 07:17:35 +09:00
satyr
54f162e523 made --nodes output soak-aware 2010-09-30 05:29:20 +09:00
satyr
b5261abb6b nodes: made ExistenceNode omit typeof for known variables 2010-09-29 11:30:05 +09:00
satyr
9bc613e4a7 nodes: added THIS 2010-09-29 11:29:17 +09:00
Jeremy Ashkenas
5967b48348 Correcting contributor link in readme 2010-09-28 20:17:23 -04:00
Jeremy Ashkenas
b0f49be19e Can't rely on Array.isArray ... 2010-09-28 20:12:37 -04:00
Jeremy Ashkenas
35f395a0e4 Merge branch 'master' of http://github.com/stephank/coffee-script 2010-09-28 20:08:27 -04:00
Jeremy Ashkenas
61852aaddc Turning off a couple more warnings we'd like to ignore in JavaScriptLint. 2010-09-28 20:04:10 -04:00
satyr
7450df8104 #713: destructuring assignment is no longer statement and correctly returns RHS value 2010-09-29 05:47:12 +09:00
Stéphan Kochen
52e7d9a672 Fixing #723; switch cases not iterated by eachChild. 2010-09-28 20:28:05 +02:00
Stéphan Kochen
8f96f5f20f Added a (failing) test that reproduces #723. 2010-09-28 20:27:37 +02:00
satyr
b2313beaf4 added last to helpers 2010-09-29 00:10:03 +09:00
Jeremy Ashkenas
c064c90ee9 Issue #706 -- enchancing empty anonymous classes. 2010-09-27 23:59:47 -04:00
Jeremy Ashkenas
2e3f575f9c Fixing issue #276 -- unsoaked cached indexes. 2010-09-27 23:23:08 -04:00
Jeremy Ashkenas
dc0b03e54e linking to *all* the contributors in the readme. 2010-09-27 22:56:49 -04:00
Jeremy Ashkenas
bd08d06de3 Merge branch 'unary-new' of http://github.com/satyr/coffee-script 2010-09-27 22:52:40 -04:00
Jeremy Ashkenas
8568441221 merging in satyr's fix for #653 2010-09-27 22:17:46 -04:00
Jeremy Ashkenas
a3adc9c1b6 Merge branch '653' of http://github.com/satyr/coffee-script 2010-09-27 22:13:15 -04:00
Jeremy Ashkenas
e3ec325619 rebuilt the site with some IE fixes. 2010-09-27 15:21:45 -04:00
Jeremy Ashkenas
3c848736a7 Removing 'where' from COFFEE_KEYWORDS, and adding a missing equals sign to a test. 2010-09-27 10:16:34 -04:00
satyr
3bba51d5d9 made nodes cache more aggressively, fixing #653 2010-09-27 17:56:56 +09:00
satyr
72c83f5e43 updated tests toward fixing #653 2010-09-27 16:34:00 +09:00
satyr
159150c319 "cake test" now wraps all of the "assert" module to update test counts 2010-09-27 14:17:05 +09:00
satyr
bc87d9ed3d made --nodes output prettier 2010-09-27 04:47:52 +09:00
satyr
e188b9ff41 unary-new: built parser and new => now works 2010-09-27 02:16:41 +09:00
satyr
db531495b8 unary-new: merged master 2010-09-27 01:22:33 +09:00
Jeremy Ashkenas
ecb23d15c4 Merging in satyr's rewrite-lexer.coffee 2010-09-26 10:57:03 -04:00
Jeremy Ashkenas
bd047cbb4f Merge branch 'lexer-refactor' of http://github.com/satyr/coffee-script 2010-09-26 10:40:49 -04:00
Jeremy Ashkenas
008d2ba0d3 adding a cake:bench task 2010-09-26 10:38:28 -04:00
Jeremy Ashkenas
45bd0854b6 Merging in satyr's helpers-refactor 2010-09-26 10:28:48 -04:00
satyr
3e0c35bd0f lexer: enabled multiline interpolations 2010-09-26 07:06:14 +09:00
satyr
7945178f3a lexer: unrolled @extractNextToken/@match 2010-09-26 07:01:24 +09:00
satyr
19f08888e8 lexer: more regexes fixes 2010-09-26 06:57:23 +09:00
satyr
c515aaac5a lexer: fixed ASSIGNED 2010-09-25 23:37:33 +09:00
satyr
0b3b0ab68b unary-new: added tests 2010-09-25 18:13:37 +09:00
satyr
c24e1eacb9 (experimental) made new a unary operator 2010-09-25 17:39:19 +09:00
satyr
9a3b736174 lexer: fixed broken logics (due to f051d088) and a snakecased variable 2010-09-25 16:18:31 +09:00
satyr
e0ed254252 helpers: now directly exported 2010-09-25 09:29:44 +09:00
satyr
9005682cf1 helpers: refactored and fixed comments 2010-09-25 09:18:47 +09:00
satyr
3df82a757d helpers: added test 2010-09-25 09:15:47 +09:00
satyr
3fd7f9efdd added a test for JS literal 2010-09-24 23:06:49 +09:00
satyr
d457423c24 made simple strings shortcut 2010-09-24 22:38:28 +09:00
satyr
f051d0880e lexer: improved logics 2010-09-23 14:14:18 +09:00
satyr
ed501ea37e lexer: improved consistency, preferring charAt, slice and single quotes 2010-09-23 14:11:31 +09:00
satyr
20dae3758a lexer: optimized regexes 2010-09-23 14:05:30 +09:00
Jeremy Ashkenas
a04e17c4ea Merge branch 'master' of http://github.com/sstephenson/coffee-script 2010-09-22 23:32:56 -04:00
Jeremy Ashkenas
fc149fdada merging in satyr/for-of-diet 2010-09-22 23:26:11 -04:00
Jeremy Ashkenas
19dfe4b01d merging Tim's filename branch. 2010-09-22 22:44:42 -04:00
Tim-Smart
c4a3e170e2 Support for older revisions of Node.js for CoffeeScript.run() 2010-09-23 14:41:38 +12:00
Tim-Smart
dfd6025d04 Remove (compiled) from filenames, to keep __filename accurate 2010-09-23 11:55:05 +12:00
Sam Stephenson
01c14bc640 Heredoc indentation detector ignores blank lines without trailing whitespace. 2010-09-22 08:47:43 -05:00
Jeremy Ashkenas
c435647589 removing the ability to force an if/else chain to be compiled as a statement. Ternaries will now be used as much as possible. 2010-09-22 00:41:17 -04:00
Jeremy Ashkenas
c50cf23b7b CoffeeScript 0.9.4 2010-09-21 23:58:05 -04:00
satyr
540783a6dd removed useless property accesses from for-of 2010-09-22 12:55:19 +09:00
Jeremy Ashkenas
25c8b4b34f Using the Array spaces trick to generate padding and indentation. 2010-09-21 23:17:43 -04:00
Jeremy Ashkenas
c0a89a7988 Fixing issue #700, block comment after first line of class definition. 2010-09-21 23:13:46 -04:00
Jeremy Ashkenas
07d9e9b71e fixing up block comment indentation boondoggle. 2010-09-21 22:59:28 -04:00
Jeremy Ashkenas
269f4e8da8 Tweaks to browser.coffee 2010-09-21 22:31:59 -04:00
satyr
481c3d536b made browser.coffee override Node dependent exported methods 2010-09-22 01:05:00 +09:00
Jeremy Ashkenas
7e5db250d3 Merge branch 'master' of git://github.com/StanAngeloff/coffee-script 2010-09-21 08:06:12 -04:00
Jeremy Ashkenas
970bfbe151 Merge branch 'repl' of git://github.com/Tim-Smart/coffee-script 2010-09-21 08:05:03 -04:00
Jeremy Ashkenas
7d98bb216a merged in satyr's leakless branch. 2010-09-21 08:02:22 -04:00
satyr
e4b7d06f35 removed browser specific hacks from src/* by making "rake browser" provide fake require and exports 2010-09-21 18:37:44 +09:00
satyr
b19c004680 made wrapper function keep current this 2010-09-21 16:53:58 +09:00
satyr
7bc91bf6c6 removed global dependency from grammer 2010-09-21 16:50:32 +09:00
Tim-Smart
c49cd02365 Fix REPL. Add CoffeeScript.eval method as run doesn't return result. 2010-09-21 17:36:23 +12:00
Stan Angeloff
992f4192bf Re-compiling core with new temporary variable names, all tests pass. 2010-09-21 07:55:08 +03:00
Stan Angeloff
921ab3ce68 Using old temporary variable name generation for single-letter types
(e.g., i, j, k, and so on).
2010-09-21 07:53:52 +03:00
Jeremy Ashkenas
69942c9a81 commenting out the failing test for the time being, to be fixed later. 2010-09-21 00:14:22 -04:00
Jeremy Ashkenas
fb5158630a fixing herecomment newlines. 2010-09-21 00:06:03 -04:00
Tim-Smart
34c29b3406 Cleaner stack traces.
- Improves run() function
- Re-sets the module.filename to add (compiled)
2010-09-21 15:32:37 +12:00
Jeremy Ashkenas
c0796da7b9 hacking around Jison patch to remove module dependency. 2010-09-20 23:13:02 -04:00
Jeremy Ashkenas
83651a7d6a merging in Tim's registerExtension fix for the latest Node master. 2010-09-20 22:27:04 -04:00
Jeremy Ashkenas
10d57705a0 Merge branch 'registerExtension' of git://github.com/Tim-Smart/coffee-script 2010-09-20 22:24:19 -04:00
Jeremy Ashkenas
71998e06cf Merge branch 'master' of http://github.com/leobm/coffee-script 2010-09-20 22:14:41 -04:00
Jeremy Ashkenas
a16594ed7b Merging in Stan's temporary_junk improvements. 2010-09-20 22:13:08 -04:00
Jeremy Ashkenas
f7fce3cd68 tweaking compiled tempvar names to satisfaction. 2010-09-20 21:56:18 -04:00
Tim-Smart
ba850790ed Add require.extensions support. 2010-09-21 13:23:45 +12:00
Jan-Felix Wittmann
abc1e83319 fix invalid testcase 2010-09-20 12:02:16 +02:00
Stan Angeloff
99a06ce4ea Updating name for cached length temporary variables to '_length', 'length2', and
so on.
2010-09-20 08:42:31 +03:00
Stan Angeloff
31441868e0 Allowing temporary variables to be reused. 2010-09-19 19:34:27 +03:00
Jeremy Ashkenas
5d82dddfb1 merging in Stan's temporary variables. 2010-09-19 12:00:16 -04:00
Stan Angeloff
d568b56c5e First attempt at allowing temporary variables to be reused. 2010-09-19 17:47:26 +03:00
Stan Angeloff
3ab0c12bf1 Don't store tempVars as we can get the next available one from scope. 2010-09-19 17:03:45 +03:00
Stan Angeloff
ed74f42323 Refactoring temporary name generation in a separate method, no
functional changes.
2010-09-19 16:18:01 +03:00
Jeremy Ashkenas
15d84dbb4e Fixing issue #694. Destructuring assignment as first line of implicitly called block -- regression. 2010-09-19 09:04:38 -04:00
Stan Angeloff
65fa0411b4 Part of previous commit: updating how temporary variables are generated.
We no longer need to store the name of the last generated variable,
instead we store the index.
2010-09-19 15:50:17 +03:00
Stan Angeloff
408833daef Removing code added during the migration. freeVariable(..) is called with
a `type` at all times.
2010-09-19 15:37:26 +03:00
Stan Angeloff
bb35b3e3b2 Re-compiling core with new changes. All tests pass. 2010-09-19 15:29:15 +03:00
Stan Angeloff
4a3e1fb0cb Updating nodes.coffee to make use of new temporary variables code
generators.
2010-09-19 15:28:22 +03:00
Stan Angeloff
fe68261bc2 Added generator for custom free variable types, e.g., '_cache',
'_cache2', and so on.
2010-09-19 14:55:19 +03:00
Stan Angeloff
1f2c6c77fd s/tempVars/tempVars.general/ This should allow us to store more than one
category of temporary variables.
2010-09-19 14:36:37 +03:00
Jeremy Ashkenas
08e1101c1f fixing static class properties that are implicit objects. 2010-09-18 22:25:45 -04:00
Jeremy Ashkenas
72847b9b26 tweak to block indentation test. 2010-09-18 13:20:32 -04:00
Jeremy Ashkenas
4b2d40d3b5 Merging in Stephank's fix for #692. 2010-09-18 10:36:48 -04:00
Stéphan Kochen
72d7fe2f7a Function soaks should preserve this. Fixes issue #692. 2010-09-18 12:27:14 +02:00
Jeremy Ashkenas
43f7f6c355 documenting 'invoke' in Cakefiles a little bit. 2010-09-17 20:24:10 -04:00
Jeremy Ashkenas
a53c104db1 simpler default Try CoffeeScript scriptlet. 2010-09-16 00:41:13 -04:00
Jeremy Ashkenas
2a0bd1adc7 silencing another JavaScriptLint extraneous warning. 2010-09-16 00:36:46 -04:00
Jeremy Ashkenas
a2631759c0 CoffeeScript 0.9.3 2010-09-16 00:32:57 -04:00
Jeremy Ashkenas
2b87cabbb4 removing now-unused logic from the IfNode, that used to handle switch statements. 2010-09-15 23:48:20 -04:00
Jeremy Ashkenas
d8465ce767 First draft of real switch statements for CoffeeScript switch statements. 2010-09-15 23:46:01 -04:00
Jeremy Ashkenas
60f80e2698 Fixing the double-implicit-call-into-implicit-object problem. 2010-09-15 22:29:03 -04:00
Jeremy Ashkenas
c782c2ec1c Fix for issue #685. Over-aggressize heredoc cleanup when there is no leading indentation. 2010-09-15 22:08:13 -04:00
Jeremy Ashkenas
f0d778ce49 moving addImplicitBraces and addImplicitParentheses next to each other ... perhaps they should interleave. 2010-09-14 22:57:01 -04:00
Jeremy Ashkenas
a3c224e57a Fixing issue #676, chained accesses against the super() keyword. 2010-09-12 16:33:38 -04:00
Jeremy Ashkenas
b727245834 better error for external super() call. 2010-09-12 16:25:00 -04:00
Jeremy Ashkenas
6b19e61bd0 simplifying previous commit 2010-09-12 16:20:01 -04:00
Jeremy Ashkenas
38ce0cfd9a running cacheindexes on soaks that need them. 2010-09-12 16:18:05 -04:00
Jeremy Ashkenas
61a39e04fc Issue #680. @::prop versus this::prop, fixed lexing regex. 2010-09-12 15:48:31 -04:00
Jeremy Ashkenas
ea3aa6803a using @containsType. 2010-09-12 14:44:03 -04:00
Jeremy Ashkenas
3a20d7dacb Partial fix for 653. 2010-09-12 11:08:05 -04:00
Timothy Jones
e5837b4ee9 Actually caching the splatted constructor this time. 2010-09-12 01:49:25 +12:00
Timothy Jones
d1f31c5143 Ensuring constructors invoked with splats behave correctly, along with caching. 2010-09-12 01:28:22 +12:00
Jeremy Ashkenas
4af41e9bfb Fixing issue #678 -- missing parentheses in a mixed operation(call(soak)) 2010-09-11 08:39:14 -04:00
Jeremy Ashkenas
121110a485 Adding Roast to the Resources. 2010-09-10 15:41:35 -04:00
Jeremy Ashkenas
d41a414b5c Complexifying the indebt test, one more level. 2010-09-08 22:48:28 -04:00
Jeremy Ashkenas
9bd3cca7c4 Introducing the notion of 'indebt' to mirror 'outdebt', but for suppressed indentation with trailing operators etc. Issue #639. 2010-09-08 22:46:13 -04:00
Jeremy Ashkenas
18cbddff6a Fix for Issue #655. Leading empty commas in ArgLists are now disallowed. 2010-09-08 21:39:51 -04:00
Jeremy Ashkenas
df414dab02 Issue #665. Recompile on --watch when file changes size, or mtime changes. 2010-09-08 21:08:17 -04:00
Jeremy Ashkenas
904207ba8f throwing errs from fs.readFile in watch mode. 2010-09-08 20:55:34 -04:00
Jeremy Ashkenas
44618d5765 Adding a test for Issue #669 2010-09-08 20:25:17 -04:00
Jeremy Ashkenas
70cfd54ad4 Issue #670. 'THIS' tokens should trigger an implicit call. 2010-09-08 20:15:16 -04:00
Jeremy Ashkenas
62bf0a2bc9 Merge branch 'master' of git://github.com/StanAngeloff/coffee-script 2010-09-08 09:03:42 -04:00
Jeremy Ashkenas
c9289155b4 Merge branch 'master' of git://github.com/chrislloyd/coffee-script 2010-09-08 09:03:03 -04:00
Chris Lloyd
cd67ec6e69 Bad variable name clobbers correct path in compile event. 2010-09-08 14:51:59 +02:00
Stan Angeloff
cd6261d477 Fixed #669: Wrapper arguments 2010-09-08 15:18:08 +03:00
Jeremy Ashkenas
3b60aad487 simplifying RangeNode grammar a bit. 2010-09-04 06:48:20 -04:00
Jeremy Ashkenas
493780efab separate out browser.coffee from the core coffee-script module. 2010-09-04 06:39:01 -04:00
Jeremy Ashkenas
9290e508c6 fix broken simplenum regex for rangenodes... 2010-09-01 21:20:23 -04:00
Jeremy Ashkenas
a1ebb14495 fixing broken doc link (satyr) 2010-08-31 21:52:15 -04:00
Jeremy Ashkenas
eb9a524ea1 Adding unmatched 'then' to the list of things that closes a single-line implicit call early. Issue #611. 2010-08-30 22:04:13 -04:00
Jeremy Ashkenas
0caa731291 re-enabling the mis-dented call case. Issue #657 2010-08-30 20:59:16 -04:00
Jeremy Ashkenas
704fbf499b Merging in Tesco and rofrankel's soaks for function calls. A soaked check that fails will return undefined. 2010-08-28 09:00:04 -04:00
Jeremy Ashkenas
04fd24e068 Treat 'debugger' as a pure-statement keyword, not and identifier. 2010-08-28 08:26:47 -04:00
Richard Frankel
dc6a83c030 built Tesco's fix for function soaks 2010-08-25 18:59:21 -04:00
Richard Frankel
bcecbd051b added some tests for function soak 2010-08-25 18:54:42 -04:00
Timothy Jones
6607224493 Wrapping existence tests on functions. 2010-08-26 09:03:10 +12:00
Timothy Jones
6224edd6ce Existence checks on functions now supported. 2010-08-26 07:39:30 +12:00
Timothy Jones
9598b11c77 Existence functions now parsing. 2010-08-26 06:31:56 +12:00
Jeremy Ashkenas
fa95f743f3 Fixing Issue #643. Be a little bit safer about declaring block variables as close to the block scope as possible. 2010-08-24 22:19:53 -04:00
Jeremy Ashkenas
e2c46d14f0 CoffeeScript 0.9.2 2010-08-23 22:08:33 -04:00
Jeremy Ashkenas
bd3471b3d1 Issue #641. Rename __superClass__ to __super__ 2010-08-23 21:19:43 -04:00
Jeremy Ashkenas
1b88d18d61 more tweaks and futzes to block comments. 2010-08-23 21:00:47 -04:00
Jeremy Ashkenas
b4de17d504 more tweaks to the herecomment regex. 2010-08-23 20:33:18 -04:00
Jeremy Ashkenas
f90fac0e55 Issue #572. Flexible JavaScript block comments, compatible with JSDoc, YUI-compressor, and Google Closure compiler preservation syntax. 2010-08-23 20:27:34 -04:00
Jeremy Ashkenas
9fd92bf884 updating package.json for newer NPM. 2010-08-23 11:39:06 -04:00
Jeremy Ashkenas
117204a784 Revert "Issue #619. 'new' operator misbehavior."
This reverts commit e7834de929.
2010-08-21 19:16:02 -04:00
Jeremy Ashkenas
e7834de929 Issue #619. 'new' operator misbehavior. 2010-08-21 18:54:24 -04:00
Jeremy Ashkenas
d5d5de55ae Fixing the longstanding and important Issue #637. I'm glad this one got got. 2010-08-21 12:13:43 -04:00
Jeremy Ashkenas
143c4d5efc Issue #572. Block comments now compile to // for aesthetic reasons. 2010-08-21 09:30:25 -04:00
Jeremy Ashkenas
13adc44867 Issue #633. 'not instanceof' 2010-08-21 08:56:25 -04:00
Jeremy Ashkenas
87693d84cb Updating Underscore to 1.1.0, fixing a hasOwnProperty glitch in Scope, and a double-semicolon bug in ParentheticalNode. 2010-08-21 08:30:22 -04:00
Jeremy Ashkenas
6ed33fcc6d Updating contributors in README. 2010-08-20 17:53:45 -04:00
Jeremy Ashkenas
2e59cc4807 Using unbounded ranges in a couple spots in the compiler. 2010-08-18 22:08:09 -04:00
Jeremy Ashkenas
4ddd65a4c4 Issue #621. Added the ability to leave the start and end index off of arrays. list[5..] is now valid CoffeeScript, slicing to the end of the array. 2010-08-18 21:51:44 -04:00
Jeremy Ashkenas
bf6bafa3ac Disallowing Splats outside of ParamLists and ArgLists ... where they belong. This is in anticipation of the next commit... 2010-08-18 21:27:10 -04:00
Jeremy Ashkenas
24f1174b16 Adding a test for issue #631. 2010-08-18 20:42:23 -04:00
Jeremy Ashkenas
098caa9979 Revert "Fixes Issue #618. Close implicit arguments in the middle of param lists."
This reverts commit 474c372b17.
2010-08-18 20:39:55 -04:00
Jeremy Ashkenas
b608d4a5ea Issue #626. Making the isInvertible check a little stricter. 2010-08-17 21:46:00 -04:00
Jeremy Ashkenas
4d32c47bee Merge branch 'remote_script' of http://github.com/satyr/coffee-script 2010-08-17 21:35:00 -04:00
Jeremy Ashkenas
ec54b50c67 allowing empty parens. 2010-08-17 21:31:32 -04:00
satyr
387c690530 removed noWrap (setTimeout evaluates on global) 2010-08-18 10:29:13 +09:00
Jeremy Ashkenas
536e24b024 Merge branch 'remote_script' of http://github.com/satyr/coffee-script 2010-08-17 21:15:41 -04:00
Jeremy Ashkenas
1b05cd81f0 Enabling bound functions as static members of classes... Issue #627 2010-08-17 21:07:36 -04:00
satyr
db181e2a36 enabled remote scripts in browsers 2010-08-18 09:35:52 +09:00
Jeremy Ashkenas
f41ca2e5e8 a touch of safety from trailing catches falling off the end of the rewriter. 2010-08-17 20:04:34 -04:00
Jeremy Ashkenas
a8c6a641d7 stop supressing left-hand whitespace in newline'd strings. Make 'em more literal. 2010-08-16 22:02:37 -04:00
Jeremy Ashkenas
474c372b17 Fixes Issue #618. Close implicit arguments in the middle of param lists. 2010-08-16 21:19:34 -04:00
Jeremy Ashkenas
5b9b45814f Fixing Issue #622 with a light refactor to start using a 'tags' property on all nodes. 2010-08-16 20:18:42 -04:00
Stan Angeloff
01cd5476a0 '-r' should work with $NODE_PATH as well (where previously it was an absolute/relative path) 2010-08-16 17:36:55 +03:00
Jeremy Ashkenas
027b9e9dc3 simplifying generated output for unless/is to (a isnt b) instead of not (a is b). Ticket #617 2010-08-15 15:13:33 -04:00
Jeremy Ashkenas
197f576cab Merged in Stan's patch that allows -r scripts to modify input and output. 2010-08-15 08:32:09 -04:00
Jeremy Ashkenas
0b8facc66f Merge branch 'master' of git://github.com/StanAngeloff/coffee-script 2010-08-15 08:20:50 -04:00
Jeremy Ashkenas
7a0d95c612 Issue #575. Allowing implicit objects to force implicit calls. 2010-08-14 19:56:00 -04:00
Jeremy Ashkenas
975b82f09b Issue #609. Slightly faster implementation of ||= and &&= 2010-08-14 18:02:07 -04:00
Jeremy Ashkenas
f496cc229b Further reducing amount of redundant parentheses. 2010-08-14 17:52:37 -04:00
Jeremy Ashkenas
9894eeb8e9 Improving double-parentheses suppression. Issue #587 2010-08-14 17:43:58 -04:00
Jeremy Ashkenas
129e950c59 Fixing naked chained existential checks -- the associativity recently got reversed. 2010-08-14 16:33:20 -04:00
Jeremy Ashkenas
c90a75ebc5 Fixing first part of #614 -- improperly cached existential operator, when first operand is a function call. 2010-08-14 16:24:05 -04:00
Jeremy Ashkenas
1d6eca76f8 disabling javascriptlint's 'test for equality mistyped as assignment', because it's not relevant to coffeescript. 2010-08-14 16:05:14 -04:00
Jeremy Ashkenas
6555d86328 Adding a jsl.conf configuration file for JavaScript lint, and switching to == null for soaks, accordingly. 2010-08-14 16:02:01 -04:00
Jeremy Ashkenas
c71f2794eb Fixing compound assignment as a right-hand sub expression of a larger operation. Invalid in JS, valid in Coffee. 2010-08-14 14:43:25 -04:00
Jeremy Ashkenas
ca18f1fad6 Core Compiler is JSLint-free again, after removing a couple extra semicolons that snuck in when if statements compiled at the top level. 2010-08-14 11:42:19 -04:00
Jeremy Ashkenas
ead9b1041c tweaking existential compilation. 2010-08-14 11:29:10 -04:00
Jeremy Ashkenas
1eebbfe2bc allowing more flexible whitespace-started regexes. You have to wrap 'em in parens or assign to 'em, but it's better than nothing. 2010-08-12 20:24:53 -04:00
Stan Angeloff
d30c8b321c Allow required files to change the input and output of compiled files. 2010-08-13 01:28:38 +03:00
Jeremy Ashkenas
083500fc0e fixing string interpolation docco. 2010-08-12 00:00:28 -04:00
Jeremy Ashkenas
fd6e9a1e66 Adding support for compound assignment to indented implicit objects. 2010-08-11 23:14:50 -04:00
Jeremy Ashkenas
8c45aa480b Reduced the time it takes to build the grammar from 80 seconds to 15, by consolidating Operation terminals by precedence level. 2010-08-11 23:04:33 -04:00
Jeremy Ashkenas
d704afa0e9 Fixes Issue #574 ... number keys in implicit object literals. 2010-08-11 21:49:18 -04:00
Jeremy Ashkenas
2ec857ef8d Fixing implicit object literals with leading string keys. 2010-08-11 21:41:29 -04:00
Jeremy Ashkenas
ba02ebc3dc Fixes Issue #603 -- a longstanding precedence issue involving prefix vs postfix if and unless, involving using the entire single-line if statment as an expression. 2010-08-11 21:28:22 -04:00
Jeremy Ashkenas
ac752a46bc removing bound functions from the Rewriter. 2010-08-11 21:07:47 -04:00
Jeremy Ashkenas
398ec3be5a Issue #602. Adding JS's Bitwise Assignment operators. 2010-08-11 19:24:59 -04:00
Jeremy Ashkenas
6c997978bc CoffeeScript 0.9.1 is on the books. 2010-08-11 00:40:15 -04:00
Jeremy Ashkenas
642e7fada5 adding other implicit indentation/call/object test. 2010-08-11 00:27:01 -04:00
Jeremy Ashkenas
12493779b9 fixing Issue #545 ... whitespace-only heredocs. 2010-08-11 00:02:49 -04:00
Jeremy Ashkenas
7142131f3d adding herecomment in class definition test. 2010-08-10 23:06:06 -04:00
Jeremy Ashkenas
5bdf78d5ec Fixes Issue #573. Herecomments inside of class literals. 2010-08-10 23:02:24 -04:00
Jeremy Ashkenas
60a4138d50 refactor to simplify scanTokens method in Rewriter. 2010-08-10 22:56:21 -04:00
Jeremy Ashkenas
cb52be6475 adding a top-level object literal test for Issue #542 2010-08-10 22:18:15 -04:00
Jeremy Ashkenas
c2ec40e6ce Fixes Issue #542. Ensure that top-level objects are parenthesized. It's not valid code, but we might as well not SyntaxError out. 2010-08-10 22:16:51 -04:00
Jeremy Ashkenas
87fd05afb0 New implementation of Rewriter#addImplicitIndentation, using Rewriter#detectEnd 2010-08-10 22:05:01 -04:00
Jeremy Ashkenas
45b5bae7d7 New implementation of Rewriter#addImplicitParentheses, using Rewriter#detectEnd 2010-08-10 21:46:46 -04:00
Jeremy Ashkenas
d0b918e083 New implementation of Rewriter#addImplicitBraces -- uses detectEnd.. 2010-08-10 21:13:30 -04:00
Jeremy Ashkenas
0231f8da1b adding options argument to cake documentation. 2010-08-09 09:20:35 -04:00
Jeremy Ashkenas
3eda5a2e85 prefer the include() helper to 'in', except for array literals. 2010-08-08 17:41:10 -04:00
Jeremy Ashkenas
18d6fd72de First step of the general rewriter refactor. Added a generic 'detectEnd' function which is expression-pair sensitive. Use it to reimplement closeOpenCallsAndIndexes 2010-08-08 17:37:28 -04:00
Jeremy Ashkenas
d286b33601 Fixing closures-generated-within-comprehensions to preserve block local scope for range comprehensions 2010-08-08 10:52:59 -04:00
Jeremy Ashkenas
a749d43897 Use fs.realpathSync instead of something hacky. 2010-08-08 10:05:44 -04:00
Jeremy Ashkenas
08506f160d Adding CoffeeScript as a globally-available object, when invoked from the coffee command-line, only. 2010-08-08 09:54:45 -04:00
Jeremy Ashkenas
b902377304 Fixing Issue #589. Compound assignment to an operation should have lower precedence. 2010-08-08 00:07:00 -04:00
Jeremy Ashkenas
1c903450c8 Merging in Stan's patch for a --require flag that allows you to hook into CoffeeScript compiler events for on 'compile', 'success', and 'failure' ... a better way to extend the language or do growlnotify stuff. Issue #590 2010-08-07 23:33:35 -04:00
Jeremy Ashkenas
f950e282a6 Merge branch 'hooks' of git://github.com/StanAngeloff/coffee-script 2010-08-07 22:52:08 -04:00
Jeremy Ashkenas
4da982b253 Merge branch 'master' of http://github.com/brodyberg/coffee-script 2010-08-07 22:49:08 -04:00
Stan Angeloff
b1b78dca47 Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'

Contents of 'snarl.coffee' in the working directory:

    http = require 'http'
    CoffeeScript.on 'exception', (err) ->
      client  = http.createClient 9889, 'localhost'
      request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
      request.end()
      err.handled = yes

To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.

See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 20:24:37 +03:00
Jeremy Ashkenas
0ada5a7734 Issue #587 ... Removing the Attempted Removal of Erroneous Double Parens. 2010-08-07 08:13:36 -04:00
Jeremy Ashkenas
cc10641f38 Forbidding #interp-style interpolation ... Issue #581 2010-08-07 08:07:44 -04:00
Jeremy Ashkenas
9df3e6a538 first step towards requiring #{ ... } interpolation -- removing naked interps from the compiler. 2010-08-07 08:02:16 -04:00
Brody Berg
133aa7be4a Fix typo 2010-08-04 23:23:46 -07:00
Brody Berg
6555659e82 Fix typo 2010-08-04 22:53:45 -07:00
Jeremy Ashkenas
b1f7d5e33b compile empty coffee files to js anyway. 2010-08-04 23:42:46 -04:00
Jeremy Ashkenas
17bf3b7115 be more flexible about trailing commas in implicit object literals. 2010-08-04 23:25:30 -04:00
Jeremy Ashkenas
ff9af83358 CoffeeScript 0.9.0 2010-08-04 23:14:34 -04:00
Jeremy Ashkenas
5f2326e911 fixing Issue #569. Compiling empty source files to disk with --no-wrap on. 2010-08-04 21:36:03 -04:00
Brody Berg
4d2dd337f6 Fix typo 2010-08-03 22:59:17 -07:00
Jeremy Ashkenas
f43c79c101 more additions to the documentation for 0.9.0 2010-08-03 01:13:31 -04:00
Jeremy Ashkenas
b42045f3f7 regenerating large swathes of the docs 2010-08-03 00:06:34 -04:00
Jeremy Ashkenas
3301738b84 git-go 2010-07-31 07:44:49 -04:00
Jeremy Ashkenas
d4ac11cd4f fixing up compout assignment for ?=, which was using a sligtly different path. 2010-07-31 00:42:57 -04:00
Jeremy Ashkenas
8b953bbde6 Fixing Issue #509. Double-evaluation for function calls within IndexNodes as the left-hand-assignment part of a compound-assignment operation. 2010-07-30 23:37:13 -04:00
Jeremy Ashkenas
acd69b1c70 Fixing issue #544. Needed to special case implicit-object-closing for outdents -- it's different than a single-line implicit object with a terminator. 2010-07-30 22:50:35 -04:00
Jeremy Ashkenas
f3caa9292f Fixing Issue #552, Indentation bug with chained calls with nested object literals... 2010-07-30 22:06:22 -04:00
Jeremy Ashkenas
071b527b66 Issue #559, renaming {source} option to {fileName}, on CoffeeScript.compile 2010-07-30 20:37:12 -04:00
Jeremy Ashkenas
ebad1ec552 using double-quotes for auto-quoted object keys and hash accesses. JSON-style. Issue #556 2010-07-30 20:29:05 -04:00
Jeremy Ashkenas
af451bc530 tiny thing. 2010-07-29 21:59:12 -04:00
Jeremy Ashkenas
d1b17df38c better output when trying to force a pure statment to become a return 2010-07-29 21:33:35 -04:00
Jeremy Ashkenas
b18d7fb550 removing the last traces of half-assignments. Issue #541. 2010-07-29 21:23:49 -04:00
Jeremy Ashkenas
980a663c19 ported and regenerated examples. 2010-07-29 00:51:35 -04:00
Jeremy Ashkenas
65c107fc5d finished porting over the examples. 2010-07-29 00:17:48 -04:00
Jeremy Ashkenas
da6ea27454 most of the examples converted to symbology. 2010-07-29 00:03:42 -04:00
Jeremy Ashkenas
58a5d93214 adding a test for Issue #550. 2010-07-28 20:43:39 -04:00
Jeremy Ashkenas
5b848fbc47 Merge branch 'master' of git://github.com/Tesco/coffee-script 2010-07-28 20:39:25 -04:00
Jeremy Ashkenas
8522a11bcb getting the whole codebase passing jslint again. 2010-07-28 20:38:16 -04:00
Timothy Jones
d944f81163 Prevented parameter contents from causing unexpected returns in the body. 2010-07-29 12:35:59 +12:00
Jeremy Ashkenas
c67e7fbcea moving nodes.coffee over to use Tesco's new auto-setter style. 2010-07-28 19:34:02 -04:00
Jeremy Ashkenas
a80d8d55c4 merging tesco's branch for issue #535 2010-07-28 07:34:28 -04:00
Timothy Jones
9026069f79 Support for @-prefixed splats. 2010-07-28 18:17:50 +12:00
Timothy Jones
c9421cbfcd Implement @-prefixed parameters. 2010-07-28 17:54:36 +12:00
Jeremy Ashkenas
5399b989c0 Removing now unnecessary braces from the grammar. Still compiles to identical JS. 2010-07-28 00:35:57 -04:00
Jeremy Ashkenas
9d1fd38b69 removing extraneous tempvar declarations from range generation by re-ordering... 2010-07-27 23:39:28 -04:00
Jeremy Ashkenas
a4156b71fa fixing broken range literal expansions. 2010-07-27 23:06:11 -04:00
Jeremy Ashkenas
fa4871574a one more range literal expansion test 2010-07-27 23:02:26 -04:00
Jeremy Ashkenas
a59df2cf74 merged in evilpie's fix for faster small range comprehensions 2010-07-27 23:00:26 -04:00
Jeremy Ashkenas
051a863ff5 adding slightly optimized syntax for range comprehensions that could care less about the index variable. Issue #547 2010-07-27 22:38:38 -04:00
Jeremy Ashkenas
8d544ce80b Adding anonymous class support (gets a temporary variable for a name.) Issue #548 2010-07-27 22:05:55 -04:00
Jeremy Ashkenas
cc7b0f2e8f Allowing classes to be better decorated with implicit calls. Issue #548 2010-07-27 07:03:44 -04:00
Jeremy Ashkenas
b4ef4a9e28 make the compiler use 'obj = or default' for default values. 2010-07-26 23:58:06 -04:00
Jeremy Ashkenas
9be1453886 bringing back half assignments, but just for 'a = or b' and 'a = and b' 2010-07-26 23:53:03 -04:00
Jeremy Ashkenas
89cd25ab15 finished moving over string and regex interpolation to use '#' instead of '$', Issue #544 2010-07-26 23:31:55 -04:00
Jeremy Ashkenas
d624310be1 waypoint commit with both # and $ performing interpolation. Issue #544 2010-07-26 23:08:09 -04:00
Jeremy Ashkenas
9c8a22832c merging in symbology 2010-07-26 22:08:09 -04:00
Jeremy Ashkenas
55a0e1d2ff making inline implicit objects more flexible ... can be used with trailing blocks. 2010-07-26 21:39:43 -04:00
Jeremy Ashkenas
e638de5c7c a couple more implicit objects in the source. 2010-07-26 20:54:07 -04:00
Jeremy Ashkenas
0aa36899a8 fixing test for {} + {} 2010-07-26 07:40:18 -04:00
Jeremy Ashkenas
ac2f814eb4 fixing issue 542. Parse error with leading object literal as part of operation. 2010-07-25 20:59:28 -07:00
Jeremy Ashkenas
27e5c42023 fixing some implicit object parses for issue #541 2010-07-25 17:46:08 -07:00
Jeremy Ashkenas
6b0418a74a merging master changes into symbology 2010-07-25 00:15:12 -07:00
Jeremy Ashkenas
a0b2b78962 adding nice support for fancy implicit hashes 2010-07-24 23:52:02 -07:00
Jeremy Ashkenas
d1ffffab04 Using an experimental version of new optional-brace object literals. 2010-07-24 23:42:37 -07:00
Jeremy Ashkenas
f9dff6ffc4 added and= and or= to the language. 2010-07-24 22:36:50 -07:00
Jeremy Ashkenas
88847df70b tests are now passing on symbology 2010-07-24 22:23:37 -07:00
Jeremy Ashkenas
492ee57b8f finished basic port to equality of the compiler 2010-07-24 21:36:21 -07:00
Jeremy Ashkenas
5c85bf22bb converted nodes.coffee. a big step 2010-07-24 18:21:25 -07:00
Tom
527af3b69f simplfy generated code for static ranges 2010-07-25 00:49:15 +02:00
Jeremy Ashkenas
6b6beb588c optimizing the output of compiled splat arguments. 2010-07-24 12:40:36 -07:00
Jeremy Ashkenas
dc1288d319 slightly optimizing return values of AssignNodes. Issue #539 2010-07-24 12:27:11 -07:00
Jeremy Ashkenas
87226b6f44 fixing bound functions with an __bind helper. 2010-07-24 12:12:26 -07:00
Jeremy Ashkenas
3b6f020f8a Making the spacing of symbols on function declaration consistent. No-space when single-line. Spaced when block. (StanAngeloff) 2010-07-24 08:31:43 -07:00
Jeremy Ashkenas
93d77e2354 _this to __this, for consistency. (StanAngeloff) 2010-07-24 08:11:42 -07:00
Jeremy Ashkenas
85ed376748 adding correct semicolons to bound functions 2010-07-24 00:45:00 -07:00
Jeremy Ashkenas
bfc7704ca1 first bit of equals for symbology ... barely started on lexer.coffee 2010-07-24 00:31:04 -07:00
Jeremy Ashkenas
e41abe2d83 Changing implementation of bound functions to mirror sethaurus' suggestion for cleaner output. Issue #530. Tests pass. 2010-07-23 22:34:56 -07:00
Jeremy Ashkenas
de9fb7777b fixing If/else-to-ternary with instanceof as an unparenthesized condition. JS operator precedence. 2010-07-23 20:44:56 -07:00
Jeremy Ashkenas
24a5adc898 updating package.json to work better with NPM. Issue #522 2010-07-23 11:06:17 -07:00
Jeremy Ashkenas
0a3f6c49f8 updating documentation with correct variable names. 2010-07-23 09:34:54 -07:00
Jeremy Ashkenas
8262070f5c fixing extra spaces in nested empty functions. Issue #527 2010-07-22 14:08:07 -07:00
Jeremy Ashkenas
9c4164e7a3 removing unnecessary parens from the setup part of a range comprehension. Issue #528 2010-07-22 10:37:13 -07:00
Jeremy Ashkenas
1dab47176b switching interpolateString's method signature to take on options hash. 2010-07-22 09:38:26 -07:00
Jeremy Ashkenas
dfa50c90b3 Fixes Issue #525 -- String interpolation bug due to conflict with Heredoc interpolation. 2010-07-21 15:45:25 -07:00
Jeremy Ashkenas
ff88482034 fixing regex-interpolation-sans-flags issue. 2010-07-21 10:32:36 -07:00
Jeremy Ashkenas
7e225688cb making the 'cake loc' task reflect the lines of code in the compiler only. 2010-07-21 07:26:44 -07:00
Sam Stephenson
5678bf10fd class B extends A calls A.extended(B) 2010-07-18 14:22:26 -05:00
Jeremy Ashkenas
989d539af3 adding no-argument super calls. 2010-07-18 14:46:21 -04:00
Jeremy Ashkenas
d017a8f9f7 Moving from '.addListener' to '.on' for Node v0.1.101 2010-07-18 07:54:44 -04:00
Jeremy Ashkenas
5a34f53689 enhancements to range comprehensions, back to being safe -- and usable downwards without a 'by' clause, and optimized when working with integer literals. 2010-07-17 18:45:29 -04:00
Jeremy Ashkenas
96f076983e Reserving __hasProp and friends, for safety's sake. 2010-07-17 17:30:10 -04:00
Jeremy Ashkenas
a322b3ad68 renamed #strings sectiong to #heredocs 2010-07-17 10:33:32 -04:00
Jeremy Ashkenas
9814fc2e1c Updating documentation with endtime's suggestions. 2010-07-17 10:28:06 -04:00
Jeremy Ashkenas
ec2d358ae3 updating docco to better reflect lack of explicit ternaries. Issue #510 2010-07-16 22:44:07 -04:00
Jeremy Ashkenas
6c8eab7af5 michaelficarra's suggestion to make object comprehensions' hasOwnProperty check a continue, instead of a wrapped if. 2010-07-16 22:31:36 -04:00
Jeremy Ashkenas
b810d10e80 Fixing Issue #506. existential chains should force parentheses in the presense of a compiled ternary operator. 2010-07-15 21:38:35 -04:00
Jeremy Ashkenas
72c4efbc39 adding a new comprehension 'for all key, value of object', which compiles to the naked JS for..in, including enumerable properties inherited from prototypes. 2010-07-15 21:18:35 -04:00
Jeremy Ashkenas
2a932597e4 fixing existential chains directly against a 'new Func()' call. Issue #503 2010-07-15 09:08:51 -04:00
Jeremy Ashkenas
4eed514e37 Fixing (at least partially) Issue #502. Trailing block comment parse. 2010-07-15 08:50:49 -04:00
Jeremy Ashkenas
0337dc23c3 Fix for Issue number 501 ... 2010-07-14 09:40:07 -04:00
Jeremy Ashkenas
2b3b03c3c6 adding 0.7.2 changelog to the docco, as per request. 2010-07-13 23:39:58 -04:00
Jeremy Ashkenas
6a059bfab7 fixing issue #497 try/catch/finally all empty. 2010-07-13 23:33:59 -04:00
Jeremy Ashkenas
0b87387fab slightly nicer implementation of SplatNode.compileSplattedArray 2010-07-13 22:16:19 -04:00
Jeremy Ashkenas
8c34aff1c5 Fixing issue #495 ... options wasn't being passed down in ArrayNode#compileSplatLiteral 2010-07-13 21:51:27 -04:00
Jeremy Ashkenas
cc827b139d Turning --compile on when --output is set, because it's probably what was intended. 2010-07-13 21:04:32 -04:00
Jeremy Ashkenas
c6e1a96882 adding an instanceof test for constructors-called-with-splats 2010-07-13 08:57:42 -04:00
Jeremy Ashkenas
c3410e722e (cosmetic) removing occasional extra linebreaks in JS generated from class definitions. 2010-07-12 22:51:10 -04:00
Jeremy Ashkenas
534e2a25de enabling a variable number of arguments to be passed to constructor functions. 2010-07-12 22:42:21 -04:00
Jeremy Ashkenas
d2c820b5d7 removing sudo from the npm install script. 2010-07-12 21:50:29 -04:00
Jeremy Ashkenas
ff7e729b84 bumping version to 0.7.2 for --options patch. 2010-07-12 08:17:26 -04:00
Jeremy Ashkenas
a21606e348 toFixed() seems to be non-portable. Trying a different number test. 2010-07-11 20:39:54 -04:00
Jeremy Ashkenas
4bd657160d fixing bug in option parsing with flagged arguments and cake. 2010-07-11 17:55:22 -04:00
Jeremy Ashkenas
be8d812919 removing an errant mention of named functions. 2010-07-11 10:44:33 -04:00
Jeremy Ashkenas
e40d25e4bd rebuilding docs and compressed version for CoffeeScript 0.7.1 2010-07-11 10:40:44 -04:00
Jeremy Ashkenas
2a7a26482a fixing optparse to behave nicely in the presence of hashbangs -- stop parsing after the first non-option argument, and pass the rest along -- and adding an OptionParser test. 2010-07-11 09:57:42 -04:00
Jeremy Ashkenas
3d6cdfa636 making it possible to pass in command-line arguments to a hash-banged coffee script. Ticket #473 2010-07-10 15:36:54 -04:00
Jeremy Ashkenas
15a2b7d69a Fixing issue number #486 (which is debatable). Allowing an unparenthesized if/else ternary as a trailing parameter to a call. 2010-07-10 14:52:54 -04:00
Jeremy Ashkenas
9ff8433f21 fixing previously-escaped-inner-quotes-in-double-quoted-heredoc-interpolations. Issue #479 2010-07-10 11:54:59 -04:00
Jeremy Ashkenas
1c7d51a2c4 fixing issue #485, unary minus following an existential operator. 2010-07-10 11:27:43 -04:00
Jeremy Ashkenas
49020208f9 better printing for OpNodes with running with --nodes 2010-07-10 11:17:44 -04:00
Jeremy Ashkenas
6f32fe27f8 better formatting for top-level closured-values. 2010-07-10 09:49:01 -04:00
Jeremy Ashkenas
7a16db9ad3 fixing inline-loop object-in-array tests for instance variables. Issue #481 2010-07-10 09:01:22 -04:00
Jeremy Ashkenas
2f8a29b5a0 fixing a comment/block-comment combination lexing regex issue. Ticket #478 2010-07-10 08:44:30 -04:00
Jeremy Ashkenas
64b5ccc524 Fixes issue #477, missing global helpers in REPL. 2010-07-09 01:01:31 -04:00
Jeremy Ashkenas
4fc4edc7a0 adding wavded's gedit-coffeescript to the resources section of the docs 2010-07-08 10:18:18 -04:00
Jeremy Ashkenas
358edfb21f fixing return node squashing the possiblity of a ternary, when there should be one. Issue #475 2010-07-06 23:04:35 -04:00
Jeremy Ashkenas
577daf5457 fixing herecomment/indentation bugaboo ... issue #474 2010-07-06 22:20:42 -04:00
Jeremy Ashkenas
afa3bb4191 added dsc's coffeecup to the resources section. 2010-07-05 08:51:45 -04:00
Jeremy Ashkenas
e81810d845 fixing issue #427 -- incorrect stringification of reserved word 2010-07-04 20:55:21 -04:00
Jeremy Ashkenas
c57ebffe6f fixing Lexer::OPERATOR regex for non-spaced + unary arithmetic. Issue #471 2010-07-04 13:29:22 -04:00
Jeremy Ashkenas
e281133f12 fixing empty catch clauses ... Issue #470 2010-07-04 12:50:04 -04:00
Jeremy Ashkenas
92878558c6 fixing improper formatting in range-to-array expansion. 2010-07-03 17:00:30 -04:00
Jeremy Ashkenas
ec449158c6 fixing improperly-formatted-output of pattern matching within comprehension arguments. 2010-07-03 15:09:21 -04:00
Jeremy Ashkenas
eefa004b8f fixing the block comment test to use defined variables. 2010-07-01 21:51:28 -04:00
Jeremy Ashkenas
77a75ed365 adding passed-through block comments back to the grammar/lexer/rewriter/nodes ... thanks, Trevor Burnham. 2010-07-01 21:26:33 -04:00
Jeremy Ashkenas
364ec2a694 better syntax errors for tokens-not-in-the-grammar. Coming soon to a Jison near you (hopefully) 2010-07-01 20:40:08 -04:00
Jeremy Ashkenas
9a8a707016 throw a syntax error if you try to use the fat arrow to define a class constructor. 2010-06-30 22:03:20 -04:00
Jeremy Ashkenas
7a5f014014 fixing closurenode wrapping of bodies with bound function declarations inside -- this doesn't have to be mentioned explicitly. 2010-06-30 21:54:16 -04:00
Jeremy Ashkenas
5ca5a504a4 allowing empty bodies in try blocks and in catch blocks 2010-06-30 20:53:09 -04:00
Jeremy Ashkenas
cb45c8feac fixing html entity in the changelog 2010-06-30 19:51:49 -04:00
Jeremy Ashkenas
7d79d73b58 allowing paren-less instance creation, a la 'new Class' 2010-06-29 21:03:50 -04:00
Jeremy Ashkenas
7c426db36a fixing range literals (which had gone untested) oops. 2010-06-28 20:26:31 -04:00
Jeremy Ashkenas
744638ed08 adding a one-line exception test. 2010-06-28 08:52:13 -04:00
Jeremy Ashkenas
9bc7cd7904 adding a one-line exception test. 2010-06-28 08:50:44 -04:00
Jeremy Ashkenas
d83bbfb1d5 updating readme with NPM install. 2010-06-28 01:19:04 -04:00
Jeremy Ashkenas
4ad9e82f50 docs for the NPM install 2010-06-28 01:06:53 -04:00
Jeremy Ashkenas
677c7edf3f CoffeeScript 0.7.0 is on the books. 2010-06-28 01:00:53 -04:00
Jeremy Ashkenas
e56af4967c removing our vendor'd copy of Jison ... you should install it from NPM now. 2010-06-28 00:26:45 -04:00
Jeremy Ashkenas
1f7af35368 getting ready for a 0.7.0. cleanups and doc revisions, not quite there yet. 2010-06-28 00:19:58 -04:00
Jeremy Ashkenas
08ab4abd43 removing obvious redundant parentheses. 2010-06-27 23:55:18 -04:00
Jeremy Ashkenas
a810eb29db slightly simpler comment regex. 2010-06-27 22:26:59 -04:00
Jeremy Ashkenas
3881324007 cleaning up the grammar rule for Super 2010-06-27 16:50:31 -04:00
Jeremy Ashkenas
af3b356d70 fixing an improper-js-output bug when using a loop-compiled inarray clause as part of a larger expression 2010-06-27 13:27:51 -04:00
Jeremy Ashkenas
24676eea71 Fixing commented-out if-clauses or empty if-clauses. 2010-06-27 13:19:23 -04:00
Jeremy Ashkenas
7e2eb997a8 adding a test for trailing-comments-preceding-outdents 2010-06-27 13:02:47 -04:00
Jeremy Ashkenas
ec570c46bf Big commit. First draft of stripping comments from generated JS output. Issue #41 2010-06-27 12:59:54 -04:00
Jeremy Ashkenas
8eedfe4bc6 slight simplification of the if-else grammar rules 2010-06-27 11:46:30 -04:00
Jeremy Ashkenas
800fb81d1b Re-ordering lexer rules for fewer regex matches / slightly faster lexing. 2010-06-27 10:58:08 -04:00
Jeremy Ashkenas
e020f5849c adding a test for #454 2010-06-26 17:21:30 -04:00
Jeremy Ashkenas
698784e103 fixing issue #454 single-line function with single-line if/else 2010-06-26 17:20:13 -04:00
Jeremy Ashkenas
f7345ffaac removing extensions from CoffeeScript 2010-06-26 13:36:31 -04:00
Jeremy Ashkenas
b7faa4a7f2 using the new in-tests for the Rewriter. 2010-06-21 23:54:43 -04:00
Jeremy Ashkenas
0fcfb80be4 switching 'a in b' to 'a of b', and adding an array presence check for 'a in b'. 2010-06-21 23:51:12 -04:00
Jeremy Ashkenas
38a9b7166b Adding TrevorBurnham's suggestion for 'a not in b' 2010-06-21 22:25:28 -04:00
Jeremy Ashkenas
3b28f52ff7 adding non-ASCII characters to test_literals.coffee for Node v0.1.99 2010-06-21 20:47:58 -04:00
Jeremy Ashkenas
7725fe338e Merge branch 'npm' of git://github.com/Tim-Smart/coffee-script 2010-06-21 18:57:17 -04:00
Tim-Smart
2ed66f6e8b Update package.json to allow for npm publishing and installation 2010-06-22 10:48:49 +12:00
Jeremy Ashkenas
9aaf789c21 changing a couple repetitions to DRY objects ... doesn't change the compiled output. 2010-06-20 11:19:50 -04:00
Jeremy Ashkenas
d5cf339b83 adding a test for holmsand's patch for Object.prototype-named variables. 2010-06-16 07:24:17 -04:00
Dan Holmsand
6bc7b56e6e Make sure variables named e.g. "constructor" are declared with var 2010-06-16 12:54:53 +02:00
Jeremy Ashkenas
e4db6d47c2 Updated Cakefile from Tim_Smart with colorized, explained 'cake install' 2010-06-15 21:33:53 -04:00
Jeremy Ashkenas
ce4e00e5ae mistaken camelCase 'nodeLibraries' from the great under_score purge ... now fixed. 2010-06-15 20:40:10 -04:00
Jeremy Ashkenas
06ca2ef726 more streamlined code generation for instance-bound methods ... keep the prototype method around, and just bind it in the constructor. 2010-06-15 02:21:01 -04:00
Jeremy Ashkenas
8d853a6d58 adding the ability to have classes with functions pre-bound to the instance, using the fat arrow, and the constructor-function-definition pattern, avoiding prototypes. 2010-06-15 01:28:30 -04:00
Jeremy Ashkenas
de768aefc3 a bit more work on keywords-in-object-literals... 2010-06-15 01:03:14 -04:00
Jeremy Ashkenas
4b284f6687 first draft at ticket #437 ... automatic quoting of reserved words and keywords. 2010-06-15 00:54:02 -04:00
Jeremy Ashkenas
d0948e5586 fixing comprehensions to also close over the index variable, if used in an inner function... 2010-06-13 21:43:04 -04:00
Jeremy Ashkenas
b0a45e5b93 Ticket #423. When functions are generated within comprehensions ... the comprehensions should close over the element instead of sharing it. 2010-06-13 21:21:30 -04:00
Jeremy Ashkenas
6f91331626 slight refactor to IfNode::ensureExpressions 2010-06-13 18:04:09 -04:00
Jeremy Ashkenas
4ecb1bb2ed switching to 'Compiled' messages after the code has finished compiling on --watch ... 2010-06-13 14:21:02 -04:00
Jeremy Ashkenas
3bcca99cba adding another statement/expression/return test. 2010-06-13 01:19:31 -04:00
Jeremy Ashkenas
5612a59b30 allowing implicit returns to be pushed down into each branch of computation, even when there's an explicit return nested more deeply. Issue #401 2010-06-13 01:13:52 -04:00
Jeremy Ashkenas
88ea66b4c9 allowing a regex literal to be the last token in a file ... Lexer bug. 2010-06-13 00:56:42 -04:00
Jeremy Ashkenas
b61399fbde fixing issue #396 ... issue with nested if/elses getting mis-nested. 2010-06-12 19:38:14 -04:00
Jeremy Ashkenas
a8db2bcf10 fixing a mistaken camelCase in the Cakefile 2010-06-12 19:10:10 -04:00
Jeremy Ashkenas
e14f4c5db1 First draft of switching the CoffeeScript Compiler over to camelCase. Pour one on the ground for underscores... 2010-06-12 19:05:13 -04:00
Jeremy Ashkenas
1948b0c7c7 linebreaks in the rewriter ... cosmetic. 2010-06-12 18:09:07 -04:00
Jeremy Ashkenas
4b4b0e630e yet another rewriter-based comment fix, this time for issue #403 2010-06-12 18:06:33 -04:00
Jeremy Ashkenas
d9071a80a0 Unsatisfactory patch that fixes Issue #394 ... comments that prefix spaced out if/else clauses. 2010-06-12 17:41:46 -04:00
Jeremy Ashkenas
969740a263 slight simplification to if/else in the grammar. 2010-06-12 13:53:11 -04:00
Jeremy Ashkenas
0222d90fa3 adding a 'loop' keyword to CoffeeScript. Takes an expression or a block. Runs it until you break or return out. 2010-06-12 12:15:53 -04:00
Jeremy Ashkenas
a133e018cc Making the REPL the default behaviour of 'coffee', when called with no arguments, a-la Node and Python. 2010-06-12 11:09:30 -04:00
Jeremy Ashkenas
c2d1ae06c5 removing the <- bind operator from CoffeeScript... 2010-06-12 11:00:56 -04:00
Jeremy Ashkenas
59e41f195b simpler 'cake loc' task. 2010-06-11 18:53:12 -04:00
Jeremy Ashkenas
7987d4e5ce adding a cake task to check loc 2010-06-11 18:47:48 -04:00
Jeremy Ashkenas
a8e331a778 new improved REPL, using Node's new 'readline' module... 2010-06-11 18:36:18 -04:00
Jeremy Ashkenas
eb97652537 adding a sentence about parentheses wrapping. 2010-06-11 17:28:18 -04:00
Jeremy Ashkenas
0a4fe7ed97 fixing the lexer so that leading commas surpress newlines 2010-06-11 08:29:16 -04:00
Jeremy Ashkenas
676e893c14 reworking parser for more permissive non-comma-separated array elements. 2010-06-09 00:37:23 -04:00
Jeremy Ashkenas
e37056192b Fix for issue #414 -- apostrophes in heredocs. 2010-06-02 19:53:03 -04:00
Jeremy Ashkenas
8321f6bfe3 making block comments require their own lines for delimiters. Issue 379. 2010-06-02 00:03:07 -04:00
Jeremy Ashkenas
b3d1c238eb fixing block comments at the top of function blocks, and in other locations ... Issue #379 2010-06-01 23:56:10 -04:00
Jeremy Ashkenas
61d9bd7e5e making the lexer more sophisticated about incorrect outdents ... a little safer for everyone. 2010-06-01 23:32:46 -04:00
Jeremy Ashkenas
1fbb6e8734 adding copying header to extras/coffee-script.js 2010-06-01 22:09:00 -04:00
Jeremy Ashkenas
59de6b505a ahh, finally. switched up our Jison configuration to provide better syntax errors. Now you get the unexpected token, instead of the expected one. 2010-06-01 20:21:12 -04:00
Jeremy Ashkenas
ea1411cd07 removing call to deprecated sys.p() in the REPL, now it's 'puts inspect value' 2010-06-01 19:24:48 -04:00
Jeremy Ashkenas
c5fd64c72a allowing direct calls against numbers. 2010-05-31 22:56:51 -04:00
Jeremy Ashkenas
45f442bd73 allowing Klass::['dynamic-property'] syntax. Issue #392 2010-05-31 22:32:43 -04:00
Jeremy Ashkenas
b8a4adbdc7 whitespace adjustments 2010-05-31 19:54:28 -04:00
Jeremy Ashkenas
47fdcebb01 one more range comprehension vs range literal test, for thoroughness. 2010-05-31 19:43:30 -04:00
Jeremy Ashkenas
8cdd8de360 adding a negative range comprehension test. 2010-05-31 19:41:02 -04:00
Jeremy Ashkenas
7402aea9f2 cleaner generated code for range comprehensions, but you have to use an explicit step to go downwards. Forked the code path for cleaner range literals as well. 2010-05-31 19:38:45 -04:00
Jeremy Ashkenas
300c711af1 enabling compilation of non-.coffee-extension files passed directly to the coffee command (Issue #391) 2010-05-31 15:36:41 -04:00
Jeremy Ashkenas
39b8bbc39b Moving all of the 'test_issues' tests from 'hiatus' to their proper locations... 2010-05-31 15:13:48 -04:00
Jeremy Ashkenas
90f96af720 Simpler stab at a fix for issue #397. Allow CoffeeScript-only keywords to be used as accessors, or in assignment. 2010-05-31 14:42:30 -04:00
Jeremy Ashkenas
710b2b5fdc moving issue #381 test to the proper spot. 2010-05-31 14:03:07 -04:00
Jeremy Ashkenas
a577b81eb3 reworking fix for Issue #383 with a more sensitive regex. (decimals without a leading zero) 2010-05-31 13:40:03 -04:00
Jeremy Ashkenas
a5478b0712 refactoring name_access_type into tag_accessor 2010-05-31 13:25:06 -04:00
Jeremy Ashkenas
12587d8295 reworking Stan's nodes.coffee type/children work a bit for issue 386 2010-05-31 10:36:50 -04:00
Stan Angeloff
e17bb4ff11 FIXES #397: Can't use @variable in switch in instance method 2010-05-26 21:58:11 +03:00
Stan Angeloff
aba19841ee FIXES #390: super() calls in constructor of classes that are defined as object properties 2010-05-25 09:15:46 +03:00
Stan Angeloff
0288dba46c Whoops, forgot the extra condition before we perform the rewrite 2010-05-23 12:52:49 +03:00
Stan Angeloff
5a306785ba Tests to ensure reserver words and operators can be used as object keys 2010-05-23 12:44:40 +03:00
Stan Angeloff
c200b95f6a Allowing operators as object keys 2010-05-23 12:42:15 +03:00
Stan Angeloff
2cccd621ea First steps in allowing reserved words as object keys 2010-05-23 12:21:31 +03:00
Stan Angeloff
385b18f588 FIXES #383: Numbers that start with . not recognized 2010-05-20 00:20:33 +03:00
Stan Angeloff
bf1f9f4b95 FIXES #380: problem with @ and instanceof 2010-05-19 23:51:53 +03:00
Stan Angeloff
4c3271728d OOP love for nodes.coffee 2010-05-19 23:24:55 +03:00
Stan Angeloff
57231ae75d Merging type, children and statement functions 2010-05-19 22:53:05 +03:00
Stan Angeloff
97c2a70593 Baby steps fixing #386 2010-05-19 22:37:42 +03:00
Jeremy Ashkenas
485346f0e5 CoffeeScript 0.6.2 2010-05-15 01:18:05 -04:00
Jeremy Ashkenas
a8d4c3a567 sprinkling toString() throughout, for Node.js 0.1.95 compatibility. 2010-05-15 00:34:14 -04:00
Jeremy Ashkenas
dfb3a13246 Fixed lingering CoffeeScript Compiler running live in Internet Explorer bugs. Implemented helpers.index_of and removed named functions. Ticket #366 2010-05-14 23:40:04 -04:00
Jeremy Ashkenas
f84eb9ed47 fixing heredoc indentation from herecomment tweaks 2010-05-14 21:50:17 -04:00
Jeremy Ashkenas
8136c5f3de making regexes stricter about their flags. 2010-05-14 09:14:41 -04:00
Jeremy Ashkenas
45669e08c6 better indentation handling for far-left heredocs and herecomments 2010-05-12 21:49:46 -04:00
Jeremy Ashkenas
a5db69e1af better indentation handling for far-left heredocs and herecomments 2010-05-12 21:47:31 -04:00
Jeremy Ashkenas
8aceef20e1 Adding initial implementation of here-comments (block comments) Issue #368 2010-05-12 20:56:44 -04:00
Jeremy Ashkenas
7e3c71ed19 Allowing more flexible linebreaks/indentation within object literals. 2010-05-12 18:28:40 -04:00
Jeremy Ashkenas
9d09bee6fb better test for sans-condition switch... 2010-05-11 09:32:16 -04:00
Jeremy Ashkenas
cd6ee373ff enabling condition-less switches. 2010-05-10 22:57:51 -04:00
Jeremy Ashkenas
4d0acc9b02 fixing andreyvit's issue with parentheses not being applied to multi-operators as the condition clause of a switch... 2010-05-10 22:50:11 -04:00
Jeremy Ashkenas
393fbf1b66 merging in gfxmonk's cleanup to how children of nodes are determined. Removing some (so far) unused portions. 2010-05-10 22:41:18 -04:00
gfxmonk
3324b03a5d Merge remote branch 'upstream/master'
Conflicts:
	src/nodes.coffee
2010-05-10 21:09:00 +10:00
gfxmonk
eb91f9922d determine @children dynamically based on attribute names, instead of manual bookkeeping 2010-05-10 20:58:01 +10:00
Jeremy Ashkenas
9a7420ccd0 adding support for calling variadic functions with less than the requested number of arguments. 2010-05-08 12:44:54 -04:00
Jeremy Ashkenas
be72120311 further minor cleanup to varargs 2010-05-08 12:20:14 -04:00
Jeremy Ashkenas
c452c3a101 minor cleanup to varargs 2010-05-08 12:15:47 -04:00
Tim Jones
0b3bb66708 Added safe soaking on non-existent variables. 2010-05-05 21:58:48 +12:00
Jeremy Ashkenas
d0d0fa4d10 disallowing regex literals as implicit calls immediatly after ']', a rare case, I hope. Ticket #358 2010-05-04 23:50:22 -04:00
Jeremy Ashkenas
6222ed622f forcing spaces for implicit calls ... making '@ name' a call instead of an access. Ticket #353 2010-05-04 23:44:54 -04:00
Jeremy Ashkenas
1a03e98057 making 'while' and 'until' have the same associativity and precedence as 'for', #356 2010-05-04 23:37:03 -04:00
Jeremy Ashkenas
46cea93fc3 recompiling annotated documentation 2010-05-04 23:31:28 -04:00
Jeremy Ashkenas
d64b8fd9d8 merged in Trevor Burnham's recursive coffee compilation, with some adjustments... 2010-05-04 23:22:28 -04:00
Jeremy Ashkenas
c051daee2f Merge commit 'TrevorBurnham/master' 2010-05-04 23:01:15 -04:00
Tim Jones
ae70d10996 Removing obsolete delete calls. 2010-05-03 21:17:30 -04:00
Tim Jones
52e6399e02 Added missing or to IndexNode. 2010-05-03 21:17:23 -04:00
Tim Jones
ac05f62f2f Wrapping all soaked chains that are involved in operations. 2010-05-03 21:17:16 -04:00
Tim Jones
4d935efd09 Stop anonymous supers. 2010-05-03 21:16:50 -04:00
Trevor Burnham
fa8cc7976a Added recursive compilation and monitoring option to coffee command 2010-05-03 17:38:59 -04:00
Jeremy Ashkenas
ee4e34bf6d relative requires... 2010-05-01 11:00:43 -04:00
gfxmonk
c8e0f8b149 Cleaned up IfNodes
- renamed rewrite_condition() to switches_over(),
   and @switcher to @switch_subject
 - removed unused else_body constructor parameter, as well
   as unnecessary push() method
 - ensure both @body and @else_body are always Expressions
   (previously they could be either Expressions or IfNode)
2010-05-02 00:39:34 +10:00
gfxmonk
b47188763c add require statements to tests that depend on coffee-script modules 2010-05-02 00:27:50 +10:00
Jeremy Ashkenas
5e5c9df5c4 removing holmsand's cleanup 2010-05-01 08:40:02 -04:00
Jeremy Ashkenas
1a97f599dd added a test for the multiple-functions-passed-sans-parens 2010-04-30 23:20:22 -04:00
Tim Jones
3b264c9572 Added a small part to the rewriter to allow a better two-function call. 2010-05-01 14:04:57 +12:00
Dan Holmsand
144c096ae6 Remove unused variable index_var from for loops 2010-04-30 09:48:30 +02:00
Jeremy Ashkenas
adbcd320b2 adding until loops as the inverse of while loops 2010-04-28 22:08:00 -04:00
Jeremy Ashkenas
17ba44056e changing 'filter' to 'guard' to get around Express' clobbering of Object.prototype. 2010-04-28 21:46:47 -04:00
Jeremy Ashkenas
502abade7c rewriting the compiler using 'unless' blocks where appropriate. 2010-04-27 19:38:24 -04:00
Jeremy Ashkenas
b746c9018e adding 'unless' blocks 2010-04-27 19:35:15 -04:00
Jeremy Ashkenas
92af641827 no newline on no_such_task for Cake 2010-04-27 07:59:19 -04:00
Jeremy Ashkenas
b5606a247d adding pattern matching for comprehensions. 2010-04-26 23:46:35 -04:00
Jeremy Ashkenas
d62baf5a5d Merge branch 'for_destructuring' of git://github.com/StanAngeloff/coffee-script 2010-04-26 23:34:07 -04:00
Jeremy Ashkenas
e17567866a Merge branch 'master' of git://github.com/Tesco/coffee-script 2010-04-26 23:31:18 -04:00
Stan Angeloff
76f9596f22 Cleaning up. 2010-04-26 21:54:31 +03:00
Stan Angeloff
2a3a713811 Allowing pattern matching within for..loops 2010-04-26 21:35:35 +03:00
gfxmonk
175ebb3cd8 fail with appropriate error status if child process fails 2010-04-26 16:08:19 +10:00
Tim Jones
95367a4a63 Fixing silly mistake with the comments. 2010-04-26 16:00:12 +12:00
Tim Jones
8950c3c4c8 Fixing invalid pattern matching and object creation. 2010-04-26 15:54:47 +12:00
Jeremy Ashkenas
2d1abd099d rewriting the Lexer, CommandLine, Nodes, and Rewriter to take advantage of the new DRY object pattern matching. 2010-04-25 22:29:43 -04:00
Jeremy Ashkenas
a894db35fd Got the DRY object pattern matching style working properly, from Harmony. {name, age}: person now works correctly. 2010-04-25 22:21:53 -04:00
Jeremy Ashkenas
328a14014c eliminating the IndentedAssignList nonterminal. 2010-04-25 21:22:29 -04:00
Jeremy Ashkenas
315a2c63fa simplifying the grammar by replacing all of our trailing comma rules with an OptComma nonterminal. 2010-04-25 21:17:46 -04:00
Jeremy Ashkenas
ca4ea7649d Throwing an error when pattern matching has a non-identifier on the left-hand side. 2010-04-25 11:22:15 -04:00
Jeremy Ashkenas
08c877ec7b Fixing string keys in pattern matching on objects (ticket 325) 2010-04-25 11:07:09 -04:00
Jeremy Ashkenas
212ad45be4 merging gfxmonk's removed error event fix. 2010-04-24 22:13:13 -04:00
gfxmonk
e9b37c7578 replaced nonexistant error event callback with a combination of stderr and exit events 2010-04-25 11:24:06 +10:00
Jeremy Ashkenas
1438cecfad Fixing splats-with-super()-in-classes, an oversight. 2010-04-24 15:57:15 -04:00
Jeremy Ashkenas
49824ce1a6 removing yytext mentions for real this time. 2010-04-21 23:21:48 -04:00
Jeremy Ashkenas
bc0ec9dc07 Revert "removing yytext mentions from the grammar"
This reverts commit 5957b9f155.
2010-04-21 23:10:45 -04:00
Jeremy Ashkenas
5957b9f155 removing yytext mentions from the grammar 2010-04-21 23:01:14 -04:00
Jeremy Ashkenas
72e6e828f1 new version of Jison vendored ... rebuild the grammar, tests pass. 2010-04-21 22:52:20 -04:00
Jeremy Ashkenas
01b4393fa7 fixing Issue #328, parse error with indents and comments (StanAngeloff) 2010-04-21 22:26:45 -04:00
Jeremy Ashkenas
bf2a5386f9 requiring helpers module in test_bind.coffee 2010-04-21 19:52:58 -04:00
Jeremy Ashkenas
fb4d4a609b making bin/cake install add CoffeeScript as a Node.js library, and creating an index.js file for the top-level inclusion. 2010-04-20 20:20:38 -04:00
Jeremy Ashkenas
1cddb2aa88 Redoing Rewriter#add_implicit_parentheses to be more robust. 2010-04-20 01:32:12 -04:00
Jeremy Ashkenas
aac9679282 merging in gfodor's excellent Rewriter patch. 2010-04-19 23:18:39 -04:00
Jeremy Ashkenas
90472685e8 Merge branch 'master' of git://github.com/gfodor/coffee-script 2010-04-19 23:12:24 -04:00
Jeremy Ashkenas
7bb764b3e4 ignoring raw 2010-04-18 18:14:17 -04:00
Greg Fodor
1aed9c545f Fix for bug with chaining 2010-04-18 00:41:47 -04:00
Jeremy Ashkenas
c937e49689 adding 'coffeescript-idea' to the resources section. 2010-04-13 23:41:18 -04:00
Jeremy Ashkenas
0d860516ac fixing non-spaced function application. 2010-04-13 09:05:55 -04:00
Jeremy Ashkenas
4ced1d65b4 allowing 'debugger' ... it should never have been a reserved word. 2010-04-12 21:23:01 -04:00
Jeremy Ashkenas
92540d5e85 CoffeeScript 0.6.1, for Node.js v0.1.90 2010-04-12 21:20:00 -04:00
Jeremy Ashkenas
ea982a627e adding coffee-haml-filter to the docs 2010-04-11 17:57:29 -04:00
Jeremy Ashkenas
835ecac8db simplifying some unecessary interpolated expressions into interpolated values. 2010-04-11 16:57:53 -04:00
Jeremy Ashkenas
c3bbb48041 adding a test case for issue 309, interpolations with implicit calls. 2010-04-11 09:37:48 -04:00
Jeremy Ashkenas
2e842f0146 merging Stan's recursive tokenizing fix for interpolations. 2010-04-11 09:26:21 -04:00
Jeremy Ashkenas
8de2fb9009 Merge commit 'StanAngeloff/issue_309' 2010-04-11 09:22:31 -04:00
Stan Angeloff
17e177405a FIXES #309: Optional parens and interpolation. 2010-04-11 12:22:54 +03:00
Dr Nic Williams
ef67561fb3 Using anonymous callback for 'exit' event when running tests 2010-04-11 19:05:49 +10:00
Jeremy Ashkenas
df97effb9c fixing implicit-call-in-function-in-parens bug. 2010-04-10 18:56:46 -04:00
Jeremy Ashkenas
8317960f81 Battery of patches for compatibility with Node v0.1.90 2010-04-10 18:05:35 -04:00
Jeremy Ashkenas
065bf54094 generated closures should only call() or apply() when necessary. 2010-04-10 14:40:05 -04:00
Jeremy Ashkenas
f36acc27e5 safely preserving the arguments object through generated closure wrappers. 2010-04-10 14:20:32 -04:00
Jeremy Ashkenas
491ad6de95 adding webchat to the doc page 2010-04-10 13:42:39 -04:00
Jeremy Ashkenas
3eedf8ed1b Adding noonat to the contributor list 2010-04-06 21:09:23 -04:00
Jeremy Ashkenas
75b260e495 Merge branch 'master' of git://github.com/noonat/coffee-script 2010-04-06 21:08:29 -04:00
noonat
2351948291 Renamed Lexer.tag() argument to new_tag, due to Rhino scope confusion 2010-04-05 22:58:56 -07:00
Tim Jones
538e518d76 Realigning function arrows. 2010-04-06 02:29:38 +12:00
Tim Jones
de955dacc4 Added Statement to the grammar. 2010-04-06 02:26:23 +12:00
Chris Lloyd
19ed63129e Interpolated strings are expressions. 2010-04-04 17:05:52 +10:00
Chris Lloyd
2e744a1c1b Failing test for string interpolation. Interpolated strings need to be expressions, not values. 2010-04-04 16:54:59 +10:00
Jeremy Ashkenas
89534b88b1 merging in Chris Lloyd's fix for optional descriptions on Cake tasks. 2010-04-04 00:20:17 -04:00
Jeremy Ashkenas
c067808b54 CoffeeScript 0.6.0 is on the books. 2010-04-03 20:43:50 -04:00
Jeremy Ashkenas
59ae79d8fb rebuilding the docs with the fixed highlighter for '@' and regexes. 2010-04-03 19:10:26 -04:00
Jeremy Ashkenas
ad1c5e1884 merging non-func-constructor-fix, but a little more forgiving. 2010-04-03 14:53:26 -04:00
Stan Angeloff
9958cedd89 Throwing proper error when "constructor" is not a function within a class body. 2010-04-03 21:43:42 +03:00
Jeremy Ashkenas
d1aaed4430 Merge branch 'master' of git://github.com/Tesco/coffee-script 2010-04-03 12:21:31 -04:00
Tim Jones
89debc87b2 Removing {@prop: value} from the grammar. 2010-04-04 04:18:29 +12:00
Jeremy Ashkenas
9d2c81ea54 rebuilding the docs with new pygments, no errors on '@' 2010-04-03 12:01:46 -04:00
Jeremy Ashkenas
44765907b3 tiny tweak 2010-04-03 11:16:49 -04:00
Jeremy Ashkenas
4a85f3d499 cleaning up tests ... consolidation, consistency... 2010-04-03 10:39:32 -04:00
Jeremy Ashkenas
f99b5ad463 Merging Tesco's invoking-this-fix 2010-04-03 09:58:45 -04:00
Tim Jones
8fc631269b Added a rule to prevent invoking THIS. 2010-04-03 14:14:16 +13:00
Tim Jones
a1975583a7 Added THIS to CALLABLE. 2010-04-03 13:58:21 +13:00
Jeremy Ashkenas
1c628e7883 fixing parens-around-implicit-function-with-multiline-chained-chaser bug 2010-04-01 23:38:20 -04:00
Jeremy Ashkenas
3605168e85 fixing single evaluation of functions used in chained comparisons wrapped in parentheses. 2010-03-31 22:48:47 -04:00
Jeremy Ashkenas
f86fca2739 merged tanob's fix for installing outside of /usr/local without a /bin 2010-03-31 21:30:14 -04:00
Adriano Bonat
0410748e2d Merge remote branch 'upstream/master' 2010-03-31 22:14:26 -03:00
Adriano Bonat
2172878f21 When installing in different prefixes, prefix + '/bin' may not exist. 2010-03-31 09:38:05 -03:00
Jeremy Ashkenas
d3a51fbfa1 stylistics: removing a bunch of unecessary parentheses 2010-03-31 00:17:49 -04:00
Jeremy Ashkenas
aae2405de4 removing all of the 'type' tags from the Nodes. Simply using constructor.name instead. 2010-03-31 00:04:14 -04:00
Jeremy Ashkenas
2b578367a9 rebuilding the source documentation with the new utility refactors 2010-03-30 23:53:02 -04:00
Jeremy Ashkenas
f9b028b78c __extend back to __extends, as is the correct name. 2010-03-30 20:15:51 -04:00
Jeremy Ashkenas
572aa4e98f reverting the grammar to the pre-slice notation. 2010-03-30 20:11:40 -04:00
Jeremy Ashkenas
864275f07e removing __range, and all the slice behavior it enabled. If you can't do array[-1], then you shouldn't be able to do array[0..-1] -- it's just too inconsistent. 2010-03-30 20:06:44 -04:00
Jeremy Ashkenas
998a7c8cb0 more cleanups, added a utility helper function to the codegen 2010-03-30 19:48:37 -04:00
Jeremy Ashkenas
6d7a04228f another reshuffle ... removed utilities.coffee entirely. 2010-03-30 19:42:09 -04:00
Jeremy Ashkenas
4a8c2e8a13 more refactors to utilities ... removing dependencies and the namespacing 2010-03-30 19:27:38 -04:00
Jeremy Ashkenas
f3a60edc5d simplifying the lookup of the top-level scope object 2010-03-30 19:21:14 -04:00
Jeremy Ashkenas
1e1146d61d more utility simplifications 2010-03-30 19:17:40 -04:00
Jeremy Ashkenas
832e1d8cb8 Utilities doesn't need to be a class, and removing __utilities.keys 2010-03-30 19:00:59 -04:00
Jeremy Ashkenas
4936211a9c modified shorter imlementation of bind 2010-03-30 18:49:55 -04:00
Jeremy Ashkenas
f0d731009f merged matehat's utility branch, arraySlice -> slice, removed dead dependency... 2010-03-30 18:27:53 -04:00
Jeremy Ashkenas
a6248d03e5 Merge branch 'slice' of git://github.com/matehat/coffee-script 2010-03-30 18:19:41 -04:00
Jeremy Ashkenas
a934cf4947 make JSLint happy about the while condition 2010-03-30 18:19:09 -04:00
matehat
c498b7090e Removed __splice in the same manner 2010-03-30 18:14:51 -04:00
matehat
ca9e45e8af Removed the __slice method, in favor of the native array slice method 2010-03-30 17:57:23 -04:00
matehat
97096696a2 Put back every utility functions on the global scope, automatically prefixed with __ and set them dynamically as reserved on the lexer. 2010-03-30 16:48:43 -04:00
matehat
27fb3763b4 A set of improvements on previous code 2010-03-30 16:14:07 -04:00
matehat
da43c70488 Merged in StanAngeloff excellent slice branch, applying recent factoring of utility functions 2010-03-30 15:43:30 -04:00
Stan Angeloff
76ade0cb4d Removing vendor specific files for measurement tests. 2010-03-30 14:33:57 -04:00
Stan Angeloff
09e1526bca Removing commented code in compile_splice -- this is working correctly now. 2010-03-30 14:33:57 -04:00
Stan Angeloff
7d1fbeb708 Re-compiling the core using the new __slice and __splice functions. 2010-03-30 14:32:37 -04:00
Stan Angeloff
15217c705e Allowing for negative indices in slice literals. 2010-03-30 14:30:15 -04:00
matehat
9f108e87eb Removed unused __hasProp assignment and declared Coffeescript a reserved name 2010-03-30 11:20:53 -04:00
matehat
1e786d6d8b Removed unnecessary check 2010-03-30 10:58:21 -04:00
matehat
0557eb9b93 Removed hard-coding of utility object name 2010-03-30 09:08:16 -04:00
matehat
241f6f3068 Applied the utility factoring into a "Coffeescript" object to the core. All tests pass fast. 2010-03-30 09:02:51 -04:00
Jeremy Ashkenas
326656245a using the new static properties of class definitions in the CoffeeScript compiler -- it's hardly used. 2010-03-29 21:49:20 -04:00
Jeremy Ashkenas
177ec92c39 adding class methods to class definition syntax, using '@' 2010-03-29 21:43:12 -04:00
Jeremy Ashkenas
711dacae5f more little documentation for the rewriter ... moving along 2010-03-29 21:22:12 -04:00
Jeremy Ashkenas
c19183118e removing a case from Rewriter#add_implicit_parentheses that apparently never happens... 2010-03-29 20:52:22 -04:00
Jeremy Ashkenas
0af132d0c6 update internal documentation ... it's been a while 2010-03-29 20:48:41 -04:00
Jeremy Ashkenas
83c0e77ca8 making the Rewriter's add_implicit_calls more sensitive of parenthetical arguments. 2010-03-28 17:12:30 -04:00
Jeremy Ashkenas
1e315b5a33 fixing single-line implicit call wrapped around function with trailing arguments 2010-03-28 16:44:41 -04:00
Tim Jones
6e0e0767f9 Removed unprocessed values on a for loop from the grammar. 2010-03-29 07:32:01 +13:00
Tim Jones
6df50399a9 Restricted class and extends values to simple assignments. 2010-03-29 06:14:35 +13:00
Tim Jones
7b9a8998cf Addressing some assignment issues. 2010-03-29 06:06:16 +13:00
Jeremy Ashkenas
7de5253318 removing unused reserved variable 'source var' from range comprehensions 2010-03-27 16:04:47 -04:00
Jeremy Ashkenas
eaf4a71d32 Revert "Added Unix-like piping. Allows chaining of function calls where every succeeding call receives as first argument the result of all preceding expressions."
This reverts commit 7ee10e06be.
2010-03-27 15:25:34 -04:00
Jeremy Ashkenas
4dd40034ed Revert "removing the special case for | or"
This reverts commit 9763839ed1.
2010-03-27 15:25:27 -04:00
Jeremy Ashkenas
030476d335 Revert "typo for @compile_bitwise_or"
This reverts commit 45aae5e322.
2010-03-27 15:25:19 -04:00
Jeremy Ashkenas
45aae5e322 typo for @compile_bitwise_or 2010-03-27 12:13:24 -04:00
Jeremy Ashkenas
9763839ed1 removing the special case for | or 2010-03-27 10:28:08 -04:00
Stan Angeloff
7ee10e06be Added Unix-like piping. Allows chaining of function calls where every succeeding call receives as first argument the result of all preceding expressions. 2010-03-27 15:49:33 +02:00
matehat
8f3ea1d0c5 Fixed a small bug that happened when having a trailing comma in multiline array and object literals 2010-03-26 14:11:34 -04:00
matehat
b9b87f7d8e Minor modifications to the grammar to allow a single trailing comma for function call arguments, array literal and object literals. Adjusted tests accordingly 2010-03-26 11:44:25 -04:00
Chris Lloyd
c9b6e82e2c Optional sentence descriptions for cake tasks. 2010-03-26 20:25:17 +11:00
Jeremy Ashkenas
c8f969b4a2 adding a test case for the explicit returns 2010-03-25 18:54:17 -04:00
Jeremy Ashkenas
ecd1c77f48 fixing explicit returns of comprehensions (and probably other things as well) 2010-03-25 18:51:24 -04:00
Jeremy Ashkenas
ad93d2fe4d added another language extension test for a << b into a.push(b) 2010-03-23 20:42:40 -04:00
Jeremy Ashkenas
5a4d401582 make sure that the source-hacking docs mention to 'git checkout lib' 2010-03-23 00:25:37 -04:00
Jeremy Ashkenas
590c069158 CoffeeScript 0.5.6 2010-03-23 00:18:50 -04:00
Jeremy Ashkenas
94185e3f70 Merge branch 'master' of git://github.com/matehat/coffee-script 2010-03-22 23:20:05 -04:00
Jeremy Ashkenas
9adcd16ec6 '=' -> ':' 2010-03-22 18:48:41 -04:00
matehat
74bcd898e7 improving readability a bit 2010-03-22 02:02:04 -04:00
matehat
296808d4d3 Added splats positional flexibility to pattern matching 2010-03-22 01:52:47 -04:00
Jeremy Ashkenas
b7519cb834 switching a couple of the half_assignment tests to ensure that : and = are still interchangeable 2010-03-21 23:46:58 -04:00
Jeremy Ashkenas
7d6c050048 more half-assignment tests 2010-03-21 23:39:05 -04:00
Jeremy Ashkenas
16f9a2e6b7 rewriting the compiler to use half-expression assignment 2010-03-21 23:33:24 -04:00
Jeremy Ashkenas
cbfe7f5822 fix and tests for half assignments... whew. 2010-03-21 23:24:24 -04:00
Jeremy Ashkenas
895cd88761 almost there with half-assignments 2010-03-21 23:06:04 -04:00
Jeremy Ashkenas
f2ea18b0ba removing AND OR NOT IS ISNT from the grammar 2010-03-21 22:07:46 -04:00
Jeremy Ashkenas
162f6b9d5c one step at a time 2010-03-21 22:05:49 -04:00
Jeremy Ashkenas
4f8ae3ccbe one more step 2010-03-21 21:46:53 -04:00
Jeremy Ashkenas
acd9be3863 one step further 2010-03-21 21:46:06 -04:00
Jeremy Ashkenas
ddf18ae34c nothing much 2010-03-21 21:26:12 -04:00
Jeremy Ashkenas
0da61ec47e adding a couple of interchangeable tests 2010-03-21 21:07:32 -04:00
Jeremy Ashkenas
80230414a2 merging in gfxmonk's major refactor to the way that returns are pushed down into the interior of expressions 2010-03-21 11:28:05 -04:00
Jeremy Ashkenas
ce7c0d176b briefer test runner output 2010-03-21 10:18:23 -04:00
Jeremy Ashkenas
4ec79732f1 merging gfxmonk's cleanups 2010-03-21 10:11:02 -04:00
gfxmonk
cc3c314988 Cleaned up return logic
- ReturnNodes are explicitly added during compilation
 - ReturnNode is used instead of scattering "return" throughout
   code compilation snippets
 - nodes gain a make_return method in order to do the most useful
   thing when a return is requested
2010-03-21 22:21:55 +11:00
gfxmonk
8553a89af2 improve feedback when running the test task
- run synchronously, to ensure ordering is consistent
 - big red error message (and exit status)
 - don't bail early
 - don't bother printing a stack trace (it's useless
   until we can get line numbers in eval'd code)
2010-03-21 22:21:47 +11:00
Jeremy Ashkenas
566321d67a fixing infinite recursion when compiling if statements containing pure_statements 2010-03-20 10:36:06 -04:00
Jeremy Ashkenas
a2778bf06d resolving issues with comments in the middle of unfinished single-line expressions. 2010-03-20 00:58:25 -04:00
Jeremy Ashkenas
29eff23490 renaming test_curry to test_bind 2010-03-19 23:32:00 -04:00
Jeremy Ashkenas
4ebaa82563 removing the CoffeeScript.run named function from eval'd script scope by making it anonymous 2010-03-19 23:15:42 -04:00
Jeremy Ashkenas
69911209ea adding a pattern-matching-on-expression test 2010-03-19 22:48:55 -04:00
Jeremy Ashkenas
92688c89ef merging in matehat's nice refactor to splats (in arrays and otherwise) 2010-03-19 22:41:23 -04:00
matehat
fe04f8ce6b Added function call's flexibility with splats to array literals, factoring out splat compiling, and adjusted tests 2010-03-18 09:31:40 -04:00
Jeremy Ashkenas
b72641693d fixing doubled semis 2010-03-18 08:45:26 -04:00
Jeremy Ashkenas
0c6ee52cfc merging in matehat's curry branch. cleaning some loose ends up. adding some tests. 2010-03-18 00:42:26 -04:00
matehat
1f87094628 Slightly altered syntax, similar to Underscore's Function#bind form, highly simplified lexing and parsing and no polluted scope. Passing tests included. 2010-03-18 00:19:32 -04:00
matehat
3b22018296 Applied the new splat flexibility to function currying operator 2010-03-18 00:08:34 -04:00
matehat
5be437deb9 Added some inline docs 2010-03-18 00:08:34 -04:00
matehat
8d098194dd Added the '<-' currying operator, as heavily discussed in #251, along with tests. 2010-03-18 00:08:34 -04:00
matehat
256525bfa2 Fixed a small bug about flexible splats that occured when the leading array was a literal 2010-03-18 00:08:05 -04:00
Jeremy Ashkenas
79e4f30f69 fixing a bug where the Lexer assumed that values would always be strings. 2010-03-17 22:16:18 -04:00
Jeremy Ashkenas
884637468e fixing off-by-one error in compile_splat_arguments 2010-03-17 22:07:11 -04:00
Jeremy Ashkenas
6fd7810d89 can't use indexing[] into strings cross-browser, use substr() instead. 2010-03-17 21:41:00 -04:00
Jeremy Ashkenas
2f97d0d9b1 merging matehat's flexible splats (at any position within argument lists) 2010-03-17 21:15:54 -04:00
Jeremy Ashkenas
1bb9c57767 Merge branch 'splats' of git://github.com/matehat/coffee-script 2010-03-17 21:07:31 -04:00
Jeremy Ashkenas
d880b8b8f2 adding interpolation to heredocs, using the same rules as for strings 2010-03-17 20:47:27 -04:00
matehat
7129f518a4 Added the ability for function declaration to have a splat at an arbitrary position, not just at the end. Still restrict their number to 1. Adjusted tests accordingly. 2010-03-17 15:00:19 -04:00
matehat
fa6f1c2fb1 Fixed a tiny slicing bug 2010-03-17 15:00:19 -04:00
matehat
2bd1c3acca Added the ability to put as many splats in a function call as one wants. Also optimized the assembly into static arrays. Adjusted tests accordingly. 2010-03-17 15:00:19 -04:00
Jeremy Ashkenas
70cfc9500e pushing docs to the site 2010-03-16 23:18:54 -04:00
Jeremy Ashkenas
61b011cc28 fixing trailing whitespace on the final line 2010-03-16 19:57:39 -04:00
Jeremy Ashkenas
391135b1a5 fixing the relative path to 'grammar' 2010-03-16 19:36:08 -04:00
Jeremy Ashkenas
12d8d70573 fixing incorrectly-rooted relative paths in bin/cake and bin/coffee 2010-03-16 19:27:11 -04:00
Jeremy Ashkenas
04c5aeda2d Merge branch 'master' of git://github.com/matehat/coffee-script 2010-03-16 19:15:21 -04:00
Jeremy Ashkenas
25438be207 new docs for underscore 2010-03-16 19:13:13 -04:00
matehat
33f51d76f4 Added the possibility to end an identifier with '::', refering directly to its prototype. 2010-03-16 17:39:36 -04:00
Jeremy Ashkenas
e3021909c2 comments and tests 2010-03-16 06:54:49 -04:00
Jeremy Ashkenas
61dee1beba tweakin' 2010-03-15 23:10:14 -07:00
Jeremy Ashkenas
21e954eec3 updating module loading test 2010-03-15 23:08:58 -07:00
Jeremy Ashkenas
0b3054a348 merging in matehat's registerExtension patch for direct-requires of CoffeeScript. 2010-03-15 23:03:30 -07:00
Jeremy Ashkenas
02f4cb75dd removing deprecated references to process.mixin in favor of helpers.extend for Node 0.1.32 2010-03-15 22:53:25 -07:00
Jeremy Ashkenas
3aeb8c6bdb moving the contains-a-pure-statement-means-no-closure logic into ClosureNode.wrap itself. 2010-03-15 22:27:31 -07:00
Jeremy Ashkenas
8c2b2c7f80 merging in the fixed branch for gfxmonk/break_issue 2010-03-15 22:22:41 -07:00
Jeremy Ashkenas
745c635a55 fixing issue with break statements and for loops and closures and the value of 'this' 2010-03-15 22:20:29 -07:00
Jeremy Ashkenas
c7dd31846d merging in gfxmonk's fix for reporting line numbers for unclosed { [ ( opening symbols 2010-03-15 22:09:16 -07:00
gfxmonk
e87fa4293d report line number of opening token if a pair (eg bracket) is left open 2010-03-15 22:07:40 -07:00
gfxmonk
b269884f8d fixed non-recursive traverse() for CodeNode 2010-03-15 22:03:54 -07:00
Jeremy Ashkenas
3fed9761a6 let's make that non-greedy 2010-03-15 21:50:33 -07:00
Jeremy Ashkenas
6ccf196b61 adding another language extension test, with %w{} style ruby word array literals 2010-03-15 21:47:40 -07:00
Jeremy Ashkenas
a4bd8dc623 removing outdated arguments tests 2010-03-15 21:45:37 -07:00
Jeremy Ashkenas
34f01408c9 removing arguments-to-arrays from the docs 2010-03-15 20:53:43 -07:00
Jeremy Ashkenas
73074daa07 removing arguments-to-array-conversion from coffee 2010-03-15 20:46:14 -07:00
Jeremy Ashkenas
119b80d449 removing fiddling with require.paths from CoffeeScript 2010-03-15 20:39:46 -07:00
Jeremy Ashkenas
60b3103314 using granular helper imports, for nicer within. 2010-03-14 14:58:32 -07:00
Jeremy Ashkenas
75ffb9dc84 stop mixing in helpers (t(ticket #250) -- with a test 2010-03-14 14:48:43 -07:00
Jeremy Ashkenas
b306d40bf1 we don't need relative requires for the language 2010-03-14 13:48:58 -07:00
Jeremy Ashkenas
a27f146338 fixing 'cake test' to print out the name of the file with the failing test. 2010-03-14 09:33:41 -07:00
Jeremy Ashkenas
74995358cd updating the Cakefile for the new tmbundle location. 2010-03-14 08:59:55 -07:00
Jeremy Ashkenas
35da6c32b7 removing the tmbundle from the main repository. See jashkenas/coffee-script-tmbundle for the new one 2010-03-14 08:05:33 -07:00
Jeremy Ashkenas
701a5c7cb9 Merge branch 'master' of git://github.com/drnic/coffee-script 2010-03-14 07:39:02 -07:00
gfxmonk
3c3e7f666b added another "invalid break" example, with code not on the top-level 2010-03-14 13:02:36 +11:00
gfxmonk
89dfa1fd7a added code to illustrate an issue with break statements 2010-03-14 13:02:35 +11:00
gfxmonk
1da00f0ee3 added a test case for broken "break" statement 2010-03-14 11:35:56 +11:00
gfxmonk
5809a1637f fixed non-recursive traverse() for CodeNode 2010-03-14 00:05:51 +11:00
gfxmonk
e47bea34d5 report line number of opening token if a pair (eg bracket) is left open 2010-03-14 00:03:17 +11:00
matehat
709f17c278 Added an extension on node's 'require' module so it can import .coffee module and added some tests to make sure it works. 2010-03-12 14:22:01 -05:00
Jeremy Ashkenas
3c597dde72 no need to save the lookups 2010-03-10 22:32:00 -05:00
Jeremy Ashkenas
0379431812 tweaks 2010-03-10 21:53:33 -05:00
Jeremy Ashkenas
3f9fd85afb removing the unused CallNode#push 2010-03-10 20:53:31 -05:00
Jeremy Ashkenas
7b0a235c71 removing the nearly-unused notion of 'operation sensitive' 2010-03-10 20:19:32 -05:00
Jeremy Ashkenas
55cac23976 fixing indentation for prefix while nodes 2010-03-10 20:15:12 -05:00
Dr Nic Williams
22a16a3e33 added two snippets for creating functions; matching tab/key triggers from JavaScript bundle 2010-03-11 10:27:25 +10:00
Dr Nic Williams
db555d12ea can set Grammar via Shift+Ctrl+Alt+C 2010-03-11 10:16:34 +10:00
Jeremy Ashkenas
b9f1390405 adding more comment tests -- this terminator/comment as-block business really seems to have opened them up a bit 2010-03-10 16:44:50 -05:00
Jeremy Ashkenas
f2d0aee656 added Stan's fix for try/finally without catch 2010-03-10 16:27:30 -05:00
Jeremy Ashkenas
2a47727641 allowing terminator/comment as a block, so that you can have comment-only blocks 2010-03-10 16:18:17 -05:00
Jeremy Ashkenas
ccb7f63b8a fixing exports for the browser 2010-03-10 09:47:02 -05:00
Jeremy Ashkenas
1f9bb6a1c4 fixing broken multi-line optional-paren blocks 2010-03-10 09:28:00 -05:00
Jeremy Ashkenas
21b5d2cac5 tweaks to the helper docs, if they're going to be published 2010-03-10 00:05:30 -05:00
Jeremy Ashkenas
56eeeebed1 updating the docco 2010-03-09 23:53:21 -05:00
Jeremy Ashkenas
54627f6807 CoffeeScript language extensions are now working. 2010-03-09 23:44:29 -05:00
Jeremy Ashkenas
5754d36fdd adding the broken test 2010-03-09 23:32:54 -05:00
Jeremy Ashkenas
3d14d362a8 first draft of CoffeeScript language extensions. 2010-03-09 23:04:16 -05:00
Jeremy Ashkenas
472e027463 fixing the nested-implicit-parens-on-a-single-line 2010-03-09 21:54:44 -05:00
Jeremy Ashkenas
b297510d2b big refactor -- pulled all helper functions into helpers.coffee to facilitate sharing. 2010-03-09 21:24:30 -05:00
Jeremy Ashkenas
4932d25540 making balanced_string accept an array of delimiters, in hope of using it in the Rewriter 2010-03-09 20:53:56 -05:00
Jeremy Ashkenas
b6c3b743f0 Merge branch 'tm_highlighting' of git://github.com/cehoffman/coffee-script 2010-03-09 19:45:52 -05:00
Jeremy Ashkenas
1b4edd0e37 scrubbing all carriage returns from CoffeeScript source before compiling for the benefit of Windows users. 2010-03-08 23:07:26 -05:00
Jeremy Ashkenas
dcb00b4fe8 minor refactors to balanced_string 2010-03-08 22:48:14 -05:00
Jeremy Ashkenas
b33b688373 fixing more bugs in balance/interpolate/regexp/string/etc 2010-03-08 22:25:06 -05:00
Jeremy Ashkenas
4b97b15c0c more refactors to interpolation 2010-03-08 21:55:06 -05:00
Chris Hoffman
93c0774036 Regex interpolation highlighting 2010-03-08 20:48:23 -06:00
Chris Hoffman
645885d72d Merge branch 'master' of git://github.com/jashkenas/coffee-script 2010-03-08 20:34:36 -06:00
Jeremy Ashkenas
b5af5f66fb more regexp and string interpolation tweaks 2010-03-08 21:34:10 -05:00
Chris Hoffman
fb04f8900a Merge branch 'master' of git://github.com/jashkenas/coffee-script 2010-03-08 20:12:40 -06:00
Jeremy Ashkenas
3396dce2bb waypoint -- going to try to clean up regex_token 2010-03-08 20:57:28 -05:00
Jeremy Ashkenas
3291bd2a4a removing the 'supress' option from the lexer, just look at the slash. 2010-03-08 20:07:19 -05:00
Jeremy Ashkenas
121f01c06f merged stan's interpolation_3, a couple of tweaks 2010-03-08 19:43:12 -05:00
Jeremy Ashkenas
6cac2d57ba Merge commit 'StanAngeloff/interpolation_3' 2010-03-08 19:36:09 -05:00
Jeremy Ashkenas
c04b43e047 adding documentation for var shadowing 2010-03-08 19:27:38 -05:00
Jeremy Ashkenas
ff20732dd7 Merge branch 'tm_highlighting' of git://github.com/cehoffman/coffee-script 2010-03-08 19:14:34 -05:00
Stan Angeloff
81af8f296e Regular expression interpolations; fixed bug in string interpolations when all tokens were identifiers. 2010-03-08 20:06:51 +02:00
Stan Angeloff
830d1fb42b Merge branch 'master' of git://github.com/jashkenas/coffee-script into interpolation_3 2010-03-08 16:43:41 +02:00
Jeremy Ashkenas
e19cb48d3d Merge branch 'master' of git://github.com/uiru/coffee-script 2010-03-08 09:30:25 -05:00
Chris Hoffman
f755580b11 Match regex highlighting to how coffee parses it 2010-03-08 08:18:37 -06:00
Jeremy Ashkenas
81955005b9 doc tweaks 2010-03-08 09:13:15 -05:00
Will
62a871773b Include an extra line process.mixin require 'sys' on the top to let the .js output run using node (v0.1.31) 2010-03-09 01:03:43 +11:00
Chris Hoffman
5e52e7f19e While loop can be a single line expressions so don't indent when it is 2010-03-08 08:02:23 -06:00
Chris Hoffman
4c66a6a642 Merge branch 'master' of git://github.com/jashkenas/coffee-script 2010-03-08 07:33:45 -06:00
Chris Hoffman
9e1deecf13 Merge branch 'tm_highlighting' 2010-03-08 07:33:02 -06:00
Chris Hoffman
1ce93ccceb Indent function in symbol list based on indention in source 2010-03-08 07:30:15 -06:00
Chris Hoffman
4b04f8bec1 Add auto indent settings for textmate 2010-03-08 07:28:56 -06:00
Jeremy Ashkenas
5528bc7b2d scratch 'as seen above' 2010-03-08 06:44:47 -05:00
Jeremy Ashkenas
912f3b19f7 little tweaks to the docs 2010-03-08 06:40:54 -05:00
Chris Hoffman
9e5e85780b Don't highlight fresh[key]: val situations 2010-03-08 05:37:51 -06:00
Chris Hoffman
10aa3b3ae3 Revert "Properly highlight fresh[key]: val situations" 2010-03-08 05:37:07 -06:00
Jeremy Ashkenas
bcf7b3f95b CoffeeScript 0.5.5, with string interpolation and internal documentation 2010-03-08 06:34:07 -05:00
Chris Hoffman
07f1c784a4 Properly highlight fresh[key]: val situations 2010-03-08 05:29:01 -06:00
Chris Hoffman
465994cff9 Clean up some misplaced files 2010-03-08 05:26:38 -06:00
Chris Hoffman
697ad6cbda Merge remote branch 'origin' 2010-03-08 05:15:17 -06:00
Jeremy Ashkenas
a840671015 Finishing off the docs for nodes.coffee -- almost ready to roll. 2010-03-08 05:13:05 -06:00
Jeremy Ashkenas
7f0ab8308d making ThrowNode not a pure_statement -- it can jump out of the closure just fine 2010-03-08 05:13:05 -06:00
Jeremy Ashkenas
270b9fde04 waypoint -- documented down to the ThrowNode 2010-03-08 05:13:04 -06:00
Jeremy Ashkenas
993c9899cb Fixing up command-line args for --stdio and --eval. Now makes more sense with --run by default. 2010-03-08 05:13:04 -06:00
Jeremy Ashkenas
c8246e95f1 broke the flag for --no-wrap, fixed. 2010-03-08 05:13:04 -06:00
Stan Angeloff
f08de1ed4c Empty expression interpolations evaluate as empty strings now. 2010-03-08 05:13:04 -06:00
Jeremy Ashkenas
90f2e0dbb9 Merge branch 'tm_highlighting' of git://github.com/cehoffman/coffee-script 2010-03-08 06:11:15 -05:00
Chris Hoffman
80a3bd8951 Add variable assignment highlighting for textmate 2010-03-08 05:10:08 -06:00
Jeremy Ashkenas
b0aec3cbe2 Finishing off the docs for nodes.coffee -- almost ready to roll. 2010-03-08 05:42:57 -05:00
Jeremy Ashkenas
5f5e0634dd making ThrowNode not a pure_statement -- it can jump out of the closure just fine 2010-03-08 05:19:48 -05:00
Jeremy Ashkenas
049e605016 changing from storage.type... to variable.assignment -- it was a little garish in most color schemes I tried. 2010-03-08 05:16:45 -05:00
Jeremy Ashkenas
4687c3e140 Merge branch 'tm_highlighting' of git://github.com/cehoffman/coffee-script 2010-03-08 04:59:10 -05:00
Jeremy Ashkenas
6d74e223be waypoint -- documented down to the ThrowNode 2010-03-08 04:58:39 -05:00
Chris Hoffman
221427a6b4 Make variable assignment highlighting work in more cases 2010-03-08 03:55:03 -06:00
Chris Hoffman
3bf892128d Make old style classes show up as a function and don't let $\d be highlighted as a number 2010-03-08 03:47:49 -06:00
Chris Hoffman
abd7f939f2 Don't show object creation instances in symbol list for textmate 2010-03-08 03:46:38 -06:00
Jeremy Ashkenas
299e9918b9 Fixing up command-line args for --stdio and --eval. Now makes more sense with --run by default. 2010-03-08 04:46:24 -05:00
Chris Hoffman
eea83ff613 Add comment starter preference for textmate 2010-03-08 03:46:05 -06:00
Jeremy Ashkenas
9eceab667c broke the flag for --no-wrap, fixed. 2010-03-08 04:28:26 -05:00
Stan Angeloff
026e7649d5 Empty expression interpolations evaluate as empty strings now. 2010-03-08 04:13:59 -05:00
Chris Hoffman
c807da7664 Identify functions for symbol lookup and correct lookbehind assertion 2010-03-08 02:39:38 -06:00
Chris Hoffman
dde5db621d Add some TextMate triggers for string interpolation 2010-03-08 02:06:57 -06:00
Chris Hoffman
6b95cb4ee0 Fix the naked .property highlighting in interpolation to match coffee parsing 2010-03-08 01:40:04 -06:00
Stan Angeloff
a5f69ef716 Empty expression interpolations evaluate as empty strings now. 2010-03-08 09:31:31 +02:00
Chris Hoffman
accccb5f39 Allow $ to be the first character in a variable name for highlighting in textmate 2010-03-08 01:20:43 -06:00
Chris Hoffman
f8ddccd7d0 Escape $ in regexes where it was meant as character and not end of line 2010-03-08 01:05:52 -06:00
Chris Hoffman
e06e882962 Update highlighting for class definitions in textmate 2010-03-08 00:59:21 -06:00
Chris Hoffman
c3f74ca4f1 Add string interpolation highlighting and Cakefile highlighting 2010-03-08 00:43:04 -06:00
Jeremy Ashkenas
532464f7ae waypoint -- docs halfway down through the OpNode 2010-03-07 22:47:34 -05:00
Jeremy Ashkenas
570fb013e2 test tweaks 2010-03-07 22:29:46 -05:00
Jeremy Ashkenas
71ace9d8d0 allowing naked interpolation of dotted properties. .property 2010-03-07 22:26:25 -05:00
Jeremy Ashkenas
1cf0326183 unifying the CoffeeScript.compile and CoffeeScript.run apis to be the same -- source code and options hash. 2010-03-07 22:17:45 -05:00
Jeremy Ashkenas
5b9ebd19d5 adding source file information to all coffeescript compiles 2010-03-07 22:08:24 -05:00
Jeremy Ashkenas
6ce869b3fb adding a note about the 'git co lib' - build twice shuffle to the docs -- there's been more than one question about it already. 2010-03-07 21:57:08 -05:00
Jeremy Ashkenas
06b50ecb98 unifying all of the server-side evaluation under CoffeeScript.run -- this means that __filename and __dirname and relative requires should work from all angles under Node.js 2010-03-07 21:49:08 -05:00
Jeremy Ashkenas
0bc7719572 merging in Zaach's Jison updates 2010-03-07 19:11:03 -05:00
Jeremy Ashkenas
9028f79a27 Merge branch 'master' of git://github.com/zaach/coffee-script 2010-03-07 19:09:20 -05:00
Jeremy Ashkenas
a3e1693a75 waypoint -- docc'd down to the SplatNode 2010-03-07 19:07:37 -05:00
Zachary Carter
060b3e23c1 Merge branch 'master' of git://github.com/jashkenas/coffee-script 2010-03-07 18:59:54 -05:00
Zachary Carter
612c238157 Rebuild parser, now with skinnier parse table. 2010-03-07 18:53:23 -05:00
Zachary Carter
8adbc75811 Update Jison for table optimizations. 2010-03-07 18:48:15 -05:00
Jeremy Ashkenas
7485e5482c mention rlwrap in the docs on --interactive 2010-03-07 18:19:41 -05:00
Jeremy Ashkenas
659a5436a5 adding coffee-mode and rack-coffee to the Resources section of the docs 2010-03-07 17:52:14 -05:00
Jeremy Ashkenas
c6d7a27848 waypoint on the documentation -- almost halfway through the nodes 2010-03-07 17:31:39 -05:00
Jeremy Ashkenas
094b198d5d first little bit of commenting the nodes.coffee -- with some slight refactors 2010-03-07 16:41:06 -05:00
Jeremy Ashkenas
22b97a3b54 documenting scope.coffee -- nodes.coffee is the next, and last up to bat. 2010-03-07 15:45:45 -05:00
Jeremy Ashkenas
a4f7a5e248 documenting and cleaning up the Rewriter 2010-03-07 14:41:52 -05:00
Jeremy Ashkenas
45d8cf163e updating to the latest docco 2010-03-07 13:49:34 -05:00
Jeremy Ashkenas
d46daa1d7c documenting optparse.coffee and repl.coffee 2010-03-07 13:41:15 -05:00
Jeremy Ashkenas
4906cf1aff cleaned and commented the lexer (again) interpolate_string() continues to shrink 2010-03-07 12:47:03 -05:00
Stan Angeloff
f74fae58e3 Rewritting lexer.coffee to accept nested string interpolations. 2010-03-07 11:42:52 -05:00
Jeremy Ashkenas
1602e0e823 adding complete documentation for the grammar 2010-03-07 11:41:56 -05:00
Jeremy Ashkenas
202ebf06ff documentation for command.coffee 2010-03-07 00:28:58 -05:00
Jeremy Ashkenas
3e3b71724d making equality left-associative so that our chaining works properly with it. 2010-03-06 23:48:06 -05:00
Jeremy Ashkenas
893fb98522 moving command_line.coffee -> command.coffee 2010-03-06 22:18:15 -05:00
Jeremy Ashkenas
e267226438 commenting coffee-script.coffee for documentation 2010-03-06 20:30:40 -05:00
Jeremy Ashkenas
62626b712b Commenting cake.coffee for Docco docs. 2010-03-06 20:18:50 -05:00
Jeremy Ashkenas
7bdf14b210 Override process.argv as well as process.ARGV for eval'd scripts 2010-03-06 20:09:08 -05:00
Jeremy Ashkenas
87420e6504 updating the Function Binding docs with an improved explanation. 2010-03-06 19:29:41 -05:00
Jeremy Ashkenas
c73a3ec356 updating webserver example for node API 2010-03-06 19:23:25 -05:00
Jeremy Ashkenas
2e23e6a2dc removing narwhal.coffee and narwhal.js, because I don't think that anyone was using them. 2010-03-06 19:05:21 -05:00
Jeremy Ashkenas
5b3ef78101 adding a doc:source Cake task to document CoffeeScript's internals 2010-03-06 19:02:31 -05:00
Jeremy Ashkenas
9b262d56a5 allowing relative requires of JavaScript from directly-eval'd CoffeeScript. 2010-03-06 17:40:13 -05:00
Jeremy Ashkenas
453b43992d fixing line numbers in errors printed prior to parsing 2010-03-06 16:42:40 -05:00
Jeremy Ashkenas
a5e3617015 Adding a starts() helper to avoid substring() calls for simple matches. 2010-03-06 16:24:06 -05:00
Jeremy Ashkenas
c4ad6d1ee6 minor cleanups to balanced_group -> balanced_token, removing optional escaper (unused), and using it to implement interpolated javascript. 2010-03-06 16:06:47 -05:00
Stan Angeloff
f9cde1b46d Improving performance by removing call to bound function for every character in a string. Added a third option to \delimited\ to allow custom escape sequences. 2010-03-06 15:53:37 -05:00
Jeremy Ashkenas
03bc897b39 updating CoffeeScript docs to require Node 0.1.31 + 2010-03-06 15:48:20 -05:00
Stan Angeloff
83fd84745d Rewriting string tokenizer; allowing nested double-quoted strings inside expression interpolations. 2010-03-06 15:21:30 -05:00
Jeremy Ashkenas
e977967eb5 implementing the CoffeeScript compiler using interpolation where appropriate. 2010-03-06 13:59:11 -05:00
Jeremy Ashkenas
15b00cb3ca implementing string interpolation using string interpolation 2010-03-06 13:32:43 -05:00
Jeremy Ashkenas
18e5f72a84 done converting nodes.coffee code generation to use string interpolation where appropriate 2010-03-06 00:23:54 -05:00
Jeremy Ashkenas
47682de0f0 adding a test for intermingled identifier/expression interpolations 2010-03-05 22:54:39 -05:00
Jeremy Ashkenas
b4ea43cbd0 waypoint -- starting to implement nodes.coffee with interpolations, and fixing/shortening/combining the lexer implementation to allow identifier interpolations to be interleaved with expression interps 2010-03-05 22:52:28 -05:00
Jeremy Ashkenas
08341286a3 adding back parentheses wrapper around interpolated expressions -- we need it 2010-03-05 21:12:13 -05:00
Jeremy Ashkenas
4c3b0b9a74 allowing @properties to be referenced in naked interpolations 2010-03-05 21:05:31 -05:00
Jeremy Ashkenas
d250e9e9cc some edits to the interpolation path 2010-03-05 20:42:36 -05:00
Stan Angeloff
75be5eed62 Test line commented by mistake, no functional changes 2010-03-05 19:50:28 -05:00
Stan Angeloff
e2f86678a4 Allowing expressions to be used inside strings; syntax is $\{...\} 2010-03-05 19:50:20 -05:00
Stan Angeloff
fe7d5dfd19 Added string interpolation for identifiers 2010-03-05 19:49:48 -05:00
Jeremy Ashkenas
965034e16e add proper spacing to optparse by default 2010-03-04 22:59:03 -05:00
Jeremy Ashkenas
44398d044f Updating docs for CoffeeScript 0.5.4. Tag it and bag it. 2010-03-03 23:01:53 -05:00
Jeremy Ashkenas
3feb874b1e Merge branch 'path_fix' of git://github.com/cehoffman/coffee-script 2010-03-03 20:17:58 -05:00
Chris Hoffman
f7183e6918 Use new node api for resolving a chain of symlinks 2010-03-03 16:34:17 -06:00
Samuel Reis
707cd2d734 updated command_line.js 2010-03-03 14:32:28 +01:00
Samuel Reis
c11c3ed2f2 fix: process.watchFile has moved to fs.watchFile 2010-03-03 14:31:30 +01:00
Jeremy Ashkenas
5fd0972b5d improvement to comment handling that should ensure that they have no effect on indentation 2010-03-02 19:23:21 -05:00
Jeremy Ashkenas
70cb195e6f rebuilding extras/coffee-script.js 2010-03-02 16:52:55 -05:00
Jeremy Ashkenas
c219adffd5 removing special rule from rewriter for naked functions in arrays 2010-03-02 00:43:01 -05:00
Jeremy Ashkenas
cd6dd5abfd couple more tweaks to lexer.coffee 2010-02-28 21:39:07 -05:00
Jeremy Ashkenas
29ece0e6ba better commenting the coffeescript lexer as the first trial for docco 2010-02-28 20:44:33 -05:00
Jeremy Ashkenas
45bad556ab defining __filename and __dirname correctly as local variables for eval'd scripts 2010-02-28 19:56:00 -05:00
Jeremy Ashkenas
30cf63ec92 updating Underscore.coffee to Underscore.js version 0.6.0 2010-02-28 15:12:18 -05:00
Jeremy Ashkenas
969c2e528d a number of refactors to the Lexer. It should be a good bit clearer to read now. 2010-02-28 13:34:52 -05:00
Jeremy Ashkenas
bb2bf7ce57 allowing chaining of property accesses by indentation level (really nice for Node and jQuery work) ticket #221 2010-02-28 12:49:37 -05:00
Jeremy Ashkenas
2969e156c7 fixing require paths in the Cakefile so that build:jison will work, even if you don't have it installed. 2010-02-28 10:37:12 -05:00
Jeremy Ashkenas
b08995cbcc fixing heredocs with multiple double quotes (broken regex from the Ruby translation), with tests. 2010-02-28 10:29:30 -05:00
Jeremy Ashkenas
47f71f9193 updating docs to say 'Node.js greater than 0.1.30' 2010-02-28 10:11:01 -05:00
Jeremy Ashkenas
fec2eaef7e removing the (now-unused) inherits helper, and adding a helper for creating LiteralNodes 2010-02-28 00:22:06 -05:00
Jeremy Ashkenas
56eb474bf3 If you don't specify a constructor, one will be provided for you by the state. 2010-02-28 00:13:17 -05:00
266 changed files with 17886 additions and 17083 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,8 @@
raw
presentation
test.coffee
parser.output
test/fixtures/underscore
test/*.js
examples/beautiful_code/parse.coffee
*.gem

199
Cakefile
View File

@@ -1,71 +1,186 @@
fs: require 'fs'
coffee: require 'coffee-script'
fs = require 'fs'
path = require 'path'
{extend} = require './lib/helpers'
CoffeeScript = require './lib/coffee-script'
{spawn, exec} = require 'child_process'
# ANSI Terminal Colors.
bold = '\033[0;1m'
red = '\033[0;31m'
green = '\033[0;32m'
reset = '\033[0m'
# Built file header.
header = """
/**
* CoffeeScript Compiler v#{CoffeeScript.VERSION}
* http://coffeescript.org
*
* Copyright 2010, Jeremy Ashkenas
* Released under the MIT License
*/
"""
sources = [
'src/coffee-script.coffee', 'src/grammar.coffee'
'src/helpers.coffee', 'src/lexer.coffee', 'src/nodes.coffee'
'src/rewriter.coffee', 'src/scope.coffee'
]
# Run a CoffeeScript through our node/coffee interpreter.
run: (args) ->
proc: process.createChildProcess 'bin/coffee', args
proc.addListener 'error', (err) -> if err then puts err
run = (args) ->
proc = spawn 'bin/coffee', args
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
proc.on 'exit', (status) -> process.exit(1) if status != 0
# Log a message with a color.
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
base: options.prefix or '/usr/local'
lib: base + '/lib/coffee-script'
base = options.prefix or '/usr/local'
lib = "#{base}/lib/coffee-script"
bin = "#{base}/bin"
node = "~/.node_libraries/coffee-script"
console.log "Installing CoffeeScript to #{lib}"
console.log "Linking to #{node}"
console.log "Linking 'coffee' to #{bin}/coffee"
exec([
'mkdir -p ' + lib
'cp -rf bin lib LICENSE README package.json src vendor ' + lib
'ln -sf ' + lib + '/bin/coffee ' + base + '/bin/coffee'
'ln -sf ' + lib + '/bin/cake ' + base + '/bin/cake'
"mkdir -p #{lib} #{bin}"
"cp -rf bin lib LICENSE README package.json src #{lib}"
"ln -sf #{lib}/bin/coffee #{bin}/coffee"
"ln -sf #{lib}/bin/cake #{bin}/cake"
"mkdir -p ~/.node_libraries"
"ln -sf #{lib}/lib #{node}"
].join(' && '), (err, stdout, stderr) ->
if err then print stderr
if err then console.log stderr.trim() else log 'done', green
)
task 'build', 'build the CoffeeScript language from source', ->
files: fs.readdirSync 'src'
files: 'src/' + file for file in files when file.match(/\.coffee$/)
files = fs.readdirSync 'src'
files = ('src/' + file for file in files when file.match(/\.coffee$/))
run ['-c', '-o', 'lib'].concat(files)
task 'build:full', 'rebuild the source twice, and run the tests', ->
exec 'bin/cake build && bin/cake build && bin/cake test', (err, stdout, stderr) ->
console.log stdout.trim() if stdout
console.log stderr.trim() if stderr
throw err if err
task 'build:parser', 'rebuild the Jison parser (run build first)', ->
parser: require('grammar').parser
js: parser.generate()
parser_path: 'lib/parser.js'
fs.writeFile parser_path, js
extend global, require('utils')
require 'jison'
parser = require('./lib/grammar').parser
fs.writeFile 'lib/parser.js', parser.generate()
task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', ->
exec 'plist2syntax extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage', (err) ->
exec 'plist2syntax ../coffee-script-tmbundle/Syntaxes/CoffeeScript.tmLanguage', (err) ->
throw err if err
exec 'sudo mv coffeescript.yaml /usr/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/syntax/coffeescript.syntax'
task 'build:underscore', 'rebuild the Underscore.coffee documentation page', ->
exec 'uv -s coffeescript -t idle -h examples/underscore.coffee > documentation/underscore.html'
task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
exec 'rake browser'
code = ''
for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'coffee-script', 'browser']
code += """
require['./#{name}'] = new function() {
var exports = this;
#{fs.readFileSync "lib/#{name}.js"}
};
"""
{parser, uglify} = require 'uglify-js'
ast = parser.parse """
this.CoffeeScript = function() {
function require(path){ return require[path]; }
#{code}
return require['./coffee-script']
}()
"""
code = uglify.gen_code uglify.ast_squeeze uglify.ast_mangle ast, extra: yes
fs.writeFileSync 'extras/coffee-script.js', header + '\n' + code
invoke 'test:browser'
task 'doc', 'watch and continually rebuild the documentation', ->
exec 'rake doc'
task 'doc:site', 'watch and continually rebuild the documentation for the website', ->
exec 'rake doc', (err) ->
throw err if err
task 'doc:source', 'rebuild the internal documentation', ->
exec 'docco src/*.coffee && cp -rf docs documentation && rm -r docs', (err) ->
throw err if err
task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', ->
exec 'docco examples/underscore.coffee && cp -rf docs documentation && rm -r docs', (err) ->
throw err if err
task 'bench', 'quick benchmark of compilation time', ->
{Rewriter} = require './lib/rewriter'
co = sources.map((name) -> fs.readFileSync name).join '\n'
fmt = (ms) -> " #{bold}#{ " #{ms}".slice -4 }#{reset} ms"
total = 0
now = Date.now()
time = -> total += ms = -(now - now = Date.now()); fmt ms
tokens = CoffeeScript.tokens co, rewrite: false
console.log "Lex #{time()} (#{tokens.length} tokens)"
tokens = new Rewriter().rewrite tokens
console.log "Rewrite#{time()} (#{tokens.length} tokens)"
nodes = CoffeeScript.nodes tokens
console.log "Parse #{time()}"
js = nodes.compile bare: true
console.log "Compile#{time()} (#{js.length} chars)"
console.log "total #{ fmt total }"
task 'loc', 'count the lines of source code in the CoffeeScript compiler', ->
exec "cat #{ sources.join(' ') } | grep -v '^\\( *#\\|\\s*$\\)' | wc -l | tr -s ' '", (err, stdout) ->
console.log stdout.trim()
runTests = (CoffeeScript) ->
startTime = Date.now()
passedTests = failedTests = 0
for name, func of require 'assert'
global[name] = ->
passedTests += 1
func arguments...
global.eq = global.strictEqual
global.CoffeeScript = CoffeeScript
process.on 'exit', ->
time = ((Date.now() - startTime) / 1000).toFixed(2)
message = "passed #{passedTests} tests in #{time} seconds#{reset}"
if failedTests
log "failed #{failedTests} and #{message}", red
else
log message, green
fs.readdir 'test', (err, files) ->
files.forEach (file) ->
return unless file.match(/\.coffee$/i)
fileName = path.join 'test', file
fs.readFile fileName, (err, code) ->
try
CoffeeScript.run code.toString(), {fileName}
catch err
failedTests += 1
log "failed #{fileName}", red, '\n' + err.stack?.toString()
task 'test', 'run the CoffeeScript language test suite', ->
process.mixin require 'assert'
test_count: 0
start_time: new Date()
[original_ok, original_throws]: [ok, throws]
process.mixin {
ok: (args...) -> test_count += 1; original_ok(args...)
throws: (args...) -> test_count += 1; original_throws(args...)
}
process.addListener 'exit', ->
time: ((new Date() - start_time) / 1000).toFixed(2)
puts '\033[0;32mpassed ' + test_count + ' tests in ' + time + ' seconds\033[0m'
fs.readdir 'test', (err, files) ->
for file in files
fs.readFile 'test/' + file, (err, source) ->
js: coffee.compile source
process.compile js, file
runTests CoffeeScript
task 'test:browser', 'run the test suite against the merged browser script', ->
source = fs.readFileSync 'extras/coffee-script.js', 'utf-8'
result = {}
(-> eval source).call result
runTests result.CoffeeScript

51
README
View File

@@ -1,42 +1,47 @@
=
{
} } {
{ { } }
} }{ {
{ }{ } } _____ __ __
( }{ }{ { ) / ____| / _|/ _|
.- { { } { }} -. | | ___ | |_| |_ ___ ___
( ( } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|`-..________ ..-'| | |___| (_) | | | || __/ __/
=
{
} } {
{ { } }
} }{ {
{ }{ } } _____ __ __
( }{ }{ { ) / ____| / _|/ _|
.- { { } { }} -. | | ___ | |_| |_ ___ ___
( ( } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|`-..________ ..-'| | |___| (_) | | | || __/ __/
| | \_____\___/|_| |_| \___|\___|
| ;--.
| (__ \ _____ _ _
| | ) ) / ____| (_) | |
| |/ / | (___ ___ _ __ _ _ __ | |_
| ;--.
| (__ \ _____ _ _
| | ) ) / ____| (_) | |
| |/ / | (___ ___ _ __ _ _ __ | |_
| ( / \___ \ / __| '__| | '_ \| __|
| |/ ____) | (__| | | | |_) | |_
| |/ ____) | (__| | | | |_) | |_
| | |_____/ \___|_| |_| .__/ \__|
`-.._________..-' | |
`-.._________..-' | |
|_|
CoffeeScript is a little language that compiles into JavaScript.
Install Node.js, and then the CoffeeScript compiler:
sudo bin/cake install
Or, if you have the Node Package Manager installed:
npm install coffee-script
Compile a script:
coffee /path/to/script.coffee
For documentation, usage, and examples, see:
http://coffeescript.org/
To suggest a feature, report a bug, or general discussion:
http://github.com/jashkenas/coffee-script/issues/
If you'd like to chat, drop by #coffeescript on Freenode IRC,
or on webchat.freenode.net.
The source repository:
git://github.com/jashkenas/coffee-script.git
All contributors are listed here:
http://github.com/jashkenas/coffee-script/contributors

View File

@@ -1,13 +1,13 @@
require 'rubygems'
require 'erb'
require 'fileutils'
require 'rake/testtask'
require 'rubygems'
require 'yui/compressor'
require 'json'
desc "Build the documentation page"
task :doc do
source = 'documentation/index.html.erb'
child = fork { exec "bin/coffee -c documentation/coffee/*.coffee -o documentation/js -w" }
child = fork { exec "bin/coffee -bcw -o documentation/js documentation/coffee/*.coffee" }
at_exit { Process.kill("INT", child) }
Signal.trap("INT") { exit }
loop do
@@ -21,11 +21,58 @@ task :doc do
end
end
desc "Build the single concatenated and minified script for the browser"
task :browser do
sources = %w(rewriter.js lexer.js parser.js scope.js nodes.js coffee-script.js)
code = sources.map {|s| File.read('lib/' + s) }.join('')
code = YUI::JavaScriptCompressor.new.compress(code)
File.open('extras/coffee-script.js', 'w+') {|f| f.write(code) }
end
desc "Build coffee-script-source gem"
task :gem do
require 'rubygems'
require 'rubygems/package'
gemspec = Gem::Specification.new do |s|
s.name = 'coffee-script-source'
s.version = JSON.parse(File.read('package.json'))["version"]
s.date = Time.now.strftime("%Y-%m-%d")
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"
s.description = <<-EOS
CoffeeScript is a little language that compiles into JavaScript.
Underneath all of those embarrassing braces and semicolons,
JavaScript has always had a gorgeous object model at its heart.
CoffeeScript is an attempt to expose the good parts of JavaScript
in a simple way.
EOS
s.files = [
'lib/coffee_script/coffee-script.js',
'lib/coffee_script/source.rb'
]
s.authors = ['Jeremy Ashkenas']
s.email = 'jashkenas@gmail.com'
s.rubyforge_project = 'coffee-script-source'
end
file = File.open("coffee-script-source.gem", "w")
Gem::Package.open(file, 'w') do |pkg|
pkg.metadata = gemspec.to_yaml
path = "lib/coffee_script/source.rb"
contents = <<-ERUBY
module CoffeeScript
module Source
def self.bundled_path
File.expand_path("../coffee-script.js", __FILE__)
end
end
end
ERUBY
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
tar_io.write(contents)
end
contents = File.read("extras/coffee-script.js")
path = "lib/coffee_script/coffee-script.js"
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
tar_io.write(contents)
end
end
end

View File

@@ -1,15 +1,7 @@
#!/usr/bin/env node
process.mixin(require('sys'));
var path = require('path');
var fs = require('fs');
var lib = null;
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
if (fs.lstatSync(__filename).isSymbolicLink()) {
lib = path.join(path.dirname(fs.readlinkSync(__filename)), '../lib');
} else {
lib = path.join(__dirname, '../lib');
}
require.paths.unshift(lib);
require('cake').run();
require(lib + '/cake').run();

View File

@@ -1,15 +1,7 @@
#!/usr/bin/env node
process.mixin(require('sys'));
var path = require('path');
var fs = require('fs');
var lib = null;
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
if (fs.lstatSync(__filename).isSymbolicLink()) {
lib = path.join(path.dirname(fs.readlinkSync(__filename)), '../lib');
} else {
lib = path.join(__dirname, '../lib');
}
require.paths.unshift(lib);
require('command_line').run();
require(lib + '/command').run();

View File

@@ -1,9 +1,11 @@
launch() if ignition is on
volume: 10 if band isnt spinal_tap
volume = 10 if band isnt SpinalTap
let_the_wild_rumpus_begin() unless answer is no
letTheWildRumpusBegin() unless answer is no
if car.speed < speed_limit then accelerate()
if car.speed < limit then accelerate()
print "My name is " + @name
winner = yes if pick in [47, 92, 13]
print inspect "My name is " + @name

View File

@@ -1,4 +0,0 @@
backwards: ->
alert arguments.reverse()
backwards "stairway", "to", "heaven"

View File

@@ -1,7 +1,2 @@
# Eat lunch.
lunch: eat food for food in ['toast', 'cheese', 'wine']
# Naive collision detection.
for roid in asteroids
for roid2 in asteroids when roid isnt roid2
roid.explode() if roid.overlaps roid2
eat food for food in ['toast', 'cheese', 'wine']

View File

@@ -1,2 +0,0 @@
greeting: "Hello CoffeeScript"
difficulty: 0.5

View File

@@ -0,0 +1,4 @@
###
CoffeeScript Compiler v0.9.6
Released under the MIT License
###

View File

@@ -1,5 +1,9 @@
process.mixin require 'assert'
fs = require 'fs'
task 'test', 'run each of the unit tests', ->
for test in test_files
fs.readFile test, (err, code) -> eval coffee.compile code
option '-o', '--output [DIR]', 'directory for compiled code'
task 'build:parser', 'rebuild the Jison parser', (options) ->
require 'jison'
code = require('./lib/grammar').parser.generate()
dir = options.output or 'lib'
fs.writeFile "#{dir}/parser.js", code

View File

@@ -1,25 +1,21 @@
class Animal
constructor: (@name) ->
move: (meters) ->
alert @name + " moved " + meters + "m."
class Snake extends Animal
constructor: (name) ->
@name: name
move: ->
alert "Slithering..."
super 5
class Horse extends Animal
constructor: (name) ->
@name: name
move: ->
alert "Galloping..."
super 45
sam: new Snake "Sammy the Python"
tom: new Horse "Tommy the Palomino"
sam = new Snake "Sammy the Python"
tom = new Horse "Tommy the Palomino"
sam.move()
tom.move()

View File

@@ -1,5 +1,5 @@
cholesterol: 127
cholesterol = 127
healthy: 200 > cholesterol > 60
healthy = 200 > cholesterol > 60

View File

@@ -1,9 +1,11 @@
mood: greatly_improved if singing
mood = greatlyImproved if singing
if happy and knows_it
claps_hands()
cha_cha_cha()
if happy and knowsIt
clapsHands()
chaChaCha()
else
showIt()
date: if friday then sue else jill
date = if friday then sue else jill
expensive ||= do_the_math()
options or= defaults

View File

@@ -0,0 +1,8 @@
fill = (container, liquid = "coffee") ->
"Filling the #{container} with #{liquid}..."

View File

@@ -1,4 +1,4 @@
hi: `function() {
hi = `function() {
return [document.title, "Hello JavaScript"].join(": ");
}`

View File

@@ -1,4 +1,4 @@
solipsism: true if mind? and not world?
solipsism = true if mind? and not world?
speed ?= 140

View File

@@ -1,9 +1,9 @@
grade: (student) ->
if student.excellent_work
grade = (student) ->
if student.excellentWork
"A+"
else if student.okay_stuff
if student.tried_hard then "B" else "B-"
else if student.okayStuff
if student.triedHard then "B" else "B-"
else
"C"
eldest: if 24 > 21 then "Liz" else "Ike"
eldest = if 24 > 21 then "Liz" else "Ike"

View File

@@ -1 +1 @@
six: (one: 1) + (two: 2) + (three: 3)
six = (one = 1) + (two = 2) + (three = 3)

View File

@@ -1,3 +1,3 @@
# The first ten global properties.
globals: (name for name of window)[0...10]
globals = (name for name of window)[0...10]

View File

@@ -1,6 +1,6 @@
Account: (customer, cart) ->
@customer: customer
@cart: cart
Account = (customer, cart) ->
@customer = customer
@cart = cart
$('.shopping_cart').bind 'click', (event) =>
@customer.purchase @cart

View File

@@ -1,2 +1,2 @@
square: (x) -> x * x
cube: (x) -> square(x) * x
square = (x) -> x * x
cube = (x) -> square(x) * x

View File

@@ -1,5 +1,5 @@
html: '''
<strong>
cup of coffeescript
</strong>
'''
html = '''
<strong>
cup of coffeescript
</strong>
'''

View File

@@ -0,0 +1,9 @@
OPERATOR = /// ^ (
?: [-=]> # function
| [-+*/%<>&|^!?=]= # compound assign / compare
| >>>=? # zero-fill right shift
| ([-+:])\1 # doubles
| ([&|<>])\2=? # logic / shift
| \?\. # soak access
| \.{2,3} # range or splat
) ///

View File

@@ -0,0 +1,6 @@
author = "Wittgenstein"
quote = "A picture is a fact. -- #{ author }"
sentence = "#{ 22 / 7 } is a decent approximation of π"

View File

@@ -1,5 +1,7 @@
weather_report: (location) ->
weatherReport = (location) ->
# Make an Ajax request to fetch the weather...
[location, 72, "Mostly Sunny"]
[city, temp, forecast]: weather_report "Berkeley, CA"
[city, temp, forecast] = weatherReport "Berkeley, CA"

View File

@@ -1,4 +1,4 @@
years_old: {max: 10, ida: 9, tim: 11}
yearsOld = max: 10, ida: 9, tim: 11
ages: for child, age of years_old
ages = for child, age of yearsOld
child + " is " + age

View File

@@ -1,13 +1,13 @@
futurists: {
futurists =
sculptor: "Umberto Boccioni"
painter: "Vladimir Burliuk"
poet: {
poet:
name: "F.T. Marinetti"
address: [
"Via Roma 42R"
"Bellagio, Italy 22021"
]
}
}
{poet: {name: poet, address: [street, city]}}: futurists
{poet: {name, address: [street, city]}} = futurists

View File

@@ -1,13 +1,17 @@
song: ["do", "re", "mi", "fa", "so"]
song = ["do", "re", "mi", "fa", "so"]
ages: {
max: 10
ida: 9
tim: 11
}
singers = {Jagger: "Rock", Elvis: "Roll"}
matrix: [
matrix = [
1, 0, 1
0, 0, 1
1, 1, 0
]
]
kids =
brother:
name: "Max"
age: 11
sister:
name: "Ida"
age: 9

View File

@@ -0,0 +1,3 @@
$('.account').attr class: 'active'
log object.class

View File

@@ -1,29 +1,28 @@
# Assignment:
number: 42
opposite_day: true
number = 42
opposite = true
# Conditions:
number: -42 if opposite_day
number = -42 if opposite
# Functions:
square: (x) -> x * x
square = (x) -> x * x
# Arrays:
list: [1, 2, 3, 4, 5]
list = [1, 2, 3, 4, 5]
# Objects:
math: {
math =
root: Math.sqrt
square: square
cube: (x) -> x * square x
}
# Splats:
race: (winner, runners...) ->
race = (winner, runners...) ->
print winner, runners
# Existence:
alert "I knew it!" if elvis?
# Array comprehensions:
cubed_list: math.cube num for num in list
cubes = (math.cube num for num in list)

View File

@@ -1,4 +1,4 @@
bait: 1000
and_switch: 0
theBait = 1000
theSwitch = 0
[bait, and_switch]: [and_switch, bait]
[theBait, theSwitch] = [theSwitch, theBait]

View File

@@ -0,0 +1,7 @@
tag = "<impossible>"
[open, contents..., close] = tag.split("")

View File

@@ -1,2 +1,2 @@
String::dasherize: ->
this.replace(/_/g, "-")
String::dasherize = ->
this.replace /_/g, "-"

View File

@@ -1,6 +1,2 @@
countdown: num for num in [10..1]
countdown = (num for num in [10..1])
egg_delivery: ->
for i in [0...eggs.length] by 12
dozen_eggs: eggs[i...i+12]
deliver new egg_carton(dozen)

View File

@@ -1,5 +1,5 @@
num: 1
change_numbers: ->
new_num: -1
num: 10
new_num: change_numbers()
outer = 1
changeNumbers = ->
inner = -1
outer = 10
inner = changeNumbers()

View File

@@ -1,6 +1,6 @@
numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
three_to_six: numbers[3..6]
copy = numbers[0...numbers.length]
numbers_copy: numbers[0...numbers.length]
middle = copy[3..6]

View File

@@ -1 +1 @@
lottery.draw_winner()?.address?.zipcode
zip = lottery.drawWinner?().address?.zipcode

View File

@@ -1,11 +1,11 @@
gold: silver: the_field: "unknown"
gold = silver = rest = "unknown"
award_medals: (first, second, rest...) ->
gold: first
silver: second
the_field: rest
awardMedals = (first, second, others...) ->
gold = first
silver = second
rest = others
contenders: [
contenders = [
"Michael Phelps"
"Liu Xiang"
"Yao Ming"
@@ -18,8 +18,8 @@ contenders: [
"Usain Bolt"
]
award_medals contenders...
awardMedals contenders...
alert "Gold: " + gold
alert "Silver: " + silver
alert "The Field: " + the_field
alert "The Field: " + rest

View File

@@ -1,5 +1,5 @@
numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers[3..6]: [-3, -4, -5, -6]
numbers[3..6] = [-3, -4, -5, -6]

View File

@@ -1,8 +1,8 @@
moby_dick: "Call me Ishmael. Some years ago --
never mind how long precisely -- having little
or no money in my purse, and nothing particular
to interest me on shore, I thought I would sail
about a little and see the watery part of the
world..."
mobyDick = "Call me Ishmael. Some years ago --
never mind how long precisely -- having little
or no money in my purse, and nothing particular
to interest me on shore, I thought I would sail
about a little and see the watery part of the
world..."

View File

@@ -1,10 +1,10 @@
switch day
when "Mon" then go_to_work()
when "Tue" then go_to_the_park()
when "Thu" then go_ice_fishing()
when "Mon" then go work
when "Tue" then go relax
when "Thu" then go iceFishing
when "Fri", "Sat"
if day is bingo_day
go_to_bingo()
go_dancing()
when "Sun" then go_to_church()
else go_to_work()
if day is bingoDay
go bingo
go dancing
when "Sun" then go church
else go work

View File

@@ -1,7 +1,7 @@
try
all_hell_breaks_loose()
cats_and_dogs_living_together()
allHellBreaksLoose()
catsAndDogsLivingTogether()
catch error
print error
finally
clean_up()
cleanUp()

View File

@@ -1,10 +1,10 @@
# Econ 101
if this.studying_economics
while supply > demand then buy()
while supply < demand then sell()
if this.studyingEconomics
buy() while supply > demand
sell() until supply > demand
# Nursery Rhyme
num: 6
lyrics: while num -= 1
num = 6
lyrics = while num -= 1
num + " little monkeys, jumping on the bed.
One fell out and bumped his head."

View File

@@ -1,21 +1,23 @@
body {
font-size: 14px;
font-size: 13px;
line-height: 20px;
color: #191933;
font-family: Arial, Helvetica, sans-serif;
font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif !important;
}
div.container {
.container {
width: 950px;
margin: 100px 0 50px 50px;
margin: 0;
padding: 80px 0px 50px 50px;
}
p {
p, li {
width: 625px;
}
a {
color: #000055;
}
h1, h2, h3, h4, h5, h6 {
h1, h2, h3, h4, h5, h6, b.header {
margin-top: 40px;
margin-bottom: 15px;
}
br.clear {
height: 0;
@@ -27,7 +29,6 @@ ul {
b.header {
color: #000055;
display: block;
margin: 40px 0 5px 0;
font-size: 16px;
}
li {
@@ -43,6 +44,15 @@ table {
td {
padding: 9px 15px 9px 0;
}
table.definitions {
width: auto;
margin: 30px 0;
border-left: 6px solid #ccccdd;
}
table.definitions td {
text-align: center;
padding: 5px 20px;
}
code, pre, tt, textarea {
font-family: Monaco, Consolas, "Lucida Console", monospace;
font-size: 12px;
@@ -54,12 +64,10 @@ code, pre, tt, textarea {
tt {
background: #f8f8ff;
border: 1px solid #dedede;
font-size: 85%;
padding: 0px 0.2em;
}
pre {
border-left: 6px solid #222255;
margin-left: 13px;
border-left: 6px solid #ccccdd;
padding: 3px 0 3px 12px;
font-size: 12px;
}
@@ -68,6 +76,11 @@ code, pre, tt, textarea {
margin-left: 0;
padding-left: 0;
}
.timestamp {
font-size: 12px;
font-weight: normal;
color: black;
}
div.code {
position: relative;
border: 1px solid #cacaca;
@@ -75,6 +88,7 @@ div.code {
padding: 7px 0 10px 0;
-moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;
-webkit-box-shadow: 0px 0px 7px #cacaca;
zoom: 1;
}
div.code button {
position: absolute;
@@ -105,14 +119,15 @@ div.code {
position: fixed;
z-index: 100;
height: 50px;
min-width: 490px;
left: 40px; right: 40px; top: 25px;
background: #ddd;
padding-left: 235px;
background: #eee;
background: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#d0d0d0));
background: -moz-linear-gradient(top, #f5f5f5, #d0d0d0);
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#F5F5F5', EndColorStr='#D0D0D0');
border: 1px solid #aaa;
-webkit-border-radius: 20px; -moz-border-radius: 20px; border-radius: 20px;
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
-webkit-box-shadow: 0 0 7px #aaa; -moz-box-shadow: 0 0 7px #aaa;
}
#logo {
display: block;
@@ -124,50 +139,56 @@ div.code {
#error {
position: absolute;
-webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px;
right: 15px; top: 15px; left: 565px;
right: 15px; top: 15px; left: 730px;
height: 15px;
padding: 2px 5px;
background: #fdcdcc;
color: #864544;
border: 1px solid #864544;
font: 10px/15px Arial;
font-size: 10px;
line-height: 15px;
overflow: hidden;
text-transform: uppercase;
}
.navigation {
height: 50px;
font: bold 11px/50px Arial;
font-size: 11px;
line-height: 50px;
text-transform: uppercase;
position: relative;
float: left;
padding: 0 20px;
border: 1px solid #bbb;
border-top: 0; border-bottom: 0;
border-top: 0; border-bottom: 0; border-left-width: 0;
cursor: pointer;
}
body.full_screen .navigation {
position: static;
}
.navigation.try {
border-left: 0;
.navigation.toc {
border-left-width: 1px;
}
.navigation:hover,
.navigation.active {
background: #d0d0d0;
background: #eee;
background: -webkit-gradient(linear, left top, left bottom, from(#f0f0f0), to(#c0c0c0));
background: -moz-linear-gradient(top, #f0f0f0, #c0c0c0);
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#F0F0F0', EndColorStr='#C0C0C0');
}
.navigation .button {
font-weight: bold;
}
.navigation .contents {
display: none;
position: absolute;
background: #fff;
top: 50px; left: 0;
top: 51px; left: 0;
padding: 5px 0;
margin-left: -1px;
border: 1px solid #aaa; border-top: 0;
-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
-webkit-border-top-left-radius: 0; -moz-border-radius-topleft: 0;
-webkit-border-top-right-radius: 0; -moz-border-radius-topright: 0;
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
-webkit-box-shadow: 0 5px 10px #999; -moz-box-shadow: 0 5px 10px #999;
}
.navigation.active .contents {
display: block;
@@ -180,7 +201,7 @@ div.code {
body.full_screen .navigation .contents.repl_wrapper {
position: fixed;
width: auto; height: auto;
left: 60px; top: 75px; right: 60px; bottom: 30px;
left: 60px; top: 77px; right: 60px; bottom: 30px;
}
.navigation .contents.repl_wrapper .code {
-webkit-box-shadow: none; -moz-box-shadow: none;
@@ -195,18 +216,24 @@ div.code {
.navigation .code button {
bottom: 10px;
text-transform: none;
line-height: 14px;
left: auto; right: auto;
}
.navigation .full_screen, .navigation .minimize {
right: auto;
.navigation .code .run {
width: 40px;
right: 10px;
}
.navigation .code .full_screen, .navigation .code .minimize {
left: 10px;
display: none;
width: 90px;
}
body.minimized .full_screen, body.full_screen .minimize {
body.minimized .code .full_screen, body.full_screen .code .minimize {
display: inline;
}
.navigation .contents a {
display: block;
width: 300px;
width: 290px;
text-transform: none;
text-decoration: none;
font-weight: normal;
@@ -239,7 +266,7 @@ div.code {
}
#repl_source {
width: 96%;
height: 100%;
height: 250px;
border: 0;
resize: none;
}
@@ -258,6 +285,9 @@ div.code {
margin-bottom: 0;
top: 10px; left: 10px; right: 10px; bottom: 40px;
}
body.full_screen #repl_source {
height: 100%;
}
body.full_screen #repl_source_wrap {
right: 50%;
}

View File

@@ -0,0 +1,25 @@
<!DOCTYPE html> <html> <head> <title>browser.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> browser.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Override exported methods for non-Node.js engines.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s1">&#39;./coffee-script&#39;</span>
<span class="nv">CoffeeScript.require = </span><span class="nx">require</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Use standard JavaScript <code>eval</code> to eval code.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript.eval = </span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nb">eval</span> <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Running code does not provide access to this scope.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript.run = </span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nv">options = </span><span class="p">{})</span> <span class="o">-&gt;</span>
<span class="nv">options.bare = </span><span class="kc">on</span>
<span class="nb">Function</span><span class="p">(</span><span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)()</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>If we're not in a browser environment, we're finished with the public API.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">return</span> <span class="nx">unless</span> <span class="nb">window</span><span class="o">?</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Load a remote script from the current domain via XHR.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript.load = </span><span class="p">(</span><span class="nx">url</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">xhr = </span><span class="k">new</span> <span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">ActiveXObject</span> <span class="o">or</span> <span class="nx">XMLHttpRequest</span><span class="p">)(</span><span class="s1">&#39;Microsoft.XMLHTTP&#39;</span><span class="p">)</span>
<span class="nx">xhr</span><span class="p">.</span><span class="nx">open</span> <span class="s1">&#39;GET&#39;</span><span class="p">,</span> <span class="nx">url</span><span class="p">,</span> <span class="kc">true</span>
<span class="nx">xhr</span><span class="p">.</span><span class="nx">overrideMimeType</span> <span class="s1">&#39;text/plain&#39;</span> <span class="k">if</span> <span class="s1">&#39;overrideMimeType&#39;</span> <span class="k">of</span> <span class="nx">xhr</span>
<span class="nv">xhr.onreadystatechange = </span><span class="o">-&gt;</span>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">responseText</span><span class="p">,</span> <span class="nx">options</span> <span class="k">if</span> <span class="nx">xhr</span><span class="p">.</span><span class="nx">readyState</span> <span class="o">is</span> <span class="mi">4</span>
<span class="nx">xhr</span><span class="p">.</span><span class="nx">send</span> <span class="kc">null</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Activate CoffeeScript in the browser by having it compile and evaluate
all script tags with a content-type of <code>text/coffeescript</code>.
This happens on page load.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">runScripts = </span><span class="o">-&gt;</span>
<span class="k">for</span> <span class="nx">script</span> <span class="k">in</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span> <span class="s1">&#39;script&#39;</span>
<span class="k">if</span> <span class="nx">script</span><span class="p">.</span><span class="nx">type</span> <span class="o">is</span> <span class="s1">&#39;text/coffeescript&#39;</span>
<span class="k">if</span> <span class="nx">script</span><span class="p">.</span><span class="nx">src</span>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">load</span> <span class="nx">script</span><span class="p">.</span><span class="nx">src</span>
<span class="k">else</span>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">script</span><span class="p">.</span><span class="nx">innerHTML</span>
<span class="kc">null</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Listen for window load, both in browsers and in IE.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nb">window</span><span class="p">.</span><span class="nx">addEventListener</span>
<span class="nx">addEventListener</span> <span class="s1">&#39;DOMContentLoaded&#39;</span><span class="p">,</span> <span class="nx">runScripts</span><span class="p">,</span> <span class="kc">no</span>
<span class="k">else</span>
<span class="nx">attachEvent</span> <span class="s1">&#39;onload&#39;</span><span class="p">,</span> <span class="nx">runScripts</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html> <html> <head> <title>cake.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> cake.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><code>cake</code> is a simplified version of <a href="http://www.gnu.org/software/make/">Make</a>
(<a href="http://rake.rubyforge.org/">Rake</a>, <a href="http://github.com/280north/jake">Jake</a>)
for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
and can call them from the command line, or invoke them from other tasks.</p>
<p>Running <code>cake</code> with no arguments will print out a list of all the tasks in the
current directory's Cakefile.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>External dependencies.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s1">&#39;fs&#39;</span>
<span class="nv">path = </span><span class="nx">require</span> <span class="s1">&#39;path&#39;</span>
<span class="nv">helpers = </span><span class="nx">require</span> <span class="s1">&#39;./helpers&#39;</span>
<span class="nv">optparse = </span><span class="nx">require</span> <span class="s1">&#39;./optparse&#39;</span>
<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s1">&#39;./coffee-script&#39;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Keep track of the list of defined tasks, the accepted options, and so on.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">tasks = </span><span class="p">{}</span>
<span class="nv">options = </span><span class="p">{}</span>
<span class="nv">switches = </span><span class="p">[]</span>
<span class="nv">oparse = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Mixin the top-level Cake functions for Cakefiles to use directly.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">helpers</span><span class="p">.</span><span class="nx">extend</span> <span class="nx">global</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Define a Cake task with a short name, an optional sentence description,
and the function to run as the action itself.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">task</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">description</span><span class="p">,</span> <span class="nx">action</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="p">[</span><span class="nx">action</span><span class="p">,</span> <span class="nx">description</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">description</span><span class="p">,</span> <span class="nx">action</span><span class="p">]</span> <span class="nx">unless</span> <span class="nx">action</span>
<span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="nx">name</span><span class="p">,</span> <span class="nx">description</span><span class="p">,</span> <span class="nx">action</span><span class="p">}</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Define an option that the Cakefile accepts. The parsed options hash,
containing all of the command-line options passed, will be made available
as the first argument to the action.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">option</span><span class="o">:</span> <span class="p">(</span><span class="nx">letter</span><span class="p">,</span> <span class="nx">flag</span><span class="p">,</span> <span class="nx">description</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">switches</span><span class="p">.</span><span class="nx">push</span> <span class="p">[</span><span class="nx">letter</span><span class="p">,</span> <span class="nx">flag</span><span class="p">,</span> <span class="nx">description</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Invoke another task in the current Cakefile.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">invoke</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">missingTask</span> <span class="nx">name</span> <span class="nx">unless</span> <span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span>
<span class="nx">tasks</span><span class="p">[</span><span class="nx">name</span><span class="p">].</span><span class="nx">action</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Run <code>cake</code>. Executes all of the tasks you pass, in order. Note that Node's
asynchrony may cause tasks to execute in a different order than you'd expect.
If no tasks are passed, print the help screen.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.run = </span><span class="o">-&gt;</span>
<span class="nx">path</span><span class="p">.</span><span class="nx">exists</span> <span class="s1">&#39;Cakefile&#39;</span><span class="p">,</span> <span class="p">(</span><span class="nx">exists</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">&quot;Cakefile not found in #{process.cwd()}&quot;</span><span class="p">)</span> <span class="nx">unless</span> <span class="nx">exists</span>
<span class="nv">args = </span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">slice</span> <span class="mi">2</span>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="s1">&#39;Cakefile&#39;</span><span class="p">).</span><span class="nx">toString</span><span class="p">(),</span> <span class="nx">fileName</span><span class="o">:</span> <span class="s1">&#39;Cakefile&#39;</span>
<span class="nv">oparse = </span><span class="k">new</span> <span class="nx">optparse</span><span class="p">.</span><span class="nx">OptionParser</span> <span class="nx">switches</span>
<span class="k">return</span> <span class="nx">printTasks</span><span class="p">()</span> <span class="nx">unless</span> <span class="nx">args</span><span class="p">.</span><span class="nx">length</span>
<span class="nv">options = </span><span class="nx">oparse</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">args</span><span class="p">)</span>
<span class="nx">invoke</span> <span class="nx">arg</span> <span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">options</span><span class="p">.</span><span class="nx">arguments</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Display the list of Cake tasks in a format similar to <code>rake -T</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">printTasks = </span><span class="o">-&gt;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s1">&#39;&#39;</span>
<span class="k">for</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">task</span> <span class="k">of</span> <span class="nx">tasks</span>
<span class="nv">spaces = </span><span class="mi">20</span> <span class="o">-</span> <span class="nx">name</span><span class="p">.</span><span class="nx">length</span>
<span class="nv">spaces = </span><span class="k">if</span> <span class="nx">spaces</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">then</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">spaces</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span>
<span class="nv">desc = </span><span class="k">if</span> <span class="nx">task</span><span class="p">.</span><span class="nx">description</span> <span class="k">then</span> <span class="s2">&quot;# #{task.description}&quot;</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;cake #{name}#{spaces} #{desc}&quot;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">oparse</span><span class="p">.</span><span class="nx">help</span><span class="p">()</span> <span class="k">if</span> <span class="nx">switches</span><span class="p">.</span><span class="nx">length</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Print an error and exit when attempting to all an undefined task.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">missingTask = </span><span class="p">(</span><span class="nx">task</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;No such task: \&quot;#{task}\&quot;&quot;</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">1</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,51 @@
<!DOCTYPE html> <html> <head> <title>coffee-script.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> coffee-script.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>CoffeeScript can be used both on the server, as a command-line compiler based
on Node.js/V8, or to run CoffeeScripts directly in the browser. This module
contains the main entry functions for tokenizing, parsing, and compiling
source CoffeeScript into JavaScript.</p>
<p>If included on a webpage, it will automatically sniff out, compile, and
execute all scripts present in <code>text/coffeescript</code> tags.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s1">&#39;fs&#39;</span>
<span class="nv">path = </span><span class="nx">require</span> <span class="s1">&#39;path&#39;</span>
<span class="p">{</span><span class="nx">Lexer</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;./lexer&#39;</span>
<span class="p">{</span><span class="nx">parser</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;./parser&#39;</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>TODO: Remove registerExtension when fully deprecated.</p> </td> <td class="code"> <div class="highlight"><pre><span class="k">if</span> <span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span>
<span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span><span class="p">[</span><span class="s1">&#39;.coffee&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="nx">module</span><span class="p">,</span> <span class="nx">filename</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">content = </span><span class="nx">compile</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span> <span class="nx">filename</span><span class="p">,</span> <span class="s1">&#39;utf8&#39;</span>
<span class="nx">module</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">content</span><span class="p">,</span> <span class="nx">filename</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">require</span><span class="p">.</span><span class="nx">registerExtension</span>
<span class="nx">require</span><span class="p">.</span><span class="nx">registerExtension</span> <span class="s1">&#39;.coffee&#39;</span><span class="p">,</span> <span class="p">(</span><span class="nx">content</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">compile</span> <span class="nx">content</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>The current CoffeeScript version number.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.VERSION = </span><span class="s1">&#39;0.9.6&#39;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Expose helpers for testing.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.helpers = </span><span class="nx">require</span> <span class="s1">&#39;./helpers&#39;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison
compiler.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.compile = compile = </span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nv">options = </span><span class="p">{})</span> <span class="o">-&gt;</span>
<span class="k">try</span>
<span class="p">(</span><span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">code</span><span class="p">).</span><span class="nx">compile</span> <span class="nx">options</span>
<span class="k">catch</span> <span class="nx">err</span>
<span class="nv">err.message = </span><span class="s2">&quot;In #{options.fileName}, #{err.message}&quot;</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">fileName</span>
<span class="k">throw</span> <span class="nx">err</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Tokenize a string of CoffeeScript code, and return the array of tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.tokens = </span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Parse a string of CoffeeScript code or an array of lexed tokens, and
return the AST. You can then compile it by calling <code>.compile()</code> on the root,
or traverse it by using <code>.traverse()</code> with a callback.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.nodes = </span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="k">typeof</span> <span class="nx">source</span> <span class="o">is</span> <span class="s1">&#39;string&#39;</span>
<span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">source</span><span class="p">,</span> <span class="nx">options</span>
<span class="k">else</span>
<span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">source</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Compile and execute a string of CoffeeScript (on the server), correctly
setting <code>__filename</code>, <code>__dirname</code>, and relative <code>require()</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.run = </span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>We want the root module.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">root = </span><span class="nx">module</span>
<span class="k">while</span> <span class="nx">root</span><span class="p">.</span><span class="nx">parent</span>
<span class="nv">root = </span><span class="nx">root</span><span class="p">.</span><span class="nx">parent</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Set the filename.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">root.filename = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span> <span class="nx">options</span><span class="p">.</span><span class="nx">fileName</span> <span class="o">or</span> <span class="s1">&#39;.&#39;</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Clear the module cache.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">root.moduleCache = </span><span class="p">{}</span> <span class="k">if</span> <span class="nx">root</span><span class="p">.</span><span class="nx">moduleCache</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Compile.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">root</span><span class="p">.</span><span class="nx">filename</span><span class="p">)</span> <span class="o">isnt</span> <span class="s1">&#39;.coffee&#39;</span> <span class="o">or</span> <span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span>
<span class="nx">root</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">compile</span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">),</span> <span class="nx">root</span><span class="p">.</span><span class="nx">filename</span>
<span class="k">else</span>
<span class="nx">root</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">root</span><span class="p">.</span><span class="nx">filename</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
The CoffeeScript REPL uses this to run the input.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.eval = </span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">__filename = </span><span class="nx">options</span><span class="p">.</span><span class="nx">fileName</span>
<span class="nv">__dirname = </span><span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span> <span class="nx">__filename</span>
<span class="nb">eval</span> <span class="nx">compile</span> <span class="nx">code</span><span class="p">,</span> <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Instantiate a Lexer for our use here.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">lexer = </span><span class="k">new</span> <span class="nx">Lexer</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>The real Lexer produces a generic stream of tokens. This object provides a
thin wrapper around it, compatible with the Jison API. We can then pass it
directly as a "Jison lexer".</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">parser.lexer =</span>
<span class="nx">lex</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="p">[</span><span class="nx">tag</span><span class="p">,</span> <span class="nx">@yytext</span><span class="p">,</span> <span class="nx">@yylineno</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@tokens</span><span class="p">[</span><span class="nx">@pos</span><span class="o">++</span><span class="p">]</span> <span class="o">or</span> <span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">]</span>
<span class="nx">tag</span>
<span class="nx">setInput</span><span class="o">:</span> <span class="p">(</span><span class="nx">@tokens</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="vi">@pos = </span><span class="mi">0</span>
<span class="nx">upcomingInput</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="s2">&quot;&quot;</span>
<span class="nv">parser.yy = </span><span class="nx">require</span> <span class="s1">&#39;./nodes&#39;</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,152 @@
<!DOCTYPE html> <html> <head> <title>command.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> command.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>The <code>coffee</code> utility. Handles command-line compilation of CoffeeScript
into various forms: saved into <code>.js</code> files or printed to stdout, piped to
<a href="http://javascriptlint.com/">JSLint</a> or recompiled every time the source is
saved, printed as a token stream or as the syntax tree, or launch an
interactive REPL.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>External dependencies.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s1">&#39;fs&#39;</span>
<span class="nv">path = </span><span class="nx">require</span> <span class="s1">&#39;path&#39;</span>
<span class="nv">util = </span><span class="nx">require</span> <span class="s1">&#39;util&#39;</span>
<span class="nv">helpers = </span><span class="nx">require</span> <span class="s1">&#39;./helpers&#39;</span>
<span class="nv">optparse = </span><span class="nx">require</span> <span class="s1">&#39;./optparse&#39;</span>
<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s1">&#39;./coffee-script&#39;</span>
<span class="p">{</span><span class="nx">spawn</span><span class="p">,</span> <span class="nx">exec</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;child_process&#39;</span>
<span class="p">{</span><span class="nx">EventEmitter</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;events&#39;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Allow CoffeeScript to emit Node.js events.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">helpers</span><span class="p">.</span><span class="nx">extend</span> <span class="nx">CoffeeScript</span><span class="p">,</span> <span class="k">new</span> <span class="nx">EventEmitter</span>
<span class="nv">printLine = </span><span class="p">(</span><span class="nx">line</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">process</span><span class="p">.</span><span class="nx">stdout</span><span class="p">.</span><span class="nx">write</span> <span class="nx">line</span> <span class="o">+</span> <span class="s1">&#39;\n&#39;</span>
<span class="nv">printWarn = </span><span class="p">(</span><span class="nx">line</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">process</span><span class="p">.</span><span class="nx">binding</span><span class="p">(</span><span class="s1">&#39;stdio&#39;</span><span class="p">).</span><span class="nx">writeError</span> <span class="nx">line</span> <span class="o">+</span> <span class="s1">&#39;\n&#39;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>The help banner that is printed when <code>coffee</code> is called without arguments.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">BANNER = </span><span class="s1">&#39;&#39;&#39;</span>
<span class="s1"> Usage: coffee [options] path/to/script.coffee</span>
<span class="s1"> &#39;&#39;&#39;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>The list of all the valid option flags that <code>coffee</code> knows how to handle.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">SWITCHES = </span><span class="p">[</span>
<span class="p">[</span><span class="s1">&#39;-c&#39;</span><span class="p">,</span> <span class="s1">&#39;--compile&#39;</span><span class="p">,</span> <span class="s1">&#39;compile to JavaScript and save as .js files&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-i&#39;</span><span class="p">,</span> <span class="s1">&#39;--interactive&#39;</span><span class="p">,</span> <span class="s1">&#39;run an interactive CoffeeScript REPL&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-o&#39;</span><span class="p">,</span> <span class="s1">&#39;--output [DIR]&#39;</span><span class="p">,</span> <span class="s1">&#39;set the directory for compiled JavaScript&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-w&#39;</span><span class="p">,</span> <span class="s1">&#39;--watch&#39;</span><span class="p">,</span> <span class="s1">&#39;watch scripts for changes, and recompile&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-p&#39;</span><span class="p">,</span> <span class="s1">&#39;--print&#39;</span><span class="p">,</span> <span class="s1">&#39;print the compiled JavaScript to stdout&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-l&#39;</span><span class="p">,</span> <span class="s1">&#39;--lint&#39;</span><span class="p">,</span> <span class="s1">&#39;pipe the compiled JavaScript through JSLint&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-s&#39;</span><span class="p">,</span> <span class="s1">&#39;--stdio&#39;</span><span class="p">,</span> <span class="s1">&#39;listen for and compile scripts over stdio&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-e&#39;</span><span class="p">,</span> <span class="s1">&#39;--eval&#39;</span><span class="p">,</span> <span class="s1">&#39;compile a string from the command line&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-r&#39;</span><span class="p">,</span> <span class="s1">&#39;--require [FILE*]&#39;</span><span class="p">,</span> <span class="s1">&#39;require a library before executing your script&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-b&#39;</span><span class="p">,</span> <span class="s1">&#39;--bare&#39;</span><span class="p">,</span> <span class="s1">&#39;compile without the top-level function wrapper&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-t&#39;</span><span class="p">,</span> <span class="s1">&#39;--tokens&#39;</span><span class="p">,</span> <span class="s1">&#39;print the tokens that the lexer produces&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-n&#39;</span><span class="p">,</span> <span class="s1">&#39;--nodes&#39;</span><span class="p">,</span> <span class="s1">&#39;print the parse tree that Jison produces&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-v&#39;</span><span class="p">,</span> <span class="s1">&#39;--version&#39;</span><span class="p">,</span> <span class="s1">&#39;display CoffeeScript version&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;-h&#39;</span><span class="p">,</span> <span class="s1">&#39;--help&#39;</span><span class="p">,</span> <span class="s1">&#39;display this help message&#39;</span><span class="p">]</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Switches that are still supported, but will cause a warning message.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">DEPRECATED_SWITCHES = </span><span class="p">[</span>
<span class="p">[</span><span class="s1">&#39;--no-wrap&#39;</span><span class="p">,</span> <span class="s1">&#39;compile without the top-level function wrapper&#39;</span><span class="p">]</span>
<span class="p">]</span>
<span class="nv">ALL_SWITCHES = </span><span class="nx">SWITCHES</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">DEPRECATED_SWITCHES</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Top-level objects shared by all the functions.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">opts = </span><span class="p">{}</span>
<span class="nv">sources = </span><span class="p">[]</span>
<span class="nv">optionParser = </span><span class="kc">null</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Run <code>coffee</code> by parsing passed options and determining what action to take.
Many flags cause us to divert before compiling anything. Flags passed after
<code>--</code> will be passed verbatim to your script as arguments in <code>process.argv</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.run = </span><span class="o">-&gt;</span>
<span class="nx">parseOptions</span><span class="p">()</span>
<span class="k">return</span> <span class="nx">usage</span><span class="p">()</span> <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">help</span>
<span class="k">return</span> <span class="nx">version</span><span class="p">()</span> <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">version</span>
<span class="k">return</span> <span class="nx">require</span> <span class="s1">&#39;./repl&#39;</span> <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">interactive</span>
<span class="k">return</span> <span class="nx">compileStdio</span><span class="p">()</span> <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">stdio</span>
<span class="k">return</span> <span class="nx">compileScript</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">sources</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nb">eval</span>
<span class="k">return</span> <span class="nx">require</span> <span class="s1">&#39;./repl&#39;</span> <span class="nx">unless</span> <span class="nx">sources</span><span class="p">.</span><span class="nx">length</span>
<span class="nv">separator = </span><span class="nx">sources</span><span class="p">.</span><span class="nx">indexOf</span> <span class="s1">&#39;--&#39;</span>
<span class="nv">flags = </span><span class="p">[]</span>
<span class="k">if</span> <span class="nx">separator</span> <span class="o">&gt;=</span> <span class="mi">0</span>
<span class="nv">flags = </span><span class="nx">sources</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">separator</span> <span class="o">+</span> <span class="mi">1</span>
<span class="nx">sources</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
<span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">run</span>
<span class="nv">flags = </span><span class="nx">sources</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="nx">concat</span> <span class="nx">flags</span>
<span class="nv">process.ARGV = process.argv = </span><span class="nx">flags</span>
<span class="nx">compileScripts</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Asynchronously read in each CoffeeScript in a list of source files and
compile them. If a directory is passed, recursively compile all
'.coffee' extension source files in it and all subdirectories.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">compileScripts = </span><span class="o">-&gt;</span>
<span class="k">for</span> <span class="nx">source</span> <span class="k">in</span> <span class="nx">sources</span>
<span class="nv">base = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">source</span><span class="p">)</span>
<span class="nv">compile = </span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">topLevel</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">path</span><span class="p">.</span><span class="nx">exists</span> <span class="nx">source</span><span class="p">,</span> <span class="p">(</span><span class="nx">exists</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">&quot;File not found: #{source}&quot;</span> <span class="nx">unless</span> <span class="nx">exists</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">stat</span> <span class="nx">source</span><span class="p">,</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">stats</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="nx">stats</span><span class="p">.</span><span class="nx">isDirectory</span><span class="p">()</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">readdir</span> <span class="nx">source</span><span class="p">,</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">files</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">for</span> <span class="nx">file</span> <span class="k">in</span> <span class="nx">files</span>
<span class="nx">compile</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">file</span><span class="p">)</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">topLevel</span> <span class="o">or</span> <span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">source</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;.coffee&#39;</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">readFile</span> <span class="nx">source</span><span class="p">,</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">code</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">compileScript</span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">code</span><span class="p">.</span><span class="nx">toString</span><span class="p">(),</span> <span class="nx">base</span><span class="p">)</span>
<span class="nx">watch</span> <span class="nx">source</span><span class="p">,</span> <span class="nx">base</span> <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">watch</span>
<span class="nx">compile</span> <span class="nx">source</span><span class="p">,</span> <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Compile a single source script, containing the given code, according to the
requested options. If evaluating the script directly sets <code>__filename</code>,
<code>__dirname</code> and <code>module.filename</code> to be correct relative to the script's path.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">compileScript = </span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">input</span><span class="p">,</span> <span class="nx">base</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">o = </span><span class="nx">opts</span>
<span class="nv">options = </span><span class="nx">compileOptions</span> <span class="nx">file</span>
<span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">require</span>
<span class="nx">require</span><span class="p">(</span><span class="k">if</span> <span class="nx">helpers</span><span class="p">.</span><span class="nx">starts</span><span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="s1">&#39;.&#39;</span><span class="p">)</span> <span class="k">then</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">realpathSync</span><span class="p">(</span><span class="nx">req</span><span class="p">)</span> <span class="k">else</span> <span class="nx">req</span><span class="p">)</span> <span class="k">for</span> <span class="nx">req</span> <span class="k">in</span> <span class="nx">o</span><span class="p">.</span><span class="nx">require</span>
<span class="k">try</span>
<span class="nv">t = task = </span><span class="p">{</span><span class="nx">file</span><span class="p">,</span> <span class="nx">input</span><span class="p">,</span> <span class="nx">options</span><span class="p">}</span>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">emit</span> <span class="s1">&#39;compile&#39;</span><span class="p">,</span> <span class="nx">task</span>
<span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">tokens</span> <span class="k">then</span> <span class="nx">printTokens</span> <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">tokens</span> <span class="nx">t</span><span class="p">.</span><span class="nx">input</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">nodes</span> <span class="k">then</span> <span class="nx">printLine</span> <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">nodes</span><span class="p">(</span><span class="nx">t</span><span class="p">.</span><span class="nx">input</span><span class="p">).</span><span class="nx">toString</span><span class="p">().</span><span class="nx">trim</span><span class="p">()</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">run</span> <span class="k">then</span> <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">t</span><span class="p">.</span><span class="nx">input</span><span class="p">,</span> <span class="nx">t</span><span class="p">.</span><span class="nx">options</span>
<span class="k">else</span>
<span class="nv">t.output = </span><span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">t</span><span class="p">.</span><span class="nx">input</span><span class="p">,</span> <span class="nx">t</span><span class="p">.</span><span class="nx">options</span>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">emit</span> <span class="s1">&#39;success&#39;</span><span class="p">,</span> <span class="nx">task</span>
<span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">print</span> <span class="k">then</span> <span class="nx">printLine</span> <span class="nx">t</span><span class="p">.</span><span class="nx">output</span><span class="p">.</span><span class="nx">trim</span><span class="p">()</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">compile</span> <span class="k">then</span> <span class="nx">writeJs</span> <span class="nx">t</span><span class="p">.</span><span class="nx">file</span><span class="p">,</span> <span class="nx">t</span><span class="p">.</span><span class="nx">output</span><span class="p">,</span> <span class="nx">base</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">lint</span> <span class="k">then</span> <span class="nx">lint</span> <span class="nx">t</span><span class="p">.</span><span class="nx">file</span><span class="p">,</span> <span class="nx">t</span><span class="p">.</span><span class="nx">output</span>
<span class="k">catch</span> <span class="nx">err</span>
<span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">emit</span> <span class="s1">&#39;failure&#39;</span><span class="p">,</span> <span class="nx">err</span><span class="p">,</span> <span class="nx">task</span>
<span class="k">return</span> <span class="k">if</span> <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">listeners</span><span class="p">(</span><span class="s1">&#39;failure&#39;</span><span class="p">).</span><span class="nx">length</span>
<span class="k">return</span> <span class="nx">printLine</span> <span class="nx">err</span><span class="p">.</span><span class="nx">message</span> <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">watch</span>
<span class="nx">printWarn</span> <span class="nx">err</span><span class="p">.</span><span class="nx">stack</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Attach the appropriate listeners to compile scripts incoming over <strong>stdin</strong>,
and write them back to <strong>stdout</strong>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">compileStdio = </span><span class="o">-&gt;</span>
<span class="nv">code = </span><span class="s1">&#39;&#39;</span>
<span class="nv">stdin = </span><span class="nx">process</span><span class="p">.</span><span class="nx">openStdin</span><span class="p">()</span>
<span class="nx">stdin</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="p">(</span><span class="nx">buffer</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">code</span> <span class="o">+=</span> <span class="nx">buffer</span><span class="p">.</span><span class="nx">toString</span><span class="p">()</span> <span class="k">if</span> <span class="nx">buffer</span>
<span class="nx">stdin</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;end&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
<span class="nx">compileScript</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Watch a source CoffeeScript file using <code>fs.watchFile</code>, recompiling it every
time the file is updated. May be used in combination with other options,
such as <code>--lint</code> or <code>--print</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">watch = </span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">base</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">watchFile</span> <span class="nx">source</span><span class="p">,</span> <span class="p">{</span><span class="nx">persistent</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">interval</span><span class="o">:</span> <span class="mi">500</span><span class="p">},</span> <span class="p">(</span><span class="nx">curr</span><span class="p">,</span> <span class="nx">prev</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">return</span> <span class="k">if</span> <span class="nx">curr</span><span class="p">.</span><span class="nx">size</span> <span class="o">is</span> <span class="nx">prev</span><span class="p">.</span><span class="nx">size</span> <span class="o">and</span> <span class="nx">curr</span><span class="p">.</span><span class="nx">mtime</span><span class="p">.</span><span class="nx">getTime</span><span class="p">()</span> <span class="o">is</span> <span class="nx">prev</span><span class="p">.</span><span class="nx">mtime</span><span class="p">.</span><span class="nx">getTime</span><span class="p">()</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">readFile</span> <span class="nx">source</span><span class="p">,</span> <span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">code</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">throw</span> <span class="nx">err</span> <span class="k">if</span> <span class="nx">err</span>
<span class="nx">compileScript</span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">code</span><span class="p">.</span><span class="nx">toString</span><span class="p">(),</span> <span class="nx">base</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Write out a JavaScript source file with the compiled code. By default, files
are written out in <code>cwd</code> as <code>.js</code> files with the same name, but the output
directory can be customized with <code>--output</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">writeJs = </span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">js</span><span class="p">,</span> <span class="nx">base</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">filename = </span><span class="nx">path</span><span class="p">.</span><span class="nx">basename</span><span class="p">(</span><span class="nx">source</span><span class="p">,</span> <span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">source</span><span class="p">))</span> <span class="o">+</span> <span class="s1">&#39;.js&#39;</span>
<span class="nv">srcDir = </span><span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span> <span class="nx">source</span>
<span class="nv">baseDir = </span><span class="nx">srcDir</span><span class="p">.</span><span class="nx">substring</span> <span class="nx">base</span><span class="p">.</span><span class="nx">length</span>
<span class="nv">dir = </span><span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">output</span> <span class="k">then</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">output</span><span class="p">,</span> <span class="nx">baseDir</span> <span class="k">else</span> <span class="nx">srcDir</span>
<span class="nv">jsPath = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">dir</span><span class="p">,</span> <span class="nx">filename</span>
<span class="nv">compile = </span><span class="o">-&gt;</span>
<span class="nv">js = </span><span class="s1">&#39; &#39;</span> <span class="k">if</span> <span class="nx">js</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;=</span> <span class="mi">0</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">writeFile</span> <span class="nx">jsPath</span><span class="p">,</span> <span class="nx">js</span><span class="p">,</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="nx">err</span> <span class="k">then</span> <span class="nx">printLine</span> <span class="nx">err</span><span class="p">.</span><span class="nx">message</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">compile</span> <span class="o">and</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">watch</span> <span class="k">then</span> <span class="nx">util</span><span class="p">.</span><span class="nx">log</span> <span class="s2">&quot;compiled #{source}&quot;</span>
<span class="nx">path</span><span class="p">.</span><span class="nx">exists</span> <span class="nx">dir</span><span class="p">,</span> <span class="p">(</span><span class="nx">exists</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="nx">exists</span> <span class="k">then</span> <span class="nx">compile</span><span class="p">()</span> <span class="k">else</span> <span class="nx">exec</span> <span class="s2">&quot;mkdir -p #{dir}&quot;</span><span class="p">,</span> <span class="nx">compile</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Pipe compiled JS through JSLint (requires a working <code>jsl</code> command), printing
any errors or warnings that arise.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">lint = </span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">js</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">printIt = </span><span class="p">(</span><span class="nx">buffer</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">printLine</span> <span class="nx">file</span> <span class="o">+</span> <span class="s1">&#39;:\t&#39;</span> <span class="o">+</span> <span class="nx">buffer</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">trim</span><span class="p">()</span>
<span class="nv">conf = </span><span class="nx">__dirname</span> <span class="o">+</span> <span class="s1">&#39;/../extras/jsl.conf&#39;</span>
<span class="nv">jsl = </span><span class="nx">spawn</span> <span class="s1">&#39;jsl&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;-nologo&#39;</span><span class="p">,</span> <span class="s1">&#39;-stdin&#39;</span><span class="p">,</span> <span class="s1">&#39;-conf&#39;</span><span class="p">,</span> <span class="nx">conf</span><span class="p">]</span>
<span class="nx">jsl</span><span class="p">.</span><span class="nx">stdout</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="nx">printIt</span>
<span class="nx">jsl</span><span class="p">.</span><span class="nx">stderr</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="nx">printIt</span>
<span class="nx">jsl</span><span class="p">.</span><span class="nx">stdin</span><span class="p">.</span><span class="nx">write</span> <span class="nx">js</span>
<span class="nx">jsl</span><span class="p">.</span><span class="nx">stdin</span><span class="p">.</span><span class="nx">end</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Pretty-print a stream of tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">printTokens = </span><span class="p">(</span><span class="nx">tokens</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">strings = </span><span class="k">for</span> <span class="nx">token</span> <span class="k">in</span> <span class="nx">tokens</span>
<span class="p">[</span><span class="nx">tag</span><span class="p">,</span> <span class="nx">value</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">token</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">toString</span><span class="p">().</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\n/</span><span class="p">,</span> <span class="s1">&#39;\\n&#39;</span><span class="p">)]</span>
<span class="s2">&quot;[#{tag} #{value}]&quot;</span>
<span class="nx">printLine</span> <span class="nx">strings</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Use the <a href="optparse.html">OptionParser module</a> to extract all options from
<code>process.argv</code> that are specified in <code>SWITCHES</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">parseOptions = </span><span class="o">-&gt;</span>
<span class="nv">optionParser = </span><span class="k">new</span> <span class="nx">optparse</span><span class="p">.</span><span class="nx">OptionParser</span> <span class="nx">ALL_SWITCHES</span><span class="p">,</span> <span class="nx">BANNER</span>
<span class="nv">o = opts = </span><span class="nx">optionParser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">slice</span> <span class="mi">2</span>
<span class="nx">o</span><span class="p">.</span><span class="nx">compile</span> <span class="o">or=</span> <span class="o">!!</span><span class="nx">o</span><span class="p">.</span><span class="nx">output</span>
<span class="nv">o.run = </span><span class="o">not</span> <span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">compile</span> <span class="o">or</span> <span class="nx">o</span><span class="p">.</span><span class="nx">print</span> <span class="o">or</span> <span class="nx">o</span><span class="p">.</span><span class="nx">lint</span><span class="p">)</span>
<span class="nv">o.print = </span><span class="o">!!</span> <span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">print</span> <span class="o">or</span> <span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nb">eval</span> <span class="o">or</span> <span class="nx">o</span><span class="p">.</span><span class="nx">stdio</span> <span class="o">and</span> <span class="nx">o</span><span class="p">.</span><span class="nx">compile</span><span class="p">))</span>
<span class="nv">sources = </span><span class="nx">o</span><span class="p">.</span><span class="nx">arguments</span>
<span class="k">if</span> <span class="nx">opts</span><span class="p">[</span><span class="s1">&#39;no-wrap&#39;</span><span class="p">]</span>
<span class="nx">printWarn</span> <span class="s1">&#39;--no-wrap is deprecated; please use --bare instead.&#39;</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>The compile-time options to pass to the CoffeeScript compiler.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">compileOptions = </span><span class="p">(</span><span class="nx">fileName</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="p">{</span><span class="nx">fileName</span><span class="p">,</span> <span class="nx">bare</span><span class="o">:</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">bare</span> <span class="o">or</span> <span class="nx">opts</span><span class="p">[</span><span class="s1">&#39;no-wrap&#39;</span><span class="p">]}</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Print the <code>--help</code> usage message and exit. Deprecated switches are not
shown.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">usage = </span><span class="o">-&gt;</span>
<span class="nx">printLine</span> <span class="p">(</span><span class="k">new</span> <span class="nx">optparse</span><span class="p">.</span><span class="nx">OptionParser</span> <span class="nx">SWITCHES</span><span class="p">,</span> <span class="nx">BANNER</span><span class="p">).</span><span class="nx">help</span><span class="p">()</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">0</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>Print the <code>--version</code> message and exit.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">version = </span><span class="o">-&gt;</span>
<span class="nx">printLine</span> <span class="s2">&quot;CoffeeScript version #{CoffeeScript.VERSION}&quot;</span>
<span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">0</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,186 @@
/*--------------------- Layout and Typography ----------------------------*/
body {
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
font-size: 15px;
line-height: 22px;
color: #252519;
margin: 0; padding: 0;
}
a {
color: #261a3b;
}
a:visited {
color: #261a3b;
}
p {
margin: 0 0 15px 0;
}
h1, h2, h3, h4, h5, h6 {
margin: 0px 0 15px 0;
}
h1 {
margin-top: 40px;
}
#container {
position: relative;
}
#background {
position: fixed;
top: 0; left: 525px; right: 0; bottom: 0;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
z-index: -1;
}
#jump_to, #jump_page {
background: white;
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
font: 10px Arial;
text-transform: uppercase;
cursor: pointer;
text-align: right;
}
#jump_to, #jump_wrapper {
position: fixed;
right: 0; top: 0;
padding: 5px 10px;
}
#jump_wrapper {
padding: 0;
display: none;
}
#jump_to:hover #jump_wrapper {
display: block;
}
#jump_page {
padding: 5px 0 3px;
margin: 0 0 25px 25px;
}
#jump_page .source {
display: block;
padding: 5px 10px;
text-decoration: none;
border-top: 1px solid #eee;
}
#jump_page .source:hover {
background: #f5f5ff;
}
#jump_page .source:first-child {
}
table td {
border: 0;
outline: 0;
}
td.docs, th.docs {
max-width: 450px;
min-width: 450px;
min-height: 5px;
padding: 10px 25px 1px 50px;
overflow-x: hidden;
vertical-align: top;
text-align: left;
}
.docs pre {
margin: 15px 0 15px;
padding-left: 15px;
}
.docs p tt, .docs p code {
background: #f8f8ff;
border: 1px solid #dedede;
font-size: 12px;
padding: 0 0.2em;
}
.pilwrap {
position: relative;
}
.pilcrow {
font: 12px Arial;
text-decoration: none;
color: #454545;
position: absolute;
top: 3px; left: -20px;
padding: 1px 2px;
opacity: 0;
-webkit-transition: opacity 0.2s linear;
}
td.docs:hover .pilcrow {
opacity: 1;
}
td.code, th.code {
padding: 14px 15px 16px 25px;
width: 100%;
vertical-align: top;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
}
pre, tt, code {
font-size: 12px; line-height: 18px;
font-family: Monaco, Consolas, "Lucida Console", monospace;
margin: 0; padding: 0;
}
/*---------------------- Syntax Highlighting -----------------------------*/
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
body .hll { background-color: #ffffcc }
body .c { color: #408080; font-style: italic } /* Comment */
body .err { border: 1px solid #FF0000 } /* Error */
body .k { color: #954121 } /* Keyword */
body .o { color: #666666 } /* Operator */
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
body .cp { color: #BC7A00 } /* Comment.Preproc */
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
body .cs { color: #408080; font-style: italic } /* Comment.Special */
body .gd { color: #A00000 } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #FF0000 } /* Generic.Error */
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
body .gi { color: #00A000 } /* Generic.Inserted */
body .go { color: #808080 } /* Generic.Output */
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
body .gt { color: #0040D0 } /* Generic.Traceback */
body .kc { color: #954121 } /* Keyword.Constant */
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
body .kp { color: #954121 } /* Keyword.Pseudo */
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
body .kt { color: #B00040 } /* Keyword.Type */
body .m { color: #666666 } /* Literal.Number */
body .s { color: #219161 } /* Literal.String */
body .na { color: #7D9029 } /* Name.Attribute */
body .nb { color: #954121 } /* Name.Builtin */
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
body .no { color: #880000 } /* Name.Constant */
body .nd { color: #AA22FF } /* Name.Decorator */
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
body .nf { color: #0000FF } /* Name.Function */
body .nl { color: #A0A000 } /* Name.Label */
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
body .nv { color: #19469D } /* Name.Variable */
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #666666 } /* Literal.Number.Float */
body .mh { color: #666666 } /* Literal.Number.Hex */
body .mi { color: #666666 } /* Literal.Number.Integer */
body .mo { color: #666666 } /* Literal.Number.Oct */
body .sb { color: #219161 } /* Literal.String.Backtick */
body .sc { color: #219161 } /* Literal.String.Char */
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
body .s2 { color: #219161 } /* Literal.String.Double */
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
body .sh { color: #219161 } /* Literal.String.Heredoc */
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
body .sx { color: #954121 } /* Literal.String.Other */
body .sr { color: #BB6688 } /* Literal.String.Regex */
body .s1 { color: #219161 } /* Literal.String.Single */
body .ss { color: #19469D } /* Literal.String.Symbol */
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
body .vc { color: #19469D } /* Name.Variable.Class */
body .vg { color: #19469D } /* Name.Variable.Global */
body .vi { color: #19469D } /* Name.Variable.Instance */
body .il { color: #666666 } /* Literal.Number.Integer.Long */

View File

@@ -0,0 +1,404 @@
<!DOCTYPE html> <html> <head> <title>grammar.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> grammar.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>The CoffeeScript parser is generated by <a href="http://github.com/zaach/jison">Jison</a>
from this grammar file. Jison is a bottom-up parser generator, similar in
style to <a href="http://www.gnu.org/software/bison">Bison</a>, implemented in JavaScript.
It can recognize <a href="http://en.wikipedia.org/wiki/LR_grammar">LALR(1), LR(0), SLR(1), and LR(1)</a>
type grammars. To create the Jison parser, we list the pattern to match
on the left-hand side, and the action to take (usually the creation of syntax
tree nodes) on the right. As the parser runs, it
shifts tokens from our token stream, from left to right, and
<a href="http://en.wikipedia.org/wiki/Bottom-up_parsing">attempts to match</a>
the token sequence against the rules below. When a match can be made, it
reduces into the <a href="http://en.wikipedia.org/wiki/Terminal_and_nonterminal_symbols">nonterminal</a>
(the enclosing name at the top), and we proceed from there.</p>
<p>If you run the <code>cake build:parser</code> command, Jison constructs a parse table
from our rules and saves it into <code>lib/parser.js</code>.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>The only dependency is on the <strong>Jison.Parser</strong>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">Parser</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;jison&#39;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h2>Jison DSL</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Since we're going to be wrapped in a function by Jison in any case, if our
action immediately returns a value, we can optimize by removing the function
wrapper and just returning the value directly.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">unwrap = </span><span class="sr">/^function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Our handy DSL for Jison grammar generation, thanks to
<a href="http://github.com/creationix">Tim Caswell</a>. For every rule in the grammar,
we pass the pattern-defining string, the action to run, and extra options,
optionally. If no action is specified, we simply pass the value of the
previous nonterminal.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">o = </span><span class="p">(</span><span class="nx">patternString</span><span class="p">,</span> <span class="nx">action</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">patternString = </span><span class="nx">patternString</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\s{2,}/g</span><span class="p">,</span> <span class="s1">&#39; &#39;</span>
<span class="k">return</span> <span class="p">[</span><span class="nx">patternString</span><span class="p">,</span> <span class="s1">&#39;$$ = $1;&#39;</span><span class="p">,</span> <span class="nx">options</span><span class="p">]</span> <span class="nx">unless</span> <span class="nx">action</span>
<span class="nv">action = </span><span class="k">if</span> <span class="nv">match = </span><span class="nx">unwrap</span><span class="p">.</span><span class="nx">exec</span> <span class="nx">action</span> <span class="k">then</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">else</span> <span class="s2">&quot;(#{action}())&quot;</span>
<span class="nv">action = </span><span class="nx">action</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\bnew /g</span><span class="p">,</span> <span class="s1">&#39;$&amp;yy.&#39;</span>
<span class="nv">action = </span><span class="nx">action</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\b(?:Expressions\.wrap|extend)\b/g</span><span class="p">,</span> <span class="s1">&#39;yy.$&amp;&#39;</span>
<span class="p">[</span><span class="nx">patternString</span><span class="p">,</span> <span class="s2">&quot;$$ = #{action};&quot;</span><span class="p">,</span> <span class="nx">options</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h2>Grammatical Rules</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>In all of the rules that follow, you'll see the name of the nonterminal as
the key to a list of alternative matches. With each match's action, the
dollar-sign variables are provided by Jison as references to the value of
their numeric position, so in this rule:</p>
<pre><code>"Expression UNLESS Expression"
</code></pre>
<p><code>$1</code> would be the value of the first <code>Expression</code>, <code>$2</code> would be the token
for the <code>UNLESS</code> terminal, and <code>$3</code> would be the value of the second
<code>Expression</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">grammar =</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>The <strong>Root</strong> is the top-level node in the syntax tree. Since we parse bottom-up,
all parsing must end here.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Root</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Expressions</span>
<span class="nx">o</span> <span class="s1">&#39;Body&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Block TERMINATOR&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Any list of statements and expressions, separated by line breaks or semicolons.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Body</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Line&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;Body TERMINATOR Line&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">push</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;Body TERMINATOR&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Expressions and statements, which make up a line in a body.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Line</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Expression&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Statement&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Pure statements which cannot be expressions.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Statement</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Return&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Throw&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Comment&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;STATEMENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>All the different types of expressions in our language. The basic unit of
CoffeeScript is the <strong>Expression</strong> -- everything that can be an expression
is one. Expressions serve as the building blocks of many other rules, making
them somewhat circular.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Expression</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Value&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Invocation&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Code&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Operation&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Assign&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;If&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Try&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;While&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;For&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Switch&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Class&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>An indented block of expressions. Note that the <a href="rewriter.html">Rewriter</a>
will convert some postfix forms into blocks for us, by adjusting the
token stream.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Block</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;INDENT Body OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;INDENT OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Expressions</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>A literal identifier, a variable name or property.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Identifier</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;IDENTIFIER&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Alphanumerics are separated from the other <strong>Literal</strong> matchers because
they can also serve as keys in object literals.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">AlphaNumeric</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;NUMBER&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;STRING&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>All of our immediate values. These can (in general), be passed straight
through and printed to JavaScript.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Literal</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;AlphaNumeric&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;JS&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;REGEX&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;BOOL&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
<span class="k">new</span> <span class="nx">Literal</span> <span class="k">if</span> <span class="nx">$1</span> <span class="o">is</span> <span class="s1">&#39;undefined&#39;</span> <span class="k">then</span> <span class="s1">&#39;void 0&#39;</span> <span class="k">else</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Assignment of a variable, property, or index to a value.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Assign</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Assignable = Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Assign</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;Assignable = INDENT Expression OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Assign</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$4</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Assignment when it happens within an object literal. The difference from
the ordinary <strong>Assign</strong> is that these allow numbers and strings as keys.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">AssignObj</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;ObjAssignable&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;ObjAssignable : Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Assign</span> <span class="k">new</span> <span class="nx">Value</span><span class="p">(</span><span class="nx">$1</span><span class="p">),</span> <span class="nx">$3</span><span class="p">,</span> <span class="s1">&#39;object&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;ObjAssignable :</span>
<span class="s1"> INDENT Expression OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Assign</span> <span class="k">new</span> <span class="nx">Value</span><span class="p">(</span><span class="nx">$1</span><span class="p">),</span> <span class="nx">$4</span><span class="p">,</span> <span class="s1">&#39;object&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Comment&#39;</span>
<span class="p">]</span>
<span class="nx">ObjAssignable</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Identifier&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;AlphaNumeric&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;ThisProperty&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>A return statement from a function body.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Return</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;RETURN Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Return</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;RETURN&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Return</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>A block comment.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Comment</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;HERECOMMENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Comment</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>The <strong>Code</strong> node is the function literal. It's defined by an indented block
of <strong>Expressions</strong> preceded by a function arrow, with an optional parameter
list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Code</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;PARAM_START ParamList PARAM_END FuncGlyph Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Code</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$5</span><span class="p">,</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;FuncGlyph Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Code</span> <span class="p">[],</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>CoffeeScript has two different symbols for functions. <code>-&gt;</code> is for ordinary
functions, and <code>=&gt;</code> is for functions bound to the current value of <em>this</em>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">FuncGlyph</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;-&gt;&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="s1">&#39;func&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;=&gt;&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="s1">&#39;boundfunc&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>An optional, trailing comma.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">OptComma</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;,&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>The list of parameters that a function accepts can be of any length.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ParamList</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[]</span>
<span class="nx">o</span> <span class="s1">&#39;Param&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;ParamList , Param&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">$3</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>A single parameter in a function definition can be ordinary, or a splat
that hoovers up the remaining arguments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Param</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;ParamVar&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Param</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;ParamVar ...&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Param</span> <span class="nx">$1</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="kc">on</span>
<span class="nx">o</span> <span class="s1">&#39;ParamVar = Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Param</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="p">]</span>
<span class="nx">ParamVar</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Identifier&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;ThisProperty&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Array&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Object&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>A splat that occurs outside of a parameter list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Splat</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Expression ...&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Splat</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Variables and properties that can be assigned to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">SimpleAssignable</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Identifier&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;Value Accessor&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">push</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;Invocation Accessor&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span><span class="p">,</span> <span class="p">[</span><span class="nx">$2</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;ThisProperty&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Everything that can be assigned to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Assignable</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;SimpleAssignable&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Array&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;Object&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>The types of things that can be treated as values -- assigned to, invoked
as functions, indexed into, named as a class, etc.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Value</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Assignable&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Literal&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;Parenthetical&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;Range&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;This&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>The general group of accessors into an object, by property, by prototype
or by array index or slice.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Accessor</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;. Identifier&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Access</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;?. Identifier&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Access</span> <span class="nx">$2</span><span class="p">,</span> <span class="s1">&#39;soak&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;:: Identifier&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Access</span> <span class="nx">$2</span><span class="p">,</span> <span class="s1">&#39;proto&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;::&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Access</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="s1">&#39;prototype&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Index&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Slice&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Slice</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Indexing into an object or array using bracket notation.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Index</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;INDEX_START Expression INDEX_END&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Index</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;INDEX_SOAK Index&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">extend</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">soak</span> <span class="o">:</span> <span class="kc">yes</span>
<span class="nx">o</span> <span class="s1">&#39;INDEX_PROTO Index&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">extend</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">proto</span><span class="o">:</span> <span class="kc">yes</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <p>In CoffeeScript, an object literal is simply a list of assignments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">Object</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;{ AssignList OptComma }&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Obj</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">generated</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#182;</a> </div> <p>Assignment of properties within an object literal can be separated by
comma, as in JavaScript, or simply by newline.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">AssignList</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[]</span>
<span class="nx">o</span> <span class="s1">&#39;AssignObj&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;AssignList , AssignObj&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;AssignList OptComma TERMINATOR AssignObj&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;AssignList OptComma INDENT AssignList OptComma OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">$4</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <p>Class definitions have optional bodies of prototype property assignments,
and optional references to the superclass.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Class</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;CLASS&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Class</span>
<span class="nx">o</span> <span class="s1">&#39;CLASS Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Class</span> <span class="kc">null</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;CLASS EXTENDS Value&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Class</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;CLASS EXTENDS Value Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Class</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;CLASS SimpleAssignable&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Class</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;CLASS SimpleAssignable Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Class</span> <span class="nx">$2</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;CLASS SimpleAssignable EXTENDS Value&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Class</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;CLASS SimpleAssignable EXTENDS Value Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Class</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">$5</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-35">&#182;</a> </div> <p>Ordinary function invocation, or a chained series of calls.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Invocation</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Value OptFuncExist Arguments&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Call</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;Invocation OptFuncExist Arguments&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Call</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;SUPER&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
<span class="k">new</span> <span class="nx">Call</span> <span class="s1">&#39;super&#39;</span><span class="p">,</span> <span class="p">[</span><span class="k">new</span> <span class="nx">Splat</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="s1">&#39;arguments&#39;</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;SUPER Arguments&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
<span class="k">new</span> <span class="nx">Call</span> <span class="s1">&#39;super&#39;</span><span class="p">,</span> <span class="nx">$2</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-36">&#182;</a> </div> <p>An optional existence check on a function.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">OptFuncExist</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="kc">no</span>
<span class="nx">o</span> <span class="s1">&#39;FUNC_EXIST&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="kc">yes</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-37">&#182;</a> </div> <p>The list of arguments to a function call.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Arguments</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;CALL_START CALL_END&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[]</span>
<span class="nx">o</span> <span class="s1">&#39;CALL_START ArgList OptComma CALL_END&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$2</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">&#182;</a> </div> <p>A reference to the <em>this</em> current object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">This</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;THIS&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="s1">&#39;this&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;@&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="k">new</span> <span class="nx">Literal</span> <span class="s1">&#39;this&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-39">&#182;</a> </div> <p>A reference to a property on <em>this</em>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ThisProperty</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;@ Identifier&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="k">new</span> <span class="nx">Literal</span><span class="p">(</span><span class="s1">&#39;this&#39;</span><span class="p">),</span> <span class="p">[</span><span class="k">new</span> <span class="nx">Access</span><span class="p">(</span><span class="nx">$2</span><span class="p">)],</span> <span class="s1">&#39;this&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>The array literal.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nb">Array</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;[ ]&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Arr</span> <span class="p">[]</span>
<span class="nx">o</span> <span class="s1">&#39;[ ArgList OptComma ]&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Arr</span> <span class="nx">$2</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>Inclusive and exclusive range dots.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">RangeDots</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;..&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="s1">&#39;inclusive&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;...&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="s1">&#39;exclusive&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-42">&#182;</a> </div> <p>The CoffeeScript range literal.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Range</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;[ Expression RangeDots Expression ]&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Range</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">$3</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-43">&#182;</a> </div> <p>Array slice literals.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Slice</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;INDEX_START Expression RangeDots Expression INDEX_END&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Range</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;INDEX_START Expression RangeDots INDEX_END&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Range</span> <span class="nx">$2</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;INDEX_START RangeDots Expression INDEX_END&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Range</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">$2</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-44">&#182;</a> </div> <p>The <strong>ArgList</strong> is both the list of objects passed into a function call,
as well as the contents of an array literal
(i.e. comma-separated expressions). Newlines work as well.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ArgList</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Arg&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;ArgList , Arg&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;ArgList OptComma TERMINATOR Arg&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;INDENT ArgList OptComma OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;ArgList OptComma INDENT ArgList OptComma OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">$4</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-45">&#182;</a> </div> <p>Valid arguments are Expressions or Splats.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Arg</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Expression&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Splat&#39;</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-46"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-46">&#182;</a> </div> <p>Just simple, comma-separated, required arguments (no fancy syntax). We need
this to be separate from the <strong>ArgList</strong> for use in <strong>Switch</strong> blocks, where
having the newlines wouldn't make sense.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">SimpleArgs</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Expression&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;SimpleArgs , Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[].</span><span class="nx">concat</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-47">&#182;</a> </div> <p>The variants of <em>try/catch/finally</em> exception handling blocks.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Try</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;TRY Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Try</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;TRY Block Catch&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Try</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$3</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">$3</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;TRY Block FINALLY Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Try</span> <span class="nx">$2</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;TRY Block Catch FINALLY Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Try</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$3</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">$3</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nx">$5</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-48">&#182;</a> </div> <p>A catch clause names its error and runs a block of code.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Catch</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;CATCH Identifier Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[</span><span class="nx">$2</span><span class="p">,</span> <span class="nx">$3</span><span class="p">]</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-49"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-49">&#182;</a> </div> <p>Throw an exception object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Throw</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;THROW Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Throw</span> <span class="nx">$2</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-50">&#182;</a> </div> <p>Parenthetical expressions. Note that the <strong>Parenthetical</strong> is a <strong>Value</strong>,
not an <strong>Expression</strong>, so if you need to use an expression in a place
where only values are accepted, wrapping it in parentheses will always do
the trick.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Parenthetical</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;( Body )&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Parens</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;( INDENT Body OUTDENT )&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Parens</span> <span class="nx">$3</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-51">&#182;</a> </div> <p>The condition portion of a while loop.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">WhileSource</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;WHILE Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">While</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;WHILE Expression WHEN Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">While</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">guard</span><span class="o">:</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;UNTIL Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">While</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">invert</span><span class="o">:</span> <span class="kc">true</span>
<span class="nx">o</span> <span class="s1">&#39;UNTIL Expression WHEN Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">While</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">invert</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">guard</span><span class="o">:</span> <span class="nx">$4</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-52">&#182;</a> </div> <p>The while loop can either be normal, with a block of expressions to execute,
or postfix, with a single expression. There is no do..while.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">While</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;WhileSource Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">addBody</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;Statement WhileSource&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$2</span><span class="p">.</span><span class="nx">addBody</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;Expression WhileSource&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$2</span><span class="p">.</span><span class="nx">addBody</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;Loop&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span>
<span class="p">]</span>
<span class="nx">Loop</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;LOOP Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">While</span><span class="p">(</span><span class="k">new</span> <span class="nx">Literal</span> <span class="s1">&#39;true&#39;</span><span class="p">).</span><span class="nx">addBody</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;LOOP Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">While</span><span class="p">(</span><span class="k">new</span> <span class="nx">Literal</span> <span class="s1">&#39;true&#39;</span><span class="p">).</span><span class="nx">addBody</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span> <span class="p">[</span><span class="nx">$2</span><span class="p">]</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-53">&#182;</a> </div> <p>Array, object, and range comprehensions, at the most generic level.
Comprehensions can either be normal, with a block of expressions to execute,
or postfix, with a single expression.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">For</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Statement ForBody&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">For</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$2</span><span class="p">.</span><span class="nx">vars</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">$2</span><span class="p">.</span><span class="nx">vars</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;Expression ForBody&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">For</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$2</span><span class="p">.</span><span class="nx">vars</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">$2</span><span class="p">.</span><span class="nx">vars</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;ForBody Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">For</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">vars</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">vars</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="p">]</span>
<span class="nx">ForBody</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;FOR Range&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">source</span><span class="o">:</span> <span class="k">new</span> <span class="nx">Value</span><span class="p">(</span><span class="nx">$2</span><span class="p">),</span> <span class="nx">vars</span><span class="o">:</span> <span class="p">[]</span>
<span class="nx">o</span> <span class="s1">&#39;ForStart ForSource&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nv">$2.own = </span><span class="nx">$1</span><span class="p">.</span><span class="nx">own</span><span class="p">;</span> <span class="nv">$2.vars = </span><span class="nx">$1</span><span class="p">;</span> <span class="nx">$2</span>
<span class="p">]</span>
<span class="nx">ForStart</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;FOR ForVariables&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;FOR OWN ForVariables&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nv">$3.own = </span><span class="kc">yes</span><span class="p">;</span> <span class="nx">$3</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-54"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-54">&#182;</a> </div> <p>An array of all accepted values for a variable inside the loop.
This enables support for pattern matching.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ForValue</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;Identifier&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Array&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;Object&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Value</span> <span class="nx">$1</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-55"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-55">&#182;</a> </div> <p>An array or range comprehension has variables for the current element
and (optional) reference to the current index. Or, <em>key, value</em>, in the case
of object comprehensions.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ForVariables</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;ForValue&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
<span class="nx">o</span> <span class="s1">&#39;ForValue , ForValue&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[</span><span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span><span class="p">]</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-56"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-56">&#182;</a> </div> <p>The source of a comprehension is an array or object with an optional guard
clause. If it's an array comprehension, you can also choose to step through
in fixed-size increments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ForSource</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;FORIN Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">source</span><span class="o">:</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;FOROF Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">source</span><span class="o">:</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">object</span><span class="o">:</span> <span class="kc">yes</span>
<span class="nx">o</span> <span class="s1">&#39;FORIN Expression WHEN Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">source</span><span class="o">:</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">guard</span><span class="o">:</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;FOROF Expression WHEN Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">source</span><span class="o">:</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">guard</span><span class="o">:</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">object</span><span class="o">:</span> <span class="kc">yes</span>
<span class="nx">o</span> <span class="s1">&#39;FORIN Expression BY Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">source</span><span class="o">:</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">step</span><span class="o">:</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;FORIN Expression WHEN Expression BY Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">source</span><span class="o">:</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">guard</span><span class="o">:</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">step</span><span class="o">:</span> <span class="nx">$6</span>
<span class="nx">o</span> <span class="s1">&#39;FORIN Expression BY Expression WHEN Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">source</span><span class="o">:</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">step</span><span class="o">:</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">guard</span><span class="o">:</span> <span class="nx">$6</span>
<span class="p">]</span>
<span class="nx">Switch</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;SWITCH Expression INDENT Whens OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Switch</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$4</span>
<span class="nx">o</span> <span class="s1">&#39;SWITCH Expression INDENT Whens ELSE Block OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Switch</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">$6</span>
<span class="nx">o</span> <span class="s1">&#39;SWITCH INDENT Whens OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Switch</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;SWITCH INDENT Whens ELSE Block OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Switch</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">$5</span>
<span class="p">]</span>
<span class="nx">Whens</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;When&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Whens When&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">$2</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-57"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-57">&#182;</a> </div> <p>An individual <strong>When</strong> clause, with action.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">When</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;LEADING_WHEN SimpleArgs Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[[</span><span class="nx">$2</span><span class="p">,</span> <span class="nx">$3</span><span class="p">]]</span>
<span class="nx">o</span> <span class="s1">&#39;LEADING_WHEN SimpleArgs Block TERMINATOR&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="p">[[</span><span class="nx">$2</span><span class="p">,</span> <span class="nx">$3</span><span class="p">]]</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-58"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-58">&#182;</a> </div> <p>The most basic form of <em>if</em> is a condition and an action. The following
if-related rules are broken up along these lines in order to avoid
ambiguity.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">IfBlock</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;IF Expression Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">If</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;UNLESS Expression Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">If</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">invert</span><span class="o">:</span> <span class="kc">true</span>
<span class="nx">o</span> <span class="s1">&#39;IfBlock ELSE IF Expression Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">addElse</span> <span class="k">new</span> <span class="nx">If</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">$5</span>
<span class="nx">o</span> <span class="s1">&#39;IfBlock ELSE Block&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">addElse</span> <span class="nx">$3</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-59"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-59">&#182;</a> </div> <p>The full complement of <em>if</em> expressions, including postfix one-liner
<em>if</em> and <em>unless</em>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">If</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;IfBlock&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;Statement POST_IF Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">If</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span><span class="p">([</span><span class="nx">$1</span><span class="p">]),</span> <span class="nx">statement</span><span class="o">:</span> <span class="kc">true</span>
<span class="nx">o</span> <span class="s1">&#39;Expression POST_IF Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">If</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span><span class="p">([</span><span class="nx">$1</span><span class="p">]),</span> <span class="nx">statement</span><span class="o">:</span> <span class="kc">true</span>
<span class="nx">o</span> <span class="s1">&#39;Statement POST_UNLESS Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">If</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span><span class="p">([</span><span class="nx">$1</span><span class="p">]),</span> <span class="nx">statement</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">invert</span><span class="o">:</span> <span class="kc">true</span>
<span class="nx">o</span> <span class="s1">&#39;Expression POST_UNLESS Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">If</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span><span class="p">([</span><span class="nx">$1</span><span class="p">]),</span> <span class="nx">statement</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">invert</span><span class="o">:</span> <span class="kc">true</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-60"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-60">&#182;</a> </div> <p>Arithmetic and logical operators, working on one or more operands.
Here they are grouped by order of precedence. The actual precedence rules
are defined at the bottom of the page. It would be shorter if we could
combine most of these rules into a single generic <em>Operand OpSymbol Operand</em>
-type rule, but in order to make the precedence binding possible, separate
rules are necessary.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Operation</span><span class="o">:</span> <span class="p">[</span>
<span class="nx">o</span> <span class="s1">&#39;UNARY Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="nx">$1</span> <span class="p">,</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;- Expression&#39;</span><span class="p">,</span> <span class="p">(</span><span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="s1">&#39;-&#39;</span><span class="p">,</span> <span class="nx">$2</span><span class="p">),</span> <span class="nx">prec</span><span class="o">:</span> <span class="s1">&#39;UNARY&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;+ Expression&#39;</span><span class="p">,</span> <span class="p">(</span><span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="s1">&#39;+&#39;</span><span class="p">,</span> <span class="nx">$2</span><span class="p">),</span> <span class="nx">prec</span><span class="o">:</span> <span class="s1">&#39;UNARY&#39;</span>
<span class="nx">o</span> <span class="s1">&#39;-- SimpleAssignable&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="s1">&#39;--&#39;</span><span class="p">,</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;++ SimpleAssignable&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="s1">&#39;++&#39;</span><span class="p">,</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;SimpleAssignable --&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="s1">&#39;--&#39;</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="kc">true</span>
<span class="nx">o</span> <span class="s1">&#39;SimpleAssignable ++&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="s1">&#39;++&#39;</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-61"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-61">&#182;</a> </div> <p><a href="http://jashkenas.github.com/coffee-script/#existence">The existential operator</a>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">o</span> <span class="s1">&#39;Expression ?&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Existence</span> <span class="nx">$1</span>
<span class="nx">o</span> <span class="s1">&#39;Expression + Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="s1">&#39;+&#39;</span> <span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;Expression - Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="s1">&#39;-&#39;</span> <span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;Expression MATH Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;Expression SHIFT Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;Expression COMPARE Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;Expression LOGIC Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Op</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;Expression RELATION Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="nx">$2</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;!&#39;</span>
<span class="k">new</span> <span class="nx">Op</span><span class="p">(</span><span class="nx">$2</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span><span class="p">).</span><span class="nx">invert</span><span class="p">()</span>
<span class="k">else</span>
<span class="k">new</span> <span class="nx">Op</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="nx">o</span> <span class="s1">&#39;SimpleAssignable COMPOUND_ASSIGN</span>
<span class="s1"> Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Assign</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span><span class="p">,</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;SimpleAssignable COMPOUND_ASSIGN</span>
<span class="s1"> INDENT Expression OUTDENT&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Assign</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$4</span><span class="p">,</span> <span class="nx">$2</span>
<span class="nx">o</span> <span class="s1">&#39;SimpleAssignable EXTENDS Expression&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="k">new</span> <span class="nx">Extends</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-62"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-62">&#182;</a> </div> <h2>Precedence</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-63"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-63">&#182;</a> </div> <p>Operators at the top of this list have higher precedence than the ones lower
down. Following these rules is what makes <code>2 + 3 * 4</code> parse as:</p>
<pre><code>2 + (3 * 4)
</code></pre>
<p>And not:</p>
<pre><code>(2 + 3) * 4
</code></pre> </td> <td class="code"> <div class="highlight"><pre><span class="nv">operators = </span><span class="p">[</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="s1">&#39;?.&#39;</span><span class="p">,</span> <span class="s1">&#39;::&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;CALL_START&#39;</span><span class="p">,</span> <span class="s1">&#39;CALL_END&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;nonassoc&#39;</span><span class="p">,</span> <span class="s1">&#39;++&#39;</span><span class="p">,</span> <span class="s1">&#39;--&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;?&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;right&#39;</span><span class="p">,</span> <span class="s1">&#39;UNARY&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;MATH&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;+&#39;</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;SHIFT&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;RELATION&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;COMPARE&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;left&#39;</span><span class="p">,</span> <span class="s1">&#39;LOGIC&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;nonassoc&#39;</span><span class="p">,</span> <span class="s1">&#39;INDENT&#39;</span><span class="p">,</span> <span class="s1">&#39;OUTDENT&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;right&#39;</span><span class="p">,</span> <span class="s1">&#39;=&#39;</span><span class="p">,</span> <span class="s1">&#39;:&#39;</span><span class="p">,</span> <span class="s1">&#39;COMPOUND_ASSIGN&#39;</span><span class="p">,</span> <span class="s1">&#39;RETURN&#39;</span><span class="p">,</span> <span class="s1">&#39;THROW&#39;</span><span class="p">,</span> <span class="s1">&#39;EXTENDS&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;right&#39;</span><span class="p">,</span> <span class="s1">&#39;FORIN&#39;</span><span class="p">,</span> <span class="s1">&#39;FOROF&#39;</span><span class="p">,</span> <span class="s1">&#39;BY&#39;</span><span class="p">,</span> <span class="s1">&#39;WHEN&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;right&#39;</span><span class="p">,</span> <span class="s1">&#39;IF&#39;</span><span class="p">,</span> <span class="s1">&#39;UNLESS&#39;</span><span class="p">,</span> <span class="s1">&#39;ELSE&#39;</span><span class="p">,</span> <span class="s1">&#39;FOR&#39;</span><span class="p">,</span> <span class="s1">&#39;WHILE&#39;</span><span class="p">,</span> <span class="s1">&#39;UNTIL&#39;</span><span class="p">,</span> <span class="s1">&#39;LOOP&#39;</span><span class="p">,</span> <span class="s1">&#39;SUPER&#39;</span><span class="p">,</span> <span class="s1">&#39;CLASS&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;right&#39;</span><span class="p">,</span> <span class="s1">&#39;POST_IF&#39;</span><span class="p">,</span> <span class="s1">&#39;POST_UNLESS&#39;</span><span class="p">]</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-64"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-64">&#182;</a> </div> <h2>Wrapping Up</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-65"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-65">&#182;</a> </div> <p>Finally, now what we have our <strong>grammar</strong> and our <strong>operators</strong>, we can create
our <strong>Jison.Parser</strong>. We do this by processing all of our rules, recording all
terminals (every symbol which does not appear as the name of a rule above)
as "tokens".</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">tokens = </span><span class="p">[]</span>
<span class="k">for</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">alternatives</span> <span class="k">of</span> <span class="nx">grammar</span>
<span class="nx">grammar</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="k">for</span> <span class="nx">alt</span> <span class="k">in</span> <span class="nx">alternatives</span>
<span class="k">for</span> <span class="nx">token</span> <span class="k">in</span> <span class="nx">alt</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">split</span> <span class="s1">&#39; &#39;</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">push</span> <span class="nx">token</span> <span class="nx">unless</span> <span class="nx">grammar</span><span class="p">[</span><span class="nx">token</span><span class="p">]</span>
<span class="nx">alt</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;return #{alt[1]}&quot;</span> <span class="k">if</span> <span class="nx">name</span> <span class="o">is</span> <span class="s1">&#39;Root&#39;</span>
<span class="nx">alt</span></pre></div> </td> </tr> <tr id="section-66"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-66">&#182;</a> </div> <p>Initialize the <strong>Parser</strong> with our list of terminal <strong>tokens</strong>, our <strong>grammar</strong>
rules, and the name of the root. Reverse the operators because Jison orders
precedence from low to high, and we have it high to low
(as in <a href="http://dinosaur.compilertools.net/yacc/index.html">Yacc</a>).</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.parser = </span><span class="k">new</span> <span class="nx">Parser</span>
<span class="nx">tokens</span> <span class="o">:</span> <span class="nx">tokens</span><span class="p">.</span><span class="nx">join</span> <span class="s1">&#39; &#39;</span>
<span class="nx">bnf</span> <span class="o">:</span> <span class="nx">grammar</span>
<span class="nx">operators</span> <span class="o">:</span> <span class="nx">operators</span><span class="p">.</span><span class="nx">reverse</span><span class="p">()</span>
<span class="nx">startSymbol</span> <span class="o">:</span> <span class="s1">&#39;Root&#39;</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,30 @@
<!DOCTYPE html> <html> <head> <title>helpers.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> helpers.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>This file contains the common helper functions that we'd like to share among
the <strong>Lexer</strong>, <strong>Rewriter</strong>, and the <strong>Nodes</strong>. Merge objects, flatten
arrays, count characters, that sort of thing.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Peek at the beginning of a given string to see if it matches a sequence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.starts = </span><span class="p">(</span><span class="nx">string</span><span class="p">,</span> <span class="nx">literal</span><span class="p">,</span> <span class="nx">start</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">literal</span> <span class="o">is</span> <span class="nx">string</span><span class="p">.</span><span class="nx">substr</span> <span class="nx">start</span><span class="p">,</span> <span class="nx">literal</span><span class="p">.</span><span class="nx">length</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Peek at the end of a given string to see if it matches a sequence.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ends = </span><span class="p">(</span><span class="nx">string</span><span class="p">,</span> <span class="nx">literal</span><span class="p">,</span> <span class="nx">back</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">len = </span><span class="nx">literal</span><span class="p">.</span><span class="nx">length</span>
<span class="nx">literal</span> <span class="o">is</span> <span class="nx">string</span><span class="p">.</span><span class="nx">substr</span> <span class="nx">string</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="nx">len</span> <span class="o">-</span> <span class="p">(</span><span class="nx">back</span> <span class="o">or</span> <span class="mi">0</span><span class="p">),</span> <span class="nx">len</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Trim out all falsy values from an array.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.compact = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">item</span> <span class="k">for</span> <span class="nx">item</span> <span class="k">in</span> <span class="nx">array</span> <span class="k">when</span> <span class="nx">item</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Count the number of occurrences of a character in a string.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.count = </span><span class="p">(</span><span class="nx">string</span><span class="p">,</span> <span class="nx">letter</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">num = pos = </span><span class="mi">0</span>
<span class="nx">num</span><span class="o">++</span> <span class="k">while</span> <span class="nv">pos = </span><span class="mi">1</span> <span class="o">+</span> <span class="nx">string</span><span class="p">.</span><span class="nx">indexOf</span> <span class="nx">letter</span><span class="p">,</span> <span class="nx">pos</span>
<span class="nx">num</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Merge objects, returning a fresh copy with attributes from both sides.
Used every time <code>Base#compile</code> is called, to allow properties in the
options hash to propagate down the tree without polluting other branches.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.merge = </span><span class="p">(</span><span class="nx">options</span><span class="p">,</span> <span class="nx">overrides</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">extend</span> <span class="p">(</span><span class="nx">extend</span> <span class="p">{},</span> <span class="nx">options</span><span class="p">),</span> <span class="nx">overrides</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Extend a source object with the properties of another object (shallow copy).</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">extend = exports.extend = </span><span class="p">(</span><span class="nx">object</span><span class="p">,</span> <span class="nx">properties</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">properties</span>
<span class="nx">object</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span>
<span class="nx">object</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Return a flattened version of an array.
Handy for getting a list of <code>children</code> from the nodes.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.flatten = flatten = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">flattened = </span><span class="p">[]</span>
<span class="k">for</span> <span class="nx">element</span> <span class="k">in</span> <span class="nx">array</span>
<span class="k">if</span> <span class="nx">element</span> <span class="k">instanceof</span> <span class="nb">Array</span>
<span class="nv">flattened = </span><span class="nx">flattened</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">flatten</span> <span class="nx">element</span>
<span class="k">else</span>
<span class="nx">flattened</span><span class="p">.</span><span class="nx">push</span> <span class="nx">element</span>
<span class="nx">flattened</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Delete a key from an object, returning the value. Useful when a node is
looking for a particular method in an options hash.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.del = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">key</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">val = </span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span>
<span class="k">delete</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span>
<span class="nx">val</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Gets the last item of an array(-like) object.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.last = </span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">back</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">array</span><span class="p">[</span><span class="nx">array</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="p">(</span><span class="nx">back</span> <span class="o">or</span> <span class="mi">0</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,3 @@
<!DOCTYPE html> <html> <head> <title>index.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> index.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>Loader for CoffeeScript as a Node.js library.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span> <span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">require</span> <span class="s1">&#39;./coffee-script&#39;</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,73 @@
<!DOCTYPE html> <html> <head> <title>optparse.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> optparse.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>A simple <strong>OptionParser</strong> class to parse option flags from the command-line.
Use it like so:</p>
<pre><code>parser = new OptionParser switches, helpBanner
options = parser.parse process.argv
</code></pre>
<p>The first non-option is considered to be the start of the file (and file
option) list, and all subsequent arguments are left unparsed.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.OptionParser = </span><span class="nx">class</span> <span class="nx">OptionParser</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Initialize with a list of valid options, in the form:</p>
<pre><code>[short-flag, long-flag, description]
</code></pre>
<p>Along with an an optional banner for the usage help.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">rules</span><span class="p">,</span> <span class="nx">@banner</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="vi">@rules = </span><span class="nx">buildRules</span> <span class="nx">rules</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Parse the list of arguments, populating an <code>options</code> object with all of the
specified options, and returning it. <code>options.arguments</code> will be an array
containing the remaining non-option arguments. This is a simpler API than
many option parsers that allow you to attach callback actions for every
flag. Instead, you're responsible for interpreting the options object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">parse</span><span class="o">:</span> <span class="p">(</span><span class="nx">args</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">options = </span><span class="nx">arguments</span><span class="o">:</span> <span class="p">[]</span>
<span class="nv">args = </span><span class="nx">normalizeArguments</span> <span class="nx">args</span>
<span class="k">for</span> <span class="nx">arg</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">args</span>
<span class="nv">isOption = </span><span class="o">!!</span><span class="p">(</span><span class="nx">arg</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">LONG_FLAG</span><span class="p">)</span> <span class="o">or</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">SHORT_FLAG</span><span class="p">))</span>
<span class="nv">matchedRule = </span><span class="kc">no</span>
<span class="k">for</span> <span class="nx">rule</span> <span class="k">in</span> <span class="nx">@rules</span>
<span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="o">is</span> <span class="nx">arg</span> <span class="o">or</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span> <span class="o">is</span> <span class="nx">arg</span>
<span class="nv">value = </span><span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">hasArgument</span> <span class="k">then</span> <span class="nx">args</span><span class="p">[</span><span class="nx">i</span> <span class="o">+=</span> <span class="mi">1</span><span class="p">]</span> <span class="k">else</span> <span class="kc">true</span>
<span class="nx">options</span><span class="p">[</span><span class="nx">rule</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">isList</span> <span class="k">then</span> <span class="p">(</span><span class="nx">options</span><span class="p">[</span><span class="nx">rule</span><span class="p">.</span><span class="nx">name</span><span class="p">]</span> <span class="o">or</span> <span class="p">[]).</span><span class="nx">concat</span> <span class="nx">value</span> <span class="k">else</span> <span class="nx">value</span>
<span class="nv">matchedRule = </span><span class="kc">yes</span>
<span class="k">break</span>
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">&quot;unrecognized option: #{arg}&quot;</span> <span class="k">if</span> <span class="nx">isOption</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">matchedRule</span>
<span class="k">if</span> <span class="o">not</span> <span class="nx">isOption</span>
<span class="nv">options.arguments = </span><span class="nx">args</span><span class="p">.</span><span class="nx">slice</span> <span class="nx">i</span>
<span class="k">break</span>
<span class="nx">options</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Return the help text for this <strong>OptionParser</strong>, listing and describing all
of the valid options, for <code>--help</code> and such.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">help</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nv">lines = </span><span class="p">[</span><span class="s1">&#39;Available options:&#39;</span><span class="p">]</span>
<span class="nx">lines</span><span class="p">.</span><span class="nx">unshift</span> <span class="s2">&quot;#{@banner}\n&quot;</span> <span class="k">if</span> <span class="nx">@banner</span>
<span class="k">for</span> <span class="nx">rule</span> <span class="k">in</span> <span class="nx">@rules</span>
<span class="nv">spaces = </span><span class="mi">15</span> <span class="o">-</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">length</span>
<span class="nv">spaces = </span><span class="k">if</span> <span class="nx">spaces</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">then</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">spaces</span> <span class="o">+</span> <span class="mi">1</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">)</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span>
<span class="nv">letPart = </span><span class="k">if</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="k">then</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">shortFlag</span> <span class="o">+</span> <span class="s1">&#39;, &#39;</span> <span class="k">else</span> <span class="s1">&#39; &#39;</span>
<span class="nx">lines</span><span class="p">.</span><span class="nx">push</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nx">letPart</span> <span class="o">+</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">longFlag</span> <span class="o">+</span> <span class="nx">spaces</span> <span class="o">+</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">description</span>
<span class="s2">&quot;\n#{ lines.join(&#39;\n&#39;) }\n&quot;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h2>Helpers</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Regex matchers for option flags.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">LONG_FLAG = </span><span class="sr">/^(--\w[\w\-]+)/</span>
<span class="nv">SHORT_FLAG = </span><span class="sr">/^(-\w)/</span>
<span class="nv">MULTI_FLAG = </span><span class="sr">/^-(\w{2,})/</span>
<span class="nv">OPTIONAL = </span><span class="sr">/\[(\w+(\*?))\]/</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Build and return the list of option rules. If the optional <em>short-flag</em> is
unspecified, leave it out by padding with <code>null</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">buildRules = </span><span class="p">(</span><span class="nx">rules</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">for</span> <span class="nx">tuple</span> <span class="k">in</span> <span class="nx">rules</span>
<span class="nx">tuple</span><span class="p">.</span><span class="nx">unshift</span> <span class="kc">null</span> <span class="k">if</span> <span class="nx">tuple</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="mi">3</span>
<span class="nx">buildRule</span> <span class="nx">tuple</span><span class="p">...</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Build a rule from a <code>-o</code> short flag, a <code>--output [DIR]</code> long flag, and the
description of what the option does.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">buildRule = </span><span class="p">(</span><span class="nx">shortFlag</span><span class="p">,</span> <span class="nx">longFlag</span><span class="p">,</span> <span class="nx">description</span><span class="p">,</span> <span class="nv">options = </span><span class="p">{})</span> <span class="o">-&gt;</span>
<span class="nv">match = </span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">OPTIONAL</span><span class="p">)</span>
<span class="nv">longFlag = </span><span class="nx">longFlag</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">LONG_FLAG</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
<span class="p">{</span>
<span class="nx">name</span><span class="o">:</span> <span class="nx">longFlag</span><span class="p">.</span><span class="nx">substr</span> <span class="mi">2</span>
<span class="nx">shortFlag</span><span class="o">:</span> <span class="nx">shortFlag</span>
<span class="nx">longFlag</span><span class="o">:</span> <span class="nx">longFlag</span>
<span class="nx">description</span><span class="o">:</span> <span class="nx">description</span>
<span class="nx">hasArgument</span><span class="o">:</span> <span class="o">!!</span><span class="p">(</span><span class="nx">match</span> <span class="o">and</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="nx">isList</span><span class="o">:</span> <span class="o">!!</span><span class="p">(</span><span class="nx">match</span> <span class="o">and</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Normalize arguments by expanding merged flags into multiple flags. This allows
you to have <code>-wl</code> be the same as <code>--watch --lint</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">normalizeArguments = </span><span class="p">(</span><span class="nx">args</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">args = </span><span class="nx">args</span><span class="p">.</span><span class="nx">slice</span> <span class="mi">0</span>
<span class="nv">result = </span><span class="p">[]</span>
<span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">args</span>
<span class="k">if</span> <span class="nv">match = </span><span class="nx">arg</span><span class="p">.</span><span class="nx">match</span> <span class="nx">MULTI_FLAG</span>
<span class="nx">result</span><span class="p">.</span><span class="nx">push</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="nx">l</span> <span class="k">for</span> <span class="nx">l</span> <span class="k">in</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">split</span> <span class="s1">&#39;&#39;</span>
<span class="k">else</span>
<span class="nx">result</span><span class="p">.</span><span class="nx">push</span> <span class="nx">arg</span>
<span class="nx">result</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html> <html> <head> <title>repl.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> repl.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>A very simple Read-Eval-Print-Loop. Compiles one line at a time to JavaScript
and evaluates it. Good for simple tests, or poking around the <strong>Node.js</strong> API.
Using it looks like this:</p>
<pre><code>coffee&gt; console.log "#{num} bottles of beer" for num in [99..1]
</code></pre> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Require the <strong>coffee-script</strong> module to get access to the compiler.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s1">&#39;./coffee-script&#39;</span>
<span class="nv">helpers = </span><span class="nx">require</span> <span class="s1">&#39;./helpers&#39;</span>
<span class="nv">readline = </span><span class="nx">require</span> <span class="s1">&#39;readline&#39;</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Start by opening up <strong>stdio</strong>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">stdio = </span><span class="nx">process</span><span class="p">.</span><span class="nx">openStdin</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Log an error.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">error = </span><span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">stdio</span><span class="p">.</span><span class="nx">write</span> <span class="p">(</span><span class="nx">err</span><span class="p">.</span><span class="nx">stack</span> <span class="o">or</span> <span class="nx">err</span><span class="p">.</span><span class="nx">toString</span><span class="p">())</span> <span class="o">+</span> <span class="s1">&#39;\n\n&#39;</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Quick alias for quitting the REPL.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">helpers</span><span class="p">.</span><span class="nx">extend</span> <span class="nx">global</span><span class="p">,</span> <span class="nx">quit</span><span class="o">:</span> <span class="o">-&gt;</span> <span class="nx">process</span><span class="p">.</span><span class="nx">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>The main REPL function. <strong>run</strong> is called every time a line of code is entered.
Attempt to evaluate the command. If there's an exception, print it out instead
of exiting.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">run = </span><span class="p">(</span><span class="nx">buffer</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">try</span>
<span class="nv">val = </span><span class="nx">CoffeeScript</span><span class="p">.</span><span class="nb">eval</span> <span class="nx">buffer</span><span class="p">.</span><span class="nx">toString</span><span class="p">(),</span> <span class="nx">bare</span><span class="o">:</span> <span class="kc">on</span><span class="p">,</span> <span class="nx">globals</span><span class="o">:</span> <span class="kc">on</span><span class="p">,</span> <span class="nx">fileName</span><span class="o">:</span> <span class="s1">&#39;repl&#39;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">val</span> <span class="k">if</span> <span class="nx">val</span> <span class="o">isnt</span> <span class="kc">undefined</span>
<span class="k">catch</span> <span class="nx">err</span>
<span class="nx">error</span> <span class="nx">err</span>
<span class="nx">repl</span><span class="p">.</span><span class="nx">prompt</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Make sure that uncaught exceptions don't kill the REPL.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">process</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;uncaughtException&#39;</span><span class="p">,</span> <span class="nx">error</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Create the REPL by listening to <strong>stdin</strong>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">repl = </span><span class="nx">readline</span><span class="p">.</span><span class="nx">createInterface</span> <span class="nx">stdio</span>
<span class="nx">repl</span><span class="p">.</span><span class="nx">setPrompt</span> <span class="s1">&#39;coffee&gt; &#39;</span>
<span class="nx">stdio</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="p">(</span><span class="nx">buffer</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">repl</span><span class="p">.</span><span class="nx">write</span> <span class="nx">buffer</span>
<span class="nx">repl</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;close&#39;</span><span class="p">,</span> <span class="o">-&gt;</span> <span class="nx">stdio</span><span class="p">.</span><span class="nx">destroy</span><span class="p">()</span>
<span class="nx">repl</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;line&#39;</span><span class="p">,</span> <span class="nx">run</span>
<span class="nx">repl</span><span class="p">.</span><span class="nx">prompt</span><span class="p">()</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,251 @@
<!DOCTYPE html> <html> <head> <title>rewriter.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> rewriter.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>The CoffeeScript language has a good deal of optional syntax, implicit syntax,
and shorthand syntax. This can greatly complicate a grammar and bloat
the resulting parse table. Instead of making the parser handle it all, we take
a series of passes over the token stream, using this <strong>Rewriter</strong> to convert
shorthand into the unambiguous long form, add implicit indentation and
parentheses, balance incorrect nestings, and generally clean things up.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>The <strong>Rewriter</strong> class is used by the <a href="lexer.html">Lexer</a>, directly against
its internal array of tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">class</span> <span class="nx">exports</span><span class="p">.</span><span class="nx">Rewriter</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Helpful snippet for debugging:
console.log (t[0] + '/' + t[1] for t in @tokens).join ' '</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Rewrite the token stream in multiple passes, one logical filter at
a time. This could certainly be changed into a single pass through the
stream, with a big ol' efficient switch, but it's much nicer to work with
like this. The order of these passes matters -- indentation must be
corrected before implicit parentheses can be wrapped around blocks of code.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">rewrite</span><span class="o">:</span> <span class="p">(</span><span class="nx">@tokens</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">@removeLeadingNewlines</span><span class="p">()</span>
<span class="nx">@removeMidExpressionNewlines</span><span class="p">()</span>
<span class="nx">@closeOpenCalls</span><span class="p">()</span>
<span class="nx">@closeOpenIndexes</span><span class="p">()</span>
<span class="nx">@addImplicitIndentation</span><span class="p">()</span>
<span class="nx">@tagPostfixConditionals</span><span class="p">()</span>
<span class="nx">@addImplicitBraces</span><span class="p">()</span>
<span class="nx">@addImplicitParentheses</span><span class="p">()</span>
<span class="nx">@ensureBalance</span> <span class="nx">BALANCED_PAIRS</span>
<span class="nx">@rewriteClosingParens</span><span class="p">()</span>
<span class="nx">@tokens</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Rewrite the token stream, looking one token ahead and behind.
Allow the return value of the block to tell us how many tokens to move
forwards (or backwards) in the stream, to make sure we don't miss anything
as tokens are inserted and removed, and the stream changes length under
our feet.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">scanTokens</span><span class="o">:</span> <span class="p">(</span><span class="nx">block</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="p">{</span><span class="nx">tokens</span><span class="p">}</span> <span class="o">=</span> <span class="k">this</span>
<span class="nv">i = </span><span class="mi">0</span>
<span class="nx">i</span> <span class="o">+=</span> <span class="nx">block</span><span class="p">.</span><span class="nx">call</span> <span class="k">this</span><span class="p">,</span> <span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">tokens</span> <span class="k">while</span> <span class="nv">token = </span><span class="nx">tokens</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span>
<span class="kc">true</span>
<span class="nx">detectEnd</span><span class="o">:</span> <span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="nx">action</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="p">{</span><span class="nx">tokens</span><span class="p">}</span> <span class="o">=</span> <span class="k">this</span>
<span class="nv">levels = </span><span class="mi">0</span>
<span class="k">while</span> <span class="nv">token = </span><span class="nx">tokens</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span>
<span class="k">return</span> <span class="nx">action</span><span class="p">.</span><span class="nx">call</span> <span class="k">this</span><span class="p">,</span> <span class="nx">token</span><span class="p">,</span> <span class="nx">i</span> <span class="k">if</span> <span class="nx">levels</span> <span class="o">is</span> <span class="mi">0</span> <span class="o">and</span> <span class="nx">condition</span><span class="p">.</span><span class="nx">call</span> <span class="k">this</span><span class="p">,</span> <span class="nx">token</span><span class="p">,</span> <span class="nx">i</span>
<span class="k">return</span> <span class="nx">action</span><span class="p">.</span><span class="nx">call</span> <span class="k">this</span><span class="p">,</span> <span class="nx">token</span><span class="p">,</span> <span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">token</span> <span class="o">or</span> <span class="nx">levels</span> <span class="o">&lt;</span> <span class="mi">0</span>
<span class="k">if</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="nx">EXPRESSION_START</span>
<span class="nx">levels</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="nx">EXPRESSION_END</span>
<span class="nx">levels</span> <span class="o">-=</span> <span class="mi">1</span>
<span class="nx">i</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Leading newlines would introduce an ambiguity in the grammar, so we
dispatch them here.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">removeLeadingNewlines</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="k">break</span> <span class="k">for</span> <span class="p">[</span><span class="nx">tag</span><span class="p">],</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">@tokens</span> <span class="k">when</span> <span class="nx">tag</span> <span class="o">isnt</span> <span class="s1">&#39;TERMINATOR&#39;</span>
<span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">i</span> <span class="k">if</span> <span class="nx">i</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Some blocks occur in the middle of expressions -- when we're expecting
this, remove their trailing newlines.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">removeMidExpressionNewlines</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nx">@scanTokens</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">tokens</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">return</span> <span class="mi">1</span> <span class="nx">unless</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;TERMINATOR&#39;</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="k">in</span> <span class="nx">EXPRESSION_CLOSE</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span><span class="p">,</span> <span class="mi">1</span>
<span class="mi">0</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>The lexer has tagged the opening parenthesis of a method call. Match it with
its paired close. We have the mis-nested outdent case included here for
calls that close on the same line, just before their outdent.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">closeOpenCalls</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nv">condition = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;)&#39;</span><span class="p">,</span> <span class="s1">&#39;CALL_END&#39;</span><span class="p">]</span> <span class="o">or</span>
<span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;OUTDENT&#39;</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;)&#39;</span>
<span class="nv">action = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">@tokens</span><span class="p">[</span><span class="k">if</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;OUTDENT&#39;</span> <span class="k">then</span> <span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">else</span> <span class="nx">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;CALL_END&#39;</span>
<span class="nx">@scanTokens</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">@detectEnd</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="nx">action</span> <span class="k">if</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;CALL_START&#39;</span>
<span class="mi">1</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>The lexer has tagged the opening parenthesis of an indexing operation call.
Match it with its paired close.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">closeOpenIndexes</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nv">condition = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;]&#39;</span><span class="p">,</span> <span class="s1">&#39;INDEX_END&#39;</span><span class="p">]</span>
<span class="nv">action = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;INDEX_END&#39;</span>
<span class="nx">@scanTokens</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">@detectEnd</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="nx">action</span> <span class="k">if</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;INDEX_START&#39;</span>
<span class="mi">1</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Object literals may be written with implicit braces, for simple cases.
Insert the missing braces here, so that the parser doesn't have to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">addImplicitBraces</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nv">stack = </span><span class="p">[]</span>
<span class="nv">start = </span><span class="kc">null</span>
<span class="nv">startIndent = </span><span class="mi">0</span>
<span class="nv">condition = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="p">[</span><span class="nx">one</span><span class="p">,</span> <span class="nx">two</span><span class="p">,</span> <span class="nx">three</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@tokens</span><span class="p">[</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span> <span class="p">..</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">3</span><span class="p">]</span>
<span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="s1">&#39;HERECOMMENT&#39;</span> <span class="o">is</span> <span class="nx">one</span><span class="o">?</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="p">[</span><span class="nx">tag</span><span class="p">]</span> <span class="o">=</span> <span class="nx">token</span>
<span class="p">(</span><span class="nx">tag</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;TERMINATOR&#39;</span><span class="p">,</span> <span class="s1">&#39;OUTDENT&#39;</span><span class="p">]</span> <span class="o">and</span>
<span class="o">not</span> <span class="p">(</span><span class="nx">two</span><span class="o">?</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;:&#39;</span> <span class="o">or</span> <span class="nx">one</span><span class="o">?</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;@&#39;</span> <span class="o">and</span> <span class="nx">three</span><span class="o">?</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;:&#39;</span><span class="p">))</span> <span class="o">or</span>
<span class="p">(</span><span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;,&#39;</span> <span class="o">and</span> <span class="nx">one</span> <span class="o">and</span>
<span class="nx">one</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">not</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;IDENTIFIER&#39;</span><span class="p">,</span> <span class="s1">&#39;NUMBER&#39;</span><span class="p">,</span> <span class="s1">&#39;STRING&#39;</span><span class="p">,</span> <span class="s1">&#39;@&#39;</span><span class="p">,</span> <span class="s1">&#39;TERMINATOR&#39;</span><span class="p">,</span> <span class="s1">&#39;OUTDENT&#39;</span><span class="p">])</span>
<span class="nv">action = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="nx">token</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
<span class="nx">@scanTokens</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">tokens</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">tag = </span><span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="k">in</span> <span class="nx">EXPRESSION_START</span>
<span class="nx">stack</span><span class="p">.</span><span class="nx">push</span> <span class="p">[(</span><span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;INDENT&#39;</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;{&#39;</span> <span class="k">then</span> <span class="s1">&#39;{&#39;</span> <span class="k">else</span> <span class="nx">tag</span><span class="p">),</span> <span class="nx">i</span><span class="p">]</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nx">tag</span> <span class="k">in</span> <span class="nx">EXPRESSION_END</span>
<span class="nv">start = </span><span class="nx">stack</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="mi">1</span> <span class="nx">unless</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;:&#39;</span> <span class="o">and</span>
<span class="p">((</span><span class="nv">ago = </span><span class="nx">@tag</span> <span class="nx">i</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;:&#39;</span> <span class="o">or</span> <span class="nx">stack</span><span class="p">[</span><span class="nx">stack</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span><span class="o">?</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">isnt</span> <span class="s1">&#39;{&#39;</span><span class="p">)</span>
<span class="nx">stack</span><span class="p">.</span><span class="nx">push</span> <span class="p">[</span><span class="s1">&#39;{&#39;</span><span class="p">]</span>
<span class="nv">idx = </span> <span class="k">if</span> <span class="nx">ago</span> <span class="o">is</span> <span class="s1">&#39;@&#39;</span> <span class="k">then</span> <span class="nx">i</span> <span class="o">-</span> <span class="mi">2</span> <span class="k">else</span> <span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span>
<span class="nx">idx</span> <span class="o">-=</span> <span class="mi">2</span> <span class="k">while</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">idx</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;HERECOMMENT&#39;</span>
<span class="nv">value = </span><span class="k">new</span> <span class="nb">String</span><span class="p">(</span><span class="s1">&#39;{&#39;</span><span class="p">)</span>
<span class="nv">value.generated = </span><span class="kc">yes</span>
<span class="nv">tok = </span><span class="p">[</span><span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">token</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
<span class="nv">tok.generated = </span><span class="kc">yes</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">idx</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">tok</span>
<span class="nx">@detectEnd</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="nx">action</span>
<span class="mi">2</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Methods may be optionally called without parentheses, for simple cases.
Insert the implicit parentheses here, so that the parser doesn't have to
deal with them.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">addImplicitParentheses</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nv">noCall = </span><span class="kc">no</span>
<span class="nv">action = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">idx = </span><span class="k">if</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;OUTDENT&#39;</span> <span class="k">then</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span> <span class="k">else</span> <span class="nx">i</span>
<span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">idx</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;CALL_END&#39;</span><span class="p">,</span> <span class="s1">&#39;)&#39;</span><span class="p">,</span> <span class="nx">token</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
<span class="nx">@scanTokens</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">tokens</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">tag = </span><span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="nv">noCall = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">tag</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;CLASS&#39;</span><span class="p">,</span> <span class="s1">&#39;IF&#39;</span><span class="p">,</span> <span class="s1">&#39;UNLESS&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="nx">prev</span><span class="p">,</span> <span class="nx">current</span><span class="p">,</span> <span class="nx">next</span><span class="p">]</span> <span class="o">=</span> <span class="nx">tokens</span><span class="p">[</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span> <span class="p">..</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span>
<span class="nv">callObject = </span><span class="o">not</span> <span class="nx">noCall</span> <span class="o">and</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;INDENT&#39;</span> <span class="o">and</span>
<span class="nx">next</span> <span class="o">and</span> <span class="nx">next</span><span class="p">.</span><span class="nx">generated</span> <span class="o">and</span> <span class="nx">next</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;{&#39;</span> <span class="o">and</span>
<span class="nx">prev</span> <span class="o">and</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="nx">IMPLICIT_FUNC</span>
<span class="nv">seenSingle = </span><span class="kc">no</span>
<span class="nv">noCall = </span><span class="kc">no</span> <span class="k">if</span> <span class="nx">tag</span> <span class="k">in</span> <span class="nx">LINEBREAKS</span>
<span class="nv">token.call = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">prev</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">prev</span><span class="p">.</span><span class="nx">spaced</span> <span class="o">and</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;?&#39;</span>
<span class="k">return</span> <span class="mi">1</span> <span class="nx">unless</span> <span class="nx">callObject</span> <span class="o">or</span>
<span class="nx">prev</span><span class="o">?</span><span class="p">.</span><span class="nx">spaced</span> <span class="o">and</span> <span class="p">(</span><span class="nx">prev</span><span class="p">.</span><span class="nx">call</span> <span class="o">or</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="nx">IMPLICIT_FUNC</span><span class="p">)</span> <span class="o">and</span>
<span class="p">(</span><span class="nx">tag</span> <span class="k">in</span> <span class="nx">IMPLICIT_CALL</span> <span class="o">or</span> <span class="o">not</span> <span class="p">(</span><span class="nx">token</span><span class="p">.</span><span class="nx">spaced</span> <span class="o">or</span> <span class="nx">token</span><span class="p">.</span><span class="nx">newLine</span><span class="p">)</span> <span class="o">and</span> <span class="nx">tag</span> <span class="k">in</span> <span class="nx">IMPLICIT_UNSPACED_CALL</span><span class="p">)</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;CALL_START&#39;</span><span class="p">,</span> <span class="s1">&#39;(&#39;</span><span class="p">,</span> <span class="nx">token</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
<span class="nx">@detectEnd</span> <span class="nx">i</span> <span class="o">+</span> <span class="p">(</span><span class="k">if</span> <span class="nx">callObject</span> <span class="k">then</span> <span class="mi">2</span> <span class="k">else</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">return</span> <span class="kc">yes</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">seenSingle</span> <span class="o">and</span> <span class="nx">token</span><span class="p">.</span><span class="nx">fromThen</span>
<span class="p">[</span><span class="nx">tag</span><span class="p">]</span> <span class="o">=</span> <span class="nx">token</span>
<span class="nv">seenSingle = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">tag</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;IF&#39;</span><span class="p">,</span> <span class="s1">&#39;ELSE&#39;</span><span class="p">,</span> <span class="s1">&#39;UNLESS&#39;</span><span class="p">,</span> <span class="s1">&#39;-&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;=&gt;&#39;</span><span class="p">]</span>
<span class="k">return</span> <span class="kc">yes</span> <span class="k">if</span> <span class="nx">tag</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="s1">&#39;?.&#39;</span><span class="p">,</span> <span class="s1">&#39;::&#39;</span><span class="p">]</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;OUTDENT&#39;</span>
<span class="o">not</span> <span class="nx">token</span><span class="p">.</span><span class="nx">generated</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">isnt</span> <span class="s1">&#39;,&#39;</span> <span class="o">and</span> <span class="nx">tag</span> <span class="k">in</span> <span class="nx">IMPLICIT_END</span> <span class="o">and</span>
<span class="p">(</span><span class="nx">tag</span> <span class="o">isnt</span> <span class="s1">&#39;INDENT&#39;</span> <span class="o">or</span>
<span class="p">(</span><span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">isnt</span> <span class="s1">&#39;CLASS&#39;</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">not</span> <span class="k">in</span> <span class="nx">IMPLICIT_BLOCK</span> <span class="o">and</span>
<span class="o">not</span> <span class="p">((</span><span class="nv">post = </span><span class="nx">@tokens</span><span class="p">[</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">])</span> <span class="o">and</span> <span class="nx">post</span><span class="p">.</span><span class="nx">generated</span> <span class="o">and</span> <span class="nx">post</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;{&#39;</span><span class="p">)))</span>
<span class="p">,</span> <span class="nx">action</span>
<span class="nx">prev</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;FUNC_EXIST&#39;</span> <span class="k">if</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;?&#39;</span>
<span class="mi">2</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Because our grammar is LALR(1), it can't handle some single-line
expressions that lack ending delimiters. The <strong>Rewriter</strong> adds the implicit
blocks, so it doesn't need to. ')' can close a single-line block,
but we need to make sure it's balanced.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">addImplicitIndentation</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nx">@scanTokens</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">tokens</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="p">[</span><span class="nx">tag</span><span class="p">]</span> <span class="o">=</span> <span class="nx">token</span>
<span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;TERMINATOR&#39;</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;THEN&#39;</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span><span class="p">,</span> <span class="mi">1</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;ELSE&#39;</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">isnt</span> <span class="s1">&#39;OUTDENT&#39;</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">@indentation</span><span class="p">(</span><span class="nx">token</span><span class="p">)...</span>
<span class="k">return</span> <span class="mi">2</span>
<span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;CATCH&#39;</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;OUTDENT&#39;</span><span class="p">,</span> <span class="s1">&#39;TERMINATOR&#39;</span><span class="p">,</span> <span class="s1">&#39;FINALLY&#39;</span><span class="p">]</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">@indentation</span><span class="p">(</span><span class="nx">token</span><span class="p">)...</span>
<span class="k">return</span> <span class="mi">4</span>
<span class="k">if</span> <span class="nx">tag</span> <span class="k">in</span> <span class="nx">SINGLE_LINERS</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">isnt</span> <span class="s1">&#39;INDENT&#39;</span> <span class="o">and</span>
<span class="o">not</span> <span class="p">(</span><span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;ELSE&#39;</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;IF&#39;</span><span class="p">)</span>
<span class="nv">starter = </span><span class="nx">tag</span>
<span class="p">[</span><span class="nx">indent</span><span class="p">,</span> <span class="nx">outdent</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@indentation</span> <span class="nx">token</span>
<span class="nv">indent.fromThen = </span><span class="kc">true</span> <span class="k">if</span> <span class="nx">starter</span> <span class="o">is</span> <span class="s1">&#39;THEN&#39;</span>
<span class="nv">indent.generated = outdent.generated = </span><span class="kc">true</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">indent</span>
<span class="nv">condition = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">token</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">isnt</span> <span class="s1">&#39;;&#39;</span> <span class="o">and</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="nx">SINGLE_CLOSERS</span> <span class="o">and</span>
<span class="o">not</span> <span class="p">(</span><span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">&#39;ELSE&#39;</span> <span class="o">and</span> <span class="nx">starter</span> <span class="o">not</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;IF&#39;</span><span class="p">,</span> <span class="s1">&#39;THEN&#39;</span><span class="p">])</span>
<span class="nv">action = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="p">(</span><span class="k">if</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;,&#39;</span> <span class="k">then</span> <span class="nx">i</span> <span class="o">-</span> <span class="mi">1</span> <span class="k">else</span> <span class="nx">i</span><span class="p">),</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">outdent</span>
<span class="nx">@detectEnd</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="nx">action</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">&#39;THEN&#39;</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Tag postfix conditionals as such, so that we can parse them with a
different precedence.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">tagPostfixConditionals</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nv">condition = </span><span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;TERMINATOR&#39;</span><span class="p">,</span> <span class="s1">&#39;INDENT&#39;</span><span class="p">]</span>
<span class="nx">@scanTokens</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">return</span> <span class="mi">1</span> <span class="nx">unless</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">in</span> <span class="p">[</span><span class="s1">&#39;IF&#39;</span><span class="p">,</span> <span class="s1">&#39;UNLESS&#39;</span><span class="p">]</span>
<span class="nv">original = </span><span class="nx">token</span>
<span class="nx">@detectEnd</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">original</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;POST_&#39;</span> <span class="o">+</span> <span class="nx">original</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">isnt</span> <span class="s1">&#39;INDENT&#39;</span>
<span class="mi">1</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Ensure that all listed pairs of tokens are correctly balanced throughout
the course of the token stream.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ensureBalance</span><span class="o">:</span> <span class="p">(</span><span class="nx">pairs</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">levels = </span><span class="p">{}</span>
<span class="nv">openLine = </span><span class="p">{}</span>
<span class="k">for</span> <span class="nx">token</span> <span class="k">in</span> <span class="nx">@tokens</span>
<span class="p">[</span><span class="nx">tag</span><span class="p">]</span> <span class="o">=</span> <span class="nx">token</span>
<span class="k">for</span> <span class="p">[</span><span class="nx">open</span><span class="p">,</span> <span class="nx">close</span><span class="p">]</span> <span class="k">in</span> <span class="nx">pairs</span>
<span class="nx">levels</span><span class="p">[</span><span class="nx">open</span><span class="p">]</span> <span class="o">|=</span> <span class="mi">0</span>
<span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="nx">open</span>
<span class="nx">openLine</span><span class="p">[</span><span class="nx">open</span><span class="p">]</span> <span class="o">=</span> <span class="nx">token</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="nx">levels</span><span class="p">[</span><span class="nx">open</span><span class="p">]</span><span class="o">++</span> <span class="o">is</span> <span class="mi">0</span>
<span class="k">else</span> <span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="nx">close</span> <span class="o">and</span> <span class="o">--</span><span class="nx">levels</span><span class="p">[</span><span class="nx">open</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">0</span>
<span class="k">throw</span> <span class="nb">Error</span> <span class="s2">&quot;too many #{token[1]} on line #{token[2] + 1}&quot;</span>
<span class="k">for</span> <span class="nx">open</span><span class="p">,</span> <span class="nx">level</span> <span class="k">of</span> <span class="nx">levels</span> <span class="k">when</span> <span class="nx">level</span> <span class="o">&gt;</span> <span class="mi">0</span>
<span class="k">throw</span> <span class="nb">Error</span> <span class="s2">&quot;unclosed #{ open } on line #{openLine[open] + 1}&quot;</span>
<span class="k">this</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>We'd like to support syntax like this:</p>
<pre><code>el.click((event) -&gt;
el.hide())
</code></pre>
<p>In order to accomplish this, move outdents that follow closing parens
inwards, safely. The steps to accomplish this are:</p>
<ol>
<li>Check that all paired tokens are balanced and in order.</li>
<li>Rewrite the stream with a stack: if you see an <code>EXPRESSION_START</code>, add it
to the stack. If you see an <code>EXPRESSION_END</code>, pop the stack and replace
it with the inverse of what we've just popped.</li>
<li>Keep track of "debt" for tokens that we manufacture, to make sure we end
up balanced in the end.</li>
<li>Be careful not to alter array or parentheses delimiters with overzealous
rewriting.</li>
</ol> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">rewriteClosingParens</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nv">stack = </span><span class="p">[]</span>
<span class="nv">debt = </span><span class="p">{}</span>
<span class="nx">debt</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span> <span class="k">for</span> <span class="nx">key</span> <span class="k">of</span> <span class="nx">INVERSES</span>
<span class="nx">@scanTokens</span> <span class="p">(</span><span class="nx">token</span><span class="p">,</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">tokens</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="p">(</span><span class="nv">tag = </span><span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="k">in</span> <span class="nx">EXPRESSION_START</span>
<span class="nx">stack</span><span class="p">.</span><span class="nx">push</span> <span class="nx">token</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="mi">1</span> <span class="nx">unless</span> <span class="nx">tag</span> <span class="k">in</span> <span class="nx">EXPRESSION_END</span>
<span class="k">if</span> <span class="nx">debt</span><span class="p">[</span><span class="nv">inv = </span><span class="nx">INVERSES</span><span class="p">[</span><span class="nx">tag</span><span class="p">]]</span> <span class="o">&gt;</span> <span class="mi">0</span>
<span class="nx">debt</span><span class="p">[</span><span class="nx">inv</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">1</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span><span class="p">,</span> <span class="mi">1</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="nv">match = </span><span class="nx">stack</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
<span class="nv">mtag = </span><span class="nx">match</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="nv">oppos = </span><span class="nx">INVERSES</span><span class="p">[</span><span class="nx">mtag</span><span class="p">]</span>
<span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="nx">oppos</span>
<span class="nx">debt</span><span class="p">[</span><span class="nx">mtag</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="nv">val = </span><span class="p">[</span><span class="nx">oppos</span><span class="p">,</span> <span class="k">if</span> <span class="nx">mtag</span> <span class="o">is</span> <span class="s1">&#39;INDENT&#39;</span> <span class="k">then</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">else</span> <span class="nx">oppos</span><span class="p">]</span>
<span class="k">if</span> <span class="nx">@tag</span><span class="p">(</span><span class="nx">i</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span> <span class="o">is</span> <span class="nx">mtag</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span> <span class="o">+</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">val</span>
<span class="nx">stack</span><span class="p">.</span><span class="nx">push</span> <span class="nx">match</span>
<span class="k">else</span>
<span class="nx">tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">i</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">val</span>
<span class="mi">1</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Generate the indentation tokens, based on another token on the same line.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">indentation</span><span class="o">:</span> <span class="p">(</span><span class="nx">token</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="p">[[</span><span class="s1">&#39;INDENT&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">token</span><span class="p">[</span><span class="mi">2</span><span class="p">]],</span> <span class="p">[</span><span class="s1">&#39;OUTDENT&#39;</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="nx">token</span><span class="p">[</span><span class="mi">2</span><span class="p">]]]</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Look up a tag by token index.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">tag</span><span class="o">:</span> <span class="p">(</span><span class="nx">i</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nx">@tokens</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span><span class="o">?</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <h2>Constants</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>List of the token pairs that must be balanced.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">BALANCED_PAIRS = </span><span class="p">[</span>
<span class="p">[</span><span class="s1">&#39;(&#39;</span><span class="p">,</span> <span class="s1">&#39;)&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;[&#39;</span><span class="p">,</span> <span class="s1">&#39;]&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;INDENT&#39;</span><span class="p">,</span> <span class="s1">&#39;OUTDENT&#39;</span><span class="p">],</span>
<span class="p">[</span><span class="s1">&#39;CALL_START&#39;</span><span class="p">,</span> <span class="s1">&#39;CALL_END&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;PARAM_START&#39;</span><span class="p">,</span> <span class="s1">&#39;PARAM_END&#39;</span><span class="p">]</span>
<span class="p">[</span><span class="s1">&#39;INDEX_START&#39;</span><span class="p">,</span> <span class="s1">&#39;INDEX_END&#39;</span><span class="p">]</span>
<span class="p">]</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>The inverse mappings of <code>BALANCED_PAIRS</code> we're trying to fix up, so we can
look things up from either end.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">INVERSES = </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>The tokens that signal the start/end of a balanced pair.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">EXPRESSION_START = </span><span class="p">[]</span>
<span class="nv">EXPRESSION_END = </span><span class="p">[]</span>
<span class="k">for</span> <span class="p">[</span><span class="nx">left</span><span class="p">,</span> <span class="nx">rite</span><span class="p">]</span> <span class="k">in</span> <span class="nx">BALANCED_PAIRS</span>
<span class="nx">EXPRESSION_START</span><span class="p">.</span><span class="nx">push</span> <span class="nx">INVERSES</span><span class="p">[</span><span class="nx">rite</span><span class="p">]</span> <span class="o">=</span> <span class="nx">left</span>
<span class="nx">EXPRESSION_END</span> <span class="p">.</span><span class="nx">push</span> <span class="nx">INVERSES</span><span class="p">[</span><span class="nx">left</span><span class="p">]</span> <span class="o">=</span> <span class="nx">rite</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Tokens that indicate the close of a clause of an expression.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">EXPRESSION_CLOSE = </span><span class="p">[</span><span class="s1">&#39;CATCH&#39;</span><span class="p">,</span> <span class="s1">&#39;WHEN&#39;</span><span class="p">,</span> <span class="s1">&#39;ELSE&#39;</span><span class="p">,</span> <span class="s1">&#39;FINALLY&#39;</span><span class="p">].</span><span class="nx">concat</span> <span class="nx">EXPRESSION_END</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Tokens that, if followed by an <code>IMPLICIT_CALL</code>, indicate a function invocation.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IMPLICIT_FUNC = </span><span class="p">[</span><span class="s1">&#39;IDENTIFIER&#39;</span><span class="p">,</span> <span class="s1">&#39;SUPER&#39;</span><span class="p">,</span> <span class="s1">&#39;)&#39;</span><span class="p">,</span> <span class="s1">&#39;CALL_END&#39;</span><span class="p">,</span> <span class="s1">&#39;]&#39;</span><span class="p">,</span> <span class="s1">&#39;INDEX_END&#39;</span><span class="p">,</span> <span class="s1">&#39;@&#39;</span><span class="p">,</span> <span class="s1">&#39;THIS&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>If preceded by an <code>IMPLICIT_FUNC</code>, indicates a function invocation.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IMPLICIT_CALL = </span><span class="p">[</span>
<span class="s1">&#39;IDENTIFIER&#39;</span><span class="p">,</span> <span class="s1">&#39;NUMBER&#39;</span><span class="p">,</span> <span class="s1">&#39;STRING&#39;</span><span class="p">,</span> <span class="s1">&#39;JS&#39;</span><span class="p">,</span> <span class="s1">&#39;REGEX&#39;</span><span class="p">,</span> <span class="s1">&#39;NEW&#39;</span><span class="p">,</span> <span class="s1">&#39;PARAM_START&#39;</span><span class="p">,</span> <span class="s1">&#39;CLASS&#39;</span>
<span class="s1">&#39;IF&#39;</span><span class="p">,</span> <span class="s1">&#39;UNLESS&#39;</span><span class="p">,</span> <span class="s1">&#39;TRY&#39;</span><span class="p">,</span> <span class="s1">&#39;SWITCH&#39;</span><span class="p">,</span> <span class="s1">&#39;THIS&#39;</span><span class="p">,</span> <span class="s1">&#39;BOOL&#39;</span><span class="p">,</span> <span class="s1">&#39;UNARY&#39;</span><span class="p">,</span>
<span class="s1">&#39;@&#39;</span><span class="p">,</span> <span class="s1">&#39;-&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;=&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;[&#39;</span><span class="p">,</span> <span class="s1">&#39;(&#39;</span><span class="p">,</span> <span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;--&#39;</span><span class="p">,</span> <span class="s1">&#39;++&#39;</span>
<span class="p">]</span>
<span class="nv">IMPLICIT_UNSPACED_CALL = </span><span class="p">[</span><span class="s1">&#39;+&#39;</span><span class="p">,</span> <span class="s1">&#39;-&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Tokens indicating that the implicit call must enclose a block of expressions.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IMPLICIT_BLOCK = </span><span class="p">[</span><span class="s1">&#39;-&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;=&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;[&#39;</span><span class="p">,</span> <span class="s1">&#39;,&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>Tokens that always mark the end of an implicit call for single-liners.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IMPLICIT_END = </span><span class="p">[</span><span class="s1">&#39;POST_IF&#39;</span><span class="p">,</span> <span class="s1">&#39;POST_UNLESS&#39;</span><span class="p">,</span> <span class="s1">&#39;FOR&#39;</span><span class="p">,</span> <span class="s1">&#39;WHILE&#39;</span><span class="p">,</span> <span class="s1">&#39;UNTIL&#39;</span><span class="p">,</span> <span class="s1">&#39;WHEN&#39;</span><span class="p">,</span> <span class="s1">&#39;BY&#39;</span><span class="p">,</span> <span class="s1">&#39;LOOP&#39;</span><span class="p">,</span> <span class="s1">&#39;TERMINATOR&#39;</span><span class="p">,</span> <span class="s1">&#39;INDENT&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Single-line flavors of block expressions that have unclosed endings.
The grammar can't disambiguate them, so we insert the implicit indentation.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">SINGLE_LINERS = </span><span class="p">[</span><span class="s1">&#39;ELSE&#39;</span><span class="p">,</span> <span class="s1">&#39;-&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;=&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;TRY&#39;</span><span class="p">,</span> <span class="s1">&#39;FINALLY&#39;</span><span class="p">,</span> <span class="s1">&#39;THEN&#39;</span><span class="p">]</span>
<span class="nv">SINGLE_CLOSERS = </span><span class="p">[</span><span class="s1">&#39;TERMINATOR&#39;</span><span class="p">,</span> <span class="s1">&#39;CATCH&#39;</span><span class="p">,</span> <span class="s1">&#39;FINALLY&#39;</span><span class="p">,</span> <span class="s1">&#39;ELSE&#39;</span><span class="p">,</span> <span class="s1">&#39;OUTDENT&#39;</span><span class="p">,</span> <span class="s1">&#39;LEADING_WHEN&#39;</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Tokens that end a line.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">LINEBREAKS = </span><span class="p">[</span><span class="s1">&#39;TERMINATOR&#39;</span><span class="p">,</span> <span class="s1">&#39;INDENT&#39;</span><span class="p">,</span> <span class="s1">&#39;OUTDENT&#39;</span><span class="p">]</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

View File

@@ -0,0 +1,54 @@
<!DOCTYPE html> <html> <head> <title>scope.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="browser.html"> browser.coffee </a> <a class="source" href="cake.html"> cake.coffee </a> <a class="source" href="coffee-script.html"> coffee-script.coffee </a> <a class="source" href="command.html"> command.coffee </a> <a class="source" href="grammar.html"> grammar.coffee </a> <a class="source" href="helpers.html"> helpers.coffee </a> <a class="source" href="index.html"> index.coffee </a> <a class="source" href="lexer.html"> lexer.coffee </a> <a class="source" href="nodes.html"> nodes.coffee </a> <a class="source" href="optparse.html"> optparse.coffee </a> <a class="source" href="repl.html"> repl.coffee </a> <a class="source" href="rewriter.html"> rewriter.coffee </a> <a class="source" href="scope.html"> scope.coffee </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> scope.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p>The <strong>Scope</strong> class regulates lexical scoping within CoffeeScript. As you
generate code, you create a tree of scopes in the same shape as the nested
function bodies. Each scope knows about the variables declared within it,
and has a reference to its parent enclosing scope. In this way, we know which
variables are new and need to be declared with <code>var</code>, and which are shared
with the outside.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <p>Import the helpers we plan to use.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">extend</span><span class="p">,</span> <span class="nx">last</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">&#39;./helpers&#39;</span>
<span class="nv">exports.Scope = </span><span class="nx">class</span> <span class="nx">Scope</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>The top-level <strong>Scope</strong> object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">@root</span><span class="o">:</span> <span class="kc">null</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Initialize a scope with its parent, for lookups up the chain,
as well as a reference to the <strong>Expressions</strong> node is belongs to, which is
where it should declare its variables, and a reference to the function that
it wraps.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">constructor</span><span class="o">:</span><span class="p">(</span><span class="nx">@parent</span><span class="p">,</span> <span class="nx">@expressions</span><span class="p">,</span> <span class="nx">@method</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="vi">@variables = </span><span class="p">[{</span><span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;arguments&#39;</span><span class="p">,</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">&#39;arguments&#39;</span><span class="p">}]</span>
<span class="vi">@positions = </span><span class="p">{}</span>
<span class="nv">Scope.root = </span><span class="k">this</span> <span class="nx">unless</span> <span class="nx">@parent</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Adds a new variable or overrides an existing one.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">add</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">type</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="k">typeof</span> <span class="p">(</span><span class="nv">pos = </span><span class="nx">@positions</span><span class="p">[</span><span class="nx">name</span><span class="p">])</span> <span class="o">is</span> <span class="s1">&#39;number&#39;</span>
<span class="nx">@variables</span><span class="p">[</span><span class="nx">pos</span><span class="p">].</span><span class="nv">type = </span><span class="nx">type</span>
<span class="k">else</span>
<span class="nx">@positions</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@variables</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span><span class="nx">name</span><span class="p">,</span> <span class="nx">type</span><span class="p">})</span> <span class="o">-</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Look up a variable name in lexical scope, and declare it if it does not
already exist.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">find</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">return</span> <span class="kc">yes</span> <span class="k">if</span> <span class="nx">@check</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">options</span>
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="s1">&#39;var&#39;</span>
<span class="vi">@hasDeclarations = </span><span class="kc">yes</span>
<span class="kc">no</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Reserve a variable name as originating from a function parameter for this
scope. No <code>var</code> required for internal references.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">parameter</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">return</span> <span class="k">if</span> <span class="nx">@shared</span> <span class="o">and</span> <span class="nx">@check</span> <span class="nx">name</span><span class="p">,</span> <span class="kc">yes</span>
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="s1">&#39;param&#39;</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Just check to see if a variable has already been declared, without reserving,
walks up to the root scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">check</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">immediate</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">found = </span><span class="o">!!</span><span class="nx">@type</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span>
<span class="k">return</span> <span class="nx">found</span> <span class="k">if</span> <span class="nx">found</span> <span class="o">or</span> <span class="nx">immediate</span>
<span class="o">!!</span><span class="nx">@parent</span><span class="o">?</span><span class="p">.</span><span class="nx">check</span> <span class="nx">name</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Generate a temporary variable name at the given index.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">temporary</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">index</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">if</span> <span class="nx">name</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">1</span>
<span class="s1">&#39;_&#39;</span> <span class="o">+</span> <span class="nx">name</span> <span class="o">+</span> <span class="k">if</span> <span class="nx">index</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="k">then</span> <span class="nx">index</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span>
<span class="k">else</span>
<span class="s1">&#39;_&#39;</span> <span class="o">+</span> <span class="p">(</span><span class="nx">index</span> <span class="o">+</span> <span class="nb">parseInt</span> <span class="nx">name</span><span class="p">,</span> <span class="mi">36</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">36</span><span class="p">).</span><span class="nx">replace</span> <span class="sr">/\d/g</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Gets the type of a variable.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">type</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">return</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span> <span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span> <span class="o">is</span> <span class="nx">name</span>
<span class="kc">null</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>If we need to store an intermediate result, find an available name for a
compiler-generated variable. <code>_var</code>, <code>_var2</code>, and so on...</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">freeVariable</span><span class="o">:</span> <span class="p">(</span><span class="nx">type</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nv">index = </span><span class="mi">0</span>
<span class="nx">index</span><span class="o">++</span> <span class="k">while</span> <span class="nx">@check</span><span class="p">((</span><span class="nv">temp = </span><span class="nx">@temporary</span> <span class="nx">type</span><span class="p">,</span> <span class="nx">index</span><span class="p">),</span> <span class="kc">true</span><span class="p">)</span>
<span class="nx">@add</span> <span class="nx">temp</span><span class="p">,</span> <span class="s1">&#39;var&#39;</span>
<span class="vi">@hasDeclarations = </span><span class="kc">yes</span>
<span class="nx">temp</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Ensure that an assignment is made at the top of this scope
(or at the top-level scope, if requested).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">assign</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="nx">@add</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">value</span><span class="o">:</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">assigned</span><span class="o">:</span> <span class="kc">true</span>
<span class="vi">@hasAssignments = </span><span class="kc">yes</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Return the list of variables first declared in this scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">declaredVariables</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="nv">realVars = </span><span class="p">[]</span>
<span class="nv">tempVars = </span><span class="p">[]</span>
<span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span> <span class="o">is</span> <span class="s1">&#39;var&#39;</span>
<span class="p">(</span><span class="k">if</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="o">is</span> <span class="s1">&#39;_&#39;</span> <span class="k">then</span> <span class="nx">tempVars</span> <span class="k">else</span> <span class="nx">realVars</span><span class="p">).</span><span class="nx">push</span> <span class="nx">v</span><span class="p">.</span><span class="nx">name</span>
<span class="nx">realVars</span><span class="p">.</span><span class="nx">sort</span><span class="p">().</span><span class="nx">concat</span> <span class="nx">tempVars</span><span class="p">.</span><span class="nx">sort</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Return the list of assignments that are supposed to be made at the top
of this scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">assignedVariables</span><span class="o">:</span> <span class="o">-&gt;</span>
<span class="s2">&quot;#{v.name} = #{v.type.value}&quot;</span> <span class="k">for</span> <span class="nx">v</span> <span class="k">in</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">v</span><span class="p">.</span><span class="nx">type</span><span class="p">.</span><span class="nx">assigned</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,17 @@
(function(){
var volume;
if (ignition === true) {
launch();
}
if (band !== spinal_tap) {
volume = 10;
}
if (!(answer === false)) {
let_the_wild_rumpus_begin();
}
car.speed < speed_limit ? accelerate() : null;
print("My name is " + this.name);
})();
var volume, winner;
if (ignition === true) {
launch();
}
if (band !== SpinalTap) {
volume = 10;
}
if (answer !== false) {
letTheWildRumpusBegin();
}
if (car.speed < limit) {
accelerate();
}
if (pick === 47 || pick === 92 || pick === 13) {
winner = true;
}
print(inspect("My name is " + this.name));

View File

@@ -1,8 +0,0 @@
(function(){
var backwards;
backwards = function backwards() {
arguments = Array.prototype.slice.call(arguments, 0);
return alert(arguments.reverse());
};
backwards("stairway", "to", "heaven");
})();

View File

@@ -1,26 +1,6 @@
(function(){
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, food, lunch, roid, roid2;
// Eat lunch.
lunch = (function() {
_a = []; _b = ['toast', 'cheese', 'wine'];
for (_c = 0, _d = _b.length; _c < _d; _c++) {
food = _b[_c];
_a.push(eat(food));
}
return _a;
}).call(this);
// Naive collision detection.
_e = asteroids;
for (_f = 0, _g = _e.length; _f < _g; _f++) {
roid = _e[_f];
_h = asteroids;
for (_i = 0, _j = _h.length; _i < _j; _i++) {
roid2 = _h[_i];
if (roid !== roid2) {
if (roid.overlaps(roid2)) {
roid.explode();
}
}
}
}
})();
var food, _i, _len, _ref;
_ref = ['toast', 'cheese', 'wine'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
food = _ref[_i];
eat(food);
}

View File

@@ -1,5 +0,0 @@
(function(){
var difficulty, greeting;
greeting = "Hello CoffeeScript";
difficulty = 0.5;
})();

View File

@@ -0,0 +1,4 @@
/*
CoffeeScript Compiler v0.9.6
Released under the MIT License
*/

View File

@@ -1,14 +1,10 @@
(function(){
process.mixin(require('assert'));
task('test', 'run each of the unit tests', function() {
var _a, _b, _c, _d, test;
_a = []; _b = test_files;
for (_c = 0, _d = _b.length; _c < _d; _c++) {
test = _b[_c];
_a.push(fs.readFile(test, function(err, code) {
return eval(coffee.compile(code));
}));
}
return _a;
});
})();
var fs;
fs = require('fs');
option('-o', '--output [DIR]', 'directory for compiled code');
task('build:parser', 'rebuild the Jison parser', function(options) {
var code, dir;
require('jison');
code = require('./lib/grammar').parser.generate();
dir = options.output || 'lib';
return fs.writeFile("" + dir + "/parser.js", code);
});

View File

@@ -1,36 +1,44 @@
(function(){
var Animal, Horse, Snake, sam, tom;
var __extends = function(child, parent) {
var ctor = function(){ };
ctor.prototype = parent.prototype;
child.__superClass__ = parent.prototype;
child.prototype = new ctor();
child.prototype.constructor = child;
};
Animal = function Animal() { };
Animal.prototype.move = function move(meters) {
var Animal, Horse, Snake, sam, tom;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
};
Animal = function() {
function Animal(name) {
this.name = name;
}
Animal.prototype.move = function(meters) {
return alert(this.name + " moved " + meters + "m.");
};
Snake = function Snake(name) {
this.name = name;
return this;
};
return Animal;
}();
Snake = function() {
function Snake() {
Snake.__super__.constructor.apply(this, arguments);
}
__extends(Snake, Animal);
Snake.prototype.move = function move() {
Snake.prototype.move = function() {
alert("Slithering...");
return Snake.__superClass__.move.call(this, 5);
};
Horse = function Horse(name) {
this.name = name;
return this;
return Snake.__super__.move.call(this, 5);
};
return Snake;
}();
Horse = function() {
function Horse() {
Horse.__super__.constructor.apply(this, arguments);
}
__extends(Horse, Animal);
Horse.prototype.move = function move() {
Horse.prototype.move = function() {
alert("Galloping...");
return Horse.__superClass__.move.call(this, 45);
return Horse.__super__.move.call(this, 45);
};
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();
})();
return Horse;
}();
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();

View File

@@ -1,5 +1,3 @@
(function(){
var cholesterol, healthy;
cholesterol = 127;
healthy = (200 > cholesterol) && (cholesterol > 60);
})();
var cholesterol, healthy;
cholesterol = 127;
healthy = (200 > cholesterol && cholesterol > 60);

View File

@@ -1,12 +1,12 @@
(function(){
var date, expensive, mood;
if (singing) {
mood = greatly_improved;
}
if (happy && knows_it) {
claps_hands();
cha_cha_cha();
}
date = friday ? sue : jill;
expensive = expensive || do_the_math();
})();
var date, mood;
if (singing) {
mood = greatlyImproved;
}
if (happy && knowsIt) {
clapsHands();
chaChaCha();
} else {
showIt();
}
date = friday ? sue : jill;
options || (options = defaults);

View File

@@ -0,0 +1,7 @@
var fill;
fill = function(container, liquid) {
if (liquid == null) {
liquid = "coffee";
}
return "Filling the " + container + " with " + liquid + "...";
};

View File

@@ -1,6 +1,4 @@
(function(){
var hi;
hi = function() {
var hi;
hi = function() {
return [document.title, "Hello JavaScript"].join(": ");
};
})();
};

View File

@@ -1,7 +1,5 @@
(function(){
var solipsism, speed;
if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
solipsism = true;
}
speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140;
})();
var solipsism;
if ((typeof mind != "undefined" && mind !== null) && !(typeof world != "undefined" && world !== null)) {
solipsism = true;
}
typeof speed != "undefined" && speed !== null ? speed : speed = 140;

View File

@@ -1,13 +1,15 @@
(function(){
var eldest, grade;
grade = function grade(student) {
if (student.excellent_work) {
return "A+";
} else if (student.okay_stuff) {
return student.tried_hard ? "B" : "B-";
var eldest, grade;
grade = function(student) {
if (student.excellentWork) {
return "A+";
} else if (student.okayStuff) {
if (student.triedHard) {
return "B";
} else {
return "C";
return "B-";
}
};
eldest = 24 > 21 ? "Liz" : "Ike";
})();
} else {
return "C";
}
};
eldest = 24 > 21 ? "Liz" : "Ike";

View File

@@ -1,4 +1,2 @@
(function(){
var one, six, three, two;
six = ((one = 1)) + ((two = 2)) + ((three = 3));
})();
var one, six, three, two;
six = (one = 1) + (two = 2) + (three = 3);

View File

@@ -1,12 +1,8 @@
(function(){
var _a, _b, globals, name;
var __hasProp = Object.prototype.hasOwnProperty;
// The first ten global properties.
globals = (function() {
_a = []; _b = window;
for (name in _b) { if (__hasProp.call(_b, name)) {
_a.push(name);
}}
return _a;
}).call(this).slice(0, 10);
})();
var globals, name, _results;
globals = (function() {
_results = [];
for (name in window) {
_results.push(name);
}
return _results;
}()).slice(0, 10);

View File

@@ -1,9 +1,7 @@
(function(){
alert((function() {
try {
return nonexistent / undefined;
} catch (error) {
return "And the error is ... " + error;
}
}).call(this));
})();
alert(function() {
try {
return nonexistent / void 0;
} catch (error) {
return "And the error is ... " + error;
}
}());

View File

@@ -1,15 +1,9 @@
(function(){
var Account;
Account = function Account(customer, cart) {
this.customer = customer;
this.cart = cart;
return $('.shopping_cart').bind('click', (function(__this) {
var __func = function(event) {
return this.customer.purchase(this.cart);
};
return (function() {
return __func.apply(__this, arguments);
});
})(this));
};
})();
var Account;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Account = function(customer, cart) {
this.customer = customer;
this.cart = cart;
return $('.shopping_cart').bind('click', __bind(function(event) {
return this.customer.purchase(this.cart);
}, this));
};

View File

@@ -1,9 +1,7 @@
(function(){
var cube, square;
square = function square(x) {
return x * x;
};
cube = function cube(x) {
return square(x) * x;
};
})();
var cube, square;
square = function(x) {
return x * x;
};
cube = function(x) {
return square(x) * x;
};

View File

@@ -1,4 +1,2 @@
(function(){
var html;
html = "<strong>\n cup of coffeescript\n</strong>";
})();
var html;
html = '<strong>\n cup of coffeescript\n</strong>';

View File

@@ -0,0 +1,2 @@
var OPERATOR;
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;

View File

@@ -0,0 +1,4 @@
var author, quote, sentence;
author = "Wittgenstein";
quote = "A picture is a fact. -- " + author;
sentence = "" + (22 / 7) + " is a decent approximation of π";

View File

@@ -1,7 +0,0 @@
(function(){
// CoffeeScript on the left, JS on the right.
var square = function(x) {
return x * x;
};
})();

View File

@@ -1,11 +1,5 @@
(function(){
var _a, city, forecast, temp, weather_report;
weather_report = function weather_report(location) {
// Make an Ajax request to fetch the weather...
return [location, 72, "Mostly Sunny"];
};
_a = weather_report("Berkeley, CA");
city = _a[0];
temp = _a[1];
forecast = _a[2];
})();
var city, forecast, temp, weatherReport, _ref;
weatherReport = function(location) {
return [location, 72, "Mostly Sunny"];
};
_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];

View File

@@ -1,17 +1,14 @@
(function(){
var _a, _b, age, ages, child, years_old;
var __hasProp = Object.prototype.hasOwnProperty;
years_old = {
max: 10,
ida: 9,
tim: 11
};
ages = (function() {
_a = []; _b = years_old;
for (child in _b) { if (__hasProp.call(_b, child)) {
age = _b[child];
_a.push(child + " is " + age);
}}
return _a;
}).call(this);
})();
var age, ages, child, yearsOld, _results;
yearsOld = {
max: 10,
ida: 9,
tim: 11
};
ages = function() {
_results = [];
for (child in yearsOld) {
age = yearsOld[child];
_results.push(child + " is " + age);
}
return _results;
}();

View File

@@ -1,17 +1,10 @@
(function(){
var _a, _b, _c, city, futurists, poet, street;
futurists = {
sculptor: "Umberto Boccioni",
painter: "Vladimir Burliuk",
poet: {
name: "F.T. Marinetti",
address: ["Via Roma 42R", "Bellagio, Italy 22021"]
}
};
_a = futurists;
_b = _a.poet;
poet = _b.name;
_c = _b.address;
street = _c[0];
city = _c[1];
})();
var city, futurists, name, street, _ref, _ref2;
futurists = {
sculptor: "Umberto Boccioni",
painter: "Vladimir Burliuk",
poet: {
name: "F.T. Marinetti",
address: ["Via Roma 42R", "Bellagio, Italy 22021"]
}
};
_ref = futurists.poet, name = _ref.name, _ref2 = _ref.address, street = _ref2[0], city = _ref2[1];

View File

@@ -1,10 +1,17 @@
(function(){
var ages, matrix, song;
song = ["do", "re", "mi", "fa", "so"];
ages = {
max: 10,
ida: 9,
tim: 11
};
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
})();
var kids, matrix, singers, song;
song = ["do", "re", "mi", "fa", "so"];
singers = {
Jagger: "Rock",
Elvis: "Roll"
};
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
kids = {
brother: {
name: "Max",
age: 11
},
sister: {
name: "Ida",
age: 9
}
};

View File

@@ -0,0 +1,4 @@
$('.account').attr({
"class": 'active'
});
log(object["class"]);

View File

@@ -1,43 +1,34 @@
(function(){
var _a, _b, _c, _d, cubed_list, list, math, num, number, opposite_day, race, square;
// Assignment:
number = 42;
opposite_day = true;
// Conditions:
if (opposite_day) {
number = -42;
var cubes, list, math, num, number, opposite, race, square, _i, _len, _results;
var __slice = Array.prototype.slice;
number = 42;
opposite = true;
if (opposite) {
number = -42;
}
square = function(x) {
return x * x;
};
list = [1, 2, 3, 4, 5];
math = {
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
}
// Functions:
square = function square(x) {
return x * x;
};
// Arrays:
list = [1, 2, 3, 4, 5];
// Objects:
math = {
root: Math.sqrt,
square: square,
cube: function cube(x) {
return x * square(x);
}
};
// Splats:
race = function race(winner) {
var runners;
runners = Array.prototype.slice.call(arguments, 1);
return print(winner, runners);
};
// Existence:
if ((typeof elvis !== "undefined" && elvis !== null)) {
alert("I knew it!");
};
race = function() {
var runners, winner;
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return print(winner, runners);
};
if (typeof elvis != "undefined" && elvis !== null) {
alert("I knew it!");
}
cubes = (function() {
_results = [];
for (_i = 0, _len = list.length; _i < _len; _i++) {
num = list[_i];
_results.push(math.cube(num));
}
// Array comprehensions:
cubed_list = (function() {
_a = []; _b = list;
for (_c = 0, _d = _b.length; _c < _d; _c++) {
num = _b[_c];
_a.push(math.cube(num));
}
return _a;
}).call(this);
})();
return _results;
}());

View File

@@ -1,8 +1,4 @@
(function(){
var _a, and_switch, bait;
bait = 1000;
and_switch = 0;
_a = [and_switch, bait];
bait = _a[0];
and_switch = _a[1];
})();
var theBait, theSwitch, _ref;
theBait = 1000;
theSwitch = 0;
_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];

View File

@@ -0,0 +1,4 @@
var close, contents, open, tag, _i, _ref;
var __slice = Array.prototype.slice;
tag = "<impossible>";
_ref = tag.split(""), open = _ref[0], contents = 3 <= _ref.length ? __slice.call(_ref, 1, _i = _ref.length - 1) : (_i = 1, []), close = _ref[_i++];

View File

@@ -1,5 +1,3 @@
(function(){
String.prototype.dasherize = function dasherize() {
return this.replace(/_/g, "-");
};
})();
String.prototype.dasherize = function() {
return this.replace(/_/g, "-");
};

View File

@@ -1,8 +0,0 @@
(function(){
// Comments start with hash marks. Periods mark the end of a block.
var left_hand = raining ? umbrella : parasol;
// To signal the beginning of the next expression,
// use "then", or a newline.
left_hand = raining ? umbrella : parasol;
})();

View File

@@ -1,21 +1,8 @@
(function(){
var _a, _b, _c, _d, _e, countdown, egg_delivery, num;
countdown = (function() {
_a = []; _d = 10; _e = 1;
for (_c = 0, num = _d; (_d <= _e ? num <= _e : num >= _e); (_d <= _e ? num += 1 : num -= 1), _c++) {
_a.push(num);
}
return _a;
}).call(this);
egg_delivery = function egg_delivery() {
var _f, _g, _h, _i, _j, dozen_eggs, i;
_f = []; _i = 0; _j = eggs.length;
for (_h = 0, i = _i; (_i <= _j ? i < _j : i > _j); (_i <= _j ? i += 12 : i -= 12), _h++) {
_f.push((function() {
dozen_eggs = eggs.slice(i, i + 12);
return deliver(new egg_carton(dozen));
}).call(this));
}
return _f;
};
})();
var countdown, num, _results;
countdown = (function() {
_results = [];
for (num = 10; num >= 1; num--) {
_results.push(num);
}
return _results;
}());

View File

@@ -1,10 +1,8 @@
(function(){
var change_numbers, new_num, num;
num = 1;
change_numbers = function change_numbers() {
var new_num;
new_num = -1;
return num = 10;
};
new_num = change_numbers();
})();
var changeNumbers, inner, outer;
outer = 1;
changeNumbers = function() {
var inner;
inner = -1;
return outer = 10;
};
inner = changeNumbers();

View File

@@ -1,6 +1,4 @@
(function(){
var numbers, numbers_copy, three_to_six;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
three_to_six = numbers.slice(3, 6 + 1);
numbers_copy = numbers.slice(0, numbers.length);
})();
var copy, middle, numbers;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
copy = numbers.slice(0, numbers.length);
middle = copy.slice(3, 6 + 1);

View File

@@ -1,4 +1,2 @@
(function(){
var _a;
(_a = lottery.draw_winner()) == undefined ? undefined : _a.address == undefined ? undefined : _a.address.zipcode;
})();
var zip, _ref;
zip = typeof lottery.drawWinner === "function" ? (_ref = lottery.drawWinner().address) != null ? _ref.zipcode : void 0 : void 0;

View File

@@ -1,16 +1,15 @@
(function(){
var award_medals, contenders, gold, silver, the_field;
gold = (silver = (the_field = "unknown"));
award_medals = function award_medals(first, second) {
var rest;
rest = Array.prototype.slice.call(arguments, 2);
gold = first;
silver = second;
return the_field = rest;
};
contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
award_medals.apply(this, contenders);
alert("Gold: " + gold);
alert("Silver: " + silver);
alert("The Field: " + the_field);
})();
var awardMedals, contenders, gold, rest, silver;
var __slice = Array.prototype.slice;
gold = silver = rest = "unknown";
awardMedals = function() {
var first, others, second;
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
gold = first;
silver = second;
return rest = others;
};
contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
awardMedals.apply(null, contenders);
alert("Gold: " + gold);
alert("Silver: " + silver);
alert("The Field: " + rest);

View File

@@ -1,5 +1,3 @@
(function(){
var numbers;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6]));
})();
var numbers;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
[].splice.apply(numbers, [3, 4].concat([-3, -4, -5, -6]));

Some files were not shown because too many files have changed in this diff Show More