--- /dev/null
+../../css
\ No newline at end of file
--- /dev/null
+../../img
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Kiwi IRC</title><link rel="stylesheet" type="text/css" href="css/default.css"/><link rel="stylesheet" type="text/css" href="css/ui.css"/><script src="http://192.168.1.127:7777/socket.io/socket.io.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script><script type="text/javascript" src="js/jquery.json-2.2.min.js"></script><script type="text/javascript" src="js/util.js"></script><script type="text/javascript" src="js/gateway.js"></script><script type="text/javascript" src="js/front.js"></script><script type="text/javascript" src="js/iscroll.js"></script><script type="text/javascript">var agent = 'normal';
+var touchscreen = false;
+var init_data = {};
+var kiwi_server = 'http://192.168.1.127:7777/';
+var touch_scroll;
+
+$(document).ready(function(){
+ manageDebug(false);
+
+ //#channel,##channel,&channel
+ var chans = document.location.hash.match(/[#&]+[^ ,\007]+/g);
+ if(chans != null && chans.length > 0) {
+ init_data.channel = chans.join(',');
+ $('#channel').val(init_data.channel);
+ }
+
+ front.init();
+ gateway.start(kiwi_server);
+
+ addEvents();
+ $('.nick').focus();
+});
+
+
+function addEvents(){
+ $('.more_link').click(function(){ $('.content.bottom').slideDown('fast'); $('.network').focus(); return false; });
+ $('.formconnectwindow').submit(function(){
+ init_data.channel = $('#channel').val();
+ return false;
+ });
+ $('a.connect').click(function(){ $('.formconnectwindow').submit(); return false; });
+}
+
+
+</script><script id="tmpl_about_box" type="text/x-jquery-tmpl"> <h2>Kiwi IRC</h2>
+ <p>An alternative to downloading an irc client. Kiwi IRC is the best web app you'll use for the next couple years.</p>
+ <button class="about_close">Close</button>
+ <p class="info">${about}</p>
+ <p class="revisions">Front: ${front_revision}<br />Gateway: ${gateway_revision}</p>
+</script><script id="tmpl_change_nick" type="text/x-jquery-tmpl"> <div class="newnick box">
+ Your new nick:<br />
+ <form class="form_newnick">
+ <input type="text" class="txtnewnick" /><br />
+ <button class="butnewnick" type="submit">Change</button> <a class="link cancelnewnick">Cancel</a>
+ </form>
+ </div>
+</script><script id="tmpl_plugins" type="text/x-jquery-tmpl"> <div class="list">
+ <h2>Kiwi plugins</h2>
+ <p>
+ <select multiple="multiple" id="plugin_list">
+ </select>
+ <button id="plugins_list_unload">Unload</button>
+ </p>
+ </div>
+ <div class="load">
+ Plugin file URL:<br />
+ <form>
+ <input type="text" class="txtpluginfile" /><br />
+ <button class="butnewnick" type="submit">Load..</button> <a class="link cancelpluginfile">Cancel</a>
+ </form>
+ </div>
+</script><script id="tmpl_user_box" type="text/x-jquery-tmpl"> <div class="userbox">
+ <input type="hidden" class="userbox_nick" value="${nick}" />
+ <a href="#" class="userbox_query">Message</a>
+ <a href="#" class="userbox_whois">Info</a>
+ </div>
+</script></head><body><div id="kiwi"><div class="connectwindow"><h1 class="logo">Kiwi IRC</h1><div id="login"><form class="formconnectwindow"><div class="content top"><ul><li><label for="nick">Your nickname:</label><input type="text" id="nick" name="nick" placeholder="Your nick.." class="nick"/></li></ul><a href="" class="connect">Connect...</a></div><div style="" class="more"><a href="" class="more_link">more</a><div class="content bottom"><ul><li><label for="network">Server:</label><input type="text" id="network" name="network" value="irc.anonnet.org" class="network"/></li><li><label for="channel">Channel:</label><input type="text" id="channel" name="channel" value="#kiwiirc" class="channel"/></li></ul><a href="" class="connect">Connect...</a></div></div></form></div></div><div class="windowlist"><div class="poweredby">Powered by Kiwi IRC</div><ul></ul></div><div class="cur_topic"></div><div class="userlist"><ul></ul></div><div id="windows" class="windows"><div style="width:100%" class="scroller"></div></div><div class="control"><div class="msginput"><div class="nick"><a href="#"></a>:
+</div><input type="text" name="kiwi_msginput" id="kiwi_msginput"/></div><div class="plugins"><ul><li><a class="load_plugin_file">Plugins</a></li></ul></div></div></div></body></html>
\ No newline at end of file
--- /dev/null
+!!! transitional
+html(xmlns="http://www.w3.org/1999/xhtml")
+ head
+
+ meta(http-equiv="Content-Type", content="text/html; charset=utf-8")
+ - if ((agent === 'android') || (agent === 'iphone') || (agent === 'ipad') || (agent === 'ipod'))
+ meta(name="viewport", content="width=device-width,user-scalable=no")
+
+ title Kiwi IRC
+ link(rel="stylesheet", type="text/css", href="css/default.css")
+ link(rel="stylesheet", type="text/css", href="css/ui.css")
+
+ - if (touchscreen)
+ link(rel="stylesheet", type="text/css", href="css/touchscreen_tweaks.css")
+
+ script(src="http://192.168.1.127:7777/socket.io/socket.io.js")
+ script(type="text/javascript", src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js")
+ script(type="text/javascript", src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js")
+ script(type="text/javascript", src="js/jquery.json-2.2.min.js")
+ script(type="text/javascript", src="js/util.js")
+ script(type="text/javascript", src="js/gateway.js")
+ script(type="text/javascript", src="js/front.js")
+ script(type="text/javascript", src="js/iscroll.js")
+
+ - if (touchscreen)
+ script(type="text/javascript", src="js/touchscreen_tweaks.js")
+
+ - var proto
+ - if (config.listen_ssl)
+ - proto = 'https'
+ - else
+ - proto = 'http'
+ script(type="text/javascript")
+ var agent = '#{agent}';
+ var touchscreen = #{touchscreen};
+ var init_data = {};
+ var kiwi_server = '#{proto}://192.168.1.127:7777/';
+ var touch_scroll;
+
+ $(document).ready(function(){
+ manageDebug(false);
+
+ //#channel,##channel,&channel
+ var chans = document.location.hash.match(/[#&]+[^ ,\\007]+/g);
+ if(chans != null && chans.length > 0) {
+ init_data.channel = chans.join(',');
+ $('#channel').val(init_data.channel);
+ }
+
+ front.init();
+ gateway.start(kiwi_server);
+
+ addEvents();
+ $('.nick').focus();
+ });
+
+
+ function addEvents(){
+ $('.more_link').click(function(){ $('.content.bottom').slideDown('fast'); $('.network').focus(); return false; });
+ $('.formconnectwindow').submit(function(){
+ init_data.channel = $('#channel').val();
+ return false;
+ });
+ $('a.connect').click(function(){ $('.formconnectwindow').submit(); return false; });
+ }
+
+
+ script#tmpl_about_box(type="text/x-jquery-tmpl")
+ | <h2>Kiwi IRC</h2>
+ | <p>An alternative to downloading an irc client. Kiwi IRC is the best web app you'll use for the next couple years.</p>
+ | <button class="about_close">Close</button>
+ | <p class="info">${about}</p>
+ | <p class="revisions">Front: ${front_revision}<br />Gateway: ${gateway_revision}</p>
+
+ script#tmpl_change_nick(type="text/x-jquery-tmpl")
+ | <div class="newnick box">
+ | Your new nick:<br />
+ | <form class="form_newnick">
+ | <input type="text" class="txtnewnick" /><br />
+ | <button class="butnewnick" type="submit">Change</button> <a class="link cancelnewnick">Cancel</a>
+ | </form>
+ | </div>
+
+
+ script#tmpl_plugins(type="text/x-jquery-tmpl")
+ | <div class="list">
+ | <h2>Kiwi plugins</h2>
+ | <p>
+ | <select multiple="multiple" id="plugin_list">
+ | </select>
+ | <button id="plugins_list_unload">Unload</button>
+ | </p>
+ | </div>
+ | <div class="load">
+ | Plugin file URL:<br />
+ | <form>
+ | <input type="text" class="txtpluginfile" /><br />
+ | <button class="butnewnick" type="submit">Load..</button> <a class="link cancelpluginfile">Cancel</a>
+ | </form>
+ | </div>
+
+ script#tmpl_user_box(type="text/x-jquery-tmpl")
+ | <div class="userbox">
+ | <input type="hidden" class="userbox_nick" value="${nick}" />
+ | <a href="#" class="userbox_query">Message</a>
+ | <a href="#" class="userbox_whois">Info</a>
+ | </div>
+
+ body
+
+ div#kiwi
+ div.connectwindow
+ h1.logo Kiwi IRC
+ div#login
+ form.formconnectwindow
+ div.content.top
+ ul
+ li
+ label(for="nick") Your nickname:
+ input(type="text", id="nick", name="nick", class="nick", placeholder="Your nick..")
+ a.connect(href="") Connect...
+
+ - var display
+ - if (server_set)
+ - display = 'display:none'
+ - else
+ - display = '';
+ div.more(style=display)
+ a(href="", class="more_link") more
+ div.content.bottom
+ ul
+ li
+ label(for="network") Server:
+ input(type="text", id="network", name="network", class="network", value=server)
+ li
+ label(for="channel") Channel:
+ input(type="text", id="channel", name="channel", class="channel", value="#kiwiirc")
+ a.connect(href="") Connect...
+
+
+
+ div.windowlist
+ div.poweredby Powered by Kiwi IRC
+ ul
+
+ div.cur_topic
+
+ div.userlist
+ ul
+
+ div#windows.windows
+ div.scroller(style="width:100%")
+
+ div.control
+ div.msginput
+ div.nick
+ a(href="#")
+ | :
+ input(type="text", name="kiwi_msginput", id="kiwi_msginput")
+ div.plugins
+ ul
+ li
+ a.load_plugin_file Plugins
+ - if (debug)
+ li
+ a.reload_css Reload CSS
--- /dev/null
+../../js/
\ No newline at end of file
--- /dev/null
+.DS_Store
+lib-cov
+testing
+node_modules
--- /dev/null
+[submodule "support/expresso"]
+ path = support/expresso
+ url = git://github.com/visionmedia/expresso.git
+[submodule "support/sass"]
+ path = support/sass
+ url = git://github.com/visionmedia/sass.js.git
+[submodule "benchmarks/haml-js"]
+ path = benchmarks/haml-js
+ url = git://github.com/creationix/haml-js.git
+[submodule "benchmarks/ejs"]
+ path = benchmarks/ejs
+ url = git://github.com/visionmedia/ejs.git
+[submodule "benchmarks/haml"]
+ path = benchmarks/haml
+ url = git://github.com/visionmedia/haml.js.git
+[submodule "support/coffee-script"]
+ path = support/coffee-script
+ url = http://github.com/jashkenas/coffee-script.git
+[submodule "support/stylus"]
+ path = support/stylus
+ url = git://github.com/LearnBoost/stylus.git
--- /dev/null
+test
+support
+benchmarks
+examples
--- /dev/null
+
+0.13.0 / 2011-07-13
+==================
+
+ * Added `mixin` support
+ * Added `include` support
+ * Added array support for the class attribute
+
+0.12.4 / 2011-06-23
+==================
+
+ * Fixed filter indentation bug. Closes #243
+
+0.12.3 / 2011-06-21
+==================
+
+ * Fixed empty strings support. Closes #223
+ * Fixed conditional comments documentation. Closes #245
+
+0.12.2 / 2011-06-16
+==================
+
+ * Fixed `make test`
+ * Fixed block comments
+
+0.12.1 / 2011-06-04
+==================
+
+ * Fixed attribute interpolation with double quotes. Fixes #232 [topaxi]
+
+0.12.0 / 2011-06-03
+==================
+
+ * Added `doctype` as alias of `!!!`
+ * Added; doctype value is now case-insensitive
+ * Added attribute interpolation support
+ * Fixed; retain original indentation spaces in text blocks
+
+0.11.1 / 2011-06-01
+==================
+
+ * Fixed text block indentation [Laszlo Bacsi]
+ * Changed; utilizing devDependencies
+ * Fixed try/catch issue with renderFile(). Closes #227
+ * Removed attribute ":" support, use "=" (option for ':' coming soon)
+
+0.11.0 / 2011-05-14
+==================
+
+ * Added `self` object to avoid poor `with(){}` performance [masylum]
+ * Added `doctype` option [Jeremy Larkin]
+
+0.10.7 / 2011-05-04
+==================
+
+ * expose Parser
+
+0.10.6 / 2011-04-29
+==================
+
+ * Fixed CS `Object.keys()` [reported by robholland]
+
+0.10.5 / 2011-04-26
+==================
+
+ * Added error context after the lineno
+ * Added; indicate failing lineno with ">"
+ * Added `Object.keys()` for the client-side
+ * Fixed attr strings when containing the opposite quote. Closes 207
+ * Fixed attr issue with js expressions within strings
+ * Fixed single-quote filter escape bug. Closes #196
+
+
+0.10.4 / 2011-04-05
+==================
+
+ * Added `html` doctype, same as "5"
+ * Fixed `pre`, no longer text-only
+
+0.10.3 / 2011-03-30
+==================
+
+ * Fixed support for quoted attribute keys ex `rss("xmlns:atom"="atom")`
+
+0.10.2 / 2011-03-30
+==================
+
+ * Fixed pipeless text bug with missing outdent
+
+0.10.1 / 2011-03-28
+==================
+
+ * Fixed `support/compile.js` to exclude browser js in node
+ * Fixes for IE [Patrick Pfeiffer]
+
+0.10.0 / 2011-03-25
+==================
+
+ * Added AST-filter support back in the form of `<tag>[attrs]<:><block>`
+
+0.9.3 / 2011-03-24
+==================
+
+ * Added `Block#unshift(node)`
+ * Added `jade.js` for the client-side to the repo
+ * Added `jade.min.js` for the client-side to the repo
+ * Removed need for pipes in filters. Closes #185
+ Note that this _will_ break filters used to
+ manipulate the AST, until we have a different
+ syntax for doing so.
+
+0.9.2 / 2011-03-23
+==================
+
+ * Added jade `--version`
+ * Removed `${}` interpolation support, use `#{}`
+
+0.9.1 / 2011-03-16
+==================
+
+ * Fixed invalid `.map()` call due to recent changes
+
+0.9.0 / 2011-03-16
+==================
+
+ * Added client-side browser support via `make jade.js` and `make jade.min.js`.
+
+0.8.9 / 2011-03-15
+==================
+
+ * Fixed preservation of newlines in text blocks
+
+0.8.8 / 2011-03-14
+==================
+
+ * Fixed jade(1) stdio
+
+0.8.7 / 2011-03-14
+==================
+
+ * Added `mkdirs()` to jade(1)
+ * Added jade(1) stdio support
+ * Added new features to jade(1), `--watch`, recursive compilation etc [khingebjerg]
+ * Fixed pipe-less text newlines
+ * Removed jade(1) `--pipe` flag
+
+0.8.6 / 2011-03-11
+==================
+
+ * Fixed parenthesized expressions in attrs. Closes #170
+ * Changed; default interpolation values `== null` to ''. Closes #167
+
+0.8.5 / 2011-03-09
+==================
+
+ * Added pipe-less text support with immediate ".". Closes #157
+ * Fixed object support in attrs
+ * Fixed array support for attrs
+
+0.8.4 / 2011-03-08
+==================
+
+ * Fixed issue with expressions being evaluated several times. closes #162
+
+0.8.2 / 2011-03-07
+==================
+
+ * Added markdown, discount, and markdown-js support to `:markdown`. Closes #160
+ * Removed `:discount`
+
+0.8.1 / 2011-03-04
+==================
+
+ * Added `pre` pipe-less text support (and auto-escaping)
+
+0.8.0 / 2011-03-04
+==================
+
+ * Added block-expansion support. Closes #74
+ * Added support for multi-line attrs without commas. Closes #65
+
+0.7.1 / 2011-03-04
+==================
+
+ * Fixed `script()` etc pipe-less text with attrs
+
+0.7.0 / 2011-03-04
+==================
+
+ * Removed `:javascript` filter (it doesn't really do anything special, use `script` tags)
+ * Added pipe-less text support. Tags that only accept text nodes (`script`, `textarea`, etc) do not require `|`.
+ * Added `:text` filter for ad-hoc pipe-less
+ * Added flexible indentation. Tabs, arbitrary number of spaces etc
+ * Added conditional-comment support. Closes #146
+ * Added block comment support
+ * Added rss example
+ * Added `:stylus` filter
+ * Added `:discount` filter
+ * Fixed; auto-detect xml and do not self-close tags. Closes #147
+ * Fixed whitespace issue. Closes #118
+ * Fixed attrs. `,`, `=`, and `:` within attr value strings are valid Closes #133
+ * Fixed; only output "" when code == null. Ex: `span.name= user.name` when undefined or null will not output "undefined". Closes #130
+ * Fixed; throw on unexpected token instead of hanging
+
+0.6.3 / 2011-02-02
+==================
+
+ * Added `each` support for Array-like objects [guillermo]
+
+0.6.2 / 2011-02-02
+==================
+
+ * Added CSRF example, showing how you can transparently add inputs to a form
+ * Added link to vim-jade
+ * Fixed self-closing col support [guillermo]
+ * Fixed exception when getAttribute or removeAttribute run into removed attributes [Naitik Shah]
+
+0.6.0 / 2010-12-19
+==================
+
+ * Added unescaped interpolation variant `!{code}`. Closes #124
+ * Changed; escape interpolated code by default `#{code}`
+
+0.5.7 / 2010-12-08
+==================
+
+ * Fixed; hyphen in get `tag()`
+
+0.5.6 / 2010-11-24
+==================
+
+ * Added `exports.compile(str, options)`
+ * Renamed internal `_` to `__`, since `_()` is commonly used for translation
+
+0.5.5 / 2010-10-30
+==================
+
+ * Add _coffeescript_ filter [Michael Hampton]
+ * Added link to _slim_; a ruby implementation
+ * Fixed quoted attributes issue.
+
+ * Fixed attribute issue with over greedy regexp.
+ Previously "p(foo=(((('bar')))))= ((('baz')))"
+ would __fail__ for example since the regexp
+ would lookahead to far. Now we simply pair
+ the delimiters.
+
+0.5.4 / 2010-10-18
+==================
+
+ * Adding newline when using tag code when preceding text
+ * Assume newline in tag text when preceding text
+ * Changed; retain leading text whitespace
+ * Fixed code block support to prevent multiple buffer openings [Jake Luer]
+ * Fixed nested filter support
+
+0.5.3 / 2010-10-06
+==================
+
+ * Fixed bug when tags with code also have a block [reported by chrisirhc]
+
+0.5.2 / 2010-10-05
+==================
+
+ * Added; Text introduces newlines to mimic the grammar.
+ Whitespace handling is a little tricky with this sort of grammar.
+ Jade will now mimic the written grammar, meaning that text blocks
+ using the "|" margin character will introduce a literal newline,
+ where as immediate tag text (ex "a(href='#') Link") will not.
+
+ This may not be ideal, but it makes more sense than what Jade was
+ previously doing.
+
+ * Added `Tag#text` to disambiguate between immediate / block text
+ * Removed _pretty_ option (was kinda useless in the state it was in)
+ * Reverted ignoring of newlines. Closes #92.
+ * Fixed; `Parser#parse()` ignoring newlines
+
+0.5.1 / 2010-10-04
+==================
+
+ * Added many examples
+ * Added; compiler api is now public
+ * Added; filters can accept / manipulate the parse tree
+ * Added filter attribute support. Closes #79
+ * Added LL(*) capabilities
+ * Performance; wrapping code blocks in {} instead of `(function(){}).call(this)`
+ * Performance; Optimized attribute buffering
+ * Fixed trailing newlines in blocks
+
+0.5.0 / 2010-09-11
+==================
+
+ * __Major__ refactor. Logic now separated into lexer/parser/compiler for future extensibility.
+ * Added _pretty_ option
+ * Added parse tree output for _debug_ option
+ * Added new examples
+ * Removed _context_ option, use _scope_
+
+0.4.1 / 2010-09-09
+==================
+
+ * Added support for arbitrary indentation for single-line comments. Closes #71
+ * Only strip first space in text (ex '| foo' will buffer ' foo')
+
+0.4.0 / 2010-08-30
+==================
+
+ * Added tab naive support (tabs are converted to a single indent, aka two spaces). Closes #24
+ * Added unbuffered comment support. Closes #62
+ * Added hyphen support for tag names, ex: "fb:foo-bar"
+ * Fixed bug with single quotes in comments. Closes #61
+ * Fixed comment whitespace issue, previously padding. Closes #55
+
+0.3.0 / 2010-08-04
+==================
+
+ * Added single line comment support. Closes #25
+ * Removed CDATA from _:javascript_ filter. Closes #47
+ * Removed _sys_ local
+ * Fixed code following tag
+
+0.2.4 / 2010-08-02
+==================
+
+ * Added Buffer support to `render()`
+ * Fixed filter text block exception reporting
+ * Fixed tag exception reporting
+
+0.2.3 / 2010-07-27
+==================
+
+ * Fixed newlines before block
+ * Fixed; tag text allowing arbitrary trailing whitespace
+
+0.2.2 / 2010-07-16
+==================
+
+ * Added support for `jade.renderFile()` to utilize primed cache
+ * Added link to [textmate bundle](http://github.com/miksago/jade-tmbundle)
+ * Fixed filter issue with single quotes
+ * Fixed hyphenated attr bug
+ * Fixed interpolation single quotes. Closes #28
+ * Fixed issue with comma in attrs
+
+0.2.1 / 2010-07-09
+==================
+
+ * Added support for node-discount and markdown-js
+ depending on which is available.
+
+ * Added support for tags to have blocks _and_ text.
+ this kinda fucks with arbitrary whitespace unfortunately,
+ but also fixes trailing spaces after tags _with_ blocks.
+
+ * Caching generated functions. Closes #46
+
+0.2.0 / 2010-07-08
+==================
+
+ * Added `- each` support for readable iteration
+ * Added [markdown-js](http://github.com/evilstreak/markdown-js) support (no compilation required)
+ * Removed node-discount support
+
+0.1.0 / 2010-07-05
+==================
+
+ * Added `${}` support for interpolation. Closes #45
+ * Added support for quoted attr keys: `label("for": 'something')` is allowed (_although not required_) [Guillermo]
+ * Added `:less` filter [jakeluer]
+
+0.0.2 / 2010-07-03
+==================
+
+ * Added `context` as synonym for `scope` option [Guillermo]
+ * Fixed attr splitting: `div(style:"color: red")` is now allowed
+ * Fixed issue with `(` and `)` within attrs: `a(class: (a ? 'a' : 'b'))` is now allowed
+ * Fixed issue with leading / trailing spaces in attrs: `a( href="#" )` is now allowed [Guillermo]
+
--- /dev/null
+(The MIT License)
+
+Copyright (c) 2009-2010 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- /dev/null
+
+TESTS = test/*.js
+SRC = $(shell find lib -name "*.js" -type f)
+UGLIFY_FLAGS = --no-mangle
+
+test:
+ @./node_modules/.bin/expresso \
+ -I node_modules \
+ $(TESTS)
+
+benchmark:
+ @node benchmarks/jade.js \
+ && node benchmarks/jade-self.js \
+ && node benchmarks/haml.js \
+ && node benchmarks/haml2.js \
+ && node benchmarks/ejs.js
+
+jade.js: $(SRC)
+ @node support/compile.js $^
+
+jade.min.js: jade.js
+ @uglifyjs $(UGLIFY_FLAGS) $< > $@ \
+ && du jade.min.js \
+ && du jade.js
+
+clean:
+ rm -f jade.js
+ rm -f jade.min.js
+
+.PHONY: test benchmark clean
--- /dev/null
+
+# Jade - template engine
+
+ Jade is a high performance template engine heavily influenced by [Haml](http://haml-lang.com)
+ and implemented with JavaScript for [node](http://nodejs.org).
+
+## Features
+
+ - client-side support
+ - great readability
+ - flexible indentation
+ - block-expansion
+ - mixins
+ - static includes
+ - attribute interpolation
+ - code is escaped by default for security
+ - contextual error reporting at compile & run time
+ - executable for compiling jade templates via the command line
+ - html 5 mode (using the _!!! 5_ doctype)
+ - optional memory caching
+ - combine dynamic and static tag classes
+ - parse tree manipulation via _filters_
+ - supports [Express JS](http://expressjs.com) out of the box
+ - transparent iteration over objects, arrays, and even non-enumerables via `- each`
+ - block comments
+ - no tag prefix
+ - AST filters
+ - filters
+ - :sass must have [sass.js](http://github.com/visionmedia/sass.js) installed
+ - :less must have [less.js](http://github.com/cloudhead/less.js) installed
+ - :markdown must have [markdown-js](http://github.com/evilstreak/markdown-js) installed or [node-discount](http://github.com/visionmedia/node-discount)
+ - :cdata
+ - :coffeescript must have [coffee-script](http://jashkenas.github.com/coffee-script/) installed
+ - [Vim Syntax](https://github.com/digitaltoad/vim-jade)
+ - [TextMate Bundle](http://github.com/miksago/jade-tmbundle)
+ - [Screencasts](http://tjholowaychuk.com/post/1004255394/jade-screencast-template-engine-for-nodejs)
+ - [html2jade](https://github.com/donpark/html2jade) converter
+
+## Implementations
+
+ - [php](http://github.com/everzet/jade.php)
+ - [scala](http://scalate.fusesource.org/versions/snapshot/documentation/scaml-reference.html)
+ - [ruby](http://github.com/stonean/slim)
+
+## Installation
+
+via npm:
+
+ npm install jade
+
+## Browser Support
+
+ To compile jade to a single file compatible for client-side use simply execute:
+
+ $ make jade.js
+
+ Alternatively, if uglifyjs is installed via npm (`npm install uglify-js`) you may execute the following which will create both files.
+
+ $ make jade.min.js
+
+## Public API
+
+```javascript
+ var jade = require('jade');
+
+ // Render a string
+ jade.render('string of jade', { options: 'here' });
+
+ // Render a file
+ jade.renderFile('path/to/some.jade', { options: 'here' }, function(err, html){
+ // options are optional,
+ // the callback can be the second arg
+ });
+
+ // Compile a function
+ var fn = jade.compile('string of jade', options);
+ fn.call(scope, locals);
+```
+
+### Options
+
+ - `scope` Evaluation scope (`this`)
+ - `self` Use a `self` namespace to hold the locals. _false by default_
+ - `locals` Local variable object
+ - `filename` Used in exceptions, and required when using includes
+ - `debug` Outputs tokens and function body generated
+ - `compiler` Compiler to replace jade's default
+
+## Syntax
+
+### Line Endings
+
+**CRLF** and **CR** are converted to **LF** before parsing.
+
+### Tags
+
+A tag is simply a leading word:
+
+ html
+
+for example is converted to `<html></html>`
+
+tags can also have ids:
+
+ div#container
+
+which would render `<div id="container"></div>`
+
+how about some classes?
+
+ div.user-details
+
+renders `<div class="user-details"></div>`
+
+multiple classes? _and_ an id? sure:
+
+ div#foo.bar.baz
+
+renders `<div id="foo" class="bar baz"></div>`
+
+div div div sure is annoying, how about:
+
+ #foo
+ .bar
+
+which is syntactic sugar for what we have already been doing, and outputs:
+
+ `<div id="foo"></div><div class="bar"></div>`
+
+### Tag Text
+
+Simply place some content after the tag:
+
+ p wahoo!
+
+renders `<p>wahoo!</p>`.
+
+well cool, but how about large bodies of text:
+
+ p
+ | foo bar baz
+ | rawr rawr
+ | super cool
+ | go jade go
+
+renders `<p>foo bar baz rawr.....</p>`
+
+interpolation? yup! both types of text can utilize interpolation,
+if we passed `{ locals: { name: 'tj', email: 'tj@vision-media.ca' }}` to `render()`
+we can do the following:
+
+ #user #{name} <#{email}>
+
+outputs `<div id="user">tj <tj@vision-media.ca></div>`
+
+Actually want `#{}` for some reason? escape it!
+
+ p \#{something}
+
+now we have `<p>#{something}</p>`
+
+We can also utilize the unescaped variant `!{html}`, so the following
+will result in a literal script tag:
+
+ - var html = "<script></script>"
+ | !{html}
+
+Nested tags that also contain text can optionally use a text block:
+
+ label
+ | Username:
+ input(name='user[name]')
+
+or immediate tag text:
+
+ label Username:
+ input(name='user[name]')
+
+Tags that accept _only_ text such as `script`, `style`, and `textarea` do not
+need the leading `|` character, for example:
+
+ html
+ head
+ title Example
+ script
+ if (foo) {
+ bar();
+ } else {
+ baz();
+ }
+
+Once again as an alternative, we may use a leading '.' to indicate a text block, for example:
+
+ p.
+ foo asdf
+ asdf
+ asdfasdfaf
+ asdf
+ asd.
+
+outputs:
+
+ <p>foo asdf
+ asdf
+ asdfasdfaf
+ asdf
+ asd
+ .
+ </p>
+
+This however differs from a leading '.' followed by a space, which although is ignored by the Jade parser, tells Jade that this period is a literal:
+
+ p .
+
+outputs:
+
+ <p>.</p>
+
+### Comments
+
+Single line comments currently look the same as JavaScript comments,
+aka "//" and must be placed on their own line:
+
+ // just some paragraphs
+ p foo
+ p bar
+
+would output
+
+ <!-- just some paragraphs -->
+ <p>foo</p>
+ <p>bar</p>
+
+Jade also supports unbuffered comments, by simply adding a hyphen:
+
+ //- will not output within markup
+ p foo
+ p bar
+
+outputting
+
+ <p>foo</p>
+ <p>bar</p>
+
+### Block Comments
+
+ A block comment is legal as well:
+
+ body
+ //
+ #content
+ h1 Example
+
+outputting
+
+ <body>
+ <!--
+ <div id="content">
+ <h1>Example</h1>
+ </div>
+ -->
+ </body>
+
+Jade supports conditional-comments as well, for example:
+
+ body
+ //if IE
+ a(href='http://www.mozilla.com/en-US/firefox/') Get Firefox
+
+outputs:
+
+ <body>
+ <!--[if IE]>
+ <a href="http://www.mozilla.com/en-US/firefox/">Get Firefox</a>
+ <![endif]-->
+ </body>
+
+
+### Nesting
+
+ Jade supports nesting to define the tags in a natural way:
+
+ ul
+ li.first
+ a(href='#') foo
+ li
+ a(href='#') bar
+ li.last
+ a(href='#') baz
+
+### Block Expansion
+
+ Block expansion allows you to create terse single-line nested tags,
+ the following example is equivalent to the nesting example above.
+
+ ul
+ li.first: a(href='#') foo
+ li: a(href='#') bar
+ li.last: a(href='#') baz
+
+
+### Attributes
+
+Jade currently supports '(' and ')' as attribute delimiters.
+
+ a(href='/login', title='View login page') Login
+
+Boolean attributes are also supported:
+
+ input(type="checkbox", checked)
+
+Boolean attributes with code will only output the attribute when `true`:
+
+ input(type="checkbox", checked= someValue)
+
+Multiple lines work too:
+
+ input(type='checkbox',
+ name='agreement',
+ checked)
+
+Multiple lines without the comma work fine:
+
+ input(type='checkbox'
+ name='agreement'
+ checked)
+
+Funky whitespace? fine:
+
+
+ input(
+ type='checkbox'
+ name='agreement'
+ checked)
+
+Colons work:
+
+ rss(xmlns:atom="atom")
+
+Suppose we have the `user` local `{ id: 12, name: 'tobi' }`
+and we wish to create an anchor tag with `href` pointing to "/user/12"
+we could use regular javascript concatenation:
+
+ a(href='/user/' + user.id)= user.name
+
+or we could use jade's interpolation:
+
+ a(href='/user/#{user.id}')= user.name
+
+The `class` attribute is special-cased when an array is given,
+allowing you to pass an array such as `bodyClasses = ['user', 'authenticated']` directly:
+
+ body(class=bodyClasses)
+
+### Doctypes
+
+To add a doctype simply use `!!!`, or `doctype` followed by an optional value:
+
+ !!!
+
+Will output the _transitional_ doctype, however:
+
+ !!! 5
+
+or
+
+ !!! html
+
+or
+
+ doctype html
+
+doctypes are case-insensitive, so the following are equivalent:
+
+ doctype Basic
+ doctype basic
+
+Will output the _html 5_ doctype. Below are the doctypes
+defined by default, which can easily be extended:
+
+```javascript
+ var doctypes = exports.doctypes = {
+ '5': '<!DOCTYPE html>',
+ 'xml': '<?xml version="1.0" encoding="utf-8" ?>',
+ 'default': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
+ 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
+ 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
+ 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
+ '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
+ 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
+ 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
+ };
+```
+
+To alter the default simply change:
+
+```javascript
+ jade.doctypes.default = 'whatever you want';
+```
+
+## Filters
+
+Filters are prefixed with `:`, for example `:markdown` and
+pass the following block of text to an arbitrary function for processing. View the _features_
+at the top of this document for available filters.
+
+ body
+ :markdown
+ Woah! jade _and_ markdown, very **cool**
+ we can even link to [stuff](http://google.com)
+
+Renders:
+
+ <body><p>Woah! jade <em>and</em> markdown, very <strong>cool</strong> we can even link to <a href="http://google.com">stuff</a></p></body>
+
+Filters may also manipulate the parse tree. For example perhaps I want to
+bake conditionals right into jade, we could do so with a filter named _conditionals_. Typically filters work on text blocks, however by passing a regular block our filter can do anything it wants with the tags nested within it.
+
+ body
+ conditionals:
+ if role == 'admin'
+ p You are amazing
+ else
+ p Not so amazing
+
+Not that we no longer prefix with "-" for these code blocks. Examples of
+how to manipulate the parse tree can be found at _./examples/conditionals.js_ and _./examples/model.js_, basically we subclass and re-implement visitor methods as needed. There are several interesting use-cases for this functionality above what was shown above such as transparently aggregating / compressing assets to reduce the number of HTTP requests, transparent record error reporting, and more.
+
+## Code
+
+Jade currently supports three classifications of executable code. The first
+is prefixed by `-`, and is not buffered:
+
+ - var foo = 'bar';
+
+This can be used for conditionals, or iteration:
+
+ - for (var key in obj)
+ p= obj[key]
+
+Due to Jade's buffering techniques the following is valid as well:
+
+ - if (foo)
+ ul
+ li yay
+ li foo
+ li worked
+ - else
+ p oh no! didnt work
+
+Hell, even verbose iteration:
+
+ - if (items.length)
+ ul
+ - items.forEach(function(item){
+ li= item
+ - })
+
+Anything you want!
+
+Next up we have _escaped_ buffered code, which is used to
+buffer a return value, which is prefixed by `=`:
+
+ - var foo = 'bar'
+ = foo
+ h1= foo
+
+Which outputs `bar<h1>bar</h1>`. Code buffered by `=` is escaped
+by default for security, however to output unescaped return values
+you may use `!=`:
+
+ p!= aVarContainingMoreHTML
+
+The on exception made in terms of allowing "vanilla" JavaScript, is
+the `- each` token. This takes the form of:
+
+ - each VAL[, KEY] in OBJ
+
+An example iterating over an array:
+
+ - var items = ["one", "two", "three"]
+ - each item in items
+ li= item
+
+outputs:
+
+ <li>one</li>
+ <li>two</li>
+ <li>three</li>
+
+iterating an object's keys and values:
+
+ - var obj = { foo: 'bar' }
+ - each val, key in obj
+ li #{key}: #{val}
+
+would output `<li>foo: bar</li>`
+
+You can also nest these!
+
+ - each user in users
+ - each role in user.roles
+ li= role
+
+When a property is undefined, Jade will output an empty string. For example:
+
+ textarea= user.signature
+
+when undefined would normally output "undefined" in your html, however recent
+versions of Jade will simply render:
+
+ <textarea></textarea>
+
+## Includes
+
+ Includes allow you to statically include chunks of Jade
+ which lives in a separate file. The classical example is
+ including a header and footer. Suppose we have the following
+ directory structure:
+
+ ./layout.jade
+ ./includes/
+ ./head.jade
+ ./tail.jade
+
+and the following _layout.jade_:
+
+ html
+ include includes/head
+ body
+ h1 My Site
+ p Welcome to my super amazing site.
+ include includes/foot
+
+both includes _includes/head_ and _includes/foot_ are
+read relative to the `filename` option given to _layout.jade_,
+which should be an absolute path to this file, however Express
+and the `renderFile()` method do this for you. Include then parses
+these files, and injects the AST produced to render what you would expect:
+
+```html
+<html>
+ <head>
+ <title>My Site</title>
+ <script src="/javascripts/jquery.js">
+ </script><script src="/javascripts/app.js"></script>
+ </head>
+ <body>
+ <h1>My Site</h1>
+ <p>Welcome to my super lame site.</p>
+ <div id="footer">
+ <p>Copyright>(c) foobar</p>
+ </div>
+ </body>
+</html>
+```
+
+## Mixins
+
+ Mixins are converted to regular JavaScript functions in
+ the compiled template that Jade constructs. Mixins may
+ take arguments, though not required:
+
+ mixin list
+ ul
+ li foo
+ li bar
+ li baz
+
+ Utilizing a mixin without args looks similar, just without a block:
+
+ h2 Groceries
+ mixin list
+
+ Mixins may take one or more arguments as well, the arguments
+ are regular javascripts expressions, so for example the following:
+
+ mixin pets(pets)
+ ul.pets
+ - each pet in pets
+ li= pet
+
+ mixin profile(user)
+ .user
+ h2= user.name
+ mixin pets(user.pets)
+
+ Would yield something similar to the following html:
+
+```html
+<div class="user">
+ <h2>tj</h2>
+ <ul class="pets">
+ <li>tobi</li>
+ <li>loki</li>
+ <li>jane</li>
+ <li>manny</li>
+ </ul>
+</div>
+```
+
+## bin/jade
+
+Output html to _stdout_:
+
+ jade < my.jade > my.html
+
+Generate _examples/*.html_:
+
+ jade examples/*.jade
+
+Pass options:
+
+ jade examples/layout.jade --options '{ locals: { title: "foo" }}'
+
+Usage info:
+
+ Usage: jade [options]
+ [path ...]
+ < in.jade > out.jade
+ Options:
+ -o, --options <str> JavaScript options object passed
+ -h, --help Output help information
+ -w, --watch Watch file(s) or folder(s) for changes and re-compile
+ -v, --version Output jade version
+ --out <dir> Output the compiled html to <dir>
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2009-2010 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var sys = require('sys');
+
+var currentLabel,
+ startTime;
+
+exports.times = 2000;
+
+exports.start = function(label){
+ currentLabel = label;
+ startTime = new Date;
+ sys.print(' - \x1b[33m' + currentLabel + '\x1b[0m: ');
+};
+
+exports.stop = function(){
+ var stopTime = new Date,
+ duration = stopTime - startTime;
+ sys.print(duration + ' ms\n');
+};
+
+exports.locals = {
+ one: 'one',
+ two: 'two',
+ three: 'three',
+ items: Array(200).join('test ').split(' ')
+};
+
+console.log('\nbenchmarking %d times\n', exports.times);
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var bm = require('./common'),
+ ejs = require('./ejs/lib/ejs'),
+ fs = require('fs');
+
+var str = fs.readFileSync(__dirname + '/example.ejs', 'ascii');
+
+var n = bm.times;
+bm.start('ejs compilation');
+while (n--) {
+ ejs.render(str, { locals: bm.locals });
+}
+bm.stop();
+
+var n = bm.times;
+bm.start('ejs execution');
+while (n--) {
+ ejs.render(str, { locals: bm.locals, cache: true, filename: 'example.ejs' });
+}
+bm.stop();
\ No newline at end of file
--- /dev/null
+# ignore any vim files:
+*.sw[a-z]
+vim/.netrwhist
--- /dev/null
+[submodule "support/expresso"]
+ path = support/expresso
+ url = http://github.com/visionmedia/expresso.git
--- /dev/null
+
+0.3.1 / 2011-02-23
+==================
+
+ * Fixed optional `compile()` options
+
+0.3.0 / 2011-02-14
+==================
+
+ * Added 'json' filter [Yuriy Bogdanov]
+ * Use exported version of parse function to allow monkey-patching [Anatoliy Chakkaev]
+
+0.2.1 / 2010-10-07
+==================
+
+ * Added filter support
+ * Fixed _cache_ option. ~4x performance increase
+
+0.2.0 / 2010-08-05
+==================
+
+ * Added support for global tag config
+ * Added custom tag support. Closes #5
+ * Fixed whitespace bug. Closes #4
+
+0.1.0 / 2010-08-04
+==================
+
+ * Faster implementation [ashleydev]
+
+0.0.4 / 2010-08-02
+==================
+
+ * Fixed single quotes for content outside of template tags. [aniero]
+ * Changed; `exports.compile()` now expects only "locals"
+
+0.0.3 / 2010-07-15
+==================
+
+ * Fixed single quotes
+
+0.0.2 / 2010-07-09
+==================
+
+ * Fixed newline preservation
+
+0.0.1 / 2010-07-09
+==================
+
+ * Initial release
--- /dev/null
+
+test:
+ @./support/expresso/bin/expresso -I lib test/*.test.js
+
+.PHONY: test
\ No newline at end of file
--- /dev/null
+
+# EJS
+
+Embedded JavaScript templates.
+
+## Installation
+
+ $ npm install ejs
+
+## Features
+
+ * Complies with the [Express](http://expressjs.com) view system
+ * Static caching of intermediate JavaScript
+ * Unbuffered code for conditionals etc `<% code %>`
+ * Escapes html by default with `<%= code %>`
+ * Unescaped buffering with `<%- code %>`
+ * Supports tag customization
+ * Filter support for designer-friendly templates
+
+## Example
+
+ <% if (user) { %>
+ <h2><%= user.name %></h2>
+ <% } %>
+
+## Usage
+
+ ejs.compile(str, options);
+ // => Function
+
+ ejs.render(str, options);
+ // => str
+
+## Options
+
+ - `locals` Local variables object
+ - `cache` Compiled functions are cached, requires `filename`
+ - `filename` Used by `cache` to key caches
+ - `scope` Function execution context
+ - `debug` Output generated function body
+ - `open` Open tag, defaulting to "<%"
+ - `close` Closing tag, defaulting to "%>"
+
+## Custom Tags
+
+Custom tags can also be applied globally:
+
+ var ejs = require('ejs');
+ ejs.open = '{{';
+ ejs.close = '}}';
+
+Which would make the following a valid template:
+
+ <h1>{{= title }}</h1>
+
+## Filters
+
+EJS conditionally supports the concept of "filters". A "filter chain"
+is a designer friendly api for manipulating data, without writing JavaScript.
+
+Filters can be applied by supplying the _:_ modifier, so for example if we wish to take the array `[{ name: 'tj' }, { name: 'mape' }, { name: 'guillermo' }]` and output a list of names we can do this simply with filters:
+
+Template:
+
+ <p><%=: users | map:'name' | join %></p>
+
+Output:
+
+ <p>Tj, Mape, Guillermo</p>
+
+Render call:
+
+ ejs.render(str, {
+ locals: {
+ users: [
+ { name: 'tj' },
+ { name: 'mape' },
+ { name: 'guillermo' }
+ ]
+ }
+ });
+
+Or perhaps capitalize the first user's name for display:
+
+ <p><%=: users | first | capitalize %></p>
+
+## Filter List
+
+Currently these filters are available:
+
+ - first
+ - last
+ - capitalize
+ - downcase
+ - upcase
+ - sort
+ - sort_by:'prop'
+ - size
+ - length
+ - plus:n
+ - minus:n
+ - times:n
+ - divided_by:n
+ - join:'val'
+ - truncate:n
+ - truncate_words:n
+ - replace:pattern,substitution
+ - prepend:val
+ - append:val
+ - map:'prop'
+ - reverse
+ - get:'prop'
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2009-2010 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null
+
+
+var ejs = require('./lib/ejs'),
+ str = '<% if (foo) { %><p><%= foo %></p><% } %>',
+ times = 50000;
+
+console.log('rendering ' + times + ' times');
+
+var start = new Date;
+while (times--) {
+ ejs.render(str, { cache: true, filename: 'test', locals: { foo: 'bar' }});
+}
+
+console.log('took ' + (new Date - start) + 'ms');
\ No newline at end of file
--- /dev/null
+<% if (names.length) { %>
+ <ul>
+ <% names.forEach(function(name){ %>
+ <li><%= name %></li>
+ <% }) %>
+ </ul>
+<% } %>
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var ejs = require('../')
+ , fs = require('fs')
+ , str = fs.readFileSync(__dirname + '/list.ejs', 'utf8');
+
+var ret = ejs.render(str, {
+ locals: {
+ names: ['foo', 'bar', 'baz']
+ }
+});
+
+console.log(ret);
\ No newline at end of file
--- /dev/null
+
+module.exports = require('./lib/ejs');
\ No newline at end of file
--- /dev/null
+
+/*!
+ * EJS
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var sys = require('sys')
+ , utils = require('./utils');
+
+/**
+ * Library version.
+ */
+
+exports.version = '0.3.0';
+
+/**
+ * Filters.
+ *
+ * @type Object
+ */
+
+var filters = exports.filters = require('./filters');
+
+/**
+ * Intermediate js cache.
+ *
+ * @type Object
+ */
+
+var cache = {};
+
+/**
+ * Clear intermediate js cache.
+ *
+ * @api public
+ */
+
+exports.clearCache = function(){
+ cache = {};
+};
+
+/**
+ * Translate filtered code into function calls.
+ *
+ * @param {String} js
+ * @return {String}
+ * @api private
+ */
+
+function filtered(js) {
+ return js.substr(1).split('|').reduce(function(js, filter){
+ var parts = filter.split(':')
+ , name = parts.shift()
+ , args = parts.shift() || '';
+ if (args) args = ', ' + args;
+ return 'filters.' + name + '(' + js + args + ')';
+ });
+};
+
+/**
+ * Parse the given `str` of ejs, returning the function body.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api public
+ */
+
+var parse = exports.parse = function(str, options){
+ var options = options || {}
+ , open = options.open || exports.open || '<%'
+ , close = options.close || exports.close || '%>';
+
+ var buf = [
+ "var buf = [];"
+ , "\nwith (locals) {"
+ , "\n buf.push('"
+ ];
+
+ for (var i = 0, len = str.length; i < len; ++i) {
+ if (str.slice(i, open.length + i) == open) {
+ i += open.length
+
+ var prefix, postfix;
+ switch (str[i]) {
+ case '=':
+ prefix = "', escape(";
+ postfix = "), '";
+ ++i;
+ break;
+ case '-':
+ prefix = "', ";
+ postfix = ", '";
+ ++i;
+ break;
+ default:
+ prefix = "'); ";
+ postfix = "; buf.push('";
+ }
+
+ var start = i;
+ var end = str.indexOf(close, i);
+ var js = str.substring(i, end);
+ if (js[0] == ':') js = filtered(js);
+ buf.push(prefix, js, postfix);
+ i += end - start + close.length - 1;
+
+ } else if (str[i] == "\\") {
+ buf.push("\\\\");
+ } else if (str[i] == "'") {
+ buf.push("\\'");
+ } else if (str[i] == "\r") {
+ buf.push(" ");
+ } else if (str[i] == "\n") {
+ buf.push("\\n");
+ } else {
+ buf.push(str[i]);
+ }
+ }
+ buf.push("');\n}\nreturn buf.join('');");
+ return buf.join('');
+};
+
+/**
+ * Compile the given `str` of ejs into a `Function`.
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @return {Function}
+ * @api public
+ */
+
+var compile = exports.compile = function(str, options){
+ options = options || {};
+ if (options.debug) sys.puts(exports.parse(str));
+ var fn = new Function('locals, filters, escape', exports.parse(str, options));
+ return function(locals){
+ return fn.call(this, locals, filters, utils.escape);
+ }
+};
+
+/**
+ * Render the given `str` of ejs.
+ *
+ * Options:
+ *
+ * - `locals` Local variables object
+ * - `cache` Compiled functions are cached, requires `filename`
+ * - `filename` Used by `cache` to key caches
+ * - `scope` Function execution context
+ * - `debug` Output generated function body
+ * - `open` Open tag, defaulting to "<%"
+ * - `close` Closing tag, defaulting to "%>"
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @return {String}
+ * @api public
+ */
+
+exports.render = function(str, options){
+ var fn
+ , options = options || {};
+ if (options.cache) {
+ if (options.filename) {
+ fn = cache[options.filename] || (cache[options.filename] = compile(str, options));
+ } else {
+ throw new Error('"cache" option requires "filename".');
+ }
+ } else {
+ fn = compile(str, options);
+ }
+ return fn.call(options.scope, options.locals || {});
+};
+
+/**
+ * Expose to require().
+ */
+
+if (require.extensions) {
+ require.extensions['.ejs'] = function(module, filename) {
+ source = require('fs').readFileSync(filename, 'utf-8');
+ module._compile(compile(source, {}), filename);
+ };
+} else if (require.registerExtension) {
+ require.registerExtension('.ejs', function(src) {
+ return compile(src, {});
+ });
+}
--- /dev/null
+
+/*!
+ * EJS - Filters
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * First element of the target `obj`.
+ */
+
+exports.first = function(obj) {
+ return obj[0];
+};
+
+/**
+ * Last element of the target `obj`.
+ */
+
+exports.last = function(obj) {
+ return obj[obj.length - 1];
+};
+
+/**
+ * Capitalize the first letter of the target `str`.
+ */
+
+exports.capitalize = function(str){
+ str = String(str);
+ return str[0].toUpperCase() + str.substr(1, str.length);
+};
+
+/**
+ * Downcase the target `str`.
+ */
+
+exports.downcase = function(str){
+ return String(str).toLowerCase();
+};
+
+/**
+ * Uppercase the target `str`.
+ */
+
+exports.upcase = function(str){
+ return String(str).toUpperCase();
+};
+
+/**
+ * Sort the target `obj`.
+ */
+
+exports.sort = function(obj){
+ return Object.create(obj).sort();
+};
+
+/**
+ * Sort the target `obj` by the given `prop` ascending.
+ */
+
+exports.sort_by = function(obj, prop){
+ return Object.create(obj).sort(function(a, b){
+ a = a[prop], b = b[prop];
+ if (a > b) return 1;
+ if (a < b) return -1;
+ return 0;
+ });
+};
+
+/**
+ * Size or length of the target `obj`.
+ */
+
+exports.size = exports.length = function(obj) {
+ return obj.length;
+};
+
+/**
+ * Add `a` and `b`.
+ */
+
+exports.plus = function(a, b){
+ return Number(a) + Number(b);
+};
+
+/**
+ * Subtract `b` from `a`.
+ */
+
+exports.minus = function(a, b){
+ return Number(a) - Number(b);
+};
+
+/**
+ * Multiply `a` by `b`.
+ */
+
+exports.times = function(a, b){
+ return Number(a) * Number(b);
+};
+
+/**
+ * Divide `a` by `b`.
+ */
+
+exports.divided_by = function(a, b){
+ return Number(a) / Number(b);
+};
+
+/**
+ * Join `obj` with the given `str`.
+ */
+
+exports.join = function(obj, str){
+ return obj.join(str || ', ');
+};
+
+/**
+ * Truncate `str` to `len`.
+ */
+
+exports.truncate = function(str, len){
+ str = String(str);
+ return str.substr(0, len);
+};
+
+/**
+ * Truncate `str` to `n` words.
+ */
+
+exports.truncate_words = function(str, n){
+ var str = String(str)
+ , words = str.split(/ +/);
+ return words.slice(0, n).join(' ');
+};
+
+/**
+ * Replace `pattern` with `substitution` in `str`.
+ */
+
+exports.replace = function(str, pattern, substitution){
+ return String(str).replace(pattern, substitution || '');
+};
+
+/**
+ * Prepend `val` to `obj`.
+ */
+
+exports.prepend = function(obj, val){
+ return Array.isArray(obj)
+ ? [val].concat(obj)
+ : val + obj;
+};
+
+/**
+ * Append `val` to `obj`.
+ */
+
+exports.append = function(obj, val){
+ return Array.isArray(obj)
+ ? obj.concat(val)
+ : obj + val;
+};
+
+/**
+ * Map the given `prop`.
+ */
+
+exports.map = function(arr, prop){
+ return arr.map(function(obj){
+ return obj[prop];
+ });
+};
+
+/**
+ * Reverse the given `obj`.
+ */
+
+exports.reverse = function(obj){
+ return Array.isArray(obj)
+ ? obj.reverse()
+ : String(obj).split('').reverse().join('');
+};
+
+/**
+ * Get `prop` of the given `obj`.
+ */
+
+exports.get = function(obj, prop){
+ return obj[prop];
+};
+
+/**
+ * Packs the given `obj` into json string
+ */
+exports.json = function(obj){
+ return JSON.stringify(obj);
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * EJS
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Escape the given string of `html`.
+ *
+ * @param {String} html
+ * @return {String}
+ * @api private
+ */
+
+exports.escape = function(html){
+ return String(html)
+ .replace(/&(?!\w+;)/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"');
+};
+
\ No newline at end of file
--- /dev/null
+{
+ "name": "ejs",
+ "description": "Embedded JavaScript templates",
+ "version": "0.3.1",
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "keywords": ["template", "engine", "ejs"],
+ "main": "./lib/ejs.js"
+}
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var ejs = require('ejs');
+
+module.exports = {
+ 'test .version': function(assert){
+ assert.ok(/^\d+\.\d+\.\d+$/.test(ejs.version), 'Test .version format');
+ },
+
+ 'test html': function(assert){
+ assert.equal('<p>yay</p>', ejs.render('<p>yay</p>'));
+ },
+
+ 'test buffered code': function(assert){
+ var html = '<p>tj</p>',
+ str = '<p><%= name %></p>',
+ locals = { name: 'tj' };
+ assert.equal(html, ejs.render(str, { locals: locals }));
+ },
+
+ 'test unbuffered code': function(assert){
+ var html = '<p>tj</p>',
+ str = '<% if (name) { %><p><%= name %></p><% } %>',
+ locals = { name: 'tj' };
+ assert.equal(html, ejs.render(str, { locals: locals }));
+ },
+
+ 'test `scope` option': function(assert){
+ var html = '<p>tj</p>',
+ str = '<p><%= this %></p>';
+ assert.equal(html, ejs.render(str, { scope: 'tj' }));
+ },
+
+ 'test escaping': function(assert){
+ assert.equal('<script>', ejs.render('<%= "<script>" %>'));
+ assert.equal('<script>', ejs.render('<%- "<script>" %>'));
+ },
+
+ 'test newlines': function(assert){
+ var html = '\n<p>tj</p>\n<p>tj@sencha.com</p>',
+ str = '<% if (name) { %>\n<p><%= name %></p>\n<p><%= email %></p><% } %>',
+ locals = { name: 'tj', email: 'tj@sencha.com' };
+ assert.equal(html, ejs.render(str, { locals: locals }));
+ },
+
+ 'test single quotes': function(assert){
+ var html = '<p>WAHOO</p>',
+ str = "<p><%= up('wahoo') %></p>",
+ locals = { up: function(str){ return str.toUpperCase(); }};
+ assert.equal(html, ejs.render(str, { locals: locals }));
+ },
+
+ 'test single quotes in the html': function(assert){
+ var html = '<p>WAHOO that\'s cool</p>',
+ str = '<p><%= up(\'wahoo\') %> that\'s cool</p>',
+ locals = { up: function(str){ return str.toUpperCase(); }};
+ assert.equal(html, ejs.render(str, { locals: locals }));
+ },
+
+ 'test multiple single quotes': function(assert) {
+ var html = "<p>couldn't shouldn't can't</p>",
+ str = "<p>couldn't shouldn't can't</p>";
+ assert.equal(html, ejs.render(str));
+ },
+
+ 'test single quotes inside tags': function(assert) {
+ var html = '<p>string</p>',
+ str = "<p><%= 'string' %></p>";
+ assert.equal(html, ejs.render(str));
+ },
+
+ 'test back-slashes in the document': function(assert) {
+ var html = "<p>backslash: '\\'</p>",
+ str = "<p>backslash: '\\'</p>";
+ assert.equal(html, ejs.render(str));
+ },
+
+ 'test double quotes': function(assert){
+ var html = '<p>WAHOO</p>',
+ str = '<p><%= up("wahoo") %></p>',
+ locals = { up: function(str){ return str.toUpperCase(); }};
+ assert.equal(html, ejs.render(str, { locals: locals }));
+ },
+
+ 'test multiple double quotes': function(assert) {
+ var html = '<p>just a "test" wahoo</p>',
+ str = '<p>just a "test" wahoo</p>';
+ assert.equal(html, ejs.render(str));
+ },
+
+ 'test whitespace': function(assert){
+ var html = '<p>foo</p>',
+ str = '<p><%="foo"%></p>';
+ assert.equal(html, ejs.render(str));
+
+ var html = '<p>foo</p>',
+ str = '<p><%=bar%></p>';
+ assert.equal(html, ejs.render(str, { locals: { bar: 'foo' }}));
+ },
+
+ 'test custom tags': function(assert){
+ var html = '<p>foo</p>',
+ str = '<p>{{= "foo" }}</p>';
+
+ assert.equal(html, ejs.render(str, {
+ open: '{{',
+ close: '}}'
+ }));
+
+ var html = '<p>foo</p>',
+ str = '<p><?= "foo" ?></p>';
+
+ assert.equal(html, ejs.render(str, {
+ open: '<?',
+ close: '?>'
+ }));
+ },
+
+ 'test custom tags over 2 chars': function(assert){
+ var html = '<p>foo</p>',
+ str = '<p>{{{{= "foo" }>>}</p>';
+
+ assert.equal(html, ejs.render(str, {
+ open: '{{{{',
+ close: '}>>}'
+ }));
+
+ var html = '<p>foo</p>',
+ str = '<p><??= "foo" ??></p>';
+
+ assert.equal(html, ejs.render(str, {
+ open: '<??',
+ close: '??>'
+ }));
+ },
+
+ 'test global custom tags': function(assert){
+ var html = '<p>foo</p>',
+ str = '<p>{{= "foo" }}</p>';
+ ejs.open = '{{';
+ ejs.close = '}}';
+ assert.equal(html, ejs.render(str));
+ delete ejs.open;
+ delete ejs.close;
+ },
+
+ 'test iteration': function(assert){
+ var html = '<p>foo</p>',
+ str = '<% for (var key in items) { %>'
+ + '<p><%= items[key] %></p>'
+ + '<% } %>';
+ assert.equal(html, ejs.render(str, {
+ locals: {
+ items: ['foo']
+ }
+ }));
+
+ var html = '<p>foo</p>',
+ str = '<% items.forEach(function(item){ %>'
+ + '<p><%= item %></p>'
+ + '<% }) %>';
+ assert.equal(html, ejs.render(str, {
+ locals: {
+ items: ['foo']
+ }
+ }));
+ },
+
+ 'test filter support': function(assert){
+ var html = 'Zab',
+ str = '<%=: items | reverse | first | reverse | capitalize %>';
+ assert.equal(html, ejs.render(str, {
+ locals: {
+ items: ['foo', 'bar', 'baz']
+ }
+ }));
+ },
+
+ 'test filter argument support': function(assert){
+ var html = 'tj, guillermo',
+ str = '<%=: users | map:"name" | join:", " %>';
+ assert.equal(html, ejs.render(str, {
+ locals: {
+ users: [
+ { name: 'tj' },
+ { name: 'guillermo' }
+ ]
+ }
+ }));
+ },
+
+ 'test sort_by filter': function(assert){
+ var html = 'tj',
+ str = '<%=: users | sort_by:"name" | last | get:"name" %>';
+ assert.equal(html, ejs.render(str, {
+ locals: {
+ users: [
+ { name: 'guillermo' },
+ { name: 'tj' },
+ { name: 'mape' }
+ ]
+ }
+ }));
+ },
+
+ 'test custom filters': function(assert){
+ var html = 'Welcome Tj Holowaychuk',
+ str = '<%=: users | first | greeting %>';
+
+ ejs.filters.greeting = function(user){
+ return 'Welcome ' + user.first + ' ' + user.last + '';
+ };
+
+ assert.equal(html, ejs.render(str, {
+ locals: {
+ users: [
+ { first: 'Tj', last: 'Holowaychuk' }
+ ]
+ }
+ }));
+ }
+};
--- /dev/null
+ul
+ li!= self.one
+ li!= self.two
+ li!= self.three
+ - each item in self.items
+ li!= item
--- /dev/null
+<ul>
+ <li><%- one %></li>
+ <li><%- two %></li>
+ <li><%- three %></li>
+ <% items.forEach(function(item){ %>
+ <li><%- item %></li>
+ <% }) %>
+</ul>
\ No newline at end of file
--- /dev/null
+%ul
+ %li= one
+ %li= two
+ %li= three
+ :each item in items
+ %li= item
\ No newline at end of file
--- /dev/null
+ul
+ li!= one
+ li!= two
+ li!= three
+ - each item in items
+ li!= item
\ No newline at end of file
--- /dev/null
+%ul
+ %li!= one
+ %li!= two
+ %li!= three
+ - each item in items
+ %li!= item
\ No newline at end of file
--- /dev/null
+# HAML-JS Changelog
+
+- **v0.2.5** - *2010-05-06* - NPM support
+
+ Fixed to work with Node Package Manager
+
+- **v0.2.4** - *2010-04-16* - Bug fixes, XML support
+
+ Allow for commas in calls to helpers in attributes. Also make haml more XML friendly.
+
+- **v0.2.3** - *2010-04-10* - Bug fixes
+
+ Fixed an issue where "content" html attributes got munched. (This broke meta tags)
+
+- **v0.2.2** - *2010-04-05* - Bug fixes
+
+ Fixed two issues where the parser incorrectly parsed blank lines and extra spaces in attribute blocks.
+
+- **v0.2.1** - *2010-04-01* - Minor speed tweak
+
+ `Haml()` now caches the eval step so that there is no eval in executing a compiled template. This should make things a bit faster.
+
+- **v0.2.0** - *2010-03-31* - Function based API, Safe whitespace, Code interpolation.
+
+ At the request of some users, I've removed the new insertion into the generated html. This means that most html will be on one long line, but as an added advantage you won't have that extra whitespace next to your anchor labels messing up your visual display.
+
+ Also I added string interpolation to every place I could fit it. This means you can do crazy stuff like interpolate within strings in attributes, in the body on plain text sections, and of course in javascript and css plugin blocks.
+
+ In order to tame the API, I deprecated the four old interfaces `compile`, `optimize`, `execute` and `render`. The new API is that the Haml/exports object itself is now a function that takes in haml text and outputs a compiled, optimized, ready to execute function.
+
+- **0.1.2** - *2010-02-03* - Bug fixes, plugin aliases, CommonJS, and more...
+
+ This is a big release with many improvements. First haml-js is now a CommonJS module and is in the Tusk repository. Thanks to Tom Robinson for helping with that. Some of the plugins got aliases for people who didn't like the original name. For example, you can now do `:javascript` instead of `:script` and `:for` instead of `:each`. There were many bug fixes now that the code is starting to be actually used by myself and others.
+
+- **0.1.1** - *2010-01-09* - Add :css and :script plugins
+
+ Added two quick plugins that make working with javascript and css much easier.
+
+ - **0.1.0** - *2010-01-09* - Complete Rewrite
+
+ Rewrote the compiler to be recursive and compile to JavaScript code instead of JSON data structures. This fixes all the outstanding bugs and simplifies the code. Pending is restoring the `:script` and `:css` plugins.
+
+ - **0.0.1** - *2009-12-16* - Initial release
+
+ Change how haml is packaged. It is a pure JS function with no node dependencies. There is an exports hook for commonjs usability. It's now the responsibility of the script user to acquire the haml text.
+
+
--- /dev/null
+Copyright (c) 2009 Tim Caswell
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null
+# haml-js - Server side templating language for JavaScript
+
+Ever wanted to use the excellent HAML syntax on a javascript project? Me too, so I made one!. This has most of the same functionality as the traditional [haml][].
+
+## About the language
+
+Here is the first example(with a little extra added) from the [haml][] site converted to haml-js:
+
+**haml-js**
+
+ !!! XML
+ !!! strict
+ %html{ xmlns: "http://www.w3.org/1999/xhtml" }
+ %head
+ %title Sample haml template
+ %body
+ .profile
+ .left.column
+ #date= print_date()
+ #address= current_user.address
+ .right.column
+ #email= current_user.email
+ #bio= current_user.bio
+
+**html**
+
+ <?xml version='1.0' encoding='utf-8' ?>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Sample haml template
+ </title></head><body><div class="profile"><div class="left column"><div id="date">January 1, 2009
+ </div><div id="address">Richardson, TX
+ </div></div><div class="right column"><div id="email">tim@creationix.com
+ </div><div id="bio">Experienced software professional...
+ </div></div></div></body></html>
+
+Note that this works almost the same as ruby's [haml][], but doesn't pretty print the html. This would greatly slow down and complicate the code. If you really want pretty printed html, then I suggest writing one using the xml parser library and process the resulting html..
+
+## API
+
+### Haml(haml) -> template(locals) -> html
+
+This is the new (as of 0.2.0) way to generate haml templates. A haml template is a live function that takes in "this" context and a "locals" variable. This compile step takes a few milliseconds to complete so it should be done at startup and the resulting function should be cached. Then to use the template function you simply call it with the desired local variables and it will output html at blazing speeds (we're talking millions per second on my 13" MBP)
+
+Compile and store a template:
+
+ var main = Haml(main_haml);
+
+Then use it whenever you need a new version:
+
+ main({name: "Tim", age: 28});
+
+That's it. Haml templating made easy!
+
+If you want to store the generated javascript to a file to skip the compile step later on you can either decompile the template function or use the `compile` and `optimize` advanced functions directly.
+
+
+### Haml.compile(text) -> JavaScript compiled template
+
+Given a haml template as raw text, this compiles it to a javascript expression
+that can later be eval'ed to get the final HTML.
+
+The following input:
+
+ #home
+ = title
+ %ul.menu
+ %li Go Home
+ %li Go Back
+
+Produces the following JavaScript expression:
+
+ "<div id=\"home\">" +
+ title +
+ "\n" +
+ "<ul class=\"menu\">" +
+ "<li>" +
+ "Go Home\n" +
+ "</li>" +
+ "<li>" +
+ "Go Back\n" +
+ "</li>" +
+ "</ul>" +
+ "</div>"
+
+### Haml.optimize(js) -> optimized JavaScript expression
+
+Takes the output of compile and optimizes it to run faster with the tradeoff of longer compile time. This is useful for framework developers wanting to use haml in their framework and want to cache the compiled templates for performance.
+
+With the previous input it outputs:
+
+ "<div id=\"home\">" +
+ title +
+ "\n<ul class=\"menu\"><li>Go Home\n</li><li>Go Back\n</li></ul></div>"
+
+Notice how congruent static strings are merged into a single string literal when possible.
+
+### Haml.execute(js, context, locals) -> Executes a compiles template
+
+Context is the value of `this` in the template, and locals is a hash of local variables.
+
+### Haml.render(text, options) -> html text
+
+This is a convenience function that compiles and executes to html in one shot. Most casual users will want to use this function exclusively.
+
+The `text` parameter is the haml source already read from a file.
+
+The three recognized `options` are:
+
+ - **context**: This is the `this` context within the haml template.
+ - **locals**: This is an object that's used in the `with` scope. Basically it creates local variables and function accessible to the haml template.
+ - **optimize**: This is a flag to tell the compiler to use the extra optimizations.
+
+See [test.js][] for an example usage of Haml.render
+
+## Code interpolation
+
+New in version 0.2.0 there is string interpolation throughout. This means that the body of regular text areas can have embedded code. This is true for attributes and the contents of plugins like javascript and markdown also. If you notice an area that doesn't support interpolation and it should then send me a note and I'll add it.
+
+## Plugins
+
+There are plugins in the parser for things like inline script tags, css blocks, and support for if statements and for loops.
+
+### `:if` statements
+
+`if` statements evaluate a condition for truthiness (as opposed to a strict comparison to `true`) and includes the content inside the block if it's truthy.
+
+ :if todolist.length > 20
+ %p Oh my, you are a busy fellow!
+
+### `:each` loops
+
+`:each` loops allow you to loop over a collection including a block of content once for each item. You need to what variable to pull the data from and where to put the index and value. The index variable is optional and defaults to `__key__`.
+
+Here is an example over a simple array.
+
+ %ul.todolist
+ :each item in todolist
+ %li= item.description
+
+You can loop over the keys and values of objects too (Note the inner `:each` loop)
+
+ :each item in data
+ :if item.age < 100
+ %dl
+ :each name, value in item
+ %dt&= name
+ %dd&= value
+
+### `:css` and `:javascript` helpers.
+
+It's easy to embed javascript and css blocks in an haml document.
+
+ %head
+ :javascript
+ function greet(message) {
+ alert("Message from MCP: " + message);
+ }
+ %title Script and Css test
+ :css
+ body {
+ color: pink;
+ }
+ %body{ onload: "greet(\"I'm Pink\")" } COLOR ME PINK
+
+This compiles to the following HTML:
+
+ <head>
+ <script type="text/javascript">
+ //<![CDATA[
+ function greet(message) {
+ alert("Message from MCP: " + message);
+ }
+ //]]>
+ </script>
+ <title>Script and Css test
+ </title>
+ <style type="text/css">
+ body {
+ color: pink;
+ }
+ </style>
+ </head><body onload="greet("I'm Pink")"> COLOR ME PINK
+ </body>
+
+## Get Involved
+
+If you want to use this project and something is missing then send me a message. I'm very busy and have several open source projects I manage. I'll contribute to this project as I have time, but if there is more interest for some particular aspect, I'll work on it a lot faster. Also you're welcome to fork this project and send me patches/pull-requests.
+
+## About Performance
+
+The haml compiler isn't built for speed, it's built for maintainability. The actual generated templates, however are blazing fast. I benchmarked them with over 65 million renders per second on a small (20 line) template with some dynamic data on my laptop. Compare this to the 629 compiles per second I got out of the compiler. The idea is that you pre-compile your templates and reuse them on every request. While 629 per second is nothing compared to 65 million, that still means that your server with over 600 different views can boot up in about a second. I think that's fine for something that only happens every few weeks.
+
+## License
+
+Haml-js is [licensed][] under the [MIT license][].
+
+[MIT license]: http://creativecommons.org/licenses/MIT/
+[licensed]: http://github.com/creationix/haml-js/blob/master/LICENSE
+[jquery-haml]: http://github.com/creationix/jquery-haml
+[haml]: http://haml-lang.com/
+[test.js]: http://github.com/creationix/haml-js/blob/master/test/test.js
+
+
+
+
--- /dev/null
+var Haml;
+
+(function () {
+
+ var matchers, self_close_tags, embedder, forceXML;
+
+ function html_escape(text) {
+ return (text + "").
+ replace(/&/g, "&").
+ replace(/</g, "<").
+ replace(/>/g, ">").
+ replace(/\"/g, """);
+ }
+
+ function render_attribs(attribs) {
+ var key, value, result = [];
+ for (key in attribs) {
+ if (key !== '_content' && attribs.hasOwnProperty(key)) {
+ switch (attribs[key]) {
+ case 'undefined':
+ case 'false':
+ case 'null':
+ case '""':
+ break;
+ default:
+ try {
+ value = JSON.parse("[" + attribs[key] +"]")[0];
+ if (value === true) {
+ value = key;
+ } else if (typeof value === 'string' && embedder.test(value)) {
+ value = '" +\n' + parse_interpol(html_escape(value)) + ' +\n"';
+ } else {
+ value = html_escape(value);
+ }
+ result.push(" " + key + '=\\"' + value + '\\"');
+ } catch (e) {
+ result.push(" " + key + '=\\"" + html_escape(' + attribs[key] + ') + "\\"');
+ }
+ }
+ }
+ }
+ return result.join("");
+ }
+
+ // Parse the attribute block using a state machine
+ function parse_attribs(line) {
+ var attributes = {},
+ l = line.length,
+ i, c,
+ count = 1,
+ quote = false,
+ skip = false,
+ open, close, joiner, seperator,
+ pair = {
+ start: 1,
+ middle: null,
+ end: null
+ };
+
+ if (!(l > 0 && (line.charAt(0) === '{' || line.charAt(0) === '('))) {
+ return {
+ _content: line[0] === ' ' ? line.substr(1, l) : line
+ };
+ }
+ open = line.charAt(0);
+ close = (open === '{') ? '}' : ')';
+ joiner = (open === '{') ? ':' : '=';
+ seperator = (open === '{') ? ',' : ' ';
+
+ function process_pair() {
+ if (typeof pair.start === 'number' &&
+ typeof pair.middle === 'number' &&
+ typeof pair.end === 'number') {
+ var key = line.substr(pair.start, pair.middle - pair.start).trim(),
+ value = line.substr(pair.middle + 1, pair.end - pair.middle - 1).trim();
+ attributes[key] = value;
+ }
+ pair = {
+ start: null,
+ middle: null,
+ end: null
+ };
+ }
+
+ for (i = 1; count > 0; i += 1) {
+
+ // If we reach the end of the line, then there is a problem
+ if (i > l) {
+ throw "Malformed attribute block";
+ }
+
+ c = line.charAt(i);
+ if (skip) {
+ skip = false;
+ } else {
+ if (quote) {
+ if (c === '\\') {
+ skip = true;
+ }
+ if (c === quote) {
+ quote = false;
+ }
+ } else {
+ if (c === '"' || c === "'") {
+ quote = c;
+ }
+
+ if (count === 1) {
+ if (c === joiner) {
+ pair.middle = i;
+ }
+ if (c === seperator || c === close) {
+ pair.end = i;
+ process_pair();
+ if (c === seperator) {
+ pair.start = i + 1;
+ }
+ }
+ }
+
+ if (c === open || c === "(") {
+ count += 1;
+ }
+ if (c === close || (count > 1 && c === ")")) {
+ count -= 1;
+ }
+ }
+ }
+ }
+ attributes._content = line.substr(i, line.length);
+ return attributes;
+ }
+
+ // Split interpolated strings into an array of literals and code fragments.
+ function parse_interpol(value) {
+ var items = [],
+ pos = 0,
+ next = 0,
+ match;
+ while (true) {
+ // Match up to embedded string
+ next = value.substr(pos).search(embedder);
+ if (next < 0) {
+ if (pos < value.length) {
+ items.push(JSON.stringify(value.substr(pos)));
+ }
+ break;
+ }
+ items.push(JSON.stringify(value.substr(pos, next)));
+ pos += next;
+
+ // Match embedded string
+ match = value.substr(pos).match(embedder);
+ next = match[0].length;
+ if (next < 0) { break; }
+ items.push(match[1] || match[2]);
+ pos += next;
+ }
+ return items.filter(function (part) { return part && part.length > 0}).join(" +\n");
+ }
+
+ // Used to find embedded code in interpolated strings.
+ embedder = /\#\{([^}]*)\}/;
+
+ self_close_tags = ["meta", "img", "link", "br", "hr", "input", "area", "base"];
+
+ // All matchers' regexps should capture leading whitespace in first capture
+ // and trailing content in last capture
+ matchers = [
+ // html tags
+ {
+ regexp: /^(\s*)((?:[.#%][a-z_\-][a-z0-9_:\-]*)+)(.*)$/i,
+ process: function () {
+ var tag, classes, ids, attribs, content;
+ tag = this.matches[2];
+ classes = tag.match(/\.([a-z_\-][a-z0-9_\-]*)/gi);
+ ids = tag.match(/\#([a-z_\-][a-z0-9_\-]*)/gi);
+ tag = tag.match(/\%([a-z_\-][a-z0-9_:\-]*)/gi);
+
+ // Default to <div> tag
+ tag = tag ? tag[0].substr(1, tag[0].length) : 'div';
+
+ attribs = this.matches[3];
+ if (attribs) {
+ attribs = parse_attribs(attribs);
+ if (attribs._content) {
+ this.contents.unshift(attribs._content.trim());
+ delete(attribs._content);
+ }
+ } else {
+ attribs = {};
+ }
+
+ if (classes) {
+ classes = classes.map(function (klass) {
+ return klass.substr(1, klass.length);
+ }).join(' ');
+ if (attribs['class']) {
+ try {
+ attribs['class'] = JSON.stringify(classes + " " + JSON.parse(attribs['class']));
+ } catch (e) {
+ attribs['class'] = JSON.stringify(classes + " ") + " + " + attribs['class'];
+ }
+ } else {
+ attribs['class'] = JSON.stringify(classes);
+ }
+ }
+ if (ids) {
+ ids = ids.map(function (id) {
+ return id.substr(1, id.length);
+ }).join(' ');
+ if (attribs.id) {
+ attribs.id = JSON.stringify(ids + " ") + attribs.id;
+ } else {
+ attribs.id = JSON.stringify(ids);
+ }
+ }
+
+ attribs = render_attribs(attribs);
+
+ content = this.render_contents();
+ if (content === '""') {
+ content = '';
+ }
+
+ if (forceXML ? content.length > 0 : self_close_tags.indexOf(tag) == -1) {
+ return '"<' + tag + attribs + '>"' +
+ (content.length > 0 ? ' + \n' + content : "") +
+ ' + \n"</' + tag + '>"';
+ } else {
+ return '"<' + tag + attribs + ' />"';
+ }
+ }
+ },
+
+ // each loops
+ {
+ regexp: /^(\s*)(?::for|:each)\s+(?:([a-z_][a-z_\-]*),\s*)?([a-z_][a-z_\-]*)\s+in\s+(.*)(\s*)$/i,
+ process: function () {
+ var ivar = this.matches[2] || '__key__', // index
+ vvar = this.matches[3], // value
+ avar = this.matches[4], // array
+ rvar = '__result__'; // results
+
+ if (this.matches[5]) {
+ this.contents.unshift(this.matches[5]);
+ }
+ return '(function () { ' +
+ 'var ' + rvar + ' = [], ' + ivar + ', ' + vvar + '; ' +
+ 'for (' + ivar + ' in ' + avar + ') { ' +
+ 'if (' + avar + '.hasOwnProperty(' + ivar + ')) { ' +
+ vvar + ' = ' + avar + '[' + ivar + ']; ' +
+ rvar + '.push(\n' + (this.render_contents() || "''") + '\n); ' +
+ '} } return ' + rvar + '.join(""); }).call(this)';
+ }
+ },
+
+ // if statements
+ {
+ regexp: /^(\s*):if\s+(.*)\s*$/i,
+ process: function () {
+ var condition = this.matches[2];
+ return '(function () { ' +
+ 'if (' + condition + ') { ' +
+ 'return (\n' + (this.render_contents() || '') + '\n);' +
+ '} else { return ""; } }).call(this)';
+ }
+ },
+
+ // declarations
+ {
+ regexp: /^()!!!(?:\s*(.*))\s*$/,
+ process: function () {
+ var line = '';
+ switch ((this.matches[2] || '').toLowerCase()) {
+ case '':
+ // XHTML 1.0 Transitional
+ line = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
+ break;
+ case 'strict':
+ case '1.0':
+ // XHTML 1.0 Strict
+ line = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
+ break;
+ case 'frameset':
+ // XHTML 1.0 Frameset
+ line = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
+ break;
+ case '5':
+ // XHTML 5
+ line = '<!DOCTYPE html>';
+ break;
+ case '1.1':
+ // XHTML 1.1
+ line = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
+ break;
+ case 'basic':
+ // XHTML Basic 1.1
+ line = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">';
+ break;
+ case 'mobile':
+ // XHTML Mobile 1.2
+ line = '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">';
+ break;
+ case 'xml':
+ // XML
+ line = "<?xml version='1.0' encoding='utf-8' ?>";
+ break;
+ case 'xml iso-8859-1':
+ // XML iso-8859-1
+ line = "<?xml version='1.0' encoding='iso-8859-1' ?>";
+ break;
+ }
+ return JSON.stringify(line + "\n");
+ }
+ },
+
+ // Embedded markdown. Needs to be added to exports externally.
+ {
+ regexp: /^(\s*):markdown\s*$/i,
+ process: function () {
+ return parse_interpol(exports.Markdown.encode(this.contents.join("\n")));
+ }
+ },
+
+ // script blocks
+ {
+ regexp: /^(\s*):(?:java)?script\s*$/,
+ process: function () {
+ return parse_interpol('\n<script type="text/javascript">\n' +
+ '//<![CDATA[\n' +
+ this.contents.join("\n") +
+ "\n//]]>\n</script>\n");
+ }
+ },
+
+ // css blocks
+ {
+ regexp: /^(\s*):css\s*$/,
+ process: function () {
+ return JSON.stringify('\n<style type="text/css">\n' +
+ this.contents.join("\n") +
+ "\n</style>\n");
+ }
+ },
+
+ ];
+
+ function compile(lines) {
+ var block = false,
+ output = [];
+
+ // If lines is a string, turn it into an array
+ if (typeof lines === 'string') {
+ lines = lines.trim().split("\n");
+ }
+
+ lines.forEach(function(line) {
+ var match, found = false;
+
+ // Collect all text as raw until outdent
+ if (block) {
+ match = block.check_indent(line);
+ if (match) {
+ block.contents.push(match[1] || "");
+ return;
+ } else {
+ output.push(block.process());
+ block = false;
+ }
+ }
+
+ matchers.forEach(function (matcher) {
+ if (!found) {
+ match = matcher.regexp(line);
+ if (match) {
+ block = {
+ contents: [],
+ matches: match,
+ check_indent: new RegExp("^(?:\\s*|" + match[1] + " (.*))$"),
+ process: matcher.process,
+ render_contents: function () {
+ return compile(this. contents);
+ }
+ };
+ found = true;
+ }
+ }
+ });
+
+ // Match plain text
+ if (!found) {
+ output.push(function () {
+ // Escaped plain text
+ if (line[0] === '\\') {
+ return parse_interpol(line.substr(1, line.length));
+ }
+
+ // Plain variable data
+ if (line[0] === '=') {
+ line = line.substr(1, line.length).trim();
+ try {
+ return parse_interpol(JSON.parse(line));
+ } catch (e) {
+ return line;
+ }
+ }
+
+ // HTML escape variable data
+ if (line.substr(0, 2) === "&=") {
+ line = line.substr(2, line.length).trim();
+ try {
+ return JSON.stringify(html_escape(JSON.parse(line)));
+ } catch (e2) {
+ return 'html_escape(' + line + ')';
+ }
+ }
+
+ // Plain text
+ return parse_interpol(line);
+ }());
+ }
+
+ });
+ if (block) {
+ output.push(block.process());
+ }
+ return output.filter(function (part) { return part && part.length > 0}).join(" +\n");
+ };
+
+ function optimize(js) {
+ var new_js = [], buffer = [], part, end;
+
+ function flush() {
+ if (buffer.length > 0) {
+ new_js.push(JSON.stringify(buffer.join("")) + end);
+ buffer = [];
+ }
+ }
+ js.split("\n").forEach(function (line) {
+ part = line.match(/^(\".*\")(\s*\+\s*)?$/);
+ if (!part) {
+ flush();
+ new_js.push(line);
+ return;
+ }
+ end = part[2] || "";
+ part = part[1];
+ try {
+ buffer.push(JSON.parse(part));
+ } catch (e) {
+ flush();
+ new_js.push(line);
+ }
+ });
+ flush();
+ return new_js.join("\n");
+ };
+
+ function render(text, options) {
+ options = options || {};
+ text = text || "";
+ var js = compile(text);
+ if (options.optimize) {
+ js = Haml.optimize(js);
+ }
+ return execute(js, options.context || Haml, options.locals);
+ };
+
+ function execute(js, self, locals) {
+ return (function () {
+ with(locals || {}) {
+ try {
+ return eval("(" + js + ")");
+ } catch (e) {
+ return "\n<pre class='error'>" + html_escape(e.stack) + "</pre>\n";
+ }
+
+ }
+ }).call(self);
+ };
+
+ Haml = function Haml(haml, xml) {
+ forceXML = xml;
+ var js = optimize(compile(haml));
+ return new Function("locals",
+ html_escape + "\n" +
+ "with(locals || {}) {\n" +
+ " try {\n" +
+ " return (" + js + ");\n" +
+ " } catch (e) {\n" +
+ " return \"\\n<pre class='error'>\" + html_escape(e.stack) + \"</pre>\\n\";\n" +
+ " }\n" +
+ "}");
+ }
+ Haml.compile = compile;
+ Haml.optimize = optimize;
+ Haml.render = render;
+ Haml.execute = execute;
+
+}());
+
+// Hook into module system
+if (typeof module !== 'undefined') {
+ module.exports = Haml;
+}
--- /dev/null
+{
+ "name": "haml",
+ "description": "Haml ported to server-side Javascript. This is a traditional server-side templating language.",
+ "keywords": ["haml", "template"],
+ "main" : "./lib/haml",
+ "author": "Tim Caswell <tim@creationix.com>",
+ "version": "0.2.5"
+}
\ No newline at end of file
--- /dev/null
+%tag(name="value" name2=true ns:tag=100)
+%input#space-end(type="hidden" value="3" )
+%input#space-start( type="hidden" value="3" )
+%input#space-middle(type="hidden" value="3")
--- /dev/null
+<tag name="value" name2="name2" ns:tag="100"></tag><input type="hidden" value="3" id="space-end" /><input type="hidden" value="3" id="space-start" /><input type="hidden" value="3" id="space-middle" />
\ No newline at end of file
--- /dev/null
+%div
+ Does not close properly
+ %div Nested same level as next div
+%div
+ Will be nested, but should be top level
\ No newline at end of file
--- /dev/null
+<div>Does not close properly<div>Nested same level as next div</div></div><div>Will be nested, but should be top level</div>
\ No newline at end of file
--- /dev/null
+!!!
+!!! strict
+!!! 1.1
+!!! 5
+!!! xml
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<!DOCTYPE html>
+<?xml version='1.0' encoding='utf-8' ?>
--- /dev/null
+%head
+ :javascript
+ Page.chapter = #{JSON.stringify(chapter)};
+%body
+ %h1 Welcome #{name}
+ %div{class: "div_#{id}"}
--- /dev/null
+<head>
+<script type="text/javascript">
+//<![CDATA[
+Page.chapter = {"name":"Ninja","page":42};
+//]]>
+</script>
+</head><body><h1>Welcome Tim</h1><div class="div_42"></div></body>
\ No newline at end of file
--- /dev/null
+{
+ locals: {
+ chapter: {name: "Ninja", page: 42},
+ name: "Tim",
+ id: 42
+ }
+}
\ No newline at end of file
--- /dev/null
+:each color in colors
+ .preview{style: "color: " + color + ";"}&= name
+:each item in data
+ :if item.age < 100
+ %dl
+ :each name, value in item
+ %dt&= name
+ %dd&= value
+:each number in [1,2,3,4,5,6,7]
+ = number
+:for word in "Hello World".split(" ")
+ = word
\ No newline at end of file
--- /dev/null
+<div style="color: #f80;" class="preview">My Rainbow</div><div style="color: #08f;" class="preview">My Rainbow</div><div style="color: #4f4;" class="preview">My Rainbow</div><dl><dt>name</dt><dd>Tim Caswell</dd><dt>age</dt><dd>27</dd></dl>1234567HelloWorld
\ No newline at end of file
--- /dev/null
+{
+ locals: {
+ colors: ["#f80", "#08f", "#4f4"],
+ name: "My Rainbow",
+ data: [
+ {name: "Tim Caswell", age: 27},
+ {name: "John Smith", age: 107},
+ ]
+ }
+}
\ No newline at end of file
--- /dev/null
+%meta(http-equiv="content-type" content="text/html; charset=UTF-8")
--- /dev/null
+<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
\ No newline at end of file
--- /dev/null
+!!! 5
+%html
+ %head
+ %title atomix
+
+ %script(src='atomix_xlib.js')
--- /dev/null
+<!DOCTYPE html>
+<html><head><title>atomix</title><script src="atomix_xlib.js"></script></head></html>
\ No newline at end of file
--- /dev/null
+%p= this.name
+#main
+ :each item in items
+ .item= this.name + ": " + item
+ :if items
+ #cool= this.name
\ No newline at end of file
--- /dev/null
+<p>Frank</p><div id="main"><div class="item">Frank: 1</div><div class="item">Frank: 2</div><div class="item">Frank: 3</div><div id="cool">Frank</div></div>
\ No newline at end of file
--- /dev/null
+{
+ context: {
+ name: "Frank"
+ },
+ locals: {
+ items: [1,2,3]
+ }
+}
\ No newline at end of file
--- /dev/null
+%html
+ %body
+ %div#a
+ %div I do not self close.
+ :javascript
+ (function(){
+ document.getElementById('a').textContent='I self close';
+ })();
--- /dev/null
+<html><body><div id="a"></div><div>I do not self close.</div>
+<script type="text/javascript">
+//<![CDATA[
+(function(){
+ document.getElementById('a').textContent='I self close';
+})();
+//]]>
+</script>
+</body></html>
\ No newline at end of file
--- /dev/null
+#plain= "Plain Text"
+#escaped&= "<escaped>"
+%input{checked: true}
+%input{checked: false}
+%input{checked: null}
+%input{checked: undefined}
+%input{checked: 0}
+%input{checked: ""}
\ No newline at end of file
--- /dev/null
+<div id="plain">Plain Text</div><div id="escaped"><escaped></div><input checked="checked" /><input /><input /><input /><input checked="0" /><input />
\ No newline at end of file
--- /dev/null
+%head
+ :javascript
+ function greet(message) {
+ alert("Message from MCP: " + message);
+ }
+ %title Script and Css test
+ :css
+ body {
+ color: pink;
+ }
+%body{onload: "greet(\"I'm Pink\")"} COLOR ME PINK
+
--- /dev/null
+<head>
+<script type="text/javascript">
+//<![CDATA[
+function greet(message) {
+ alert("Message from MCP: " + message);
+}
+//]]>
+</script>
+<title>Script and Css test</title>
+<style type="text/css">
+body {
+ color: pink;
+}
+</style>
+</head><body onload="greet("I'm Pink")">COLOR ME PINK</body>
\ No newline at end of file
--- /dev/null
+%html
+ %head
+ :if url !='/'
+ %script
+ %meta{name: "test", value:"Monkey"}
+ %body
+ %a{ href: url }
+ link
\ No newline at end of file
--- /dev/null
+<html><head><script></script><meta name="test" value="Monkey" /></head><body><a href="http://nodejs.org/">link</a></body></html>
\ No newline at end of file
--- /dev/null
+{
+ locals: {
+ url: "http://nodejs.org/"
+ }
+}
\ No newline at end of file
--- /dev/null
+!!! XML
+!!! strict
+%html{ xmlns: "http://www.w3.org/1999/xhtml" }
+ %head
+ %title
+ Sample haml template
+ %body
+ .profile
+ .left.column
+ #date= print_date()
+ #address= current_user.address
+ .right.column
+ #email= current_user.email
+ #bio= current_user.bio
\ No newline at end of file
--- /dev/null
+<?xml version='1.0' encoding='utf-8' ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Sample haml template</title></head><body><div class="profile"><div class="left column"><div id="date">January 1, 2009</div><div id="address">Richardson, TX</div></div><div class="right column"><div id="email">tim@creationix.com</div><div id="bio">Experienced software professional...</div></div></div></body></html>
\ No newline at end of file
--- /dev/null
+{
+ locals: {
+ print_date: function () {
+ return 'January 1, 2009';
+ },
+ current_user: {
+ address: "Richardson, TX",
+ email: "tim@creationix.com",
+ bio: "Experienced software professional..."
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+var FILE = require("file");
+var ASSERT = require("assert");
+
+var Haml = require("../lib/haml");
+
+FILE.glob("test/*.haml").forEach(function(hamlFile) {
+ exports["test " + hamlFile] = function() {
+ var scopeFile = hamlFile.replace(/haml$/, "js");
+ var htmlFile = hamlFile.replace(/haml$/, "html");
+
+ var haml = FILE.read(hamlFile);
+ var expected = FILE.read(htmlFile);
+ var scope = FILE.exists(scopeFile) ? eval("("+FILE.read(scopeFile)+")") : {};
+
+ var js = Haml.compile(haml);
+ var js_opt = Haml.optimize(js);
+ var actual = Haml.execute(js_opt, scope.context, scope.locals);
+ ASSERT.equal(actual.trim(), expected.trim());
+ }
+});
+
+if (module == require.main)
+ require("os").exit(require("test").run(exports));
--- /dev/null
+var fs = require('fs');
+var assert = require('assert');
+var sys = require('sys');
+
+var Haml = require("../lib/haml");
+
+fs.readdir('.', function (err, files) {
+ files.forEach(function (haml_file) {
+ var m = haml_file.match(/^(.*)\.haml/),
+ base;
+ if (!m) {
+ return;
+ }
+ base = m[1];
+
+ function load_haml(scope) {
+ fs.readFile(haml_file, "utf8", function (err, haml) {
+ fs.readFile(base + ".html", "utf8", function (err, expected) {
+ try {
+ var js = Haml.compile(haml);
+ var js_opt = Haml.optimize(js);
+ var actual = Haml(haml).call(scope.context, scope.locals);
+ assert.equal(actual, expected);
+
+ sys.puts(haml_file + " Passed")
+ } catch (e) {
+ var message = e.name;
+ if (e.message) { message += ": " + e.message; }
+ sys.error(haml_file + " FAILED")
+ sys.error(message);
+ sys.error("\nJS:\n\n" + js);
+ sys.error("\nOptimized JS:\n\n" + js_opt);
+ sys.error("\nActual:\n\n" + actual);
+ sys.error("\nExpected:\n\n" + expected);
+ process.exit();
+ }
+ });
+ });
+ }
+
+ // Load scope
+ if (files.indexOf(base + ".js") >= 0) {
+ fs.readFile(base + ".js", "utf8", function (err, js) {
+ load_haml(eval("(" + js + ")"));
+ });
+ } else {
+ load_haml({});
+ }
+ });
+});
+
+
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var bm = require('./common'),
+ haml = require('./haml-js/lib/haml'),
+ fs = require('fs');
+
+var str = fs.readFileSync(__dirname + '/example.haml', 'ascii');
+
+var n = bm.times;
+bm.start('haml-js compilation');
+while (n--) {
+ haml(str);
+}
+bm.stop();
+
+var n = bm.times;
+var fn = haml(str);
+bm.start('haml-js execution');
+while (n--) {
+ fn.call('whatever scope', bm.locals);
+}
+bm.stop();
\ No newline at end of file
--- /dev/null
+[submodule "benchmarks/haml-js"]
+ path = benchmarks/haml-js
+ url = git://github.com/creationix/haml-js.git
--- /dev/null
+benchmarks
\ No newline at end of file
--- /dev/null
+
+0.4.5 / 2010-06-04
+==================
+
+ * Ignoring stray indent
+
+0.4.4 / 2010-05-27
+==================
+
+ * Fixed arbitrary whitespace support
+
+0.4.3 / 2010-05-25
+==================
+
+ * Fixed support for CRLF / CR line-endings, converted on input
+ * Exporting HamlError
+
+0.4.2 / 2010-05-25
+==================
+
+ * Added HamlError
+ * Buffer newline indentation. Closes #23
+ * Benchmarks with node-bench
+
+0.4.1 / 2010-05-17
+==================
+
+ * Fixed "- each" with non-enumerables, no longer throws exception
+ * Fixed array iteration
+
+0.4.0 / 2010-05-06
+==================
+
+ * Using Function constructor instead of eval()
+ * Performance enhanced by faster iteration implementation for "- each"
+
+0.3.1 / 2010-04-26
+==================
+
+ * Fixed support for tags with hypens (both namespace / tag name, ex: "fb:login-button")
+
+0.3.0 / 2010-04-16
+==================
+
+ * Added xml namespace support
+ * Added xml support
+
+0.2.0 / 2010-04-06
+==================
+
+ * Added conditional comment support [ciaranj]
+ * Fixed; Trimming input string before tokenization
+ * Fixed issue requiring quoting of "for" when used in attrs [aheckmann]
+ * Fixed; Exposing Haml compilation cache. Closes #12
+ * Fixed :javascript "type" attr, now "text/javascript" [aheckmann]
+
+0.1.0 / 2010-03-31
+==================
+
+ * Added "cache" option, making haml.js over 90 times faster than haml-js
+ * Improved textBlock whitespace replication
+ * Fixed empty tags followed by class / ids on new lines. Closes #6
+
+0.0.4 / 2010-03-29
+==================
+
+ * Added better error reporting
+
+0.0.3 / 2010-03-29
+==================
+
+ * Added "filename" option support to aid in error reporting
+ * Added exports.compile() to create intermediate javascript
+ * Added `make benchmark`
+ * Changed; caching function templates to increase performance
+ * Fixed; ids and classes allowing underscores. Closes #5
+ * Fixed outdent issue when \n is not followed by whitespace. Closes #8
+
+0.0.2 / 2010-03-26
+==================
+
+ * Added haml.js vs haml-js benchmarks
+ * Fixed; commenting :javascript CDATA
+
+0.0.1 / 2010-03-26
+==================
+
+ * Initial release
--- /dev/null
+
+test:
+ @node spec/node.js
+
+benchmark:
+ @node-bench benchmarks/run.js
+
+.PHONY: test benchmark
\ No newline at end of file
--- /dev/null
+
+# Haml.js
+
+ High performance JavaScript [Haml](http://haml-lang.com) implementation for [nodejs](http://nodejs.org)
+
+ For a higher quality implementation you may want to look at my [Jade](http://jade-lang.com) template engine,
+ however the syntax is slightly different. Jade's engine may be back-ported to haml.js in the future.
+
+## Installation
+
+ Install the [Kiwi package manager for nodejs](http://github.com/visionmedia/kiwi)
+ and run:
+
+ $ kiwi install haml
+
+ node> require('haml')
+
+Or npm:
+
+ $ npm install hamljs
+
+ node> require('hamljs')
+
+## About
+
+ Benchmarks rendering the same 21 line haml file located at _benchmarks/page.haml_,
+ shows that this library is nearly **65%** or **3 times** faster than haml-js.
+
+ Winner: haml.js
+ Compared with next highest (haml-js), it's:
+ 65.39% faster
+ 2.89 times as fast
+ 0 order(s) of magnitude faster
+
+ Haml.js attempts to comply with the original [Haml](http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html)
+ implementation as well as possible. There are no magic "plugins" like
+ found in other JavaScript haml implementations, for example the following
+ will work just fine:
+
+ - if (items)
+ %ul
+ - for (var i = 0; i < items.length; ++i)
+ %li= items[i]
+
+ Iteration is the one exception to these magical plugins,
+ since this is **ugly** in JavaScript, you may also:
+
+ - if (items)
+ %ul
+ - each item in items
+ %li= item
+
+## Usage
+
+ var haml = require('haml')
+ haml.render('a string of haml', { a: 'hash', of: 'options' })
+
+## Options
+
+ * context
+ - when passed the value of "this" becomes the given "context" object
+ * locals
+ - when passed all members of this object become available to this template
+ * filename
+ - required when _cache_ is enabled
+ * cache
+ - compiled intermediate javascript is cached in memory keyed by _filename_
+
+## Tags
+
+ %div text
+
+html:
+
+ <div>text</div>
+
+## Classes
+
+ %div.article.first
+ article text here
+ and here
+
+html:
+
+ <div class="article first">
+ article text here and here
+ </div>
+
+## Div Class Shortcut
+
+ .comment hey
+
+html:
+
+ <div class="comment">hey</div>
+
+## Div Id Shortcut
+
+ #article-1 foo
+
+html:
+
+ <div id="article-1">foo</div>
+
+## Combining Ids and Classes
+
+You may chain id and classes in any order:
+
+ .article#first.summary content
+
+html:
+
+ <div id="first" class="article summary">context</div>
+
+## Attributes
+
+ %a{ href: 'http://google.com', title: 'Google It' } Google
+
+html:
+
+ <a href="http://google.com" title="Google It">Google</a>
+
+Attribute keys such as "for" are automatically quoted
+by haml.js, so instead of:
+
+ %label{ 'for': 'something' }
+
+you should:
+
+ %label{ for: 'something' }
+
+which will render:
+
+ <label for="something"></label>
+
+## Boolean Attributes
+
+ %input{ type: 'checkbox', checked: true }
+
+html:
+
+ <input type="checkbox" checked="checked"/>
+
+## Combining Attributes, Ids, and Classes
+
+Wemay also contain id and classes before or after:
+
+ %a.button{ href: 'http://google.com', title: 'Google It' }.first Google
+
+html:
+
+ <a href="http://google.com" title="Google It" class="button first">Google</a>
+
+## Code
+
+Code starting with a hyphen will be executed but
+not buffered, where as code using the equals sign
+will be buffered:
+
+ - a = 1
+ - b = 2
+ = a + b
+
+html:
+
+ 3
+
+HTML buffered with equals sign will **always** be escaped:
+
+ = "<br/>"
+
+html:
+
+ <br/>
+
+To prevent escaping of HTML entities we can use _!=_:
+
+ != "<br/>"
+
+html:
+
+ <br/>
+
+## Iteration
+
+ %ul
+ - each item in items
+ %li= item
+
+html:
+
+ <ul>
+ <li>one</li>
+ <li>two</li>
+ <li>three</li>
+ </ul>
+
+If you require the key or index of the object
+or array during iteration simple append a comma
+following another id:
+
+ %ul
+ - each item, index in items
+ %li= item + '(' + index + ')'
+
+html:
+
+ <ul>
+ <li>one(0)</li>
+ <li>two(1)</li>
+ <li>three(2)</li>
+ </ul>
+
+## Doctypes
+
+Defaults to transitional:
+
+ !!!
+
+html:
+
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+Optionally pass a supported doctype name:
+
+ !!! strict
+
+html:
+
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+
+currently supported doctypes, which can be
+extended simply by adding values to to _haml.doctypes_.
+
+ '5': '<!DOCTYPE html>',
+ 'xml': '<?xml version="1.0" encoding="utf-8" ?>',
+ 'default': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
+ 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
+ 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
+ '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
+ 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
+ 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
+
+
+## :cdata
+
+ %script
+ :cdata
+ foo
+
+html:
+
+ <script><![CDATA[
+ foo
+ ]]></script>
+
+## :javascript
+
+ %head
+ :javascript
+ if (foo)
+ if (bar)
+ alert('baz')
+
+html:
+
+ <head>
+ <script type="javascript">
+ //<![CDATA[
+ if (foo)
+ if (bar)
+ alert('baz')
+ //]]>
+ </script>
+ </head>
+
+## Extending Haml
+
+### Adding Filters
+
+ var haml = require('haml')
+ haml.filters.my_filter = function(str) {
+ return doSomethingWith(str)
+ }
+
+by registering the filter function _my_filter_ we can now
+utilize it within our Haml templates as shown below:
+ %p
+ :my_filter
+ some text
+ here yay
+ whoop awesome
+
+### Adding Doctypes
+
+ var haml = require('haml')
+ haml.doctypes.foo = '<!DOCTYPE ... >'
+
+Will now allow you to:
+ !!! foo
+
+## Running Benchmarks
+
+To run benchmarks against [haml-js](http://github.com/creationix/haml-js)
+simply execute:
+
+ $ git submodule update --init
+ $ node benchmarks/run.js
+
+## More Information
+
+ * View _spec/fixtures_ for more examples
+ * Official [Haml](http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html) reference
+ * JavaScript [Sass](http://github.com/visionmedia/sass.js) implementation
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- /dev/null
+!!!
+%html
+ %head
+ %title Welcome
+ %script{ src: 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', type: 'javascript' }
+ -# javascript filter (and others)
+ -# support arbitrary whitespace
+ :javascript
+ $(function(){
+ alert('yay!')
+ })
+ %meta{ name: 'keywords', content: 'foo bar baz' }
+ %body
+ %h1 Title
+ %ul
+ %li one
+ %li two
+ %li
+ %ol
+ %li one
+ %li two
+ %li three
+ %li four
+ %ul
+ %li five
+ %li six
+ %li
+ %ol
+ %li seven
+ %li eight
\ No newline at end of file
--- /dev/null
+
+var fs = require('fs'),
+ haml = require('../lib/haml'),
+ hamlJS = require('./haml-js/lib/haml'),
+ page = fs.readFileSync('benchmarks/page.haml')
+
+var js = hamlJS.compile(page)
+
+exports.compare = {
+ 'haml.js': function(){
+ haml.render(page)
+ },
+ 'haml.js cached': function(){
+ haml.render(page, { cache: true, filename: 'page.haml' })
+ },
+ 'haml-js': function(){
+ hamlJS.render(page)
+ },
+ 'haml-js cached': function(){
+ hamlJS.execute(js)
+ },
+ 'haml-js cached / optimized': function(){
+ hamlJS.execute(js)
+ }
+}
--- /dev/null
+
+var sys = require('sys'),
+ fs = require('fs'),
+ haml = require('../lib/haml')
+
+var options = {
+ filename: 'page.haml',
+ locals: {
+ title: 'Welcome',
+ body: 'wahoo',
+ usersOnline: 15
+ }
+}
+
+sys.puts(haml.render(fs.readFileSync('examples/page.haml'), options))
\ No newline at end of file
--- /dev/null
+%html
+ %head
+ %title= title
+
+ %script{ src: 'jquery.js' }
+
+ %script{ src: 'jquery.ui.js' }
+
+ %body
+ %h1 Welcome
+
+ %ul#menu
+ %li.first one
+ %li two
+ %li.last three
+ %li
+ %ul
+ %li nested
+
+ #content
+ = body
+ #usersOnline= usersOnline
--- /dev/null
+lib/haml.js
\ No newline at end of file
--- /dev/null
+
+// Haml - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+/**
+ * Module dependencies.
+ */
+
+var sys = require('sys')
+
+/**
+ * Version.
+ */
+
+exports.version = '0.4.5'
+
+/**
+ * Haml template cache.
+ */
+
+exports.cache = {}
+
+/**
+ * Default error context length.
+ */
+
+exports.errorContextLength = 15
+
+/**
+ * Self closing tags.
+ */
+
+exports.selfClosing = [
+ 'meta',
+ 'img',
+ 'link',
+ 'br',
+ 'hr',
+ 'input',
+ 'area',
+ 'base'
+ ]
+
+/**
+ * Default supported doctypes.
+ */
+
+exports.doctypes = {
+ '5': '<!DOCTYPE html>',
+ 'xml': '<?xml version="1.0" encoding="utf-8" ?>',
+ 'default': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
+ 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
+ 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
+ '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
+ 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
+ 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
+}
+
+/**
+ * Default filters.
+ */
+
+exports.filters = {
+
+ /**
+ * Return plain string.
+ */
+
+ plain: function(str) {
+ return str
+ },
+
+ /**
+ * Wrap with CDATA tags.
+ */
+
+ cdata: function(str) {
+ return '<![CDATA[\n' + str + '\n]]>'
+ },
+
+ /**
+ * Wrap with <script> and CDATA tags.
+ */
+
+ javascript: function(str) {
+ return '<script type="text/javascript">\n//<![CDATA[\n' + str + '\n//]]></script>'
+ }
+}
+
+/**
+ * Function templates.
+ */
+
+exports.templates = {
+
+ /**
+ * Execute __code__.
+ */
+
+ code: (function(){
+ __code__;
+ return ""
+ }).toString(),
+
+ /**
+ * Execute __code__ followed by buffering __block__.
+ */
+
+ codeBlock: (function(){
+ var buf = [];
+ __code__
+ buf.push(__block__);
+ return buf.join("")
+ }).toString(),
+
+ /**
+ * Iterate __vals__ as __val__ while buffering __block__.
+ */
+
+ iterate: (function(){
+ var buf = [];
+ if (__vals__ instanceof Array) {
+ for (var i = 0, len = __vals__.length; i < len; ++i) {
+ var __key__ = i;
+ var __val__ = __vals__[i];
+ buf.push(__block__);
+ }
+ } else if (__vals__) {
+ var keys = Object.keys(__vals__);
+ for (var i = 0, len = keys.length; i < len; ++i) {
+ var __key__ = keys[i];
+ var __val__ = __vals__[__key__];
+ buf.push(__block__);
+ }
+ }
+ return buf.join("")
+ }).toString()
+}
+
+/**
+ * HamlError.
+ */
+
+var HamlError = exports.HamlError = function(msg) {
+ this.name = 'HamlError'
+ this.message = msg
+ Error.captureStackTrace(this, exports.render)
+}
+sys.inherits(HamlError, Error)
+
+/**
+ * Lexing rules.
+ */
+
+var rules = {
+ indent: /^\n( *)(?! *-#)/,
+ conditionalComment: /^\/(\[[^\n]+\])/,
+ comment: /^\n? *\/ */,
+ silentComment: /^\n? *-#([^\n]*)/,
+ doctype: /^!!! *([^\n]*)/,
+ escape: /^\\(.)/,
+ filter: /^:(\w+) */,
+ each: /^\- *each *(\w+)(?: *, *(\w+))? * in ([^\n]+)/,
+ code: /^\-([^\n]+)/,
+ outputCode: /^!=([^\n]+)/,
+ escapeCode: /^=([^\n]+)/,
+ attrs: /^\{(.*?)\}/,
+ tag: /^%([-a-zA-Z][-a-zA-Z0-9:]*)/,
+ class: /^\.([\w\-]+)/,
+ id: /^\#([\w\-]+)/,
+ text: /^([^\n]+)/
+}
+
+/**
+ * Return error context _str_.
+ *
+ * @param {string} str
+ * @return {string}
+ * @api private
+ */
+
+function context(str) {
+ return String(str)
+ .substr(0, exports.errorContextLength)
+ .replace(/\n/g, '\\n')
+}
+
+/**
+ * Tokenize _str_.
+ *
+ * @param {string} str
+ * @return {array}
+ * @api private
+ */
+
+function tokenize(str) {
+ var captures,
+ token,
+ tokens = [],
+ line = 1,
+ lastIndents = 0,
+ str = String(str).trim().replace(/\r\n|\r/g, '\n')
+ function error(msg){ throw new HamlError('(Haml):' + line + ' ' + msg) }
+ while (str.length) {
+ for (var type in rules)
+ if (captures = rules[type].exec(str)) {
+ token = {
+ type: type,
+ line: line,
+ match: captures[0],
+ val: captures.length > 2
+ ? captures.slice(1)
+ : captures[1]
+ }
+ str = str.substr(captures[0].length)
+ if (type === 'newline' ||
+ type === 'indent') ++line
+ if (type !== 'indent') break
+ var indents = token.val.length / 2
+ if (indents % 1)
+ error('invalid indentation; got ' + token.val.length + ' spaces, should be multiple of 2')
+ else if (indents - 1 > lastIndents)
+ error('invalid indentation; got ' + indents + ', when previous was ' + lastIndents)
+ else if (lastIndents > indents)
+ while (lastIndents-- > indents)
+ tokens.push({ type: 'outdent', line: line })
+ else if (lastIndents !== indents)
+ tokens.push({ type: 'indent', line: line })
+ else
+ tokens.push({ type: 'newline', line: line })
+ lastIndents = indents
+ }
+ if (token) {
+ if (token.type !== 'silentComment')
+ tokens.push(token)
+ token = null
+ } else
+ error('near "' + context(str) + '"')
+ }
+ return tokens.concat({ type: 'eof' })
+}
+
+/**
+ * Render template _name_ with the given placeholder _vals_.
+ *
+ * @param {string} name
+ * @param {object} vals
+ * @return {string}
+ * @api private
+ */
+
+function template(name, vals) {
+ var buf = '(' + exports.templates[name] + ').call(this)'
+ for (var key in vals)
+ buf = buf.replace(new RegExp(key, 'g'), vals[key])
+ return buf
+}
+
+// --- Parser
+
+/**
+ * Initialize parser with _str_ and _options_.
+ */
+
+function Parser(str, options) {
+ options = options || {}
+ this.tokens = tokenize(str)
+ this.xml = options.xml
+}
+
+Parser.prototype = {
+
+ /**
+ * Lookahead a single token.
+ *
+ * @return {object}
+ * @api private
+ */
+
+ get peek() {
+ return this.tokens[0]
+ },
+
+ /**
+ * Advance a single token.
+ *
+ * @return {object}
+ * @api private
+ */
+
+ get advance() {
+ return this.current = this.tokens.shift()
+ },
+
+ /**
+ * outdent
+ * | eof
+ */
+
+ get outdent() {
+ switch (this.peek.type) {
+ case 'eof':
+ return
+ case 'outdent':
+ return this.advance
+ default:
+ throw new HamlError('expected outdent, got ' + this.peek.type)
+ }
+ },
+
+ /**
+ * text
+ */
+
+ get text() {
+ return '"' + this.advance.val.trim() + '"'
+ },
+
+ /**
+ * indent expr outdent
+ */
+
+ get block() {
+ var buf = []
+ this.advance
+ while (this.peek.type !== 'outdent' &&
+ this.peek.type !== 'eof')
+ buf.push(this.expr)
+ this.outdent
+ return buf.join(' + ')
+ },
+
+ /**
+ * indent expr
+ */
+
+ get textBlock() {
+ var token,
+ indents = 1,
+ buf = []
+ this.advance
+ while (this.peek.type !== 'eof' && indents)
+ switch((token = this.advance).type) {
+ case 'newline':
+ buf.push('"\\n' + Array(indents).join(' ') + '"')
+ break
+ case 'indent':
+ ++indents
+ buf.push('"\\n' + Array(indents).join(' ') + '"')
+ break
+ case 'outdent':
+ --indents
+ if (indents === 1) buf.push('"\\n"')
+ break
+ default:
+ buf.push('"' + token.match.replace(/"/g, '\\\"') + '"')
+ }
+ return buf.join(' + ')
+ },
+
+ /**
+ * ( attrs | class | id )*
+ */
+
+ get attrs() {
+ var attrs = ['attrs', 'class', 'id'],
+ classes = [],
+ buf = []
+ while (attrs.indexOf(this.peek.type) !== -1)
+ switch (this.peek.type) {
+ case 'id':
+ buf.push('id: "' + this.advance.val + '"')
+ break
+ case 'class':
+ classes.push(this.advance.val)
+ break
+ case 'attrs':
+ buf.push(this.advance.val.replace(/(for) *:/gi, '"$1":'))
+ }
+ if (classes.length)
+ buf.push('"class": "' + classes.join(' ') + '"')
+ return buf.length
+ ? ' " + attrs({' + buf.join() + '}) + "'
+ : ''
+ },
+
+ /**
+ * tag
+ * | tag text
+ * | tag conditionalComment
+ * | tag comment
+ * | tag outputCode
+ * | tag escapeCode
+ * | tag block
+ */
+
+ get tag() {
+ var tag = this.advance.val,
+ selfClosing = !this.xml && exports.selfClosing.indexOf(tag) !== -1,
+ buf = ['"\\n<' + tag + this.attrs + (selfClosing ? '/>"' : '>"')]
+ switch (this.peek.type) {
+ case 'text':
+ buf.push(this.text)
+ break
+ case 'conditionalComment':
+ buf.push(this.conditionalComment)
+ break;
+ case 'comment':
+ buf.push(this.comment)
+ break
+ case 'outputCode':
+ buf.push(this.outputCode)
+ break
+ case 'escapeCode':
+ buf.push(this.escapeCode)
+ break
+ case 'indent':
+ buf.push(this.block)
+ }
+ if (!selfClosing) buf.push('"</' + tag + '>"')
+ return buf.join(' + ')
+ },
+
+ /**
+ * outputCode
+ */
+
+ get outputCode() {
+ return this.advance.val
+ },
+
+ /**
+ * escapeCode
+ */
+
+ get escapeCode() {
+ return 'escape(' + this.advance.val + ')'
+ },
+
+ /**
+ * doctype
+ */
+
+ get doctype() {
+ var doctype = this.advance.val.trim().toLowerCase() || 'default'
+ if (doctype in exports.doctypes)
+ return '"' + exports.doctypes[doctype].replace(/"/g, '\\"') + '"'
+ else
+ throw new HamlError("doctype `" + doctype + "' does not exist")
+ },
+
+ /**
+ * conditional comment expr
+ */
+
+ get conditionalComment() {
+ var condition= this.advance.val
+ var buf = this.peek.type === 'indent'
+ ? this.block
+ : this.expr
+ return '"<!--' + condition + '>" + (' + buf + ') + "<![endif]-->"'
+ },
+
+ /**
+ * comment expr
+ */
+
+ get comment() {
+ this.advance
+ var buf = this.peek.type === 'indent'
+ ? this.block
+ : this.expr
+ return '"<!-- " + (' + buf + ') + " -->"'
+ },
+
+ /**
+ * code
+ * | code block
+ */
+
+ get code() {
+ var code = this.advance.val
+ if (this.peek.type === 'indent')
+ return template('codeBlock', { __code__: code, __block__: this.block })
+ return template('code', { __code__: code })
+ },
+
+ /**
+ * filter textBlock
+ */
+
+ get filter() {
+ var filter = this.advance.val
+ if (!(filter in exports.filters))
+ throw new HamlError("filter `" + filter + "' does not exist")
+ if (this.peek.type !== 'indent')
+ throw new HamlError("filter `" + filter + "' expects a text block")
+ return 'exports.filters.' + filter + '(' + this.textBlock + ')'
+ },
+
+ /**
+ * each block
+ */
+
+ get iterate() {
+ var each = this.advance
+ if (this.peek.type !== 'indent')
+ throw new HamlError("'- each' expects a block, but got " + this.peek.type)
+ return template('iterate', {
+ __key__: each.val[1],
+ __vals__: each.val[2],
+ __val__: each.val[0],
+ __block__: this.block
+ })
+ },
+
+ /**
+ * eof
+ * | tag
+ * | text*
+ * | each
+ * | code
+ * | escape
+ * | doctype
+ * | filter
+ * | comment
+ * | conditionalComment
+ * | escapeCode
+ * | outputCode
+ */
+
+ get expr() {
+ switch (this.peek.type) {
+ case 'id':
+ case 'class':
+ this.tokens.unshift({ type: 'tag', val: 'div' })
+ return this.tag
+ case 'tag':
+ return this.tag
+ case 'text':
+ var buf = []
+ while (this.peek.type === 'text') {
+ buf.push(this.advance.val.trim())
+ if (this.peek.type === 'newline')
+ this.advance
+ }
+ return '"' + buf.join(' ') + '"'
+ case 'each':
+ return this.iterate
+ case 'code':
+ return this.code
+ case 'escape':
+ return '"' + this.advance.val + '"'
+ case 'doctype':
+ return this.doctype
+ case 'filter':
+ return this.filter
+ case 'conditionalComment':
+ return this.conditionalComment
+ case 'comment':
+ return this.comment
+ case 'escapeCode':
+ return this.escapeCode
+ case 'outputCode':
+ return this.outputCode
+ case 'newline':
+ case 'indent':
+ case 'outdent':
+ this.advance
+ return this.expr
+ default:
+ throw new HamlError('unexpected ' + this.peek.type)
+ }
+ },
+
+ /**
+ * expr*
+ */
+
+ get js() {
+ var buf = []
+ while (this.peek.type !== 'eof')
+ buf.push(this.expr)
+ return buf.join(' + ')
+ }
+}
+
+/**
+ * Escape html entities in _str_.
+ *
+ * @param {string} str
+ * @return {string}
+ * @api private
+ */
+
+function escape(str) {
+ return String(str)
+ .replace(/&/g, '&')
+ .replace(/>/g, '>')
+ .replace(/</g, '<')
+ .replace(/"/g, '"')
+}
+
+/**
+ * Render _attrs_ to html escaped attributes.
+ *
+ * @param {object} attrs
+ * @return {string}
+ * @api public
+ */
+
+function attrs(attrs) {
+ var buf = []
+ for (var key in attrs)
+ if (typeof attrs[key] === 'boolean') {
+ if (attrs[key] === true)
+ buf.push(key + '="' + key + '"')
+ } else if (attrs[key])
+ buf.push(key + '="' + escape(attrs[key]) + '"')
+ return buf.join(' ')
+}
+
+/**
+ * Render a _str_ of haml.
+ *
+ * Options:
+ *
+ * - locals Local variables available to the template
+ * - context Context in which the template is evaluated (becoming "this")
+ * - filename Filename used to aid in error reporting
+ * - cache Cache compiled javascript, requires "filename"
+ * - xml Force xml support (no self-closing tags)
+ *
+ * @param {string} str
+ * @param {object} options
+ * @return {string}
+ * @api public
+ */
+
+exports.render = function(str, options) {
+ var parser,
+ options = options || {}
+ if (options.cache && !options.filename)
+ throw new Error('filename option must be passed when cache is enabled')
+ return (function(){
+ try {
+ var fn
+ if (options.cache && exports.cache[options.filename])
+ fn = exports.cache[options.filename]
+ else {
+ parser = new Parser(str, options)
+ fn = Function('locals, attrs, escape, exports', 'with (locals || {}){ return ' + parser.js + '}')
+ }
+ return (options.cache
+ ? exports.cache[options.filename] = fn
+ : fn).call(options.context, options.locals, attrs, escape, exports)
+ } catch (err) {
+ if (parser && err instanceof HamlError)
+ err.message = '(Haml):' + parser.peek.line + ' ' + err.message
+ else if (!(err instanceof HamlError))
+ err.message = '(Haml): ' + err.message
+ if (options.filename)
+ err.message = err.message.replace('Haml', options.filename)
+ throw err
+ }
+ }).call(options.context)
+}
--- /dev/null
+{
+ "name": "hamljs",
+ "description": "Faster, harder, better HAML template engine",
+ "keywords": ["haml", "template", "engine", "view", "nodejs"],
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "version": "0.4.5",
+ "directories": {
+ "lib": "."
+ }
+}
\ No newline at end of file
--- /dev/null
+---
+ name: Haml
+ description: Faster, harder, better HAML template engine
+ tags: haml html template engine
+ version: 0.4.5
--- /dev/null
+.users
\ No newline at end of file
--- /dev/null
+<div class="users"></div>
\ No newline at end of file
--- /dev/null
+.foo.bar.baz_is-awesome
\ No newline at end of file
--- /dev/null
+<div class="foo bar baz_is-awesome"></div>
\ No newline at end of file
--- /dev/null
+%ul
+ - each item in items
+ %li= item
\ No newline at end of file
--- /dev/null
+<ul>
+<li>one</li>
+<li>two</li>
+<li>three</li></ul>
\ No newline at end of file
--- /dev/null
+%ul
+ - each item, index in items
+ %li= item + '(' + index + ')'
\ No newline at end of file
--- /dev/null
+<ul>
+<li>one(0)</li>
+<li>two(1)</li>
+<li>three(2)</li></ul>
\ No newline at end of file
--- /dev/null
+%ul
+ - each item, index in items
+ %li= item + '(' + index + ')'
\ No newline at end of file
--- /dev/null
+<ul></ul>
\ No newline at end of file
--- /dev/null
+= "<br" + "/>"
\ No newline at end of file
--- /dev/null
+<br/>
\ No newline at end of file
--- /dev/null
+!= "foo" + "bar"
\ No newline at end of file
--- /dev/null
+foobar
\ No newline at end of file
--- /dev/null
+- name = "tj"
+- if (name === 'tj')
+ %p You are logged in
\ No newline at end of file
--- /dev/null
+<p>You are logged in</p>
\ No newline at end of file
--- /dev/null
+- if (true)
+ - if (false)
+ %p nope
+ - if (true)
+ %p yay
\ No newline at end of file
--- /dev/null
+<p>yay</p>
\ No newline at end of file
--- /dev/null
+/[if IE]
+ %a{ 'href' : 'http://www.mozilla.com/en-US/firefox/' }
+ %h1 Get Firefox
+/[if IE]
+ %a{ 'href' : 'http://www.mozilla.com/en-US/firefox/' }
+ /[if IE 6]
+ %h1 Get Firefox (IE6 user)
+ /[if IE 7]
+ %h1 Get Firefox (IE7 user)
\ No newline at end of file
--- /dev/null
+<!--[if IE]>
+<a href="http://www.mozilla.com/en-US/firefox/">
+<h1>Get Firefox</h1></a><![endif]--><!--[if IE]>
+<a href="http://www.mozilla.com/en-US/firefox/"><!--[if IE 6]>
+<h1>Get Firefox (IE6 user)</h1><![endif]--><!--[if IE 7]>
+<h1>Get Firefox (IE7 user)</h1><![endif]--></a><![endif]-->
\ No newline at end of file
--- /dev/null
+/
+ %ul
+ %li nope
+ %li nope
+ %li nope
\ No newline at end of file
--- /dev/null
+<!--
+<ul>
+<li>nope</li>
+<li>nope</li>
+<li>nope</li></ul> -->
\ No newline at end of file
--- /dev/null
+-# nothing
+%p yay
+ -# whatever you want
\ No newline at end of file
--- /dev/null
+<p>yay</p>
\ No newline at end of file
--- /dev/null
+ / %p foo
\ No newline at end of file
--- /dev/null
+<!--
+<p>foo</p> -->
\ No newline at end of file
--- /dev/null
+%ul
+ %li one
+ / first item
+ %li two
+ / second item
+ %ul
+ %li three
\ No newline at end of file
--- /dev/null
+<ul>
+<li>one</li><!-- first item -->
+<li>two</li><!-- second item -->
+<ul>
+<li>three</li></ul></ul>
\ No newline at end of file
--- /dev/null
+%p
+ / foo bar baz
\ No newline at end of file
--- /dev/null
+<p><!-- foo bar baz --></p>
\ No newline at end of file
--- /dev/null
+%p= this
\ No newline at end of file
--- /dev/null
+<p>yay</p>
\ No newline at end of file
--- /dev/null
+#foo\r .bar
\ No newline at end of file
--- /dev/null
+<div id="foo">
+<div class="bar"></div>
+</div>
\ No newline at end of file
--- /dev/null
+#foo\r
+ .bar
\ No newline at end of file
--- /dev/null
+<div id="foo">
+<div class="bar"></div>
+</div>
\ No newline at end of file
--- /dev/null
+!!!
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
\ No newline at end of file
--- /dev/null
+!!! xml
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
\ No newline at end of file
--- /dev/null
+!!! XML
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
\ No newline at end of file
--- /dev/null
+%html
+ %body
+ %p
\ No newline at end of file
--- /dev/null
+%p
+ \.foo
\ No newline at end of file
--- /dev/null
+<p>.foo</p>
\ No newline at end of file
--- /dev/null
+!!! xml
+%rss{ version: '2.0' }
+ %channel
+ %title ExpressJS
+ %link http://expressjs.com
+ %description Is super cool
+ %language en-us
+ %item
+ %title Creating Routes
+ %description Some stuff
+ %link http://expressjs.com/routes
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8" ?>
+<rss version="2.0">
+<channel>
+<title>ExpressJS</title>
+<link>http://expressjs.com</link>
+<description>Is super cool</description>
+<language>en-us</language>
+<item>
+<title>Creating Routes</title>
+<description>Some stuff</description>
+<link>http://expressjs.com/routes</link></item></channel></rss>
\ No newline at end of file
--- /dev/null
+%script
+ :cdata
+ foo
\ No newline at end of file
--- /dev/null
+<script><![CDATA[
+foo
+]]></script>
\ No newline at end of file
--- /dev/null
+%script
+ :cdata
+ $(function(){
+ if (foo)
+ if (bar)
+ alert('yay')
+ })
\ No newline at end of file
--- /dev/null
+<script><![CDATA[
+$(function(){
+ if (foo)
+ if (bar)
+ alert('yay')
+})
+]]></script>
\ No newline at end of file
--- /dev/null
+%head
+ :javascript
+ if (foo)
+ if (bar)
+ alert("baz")
+ foo()
+ bar()
+ %title Yay
\ No newline at end of file
--- /dev/null
+<head><script type="text/javascript">
+//<![CDATA[
+if (foo)
+ if (bar)
+ alert("baz")
+foo()
+bar()
+//]]></script>
+<title>Yay</title></head>
\ No newline at end of file
--- /dev/null
+%body
+ :plain
+ .foo
+ bar
+ = baz
\ No newline at end of file
--- /dev/null
+<body>.foo
+bar
+= baz</body>
\ No newline at end of file
--- /dev/null
+%div
+ <p>literal</p>
\ No newline at end of file
--- /dev/null
+<div><p>literal</p></div>
\ No newline at end of file
--- /dev/null
+#users
\ No newline at end of file
--- /dev/null
+<div id="users"></div>
\ No newline at end of file
--- /dev/null
+%label{ for: "forsomething"}
\ No newline at end of file
--- /dev/null
+<label for="forsomething"></label>
\ No newline at end of file
--- /dev/null
+%ul
+ - each item in items
+ %li= item
+%p= "Total: " + items.length
\ No newline at end of file
--- /dev/null
+<ul>
+<li>foo</li>
+<li>bar</li>
+<li>baz</li></ul>
+<p>Total: 3</p>
\ No newline at end of file
--- /dev/null
+%p= user
\ No newline at end of file
--- /dev/null
+<p>tj</p>
\ No newline at end of file
--- /dev/null
+%h:table{ 'xmlns:h': 'http://www.w3.org/1999/xhtml' }
\ No newline at end of file
--- /dev/null
+%body
+ %fb:test.a
+ %fb:bar
+ %fb:foo{ title: 'home' }
+ %fb:login-button
--- /dev/null
+<body>
+<fb:test class="a"></fb:test>
+<fb:bar></fb:bar>
+<fb:foo title="home"></fb:foo>
+<fb:login-button></fb:login-button></body>
--- /dev/null
+<h:table xmlns:h="http://www.w3.org/1999/xhtml"></h:table>
\ No newline at end of file
--- /dev/null
+%html
+ %head
+ %title Page Title
+ %body
+ %h1 Title
+ %p some stuff
\ No newline at end of file
--- /dev/null
+<html>
+<head>
+<title>Page Title</title></head>
+<body>
+<h1>Title</h1>
+<p>some stuff</p></body></html>
\ No newline at end of file
--- /dev/null
+%ul
+ %li one
+ %li two
+ %li
+ %ul
+ %li three
\ No newline at end of file
--- /dev/null
+<ul>
+<li>one</li>
+<li>two</li>
+<li>
+<ul>
+<li>three</li></ul></li></ul>
\ No newline at end of file
--- /dev/null
+%ul
+ %li one
+ %li two
+ %li three
+ %li
+ %ul
+ %li four
+
+%p foo
+%p
+ bar
+ baz
\ No newline at end of file
--- /dev/null
+<ul>
+<li>one</li>
+<li>two</li>
+<li>three</li>
+<li>
+<ul>
+<li>four</li></ul></li></ul>
+<p>foo</p>
+<p>bar baz</p>
\ No newline at end of file
--- /dev/null
+%input{ type: 'checkbox', checked: true }
\ No newline at end of file
--- /dev/null
+<input type="checkbox" checked="checked"/>
\ No newline at end of file
--- /dev/null
+%option{ value: '<script></script>' }
\ No newline at end of file
--- /dev/null
+<option value="<script></script>"></option>
\ No newline at end of file
--- /dev/null
+%a{ href: '/', title: 'home' }
\ No newline at end of file
--- /dev/null
+<a href="/" title="home"></a>
\ No newline at end of file
--- /dev/null
+%h1.title
\ No newline at end of file
--- /dev/null
+<h1 class="title"></h1>
\ No newline at end of file
--- /dev/null
+%body.front-page.editing-user
\ No newline at end of file
--- /dev/null
+<body class="front-page editing-user"></body>
\ No newline at end of file
--- /dev/null
+%div= "yay"
\ No newline at end of file
--- /dev/null
+<div>yay</div>
\ No newline at end of file
--- /dev/null
+%div!= "<br/>"
\ No newline at end of file
--- /dev/null
+<div><br/></div>
\ No newline at end of file
--- /dev/null
+%a#delete-user.first.button{ href: '/', title: 'Click to delete' }= "Delete " + "tj"
\ No newline at end of file
--- /dev/null
+<a id="delete-user" href="/" title="Click to delete" class="first button">Delete tj</a>
\ No newline at end of file
--- /dev/null
+%body
+ %div.a
+ %div.b
+ .c
+ .d
+ #e
+ #f
\ No newline at end of file
--- /dev/null
+<body>
+<div class="a"></div>
+<div class="b"></div>
+<div class="c"></div>
+<div class="d"></div>
+<div id="e"></div>
+<div id="f"></div></body>
\ No newline at end of file
--- /dev/null
+%div= "<br/>"
\ No newline at end of file
--- /dev/null
+<div><br/></div>
\ No newline at end of file
--- /dev/null
+%br
\ No newline at end of file
--- /dev/null
+<br/>
\ No newline at end of file
--- /dev/null
+%div
\ No newline at end of file
--- /dev/null
+<div></div>
\ No newline at end of file
--- /dev/null
+%p
+ Visit
+ %a{ href: 'http://vision-media.ca' } Vision Media
+ because im amazing,
+ yes...
\ No newline at end of file
--- /dev/null
+<p>Visit
+<a href="http://vision-media.ca">Vision Media</a>because im amazing, yes...</p>
\ No newline at end of file
--- /dev/null
+%p
+ some text
+ and more text
+ and even more text!
+ OMG
\ No newline at end of file
--- /dev/null
+<p>some text and more text and even more text! OMG</p>
\ No newline at end of file
--- /dev/null
+%div some text
\ No newline at end of file
--- /dev/null
+<div>some text</div>
\ No newline at end of file
--- /dev/null
+%a
+ %b
+
+
\ No newline at end of file
--- /dev/null
+<a>
+<b></b></a>
\ No newline at end of file
--- /dev/null
+body.jspec {
+ margin: 45px 0;
+ font: 12px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
+ background: #efefef url(images/bg.png) top left repeat-x;
+ text-align: center;
+}
+#jspec {
+ margin: 0 auto;
+ padding-top: 30px;
+ width: 1008px;
+ background: url(images/vr.png) top left repeat-y;
+ text-align: left;
+}
+#jspec-top {
+ position: relative;
+ margin: 0 auto;
+ width: 1008px;
+ height: 40px;
+ background: url(images/sprites.bg.png) top left no-repeat;
+}
+#jspec-bottom {
+ margin: 0 auto;
+ width: 1008px;
+ height: 15px;
+ background: url(images/sprites.bg.png) bottom left no-repeat;
+}
+#jspec .loading {
+ margin-top: -45px;
+ width: 1008px;
+ height: 80px;
+ background: url(images/loading.gif) 50% 50% no-repeat;
+}
+#jspec-title {
+ position: absolute;
+ top: 15px;
+ left: 20px;
+ width: 160px;
+ font-size: 22px;
+ font-weight: normal;
+ background: url(images/sprites.png) 0 -126px no-repeat;
+ text-align: center;
+}
+#jspec-title em {
+ font-size: 10px;
+ font-style: normal;
+ color: #BCC8D1;
+}
+#jspec-report * {
+ margin: 0;
+ padding: 0;
+ background: none;
+ border: none;
+}
+#jspec-report {
+ padding: 15px 40px;
+ font: 11px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
+ color: #7B8D9B;
+}
+#jspec-report.has-failures {
+ padding-bottom: 30px;
+}
+#jspec-report .hidden {
+ display: none;
+}
+#jspec-report .heading {
+ margin-bottom: 15px;
+}
+#jspec-report .heading span {
+ padding-right: 10px;
+}
+#jspec-report .heading .passes em {
+ color: #0ea0eb;
+}
+#jspec-report .heading .failures em {
+ color: #FA1616;
+}
+#jspec-report table {
+ font-size: 11px;
+ border-collapse: collapse;
+}
+#jspec-report td {
+ padding: 8px;
+ text-indent: 30px;
+ color: #7B8D9B;
+}
+#jspec-report tr.body {
+ display: none;
+}
+#jspec-report tr.body pre {
+ margin: 0;
+ padding: 0 0 5px 25px;
+}
+#jspec-report tr.even:hover + tr.body,
+#jspec-report tr.odd:hover + tr.body {
+ display: block;
+}
+#jspec-report tr td:first-child em {
+ display: block;
+ clear: both;
+ font-style: normal;
+ font-weight: normal;
+ color: #7B8D9B;
+}
+#jspec-report tr.even:hover,
+#jspec-report tr.odd:hover {
+ text-shadow: 1px 1px 1px #fff;
+ background: #F2F5F7;
+}
+#jspec-report td + td {
+ padding-right: 0;
+ width: 15px;
+}
+#jspec-report td.pass {
+ background: url(images/sprites.png) 3px -7px no-repeat;
+}
+#jspec-report td.fail {
+ background: url(images/sprites.png) 3px -158px no-repeat;
+ font-weight: bold;
+ color: #FC0D0D;
+}
+#jspec-report td.requires-implementation {
+ background: url(images/sprites.png) 3px -333px no-repeat;
+}
+#jspec-report tr.description td {
+ margin-top: 25px;
+ padding-top: 25px;
+ font-size: 12px;
+ font-weight: bold;
+ text-indent: 0;
+ color: #1a1a1a;
+}
+#jspec-report tr.description:first-child td {
+ border-top: none;
+}
+#jspec-report .assertion {
+ display: block;
+ float: left;
+ margin: 0 0 0 1px;
+ padding: 0;
+ width: 1px;
+ height: 5px;
+ background: #7B8D9B;
+}
+#jspec-report .assertion.failed {
+ background: red;
+}
+.jspec-sandbox {
+ display: none;
+}
\ No newline at end of file
--- /dev/null
+
+// JSpec - Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+;(function(){
+
+ Growl = {
+
+ // --- Version
+
+ version: '1.0.0',
+
+ /**
+ * Execute the given _cmd_, returning an array of lines from stdout.
+ *
+ * Examples:
+ *
+ * Growl.exec('growlnotify', '-m', msg)
+ *
+ * @param {string ...} cmd
+ * @return {array}
+ * @api public
+ */
+
+ exec: function(cmd) {
+ var lines = [], line
+ with (JavaImporter(java.lang, java.io)) {
+ var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments))
+ var stream = new DataInputStream(proccess.getInputStream())
+ while (line = stream.readLine())
+ lines.push(line + '')
+ stream.close()
+ }
+ return lines
+ },
+
+ /**
+ * Return the extension of the given _path_ or null.
+ *
+ * @param {string} path
+ * @return {string}
+ * @api private
+ */
+
+ extname: function(path) {
+ return path.lastIndexOf('.') != -1 ?
+ path.slice(path.lastIndexOf('.') + 1, path.length) :
+ null
+ },
+
+ /**
+ * Version of the 'growlnotify' binary.
+ *
+ * @return {string}
+ * @api private
+ */
+
+ binVersion: function() {
+ try { return this.exec('growlnotify', '-v')[0].split(' ')[1] } catch (e) {}
+ },
+
+ /**
+ * Send growl notification _msg_ with _options_.
+ *
+ * Options:
+ *
+ * - title Notification title
+ * - sticky Make the notification stick (defaults to false)
+ * - name Application name (defaults to growlnotify)
+ * - image
+ * - path to an icon sets --iconpath
+ * - path to an image sets --image
+ * - capitalized word sets --appIcon
+ * - filename uses extname as --icon
+ * - otherwise treated as --icon
+ *
+ * Examples:
+ *
+ * Growl.notify('New email')
+ * Growl.notify('5 new emails', { title: 'Thunderbird' })
+ *
+ * @param {string} msg
+ * @param {options} hash
+ * @api public
+ */
+
+ notify: function(msg, options) {
+ options = options || {}
+ var args = ['growlnotify', '-m', msg]
+ if (!this.binVersion()) throw new Error('growlnotify executable is required')
+ if (image = options.image) {
+ var flag, ext = this.extname(image)
+ flag = flag || ext == 'icns' && 'iconpath'
+ flag = flag || /^[A-Z]/.test(image) && 'appIcon'
+ flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
+ flag = flag || ext && (image = ext) && 'icon'
+ flag = flag || 'icon'
+ args.push('--' + flag, image)
+ }
+ if (options.sticky) args.push('--sticky')
+ if (options.name) args.push('--name', options.name)
+ if (options.title) args.push(options.title)
+ this.exec.apply(this, args)
+ }
+ }
+
+ JSpec.include({
+ name: 'Growl',
+ reporting: function(options){
+ var stats = JSpec.stats
+ if (stats.failures) Growl.notify('failed ' + stats.failures + ' assertions', { title: 'JSpec'})
+ else Growl.notify('passed ' + stats.passes + ' assertions', { title: 'JSpec' })
+ }
+ })
+
+})()
\ No newline at end of file
--- /dev/null
+
+// JSpec - jQuery - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+JSpec
+.requires('jQuery', 'when using jspec.jquery.js')
+.include({
+ name: 'jQuery',
+
+ // --- Initialize
+
+ init : function() {
+ jQuery.ajaxSetup({ async: false })
+ },
+
+ // --- Utilities
+
+ utilities : {
+ element: jQuery,
+ elements: jQuery,
+ sandbox : function() {
+ return jQuery('<div class="sandbox"></div>')
+ }
+ },
+
+ // --- Matchers
+
+ matchers : {
+ have_tag : "jQuery(expected, actual).length === 1",
+ have_one : "alias have_tag",
+ have_tags : "jQuery(expected, actual).length > 1",
+ have_many : "alias have_tags",
+ have_any : "alias have_tags",
+ have_child : "jQuery(actual).children(expected).length === 1",
+ have_children : "jQuery(actual).children(expected).length > 1",
+ have_text : "jQuery(actual).text() === expected",
+ have_value : "jQuery(actual).val() === expected",
+ be_enabled : "!jQuery(actual).attr('disabled')",
+ have_class : "jQuery(actual).hasClass(expected)",
+ be_animated : "jQuery(actual).queue().length > 0",
+
+ be_visible : function(actual) {
+ return jQuery(actual).css('display') != 'none' &&
+ jQuery(actual).css('visibility') != 'hidden' &&
+ jQuery(actual).attr('type') != 'hidden'
+ },
+
+ be_hidden : function(actual) {
+ return !JSpec.does(actual, 'be_visible')
+ },
+
+ have_classes : function(actual) {
+ return !JSpec.any(JSpec.toArray(arguments, 1), function(arg){
+ return !JSpec.does(actual, 'have_class', arg)
+ })
+ },
+
+ have_attr : function(actual, attr, value) {
+ return value ? jQuery(actual).attr(attr) == value:
+ jQuery(actual).attr(attr)
+ },
+
+ have_event_handlers : function(actual, expected) {
+ return jQuery(actual).data('events') ?
+ jQuery(actual).data('events').hasOwnProperty(expected) :
+ false
+ },
+
+ 'be disabled selected checked' : function(attr) {
+ return 'jQuery(actual).attr("' + attr + '")'
+ },
+
+ 'have type id title alt href src sel rev name target' : function(attr) {
+ return function(actual, value) {
+ return JSpec.does(actual, 'have_attr', attr, value)
+ }
+ }
+ }
+})
+
--- /dev/null
+
+// JSpec - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+;(function(){
+
+ JSpec = {
+ version : '4.3.2',
+ assert : true,
+ cache : {},
+ suites : [],
+ modules : [],
+ allSuites : [],
+ sharedBehaviors: [],
+ matchers : {},
+ stubbed : [],
+ options : {},
+ request : 'XMLHttpRequest' in this ? XMLHttpRequest : null,
+ stats : { specs: 0, assertions: 0, failures: 0, passes: 0, specsFinished: 0, suitesFinished: 0 },
+
+ /**
+ * Default context in which bodies are evaluated.
+ *
+ * Replace context simply by setting JSpec.context
+ * to your own like below:
+ *
+ * JSpec.context = { foo : 'bar' }
+ *
+ * Contexts can be changed within any body, this can be useful
+ * in order to provide specific helper methods to specific suites.
+ *
+ * To reset (usually in after hook) simply set to null like below:
+ *
+ * JSpec.context = null
+ *
+ */
+
+ defaultContext : {
+
+ /**
+ * Return an object used for proxy assertions.
+ * This object is used to indicate that an object
+ * should be an instance of _object_, not the constructor
+ * itself.
+ *
+ * @param {function} constructor
+ * @return {hash}
+ * @api public
+ */
+
+ an_instance_of : function(constructor) {
+ return { an_instance_of : constructor }
+ },
+
+ /**
+ * Load fixture at _path_.
+ *
+ * Fixtures are resolved as:
+ *
+ * - <path>
+ * - <path>.html
+ *
+ * @param {string} path
+ * @return {string}
+ * @api public
+ */
+
+ fixture : function(path) {
+ if (JSpec.cache[path]) return JSpec.cache[path]
+ return JSpec.cache[path] =
+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path) ||
+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path + '.html')
+ },
+
+ /**
+ * Load json fixture at _path_.
+ *
+ * JSON fixtures are resolved as:
+ *
+ * - <path>
+ * - <path>.json
+ *
+ * @param {string} path
+ * @return {object}
+ * @api public
+ */
+
+ json_fixture: function(path) {
+ if (!JSpec.cache['json:' + path])
+ JSpec.cache['json:' + path] =
+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path) ||
+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path + '.json')
+ try {
+ return eval('(' + JSpec.cache['json:' + path] + ')')
+ } catch (e) {
+ throw 'json_fixture("' + path + '"): ' + e
+ }
+ }
+ },
+
+ // --- Objects
+
+ reporters : {
+
+ /**
+ * Report to server.
+ *
+ * Options:
+ * - uri specific uri to report to.
+ * - verbose weither or not to output messages
+ * - failuresOnly output failure messages only
+ *
+ * @api public
+ */
+
+ Server : function(results, options) {
+ var uri = options.uri || 'http://' + window.location.host + '/results'
+ JSpec.post(uri, {
+ stats: JSpec.stats,
+ options: options,
+ results: map(results.allSuites, function(suite) {
+ if (suite.isExecutable())
+ return {
+ description: suite.description,
+ specs: map(suite.specs, function(spec) {
+ return {
+ description: spec.description,
+ message: !spec.passed() ? spec.failure().message : null,
+ status: spec.requiresImplementation() ? 'pending' :
+ spec.passed() ? 'pass' :
+ 'fail',
+ assertions: map(spec.assertions, function(assertion){
+ return {
+ passed: assertion.passed
+ }
+ })
+ }
+ })
+ }
+ })
+ })
+ if ('close' in main) main.close()
+ },
+
+ /**
+ * Default reporter, outputting to the DOM.
+ *
+ * Options:
+ * - reportToId id of element to output reports to, defaults to 'jspec'
+ * - failuresOnly displays only suites with failing specs
+ *
+ * @api public
+ */
+
+ DOM : function(results, options) {
+ var id = option('reportToId') || 'jspec',
+ report = document.getElementById(id),
+ failuresOnly = option('failuresOnly'),
+ classes = results.stats.failures ? 'has-failures' : ''
+ if (!report) throw 'JSpec requires the element #' + id + ' to output its reports'
+
+ function bodyContents(body) {
+ return JSpec.
+ escape(JSpec.contentsOf(body)).
+ replace(/^ */gm, function(a){ return (new Array(Math.round(a.length / 3))).join(' ') }).
+ replace(/\r\n|\r|\n/gm, '<br/>')
+ }
+
+ report.innerHTML = '<div id="jspec-report" class="' + classes + '"><div class="heading"> \
+ <span class="passes">Passes: <em>' + results.stats.passes + '</em></span> \
+ <span class="failures">Failures: <em>' + results.stats.failures + '</em></span> \
+ <span class="passes">Duration: <em>' + results.duration + '</em> ms</span> \
+ </div><table class="suites">' + map(results.allSuites, function(suite) {
+ var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran
+ if (displaySuite && suite.isExecutable())
+ return '<tr class="description"><td colspan="2">' + escape(suite.description) + '</td></tr>' +
+ map(suite.specs, function(i, spec) {
+ return '<tr class="' + (i % 2 ? 'odd' : 'even') + '">' +
+ (spec.requiresImplementation() ?
+ '<td class="requires-implementation" colspan="2">' + escape(spec.description) + '</td>' :
+ (spec.passed() && !failuresOnly) ?
+ '<td class="pass">' + escape(spec.description)+ '</td><td>' + spec.assertionsGraph() + '</td>' :
+ !spec.passed() ?
+ '<td class="fail">' + escape(spec.description) +
+ map(spec.failures(), function(a){ return '<em>' + escape(a.message) + '</em>' }).join('') +
+ '</td><td>' + spec.assertionsGraph() + '</td>' :
+ '') +
+ '<tr class="body"><td colspan="2"><pre>' + bodyContents(spec.body) + '</pre></td></tr>'
+ }).join('') + '</tr>'
+ }).join('') + '</table></div>'
+ },
+
+ /**
+ * Terminal reporter.
+ *
+ * @api public
+ */
+
+ Terminal : function(results, options) {
+ var failuresOnly = option('failuresOnly')
+ print(color("\n Passes: ", 'bold') + color(results.stats.passes, 'green') +
+ color(" Failures: ", 'bold') + color(results.stats.failures, 'red') +
+ color(" Duration: ", 'bold') + color(results.duration, 'green') + " ms \n")
+
+ function indent(string) {
+ return string.replace(/^(.)/gm, ' $1')
+ }
+
+ each(results.allSuites, function(suite) {
+ var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran
+ if (displaySuite && suite.isExecutable()) {
+ print(color(' ' + suite.description, 'bold'))
+ each(suite.specs, function(spec){
+ var assertionsGraph = inject(spec.assertions, '', function(graph, assertion){
+ return graph + color('.', assertion.passed ? 'green' : 'red')
+ })
+ if (spec.requiresImplementation())
+ print(color(' ' + spec.description, 'blue') + assertionsGraph)
+ else if (spec.passed() && !failuresOnly)
+ print(color(' ' + spec.description, 'green') + assertionsGraph)
+ else if (!spec.passed())
+ print(color(' ' + spec.description, 'red') + assertionsGraph +
+ "\n" + indent(map(spec.failures(), function(a){ return a.message }).join("\n")) + "\n")
+ })
+ print("")
+ }
+ })
+
+ quit(results.stats.failures)
+ }
+ },
+
+ Assertion : function(matcher, actual, expected, negate) {
+ extend(this, {
+ message: '',
+ passed: false,
+ actual: actual,
+ negate: negate,
+ matcher: matcher,
+ expected: expected,
+
+ // Report assertion results
+
+ report : function() {
+ if (JSpec.assert)
+ this.passed ? JSpec.stats.passes++ : JSpec.stats.failures++
+ return this
+ },
+
+ // Run the assertion
+
+ run : function() {
+ // TODO: remove unshifting
+ expected.unshift(actual)
+ this.result = matcher.match.apply(this, expected)
+ this.passed = negate ? !this.result : this.result
+ if (!this.passed) this.message = matcher.message.call(this, actual, expected, negate, matcher.name)
+ return this
+ }
+ })
+ },
+
+ ProxyAssertion : function(object, method, times, negate) {
+ var self = this,
+ old = object[method]
+
+ // Proxy
+
+ object[method] = function(){
+ var args = toArray(arguments),
+ result = old.apply(object, args)
+ self.calls.push({ args : args, result : result })
+ return result
+ }
+
+ // Times
+
+ this.times = {
+ once : 1,
+ twice : 2
+ }[times] || times || 1
+
+ extend(this, {
+ calls: [],
+ message: '',
+ defer: true,
+ passed: false,
+ negate: negate,
+ object: object,
+ method: method,
+
+ // Proxy return value
+
+ and_return : function(result) {
+ this.expectedResult = result
+ return this
+ },
+
+ // Proxy arguments passed
+
+ with_args : function() {
+ this.expectedArgs = toArray(arguments)
+ return this
+ },
+
+ // Check if any calls have failing results
+
+ anyResultsFail : function() {
+ return any(this.calls, function(call){
+ return self.expectedResult.an_instance_of ?
+ call.result.constructor != self.expectedResult.an_instance_of:
+ !equal(self.expectedResult, call.result)
+ })
+ },
+
+ // Check if any calls have passing results
+
+ anyResultsPass : function() {
+ return any(this.calls, function(call){
+ return self.expectedResult.an_instance_of ?
+ call.result.constructor == self.expectedResult.an_instance_of:
+ equal(self.expectedResult, call.result)
+ })
+ },
+
+ // Return the passing result
+
+ passingResult : function() {
+ return this.anyResultsPass().result
+ },
+
+ // Return the failing result
+
+ failingResult : function() {
+ return this.anyResultsFail().result
+ },
+
+ // Check if any arguments fail
+
+ anyArgsFail : function() {
+ return any(this.calls, function(call){
+ return any(self.expectedArgs, function(i, arg){
+ if (arg == null) return call.args[i] == null
+ return arg.an_instance_of ?
+ call.args[i].constructor != arg.an_instance_of:
+ !equal(arg, call.args[i])
+
+ })
+ })
+ },
+
+ // Check if any arguments pass
+
+ anyArgsPass : function() {
+ return any(this.calls, function(call){
+ return any(self.expectedArgs, function(i, arg){
+ return arg.an_instance_of ?
+ call.args[i].constructor == arg.an_instance_of:
+ equal(arg, call.args[i])
+
+ })
+ })
+ },
+
+ // Return the passing args
+
+ passingArgs : function() {
+ return this.anyArgsPass().args
+ },
+
+ // Return the failing args
+
+ failingArgs : function() {
+ return this.anyArgsFail().args
+ },
+
+ // Report assertion results
+
+ report : function() {
+ if (JSpec.assert)
+ this.passed ? ++JSpec.stats.passes : ++JSpec.stats.failures
+ return this
+ },
+
+ // Run the assertion
+
+ run : function() {
+ var methodString = 'expected ' + object.toString() + '.' + method + '()' + (negate ? ' not' : '' )
+
+ function times(n) {
+ return n > 2 ? n + ' times' : { 1: 'once', 2: 'twice' }[n]
+ }
+
+ if (this.expectedResult != null && (negate ? this.anyResultsPass() : this.anyResultsFail()))
+ this.message = methodString + ' to return ' + puts(this.expectedResult) +
+ ' but ' + (negate ? 'it did' : 'got ' + puts(this.failingResult()))
+
+ if (this.expectedArgs && (negate ? !this.expectedResult && this.anyArgsPass() : this.anyArgsFail()))
+ this.message = methodString + ' to be called with ' + puts.apply(this, this.expectedArgs) +
+ ' but was' + (negate ? '' : ' called with ' + puts.apply(this, this.failingArgs()))
+
+ if (negate ? !this.expectedResult && !this.expectedArgs && this.calls.length >= this.times : this.calls.length != this.times)
+ this.message = methodString + ' to be called ' + times(this.times) +
+ ', but ' + (this.calls.length == 0 ? ' was not called' : ' was called ' + times(this.calls.length))
+
+ if (!this.message.length)
+ this.passed = true
+
+ return this
+ }
+ })
+ },
+
+ /**
+ * Specification Suite block object.
+ *
+ * @param {string} description
+ * @param {function} body
+ * @api private
+ */
+
+ Suite : function(description, body, isShared) {
+ var self = this
+ extend(this, {
+ body: body,
+ description: description,
+ suites: [],
+ sharedBehaviors: [],
+ specs: [],
+ ran: false,
+ shared: isShared,
+ hooks: { 'before' : [], 'after' : [],
+ 'before_each' : [], 'after_each' : [],
+ 'before_nested' : [], 'after_nested' : []},
+
+ // Add a spec to the suite
+
+ addSpec : function(description, body) {
+ var spec = new JSpec.Spec(description, body)
+ this.specs.push(spec)
+ JSpec.stats.specs++ // TODO: abstract
+ spec.suite = this
+ },
+
+ // Add a before hook to the suite
+
+ addBefore : function(options, body) {
+ body.options = options || {}
+ this.befores.push(body)
+ },
+
+ // Add an after hook to the suite
+
+ addAfter : function(options, body) {
+ body.options = options || {}
+ this.afters.unshift(body)
+ },
+
+ // Add a hook to the suite
+
+ addHook : function(hook, body) {
+ this.hooks[hook].push(body)
+ },
+
+ // Add a nested suite
+
+ addSuite : function(description, body, isShared) {
+ var suite = new JSpec.Suite(description, body, isShared)
+ JSpec.allSuites.push(suite)
+ suite.name = suite.description
+ suite.description = this.description + ' ' + suite.description
+ this.suites.push(suite)
+ suite.suite = this
+ },
+
+ // Invoke a hook in context to this suite
+
+ hook : function(hook) {
+ if (hook != 'before' && hook != 'after')
+ if (this.suite) this.suite.hook(hook)
+
+ each(this.hooks[hook], function(body) {
+ JSpec.evalBody(body, "Error in hook '" + hook + "', suite '" + self.description + "': ")
+ })
+ },
+
+ // Check if nested suites are present
+
+ hasSuites : function() {
+ return this.suites.length
+ },
+
+ // Check if this suite has specs
+
+ hasSpecs : function() {
+ return this.specs.length
+ },
+
+ // Check if the entire suite passed
+
+ passed : function() {
+ return !any(this.specs, function(spec){
+ return !spec.passed()
+ })
+ },
+
+ isShared : function(){
+ return this.shared
+ },
+
+ isExecutable : function() {
+ return !this.isShared() && this.hasSpecs()
+ }
+ })
+ },
+
+ /**
+ * Specification block object.
+ *
+ * @param {string} description
+ * @param {function} body
+ * @api private
+ */
+
+ Spec : function(description, body) {
+ extend(this, {
+ body: body,
+ description: description,
+ assertions: [],
+
+ // Add passing assertion
+
+ pass : function(message) {
+ this.assertions.push({ passed: true, message: message })
+ if (JSpec.assert) ++JSpec.stats.passes
+ },
+
+ // Add failing assertion
+
+ fail : function(message) {
+ this.assertions.push({ passed: false, message: message })
+ if (JSpec.assert) ++JSpec.stats.failures
+ },
+
+ // Run deferred assertions
+
+ runDeferredAssertions : function() {
+ each(this.assertions, function(assertion){
+ if (assertion.defer) assertion.run().report(), hook('afterAssertion', assertion)
+ })
+ },
+
+ // Find first failing assertion
+
+ failure : function() {
+ return find(this.assertions, function(assertion){
+ return !assertion.passed
+ })
+ },
+
+ // Find all failing assertions
+
+ failures : function() {
+ return select(this.assertions, function(assertion){
+ return !assertion.passed
+ })
+ },
+
+ // Weither or not the spec passed
+
+ passed : function() {
+ return !this.failure()
+ },
+
+ // Weither or not the spec requires implementation (no assertions)
+
+ requiresImplementation : function() {
+ return this.assertions.length == 0
+ },
+
+ // Sprite based assertions graph
+
+ assertionsGraph : function() {
+ return map(this.assertions, function(assertion){
+ return '<span class="assertion ' + (assertion.passed ? 'passed' : 'failed') + '"></span>'
+ }).join('')
+ }
+ })
+ },
+
+ Module : function(methods) {
+ extend(this, methods)
+ },
+
+ JSON : {
+
+ /**
+ * Generic sequences.
+ */
+
+ meta : {
+ '\b' : '\\b',
+ '\t' : '\\t',
+ '\n' : '\\n',
+ '\f' : '\\f',
+ '\r' : '\\r',
+ '"' : '\\"',
+ '\\' : '\\\\'
+ },
+
+ /**
+ * Escapable sequences.
+ */
+
+ escapable : /[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
+
+ /**
+ * JSON encode _object_.
+ *
+ * @param {mixed} object
+ * @return {string}
+ * @api private
+ */
+
+ encode : function(object) {
+ var self = this
+ if (object == undefined || object == null) return 'null'
+ if (object === true) return 'true'
+ if (object === false) return 'false'
+ switch (typeof object) {
+ case 'number': return object
+ case 'string': return this.escapable.test(object) ?
+ '"' + object.replace(this.escapable, function (a) {
+ return typeof self.meta[a] === 'string' ? self.meta[a] :
+ '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4)
+ }) + '"' :
+ '"' + object + '"'
+ case 'object':
+ if (object.constructor == Array)
+ return '[' + map(object, function(val){
+ return self.encode(val)
+ }).join(', ') + ']'
+ else if (object)
+ return '{' + map(object, function(key, val){
+ return self.encode(key) + ':' + self.encode(val)
+ }).join(', ') + '}'
+ }
+ return 'null'
+ }
+ },
+
+ // --- DSLs
+
+ DSLs : {
+ snake : {
+ expect : function(actual){
+ return JSpec.expect(actual)
+ },
+
+ describe : function(description, body) {
+ return JSpec.currentSuite.addSuite(description, body, false)
+ },
+
+ it : function(description, body) {
+ return JSpec.currentSuite.addSpec(description, body)
+ },
+
+ before : function(body) {
+ return JSpec.currentSuite.addHook('before', body)
+ },
+
+ after : function(body) {
+ return JSpec.currentSuite.addHook('after', body)
+ },
+
+ before_each : function(body) {
+ return JSpec.currentSuite.addHook('before_each', body)
+ },
+
+ after_each : function(body) {
+ return JSpec.currentSuite.addHook('after_each', body)
+ },
+
+ before_nested : function(body) {
+ return JSpec.currentSuite.addHook('before_nested', body)
+ },
+
+ after_nested : function(body){
+ return JSpec.currentSuite.addhook('after_nested', body)
+ },
+
+ shared_behaviors_for : function(description, body){
+ return JSpec.currentSuite.addSuite(description, body, true)
+ },
+
+ should_behave_like : function(description) {
+ return JSpec.shareBehaviorsOf(description)
+ }
+ }
+ },
+
+ // --- Methods
+
+ /**
+ * Check if _value_ is 'stop'. For use as a
+ * utility callback function.
+ *
+ * @param {mixed} value
+ * @return {bool}
+ * @api public
+ */
+
+ haveStopped : function(value) {
+ return value === 'stop'
+ },
+
+ /**
+ * Include _object_ which may be a hash or Module instance.
+ *
+ * @param {hash, Module} object
+ * @return {JSpec}
+ * @api public
+ */
+
+ include : function(object) {
+ var module = object.constructor == JSpec.Module ? object : new JSpec.Module(object)
+ this.modules.push(module)
+ if ('init' in module) module.init()
+ if ('utilities' in module) extend(this.defaultContext, module.utilities)
+ if ('matchers' in module) this.addMatchers(module.matchers)
+ if ('reporters' in module) extend(this.reporters, module.reporters)
+ if ('DSLs' in module)
+ each(module.DSLs, function(name, methods){
+ JSpec.DSLs[name] = JSpec.DSLs[name] || {}
+ extend(JSpec.DSLs[name], methods)
+ })
+ return this
+ },
+
+ /**
+ * Add a module hook _name_, which is immediately
+ * called per module with the _args_ given. An array of
+ * hook return values is returned.
+ *
+ * @param {name} string
+ * @param {...} args
+ * @return {array}
+ * @api private
+ */
+
+ hook : function(name, args) {
+ args = toArray(arguments, 1)
+ return inject(JSpec.modules, [], function(results, module){
+ if (typeof module[name] == 'function')
+ results.push(JSpec.evalHook(module, name, args))
+ })
+ },
+
+ /**
+ * Eval _module_ hook _name_ with _args_. Evaluates in context
+ * to the module itself, JSpec, and JSpec.context.
+ *
+ * @param {Module} module
+ * @param {string} name
+ * @param {array} args
+ * @return {mixed}
+ * @api private
+ */
+
+ evalHook : function(module, name, args) {
+ hook('evaluatingHookBody', module, name)
+ return module[name].apply(module, args)
+ },
+
+ /**
+ * Same as hook() however accepts only one _arg_ which is
+ * considered immutable. This function passes the arg
+ * to the first module, then passes the return value of the last
+ * module called, to the following module.
+ *
+ * @param {string} name
+ * @param {mixed} arg
+ * @return {mixed}
+ * @api private
+ */
+
+ hookImmutable : function(name, arg) {
+ return inject(JSpec.modules, arg, function(result, module){
+ if (typeof module[name] == 'function')
+ return JSpec.evalHook(module, name, [result])
+ })
+ },
+
+ /**
+ * Find a shared example suite by its description or name.
+ * First searches parent tree of suites for shared behavior
+ * before falling back to global scoped nested behaviors.
+ *
+ * @param {string} description
+ * @return {Suite}
+ * @api private
+ */
+
+ findSharedBehavior : function(description) {
+ var behavior
+ return (behavior = JSpec.findLocalSharedBehavior(description))
+ ? behavior
+ : JSpec.findGlobalSharedBehavior(description)
+ },
+
+ /**
+ * Find a shared example suite within the current suite's
+ * parent tree by its description or name.
+ *
+ * @param {string} description
+ * @return {Suite}
+ * @api private
+ */
+
+ findLocalSharedBehavior : function(description) {
+ var behavior,
+ currentSuite = JSpec.currentSuite.suite
+ while (currentSuite)
+ if (behavior = find(currentSuite.suites, JSpec.suiteDescriptionPredicate(description)))
+ return behavior
+ else
+ currentSuite = currentSuite.suite
+ },
+
+ /**
+ * Find a shared example suite within the global
+ * scope by its description or name.
+ *
+ * @param {string} description
+ * @return {Suite}
+ * @api private
+ */
+
+ findGlobalSharedBehavior : function(description) {
+ return find(JSpec.suites, JSpec.suiteDescriptionPredicate(description))
+ },
+
+ /**
+ * Build a predicate that will match a suite based on name or description
+ *
+ * @param {string} description
+ * @return {function}
+ * @api private
+ */
+
+ suiteDescriptionPredicate : function(description) {
+ return function(suite){
+ return suite.name === description ||
+ suite.description === description
+ }
+ },
+
+ /**
+ * Share behaviors (specs) of the given suite with
+ * the current suite.
+ *
+ * @param {string} description
+ * @api public
+ */
+
+ shareBehaviorsOf : function(description) {
+ var suite = JSpec.findSharedBehavior(description)
+ if (suite)
+ JSpec.evalBody(suite.body)
+ else
+ throw new Error("failed to find shared behaviors named `" + description + "'")
+ },
+
+
+ /**
+ * Convert arguments to an array.
+ *
+ * @param {object} arguments
+ * @param {int} offset
+ * @return {array}
+ * @api public
+ */
+
+ toArray : function(arguments, offset) {
+ return Array.prototype.slice.call(arguments, offset || 0)
+ },
+
+ /**
+ * Return ANSI-escaped colored string.
+ *
+ * @param {string} string
+ * @param {string} color
+ * @return {string}
+ * @api public
+ */
+
+ color : function(string, color) {
+ if (option('disableColors')) {
+ return string
+ } else {
+ return "\u001B[" + {
+ bold : 1,
+ black : 30,
+ red : 31,
+ green : 32,
+ yellow : 33,
+ blue : 34,
+ magenta : 35,
+ cyan : 36,
+ white : 37
+ }[color] + 'm' + string + "\u001B[0m"
+ }
+ },
+
+ /**
+ * Default matcher message callback.
+ *
+ * @api private
+ */
+
+ defaultMatcherMessage : function(actual, expected, negate, name) {
+ return 'expected ' + puts(actual) + ' to ' +
+ (negate ? 'not ' : '') +
+ name.replace(/_/g, ' ') +
+ ' ' + (expected.length > 1 ?
+ puts.apply(this, expected.slice(1)) :
+ '')
+ },
+
+ /**
+ * Normalize a matcher message.
+ *
+ * When no messge callback is present the defaultMatcherMessage
+ * will be assigned, will suffice for most matchers.
+ *
+ * @param {hash} matcher
+ * @return {hash}
+ * @api public
+ */
+
+ normalizeMatcherMessage : function(matcher) {
+ if (typeof matcher.message != 'function')
+ matcher.message = this.defaultMatcherMessage
+ return matcher
+ },
+
+ /**
+ * Normalize a matcher body
+ *
+ * This process allows the following conversions until
+ * the matcher is in its final normalized hash state.
+ *
+ * - '==' becomes 'actual == expected'
+ * - 'actual == expected' becomes 'return actual == expected'
+ * - function(actual, expected) { return actual == expected } becomes
+ * { match : function(actual, expected) { return actual == expected }}
+ *
+ * @param {mixed} body
+ * @return {hash}
+ * @api public
+ */
+
+ normalizeMatcherBody : function(body) {
+ var captures
+ switch (body.constructor) {
+ case String:
+ if (captures = body.match(/^alias (\w+)/)) return JSpec.matchers[last(captures)]
+ if (body.length < 4) body = 'actual ' + body + ' expected'
+ return { match: function(actual, expected) { return eval(body) }}
+
+ case Function:
+ return { match: body }
+
+ default:
+ return body
+ }
+ },
+
+ /**
+ * Get option value. This method first checks if
+ * the option key has been set via the query string,
+ * otherwise returning the options hash value.
+ *
+ * @param {string} key
+ * @return {mixed}
+ * @api public
+ */
+
+ option : function(key) {
+ return (value = query(key)) !== null ? value :
+ JSpec.options[key] || null
+ },
+
+ /**
+ * Check if object _a_, is equal to object _b_.
+ *
+ * @param {object} a
+ * @param {object} b
+ * @return {bool}
+ * @api private
+ */
+
+ equal: function(a, b) {
+ if (typeof a != typeof b) return
+ if (a === b) return true
+ if (a instanceof RegExp)
+ return a.toString() === b.toString()
+ if (a instanceof Date)
+ return Number(a) === Number(b)
+ if (typeof a != 'object') return
+ if (a.length !== undefined)
+ if (a.length !== b.length) return
+ else
+ for (var i = 0, len = a.length; i < len; ++i)
+ if (!equal(a[i], b[i]))
+ return
+ for (var key in a)
+ if (!equal(a[key], b[key]))
+ return
+ return true
+ },
+
+ /**
+ * Return last element of an array.
+ *
+ * @param {array} array
+ * @return {object}
+ * @api public
+ */
+
+ last : function(array) {
+ return array[array.length - 1]
+ },
+
+ /**
+ * Convert object(s) to a print-friend string.
+ *
+ * @param {...} object
+ * @return {string}
+ * @api public
+ */
+
+ puts : function(object) {
+ if (arguments.length > 1)
+ return map(toArray(arguments), function(arg){
+ return puts(arg)
+ }).join(', ')
+ if (object === undefined) return 'undefined'
+ if (object === null) return 'null'
+ if (object === true) return 'true'
+ if (object === false) return 'false'
+ if (object.an_instance_of) return 'an instance of ' + object.an_instance_of.name
+ if (object.jquery && object.selector.length > 0) return 'selector ' + puts(object.selector)
+ if (object.jquery) return object.get(0).outerHTML
+ if (object.nodeName) return object.outerHTML
+ switch (object.constructor) {
+ case Function: return object.name || object
+ case String:
+ return '"' + object
+ .replace(/"/g, '\\"')
+ .replace(/\n/g, '\\n')
+ .replace(/\t/g, '\\t')
+ + '"'
+ case Array:
+ return inject(object, '[', function(b, v){
+ return b + ', ' + puts(v)
+ }).replace('[,', '[') + ' ]'
+ case Object:
+ object.__hit__ = true
+ return inject(object, '{', function(b, k, v) {
+ if (k == '__hit__') return b
+ return b + ', ' + k + ': ' + (v && v.__hit__ ? '<circular reference>' : puts(v))
+ }).replace('{,', '{') + ' }'
+ default:
+ return object.toString()
+ }
+ },
+
+ /**
+ * Parse an XML String and return a 'document'.
+ *
+ * @param {string} text
+ * @return {document}
+ * @api public
+ */
+
+ parseXML : function(text) {
+ var xmlDoc
+ if (window.DOMParser)
+ xmlDoc = (new DOMParser()).parseFromString(text, "text/xml")
+ else {
+ xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
+ xmlDoc.async = "false"
+ xmlDoc.loadXML(text)
+ }
+ return xmlDoc
+ },
+
+ /**
+ * Escape HTML.
+ *
+ * @param {string} html
+ * @return {string}
+ * @api public
+ */
+
+ escape : function(html) {
+ return html.toString()
+ .replace(/&/gmi, '&')
+ .replace(/"/gmi, '"')
+ .replace(/>/gmi, '>')
+ .replace(/</gmi, '<')
+ },
+
+ /**
+ * Perform an assertion without reporting.
+ *
+ * This method is primarily used for internal
+ * matchers in order retain DRYness. May be invoked
+ * like below:
+ *
+ * does('foo', 'eql', 'foo')
+ * does([1,2], 'include', 1, 2)
+ *
+ * External hooks are not run for internal assertions
+ * performed by does().
+ *
+ * @param {mixed} actual
+ * @param {string} matcher
+ * @param {...} expected
+ * @return {mixed}
+ * @api private
+ */
+
+ does : function(actual, matcher, expected) {
+ var assertion = new JSpec.Assertion(JSpec.matchers[matcher], actual, toArray(arguments, 2))
+ return assertion.run().result
+ },
+
+ /**
+ * Perform an assertion.
+ *
+ * expect(true).to('be', true)
+ * expect('foo').not_to('include', 'bar')
+ * expect([1, [2]]).to('include', 1, [2])
+ *
+ * @param {mixed} actual
+ * @return {hash}
+ * @api public
+ */
+
+ expect : function(actual) {
+ function assert(matcher, args, negate) {
+ var expected = toArray(args, 1)
+ matcher.negate = negate
+ var assertion = new JSpec.Assertion(matcher, actual, expected, negate)
+ hook('beforeAssertion', assertion)
+ if (matcher.defer) assertion.run()
+ else JSpec.currentSpec.assertions.push(assertion.run().report()), hook('afterAssertion', assertion)
+ return assertion.result
+ }
+
+ function to(matcher) {
+ return assert(matcher, arguments, false)
+ }
+
+ function not_to(matcher) {
+ return assert(matcher, arguments, true)
+ }
+
+ return {
+ to : to,
+ should : to,
+ not_to: not_to,
+ should_not : not_to
+ }
+ },
+
+ /**
+ * Strim whitespace or chars.
+ *
+ * @param {string} string
+ * @param {string} chars
+ * @return {string}
+ * @api public
+ */
+
+ strip : function(string, chars) {
+ return string.
+ replace(new RegExp('[' + (chars || '\\s') + ']*$'), '').
+ replace(new RegExp('^[' + (chars || '\\s') + ']*'), '')
+ },
+
+ /**
+ * Call an iterator callback with arguments a, or b
+ * depending on the arity of the callback.
+ *
+ * @param {function} callback
+ * @param {mixed} a
+ * @param {mixed} b
+ * @return {mixed}
+ * @api private
+ */
+
+ callIterator : function(callback, a, b) {
+ return callback.length == 1 ? callback(b) : callback(a, b)
+ },
+
+ /**
+ * Extend an object with another.
+ *
+ * @param {object} object
+ * @param {object} other
+ * @api public
+ */
+
+ extend : function(object, other) {
+ each(other, function(property, value){
+ object[property] = value
+ })
+ },
+
+ /**
+ * Iterate an object, invoking the given callback.
+ *
+ * @param {hash, array} object
+ * @param {function} callback
+ * @return {JSpec}
+ * @api public
+ */
+
+ each : function(object, callback) {
+ if (object.constructor == Array)
+ for (var i = 0, len = object.length; i < len; ++i)
+ callIterator(callback, i, object[i])
+ else
+ for (var key in object)
+ if (object.hasOwnProperty(key))
+ callIterator(callback, key, object[key])
+ },
+
+ /**
+ * Iterate with memo.
+ *
+ * @param {hash, array} object
+ * @param {object} memo
+ * @param {function} callback
+ * @return {object}
+ * @api public
+ */
+
+ inject : function(object, memo, callback) {
+ each(object, function(key, value){
+ memo = (callback.length == 2 ?
+ callback(memo, value):
+ callback(memo, key, value)) ||
+ memo
+ })
+ return memo
+ },
+
+ /**
+ * Destub _object_'s _method_. When no _method_ is passed
+ * all stubbed methods are destubbed. When no arguments
+ * are passed every object found in JSpec.stubbed will be
+ * destubbed.
+ *
+ * @param {mixed} object
+ * @param {string} method
+ * @api public
+ */
+
+ destub : function(object, method) {
+ var captures
+ if (method) {
+ if (object['__prototype__' + method])
+ delete object[method]
+ else
+ object[method] = object['__original__' + method]
+ delete object['__prototype__' + method]
+ delete object['__original____' + method]
+ }
+ else if (object) {
+ for (var key in object)
+ if (captures = key.match(/^(?:__prototype__|__original__)(.*)/))
+ destub(object, captures[1])
+ }
+ else
+ while (JSpec.stubbed.length)
+ destub(JSpec.stubbed.shift())
+ },
+
+ /**
+ * Stub _object_'s _method_.
+ *
+ * stub(foo, 'toString').and_return('bar')
+ *
+ * @param {mixed} object
+ * @param {string} method
+ * @return {hash}
+ * @api public
+ */
+
+ stub : function(object, method) {
+ hook('stubbing', object, method)
+ JSpec.stubbed.push(object)
+ var type = object.hasOwnProperty(method) ? '__original__' : '__prototype__'
+ object[type + method] = object[method]
+ object[method] = function(){}
+ return {
+ and_return : function(value) {
+ if (typeof value == 'function') object[method] = value
+ else object[method] = function(){ return value }
+ }
+ }
+ },
+
+ /**
+ * Map callback return values.
+ *
+ * @param {hash, array} object
+ * @param {function} callback
+ * @return {array}
+ * @api public
+ */
+
+ map : function(object, callback) {
+ return inject(object, [], function(memo, key, value){
+ memo.push(callIterator(callback, key, value))
+ })
+ },
+
+ /**
+ * Returns the first matching expression or null.
+ *
+ * @param {hash, array} object
+ * @param {function} callback
+ * @return {mixed}
+ * @api public
+ */
+
+ any : function(object, callback) {
+ return inject(object, null, function(state, key, value){
+ if (state == undefined)
+ return callIterator(callback, key, value) ? value : state
+ })
+ },
+
+ /**
+ * Returns an array of values collected when the callback
+ * given evaluates to true.
+ *
+ * @param {hash, array} object
+ * @return {function} callback
+ * @return {array}
+ * @api public
+ */
+
+ select : function(object, callback) {
+ return inject(object, [], function(selected, key, value){
+ if (callIterator(callback, key, value))
+ selected.push(value)
+ })
+ },
+
+ /**
+ * Define matchers.
+ *
+ * @param {hash} matchers
+ * @api public
+ */
+
+ addMatchers : function(matchers) {
+ each(matchers, function(name, body){
+ JSpec.addMatcher(name, body)
+ })
+ },
+
+ /**
+ * Define a matcher.
+ *
+ * @param {string} name
+ * @param {hash, function, string} body
+ * @api public
+ */
+
+ addMatcher : function(name, body) {
+ hook('addingMatcher', name, body)
+ if (name.indexOf(' ') != -1) {
+ var matchers = name.split(/\s+/)
+ var prefix = matchers.shift()
+ each(matchers, function(name) {
+ JSpec.addMatcher(prefix + '_' + name, body(name))
+ })
+ }
+ this.matchers[name] = this.normalizeMatcherMessage(this.normalizeMatcherBody(body))
+ this.matchers[name].name = name
+ },
+
+ /**
+ * Add a root suite to JSpec.
+ *
+ * @param {string} description
+ * @param {body} function
+ * @api public
+ */
+
+ describe : function(description, body) {
+ var suite = new JSpec.Suite(description, body, false)
+ hook('addingSuite', suite)
+ this.allSuites.push(suite)
+ this.suites.push(suite)
+ },
+
+ /**
+ * Add a shared example suite to JSpec.
+ *
+ * @param {string} description
+ * @param {body} function
+ * @api public
+ */
+
+ shared_behaviors_for : function(description, body) {
+ var suite = new JSpec.Suite(description, body, true)
+ hook('addingSuite', suite)
+ this.allSuites.push(suite)
+ this.suites.push(suite)
+ },
+
+ /**
+ * Return the contents of a function body.
+ *
+ * @param {function} body
+ * @return {string}
+ * @api public
+ */
+
+ contentsOf : function(body) {
+ return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]
+ },
+
+ /**
+ * Evaluate a JSpec capture body.
+ *
+ * @param {function} body
+ * @param {string} errorMessage (optional)
+ * @return {Type}
+ * @api private
+ */
+
+ evalBody : function(body, errorMessage) {
+ var dsl = this.DSL || this.DSLs.snake
+ var matchers = this.matchers
+ var context = this.context || this.defaultContext
+ var contents = this.contentsOf(body)
+ hook('evaluatingBody', dsl, matchers, context, contents)
+ with (dsl){ with (context) { with (matchers) { eval(contents) }}}
+ },
+
+ /**
+ * Pre-process a string of JSpec.
+ *
+ * @param {string} input
+ * @return {string}
+ * @api private
+ */
+
+ preprocess : function(input) {
+ if (typeof input != 'string') return
+ input = hookImmutable('preprocessing', input)
+ return input.
+ replace(/\t/g, ' ').
+ replace(/\r\n|\n|\r/g, '\n').
+ split('__END__')[0].
+ replace(/([\w\.]+)\.(stub|destub)\((.*?)\)$/gm, '$2($1, $3)').
+ replace(/describe\s+(.*?)$/gm, 'describe($1, function(){').
+ replace(/shared_behaviors_for\s+(.*?)$/gm, 'shared_behaviors_for($1, function(){').
+ replace(/^\s+it\s+(.*?)$/gm, ' it($1, function(){').
+ replace(/^ *(before_nested|after_nested|before_each|after_each|before|after)(?= |\n|$)/gm, 'JSpec.currentSuite.addHook("$1", function(){').
+ replace(/^\s*end(?=\s|$)/gm, '});').
+ replace(/-\{/g, 'function(){').
+ replace(/(\d+)\.\.(\d+)/g, function(_, a, b){ return range(a, b) }).
+ replace(/\.should([_\.]not)?[_\.](\w+)(?: |;|$)(.*)$/gm, '.should$1_$2($3)').
+ replace(/([\/\s]*)(.+?)\.(should(?:[_\.]not)?)[_\.](\w+)\((.*)\)\s*;?$/gm, '$1 expect($2).$3($4, $5)').
+ replace(/, \)/g, ')').
+ replace(/should\.not/g, 'should_not')
+ },
+
+ /**
+ * Create a range string which can be evaluated to a native array.
+ *
+ * @param {int} start
+ * @param {int} end
+ * @return {string}
+ * @api public
+ */
+
+ range : function(start, end) {
+ var current = parseInt(start), end = parseInt(end), values = [current]
+ if (end > current) while (++current <= end) values.push(current)
+ else while (--current >= end) values.push(current)
+ return '[' + values + ']'
+ },
+
+ /**
+ * Report on the results.
+ *
+ * @api public
+ */
+
+ report : function() {
+ this.duration = Number(new Date) - this.start
+ hook('reporting', JSpec.options)
+ new (JSpec.options.reporter || JSpec.reporters.DOM)(JSpec, JSpec.options)
+ },
+
+ /**
+ * Run the spec suites. Options are merged
+ * with JSpec options when present.
+ *
+ * @param {hash} options
+ * @return {JSpec}
+ * @api public
+ */
+
+ run : function(options) {
+ if (any(hook('running'), haveStopped)) return this
+ if (options) extend(this.options, options)
+ this.start = Number(new Date)
+ each(this.suites, function(suite) { JSpec.runSuite(suite) })
+ return this
+ },
+
+ /**
+ * Run a suite.
+ *
+ * @param {Suite} suite
+ * @api public
+ */
+
+ runSuite : function(suite) {
+ if (!suite.isShared())
+ {
+ this.currentSuite = suite
+ this.evalBody(suite.body)
+ suite.ran = true
+ hook('beforeSuite', suite), suite.hook('before'), suite.hook('before_nested')
+ each(suite.specs, function(spec) {
+ hook('beforeSpec', spec)
+ suite.hook('before_each')
+ JSpec.runSpec(spec)
+ hook('afterSpec', spec)
+ suite.hook('after_each')
+ })
+ if (suite.hasSuites()) {
+ each(suite.suites, function(suite) {
+ JSpec.runSuite(suite)
+ })
+ }
+ hook('afterSuite', suite), suite.hook('after_nested'), suite.hook('after')
+ this.stats.suitesFinished++
+ }
+ },
+
+ /**
+ * Report a failure for the current spec.
+ *
+ * @param {string} message
+ * @api public
+ */
+
+ fail : function(message) {
+ JSpec.currentSpec.fail(message)
+ },
+
+ /**
+ * Report a passing assertion for the current spec.
+ *
+ * @param {string} message
+ * @api public
+ */
+
+ pass : function(message) {
+ JSpec.currentSpec.pass(message)
+ },
+
+ /**
+ * Run a spec.
+ *
+ * @param {Spec} spec
+ * @api public
+ */
+
+ runSpec : function(spec) {
+ this.currentSpec = spec
+ try { this.evalBody(spec.body) }
+ catch (e) { fail(e) }
+ spec.runDeferredAssertions()
+ destub()
+ this.stats.specsFinished++
+ this.stats.assertions += spec.assertions.length
+ },
+
+ /**
+ * Require a dependency, with optional message.
+ *
+ * @param {string} dependency
+ * @param {string} message (optional)
+ * @return {JSpec}
+ * @api public
+ */
+
+ requires : function(dependency, message) {
+ hook('requiring', dependency, message)
+ try { eval(dependency) }
+ catch (e) { throw 'JSpec depends on ' + dependency + ' ' + message }
+ return this
+ },
+
+ /**
+ * Query against the current query strings keys
+ * or the queryString specified.
+ *
+ * @param {string} key
+ * @param {string} queryString
+ * @return {string, null}
+ * @api private
+ */
+
+ query : function(key, queryString) {
+ var queryString = (queryString || (main.location ? main.location.search : null) || '').substring(1)
+ return inject(queryString.split('&'), null, function(value, pair){
+ parts = pair.split('=')
+ return parts[0] == key ? parts[1].replace(/%20|\+/gmi, ' ') : value
+ })
+ },
+
+ /**
+ * Ad-hoc POST request for JSpec server usage.
+ *
+ * @param {string} uri
+ * @param {string} data
+ * @api private
+ */
+
+ post : function(uri, data) {
+ if (any(hook('posting', uri, data), haveStopped)) return
+ var request = this.xhr()
+ request.open('POST', uri, false)
+ request.setRequestHeader('Content-Type', 'application/json')
+ request.send(JSpec.JSON.encode(data))
+ },
+
+ /**
+ * Instantiate an XMLHttpRequest.
+ *
+ * Here we utilize IE's lame ActiveXObjects first which
+ * allow IE access serve files via the file: protocol, otherwise
+ * we then default to XMLHttpRequest.
+ *
+ * @return {XMLHttpRequest, ActiveXObject}
+ * @api private
+ */
+
+ xhr : function() {
+ return this.ieXhr() || new JSpec.request
+ },
+
+ /**
+ * Return Microsoft piece of crap ActiveXObject.
+ *
+ * @return {ActiveXObject}
+ * @api public
+ */
+
+ ieXhr : function() {
+ function object(str) {
+ try { return new ActiveXObject(str) } catch(e) {}
+ }
+ return object('Msxml2.XMLHTTP.6.0') ||
+ object('Msxml2.XMLHTTP.3.0') ||
+ object('Msxml2.XMLHTTP') ||
+ object('Microsoft.XMLHTTP')
+ },
+
+ /**
+ * Check for HTTP request support.
+ *
+ * @return {bool}
+ * @api private
+ */
+
+ hasXhr : function() {
+ return JSpec.request || 'ActiveXObject' in main
+ },
+
+ /**
+ * Try loading _file_ returning the contents
+ * string or null. Chain to locate / read a file.
+ *
+ * @param {string} file
+ * @return {string}
+ * @api public
+ */
+
+ tryLoading : function(file) {
+ try { return JSpec.load(file) } catch (e) {}
+ },
+
+ /**
+ * Load a _file_'s contents.
+ *
+ * @param {string} file
+ * @param {function} callback
+ * @return {string}
+ * @api public
+ */
+
+ load : function(file, callback) {
+ if (any(hook('loading', file), haveStopped)) return
+ if ('readFile' in main)
+ return readFile(file)
+ else if (this.hasXhr()) {
+ var request = this.xhr()
+ request.open('GET', file, false)
+ request.send(null)
+ if (request.readyState == 4 &&
+ (request.status == 0 ||
+ request.status.toString().charAt(0) == 2))
+ return request.responseText
+ }
+ else
+ throw new Error("failed to load `" + file + "'")
+ },
+
+ /**
+ * Load, pre-process, and evaluate a file.
+ *
+ * @param {string} file
+ * @param {JSpec}
+ * @api public
+ */
+
+ exec : function(file) {
+ if (any(hook('executing', file), haveStopped)) return this
+ eval('with (JSpec){' + this.preprocess(this.load(file)) + '}')
+ return this
+ }
+ }
+
+ // --- Node.js support
+
+ if (typeof GLOBAL === 'object' && typeof exports === 'object') {
+ var fs = require('fs')
+ quit = process.exit
+ print = require('sys').puts
+ readFile = function(file){
+ return fs.readFileSync(file).toString('utf8')
+ }
+ }
+
+ // --- Utility functions
+
+ var main = this,
+ find = JSpec.any,
+ utils = 'haveStopped stub hookImmutable hook destub map any last pass fail range each option inject select \
+ error escape extend puts query strip color does addMatchers callIterator toArray equal'.split(/\s+/)
+ while (utils.length) eval('var ' + utils[0] + ' = JSpec.' + utils.shift())
+ if (!main.setTimeout) main.setTimeout = function(callback){ callback() }
+
+ // --- Matchers
+
+ addMatchers({
+ equal : "===",
+ eql : "equal(actual, expected)",
+ be : "alias equal",
+ be_greater_than : ">",
+ be_less_than : "<",
+ be_at_least : ">=",
+ be_at_most : "<=",
+ be_a : "actual.constructor == expected",
+ be_an : "alias be_a",
+ be_an_instance_of : "actual instanceof expected",
+ be_null : "actual == null",
+ be_true : "actual == true",
+ be_false : "actual == false",
+ be_undefined : "typeof actual == 'undefined'",
+ be_type : "typeof actual == expected",
+ match : "typeof actual == 'string' ? actual.match(expected) : false",
+ respond_to : "typeof actual[expected] == 'function'",
+ have_length : "actual.length == expected",
+ be_within : "actual >= expected[0] && actual <= last(expected)",
+ have_length_within : "actual.length >= expected[0] && actual.length <= last(expected)",
+
+ receive : { defer : true, match : function(actual, method, times) {
+ var proxy = new JSpec.ProxyAssertion(actual, method, times, this.negate)
+ JSpec.currentSpec.assertions.push(proxy)
+ return proxy
+ }},
+
+ be_empty : function(actual) {
+ if (actual.constructor == Object && actual.length == undefined)
+ for (var key in actual)
+ return false;
+ return !actual.length
+ },
+
+ include : function(actual) {
+ for (var state = true, i = 1; i < arguments.length; i++) {
+ var arg = arguments[i]
+ switch (actual.constructor) {
+ case String:
+ case Number:
+ case RegExp:
+ case Function:
+ state = actual.toString().indexOf(arg) !== -1
+ break
+
+ case Object:
+ state = arg in actual
+ break
+
+ case Array:
+ state = any(actual, function(value){ return equal(value, arg) })
+ break
+ }
+ if (!state) return false
+ }
+ return true
+ },
+
+ throw_error : { match : function(actual, expected, message) {
+ try { actual() }
+ catch (e) {
+ this.e = e
+ var assert = function(arg) {
+ switch (arg.constructor) {
+ case RegExp : return arg.test(e.message || e.toString())
+ case String : return arg == (e.message || e.toString())
+ case Function : return e instanceof arg || e.name == arg.name
+ }
+ }
+ return message ? assert(expected) && assert(message) :
+ expected ? assert(expected) :
+ true
+ }
+ }, message : function(actual, expected, negate) {
+ // TODO: refactor when actual is not in expected [0]
+ var message_for = function(i) {
+ if (expected[i] == undefined) return 'exception'
+ switch (expected[i].constructor) {
+ case RegExp : return 'exception matching ' + puts(expected[i])
+ case String : return 'exception of ' + puts(expected[i])
+ case Function : return expected[i].name || 'Error'
+ }
+ }
+ var exception = message_for(1) + (expected[2] ? ' and ' + message_for(2) : '')
+ return 'expected ' + exception + (negate ? ' not ' : '' ) +
+ ' to be thrown, but ' + (this.e ? 'got ' + puts(this.e) : 'nothing was')
+ }},
+
+ have : function(actual, length, property) {
+ return actual[property] == null ? false : actual[property].length == length
+ },
+
+ have_at_least : function(actual, length, property) {
+ return actual[property] == null ? (length === 0) : actual[property].length >= length
+ },
+
+ have_at_most :function(actual, length, property) {
+ return actual[property] == null || actual[property].length <= length
+ },
+
+ have_within : function(actual, range, property) {
+ var length = actual[property] == undefined ? 0 : actual[property].length
+ return length >= range.shift() && length <= range.pop()
+ },
+
+ have_prop : function(actual, property, value) {
+ var actualVal = actual[property], actualType = typeof actualVal
+ return (actualType == 'function' || actualType == 'undefined') ? false :
+ typeof value === 'undefined' ||
+ does(actual[property],'eql',value)
+ },
+
+ have_property : function(actual, property, value) {
+ var actualVal = actual[property], actualType = typeof actualVal
+ return (actualType == 'function' || actualType == 'undefined') ? false :
+ typeof value === 'undefined' ||
+ value === actualVal
+ }
+ })
+
+})()
--- /dev/null
+
+// JSpec - node - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+JSpec
+.include({
+ name: 'node',
+
+ // --- Matchers
+
+ matchers : {
+ have_enumerable_property: 'actual.propertyIsEnumerable(expected)',
+ have_writable_property: 'Object.getOwnPropertyDescriptor(actual, expected).writable === true',
+ have_configurable_property: 'Object.getOwnPropertyDescriptor(actual, expected).configurable === true',
+ have_keys: 'does(Object.keys(actual), "eql", expected)',
+ have_prototype: 'Object.getPrototypeOf(actual) === expected'
+ }
+})
+
--- /dev/null
+
+// JSpec - Shell - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+;(function(){
+
+ var _quit = quit
+
+ Shell = {
+
+ // --- Global
+
+ main: this,
+
+ // --- Commands
+
+ commands: {
+ quit: ['Terminate the shell', function(){ _quit() }],
+ exit: ['Terminate the shell', function(){ _quit() }],
+ p: ['Inspect an object', function(o){ return o.toSource() }]
+ },
+
+ /**
+ * Start the interactive shell.
+ *
+ * @api public
+ */
+
+ start : function() {
+ for (var name in this.commands)
+ if (this.commands.hasOwnProperty(name))
+ this.commands[name][1].length ?
+ this.main[name] = this.commands[name][1] :
+ this.main.__defineGetter__(name, this.commands[name][1])
+ }
+ }
+
+ Shell.start()
+
+})()
\ No newline at end of file
--- /dev/null
+
+// JSpec - Mock Timers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+;(function(){
+
+ /**
+ * Version.
+ */
+
+ mockTimersVersion = '1.0.2'
+
+ /**
+ * Localized timer stack.
+ */
+
+ var timers = []
+
+ /**
+ * Set mock timeout with _callback_ and timeout of _ms_.
+ *
+ * @param {function} callback
+ * @param {int} ms
+ * @return {int}
+ * @api public
+ */
+
+ setTimeout = function(callback, ms) {
+ var id
+ return id = setInterval(function(){
+ callback()
+ clearInterval(id)
+ }, ms)
+ }
+
+ /**
+ * Set mock interval with _callback_ and interval of _ms_.
+ *
+ * @param {function} callback
+ * @param {int} ms
+ * @return {int}
+ * @api public
+ */
+
+ setInterval = function(callback, ms) {
+ callback.step = ms, callback.current = callback.last = 0
+ return timers[timers.length] = callback, timers.length
+ }
+
+ /**
+ * Destroy timer with _id_.
+ *
+ * @param {int} id
+ * @return {bool}
+ * @api public
+ */
+
+ clearInterval = clearTimeout = function(id) {
+ return delete timers[--id]
+ }
+
+ /**
+ * Reset timers.
+ *
+ * @return {array}
+ * @api public
+ */
+
+ resetTimers = function() {
+ return timers = []
+ }
+
+ /**
+ * Increment each timers internal clock by _ms_.
+ *
+ * @param {int} ms
+ * @api public
+ */
+
+ tick = function(ms) {
+ for (var i = 0, len = timers.length; i < len; ++i)
+ if (timers[i] && (timers[i].current += ms))
+ if (timers[i].current - timers[i].last >= timers[i].step) {
+ var times = Math.floor((timers[i].current - timers[i].last) / timers[i].step)
+ var remainder = (timers[i].current - timers[i].last) % timers[i].step
+ timers[i].last = timers[i].current - remainder
+ while (times-- && timers[i]) timers[i]()
+ }
+ }
+
+})()
\ No newline at end of file
--- /dev/null
+
+// JSpec - XHR - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+(function(){
+
+ var lastRequest
+
+ // --- Original XMLHttpRequest
+
+ var OriginalXMLHttpRequest = 'XMLHttpRequest' in this ?
+ XMLHttpRequest :
+ function(){}
+ var OriginalActiveXObject = 'ActiveXObject' in this ?
+ ActiveXObject :
+ undefined
+
+ // --- MockXMLHttpRequest
+
+ var MockXMLHttpRequest = function() {
+ this.requestHeaders = {}
+ }
+
+ MockXMLHttpRequest.prototype = {
+ status: 0,
+ async: true,
+ readyState: 0,
+ responseXML: null,
+ responseText: '',
+ abort: function(){},
+ onreadystatechange: function(){},
+
+ /**
+ * Return response headers hash.
+ */
+
+ getAllResponseHeaders : function(){
+ return JSpec.inject(this.responseHeaders, '', function(buf, key, val){
+ return buf + key + ': ' + val + '\r\n'
+ })
+ },
+
+ /**
+ * Return case-insensitive value for header _name_.
+ */
+
+ getResponseHeader : function(name) {
+ return this.responseHeaders[name.toLowerCase()]
+ },
+
+ /**
+ * Set case-insensitive _value_ for header _name_.
+ */
+
+ setRequestHeader : function(name, value) {
+ this.requestHeaders[name.toLowerCase()] = value
+ },
+
+ /**
+ * Open mock request.
+ */
+
+ open : function(method, url, async, user, password) {
+ this.user = user
+ this.password = password
+ this.url = url
+ this.readyState = 1
+ this.method = method.toUpperCase()
+ if (async != undefined) this.async = async
+ if (this.async) this.onreadystatechange()
+ },
+
+ /**
+ * Send request _data_.
+ */
+
+ send : function(data) {
+ var self = this
+ this.data = data
+ this.readyState = 4
+ if (this.method == 'HEAD') this.responseText = null
+ this.responseHeaders['content-length'] = (this.responseText || '').length
+ if(this.async) this.onreadystatechange()
+ this.populateResponseXML()
+ lastRequest = function(){
+ return self
+ }
+ },
+
+ /**
+ * Parse request body and populate responseXML if response-type is xml
+ * Based on the standard specification : http://www.w3.org/TR/XMLHttpRequest/
+ */
+ populateResponseXML: function() {
+ var type = this.getResponseHeader("content-type")
+ if (!type || !this.responseText || !type.match(/(text\/xml|application\/xml|\+xml$)/g))
+ return
+ this.responseXML = JSpec.parseXML(this.responseText)
+ }
+ }
+
+ // --- Response status codes
+
+ JSpec.statusCodes = {
+ 100: 'Continue',
+ 101: 'Switching Protocols',
+ 200: 'OK',
+ 201: 'Created',
+ 202: 'Accepted',
+ 203: 'Non-Authoritative Information',
+ 204: 'No Content',
+ 205: 'Reset Content',
+ 206: 'Partial Content',
+ 300: 'Multiple Choice',
+ 301: 'Moved Permanently',
+ 302: 'Found',
+ 303: 'See Other',
+ 304: 'Not Modified',
+ 305: 'Use Proxy',
+ 307: 'Temporary Redirect',
+ 400: 'Bad Request',
+ 401: 'Unauthorized',
+ 402: 'Payment Required',
+ 403: 'Forbidden',
+ 404: 'Not Found',
+ 405: 'Method Not Allowed',
+ 406: 'Not Acceptable',
+ 407: 'Proxy Authentication Required',
+ 408: 'Request Timeout',
+ 409: 'Conflict',
+ 410: 'Gone',
+ 411: 'Length Required',
+ 412: 'Precondition Failed',
+ 413: 'Request Entity Too Large',
+ 414: 'Request-URI Too Long',
+ 415: 'Unsupported Media Type',
+ 416: 'Requested Range Not Satisfiable',
+ 417: 'Expectation Failed',
+ 422: 'Unprocessable Entity',
+ 500: 'Internal Server Error',
+ 501: 'Not Implemented',
+ 502: 'Bad Gateway',
+ 503: 'Service Unavailable',
+ 504: 'Gateway Timeout',
+ 505: 'HTTP Version Not Supported'
+ }
+
+ /**
+ * Mock XMLHttpRequest requests.
+ *
+ * mockRequest().and_return('some data', 'text/plain', 200, { 'X-SomeHeader' : 'somevalue' })
+ *
+ * @return {hash}
+ * @api public
+ */
+
+ function mockRequest() {
+ return { and_return : function(body, type, status, headers) {
+ XMLHttpRequest = MockXMLHttpRequest
+ ActiveXObject = false
+ status = status || 200
+ headers = headers || {}
+ headers['content-type'] = type
+ JSpec.extend(XMLHttpRequest.prototype, {
+ responseText: body,
+ responseHeaders: headers,
+ status: status,
+ statusText: JSpec.statusCodes[status]
+ })
+ }}
+ }
+
+ /**
+ * Unmock XMLHttpRequest requests.
+ *
+ * @api public
+ */
+
+ function unmockRequest() {
+ XMLHttpRequest = OriginalXMLHttpRequest
+ ActiveXObject = OriginalActiveXObject
+ }
+
+ JSpec.include({
+ name: 'Mock XHR',
+
+ // --- Utilities
+
+ utilities : {
+ mockRequest: mockRequest,
+ unmockRequest: unmockRequest
+ },
+
+ // --- Hooks
+
+ afterSpec : function() {
+ unmockRequest()
+ },
+
+ // --- DSLs
+
+ DSLs : {
+ snake : {
+ mock_request: mockRequest,
+ unmock_request: unmockRequest,
+ last_request: function(){ return lastRequest() }
+ }
+ }
+
+ })
+})()
--- /dev/null
+
+require.paths.unshift('spec', './spec/lib', 'lib')
+require('jspec')
+require('unit/spec.helper')
+haml = require('haml')
+
+JSpec
+ .exec('spec/unit/spec.js')
+ .run({ reporter: JSpec.reporters.Terminal, fixturePath: 'spec/fixtures', failuresOnly: true })
+ .report()
--- /dev/null
+
+describe 'haml'
+ describe '.version'
+ it 'should be a triplet'
+ haml.version.should.match(/^\d+\.\d+\.\d+$/)
+ end
+ end
+
+ describe '.render()'
+ before
+ assertAs = function(name, type, options) {
+ var str = fixture(name + '.haml')
+ try {
+ var html = haml.render(str, options).trim(),
+ expected = fixture(name + '.' + type).trim()
+ if (html === expected)
+ pass()
+ else
+ fail('got:\n' + html + '\n\nexpected:\n' + expected)
+ } catch (err) {
+ if (err instanceof haml.HamlError) {
+ throw err
+ } else {
+ fail('\n:' + err.stack + '\n')
+ }
+ }
+ }
+ assert = function(name, options) {
+ assertAs(name, 'html', options, 'CRLF', '\r\n')
+ }
+ assertXML = function(name, options) {
+ assertAs(name, 'xml', options, 'CRLF', '\r\n')
+ }
+ end
+
+ it 'should allow passing of a context object'
+ assert('context', { context: 'yay' })
+ end
+
+ it 'should allow passing of literals'
+ assert('literals', { locals: { user: 'tj' }})
+ end
+
+ it 'should not fail on trailing indents'
+ assert('trailing-indent')
+ end
+
+ it 'should add xml support via the "xml" option'
+ assertXML('feed', { xml: true })
+ end
+
+ it 'should support xml namespaces'
+ assertXML('namespace')
+ end
+
+ it 'should utilize "filename" option when an error is thrown'
+ try { assert('error', { filename: 'error.haml' }) }
+ catch (err) {
+ err.message.should.eql '(error.haml):3 invalid indentation; got 3, when previous was 1'
+ }
+ end
+
+ it 'should default filename to "Haml" when an error is thrown'
+ try { assert('error') }
+ catch (err) {
+ err.message.should.eql '(Haml):3 invalid indentation; got 3, when previous was 1'
+ }
+ end
+
+ it 'should bitch when "cache" is true without a filename given'
+ // -{ assert('tag.simple', { cache: true }) }.should.throw_error
+ end
+
+ it 'should pre-compiled and cache when "cache" is true'
+ assert('tag.simple', { cache: true, filename: 'tag.simple.haml' })
+ assert('tag.simple', { cache: true, filename: 'tag.simple.haml' })
+ end
+
+ it 'should support blank lines'
+ assert('newlines')
+ end
+
+ describe '.class'
+ it 'should output a div with the given class'
+ assert('class')
+ end
+
+ it 'should work with several classes'
+ assert('classes')
+ end
+ end
+
+ describe '#id'
+ it 'should output a div with the given id'
+ assert('id')
+ end
+ end
+
+ describe '%tag'
+ it 'should work with no text or block'
+ assert('tag.simple')
+ end
+
+ it 'should work with text'
+ assert('tag.text')
+ end
+
+ it 'should work with block text'
+ assert('tag.text.block')
+ end
+
+ it 'should work with blocks of text and tags'
+ assert('tag.text.block.complex')
+ end
+
+ it 'should work with many classes / ids / attrs'
+ assert('tag.complex')
+ end
+
+ it 'should allow empty tags'
+ assert('tag.empty')
+ end
+ end
+
+ describe '%tag.class'
+ it 'should output tag with a class'
+ assert('tag.class')
+ end
+
+ it 'should work with several classes'
+ assert('tag.classes')
+ end
+
+ it 'should support self-closing tags'
+ assert('tag.self-close')
+ end
+ end
+
+ describe '%tag!='
+ it 'should output the evaluated code'
+ assert('tag.code')
+ end
+
+ it 'should not escape output'
+ assert('tag.code.no-escape')
+ end
+ end
+
+ describe '%tag='
+ it 'should escape the evaluated code'
+ assert('tag.escape')
+ end
+ end
+
+ describe '%namespace:tag'
+ it 'should output a tag with a namespace prefix'
+ assert('namespace.tag')
+ end
+ end
+
+ describe '{...}'
+ it 'should be mapped as html attributes'
+ assert('tag.attrs')
+ end
+
+ it 'should escape values'
+ assert('tag.attrs.escape')
+ end
+
+ it 'should allow booleans'
+ assert('tag.attrs.bools')
+ end
+ end
+
+ describe '!!!'
+ it 'should default the doctype to 1.0 transitional'
+ assert('doctype')
+ end
+ end
+
+ describe '!!! NAME'
+ it 'should output a specific doctype'
+ assert('doctype.xml')
+ end
+
+ it 'should be case-insensitive'
+ assert('doctype.xml.case')
+ end
+ end
+
+ describe 'nesting'
+ it 'should work when nested downwards'
+ assert('nesting.simple')
+ end
+
+ it 'should work when blocks outdent'
+ assert('nesting.complex')
+ end
+ end
+
+ describe '- code'
+ it 'should work with if statements'
+ assert('code.if')
+ end
+
+ it 'should work when nested'
+ assert('code.nested')
+ end
+ end
+
+ describe '- each'
+ it 'should iterate'
+ assert('code.each', { locals: { items: ['one', 'two', 'three'] }})
+ assert('code.each.non-enumerable', { locals: { items: null }})
+ end
+
+ it 'should iterate objects'
+ assert('code.each', { locals: { items: { 0: 'one', 1: 'two', 2: 'three' }}})
+ assert('code.each.index', { locals: { items: { 0: 'one', 1: 'two', 2: 'three' }}})
+ end
+
+ it 'should iterate with index'
+ assert('code.each.index', { locals: { items: ['one', 'two', 'three'] }})
+ end
+ end
+
+ describe '= code'
+ it 'should output evaluation'
+ assert('code')
+ end
+ end
+
+ describe '&= code'
+ it 'should output evaluation while escaping html entities'
+ assert('code.escape')
+ end
+ end
+
+ describe '<literal></html>'
+ it 'should remain intact'
+ assert('html')
+ end
+ end
+
+ describe '\\char'
+ it 'should escape the character'
+ assert('escape')
+ end
+ end
+
+ describe '-#'
+ it 'should become a silent comment'
+ assert('comment')
+ end
+ end
+
+ describe '/'
+ it 'should comment out tags'
+ assert('comment.tag')
+ end
+
+ it 'should comment out blocks'
+ assert('comment.block')
+ end
+
+ it 'should comment out text'
+ assert('comment.text')
+ end
+
+ it 'should work in blocks'
+ assert('comment.text.complex')
+ end
+ end
+
+ describe '/[]'
+ it 'should insert conditional comment blocks'
+ assert('comment.block.conditional')
+ end
+ end
+
+ describe ':filter'
+ describe 'plain'
+ it 'should ignore haml specific characters'
+ assert('filter.plain')
+ end
+ end
+
+ describe 'cdata'
+ it 'should wrap with CDATA tags'
+ assert('filter.cdata')
+ end
+
+ it 'should retain whitespace'
+ assert('filter.cdata.whitespace')
+ end
+ end
+
+ describe 'javascript'
+ it 'should wrap with <script> and CDATA tags'
+ assert('filter.javascript')
+ end
+ end
+ end
+
+ describe 'bug fixes'
+ it '#8 code block'
+ assert('issue.#8', { locals: { items: ['foo', 'bar', 'baz'] }})
+ end
+
+ it '#10 Attributes should not need quotes'
+ assert('issue.#10')
+ end
+ end
+
+ end
+end
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var bm = require('./common'),
+ haml = require('./haml/lib/haml'),
+ fs = require('fs');
+
+var str = fs.readFileSync(__dirname + '/example2.haml', 'ascii');
+
+var n = bm.times;
+bm.start('haml compilation');
+while (n--) {
+ haml.render(str, {
+ locals: bm.locals
+ });
+}
+bm.stop();
+
+var n = bm.times;
+bm.start('haml execution');
+while (n--) {
+ haml.render(str, {
+ locals: bm.locals,
+ cache: true,
+ filename: 'example2.haml'
+ });
+}
+bm.stop();
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var bm = require('./common'),
+ jade = require('../lib/jade'),
+ fs = require('fs');
+
+var str = fs.readFileSync(__dirname + '/example-self.jade', 'ascii');
+var fn = jade.compile(str, { self: true });
+var n = bm.times;
+
+bm.start('jade self compilation');
+while (n--) {
+ jade.render(str, {
+ filename: 'example-self.jade'
+ , self: true
+ , locals: bm.locals
+ });
+}
+bm.stop();
+
+var n = bm.times;
+
+bm.start('jade self execution');
+while (n--) {
+ jade.render(str, {
+ filename: 'example-self.jade'
+ , self: true
+ , cache: true
+ , locals: bm.locals
+ });
+}
+bm.stop();
+
+var n = bm.times;
+
+bm.start('jade compile()');
+while (n--) {
+ fn(bm.locals);
+}
+bm.stop();
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var bm = require('./common'),
+ jade = require('../lib/jade'),
+ fs = require('fs');
+
+var str = fs.readFileSync(__dirname + '/example.jade', 'ascii');
+var fn = jade.compile(str);
+var n = bm.times;
+
+bm.start('jade compilation');
+while (n--) {
+ jade.render(str, {
+ filename: 'example.jade',
+ locals: bm.locals
+ });
+}
+bm.stop();
+
+var n = bm.times;
+
+bm.start('jade execution');
+while (n--) {
+ jade.render(str, {
+ filename: 'example.jade',
+ cache: true,
+ locals: bm.locals
+ });
+}
+bm.stop();
+
+var n = bm.times;
+
+bm.start('jade compile()');
+while (n--) {
+ fn(bm.locals);
+}
+bm.stop();
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+ , path = require('path')
+ , resolve = path.resolve
+ , basename = path.basename
+ , dirname = path.dirname
+ , jade;
+
+try {
+ jade = require('../lib/jade');
+} catch (err) {
+ jade = require('jade');
+}
+
+/**
+ * Arguments.
+ */
+
+var args = process.argv.slice(2);
+
+/**
+ * Options javascript.
+ */
+
+var options = {};
+
+/**
+ * Destination dir.
+ */
+
+var dest;
+
+/**
+ * Watcher hash.
+ */
+
+var watchers;
+
+/**
+ * Usage information.
+ */
+
+var usage = ''
+ + '\n'
+ + ' Usage: jade [options]\n'
+ + ' [path ...]\n'
+ + ' < in.jade > out.jade'
+ + ' \n'
+ + ' Options:\n'
+ + ' -o, --options <str> JavaScript options object passed\n'
+ + ' -h, --help Output help information\n'
+ + ' -w, --watch Watch file(s) or folder(s) for changes and re-compile\n'
+ + ' -v, --version Output jade version\n'
+ + ' --out <dir> Output the compiled html to <dir>\n';
+ + '\n';
+
+// Parse arguments
+
+var arg
+ , files = [];
+while (args.length) {
+ arg = args.shift();
+ switch (arg) {
+ case '-h':
+ case '--help':
+ console.log(usage);
+ process.exit(1);
+ case '-v':
+ case '--version':
+ console.log(jade.version);
+ process.exit(1);
+ case '-o':
+ case '--options':
+ var str = args.shift();
+ if (str) {
+ options = eval('(' + str + ')');
+ } else {
+ console.error('-o, --options requires a string.');
+ process.exit(1);
+ }
+ break;
+ case '-w':
+ case '--watch':
+ watchers = {};
+ break;
+ case '--out':
+ dest = args.shift();
+ break;
+ default:
+ files.push(arg);
+ }
+}
+
+// Watching and no files passed - watch cwd
+if (watchers && !files.length) {
+ fs.readdirSync(process.cwd()).forEach(processFile);
+// Process passed files
+} else if (files.length) {
+ files.forEach(processFile);
+// Stdio
+} else {
+ var buf = '';
+ process.stdin.setEncoding('utf8');
+ process.stdin.on('data', function(chunk){
+ buf += chunk;
+ }).on('end', function(){
+ console.log(jade.render(buf, options));
+ }).resume();
+}
+
+/**
+ * Process the given path, compiling the jade files found.
+ * Always walk the subdirectories.;
+ */
+
+function processFile(path) {
+ fs.lstat(path, function(err, stat) {
+ if (err) throw err;
+ // Found jade file
+ if (stat.isFile() && path.match(/\.jade$/)) {
+ renderJade(path);
+ // Found directory
+ } else if (stat.isDirectory()) {
+ fs.readdir(path, function(err, files) {
+ if (err) throw err;
+ files.map(function(filename) {
+ return path + '/' + filename;
+ }).forEach(processFile);
+ });
+ }
+ });
+}
+
+/**
+ * Render jade
+ */
+
+function renderJade(jadefile) {
+ jade.renderFile(jadefile, options, function(err, html) {
+ if (err) throw err;
+ writeFile(jadefile, html);
+ });
+}
+
+/**
+ * mkdir -p implementation.
+ */
+
+function mkdirs(path, fn) {
+ var segs = dirname(path).split('/')
+ , dir = '';
+
+ (function next() {
+ var seg = segs.shift();
+ if (seg) {
+ dir += seg + '/';
+ fs.mkdir(dir, 0755, function(err){
+ if (!err) return next();
+ if ('EEXIST' == err.code) return next();
+ });
+ } else {
+ fn();
+ }
+ })();
+}
+
+/**
+ * Write the html output to a file.
+ */
+
+function writeFile(src, html) {
+ var path = src.replace('.jade', '.html');
+ if (dest) path = dest + '/' + path;
+ mkdirs(path, function(err){
+ if (err) throw err;
+ fs.writeFile(path, html, function(err) {
+ if (err) throw err;
+ console.log(' \033[90mcompiled\033[0m %s', path);
+ watch(src, renderJade);
+ });
+ });
+}
+
+/**
+ * Watch the given `file` and invoke `fn` when modified.
+ */
+
+function watch(file, fn) {
+ // not watching
+ if (!watchers) return;
+
+ // already watched
+ if (watchers[file]) return;
+
+ // watch the file itself
+ watchers[file] = true;
+ console.log(' \033[90mwatching\033[0m %s', file);
+ fs.watchFile(file, { interval: 50 }, function(curr, prev){
+ if (curr.mtime > prev.mtime) fn(file);
+ });
+}
--- /dev/null
+div#id.left(class='user user-' + name).container
+ h1.title= name
+ form
+ //- unbuffered comment :)
+ // An example of attributes.
+ input(type='text', name='user[name]', value=name)
+ input(checked, type='checkbox', name='user[blocked]')
+ input(type='submit', value='Update')
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+var options = { locals: { name: 'tj' }};
+jade.renderFile(__dirname + '/attributes.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+- var title = "Things"
+h1= title
+ul#users
+ - each user, name in users
+ - if (user.isA == "ferret")
+ li(class: 'user-' + name) #{name} is just a ferret
+ - else
+ li(class: 'user-' + name) #{name} #{user.email}
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+var options = {
+ locals: {
+ users: {
+ tj: { age: 23, email: 'tj@vision-media.ca', isA: 'human' },
+ tobi: { age: 1, email: 'tobi@is-amazing.com', isA: 'ferret' }
+ }
+ }
+};
+
+jade.renderFile(__dirname + '/code.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+conditionals:
+ if admin?
+ if name == 'tj'
+ p User is a wicked cool administrator
+ else
+ p User #{name} is an administrator
+ else
+ p User #{name} is a guest
\ No newline at end of file
--- /dev/null
+
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade')
+ , Compiler = jade.Compiler
+ , nodes = jade.nodes;
+
+var options = {
+ locals: {
+ name: 'tj',
+ email: 'tj@vision-media.ca',
+ admin: true
+ }
+};
+
+jade.renderFile(__dirname + '/conditionals.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
+
+jade.filters.conditionals = function(block, compiler){
+ return new Visitor(block).compile();
+};
+
+function Visitor(node) {
+ this.node = node;
+}
+
+Visitor.prototype.__proto__ = Compiler.prototype;
+
+Visitor.prototype.visit = function(node){
+ if (node.name != 'else') this.line(node);
+ this.visitNode(node);
+};
+
+Visitor.prototype.visitTag = function(node){
+ switch (node.name) {
+ case 'if':
+ // First text -> line
+ var condition = node.text[0]
+ , block = node.block;
+ node = new nodes.Code('if (' + condition + ')');
+ node.block = block;
+ this.visit(node);
+ break;
+ case 'else':
+ var block = node.block;
+ node = new nodes.Code('else');
+ node.block = block;
+ node.instrumentLineNumber = false;
+ this.visit(node);
+ break;
+ default:
+ Compiler.prototype.visitTag.call(this, node);
+ }
+};
--- /dev/null
+
+form(method='post', action='/')
+ input(type='text', name='user[name]')
+ input(type='text', name='user[email]')
+ input(type='submit', value='Submit')
--- /dev/null
+
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade'),
+ Compiler = jade.Compiler,
+ nodes = jade.nodes;
+
+var options = {
+ compiler: CSRF
+ , locals: {
+ csrf: 'WAHOOOOOO'
+ }
+};
+
+jade.renderFile(__dirname + '/csrf.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
+
+function CSRF(node, options) {
+ Compiler.call(this, node, options);
+}
+
+CSRF.prototype.__proto__ = Compiler.prototype;
+
+CSRF.prototype.visitTag = function(node){
+ var parent = Compiler.prototype.visitTag;
+ switch (node.name) {
+ case 'form':
+ if ("'post'" == node.getAttribute('method')) {
+ var tok = new nodes.Tag('input');
+ tok.setAttribute('type', '"hidden"');
+ tok.setAttribute('name', '"csrf"');
+ tok.setAttribute('value', 'csrf');
+ node.block.unshift(tok);
+ }
+ }
+ parent.call(this, node);
+};
--- /dev/null
+html
+ head
+ title Dynamic Inline JavaScript
+ script
+ var users = !{JSON.stringify(users)}
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+var options = {
+ locals: {
+ users: {
+ tj: { age: 23, email: 'tj@vision-media.ca', isA: 'human' },
+ tobi: { age: 1, email: 'tobi@is-amazing.com', isA: 'ferret' }
+ }
+ }
+};
+
+jade.renderFile(__dirname + '/dynamicscript.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+ul#users
+ - each user, name in users
+ li(class: 'user-' + name) #{name} #{user.email}
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+var options = {
+ locals: {
+ users: {
+ tj: { age: 23, email: 'tj@vision-media.ca', isA: 'human' },
+ tobi: { age: 1, email: 'tobi@is-amazing.com', isA: 'ferret' }
+ }
+ }
+};
+
+jade.renderFile(__dirname + '/each.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+form(method="post")
+ fieldset
+ legend General
+ p
+ label(for="user[name]") Username:
+ input(type="text", name="user[name]", value=user.name)
+ p
+ label(for="user[email]") Email:
+ input(type="text", name="user[email]", value=user.email)
+ .tip
+ | Enter a valid
+ | email address
+ | such as <em>tj@vision-media.ca</em>.
+ fieldset
+ legend Location
+ p
+ label(for="user[city]") City:
+ input(type="text", name="user[city]", value=user.city)
+ p
+ select(name="user[province]")
+ option(value="") -- Select Province --
+ option(value="AB") Alberta
+ option(value="BC") British Columbia
+ option(value="SK") Saskatchewan
+ option(value="MB") Manitoba
+ option(value="ON") Ontario
+ option(value="QC") Quebec
+ p.buttons
+ input(type="submit", value="Save")
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+var options = {
+ locals: {
+ user: {
+ name: 'TJ',
+ email: 'tj@vision-media.ca',
+ city: 'Victoria',
+ province: 'BC'
+ }
+ }
+};
+
+jade.renderFile(__dirname + '/form.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+
+html
+ include includes/head
+ body
+ h1 My Site
+ p Welcome to my super lame site.
+ include includes/foot
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+jade.renderFile(__dirname + '/includes.jade', function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+#footer
+ p Copyright (c) foobar
\ No newline at end of file
--- /dev/null
+head
+ title My Site
+ script(src='/javascripts/jquery.js')
+ script(src='/javascripts/app.js')
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+jade.renderFile(__dirname + '/layout.jade', { debug: true }, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+!!! 5
+html(lang="en")
+ head
+ title Example
+ script
+ if (foo) {
+ bar();
+ }
+ body
+ h1 Jade - node template engine
+ #container
+ :markdown
+ Jade is a _high performance_ template engine for [node](http://nodejs.org),
+ inspired by [haml](http://haml-lang.com/), and written by [TJ Holowaychuk](http://github.com/visionmedia).
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+jade.renderFile(__dirname + '/layout.jade', function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+
+include mixins/dialog
+include mixins/profile
+
+.one
+ mixin dialog
+
+.two
+ mixin dialog-title('Whoop')
+
+.three
+ mixin dialog-title-desc('Whoop', 'Just a mixin')
+
+
+#profile
+ mixin profile(user)
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+var user = {
+ name: 'tj'
+ , pets: ['tobi', 'loki', 'jane', 'manny']
+};
+
+var options = { locals: { user: user }};
+
+jade.renderFile(__dirname + '/mixins.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+
+mixin dialog
+ .dialog
+ h1 Whoop
+ p stuff
+
+mixin dialog-title(title)
+ .dialog
+ h1= title
+ p stuff
+
+mixin dialog-title-desc(title, desc)
+ .dialog
+ h1= title
+ p= desc
--- /dev/null
+
+mixin pets(pets)
+ ul.pets
+ - each pet in pets
+ li= pet
+
+mixin profile(user)
+ .user
+ h2= user.name
+ mixin pets(user.pets)
\ No newline at end of file
--- /dev/null
+model:
+ form(user)
+ p
+ field(name)
+ p
+ field(email)
+ p
+ field(summary, as: 'textarea')
+ buttons
\ No newline at end of file
--- /dev/null
+
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade'),
+ Compiler = jade.Compiler,
+ nodes = jade.nodes;
+
+var options = {
+ locals: {
+ user: {
+ name: 'Tobi',
+ email: 'vision-media.ca',
+ summary: 'Tobi is a ferret, he is supes cool.',
+ errors: { email: 'Invalid email' },
+ new: false
+ }
+ }
+};
+
+jade.renderFile(__dirname + '/model.jade', options, function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
+
+// First define a filter named "model",
+// which accepts a node (a Block node),
+// and the parent Compiler
+
+jade.filters.model = function(block, compiler){
+ // pass the block / previous options to our new Visitor
+ return new Visitor(block, compiler.options).compile();
+};
+
+function Visitor(node, options) {
+ // "super" to the Compiler() constructor
+ Compiler.call(this, node, options);
+}
+
+// Inherit from Compiler
+
+Visitor.prototype.__proto__ = Compiler.prototype;
+
+// Overwrite visitTag method
+
+Visitor.prototype.visitTag = function(node){
+ var parent = Compiler.prototype.visitTag;
+ switch (node.name) {
+ case 'form':
+ // Store the record variable name,
+ // in our case "user" is our first
+ // anonymous attribute
+ this.record = node.attrs[0].name;
+ // remove the record name attribute
+ node.removeAttribute(this.record);
+ node.setAttribute('id', '"' + this.record + '-model-form"');
+ node.setAttribute('method', '"post"');
+
+ // when the record is not new, we probably want a _method hidden
+ // field to tell our server to use PUT with frameworks like Express
+ var code = new nodes.Code('if (!' + this.record + '.new)');
+ var put = new nodes.Tag('input');
+ put.setAttribute('type', '"hidden"');
+ put.setAttribute('name', '"_method"');
+ put.setAttribute('value', '"put"');
+ code.block = new nodes.Block(put);
+ node.block.push(code);
+
+ parent.call(this, node);
+ break;
+ case 'field':
+ // Grab "as" attribute, defaulting it to "text"
+ // perform some surgery on it since it IS literal JavaScript
+ var name = node.attrs[0].name,
+ as = (node.getAttribute('as') || 'text').trim().replace(/'/g, ''),
+ capitalized = name.charAt(0).toUpperCase() + name.slice(1);
+
+ // Field label
+ var label = new nodes.Tag('label');
+ label.setAttribute('for', '"' + this.record + '[' + name + ']"');
+ label.block.push(new nodes.Text(capitalized + ':'));
+ parent.call(this, label);
+
+ // Field input
+ switch (as) {
+ case 'textarea':
+ var code = new nodes.Code(this.record + '.' + name, true, true);
+ node = new nodes.Tag('textarea');
+ node.block.push(code);
+ break;
+ case 'text':
+ node = new nodes.Tag('input');
+ node.setAttribute('type', '"text"');
+ node.setAttribute('value', this.record + '.' + name);
+ }
+ node.setAttribute('name', '"' + this.record + '[' + name + ']"');
+ parent.call(this, node);
+
+ // Potential error tag
+ var err = this.record + '.errors.' + name;
+ node = new nodes.Code('if (' + err + ')');
+ node.block = new nodes.Block;
+ var p = new nodes.Tag('p', new nodes.Block(new nodes.Code(err, true, true)));
+ p.setAttribute('class', '"error"');
+ node.block.push(p);
+
+ Visitor.prototype.visitCode.call(this, node);
+ break;
+ case 'buttons':
+ // Generate context sensative buttons which
+ // check the record's state.
+ node = new nodes.Tag('input');
+ node.setAttribute('type', '"submit"');
+ node.setAttribute('value', this.record + '.new ? "Save" : "Update"');
+ var p = new nodes.Tag('p', new nodes.Block(node));
+ p.setAttribute('class', '"buttons"');
+ parent.call(this, p);
+ break;
+ default:
+ parent.call(this, node);
+ }
+};
--- /dev/null
+stylesheets:
+ stylesheet('/path/to/a.css')
+ stylesheet('/path/to/b.css')
+ stylesheet('/path/to/c.css')
+ javascripts:
+ js('/path/to/a.js')
+ js('/path/to/b.js')
+ js('/path/to/c.js')
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade'),
+ nodes = jade.nodes,
+ Compiler = jade.Compiler;
+
+jade.renderFile(__dirname + '/nested-filters.jade', function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
+
+// :javascripts
+
+jade.filters.javascripts = function(block, compiler){
+ return new JavascriptsVisitor(block, compiler.options).compile();
+};
+
+function JavascriptsVisitor(node, options) {
+ Compiler.call(this, node, options);
+}
+
+// Inherit from Compiler
+
+JavascriptsVisitor.prototype.__proto__ = Compiler.prototype;
+
+// Overwrite visitTag method
+
+JavascriptsVisitor.prototype.visitTag = function(node){
+ var parent = Compiler.prototype.visitTag;
+ switch (node.name) {
+ case 'js':
+ var script = new nodes.Tag('script');
+ script.setAttribute('type', "'text/javascript'");
+ script.setAttribute('src', "'" + node.attrs[0].name + "'")
+ parent.call(this, script);
+ break;
+ default:
+ parent.call(this, node);
+ }
+};
+
+// :stylesheets
+
+jade.filters.stylesheets = function(block, compiler){
+ return new StylesheetsVisitor(block, compiler.options).compile();
+};
+
+function StylesheetsVisitor(node, options) {
+ Compiler.call(this, node, options);
+}
+
+// Inherit from Compiler
+
+StylesheetsVisitor.prototype.__proto__ = Compiler.prototype;
+
+// Overwrite visitTag method
+
+StylesheetsVisitor.prototype.visitTag = function(node){
+ var parent = Compiler.prototype.visitTag;
+ switch (node.name) {
+ case 'stylesheet':
+ var style = new nodes.Tag('link');
+ style.setAttribute('rel', "'stylesheet'");
+ style.setAttribute('href', "'" + node.attrs[0].name + "'")
+ parent.call(this, style);
+ break;
+ default:
+ parent.call(this, node);
+ }
+};
--- /dev/null
+!!! xml
+rss(version='2.0')
+channel
+ title RSS Title
+ description Some description here
+ link http://google.com
+ lastBuildDate Mon, 06 Sep 2010 00:01:00 +0000
+ pubDate Mon, 06 Sep 2009 16:45:00 +0000
+
+ item
+ title Example entry
+ description Description here
+ link http://google.com/foobar
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+jade.renderFile(__dirname + '/rss.jade', function(err, xml){
+ if (err) throw err;
+ console.log(xml);
+});
\ No newline at end of file
--- /dev/null
+| An example of an
+a(href='#') inline
+| link.
+
+form
+ label Username:
+ input(type='text', name='user[name]')
+ p
+ | Just an example of some text usage.
+ | You can have <em>inline</em> html,
+ | as well as
+ strong tags
+ | .
+
+ | Interpolation is also supported. The
+ | username is currently "#{name}".
+
+ label Email:
+ input(type='text', name='user[email]')
+ p
+ | Email is currently
+ em= email
+ | .
+
+ // alternatively, if we plan on having only
+ // text or inline-html, we can use a trailing
+ // "." to let jade know we want to omit pipes
+
+ label Username:
+ input(type='text')
+ p.
+ Just an example, like before
+ however now we can omit those
+ annoying pipes!.
+
+ Wahoo.
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade')
+ , str = require('fs').readFileSync(__dirname + '/text.jade', 'utf8')
+ , fn = jade.compile(str);
+
+console.log(fn({ name: 'tj', email: 'tj@vision-media.ca' }));
\ No newline at end of file
--- /dev/null
+- var js = '<script></script>'
+!!! 5
+html
+
+ head
+ title= "Some " + "JavaScript"
+ != js
+
+
+
+ body
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('./../lib/jade');
+
+jade.renderFile(__dirname + '/whitespace.jade', {debug:true},function(err, html){
+ if (err) throw err;
+ console.log(html);
+});
\ No newline at end of file
--- /dev/null
+
+module.exports = require('./lib/jade');
\ No newline at end of file
--- /dev/null
+
+// CommonJS require()
+
+function require(p){
+ var path = require.resolve(p)
+ , mod = require.modules[path];
+ if (!mod) throw new Error('failed to require "' + p + '"');
+ if (!mod.exports) {
+ mod.exports = {};
+ mod.call(mod.exports, mod, mod.exports, require.relative(path));
+ }
+ return mod.exports;
+ }
+
+require.modules = {};
+
+require.resolve = function (path){
+ var orig = path
+ , reg = path + '.js'
+ , index = path + '/index.js';
+ return require.modules[reg] && reg
+ || require.modules[index] && index
+ || orig;
+ };
+
+require.register = function (path, fn){
+ require.modules[path] = fn;
+ };
+
+require.relative = function (parent) {
+ return function(p){
+ if ('.' != p[0]) return require(p);
+
+ var path = parent.split('/')
+ , segs = p.split('/');
+ path.pop();
+
+ for (var i = 0; i < segs.length; i++) {
+ var seg = segs[i];
+ if ('..' == seg) path.pop();
+ else if ('.' != seg) path.push(seg);
+ }
+
+ return require(path.join('/'));
+ };
+ };
+
+
+require.register("compiler.js", function(module, exports, require){
+
+/*!
+ * Jade - Compiler
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var nodes = require('./nodes')
+ , filters = require('./filters')
+ , doctypes = require('./doctypes')
+ , selfClosing = require('./self-closing')
+ , inlineTags = require('./inline-tags')
+ , utils = require('./utils');
+
+
+ if (!Object.keys) {
+ Object.keys = function(obj){
+ var arr = [];
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ arr.push(obj);
+ }
+ }
+ return arr;
+ }
+ }
+
+ if (!String.prototype.trimLeft) {
+ String.prototype.trimLeft = function(){
+ return this.replace(/^\s+/, '');
+ }
+ }
+
+
+
+/**
+ * Initialize `Compiler` with the given `node`.
+ *
+ * @param {Node} node
+ * @param {Object} options
+ * @api public
+ */
+
+var Compiler = module.exports = function Compiler(node, options) {
+ this.options = options = options || {};
+ this.node = node;
+
+ this.hasCompiledDoctype = false;
+ this.hasCompiledTag = false;
+ if (options.doctype) this.setDoctype(options.doctype);
+
+ this.pp = options.prettyprint || false;
+ this.indentDepth = 0;
+};
+
+/**
+ * Compiler prototype.
+ */
+
+Compiler.prototype = {
+
+ /**
+ * Compile parse tree to JavaScript.
+ *
+ * @api public
+ */
+
+ compile: function(){
+ this.buf = ['var interp;'];
+ this.visit(this.node);
+ return this.buf.join('\n');
+ },
+
+ /**
+ * Sets the default doctype `name`. Sets terse mode to `true` when
+ * html 5 is used, causing self-closing tags to end with ">" vs "/>",
+ * and boolean attributes are not mirrored.
+ *
+ * @param {string} name
+ * @api public
+ */
+
+ setDoctype: function(name){
+ var doctype = doctypes[(name || 'default').toLowerCase()];
+ if (!doctype) throw new Error('unknown doctype "' + name + '"');
+ this.doctype = doctype;
+ this.terse = '5' == name || 'html' == name;
+ this.xml = 0 == this.doctype.indexOf('<?xml');
+ },
+
+ /**
+ * Buffer the given `str` optionally escaped.
+ *
+ * @param {String} str
+ * @param {Boolean} esc
+ * @api public
+ */
+
+ buffer: function(str, esc){
+ if (esc) str = utils.escape(str);
+ this.buf.push("buf.push('" + str + "');");
+ },
+
+ /**
+ * Buffer the given `node`'s lineno.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+ line: function(node){
+ if (node.instrumentLineNumber === false) return;
+ this.buf.push('__.lineno = ' + node.line + ';');
+ },
+
+ /**
+ * Visit `node`.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+ visit: function(node){
+ this.line(node);
+ return this.visitNode(node);
+ },
+
+ /**
+ * Visit `node`.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+ visitNode: function(node){
+ var name = node.constructor.name
+ || node.constructor.toString().match(/function ([^(\s]+)()/)[1];
+ return this['visit' + name](node);
+ },
+
+ /**
+ * Visit all nodes in `block`.
+ *
+ * @param {Block} block
+ * @api public
+ */
+
+ visitBlock: function(block){
+ var len = len = block.nodes.length;
+ for (var i = 0; i < len; ++i) {
+ this.visit(block.nodes[i]);
+ }
+ },
+
+ /**
+ * Visit `doctype`. Sets terse mode to `true` when html 5
+ * is used, causing self-closing tags to end with ">" vs "/>",
+ * and boolean attributes are not mirrored.
+ *
+ * @param {Doctype} doctype
+ * @api public
+ */
+
+ visitDoctype: function(doctype){
+ if (doctype && (doctype.val || !this.doctype)) {
+ this.setDoctype(doctype.val || 'default');
+ }
+
+ if (this.doctype) this.buffer(this.doctype);
+ this.hasCompiledDoctype = true;
+ },
+
+ /**
+ * Visit `tag` buffering tag markup, generating
+ * attributes, visiting the `tag`'s code and block.
+ *
+ * @param {Tag} tag
+ * @api public
+ */
+
+ visitTag: function(tag){
+ this.indentDepth++;
+ var name = tag.name;
+
+ if (!this.hasCompiledTag) {
+ if (!this.hasCompiledDoctype && 'html' == name) {
+ this.visitDoctype();
+ }
+ this.hasCompiledTag = true;
+ }
+
+ if(this.pp && inlineTags.indexOf(name) == -1)
+ this.buffer('\\n' + new Array(this.indentDepth).join(' '));
+
+ if (~selfClosing.indexOf(name) && !this.xml) {
+ this.buffer('<' + name);
+ this.visitAttributes(tag.attrs);
+ this.terse
+ ? this.buffer('>')
+ : this.buffer('/>');
+ } else {
+ // Optimize attributes buffering
+ if (tag.attrs.length) {
+ this.buffer('<' + name);
+ if (tag.attrs.length) this.visitAttributes(tag.attrs);
+ this.buffer('>');
+ } else {
+ this.buffer('<' + name + '>');
+ }
+ if (tag.code) this.visitCode(tag.code);
+ if (tag.text) this.buffer(utils.text(tag.text.nodes[0].trimLeft()));
+ this.escape = 'pre' == tag.name;
+ this.visit(tag.block);
+ if (this.pp && inlineTags.indexOf(name) == -1 && tag.textOnly == 0) this.buffer('\\n' + new Array(this.indentDepth).join(' '));
+ this.buffer('</' + name + '>');
+ }
+ this.indentDepth--;
+ },
+
+ /**
+ * Visit `filter`, throwing when the filter does not exist.
+ *
+ * @param {Filter} filter
+ * @api public
+ */
+
+ visitFilter: function(filter){
+ var fn = filters[filter.name];
+
+ // unknown filter
+ if (!fn) {
+ if (filter.isASTFilter) {
+ throw new Error('unknown ast filter "' + filter.name + ':"');
+ } else {
+ throw new Error('unknown filter ":' + filter.name + '"');
+ }
+ }
+ if (filter.isASTFilter) {
+ this.buf.push(fn(filter.block, this, filter.attrs));
+ } else {
+ var text = filter.block.nodes.join('');
+ this.buffer(utils.text(fn(text, filter.attrs)));
+ }
+ },
+
+ /**
+ * Visit `text` node.
+ *
+ * @param {Text} text
+ * @api public
+ */
+
+ visitText: function(text){
+ text = utils.text(text.nodes.join(''));
+ if (this.escape) text = escape(text);
+ this.buffer(text);
+ this.buffer('\\n');
+ },
+
+ /**
+ * Visit a `comment`, only buffering when the buffer flag is set.
+ *
+ * @param {Comment} comment
+ * @api public
+ */
+
+ visitComment: function(comment){
+ if (!comment.buffer) return;
+ if (this.pp) this.buffer('\\n' + new Array(this.indentDepth + 1).join(' '));
+ this.buffer('<!--' + utils.escape(comment.val) + '-->');
+ },
+
+ /**
+ * Visit a `BlockComment`.
+ *
+ * @param {Comment} comment
+ * @api public
+ */
+
+ visitBlockComment: function(comment){
+ if (0 == comment.val.indexOf('if')) {
+ this.buffer('<!--[' + comment.val + ']>');
+ this.visit(comment.block);
+ this.buffer('<![endif]-->');
+ } else {
+ this.buffer('<!--' + comment.val);
+ this.visit(comment.block);
+ this.buffer('-->');
+ }
+ },
+
+ /**
+ * Visit `code`, respecting buffer / escape flags.
+ * If the code is followed by a block, wrap it in
+ * a self-calling function.
+ *
+ * @param {Code} code
+ * @api public
+ */
+
+ visitCode: function(code){
+ // Wrap code blocks with {}.
+ // we only wrap unbuffered code blocks ATM
+ // since they are usually flow control
+
+ // Buffer code
+ if (code.buffer) {
+ var val = code.val.trimLeft();
+ this.buf.push('var __val__ = ' + val);
+ val = 'null == __val__ ? "" : __val__';
+ if (code.escape) val = 'escape(' + val + ')';
+ this.buf.push("buf.push(" + val + ");");
+ } else {
+ this.buf.push(code.val);
+ }
+
+ // Block support
+ if (code.block) {
+ if (!code.buffer) this.buf.push('{');
+ this.visit(code.block);
+ if (!code.buffer) this.buf.push('}');
+ }
+ },
+
+ /**
+ * Visit `each` block.
+ *
+ * @param {Each} each
+ * @api public
+ */
+
+ visitEach: function(each){
+ this.buf.push(''
+ + '// iterate ' + each.obj + '\n'
+ + '(function(){\n'
+ + ' if (\'number\' == typeof ' + each.obj + '.length) {\n'
+ + ' for (var ' + each.key + ' = 0, $$l = ' + each.obj + '.length; ' + each.key + ' < $$l; ' + each.key + '++) {\n'
+ + ' var ' + each.val + ' = ' + each.obj + '[' + each.key + '];\n');
+
+ this.visit(each.block);
+
+ this.buf.push(''
+ + ' }\n'
+ + ' } else {\n'
+ + ' for (var ' + each.key + ' in ' + each.obj + ') {\n'
+ + ' if (' + each.obj + '.hasOwnProperty(' + each.key + ')){'
+ + ' var ' + each.val + ' = ' + each.obj + '[' + each.key + '];\n');
+
+ this.visit(each.block);
+
+ this.buf.push(' }\n');
+
+ this.buf.push(' }\n }\n}).call(this);\n');
+ },
+
+ /**
+ * Visit `attrs`.
+ *
+ * @param {Array} attrs
+ * @api public
+ */
+
+ visitAttributes: function(attrs){
+ var buf = []
+ , classes = [];
+
+ if (this.terse) buf.push('terse: true');
+
+ attrs.forEach(function(attr){
+ if (attr.name == 'class') {
+ classes.push('(' + attr.val + ')');
+ } else {
+ var pair = "'" + attr.name + "':(" + attr.val + ')';
+ buf.push(pair);
+ }
+ });
+
+ if (classes.length) {
+ classes = classes.join(" + ' ' + ");
+ buf.push("class: " + classes);
+ }
+
+ buf = buf.join(', ').replace('class:', '"class":');
+
+ this.buf.push("buf.push(attrs({ " + buf + " }));");
+ }
+};
+
+/**
+ * Escape the given string of `html`.
+ *
+ * @param {String} html
+ * @return {String}
+ * @api private
+ */
+
+function escape(html){
+ return String(html)
+ .replace(/&(?!\w+;)/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"');
+}
+
+}); // module: compiler.js
+
+require.register("doctypes.js", function(module, exports, require){
+
+/*!
+ * Jade - doctypes
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+module.exports = {
+ '5': '<!DOCTYPE html>'
+ , 'html': '<!DOCTYPE html>'
+ , 'xml': '<?xml version="1.0" encoding="utf-8" ?>'
+ , 'default': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
+ , 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
+ , 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
+ , 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
+ , '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
+ , 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">'
+ , 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
+};
+}); // module: doctypes.js
+
+require.register("filters.js", function(module, exports, require){
+
+/*!
+ * Jade - filters
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+module.exports = {
+
+ /**
+ * Wrap text with CDATA block.
+ */
+
+ cdata: function(str){
+ return '<![CDATA[\\n' + str + '\\n]]>';
+ },
+
+ /**
+ * Transform sass to css, wrapped in style tags.
+ */
+
+ sass: function(str){
+ str = str.replace(/\\n/g, '\n');
+ var sass = require('sass').render(str).replace(/\n/g, '\\n');
+ return '<style>' + sass + '</style>';
+ },
+
+ /**
+ * Transform stylus to css, wrapped in style tags.
+ */
+
+ stylus: function(str, options){
+ var ret;
+ str = str.replace(/\\n/g, '\n');
+ var stylus = require('stylus');
+ stylus(str, options).render(function(err, css){
+ if (err) throw err;
+ ret = css.replace(/\n/g, '\\n');
+ });
+ return '<style>' + ret + '</style>';
+ },
+
+ /**
+ * Transform sass to css, wrapped in style tags.
+ */
+
+ less: function(str){
+ var ret;
+ str = str.replace(/\\n/g, '\n');
+ require('less').render(str, function(err, css){
+ if (err) throw err;
+ ret = '<style>' + css.replace(/\n/g, '\\n') + '</style>';
+ });
+ return ret;
+ },
+
+ /**
+ * Transform markdown to html.
+ */
+
+ markdown: function(str){
+ var md;
+
+ // support markdown / discount
+ try {
+ md = require('markdown');
+ } catch (err){
+ try {
+ md = require('discount');
+ } catch (err) {
+ try {
+ md = require('markdown-js');
+ } catch (err) {
+ throw new Error('Cannot find markdown library, install markdown or discount');
+ }
+ }
+ }
+
+ str = str.replace(/\\n/g, '\n');
+ return md.parse(str).replace(/\n/g, '\\n').replace(/'/g,''');
+ },
+
+ /**
+ * Transform coffeescript to javascript.
+ */
+
+ coffeescript: function(str){
+ str = str.replace(/\\n/g, '\n');
+ var js = require('coffee-script').compile(str).replace(/\n/g, '\\n');
+ return '<script type="text/javascript">\\n' + js + '</script>';
+ }
+};
+}); // module: filters.js
+
+require.register("inline-tags.js", function(module, exports, require){
+
+/*!
+ * Jade - inline tags
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+module.exports = [
+ 'a',
+ 'abbr',
+ 'acronym',
+ 'b',
+ 'br',
+ 'code',
+ 'em',
+ 'font',
+ 'i',
+ 'img',
+ 'ins',
+ 'kbd',
+ 'map',
+ 'samp',
+ 'small',
+ 'span',
+ 'strong',
+ 'sub',
+ 'sup'
+];
+}); // module: inline-tags.js
+
+require.register("jade.js", function(module, exports, require){
+
+/*!
+ * Jade
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Parser = require('./parser')
+ , Compiler = require('./compiler')
+
+/**
+ * Library version.
+ */
+
+exports.version = '0.12.1';
+
+/**
+ * Intermediate JavaScript cache.
+ */
+
+var cache = exports.cache = {};
+
+/**
+ * Expose self closing tags.
+ */
+
+exports.selfClosing = require('./self-closing');
+
+/**
+ * Default supported doctypes.
+ */
+
+exports.doctypes = require('./doctypes');
+
+/**
+ * Text filters.
+ */
+
+exports.filters = require('./filters');
+
+/**
+ * Utilities.
+ */
+
+exports.utils = require('./utils');
+
+/**
+ * Expose `Compiler`.
+ */
+
+exports.Compiler = Compiler;
+
+/**
+ * Expose `Parser`.
+ */
+
+exports.Parser = Parser;
+
+/**
+ * Nodes.
+ */
+
+exports.nodes = require('./nodes');
+
+/**
+ * Render the given attributes object.
+ *
+ * @param {Object} obj
+ * @return {String}
+ * @api private
+ */
+
+function attrs(obj){
+ var buf = []
+ , terse = obj.terse;
+ delete obj.terse;
+ var keys = Object.keys(obj)
+ , len = keys.length;
+ if (len) {
+ buf.push('');
+ for (var i = 0; i < len; ++i) {
+ var key = keys[i]
+ , val = obj[key];
+ if (typeof val === 'boolean' || val === '' || val == null) {
+ if (val) {
+ terse
+ ? buf.push(key)
+ : buf.push(key + '="' + key + '"');
+ }
+ } else {
+ buf.push(key + '="' + escape(val) + '"');
+ }
+ }
+ }
+ return buf.join(' ');
+}
+
+/**
+ * Escape the given string of `html`.
+ *
+ * @param {String} html
+ * @return {String}
+ * @api private
+ */
+
+function escape(html){
+ return String(html)
+ .replace(/&(?!\w+;)/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"');
+}
+
+/**
+ * Re-throw the given `err` in context to the
+ * `str` of jade, `filename`, and `lineno`.
+ *
+ * @param {Error} err
+ * @param {String} str
+ * @param {String} filename
+ * @param {String} lineno
+ * @api private
+ */
+
+function rethrow(err, str, filename, lineno){
+ var context = 3
+ , lines = str.split('\n')
+ , start = Math.max(lineno - context, 0)
+ , end = Math.min(lines.length, lineno + context);
+
+ // Error context
+ var context = lines.slice(start, end).map(function(line, i){
+ var curr = i + start + 1;
+ return (curr == lineno ? ' > ' : ' ')
+ + curr
+ + '| '
+ + line;
+ }).join('\n');
+
+ // Alter exception message
+ err.path = filename;
+ err.message = (filename || 'Jade') + ':' + lineno
+ + '\n' + context + '\n\n' + err.message;
+ throw err;
+}
+
+/**
+ * Parse the given `str` of jade and return a function body.
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @return {String}
+ * @api private
+ */
+
+function parse(str, options){
+ var filename = options.filename;
+ try {
+ // Parse
+ var parser = new Parser(str, filename);
+ if (options.debug) parser.debug();
+
+ // Compile
+ var compiler = new (options.compiler || Compiler)(parser.parse(), options)
+ , js = compiler.compile();
+
+ // Debug compiler
+ if (options.debug) {
+ console.log('\n\x1b[1mCompiled Function\x1b[0m:\n\n%s', js.replace(/^/gm, ' '));
+ }
+
+ try {
+ return ''
+ + attrs.toString() + '\n\n'
+ + escape.toString() + '\n\n'
+ + 'var buf = [];\n'
+ + (options.self
+ ? 'var self = locals || {}, __ = __ || locals.__;\n' + js
+ : 'with (locals || {}) {' + js + '}')
+ + 'return buf.join("");';
+ } catch (err) {
+ process.compile(js, filename || 'Jade');
+ return;
+ }
+ } catch (err) {
+ rethrow(err, str, filename, parser.lexer.lineno);
+ }
+}
+
+/**
+ * Compile a `Function` representation of the given jade `str`.
+ *
+ * @param {String} str
+ * @param {Options} options
+ * @return {Function}
+ * @api public
+ */
+
+exports.compile = function(str, options){
+ var options = options || {}
+ , input = JSON.stringify(str)
+ , filename = options.filename
+ ? JSON.stringify(options.filename)
+ : 'undefined';
+
+ // Reduce closure madness by injecting some locals
+ var fn = [
+ 'var __ = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };'
+ , rethrow.toString()
+ , 'try {'
+ , parse(String(str), options || {})
+ , '} catch (err) {'
+ , ' rethrow(err, __.input, __.filename, __.lineno);'
+ , '}'
+ ].join('\n');
+
+ return new Function('locals', fn);
+};
+
+/**
+ * Render the given `str` of jade.
+ *
+ * Options:
+ *
+ * - `scope` Evaluation scope (`this`)
+ * - `locals` Local variable object
+ * - `filename` Used in exceptions, and required by `cache`
+ * - `cache` Cache intermediate JavaScript in memory keyed by `filename`
+ * - `compiler` Compiler to replade jade's default
+ * - `doctype` Specify the default doctype
+ *
+ * @param {String|Buffer} str
+ * @param {Object} options
+ * @return {String}
+ * @api public
+ */
+
+exports.render = function(str, options){
+ var fn
+ , options = options || {}
+ , filename = options.filename;
+
+ // Accept Buffers
+ str = String(str);
+
+ // Cache support
+ if (options.cache) {
+ if (filename) {
+ if (cache[filename]) {
+ fn = cache[filename];
+ } else {
+ fn = cache[filename] = new Function('locals', parse(str, options));
+ }
+ } else {
+ throw new Error('filename is required when using the cache option');
+ }
+ } else {
+ fn = new Function('locals', parse(str, options));
+ }
+
+ // Render the template
+ try {
+ var locals = options.locals || {}
+ , meta = { lineno: 1 };
+ locals.__ = meta;
+ return fn.call(options.scope, locals);
+ } catch (err) {
+ rethrow(err, str, filename, meta.lineno);
+ }
+};
+
+/**
+ * Render jade template at the given `path`.
+ *
+ * @param {String} path
+ * @param {Object} options
+ * @param {Function} fn
+ * @api public
+ */
+
+exports.renderFile = function(path, options, fn){
+ var ret;
+
+ if (typeof options === 'function') {
+ fn = options;
+ options = {};
+ }
+ options.filename = path;
+
+ // Primed cache
+ if (options.cache && cache[path]) {
+ try {
+ ret = exports.render('', options);
+ } catch (err) {
+ return fn(err);
+ }
+ fn(null, ret);
+ } else {
+ fs.readFile(path, 'utf8', function(err, str){
+ if (err) return fn(err);
+ try {
+ ret = exports.render(str, options);
+ } catch (err) {
+ return fn(err);
+ }
+ fn(null, ret);
+ });
+ }
+};
+
+}); // module: jade.js
+
+require.register("lexer.js", function(module, exports, require){
+
+/*!
+ * Jade - Lexer
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Initialize `Lexer` with the given `str`.
+ *
+ * @param {String} str
+ * @api private
+ */
+
+var Lexer = module.exports = function Lexer(str) {
+ this.input = str.replace(/\r\n|\r/g, '\n');
+ this.deferredTokens = [];
+ this.lastIndents = 0;
+ this.lineno = 1;
+ this.stash = [];
+ this.indentStack = [];
+ this.indentRe = null;
+ this.pipeless = false;
+};
+
+/**
+ * Lexer prototype.
+ */
+
+Lexer.prototype = {
+
+ /**
+ * Construct a token with the given `type` and `val`.
+ *
+ * @param {String} type
+ * @param {String} val
+ * @return {Object}
+ * @api private
+ */
+
+ tok: function(type, val){
+ return {
+ type: type
+ , line: this.lineno
+ , val: val
+ }
+ },
+
+ /**
+ * Consume the given `len` of input.
+ *
+ * @param {Number} len
+ * @api private
+ */
+
+ consume: function(len){
+ this.input = this.input.substr(len);
+ },
+
+ /**
+ * Scan for `type` with the given `regexp`.
+ *
+ * @param {String} type
+ * @param {RegExp} regexp
+ * @return {Object}
+ * @api private
+ */
+
+ scan: function(regexp, type){
+ var captures;
+ if (captures = regexp.exec(this.input)) {
+ this.consume(captures[0].length);
+ return this.tok(type, captures[1]);
+ }
+ },
+
+ /**
+ * Defer the given `tok`.
+ *
+ * @param {Object} tok
+ * @api private
+ */
+
+ defer: function(tok){
+ this.deferredTokens.push(tok);
+ },
+
+ /**
+ * Lookahead `n` tokens.
+ *
+ * @param {Number} n
+ * @return {Object}
+ * @api private
+ */
+
+ lookahead: function(n){
+ var fetch = n - this.stash.length;
+ while (fetch-- > 0) this.stash.push(this.next());
+ return this.stash[--n];
+ },
+
+ /**
+ * Return the indexOf `start` / `end` delimiters.
+ *
+ * @param {String} start
+ * @param {String} end
+ * @return {Number}
+ * @api private
+ */
+
+ indexOfDelimiters: function(start, end){
+ var str = this.input
+ , nstart = 0
+ , nend = 0
+ , pos = 0;
+ for (var i = 0, len = str.length; i < len; ++i) {
+ if (start == str[i]) {
+ ++nstart;
+ } else if (end == str[i]) {
+ if (++nend == nstart) {
+ pos = i;
+ break;
+ }
+ }
+ }
+ return pos;
+ },
+
+ /**
+ * Stashed token.
+ */
+
+ stashed: function() {
+ return this.stash.length
+ && this.stash.shift();
+ },
+
+ /**
+ * Deferred token.
+ */
+
+ deferred: function() {
+ return this.deferredTokens.length
+ && this.deferredTokens.shift();
+ },
+
+ /**
+ * end-of-source.
+ */
+
+ eos: function() {
+ if (this.input.length) return;
+ if (this.indentStack.length) {
+ this.indentStack.shift();
+ return this.tok('outdent');
+ } else {
+ return this.tok('eos');
+ }
+ },
+
+ /**
+ * Block comment
+ */
+
+ blockComment: function() {
+ var captures;
+ if (captures = /^\/([^\n]+)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var tok = this.tok('block-comment', captures[1]);
+ return tok;
+ }
+ },
+
+ /**
+ * Comment.
+ */
+
+ comment: function() {
+ var captures;
+ if (captures = /^ *\/\/(-)?([^\n]+)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var tok = this.tok('comment', captures[2]);
+ tok.buffer = '-' != captures[1];
+ return tok;
+ }
+ },
+
+ /**
+ * Tag.
+ */
+
+ tag: function() {
+ var captures;
+ if (captures = /^(\w[-:\w]*)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var tok, name = captures[1];
+ if (':' == name[name.length - 1]) {
+ name = name.slice(0, -1);
+ tok = this.tok('tag', name);
+ this.deferredTokens.push(this.tok(':'));
+ while (' ' == this.input[0]) this.input = this.input.substr(1);
+ } else {
+ tok = this.tok('tag', name);
+ }
+ return tok;
+ }
+ },
+
+ /**
+ * Filter.
+ */
+
+ filter: function() {
+ return this.scan(/^:(\w+)/, 'filter');
+ },
+
+ /**
+ * Doctype.
+ */
+
+ doctype: function() {
+ return this.scan(/^(?:!!!|doctype) *(\w+)?/, 'doctype');
+ },
+
+ /**
+ * Id.
+ */
+
+ id: function() {
+ return this.scan(/^#([\w-]+)/, 'id');
+ },
+
+ /**
+ * Class.
+ */
+
+ className: function() {
+ return this.scan(/^\.([\w-]+)/, 'class');
+ },
+
+ /**
+ * Text.
+ */
+
+ text: function() {
+ return this.scan(/^(?:\| ?)?([^\n]+)/, 'text');
+ },
+
+ /**
+ * Each.
+ */
+
+ each: function() {
+ var captures;
+ if (captures = /^- *each *(\w+)(?: *, *(\w+))? * in *([^\n]+)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var tok = this.tok('each', captures[1]);
+ tok.key = captures[2] || 'index';
+ tok.code = captures[3];
+ return tok;
+ }
+ },
+
+ /**
+ * Code.
+ */
+
+ code: function() {
+ var captures;
+ if (captures = /^(!?=|-)([^\n]+)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var flags = captures[1];
+ captures[1] = captures[2];
+ var tok = this.tok('code', captures[1]);
+ tok.escape = flags[0] === '=';
+ tok.buffer = flags[0] === '=' || flags[1] === '=';
+ return tok;
+ }
+ },
+
+ /**
+ * Attributes.
+ */
+
+ attrs: function() {
+ if ('(' == this.input[0]) {
+ var index = this.indexOfDelimiters('(', ')')
+ , str = this.input.substr(1, index-1)
+ , tok = this.tok('attrs')
+ , len = str.length
+ , states = ['key']
+ , key = ''
+ , val = ''
+ , quote
+ , c;
+
+ function state(){
+ return states[states.length - 1];
+ }
+
+ function interpolate(attr) {
+ return attr.replace(/#\{([^}]+)\}/g, function(_, expr){
+ return quote + " + (" + expr + ") + " + quote;
+ });
+ }
+
+ this.consume(index + 1);
+ tok.attrs = {};
+
+ function parse(c) {
+ switch (c) {
+ case ',':
+ case '\n':
+ switch (state()) {
+ case 'expr':
+ case 'array':
+ case 'string':
+ case 'object':
+ val += c;
+ break;
+ default:
+ states.push('key');
+ val = val.trim();
+ key = key.trim();
+ if ('' == key) return;
+ tok.attrs[key.replace(/^['"]|['"]$/g, '')] = '' == val
+ ? true
+ : interpolate(val);
+ key = val = '';
+ }
+ break;
+ case '=':
+ switch (state()) {
+ case 'key char':
+ key += c;
+ break;
+ case 'val':
+ case 'expr':
+ case 'array':
+ case 'string':
+ case 'object':
+ val += c;
+ break;
+ default:
+ states.push('val');
+ }
+ break;
+ case '(':
+ if ('val' == state()) states.push('expr');
+ val += c;
+ break;
+ case ')':
+ if ('expr' == state()) states.pop();
+ val += c;
+ break;
+ case '{':
+ if ('val' == state()) states.push('object');
+ val += c;
+ break;
+ case '}':
+ if ('object' == state()) states.pop();
+ val += c;
+ break;
+ case '[':
+ if ('val' == state()) states.push('array');
+ val += c;
+ break;
+ case ']':
+ if ('array' == state()) states.pop();
+ val += c;
+ break;
+ case '"':
+ case "'":
+ switch (state()) {
+ case 'key':
+ states.push('key char');
+ break;
+ case 'key char':
+ states.pop();
+ break;
+ case 'string':
+ if (c == quote) states.pop();
+ val += c;
+ break;
+ default:
+ states.push('string');
+ val += c;
+ quote = c;
+ }
+ break;
+ case '':
+ break;
+ default:
+ switch (state()) {
+ case 'key':
+ case 'key char':
+ key += c;
+ break;
+ default:
+ val += c;
+ }
+ }
+ }
+
+ for (var i = 0; i < len; ++i) {
+ parse(str[i]);
+ }
+
+ parse(',');
+
+ return tok;
+ }
+ },
+
+ /**
+ * Indent | Outdent | Newline.
+ */
+
+ indent: function() {
+ var captures, re;
+
+ // established regexp
+ if (this.indentRe) {
+ captures = this.indentRe.exec(this.input);
+ // determine regexp
+ } else {
+ // tabs
+ re = /^\n(\t*) */;
+ captures = re.exec(this.input);
+
+ // spaces
+ if (captures && !captures[1].length) {
+ re = /^\n( *)/;
+ captures = re.exec(this.input);
+ }
+
+ // established
+ if (captures && captures[1].length) this.indentRe = re;
+ }
+
+ if (captures) {
+ var tok
+ , indents = captures[1].length;
+
+ ++this.lineno;
+ this.consume(indents + 1);
+
+ if (' ' == this.input[0] || '\t' == this.input[0]) {
+ throw new Error('Invalid indentation, you can use tabs or spaces but not both');
+ }
+
+ // blank line
+ if ('\n' == this.input[0]) return this.tok('newline');
+
+ // outdent
+ if (this.indentStack.length && indents < this.indentStack[0]) {
+ while (this.indentStack.length && this.indentStack[0] > indents) {
+ this.stash.push(this.tok('outdent'));
+ this.indentStack.shift();
+ }
+ tok = this.stash.pop();
+ // indent
+ } else if (indents && indents != this.indentStack[0]) {
+ this.indentStack.unshift(indents);
+ tok = this.tok('indent', indents);
+ // newline
+ } else {
+ tok = this.tok('newline');
+ }
+
+ return tok;
+ }
+ },
+
+ /**
+ * Pipe-less text consumed only when
+ * pipeless is true;
+ */
+
+ pipelessText: function() {
+ if (this.pipeless) {
+ if ('\n' == this.input[0]) return;
+ var i = this.input.indexOf('\n');
+ if (-1 == i) i = this.input.length;
+ var str = this.input.substr(0, i);
+ this.consume(str.length);
+ return this.tok('text', str);
+ }
+ },
+
+ /**
+ * ':'
+ */
+
+ colon: function() {
+ return this.scan(/^: */, ':');
+ },
+
+ /**
+ * Return the next token object, or those
+ * previously stashed by lookahead.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+ advance: function(){
+ return this.stashed()
+ || this.next();
+ },
+
+ /**
+ * Return the next token object.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+ next: function() {
+ return this.deferred()
+ || this.eos()
+ || this.pipelessText()
+ || this.doctype()
+ || this.tag()
+ || this.filter()
+ || this.each()
+ || this.code()
+ || this.id()
+ || this.className()
+ || this.attrs()
+ || this.indent()
+ || this.comment()
+ || this.blockComment()
+ || this.colon()
+ || this.text();
+ }
+};
+
+}); // module: lexer.js
+
+require.register("nodes/block-comment.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - BlockComment
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `BlockComment` with the given `block`.
+ *
+ * @param {String} val
+ * @param {Block} block
+ * @api public
+ */
+
+var BlockComment = module.exports = function BlockComment(val, block) {
+ this.block = block;
+ this.val = val;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+BlockComment.prototype = new Node;
+BlockComment.prototype.constructor = BlockComment;
+
+}); // module: nodes/block-comment.js
+
+require.register("nodes/block.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Block
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Block` with an optional `node`.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+var Block = module.exports = function Block(node){
+ this.nodes = [];
+ if (node) this.push(node);
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Block.prototype = new Node;
+Block.prototype.constructor = Block;
+
+
+/**
+ * Pust the given `node`.
+ *
+ * @param {Node} node
+ * @return {Number}
+ * @api public
+ */
+
+Block.prototype.push = function(node){
+ return this.nodes.push(node);
+};
+
+/**
+ * Unshift the given `node`.
+ *
+ * @param {Node} node
+ * @return {Number}
+ * @api public
+ */
+
+Block.prototype.unshift = function(node){
+ return this.nodes.unshift(node);
+};
+
+}); // module: nodes/block.js
+
+require.register("nodes/code.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Code
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `Code` node with the given code `val`.
+ * Code may also be optionally buffered and escaped.
+ *
+ * @param {String} val
+ * @param {Boolean} buffer
+ * @param {Boolean} escape
+ * @api public
+ */
+
+var Code = module.exports = function Code(val, buffer, escape) {
+ this.val = val;
+ this.buffer = buffer;
+ this.escape = escape;
+ if (/^ *else/.test(val)) this.instrumentLineNumber = false;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Code.prototype = new Node;
+Code.prototype.constructor = Code;
+
+}); // module: nodes/code.js
+
+require.register("nodes/comment.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Comment
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `Comment` with the given `val`, optionally `buffer`,
+ * otherwise the comment may render in the output.
+ *
+ * @param {String} val
+ * @param {Boolean} buffer
+ * @api public
+ */
+
+var Comment = module.exports = function Comment(val, buffer) {
+ this.val = val;
+ this.buffer = buffer;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Comment.prototype = new Node;
+Comment.prototype.constructor = Comment;
+
+}); // module: nodes/comment.js
+
+require.register("nodes/doctype.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Doctype
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `Doctype` with the given `val`.
+ *
+ * @param {String} val
+ * @api public
+ */
+
+var Doctype = module.exports = function Doctype(val) {
+ this.val = val;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Doctype.prototype = new Node;
+Doctype.prototype.constructor = Doctype;
+
+}); // module: nodes/doctype.js
+
+require.register("nodes/each.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Each
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize an `Each` node, representing iteration
+ *
+ * @param {String} obj
+ * @param {String} val
+ * @param {String} key
+ * @param {Block} block
+ * @api public
+ */
+
+var Each = module.exports = function Each(obj, val, key, block) {
+ this.obj = obj;
+ this.val = val;
+ this.key = key;
+ this.block = block;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Each.prototype = new Node;
+Each.prototype.constructor = Each;
+
+}); // module: nodes/each.js
+
+require.register("nodes/filter.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Filter
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , Block = require('./block');
+
+/**
+ * Initialize a `Filter` node with the given
+ * filter `name` and `block`.
+ *
+ * @param {String} name
+ * @param {Block|Node} block
+ * @api public
+ */
+
+var Filter = module.exports = function Filter(name, block, attrs) {
+ this.name = name;
+ this.block = block;
+ this.attrs = attrs;
+ this.isASTFilter = block instanceof Block;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Filter.prototype = new Node;
+Filter.prototype.constructor = Filter;
+
+}); // module: nodes/filter.js
+
+require.register("nodes/index.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+exports.Node = require('./node');
+exports.Tag = require('./tag');
+exports.Code = require('./code');
+exports.Each = require('./each');
+exports.Text = require('./text');
+exports.Block = require('./block');
+exports.Filter = require('./filter');
+exports.Comment = require('./comment');
+exports.BlockComment = require('./block-comment');
+exports.Doctype = require('./doctype');
+
+}); // module: nodes/index.js
+
+require.register("nodes/node.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Node
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Initialize a `Node`.
+ *
+ * @api public
+ */
+
+var Node = module.exports = function Node(){};
+}); // module: nodes/node.js
+
+require.register("nodes/tag.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Tag
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node'),
+ Block = require('./block');
+
+/**
+ * Initialize a `Tag` node with the given tag `name` and optional `block`.
+ *
+ * @param {String} name
+ * @param {Block} block
+ * @api public
+ */
+
+var Tag = module.exports = function Tag(name, block) {
+ this.name = name;
+ this.attrs = [];
+ this.block = block || new Block;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Tag.prototype = new Node;
+Tag.prototype.constructor = Tag;
+
+
+/**
+ * Set attribute `name` to `val`, keep in mind these become
+ * part of a raw js object literal, so to quote a value you must
+ * '"quote me"', otherwise or example 'user.name' is literal JavaScript.
+ *
+ * @param {String} name
+ * @param {String} val
+ * @return {Tag} for chaining
+ * @api public
+ */
+
+Tag.prototype.setAttribute = function(name, val){
+ this.attrs.push({ name: name, val: val });
+ return this;
+};
+
+/**
+ * Remove attribute `name` when present.
+ *
+ * @param {String} name
+ * @api public
+ */
+
+Tag.prototype.removeAttribute = function(name){
+ for (var i = 0, len = this.attrs.length; i < len; ++i) {
+ if (this.attrs[i] && this.attrs[i].name == name) {
+ delete this.attrs[i];
+ }
+ }
+};
+
+/**
+ * Get attribute value by `name`.
+ *
+ * @param {String} name
+ * @return {String}
+ * @api public
+ */
+
+Tag.prototype.getAttribute = function(name){
+ for (var i = 0, len = this.attrs.length; i < len; ++i) {
+ if (this.attrs[i] && this.attrs[i].name == name) {
+ return this.attrs[i].val;
+ }
+ }
+};
+
+}); // module: nodes/tag.js
+
+require.register("nodes/text.js", function(module, exports, require){
+
+/*!
+ * Jade - nodes - Text
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `Text` node with optional `line`.
+ *
+ * @param {String} line
+ * @api public
+ */
+
+var Text = module.exports = function Text(line) {
+ this.nodes = [];
+ if ('string' == typeof line) this.push(line);
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Text.prototype = new Node;
+Text.prototype.constructor = Text;
+
+
+/**
+ * Push the given `node.`
+ *
+ * @param {Node} node
+ * @return {Number}
+ * @api public
+ */
+
+Text.prototype.push = function(node){
+ return this.nodes.push(node);
+};
+
+}); // module: nodes/text.js
+
+require.register("parser.js", function(module, exports, require){
+
+/*!
+ * Jade - Parser
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Lexer = require('./lexer')
+ , nodes = require('./nodes');
+
+/**
+ * Initialize `Parser` with the given input `str` and `filename`.
+ *
+ * @param {String} str
+ * @param {String} filename
+ * @api public
+ */
+
+var Parser = exports = module.exports = function Parser(str, filename){
+ this.input = str;
+ this.lexer = new Lexer(str);
+ this.filename = filename;
+};
+
+/**
+ * Tags that may not contain tags.
+ */
+
+var textOnly = exports.textOnly = ['code', 'script', 'textarea', 'style', 'title'];
+
+/**
+ * Parser prototype.
+ */
+
+Parser.prototype = {
+
+ /**
+ * Output parse tree to stdout.
+ *
+ * @api public
+ */
+
+ debug: function(){
+ var lexer = new Lexer(this.input)
+ , tree = require('sys').inspect(this.parse(), false, 12, true);
+ console.log('\n\x1b[1mParse Tree\x1b[0m:\n');
+ console.log(tree);
+ this.lexer = lexer;
+ },
+
+ /**
+ * Return the next token object.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+ advance: function(){
+ return this.lexer.advance();
+ },
+
+ /**
+ * Single token lookahead.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+ peek: function() {
+ return this.lookahead(1);
+ },
+
+ /**
+ * Return lexer lineno.
+ *
+ * @return {Number}
+ * @api private
+ */
+
+ line: function() {
+ return this.lexer.lineno;
+ },
+
+ /**
+ * `n` token lookahead.
+ *
+ * @param {Number} n
+ * @return {Object}
+ * @api private
+ */
+
+ lookahead: function(n){
+ return this.lexer.lookahead(n);
+ },
+
+ /**
+ * Parse input returning a string of js for evaluation.
+ *
+ * @return {String}
+ * @api public
+ */
+
+ parse: function(){
+ var block = new nodes.Block;
+ block.line = this.line();
+ while ('eos' != this.peek().type) {
+ if ('newline' == this.peek().type) {
+ this.advance();
+ } else {
+ block.push(this.parseExpr());
+ }
+ }
+ return block;
+ },
+
+ /**
+ * Expect the given type, or throw an exception.
+ *
+ * @param {String} type
+ * @api private
+ */
+
+ expect: function(type){
+ if (this.peek().type === type) {
+ return this.advance();
+ } else {
+ throw new Error('expected "' + type + '", but got "' + this.peek().type + '"');
+ }
+ },
+
+ /**
+ * Accept the given `type`.
+ *
+ * @param {String} type
+ * @api private
+ */
+
+ accept: function(type){
+ if (this.peek().type === type) {
+ return this.advance();
+ }
+ },
+
+ /**
+ * tag
+ * | doctype
+ * | filter
+ * | comment
+ * | text
+ * | each
+ * | code
+ * | id
+ * | class
+ */
+
+ parseExpr: function(){
+ switch (this.peek().type) {
+ case 'tag':
+ return this.parseTag();
+ case 'doctype':
+ return this.parseDoctype();
+ case 'filter':
+ return this.parseFilter();
+ case 'comment':
+ return this.parseComment();
+ case 'block-comment':
+ return this.parseBlockComment();
+ case 'text':
+ return this.parseText();
+ case 'each':
+ return this.parseEach();
+ case 'code':
+ return this.parseCode();
+ case 'id':
+ case 'class':
+ var tok = this.advance();
+ this.lexer.defer(this.lexer.tok('tag', 'div'));
+ this.lexer.defer(tok);
+ return this.parseExpr();
+ default:
+ throw new Error('unexpected token "' + this.peek().type + '"');
+ }
+ },
+
+ /**
+ * Text
+ */
+
+ parseText: function(){
+ var tok = this.expect('text')
+ , node = new nodes.Text(tok.val);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * code
+ */
+
+ parseCode: function(){
+ var tok = this.expect('code')
+ , node = new nodes.Code(tok.val, tok.buffer, tok.escape);
+ node.line = this.line();
+ if ('indent' == this.peek().type) {
+ node.block = this.parseBlock();
+ }
+ return node;
+ },
+
+ /**
+ * block comment
+ */
+
+ parseBlockComment: function(){
+ var tok = this.expect('block-comment')
+ , node = new nodes.BlockComment(tok.val, this.parseBlock());
+ node.line = this.line();
+ return node;
+ },
+
+
+ /**
+ * comment
+ */
+
+ parseComment: function(){
+ var tok = this.expect('comment')
+ , node = new nodes.Comment(tok.val, tok.buffer);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * doctype
+ */
+
+ parseDoctype: function(){
+ var tok = this.expect('doctype')
+ , node = new nodes.Doctype(tok.val);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * filter attrs? text-block
+ */
+
+ parseFilter: function(){
+ var block
+ , tok = this.expect('filter')
+ , attrs = this.accept('attrs');
+
+ this.lexer.pipeless = true;
+ block = this.parseTextBlock();
+ this.lexer.pipeless = false;
+
+ var node = new nodes.Filter(tok.val, block, attrs && attrs.attrs);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * tag ':' attrs? block
+ */
+
+ parseASTFilter: function(){
+ var block
+ , tok = this.expect('tag')
+ , attrs = this.accept('attrs');
+
+ this.expect(':');
+ block = this.parseBlock();
+
+ var node = new nodes.Filter(tok.val, block, attrs && attrs.attrs);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * each block
+ */
+
+ parseEach: function(){
+ var tok = this.expect('each')
+ , node = new nodes.Each(tok.code, tok.val, tok.key, this.parseBlock());
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * indent (text | newline)* outdent
+ */
+
+ parseTextBlock: function(){
+ var text = new nodes.Text;
+ text.line = this.line();
+ var spaces = this.expect('indent').val;
+ if (null == this._spaces) this._spaces = spaces;
+ var indent = Array(spaces - this._spaces + 1).join(' ');
+ while ('outdent' != this.peek().type) {
+ switch (this.peek().type) {
+ case 'newline':
+ text.push('\\n');
+ this.advance();
+ break;
+ case 'indent':
+ text.push('\\n');
+ this.parseTextBlock().nodes.forEach(function(node){
+ text.push(node);
+ });
+ text.push('\\n');
+ break;
+ default:
+ text.push(indent + this.advance().val);
+ }
+ }
+ this._spaces = null;
+ this.expect('outdent');
+ return text;
+ },
+
+ /**
+ * indent expr* outdent
+ */
+
+ parseBlock: function(){
+ var block = new nodes.Block;
+ block.line = this.line();
+ this.expect('indent');
+ while ('outdent' != this.peek().type) {
+ if ('newline' == this.peek().type) {
+ this.advance();
+ } else {
+ block.push(this.parseExpr());
+ }
+ }
+ this.expect('outdent');
+ return block;
+ },
+
+ /**
+ * tag (attrs | class | id)* (text | code | ':')? newline* block?
+ */
+
+ parseTag: function(){
+ // ast-filter look-ahead
+ var i = 2;
+ if ('attrs' == this.lookahead(i).type) ++i;
+ if (':' == this.lookahead(i).type) {
+ if ('indent' == this.lookahead(++i).type) {
+ return this.parseASTFilter();
+ }
+ }
+
+ var name = this.advance().val
+ , tag = new nodes.Tag(name);
+
+ tag.line = this.line();
+
+ // (attrs | class | id)*
+ out:
+ while (true) {
+ switch (this.peek().type) {
+ case 'id':
+ case 'class':
+ var tok = this.advance();
+ tag.setAttribute(tok.type, "'" + tok.val + "'");
+ continue;
+ case 'attrs':
+ var obj = this.advance().attrs
+ , names = Object.keys(obj);
+ for (var i = 0, len = names.length; i < len; ++i) {
+ var name = names[i]
+ , val = obj[name];
+ tag.setAttribute(name, val);
+ }
+ continue;
+ default:
+ break out;
+ }
+ }
+
+ // check immediate '.'
+ if ('.' == this.peek().val) {
+ tag.textOnly = true;
+ this.advance();
+ }
+
+ // (text | code | ':')?
+ switch (this.peek().type) {
+ case 'text':
+ tag.text = this.parseText();
+ break;
+ case 'code':
+ tag.code = this.parseCode();
+ break;
+ case ':':
+ this.advance();
+ tag.block = new nodes.Block;
+ tag.block.push(this.parseTag());
+ break;
+ }
+
+ // newline*
+ while ('newline' == this.peek().type) this.advance();
+
+ tag.textOnly = tag.textOnly || ~textOnly.indexOf(tag.name);
+
+ // script special-case
+ if ('script' == tag.name) {
+ var type = tag.getAttribute('type');
+ if (type && 'text/javascript' != type.replace(/^['"]|['"]$/g, '')) {
+ tag.textOnly = false;
+ }
+ }
+
+ // block?
+ if ('indent' == this.peek().type) {
+ if (tag.textOnly) {
+ this.lexer.pipeless = true;
+ tag.block = this.parseTextBlock();
+ this.lexer.pipeless = false;
+ } else {
+ var block = this.parseBlock();
+ if (tag.block) {
+ for (var i = 0, len = block.nodes.length; i < len; ++i) {
+ tag.block.push(block.nodes[i]);
+ }
+ } else {
+ tag.block = block;
+ }
+ }
+ }
+
+ return tag;
+ }
+};
+}); // module: parser.js
+
+require.register("self-closing.js", function(module, exports, require){
+
+/*!
+ * Jade - self closing tags
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+module.exports = [
+ 'meta'
+ , 'img'
+ , 'link'
+ , 'input'
+ , 'area'
+ , 'base'
+ , 'col'
+ , 'br'
+ , 'hr'
+];
+}); // module: self-closing.js
+
+require.register("utils.js", function(module, exports, require){
+
+/*!
+ * Jade - utils
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Convert interpolation in the given string to JavaScript.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+var interpolate = exports.interpolate = function(str){
+ return str.replace(/(\\)?([#!]){(.*?)}/g, function(str, escape, flag, code){
+ return escape
+ ? str
+ : "' + "
+ + ('!' == flag ? '' : 'escape')
+ + "((interp = " + code.replace(/\\'/g, "'")
+ + ") == null ? '' : interp) + '";
+ });
+};
+
+/**
+ * Escape single quotes in `str`.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+var escape = exports.escape = function(str) {
+ return str.replace(/'/g, "\\'");
+};
+
+/**
+ * Interpolate, and escape the given `str`.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+exports.text = function(str){
+ return interpolate(escape(str));
+};
+}); // module: utils.js
--- /dev/null
+// CommonJS require()
+function require(p){var path=require.resolve(p),mod=require.modules[path];if(!mod)throw new Error('failed to require "'+p+'"');mod.exports||(mod.exports={},mod.call(mod.exports,mod,mod.exports,require.relative(path)));return mod.exports}require.modules={},require.resolve=function(path){var orig=path,reg=path+".js",index=path+"/index.js";return require.modules[reg]&®||require.modules[index]&&index||orig},require.register=function(path,fn){require.modules[path]=fn},require.relative=function(parent){return function(p){if("."!=p[0])return require(p);var path=parent.split("/"),segs=p.split("/");path.pop();for(var i=0;i<segs.length;i++){var seg=segs[i];".."==seg?path.pop():"."!=seg&&path.push(seg)}return require(path.join("/"))}},require.register("compiler.js",function(module,exports,require){var nodes=require("./nodes"),filters=require("./filters"),doctypes=require("./doctypes"),selfClosing=require("./self-closing"),utils=require("./utils");Object.keys||(Object.keys=function(obj){var arr=[];for(var key in obj)obj.hasOwnProperty(key)&&arr.push(obj);return arr}),String.prototype.trimLeft||(String.prototype.trimLeft=function(){return this.replace(/^\s+/,"")});var Compiler=module.exports=function Compiler(node,options){this.options=options=options||{},this.node=node,this.hasCompiledDoctype=!1,this.hasCompiledTag=!1,options.doctype&&this.setDoctype(options.doctype)};Compiler.prototype={compile:function(){this.buf=["var interp;"],this.visit(this.node);return this.buf.join("\n")},setDoctype:function(name){var doctype=doctypes[(name||"default").toLowerCase()];if(!doctype)throw new Error('unknown doctype "'+name+'"');this.doctype=doctype,this.terse="5"==name||"html"==name,this.xml=0==this.doctype.indexOf("<?xml")},buffer:function(str,esc){esc&&(str=utils.escape(str)),this.buf.push("buf.push('"+str+"');")},line:function(node){node.instrumentLineNumber!==!1&&this.buf.push("__.lineno = "+node.line+";")},visit:function(node){this.line(node);return this.visitNode(node)},visitNode:function(node){var name=node.constructor.name||node.constructor.toString().match(/function ([^(\s]+)()/)[1];return this["visit"+name](node)},visitBlock:function(block){var len=len=block.nodes.length;for(var i=0;i<len;++i)this.visit(block.nodes[i])},visitDoctype:function(doctype){doctype&&(doctype.val||!this.doctype)&&this.setDoctype(doctype.val||"default"),this.doctype&&this.buffer(this.doctype),this.hasCompiledDoctype=!0},visitTag:function(tag){var name=tag.name;this.hasCompiledTag||(!this.hasCompiledDoctype&&"html"==name&&this.visitDoctype(),this.hasCompiledTag=!0),~selfClosing.indexOf(name)&&!this.xml?(this.buffer("<"+name),this.visitAttributes(tag.attrs),this.terse?this.buffer(">"):this.buffer("/>")):(tag.attrs.length?(this.buffer("<"+name),tag.attrs.length&&this.visitAttributes(tag.attrs),this.buffer(">")):this.buffer("<"+name+">"),tag.code&&this.visitCode(tag.code),tag.text&&this.buffer(utils.text(tag.text.nodes[0].trimLeft())),this.escape="pre"==tag.name,this.visit(tag.block),this.buffer("</"+name+">"))},visitFilter:function(filter){var fn=filters[filter.name];if(!fn)throw filter.isASTFilter?new Error('unknown ast filter "'+filter.name+':"'):new Error('unknown filter ":'+filter.name+'"');if(filter.isASTFilter)this.buf.push(fn(filter.block,this,filter.attrs));else{var text=filter.block.nodes.join("");this.buffer(utils.text(fn(text,filter.attrs)))}},visitText:function(text){text=utils.text(text.nodes.join("")),this.escape&&(text=escape(text)),this.buffer(text),this.buffer("\\n")},visitComment:function(comment){!comment.buffer||this.buffer("<!--"+utils.escape(comment.val)+"-->")},visitBlockComment:function(comment){0==comment.val.indexOf("if")?(this.buffer("<!--["+comment.val+"]>"),this.visit(comment.block),this.buffer("<![endif]-->")):(this.buffer("<!--"+comment.val),this.visit(comment.block),this.buffer("-->"))},visitCode:function(code){if(code.buffer){var val=code.val.trimLeft();this.buf.push("var __val__ = "+val),val='null == __val__ ? "" : __val__',code.escape&&(val="escape("+val+")"),this.buf.push("buf.push("+val+");")}else this.buf.push(code.val);code.block&&(code.buffer||this.buf.push("{"),this.visit(code.block),code.buffer||this.buf.push("}"))},visitEach:function(each){this.buf.push("// iterate "+each.obj+"\n"+"(function(){\n"+" if ('number' == typeof "+each.obj+".length) {\n"+" for (var "+each.key+" = 0, $$l = "+each.obj+".length; "+each.key+" < $$l; "+each.key+"++) {\n"+" var "+each.val+" = "+each.obj+"["+each.key+"];\n"),this.visit(each.block),this.buf.push(" }\n } else {\n for (var "+each.key+" in "+each.obj+") {\n"+" if ("+each.obj+".hasOwnProperty("+each.key+")){"+" var "+each.val+" = "+each.obj+"["+each.key+"];\n"),this.visit(each.block),this.buf.push(" }\n"),this.buf.push(" }\n }\n}).call(this);\n")},visitAttributes:function(attrs){var buf=[],classes=[];this.terse&&buf.push("terse: true"),attrs.forEach(function(attr){if(attr.name=="class")classes.push("("+attr.val+")");else{var pair="'"+attr.name+"':("+attr.val+")";buf.push(pair)}}),classes.length&&(classes=classes.join(" + ' ' + "),buf.push("class: "+classes)),buf=buf.join(", ").replace("class:",'"class":'),this.buf.push("buf.push(attrs({ "+buf+" }));")}};function escape(html){return String(html).replace(/&(?!\w+;)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}}),require.register("doctypes.js",function(module,exports,require){module.exports={5:"<!DOCTYPE html>",html:"<!DOCTYPE html>",xml:'<?xml version="1.0" encoding="utf-8" ?>',"default":'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',transitional:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',strict:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',frameset:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',1.1:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',basic:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',mobile:'<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'}}),require.register("filters.js",function(module,exports,require){module.exports={cdata:function(str){return"<![CDATA[\\n"+str+"\\n]]>"},sass:function(str){str=str.replace(/\\n/g,"\n");var sass=require("sass").render(str).replace(/\n/g,"\\n");return"<style>"+sass+"</style>"},stylus:function(str,options){var ret;str=str.replace(/\\n/g,"\n");var stylus=require("stylus");stylus(str,options).render(function(err,css){if(err)throw err;ret=css.replace(/\n/g,"\\n")});return"<style>"+ret+"</style>"},less:function(str){var ret;str=str.replace(/\\n/g,"\n"),require("less").render(str,function(err,css){if(err)throw err;ret="<style>"+css.replace(/\n/g,"\\n")+"</style>"});return ret},markdown:function(str){var md;try{md=require("markdown")}catch(err){try{md=require("discount")}catch(err){try{md=require("markdown-js")}catch(err){throw new Error("Cannot find markdown library, install markdown or discount")}}}str=str.replace(/\\n/g,"\n");return md.parse(str).replace(/\n/g,"\\n").replace(/'/g,"'")},coffeescript:function(str){str=str.replace(/\\n/g,"\n");var js=require("coffee-script").compile(str).replace(/\n/g,"\\n");return'<script type="text/javascript">\\n'+js+"</script>"}}}),require.register("jade.js",function(module,exports,require){var Parser=require("./parser"),Compiler=require("./compiler");exports.version="0.12.1";var cache=exports.cache={};exports.selfClosing=require("./self-closing"),exports.doctypes=require("./doctypes"),exports.filters=require("./filters"),exports.utils=require("./utils"),exports.Compiler=Compiler,exports.Parser=Parser,exports.nodes=require("./nodes");function attrs(obj){var buf=[],terse=obj.terse;delete obj.terse;var keys=Object.keys(obj),len=keys.length;if(len){buf.push("");for(var i=0;i<len;++i){var key=keys[i],val=obj[key];typeof val=="boolean"||val===""||val==null?val&&(terse?buf.push(key):buf.push(key+'="'+key+'"')):buf.push(key+'="'+escape(val)+'"')}}return buf.join(" ")}function escape(html){return String(html).replace(/&(?!\w+;)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function rethrow(err,str,filename,lineno){var context=3,lines=str.split("\n"),start=Math.max(lineno-context,0),end=Math.min(lines.length,lineno+context),context=lines.slice(start,end).map(function(line,i){var curr=i+start+1;return(curr==lineno?" > ":" ")+curr+"| "+line}).join("\n");err.path=filename,err.message=(filename||"Jade")+":"+lineno+"\n"+context+"\n\n"+err.message;throw err}function parse(str,options){var filename=options.filename;try{var parser=new Parser(str,filename);options.debug&&parser.debug();var compiler=new(options.compiler||Compiler)(parser.parse(),options),js=compiler.compile();options.debug&&console.log("\n\e[1mCompiled Function\e[0m:\n\n%s",js.replace(/^/gm," "));try{return""+attrs.toString()+"\n\n"+escape.toString()+"\n\n"+"var buf = [];\n"+(options.self?"var self = locals || {}, __ = __ || locals.__;\n"+js:"with (locals || {}) {"+js+"}")+'return buf.join("");'}catch(err){process.compile(js,filename||"Jade");return}}catch(err){rethrow(err,str,filename,parser.lexer.lineno)}}exports.compile=function(str,options){var options=options||{},input=JSON.stringify(str),filename=options.filename?JSON.stringify(options.filename):"undefined",fn=["var __ = { lineno: 1, input: "+input+", filename: "+filename+" };",rethrow.toString(),"try {",parse(String(str),options||{}),"} catch (err) {"," rethrow(err, __.input, __.filename, __.lineno);","}"].join("\n");return new Function("locals",fn)},exports.render=function(str,options){var fn,options=options||{},filename=options.filename;str=String(str);if(options.cache)if(filename)cache[filename]?fn=cache[filename]:fn=cache[filename]=new Function("locals",parse(str,options));else throw new Error("filename is required when using the cache option");else fn=new Function("locals",parse(str,options));try{var locals=options.locals||{},meta={lineno:1};locals.__=meta;return fn.call(options.scope,locals)}catch(err){rethrow(err,str,filename,meta.lineno)}},exports.renderFile=function(path,options,fn){var ret;typeof options=="function"&&(fn=options,options={}),options.filename=path;if(options.cache&&cache[path]){try{ret=exports.render("",options)}catch(err){return fn(err)}fn(null,ret)}else fs.readFile(path,"utf8",function(err,str){if(err)return fn(err);try{ret=exports.render(str,options)}catch(err){return fn(err)}fn(null,ret)})}}),require.register("lexer.js",function(module,exports,require){var Lexer=module.exports=function Lexer(str){this.input=str.replace(/\r\n|\r/g,"\n"),this.deferredTokens=[],this.lastIndents=0,this.lineno=1,this.stash=[],this.indentStack=[],this.indentRe=null,this.pipeless=!1};Lexer.prototype={tok:function(type,val){return{type:type,line:this.lineno,val:val}},consume:function(len){this.input=this.input.substr(len)},scan:function(regexp,type){var captures;if(captures=regexp.exec(this.input)){this.consume(captures[0].length);return this.tok(type,captures[1])}},defer:function(tok){this.deferredTokens.push(tok)},lookahead:function(n){var fetch=n-this.stash.length;while(fetch-->0)this.stash.push(this.next());return this.stash[--n]},indexOfDelimiters:function(start,end){var str=this.input,nstart=0,nend=0,pos=0;for(var i=0,len=str.length;i<len;++i)if(start==str[i])++nstart;else if(end==str[i]&&++nend==nstart){pos=i;break}return pos},stashed:function(){return this.stash.length&&this.stash.shift()},deferred:function(){return this.deferredTokens.length&&this.deferredTokens.shift()},eos:function(){if(!this.input.length){if(this.indentStack.length){this.indentStack.shift();return this.tok("outdent")}return this.tok("eos")}},blockComment:function(){var captures;if(captures=/^\/([^\n]+)/.exec(this.input)){this.consume(captures[0].length);var tok=this.tok("block-comment",captures[1]);return tok}},comment:function(){var captures;if(captures=/^ *\/\/(-)?([^\n]+)/.exec(this.input)){this.consume(captures[0].length);var tok=this.tok("comment",captures[2]);tok.buffer="-"!=captures[1];return tok}},tag:function(){var captures;if(captures=/^(\w[-:\w]*)/.exec(this.input)){this.consume(captures[0].length);var tok,name=captures[1];if(":"==name[name.length-1]){name=name.slice(0,-1),tok=this.tok("tag",name),this.deferredTokens.push(this.tok(":"));while(" "==this.input[0])this.input=this.input.substr(1)}else tok=this.tok("tag",name);return tok}},filter:function(){return this.scan(/^:(\w+)/,"filter")},doctype:function(){return this.scan(/^(?:!!!|doctype) *(\w+)?/,"doctype")},id:function(){return this.scan(/^#([\w-]+)/,"id")},className:function(){return this.scan(/^\.([\w-]+)/,"class")},text:function(){return this.scan(/^(?:\| ?)?([^\n]+)/,"text")},each:function(){var captures;if(captures=/^- *each *(\w+)(?: *, *(\w+))? * in *([^\n]+)/.exec(this.input)){this.consume(captures[0].length);var tok=this.tok("each",captures[1]);tok.key=captures[2]||"index",tok.code=captures[3];return tok}},code:function(){var captures;if(captures=/^(!?=|-)([^\n]+)/.exec(this.input)){this.consume(captures[0].length);var flags=captures[1];captures[1]=captures[2];var tok=this.tok("code",captures[1]);tok.escape=flags[0]==="=",tok.buffer=flags[0]==="="||flags[1]==="=";return tok}},attrs:function(){if("("==this.input[0]){var index=this.indexOfDelimiters("(",")"),str=this.input.substr(1,index-1),tok=this.tok("attrs"),len=str.length,states=["key"],key="",val="",quote,c;function state(){return states[states.length-1]}function interpolate(attr){return attr.replace(/#\{([^}]+)\}/g,function(_,expr){return quote+" + ("+expr+") + "+quote})}this.consume(index+1),tok.attrs={};function parse(c){switch(c){case",":case"\n":switch(state()){case"expr":case"array":case"string":case"object":val+=c;break;default:states.push("key"),val=val.trim(),key=key.trim();if(""==key)return;tok.attrs[key.replace(/^['"]|['"]$/g,"")]=""==val?!0:interpolate(val),key=val=""}break;case"=":switch(state()){case"key char":key+=c;break;case"val":case"expr":case"array":case"string":case"object":val+=c;break;default:states.push("val")}break;case"(":"val"==state()&&states.push("expr"),val+=c;break;case")":"expr"==state()&&states.pop(),val+=c;break;case"{":"val"==state()&&states.push("object"),val+=c;break;case"}":"object"==state()&&states.pop(),val+=c;break;case"[":"val"==state()&&states.push("array"),val+=c;break;case"]":"array"==state()&&states.pop(),val+=c;break;case'"':case"'":switch(state()){case"key":states.push("key char");break;case"key char":states.pop();break;case"string":c==quote&&states.pop(),val+=c;break;default:states.push("string"),val+=c,quote=c}break;case"":break;default:switch(state()){case"key":case"key char":key+=c;break;default:val+=c}}}for(var i=0;i<len;++i)parse(str[i]);parse(",");return tok}},indent:function(){var captures,re;this.indentRe?captures=this.indentRe.exec(this.input):(re=/^\n(\t*) */,captures=re.exec(this.input),captures&&!captures[1].length&&(re=/^\n( *)/,captures=re.exec(this.input)),captures&&captures[1].length&&(this.indentRe=re));if(captures){var tok,indents=captures[1].length;++this.lineno,this.consume(indents+1);if(" "==this.input[0]||"\t"==this.input[0])throw new Error("Invalid indentation, you can use tabs or spaces but not both");if("\n"==this.input[0])return this.tok("newline");if(this.indentStack.length&&indents<this.indentStack[0]){while(this.indentStack.length&&this.indentStack[0]>indents)this.stash.push(this.tok("outdent")),this.indentStack.shift();tok=this.stash.pop()}else indents&&indents!=this.indentStack[0]?(this.indentStack.unshift(indents),tok=this.tok("indent",indents)):tok=this.tok("newline");return tok}},pipelessText:function(){if(this.pipeless){if("\n"==this.input[0])return;var i=this.input.indexOf("\n");-1==i&&(i=this.input.length);var str=this.input.substr(0,i);this.consume(str.length);return this.tok("text",str)}},colon:function(){return this.scan(/^: */,":")},advance:function(){return this.stashed()||this.next()},next:function(){return this.deferred()||this.eos()||this.pipelessText()||this.doctype()||this.tag()||this.filter()||this.each()||this.code()||this.id()||this.className()||this.attrs()||this.indent()||this.comment()||this.blockComment()||this.colon()||this.text()}}}),require.register("nodes/block-comment.js",function(module,exports,require){var Node=require("./node"),BlockComment=module.exports=function BlockComment(val,block){this.block=block,this.val=val};BlockComment.prototype=new Node,BlockComment.prototype.constructor=BlockComment}),require.register("nodes/block.js",function(module,exports,require){var Node=require("./node"),Block=module.exports=function Block(node){this.nodes=[],node&&this.push(node)};Block.prototype=new Node,Block.prototype.constructor=Block,Block.prototype.push=function(node){return this.nodes.push(node)},Block.prototype.unshift=function(node){return this.nodes.unshift(node)}}),require.register("nodes/code.js",function(module,exports,require){var Node=require("./node"),Code=module.exports=function Code(val,buffer,escape){this.val=val,this.buffer=buffer,this.escape=escape,/^ *else/.test(val)&&(this.instrumentLineNumber=!1)};Code.prototype=new Node,Code.prototype.constructor=Code}),require.register("nodes/comment.js",function(module,exports,require){var Node=require("./node"),Comment=module.exports=function Comment(val,buffer){this.val=val,this.buffer=buffer};Comment.prototype=new Node,Comment.prototype.constructor=Comment}),require.register("nodes/doctype.js",function(module,exports,require){var Node=require("./node"),Doctype=module.exports=function Doctype(val){this.val=val};Doctype.prototype=new Node,Doctype.prototype.constructor=Doctype}),require.register("nodes/each.js",function(module,exports,require){var Node=require("./node"),Each=module.exports=function Each(obj,val,key,block){this.obj=obj,this.val=val,this.key=key,this.block=block};Each.prototype=new Node,Each.prototype.constructor=Each}),require.register("nodes/filter.js",function(module,exports,require){var Node=require("./node"),Block=require("./block"),Filter=module.exports=function Filter(name,block,attrs){this.name=name,this.block=block,this.attrs=attrs,this.isASTFilter=block instanceof Block};Filter.prototype=new Node,Filter.prototype.constructor=Filter}),require.register("nodes/index.js",function(module,exports,require){exports.Node=require("./node"),exports.Tag=require("./tag"),exports.Code=require("./code"),exports.Each=require("./each"),exports.Text=require("./text"),exports.Block=require("./block"),exports.Filter=require("./filter"),exports.Comment=require("./comment"),exports.BlockComment=require("./block-comment"),exports.Doctype=require("./doctype")}),require.register("nodes/node.js",function(module,exports,require){var Node=module.exports=function(){}}),require.register("nodes/tag.js",function(module,exports,require){var Node=require("./node"),Block=require("./block"),Tag=module.exports=function Tag(name,block){this.name=name,this.attrs=[],this.block=block||new Block};Tag.prototype=new Node,Tag.prototype.constructor=Tag,Tag.prototype.setAttribute=function(name,val){this.attrs.push({name:name,val:val});return this},Tag.prototype.removeAttribute=function(name){for(var i=0,len=this.attrs.length;i<len;++i)this.attrs[i]&&this.attrs[i].name==name&&delete this.attrs[i]},Tag.prototype.getAttribute=function(name){for(var i=0,len=this.attrs.length;i<len;++i)if(this.attrs[i]&&this.attrs[i].name==name)return this.attrs[i].val}}),require.register("nodes/text.js",function(module,exports,require){var Node=require("./node"),Text=module.exports=function Text(line){this.nodes=[],"string"==typeof line&&this.push(line)};Text.prototype=new Node,Text.prototype.constructor=Text,Text.prototype.push=function(node){return this.nodes.push(node)}}),require.register("parser.js",function(module,exports,require){var Lexer=require("./lexer"),nodes=require("./nodes"),Parser=exports=module.exports=function Parser(str,filename){this.input=str,this.lexer=new Lexer(str),this.filename=filename},textOnly=exports.textOnly=["code","script","textarea","style"];Parser.prototype={debug:function(){var lexer=new Lexer(this.input),tree=require("sys").inspect(this.parse(),!1,12,!0);console.log("\n\e[1mParse Tree\e[0m:\n"),console.log(tree),this.lexer=lexer},advance:function(){return this.lexer.advance()},peek:function(){return this.lookahead(1)},line:function(){return this.lexer.lineno},lookahead:function(n){return this.lexer.lookahead(n)},parse:function(){var block=new nodes.Block;block.line=this.line();while("eos"!=this.peek().type)"newline"==this.peek().type?this.advance():block.push(this.parseExpr());return block},expect:function(type){if(this.peek().type===type)return this.advance();throw new Error('expected "'+type+'", but got "'+this.peek().type+'"')},accept:function(type){if(this.peek().type===type)return this.advance()},parseExpr:function(){switch(this.peek().type){case"tag":return this.parseTag();case"doctype":return this.parseDoctype();case"filter":return this.parseFilter();case"comment":return this.parseComment();case"block-comment":return this.parseBlockComment();case"text":return this.parseText();case"each":return this.parseEach();case"code":return this.parseCode();case"id":case"class":var tok=this.advance();this.lexer.defer(this.lexer.tok("tag","div")),this.lexer.defer(tok);return this.parseExpr();default:throw new Error('unexpected token "'+this.peek().type+'"')}},parseText:function(){var tok=this.expect("text"),node=new nodes.Text(tok.val);node.line=this.line();return node},parseCode:function(){var tok=this.expect("code"),node=new nodes.Code(tok.val,tok.buffer,tok.escape);node.line=this.line(),"indent"==this.peek().type&&(node.block=this.parseBlock());return node},parseBlockComment:function(){var tok=this.expect("block-comment"),node=new nodes.BlockComment(tok.val,this.parseBlock());node.line=this.line();return node},parseComment:function(){var tok=this.expect("comment"),node=new nodes.Comment(tok.val,tok.buffer);node.line=this.line();return node},parseDoctype:function(){var tok=this.expect("doctype"),node=new nodes.Doctype(tok.val);node.line=this.line();return node},parseFilter:function(){var block,tok=this.expect("filter"),attrs=this.accept("attrs");this.lexer.pipeless=!0,block=this.parseTextBlock(),this.lexer.pipeless=!1;var node=new nodes.Filter(tok.val,block,attrs&&attrs.attrs);node.line=this.line();return node},parseASTFilter:function(){var block,tok=this.expect("tag"),attrs=this.accept("attrs");this.expect(":"),block=this.parseBlock();var node=new nodes.Filter(tok.val,block,attrs&&attrs.attrs);node.line=this.line();return node},parseEach:function(){var tok=this.expect("each"),node=new nodes.Each(tok.code,tok.val,tok.key,this.parseBlock());node.line=this.line();return node},parseTextBlock:function(){var text=new nodes.Text;text.line=this.line();var spaces=this.expect("indent").val;null==this._spaces&&(this._spaces=spaces);var indent=Array(spaces-this._spaces+1).join(" ");while("outdent"!=this.peek().type)switch(this.peek().type){case"newline":text.push("\\n"),this.advance();break;case"indent":text.push("\\n"),this.parseTextBlock().nodes.forEach(function(node){text.push(node)}),text.push("\\n");break;default:text.push(indent+this.advance().val)}this._spaces=null,this.expect("outdent");return text},parseBlock:function(){var block=new nodes.Block;block.line=this.line(),this.expect("indent");while("outdent"!=this.peek().type)"newline"==this.peek().type?this.advance():block.push(this.parseExpr());this.expect("outdent");return block},parseTag:function(){var i=2;"attrs"==this.lookahead(i).type&&++i;if(":"==this.lookahead(i).type&&"indent"==this.lookahead(++i).type)return this.parseASTFilter();var name=this.advance().val,tag=new nodes.Tag(name);tag.line=this.line();out:for(;;)switch(this.peek().type){case"id":case"class":var tok=this.advance();tag.setAttribute(tok.type,"'"+tok.val+"'");continue;case"attrs":var obj=this.advance().attrs,names=Object.keys(obj);for(var i=0,len=names.length;i<len;++i){var name=names[i],val=obj[name];tag.setAttribute(name,val)}continue;default:break out}"."==this.peek().val&&(tag.textOnly=!0,this.advance());switch(this.peek().type){case"text":tag.text=this.parseText();break;case"code":tag.code=this.parseCode();break;case":":this.advance(),tag.block=new nodes.Block,tag.block.push(this.parseTag())}while("newline"==this.peek().type)this.advance();tag.textOnly=tag.textOnly||~textOnly.indexOf(tag.name);if("script"==tag.name){var type=tag.getAttribute("type");type&&"text/javascript"!=type.replace(/^['"]|['"]$/g,"")&&(tag.textOnly=!1)}if("indent"==this.peek().type)if(tag.textOnly)this.lexer.pipeless=!0,tag.block=this.parseTextBlock(),this.lexer.pipeless=!1;else{var block=this.parseBlock();if(tag.block)for(var i=0,len=block.nodes.length;i<len;++i)tag.block.push(block.nodes[i]);else tag.block=block}return tag}}}),require.register("self-closing.js",function(module,exports,require){module.exports=["meta","img","link","input","area","base","col","br","hr"]}),require.register("utils.js",function(module,exports,require){var interpolate=exports.interpolate=function(str){return str.replace(/(\\)?([#!]){(.*?)}/g,function(str,escape,flag,code){return escape?str:"' + "+("!"==flag?"":"escape")+"((interp = "+code.replace(/\\'/g,"'")+") == null ? '' : interp) + '"})},escape=exports.escape=function(str){return str.replace(/'/g,"\\'")};exports.text=function(str){return interpolate(escape(str))}})
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - Compiler
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var nodes = require('./nodes')
+ , filters = require('./filters')
+ , doctypes = require('./doctypes')
+ , selfClosing = require('./self-closing')
+ , inlineTags = require('./inline-tags')
+ , utils = require('./utils');
+
+// if browser
+//
+// if (!Object.keys) {
+// Object.keys = function(obj){
+// var arr = [];
+// for (var key in obj) {
+// if (obj.hasOwnProperty(key)) {
+// arr.push(obj);
+// }
+// }
+// return arr;
+// }
+// }
+//
+// if (!String.prototype.trimLeft) {
+// String.prototype.trimLeft = function(){
+// return this.replace(/^\s+/, '');
+// }
+// }
+//
+// end
+
+
+/**
+ * Initialize `Compiler` with the given `node`.
+ *
+ * @param {Node} node
+ * @param {Object} options
+ * @api public
+ */
+
+var Compiler = module.exports = function Compiler(node, options) {
+ this.options = options = options || {};
+ this.node = node;
+ this.hasCompiledDoctype = false;
+ this.hasCompiledTag = false;
+ this.pp = options.pretty || false;
+ this.indents = 0;
+ if (options.doctype) this.setDoctype(options.doctype);
+};
+
+/**
+ * Compiler prototype.
+ */
+
+Compiler.prototype = {
+
+ /**
+ * Compile parse tree to JavaScript.
+ *
+ * @api public
+ */
+
+ compile: function(){
+ this.buf = [];
+ this.visit(this.node);
+ return this.buf.join('\n');
+ },
+
+ /**
+ * Sets the default doctype `name`. Sets terse mode to `true` when
+ * html 5 is used, causing self-closing tags to end with ">" vs "/>",
+ * and boolean attributes are not mirrored.
+ *
+ * @param {string} name
+ * @api public
+ */
+
+ setDoctype: function(name){
+ var doctype = doctypes[(name || 'default').toLowerCase()];
+ if (!doctype) throw new Error('unknown doctype "' + name + '"');
+ this.doctype = doctype;
+ this.terse = '5' == name || 'html' == name;
+ this.xml = 0 == this.doctype.indexOf('<?xml');
+ },
+
+ /**
+ * Buffer the given `str` optionally escaped.
+ *
+ * @param {String} str
+ * @param {Boolean} esc
+ * @api public
+ */
+
+ buffer: function(str, esc){
+ if (esc) str = utils.escape(str);
+ this.buf.push("buf.push('" + str + "');");
+ },
+
+ /**
+ * Buffer the given `node`'s lineno.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+ line: function(node){
+ if (node.instrumentLineNumber === false) return;
+ this.buf.push('__.lineno = ' + node.line + ';');
+ },
+
+ /**
+ * Visit `node`.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+ visit: function(node){
+ this.line(node);
+ return this.visitNode(node);
+ },
+
+ /**
+ * Visit `node`.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+ visitNode: function(node){
+ var name = node.constructor.name
+ || node.constructor.toString().match(/function ([^(\s]+)()/)[1];
+ return this['visit' + name](node);
+ },
+
+ /**
+ * Visit all nodes in `block`.
+ *
+ * @param {Block} block
+ * @api public
+ */
+
+ visitBlock: function(block){
+ var len = len = block.nodes.length;
+ for (var i = 0; i < len; ++i) {
+ this.visit(block.nodes[i]);
+ }
+ },
+
+ /**
+ * Visit `doctype`. Sets terse mode to `true` when html 5
+ * is used, causing self-closing tags to end with ">" vs "/>",
+ * and boolean attributes are not mirrored.
+ *
+ * @param {Doctype} doctype
+ * @api public
+ */
+
+ visitDoctype: function(doctype){
+ if (doctype && (doctype.val || !this.doctype)) {
+ this.setDoctype(doctype.val || 'default');
+ }
+
+ if (this.doctype) this.buffer(this.doctype);
+ this.hasCompiledDoctype = true;
+ },
+
+ /**
+ * Visit `mixin`, generating a function that
+ * may be called within the template.
+ *
+ * @param {Mixin} mixin
+ * @api public
+ */
+
+ visitMixin: function(mixin){
+ var name = mixin.name.replace(/-/g, '_') + '_mixin'
+ , args = mixin.args || '';
+
+ if (mixin.block) {
+ this.buf.push('var ' + name + ' = function(' + args + '){');
+ this.visit(mixin.block);
+ this.buf.push('}');
+ } else {
+ this.buf.push(name + '(' + args + ');');
+ }
+ },
+
+ /**
+ * Visit `tag` buffering tag markup, generating
+ * attributes, visiting the `tag`'s code and block.
+ *
+ * @param {Tag} tag
+ * @api public
+ */
+
+ visitTag: function(tag){
+ this.indents++;
+ var name = tag.name;
+
+ if (!this.hasCompiledTag) {
+ if (!this.hasCompiledDoctype && 'html' == name) {
+ this.visitDoctype();
+ }
+ this.hasCompiledTag = true;
+ }
+
+ // pretty print
+ if (this.pp && inlineTags.indexOf(name) == -1) {
+ this.buffer('\\n' + Array(this.indents).join(' '));
+ }
+
+ if (~selfClosing.indexOf(name) && !this.xml) {
+ this.buffer('<' + name);
+ this.visitAttributes(tag.attrs);
+ this.terse
+ ? this.buffer('>')
+ : this.buffer('/>');
+ } else {
+ // Optimize attributes buffering
+ if (tag.attrs.length) {
+ this.buffer('<' + name);
+ if (tag.attrs.length) this.visitAttributes(tag.attrs);
+ this.buffer('>');
+ } else {
+ this.buffer('<' + name + '>');
+ }
+ if (tag.code) this.visitCode(tag.code);
+ if (tag.text) this.buffer(utils.text(tag.text.nodes[0].trimLeft()));
+ this.escape = 'pre' == tag.name;
+ this.visit(tag.block);
+
+ // pretty print
+ if (this.pp && !~inlineTags.indexOf(name) && !tag.textOnly) {
+ this.buffer('\\n' + Array(this.indents).join(' '));
+ }
+
+ this.buffer('</' + name + '>');
+ }
+ this.indents--;
+ },
+
+ /**
+ * Visit `filter`, throwing when the filter does not exist.
+ *
+ * @param {Filter} filter
+ * @api public
+ */
+
+ visitFilter: function(filter){
+ var fn = filters[filter.name];
+
+ // unknown filter
+ if (!fn) {
+ if (filter.isASTFilter) {
+ throw new Error('unknown ast filter "' + filter.name + ':"');
+ } else {
+ throw new Error('unknown filter ":' + filter.name + '"');
+ }
+ }
+ if (filter.isASTFilter) {
+ this.buf.push(fn(filter.block, this, filter.attrs));
+ } else {
+ var text = filter.block.nodes.join('');
+ this.buffer(utils.text(fn(text, filter.attrs)));
+ }
+ },
+
+ /**
+ * Visit `text` node.
+ *
+ * @param {Text} text
+ * @api public
+ */
+
+ visitText: function(text){
+ text = utils.text(text.nodes.join(''));
+ if (this.escape) text = escape(text);
+ this.buffer(text);
+ this.buffer('\\n');
+ },
+
+ /**
+ * Visit a `comment`, only buffering when the buffer flag is set.
+ *
+ * @param {Comment} comment
+ * @api public
+ */
+
+ visitComment: function(comment){
+ if (!comment.buffer) return;
+ if (this.pp) this.buffer('\\n' + Array(this.indents + 1).join(' '));
+ this.buffer('<!--' + utils.escape(comment.val) + '-->');
+ },
+
+ /**
+ * Visit a `BlockComment`.
+ *
+ * @param {Comment} comment
+ * @api public
+ */
+
+ visitBlockComment: function(comment){
+ if (!comment.buffer) return;
+ if (0 == comment.val.indexOf('if')) {
+ this.buffer('<!--[' + comment.val + ']>');
+ this.visit(comment.block);
+ this.buffer('<![endif]-->');
+ } else {
+ this.buffer('<!--' + comment.val);
+ this.visit(comment.block);
+ this.buffer('-->');
+ }
+ },
+
+ /**
+ * Visit `code`, respecting buffer / escape flags.
+ * If the code is followed by a block, wrap it in
+ * a self-calling function.
+ *
+ * @param {Code} code
+ * @api public
+ */
+
+ visitCode: function(code){
+ // Wrap code blocks with {}.
+ // we only wrap unbuffered code blocks ATM
+ // since they are usually flow control
+
+ // Buffer code
+ if (code.buffer) {
+ var val = code.val.trimLeft();
+ this.buf.push('var __val__ = ' + val);
+ val = 'null == __val__ ? "" : __val__';
+ if (code.escape) val = 'escape(' + val + ')';
+ this.buf.push("buf.push(" + val + ");");
+ } else {
+ this.buf.push(code.val);
+ }
+
+ // Block support
+ if (code.block) {
+ if (!code.buffer) this.buf.push('{');
+ this.visit(code.block);
+ if (!code.buffer) this.buf.push('}');
+ }
+ },
+
+ /**
+ * Visit `each` block.
+ *
+ * @param {Each} each
+ * @api public
+ */
+
+ visitEach: function(each){
+ this.buf.push(''
+ + '// iterate ' + each.obj + '\n'
+ + '(function(){\n'
+ + ' if (\'number\' == typeof ' + each.obj + '.length) {\n'
+ + ' for (var ' + each.key + ' = 0, $$l = ' + each.obj + '.length; ' + each.key + ' < $$l; ' + each.key + '++) {\n'
+ + ' var ' + each.val + ' = ' + each.obj + '[' + each.key + '];\n');
+
+ this.visit(each.block);
+
+ this.buf.push(''
+ + ' }\n'
+ + ' } else {\n'
+ + ' for (var ' + each.key + ' in ' + each.obj + ') {\n'
+ // if browser
+ // + ' if (' + each.obj + '.hasOwnProperty(' + each.key + ')){'
+ // end
+ + ' var ' + each.val + ' = ' + each.obj + '[' + each.key + '];\n');
+
+ this.visit(each.block);
+
+ // if browser
+ // this.buf.push(' }\n');
+ // end
+
+ this.buf.push(' }\n }\n}).call(this);\n');
+ },
+
+ /**
+ * Visit `attrs`.
+ *
+ * @param {Array} attrs
+ * @api public
+ */
+
+ visitAttributes: function(attrs){
+ var buf = []
+ , classes = [];
+
+ if (this.terse) buf.push('terse: true');
+
+ attrs.forEach(function(attr){
+ if (attr.name == 'class') {
+ classes.push('(' + attr.val + ')');
+ } else {
+ var pair = "'" + attr.name + "':(" + attr.val + ')';
+ buf.push(pair);
+ }
+ });
+
+ if (classes.length) {
+ classes = classes.join(" + ' ' + ");
+ buf.push("class: " + classes);
+ }
+
+ buf = buf.join(', ').replace('class:', '"class":');
+
+ this.buf.push("buf.push(attrs({ " + buf + " }));");
+ }
+};
+
+/**
+ * Escape the given string of `html`.
+ *
+ * @param {String} html
+ * @return {String}
+ * @api private
+ */
+
+function escape(html){
+ return String(html)
+ .replace(/&(?!\w+;)/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"');
+}
--- /dev/null
+
+/*!
+ * Jade - doctypes
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+module.exports = {
+ '5': '<!DOCTYPE html>'
+ , 'html': '<!DOCTYPE html>'
+ , 'xml': '<?xml version="1.0" encoding="utf-8" ?>'
+ , 'default': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
+ , 'transitional': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
+ , 'strict': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
+ , 'frameset': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'
+ , '1.1': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
+ , 'basic': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">'
+ , 'mobile': '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">'
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - filters
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+module.exports = {
+
+ /**
+ * Wrap text with CDATA block.
+ */
+
+ cdata: function(str){
+ return '<![CDATA[\\n' + str + '\\n]]>';
+ },
+
+ /**
+ * Transform sass to css, wrapped in style tags.
+ */
+
+ sass: function(str){
+ str = str.replace(/\\n/g, '\n');
+ var sass = require('sass').render(str).replace(/\n/g, '\\n');
+ return '<style>' + sass + '</style>';
+ },
+
+ /**
+ * Transform stylus to css, wrapped in style tags.
+ */
+
+ stylus: function(str, options){
+ var ret;
+ str = str.replace(/\\n/g, '\n');
+ var stylus = require('stylus');
+ stylus(str, options).render(function(err, css){
+ if (err) throw err;
+ ret = css.replace(/\n/g, '\\n');
+ });
+ return '<style>' + ret + '</style>';
+ },
+
+ /**
+ * Transform sass to css, wrapped in style tags.
+ */
+
+ less: function(str){
+ var ret;
+ str = str.replace(/\\n/g, '\n');
+ require('less').render(str, function(err, css){
+ if (err) throw err;
+ ret = '<style>' + css.replace(/\n/g, '\\n') + '</style>';
+ });
+ return ret;
+ },
+
+ /**
+ * Transform markdown to html.
+ */
+
+ markdown: function(str){
+ var md;
+
+ // support markdown / discount
+ try {
+ md = require('markdown');
+ } catch (err){
+ try {
+ md = require('discount');
+ } catch (err) {
+ try {
+ md = require('markdown-js');
+ } catch (err) {
+ throw new Error('Cannot find markdown library, install markdown or discount');
+ }
+ }
+ }
+
+ str = str.replace(/\\n/g, '\n');
+ return md.parse(str).replace(/\n/g, '\\n').replace(/'/g,''');
+ },
+
+ /**
+ * Transform coffeescript to javascript.
+ */
+
+ coffeescript: function(str){
+ str = str.replace(/\\n/g, '\n');
+ var js = require('coffee-script').compile(str).replace(/\n/g, '\\n');
+ return '<script type="text/javascript">\\n' + js + '</script>';
+ }
+};
\ No newline at end of file
--- /dev/null
+jade.js
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - inline tags
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+module.exports = [
+ 'a'
+ , 'abbr'
+ , 'acronym'
+ , 'b'
+ , 'br'
+ , 'code'
+ , 'em'
+ , 'font'
+ , 'i'
+ , 'img'
+ , 'ins'
+ , 'kbd'
+ , 'map'
+ , 'samp'
+ , 'small'
+ , 'span'
+ , 'strong'
+ , 'sub'
+ , 'sup'
+];
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Parser = require('./parser')
+ , Compiler = require('./compiler')
+// if node
+ , fs = require('fs');
+// end
+
+/**
+ * Library version.
+ */
+
+exports.version = '0.13.0';
+
+/**
+ * Intermediate JavaScript cache.
+ */
+
+var cache = exports.cache = {};
+
+/**
+ * Expose self closing tags.
+ */
+
+exports.selfClosing = require('./self-closing');
+
+/**
+ * Default supported doctypes.
+ */
+
+exports.doctypes = require('./doctypes');
+
+/**
+ * Text filters.
+ */
+
+exports.filters = require('./filters');
+
+/**
+ * Utilities.
+ */
+
+exports.utils = require('./utils');
+
+/**
+ * Expose `Compiler`.
+ */
+
+exports.Compiler = Compiler;
+
+/**
+ * Expose `Parser`.
+ */
+
+exports.Parser = Parser;
+
+/**
+ * Nodes.
+ */
+
+exports.nodes = require('./nodes');
+
+/**
+ * Render the given attributes object.
+ *
+ * @param {Object} obj
+ * @return {String}
+ * @api private
+ */
+
+function attrs(obj){
+ var buf = []
+ , terse = obj.terse;
+ delete obj.terse;
+ var keys = Object.keys(obj)
+ , len = keys.length;
+ if (len) {
+ buf.push('');
+ for (var i = 0; i < len; ++i) {
+ var key = keys[i]
+ , val = obj[key];
+ if ('boolean' == typeof val || null == val) {
+ if (val) {
+ terse
+ ? buf.push(key)
+ : buf.push(key + '="' + key + '"');
+ }
+ } else if ('class' == key && Array.isArray(val)) {
+ buf.push(key + '="' + escape(val.join(' ')) + '"');
+ } else {
+ buf.push(key + '="' + escape(val) + '"');
+ }
+ }
+ }
+ return buf.join(' ');
+}
+
+/**
+ * Escape the given string of `html`.
+ *
+ * @param {String} html
+ * @return {String}
+ * @api private
+ */
+
+function escape(html){
+ return String(html)
+ .replace(/&(?!\w+;)/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"');
+}
+
+/**
+ * Re-throw the given `err` in context to the
+ * `str` of jade, `filename`, and `lineno`.
+ *
+ * @param {Error} err
+ * @param {String} str
+ * @param {String} filename
+ * @param {String} lineno
+ * @api private
+ */
+
+function rethrow(err, str, filename, lineno){
+ var context = 3
+ , lines = str.split('\n')
+ , start = Math.max(lineno - context, 0)
+ , end = Math.min(lines.length, lineno + context);
+
+ // Error context
+ var context = lines.slice(start, end).map(function(line, i){
+ var curr = i + start + 1;
+ return (curr == lineno ? ' > ' : ' ')
+ + curr
+ + '| '
+ + line;
+ }).join('\n');
+
+ // Alter exception message
+ err.path = filename;
+ err.message = (filename || 'Jade') + ':' + lineno
+ + '\n' + context + '\n\n' + err.message;
+ throw err;
+}
+
+/**
+ * Parse the given `str` of jade and return a function body.
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @return {String}
+ * @api private
+ */
+
+function parse(str, options){
+ var filename = options.filename;
+ try {
+ // Parse
+ var parser = new Parser(str, filename);
+ if (options.debug) parser.debug();
+
+ // Compile
+ var compiler = new (options.compiler || Compiler)(parser.parse(), options)
+ , js = compiler.compile();
+
+ // Debug compiler
+ if (options.debug) {
+ console.log('\n\x1b[1mCompiled Function\x1b[0m:\n\n%s', js.replace(/^/gm, ' '));
+ }
+
+ try {
+ return ''
+ + attrs.toString() + '\n\n'
+ + escape.toString() + '\n\n'
+ + 'var buf = [];\n'
+ + (options.self
+ ? 'var self = locals || {}, __ = __ || locals.__;\n' + js
+ : 'with (locals || {}) {' + js + '}')
+ + 'return buf.join("");';
+ } catch (err) {
+ process.compile(js, filename || 'Jade');
+ return;
+ }
+ } catch (err) {
+ rethrow(err, str, filename, parser.lexer.lineno);
+ }
+}
+
+/**
+ * Compile a `Function` representation of the given jade `str`.
+ *
+ * @param {String} str
+ * @param {Options} options
+ * @return {Function}
+ * @api public
+ */
+
+exports.compile = function(str, options){
+ var options = options || {}
+ , input = JSON.stringify(str)
+ , filename = options.filename
+ ? JSON.stringify(options.filename)
+ : 'undefined';
+
+ // Reduce closure madness by injecting some locals
+ var fn = [
+ 'var __ = { lineno: 1, input: ' + input + ', filename: ' + filename + ' };'
+ , rethrow.toString()
+ , 'try {'
+ , parse(String(str), options || {})
+ , '} catch (err) {'
+ , ' rethrow(err, __.input, __.filename, __.lineno);'
+ , '}'
+ ].join('\n');
+
+ return new Function('locals', fn);
+};
+
+/**
+ * Render the given `str` of jade.
+ *
+ * Options:
+ *
+ * - `scope` Evaluation scope (`this`)
+ * - `locals` Local variable object
+ * - `filename` Used in exceptions, and required by `cache`
+ * - `cache` Cache intermediate JavaScript in memory keyed by `filename`
+ * - `compiler` Compiler to replade jade's default
+ * - `doctype` Specify the default doctype
+ *
+ * @param {String|Buffer} str
+ * @param {Object} options
+ * @return {String}
+ * @api public
+ */
+
+exports.render = function(str, options){
+ var fn
+ , options = options || {}
+ , filename = options.filename;
+
+ // Accept Buffers
+ str = String(str);
+
+ // Cache support
+ if (options.cache) {
+ if (filename) {
+ if (cache[filename]) {
+ fn = cache[filename];
+ } else {
+ fn = cache[filename] = new Function('locals', parse(str, options));
+ }
+ } else {
+ throw new Error('filename is required when using the cache option');
+ }
+ } else {
+ fn = new Function('locals', parse(str, options));
+ }
+
+ // Render the template
+ try {
+ var locals = options.locals || {}
+ , meta = { lineno: 1 };
+ locals.__ = meta;
+ return fn.call(options.scope, locals);
+ } catch (err) {
+ rethrow(err, str, filename, meta.lineno);
+ }
+};
+
+/**
+ * Render jade template at the given `path`.
+ *
+ * @param {String} path
+ * @param {Object} options
+ * @param {Function} fn
+ * @api public
+ */
+
+exports.renderFile = function(path, options, fn){
+ var ret;
+
+ if (typeof options === 'function') {
+ fn = options;
+ options = {};
+ }
+ options.filename = path;
+
+ // Primed cache
+ if (options.cache && cache[path]) {
+ try {
+ ret = exports.render('', options);
+ } catch (err) {
+ return fn(err);
+ }
+ fn(null, ret);
+ } else {
+ fs.readFile(path, 'utf8', function(err, str){
+ if (err) return fn(err);
+ try {
+ ret = exports.render(str, options);
+ } catch (err) {
+ return fn(err);
+ }
+ fn(null, ret);
+ });
+ }
+};
--- /dev/null
+
+/*!
+ * Jade - Lexer
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Initialize `Lexer` with the given `str`.
+ *
+ * @param {String} str
+ * @api private
+ */
+
+var Lexer = module.exports = function Lexer(str) {
+ this.input = str.replace(/\r\n|\r/g, '\n');
+ this.deferredTokens = [];
+ this.lastIndents = 0;
+ this.lineno = 1;
+ this.stash = [];
+ this.indentStack = [];
+ this.indentRe = null;
+ this.pipeless = false;
+};
+
+/**
+ * Lexer prototype.
+ */
+
+Lexer.prototype = {
+
+ /**
+ * Construct a token with the given `type` and `val`.
+ *
+ * @param {String} type
+ * @param {String} val
+ * @return {Object}
+ * @api private
+ */
+
+ tok: function(type, val){
+ return {
+ type: type
+ , line: this.lineno
+ , val: val
+ }
+ },
+
+ /**
+ * Consume the given `len` of input.
+ *
+ * @param {Number} len
+ * @api private
+ */
+
+ consume: function(len){
+ this.input = this.input.substr(len);
+ },
+
+ /**
+ * Scan for `type` with the given `regexp`.
+ *
+ * @param {String} type
+ * @param {RegExp} regexp
+ * @return {Object}
+ * @api private
+ */
+
+ scan: function(regexp, type){
+ var captures;
+ if (captures = regexp.exec(this.input)) {
+ this.consume(captures[0].length);
+ return this.tok(type, captures[1]);
+ }
+ },
+
+ /**
+ * Defer the given `tok`.
+ *
+ * @param {Object} tok
+ * @api private
+ */
+
+ defer: function(tok){
+ this.deferredTokens.push(tok);
+ },
+
+ /**
+ * Lookahead `n` tokens.
+ *
+ * @param {Number} n
+ * @return {Object}
+ * @api private
+ */
+
+ lookahead: function(n){
+ var fetch = n - this.stash.length;
+ while (fetch-- > 0) this.stash.push(this.next());
+ return this.stash[--n];
+ },
+
+ /**
+ * Return the indexOf `start` / `end` delimiters.
+ *
+ * @param {String} start
+ * @param {String} end
+ * @return {Number}
+ * @api private
+ */
+
+ indexOfDelimiters: function(start, end){
+ var str = this.input
+ , nstart = 0
+ , nend = 0
+ , pos = 0;
+ for (var i = 0, len = str.length; i < len; ++i) {
+ if (start == str[i]) {
+ ++nstart;
+ } else if (end == str[i]) {
+ if (++nend == nstart) {
+ pos = i;
+ break;
+ }
+ }
+ }
+ return pos;
+ },
+
+ /**
+ * Stashed token.
+ */
+
+ stashed: function() {
+ return this.stash.length
+ && this.stash.shift();
+ },
+
+ /**
+ * Deferred token.
+ */
+
+ deferred: function() {
+ return this.deferredTokens.length
+ && this.deferredTokens.shift();
+ },
+
+ /**
+ * end-of-source.
+ */
+
+ eos: function() {
+ if (this.input.length) return;
+ if (this.indentStack.length) {
+ this.indentStack.shift();
+ return this.tok('outdent');
+ } else {
+ return this.tok('eos');
+ }
+ },
+
+ /**
+ * Comment.
+ */
+
+ comment: function() {
+ var captures;
+ if (captures = /^ *\/\/(-)?([^\n]*)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var tok = this.tok('comment', captures[2]);
+ tok.buffer = '-' != captures[1];
+ return tok;
+ }
+ },
+
+ /**
+ * Tag.
+ */
+
+ tag: function() {
+ var captures;
+ if (captures = /^(\w[-:\w]*)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var tok, name = captures[1];
+ if (':' == name[name.length - 1]) {
+ name = name.slice(0, -1);
+ tok = this.tok('tag', name);
+ this.deferredTokens.push(this.tok(':'));
+ while (' ' == this.input[0]) this.input = this.input.substr(1);
+ } else {
+ tok = this.tok('tag', name);
+ }
+ return tok;
+ }
+ },
+
+ /**
+ * Filter.
+ */
+
+ filter: function() {
+ return this.scan(/^:(\w+)/, 'filter');
+ },
+
+ /**
+ * Doctype.
+ */
+
+ doctype: function() {
+ return this.scan(/^(?:!!!|doctype) *(\w+)?/, 'doctype');
+ },
+
+ /**
+ * Id.
+ */
+
+ id: function() {
+ return this.scan(/^#([\w-]+)/, 'id');
+ },
+
+ /**
+ * Class.
+ */
+
+ className: function() {
+ return this.scan(/^\.([\w-]+)/, 'class');
+ },
+
+ /**
+ * Text.
+ */
+
+ text: function() {
+ return this.scan(/^(?:\| ?)?([^\n]+)/, 'text');
+ },
+
+ /**
+ * Include.
+ */
+
+ include: function() {
+ return this.scan(/^include +([^\n]+)/, 'include');
+ },
+
+ /**
+ * Mixin.
+ */
+
+ mixin: function(){
+ var captures;
+ if (captures = /^mixin +([-\w]+)(?:\(([^\)]+)\))?/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var tok = this.tok('mixin', captures[1]);
+ tok.args = captures[2];
+ return tok;
+ }
+ },
+
+ /**
+ * Each.
+ */
+
+ each: function() {
+ var captures;
+ if (captures = /^- *each *(\w+)(?: *, *(\w+))? * in *([^\n]+)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var tok = this.tok('each', captures[1]);
+ tok.key = captures[2] || 'index';
+ tok.code = captures[3];
+ return tok;
+ }
+ },
+
+ /**
+ * Code.
+ */
+
+ code: function() {
+ var captures;
+ if (captures = /^(!?=|-)([^\n]+)/.exec(this.input)) {
+ this.consume(captures[0].length);
+ var flags = captures[1];
+ captures[1] = captures[2];
+ var tok = this.tok('code', captures[1]);
+ tok.escape = flags[0] === '=';
+ tok.buffer = flags[0] === '=' || flags[1] === '=';
+ return tok;
+ }
+ },
+
+ /**
+ * Attributes.
+ */
+
+ attrs: function() {
+ if ('(' == this.input[0]) {
+ var index = this.indexOfDelimiters('(', ')')
+ , str = this.input.substr(1, index-1)
+ , tok = this.tok('attrs')
+ , len = str.length
+ , states = ['key']
+ , key = ''
+ , val = ''
+ , quote
+ , c;
+
+ function state(){
+ return states[states.length - 1];
+ }
+
+ function interpolate(attr) {
+ return attr.replace(/#\{([^}]+)\}/g, function(_, expr){
+ return quote + " + (" + expr + ") + " + quote;
+ });
+ }
+
+ this.consume(index + 1);
+ tok.attrs = {};
+
+ function parse(c) {
+ switch (c) {
+ case ',':
+ case '\n':
+ switch (state()) {
+ case 'expr':
+ case 'array':
+ case 'string':
+ case 'object':
+ val += c;
+ break;
+ default:
+ states.push('key');
+ val = val.trim();
+ key = key.trim();
+ if ('' == key) return;
+ tok.attrs[key.replace(/^['"]|['"]$/g, '')] = '' == val
+ ? true
+ : interpolate(val);
+ key = val = '';
+ }
+ break;
+ case '=':
+ switch (state()) {
+ case 'key char':
+ key += c;
+ break;
+ case 'val':
+ case 'expr':
+ case 'array':
+ case 'string':
+ case 'object':
+ val += c;
+ break;
+ default:
+ states.push('val');
+ }
+ break;
+ case '(':
+ if ('val' == state()) states.push('expr');
+ val += c;
+ break;
+ case ')':
+ if ('expr' == state()) states.pop();
+ val += c;
+ break;
+ case '{':
+ if ('val' == state()) states.push('object');
+ val += c;
+ break;
+ case '}':
+ if ('object' == state()) states.pop();
+ val += c;
+ break;
+ case '[':
+ if ('val' == state()) states.push('array');
+ val += c;
+ break;
+ case ']':
+ if ('array' == state()) states.pop();
+ val += c;
+ break;
+ case '"':
+ case "'":
+ switch (state()) {
+ case 'key':
+ states.push('key char');
+ break;
+ case 'key char':
+ states.pop();
+ break;
+ case 'string':
+ if (c == quote) states.pop();
+ val += c;
+ break;
+ default:
+ states.push('string');
+ val += c;
+ quote = c;
+ }
+ break;
+ case '':
+ break;
+ default:
+ switch (state()) {
+ case 'key':
+ case 'key char':
+ key += c;
+ break;
+ default:
+ val += c;
+ }
+ }
+ }
+
+ for (var i = 0; i < len; ++i) {
+ parse(str[i]);
+ }
+
+ parse(',');
+
+ return tok;
+ }
+ },
+
+ /**
+ * Indent | Outdent | Newline.
+ */
+
+ indent: function() {
+ var captures, re;
+
+ // established regexp
+ if (this.indentRe) {
+ captures = this.indentRe.exec(this.input);
+ // determine regexp
+ } else {
+ // tabs
+ re = /^\n(\t*) */;
+ captures = re.exec(this.input);
+
+ // spaces
+ if (captures && !captures[1].length) {
+ re = /^\n( *)/;
+ captures = re.exec(this.input);
+ }
+
+ // established
+ if (captures && captures[1].length) this.indentRe = re;
+ }
+
+ if (captures) {
+ var tok
+ , indents = captures[1].length;
+
+ ++this.lineno;
+ this.consume(indents + 1);
+
+ if (' ' == this.input[0] || '\t' == this.input[0]) {
+ throw new Error('Invalid indentation, you can use tabs or spaces but not both');
+ }
+
+ // blank line
+ if ('\n' == this.input[0]) return this.tok('newline');
+
+ // outdent
+ if (this.indentStack.length && indents < this.indentStack[0]) {
+ while (this.indentStack.length && this.indentStack[0] > indents) {
+ this.stash.push(this.tok('outdent'));
+ this.indentStack.shift();
+ }
+ tok = this.stash.pop();
+ // indent
+ } else if (indents && indents != this.indentStack[0]) {
+ this.indentStack.unshift(indents);
+ tok = this.tok('indent', indents);
+ // newline
+ } else {
+ tok = this.tok('newline');
+ }
+
+ return tok;
+ }
+ },
+
+ /**
+ * Pipe-less text consumed only when
+ * pipeless is true;
+ */
+
+ pipelessText: function() {
+ if (this.pipeless) {
+ if ('\n' == this.input[0]) return;
+ var i = this.input.indexOf('\n');
+ if (-1 == i) i = this.input.length;
+ var str = this.input.substr(0, i);
+ this.consume(str.length);
+ return this.tok('text', str);
+ }
+ },
+
+ /**
+ * ':'
+ */
+
+ colon: function() {
+ return this.scan(/^: */, ':');
+ },
+
+ /**
+ * Return the next token object, or those
+ * previously stashed by lookahead.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+ advance: function(){
+ return this.stashed()
+ || this.next();
+ },
+
+ /**
+ * Return the next token object.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+ next: function() {
+ return this.deferred()
+ || this.eos()
+ || this.pipelessText()
+ || this.doctype()
+ || this.include()
+ || this.mixin()
+ || this.tag()
+ || this.filter()
+ || this.each()
+ || this.code()
+ || this.id()
+ || this.className()
+ || this.attrs()
+ || this.indent()
+ || this.comment()
+ || this.colon()
+ || this.text();
+ }
+};
--- /dev/null
+
+/*!
+ * Jade - nodes - BlockComment
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `BlockComment` with the given `block`.
+ *
+ * @param {String} val
+ * @param {Block} block
+ * @param {Boolean} buffer
+ * @api public
+ */
+
+var BlockComment = module.exports = function BlockComment(val, block, buffer) {
+ this.block = block;
+ this.val = val;
+ this.buffer = buffer;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+BlockComment.prototype.__proto__ = Node.prototype;
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - nodes - Block
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Block` with an optional `node`.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+var Block = module.exports = function Block(node){
+ this.nodes = [];
+ if (node) this.push(node);
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Block.prototype.__proto__ = Node.prototype;
+
+/**
+ * Pust the given `node`.
+ *
+ * @param {Node} node
+ * @return {Number}
+ * @api public
+ */
+
+Block.prototype.push = function(node){
+ return this.nodes.push(node);
+};
+
+/**
+ * Unshift the given `node`.
+ *
+ * @param {Node} node
+ * @return {Number}
+ * @api public
+ */
+
+Block.prototype.unshift = function(node){
+ return this.nodes.unshift(node);
+};
--- /dev/null
+
+/*!
+ * Jade - nodes - Code
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `Code` node with the given code `val`.
+ * Code may also be optionally buffered and escaped.
+ *
+ * @param {String} val
+ * @param {Boolean} buffer
+ * @param {Boolean} escape
+ * @api public
+ */
+
+var Code = module.exports = function Code(val, buffer, escape) {
+ this.val = val;
+ this.buffer = buffer;
+ this.escape = escape;
+ if (/^ *else/.test(val)) this.instrumentLineNumber = false;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Code.prototype.__proto__ = Node.prototype;
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - nodes - Comment
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `Comment` with the given `val`, optionally `buffer`,
+ * otherwise the comment may render in the output.
+ *
+ * @param {String} val
+ * @param {Boolean} buffer
+ * @api public
+ */
+
+var Comment = module.exports = function Comment(val, buffer) {
+ this.val = val;
+ this.buffer = buffer;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Comment.prototype.__proto__ = Node.prototype;
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - nodes - Doctype
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `Doctype` with the given `val`.
+ *
+ * @param {String} val
+ * @api public
+ */
+
+var Doctype = module.exports = function Doctype(val) {
+ this.val = val;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Doctype.prototype.__proto__ = Node.prototype;
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - nodes - Each
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize an `Each` node, representing iteration
+ *
+ * @param {String} obj
+ * @param {String} val
+ * @param {String} key
+ * @param {Block} block
+ * @api public
+ */
+
+var Each = module.exports = function Each(obj, val, key, block) {
+ this.obj = obj;
+ this.val = val;
+ this.key = key;
+ this.block = block;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Each.prototype.__proto__ = Node.prototype;
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - nodes - Filter
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , Block = require('./block');
+
+/**
+ * Initialize a `Filter` node with the given
+ * filter `name` and `block`.
+ *
+ * @param {String} name
+ * @param {Block|Node} block
+ * @api public
+ */
+
+var Filter = module.exports = function Filter(name, block, attrs) {
+ this.name = name;
+ this.block = block;
+ this.attrs = attrs;
+ this.isASTFilter = block instanceof Block;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Filter.prototype.__proto__ = Node.prototype;
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - nodes
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+exports.Node = require('./node');
+exports.Tag = require('./tag');
+exports.Code = require('./code');
+exports.Each = require('./each');
+exports.Text = require('./text');
+exports.Block = require('./block');
+exports.Mixin = require('./mixin');
+exports.Filter = require('./filter');
+exports.Comment = require('./comment');
+exports.BlockComment = require('./block-comment');
+exports.Doctype = require('./doctype');
--- /dev/null
+
+/*!
+ * Jade - nodes - Mixin
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Mixin` with `name` and `block`.
+ *
+ * @param {String} name
+ * @param {String} args
+ * @param {Block} block
+ * @api public
+ */
+
+var Mixin = module.exports = function Mixin(name, args, block){
+ this.name = name;
+ this.args = args;
+ this.block = block;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Mixin.prototype.__proto__ = Node.prototype;
+
--- /dev/null
+
+/*!
+ * Jade - nodes - Node
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Initialize a `Node`.
+ *
+ * @api public
+ */
+
+var Node = module.exports = function Node(){};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - nodes - Tag
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node'),
+ Block = require('./block');
+
+/**
+ * Initialize a `Tag` node with the given tag `name` and optional `block`.
+ *
+ * @param {String} name
+ * @param {Block} block
+ * @api public
+ */
+
+var Tag = module.exports = function Tag(name, block) {
+ this.name = name;
+ this.attrs = [];
+ this.block = block || new Block;
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Tag.prototype.__proto__ = Node.prototype;
+
+/**
+ * Set attribute `name` to `val`, keep in mind these become
+ * part of a raw js object literal, so to quote a value you must
+ * '"quote me"', otherwise or example 'user.name' is literal JavaScript.
+ *
+ * @param {String} name
+ * @param {String} val
+ * @return {Tag} for chaining
+ * @api public
+ */
+
+Tag.prototype.setAttribute = function(name, val){
+ this.attrs.push({ name: name, val: val });
+ return this;
+};
+
+/**
+ * Remove attribute `name` when present.
+ *
+ * @param {String} name
+ * @api public
+ */
+
+Tag.prototype.removeAttribute = function(name){
+ for (var i = 0, len = this.attrs.length; i < len; ++i) {
+ if (this.attrs[i] && this.attrs[i].name == name) {
+ delete this.attrs[i];
+ }
+ }
+};
+
+/**
+ * Get attribute value by `name`.
+ *
+ * @param {String} name
+ * @return {String}
+ * @api public
+ */
+
+Tag.prototype.getAttribute = function(name){
+ for (var i = 0, len = this.attrs.length; i < len; ++i) {
+ if (this.attrs[i] && this.attrs[i].name == name) {
+ return this.attrs[i].val;
+ }
+ }
+};
--- /dev/null
+
+/*!
+ * Jade - nodes - Text
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a `Text` node with optional `line`.
+ *
+ * @param {String} line
+ * @api public
+ */
+
+var Text = module.exports = function Text(line) {
+ this.nodes = [];
+ if ('string' == typeof line) this.push(line);
+};
+
+/**
+ * Inherit from `Node`.
+ */
+
+Text.prototype.__proto__ = Node.prototype;
+
+/**
+ * Push the given `node.`
+ *
+ * @param {Node} node
+ * @return {Number}
+ * @api public
+ */
+
+Text.prototype.push = function(node){
+ return this.nodes.push(node);
+};
--- /dev/null
+
+/*!
+ * Jade - Parser
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Lexer = require('./lexer')
+ , nodes = require('./nodes')
+ , path = require('path')
+ , dirname = path.dirname
+ , join = path.join
+ , fs = require('fs');
+
+/**
+ * Initialize `Parser` with the given input `str` and `filename`.
+ *
+ * @param {String} str
+ * @param {String} filename
+ * @api public
+ */
+
+var Parser = exports = module.exports = function Parser(str, filename){
+ this.input = str;
+ this.lexer = new Lexer(str);
+ this.filename = filename;
+};
+
+/**
+ * Tags that may not contain tags.
+ */
+
+var textOnly = exports.textOnly = ['code', 'script', 'textarea', 'style', 'title'];
+
+/**
+ * Parser prototype.
+ */
+
+Parser.prototype = {
+
+ /**
+ * Output parse tree to stdout.
+ *
+ * @api public
+ */
+
+ debug: function(){
+ var lexer = new Lexer(this.input)
+ , tree = require('sys').inspect(this.parse(), false, 12, true);
+ console.log('\n\x1b[1mParse Tree\x1b[0m:\n');
+ console.log(tree);
+ this.lexer = lexer;
+ },
+
+ /**
+ * Return the next token object.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+ advance: function(){
+ return this.lexer.advance();
+ },
+
+ /**
+ * Single token lookahead.
+ *
+ * @return {Object}
+ * @api private
+ */
+
+ peek: function() {
+ return this.lookahead(1);
+ },
+
+ /**
+ * Return lexer lineno.
+ *
+ * @return {Number}
+ * @api private
+ */
+
+ line: function() {
+ return this.lexer.lineno;
+ },
+
+ /**
+ * `n` token lookahead.
+ *
+ * @param {Number} n
+ * @return {Object}
+ * @api private
+ */
+
+ lookahead: function(n){
+ return this.lexer.lookahead(n);
+ },
+
+ /**
+ * Parse input returning a string of js for evaluation.
+ *
+ * @return {String}
+ * @api public
+ */
+
+ parse: function(){
+ var block = new nodes.Block;
+ block.line = this.line();
+ while ('eos' != this.peek().type) {
+ if ('newline' == this.peek().type) {
+ this.advance();
+ } else {
+ block.push(this.parseExpr());
+ }
+ }
+ return block;
+ },
+
+ /**
+ * Expect the given type, or throw an exception.
+ *
+ * @param {String} type
+ * @api private
+ */
+
+ expect: function(type){
+ if (this.peek().type === type) {
+ return this.advance();
+ } else {
+ throw new Error('expected "' + type + '", but got "' + this.peek().type + '"');
+ }
+ },
+
+ /**
+ * Accept the given `type`.
+ *
+ * @param {String} type
+ * @api private
+ */
+
+ accept: function(type){
+ if (this.peek().type === type) {
+ return this.advance();
+ }
+ },
+
+ /**
+ * tag
+ * | doctype
+ * | mixin
+ * | include
+ * | filter
+ * | comment
+ * | text
+ * | each
+ * | code
+ * | id
+ * | class
+ */
+
+ parseExpr: function(){
+ switch (this.peek().type) {
+ case 'tag':
+ return this.parseTag();
+ case 'mixin':
+ return this.parseMixin();
+ case 'include':
+ return this.parseInclude();
+ case 'doctype':
+ return this.parseDoctype();
+ case 'filter':
+ return this.parseFilter();
+ case 'comment':
+ return this.parseComment();
+ case 'text':
+ return this.parseText();
+ case 'each':
+ return this.parseEach();
+ case 'code':
+ return this.parseCode();
+ case 'id':
+ case 'class':
+ var tok = this.advance();
+ this.lexer.defer(this.lexer.tok('tag', 'div'));
+ this.lexer.defer(tok);
+ return this.parseExpr();
+ default:
+ throw new Error('unexpected token "' + this.peek().type + '"');
+ }
+ },
+
+ /**
+ * Text
+ */
+
+ parseText: function(){
+ var tok = this.expect('text')
+ , node = new nodes.Text(tok.val);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * code
+ */
+
+ parseCode: function(){
+ var tok = this.expect('code')
+ , node = new nodes.Code(tok.val, tok.buffer, tok.escape);
+ node.line = this.line();
+ if ('indent' == this.peek().type) {
+ node.block = this.parseBlock();
+ }
+ return node;
+ },
+
+ /**
+ * comment
+ */
+
+ parseComment: function(){
+ var tok = this.expect('comment')
+ , node;
+
+ if ('indent' == this.peek().type) {
+ node = new nodes.BlockComment(tok.val, this.parseBlock(), tok.buffer);
+ } else {
+ node = new nodes.Comment(tok.val, tok.buffer);
+ }
+
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * doctype
+ */
+
+ parseDoctype: function(){
+ var tok = this.expect('doctype')
+ , node = new nodes.Doctype(tok.val);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * filter attrs? text-block
+ */
+
+ parseFilter: function(){
+ var block
+ , tok = this.expect('filter')
+ , attrs = this.accept('attrs');
+
+ this.lexer.pipeless = true;
+ block = this.parseTextBlock();
+ this.lexer.pipeless = false;
+
+ var node = new nodes.Filter(tok.val, block, attrs && attrs.attrs);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * tag ':' attrs? block
+ */
+
+ parseASTFilter: function(){
+ var block
+ , tok = this.expect('tag')
+ , attrs = this.accept('attrs');
+
+ this.expect(':');
+ block = this.parseBlock();
+
+ var node = new nodes.Filter(tok.val, block, attrs && attrs.attrs);
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * each block
+ */
+
+ parseEach: function(){
+ var tok = this.expect('each')
+ , node = new nodes.Each(tok.code, tok.val, tok.key, this.parseBlock());
+ node.line = this.line();
+ return node;
+ },
+
+ /**
+ * include
+ */
+
+ parseInclude: function(){
+ if (!this.filename)
+ throw new Error('the "filename" option is required to use includes');
+
+ var path = name = this.expect('include').val.trim()
+ , dir = dirname(this.filename)
+ , path = join(dir, path + '.jade');
+
+ var str = fs.readFileSync(path, 'utf8')
+ , parser = new Parser(str, path)
+ , ast = parser.parse();
+
+ return ast;
+ },
+
+ /**
+ * mixin block
+ */
+
+ parseMixin: function(){
+ var tok = this.expect('mixin')
+ , name = tok.val
+ , args = tok.args;
+ var block = 'indent' == this.peek().type
+ ? this.parseBlock()
+ : null;
+ return new nodes.Mixin(name, args, block);
+ },
+
+ /**
+ * indent (text | newline)* outdent
+ */
+
+ parseTextBlock: function(){
+ var text = new nodes.Text;
+ text.line = this.line();
+ var spaces = this.expect('indent').val;
+ if (null == this._spaces) this._spaces = spaces;
+ var indent = Array(spaces - this._spaces + 1).join(' ');
+ while ('outdent' != this.peek().type) {
+ switch (this.peek().type) {
+ case 'newline':
+ text.push('\\n');
+ this.advance();
+ break;
+ case 'indent':
+ text.push('\\n');
+ this.parseTextBlock().nodes.forEach(function(node){
+ text.push(node);
+ });
+ text.push('\\n');
+ break;
+ default:
+ text.push(indent + this.advance().val);
+ }
+ }
+
+ if (spaces == this._spaces) this._spaces = null;
+ this.expect('outdent');
+ return text;
+ },
+
+ /**
+ * indent expr* outdent
+ */
+
+ parseBlock: function(){
+ var block = new nodes.Block;
+ block.line = this.line();
+ this.expect('indent');
+ while ('outdent' != this.peek().type) {
+ if ('newline' == this.peek().type) {
+ this.advance();
+ } else {
+ block.push(this.parseExpr());
+ }
+ }
+ this.expect('outdent');
+ return block;
+ },
+
+ /**
+ * tag (attrs | class | id)* (text | code | ':')? newline* block?
+ */
+
+ parseTag: function(){
+ // ast-filter look-ahead
+ var i = 2;
+ if ('attrs' == this.lookahead(i).type) ++i;
+ if (':' == this.lookahead(i).type) {
+ if ('indent' == this.lookahead(++i).type) {
+ return this.parseASTFilter();
+ }
+ }
+
+ var name = this.advance().val
+ , tag = new nodes.Tag(name);
+
+ tag.line = this.line();
+
+ // (attrs | class | id)*
+ out:
+ while (true) {
+ switch (this.peek().type) {
+ case 'id':
+ case 'class':
+ var tok = this.advance();
+ tag.setAttribute(tok.type, "'" + tok.val + "'");
+ continue;
+ case 'attrs':
+ var obj = this.advance().attrs
+ , names = Object.keys(obj);
+ for (var i = 0, len = names.length; i < len; ++i) {
+ var name = names[i]
+ , val = obj[name];
+ tag.setAttribute(name, val);
+ }
+ continue;
+ default:
+ break out;
+ }
+ }
+
+ // check immediate '.'
+ if ('.' == this.peek().val) {
+ tag.textOnly = true;
+ this.advance();
+ }
+
+ // (text | code | ':')?
+ switch (this.peek().type) {
+ case 'text':
+ tag.text = this.parseText();
+ break;
+ case 'code':
+ tag.code = this.parseCode();
+ break;
+ case ':':
+ this.advance();
+ tag.block = new nodes.Block;
+ tag.block.push(this.parseTag());
+ break;
+ }
+
+ // newline*
+ while ('newline' == this.peek().type) this.advance();
+
+ tag.textOnly = tag.textOnly || ~textOnly.indexOf(tag.name);
+
+ // script special-case
+ if ('script' == tag.name) {
+ var type = tag.getAttribute('type');
+ if (type && 'text/javascript' != type.replace(/^['"]|['"]$/g, '')) {
+ tag.textOnly = false;
+ }
+ }
+
+ // block?
+ if ('indent' == this.peek().type) {
+ if (tag.textOnly) {
+ this.lexer.pipeless = true;
+ tag.block = this.parseTextBlock();
+ this.lexer.pipeless = false;
+ } else {
+ var block = this.parseBlock();
+ if (tag.block) {
+ for (var i = 0, len = block.nodes.length; i < len; ++i) {
+ tag.block.push(block.nodes[i]);
+ }
+ } else {
+ tag.block = block;
+ }
+ }
+ }
+
+ return tag;
+ }
+};
--- /dev/null
+
+/*!
+ * Jade - self closing tags
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+module.exports = [
+ 'meta'
+ , 'img'
+ , 'link'
+ , 'input'
+ , 'area'
+ , 'base'
+ , 'col'
+ , 'br'
+ , 'hr'
+];
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Jade - utils
+ * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
+ * MIT Licensed
+ */
+
+/**
+ * Convert interpolation in the given string to JavaScript.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+var interpolate = exports.interpolate = function(str){
+ return str.replace(/(\\)?([#!]){(.*?)}/g, function(str, escape, flag, code){
+ return escape
+ ? str
+ : "' + "
+ + ('!' == flag ? '' : 'escape')
+ + "((interp = " + code.replace(/\\'/g, "'")
+ + ") == null ? '' : interp) + '";
+ });
+};
+
+/**
+ * Escape single quotes in `str`.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+var escape = exports.escape = function(str) {
+ return str.replace(/'/g, "\\'");
+};
+
+/**
+ * Interpolate, and escape the given `str`.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+exports.text = function(str){
+ return interpolate(escape(str));
+};
\ No newline at end of file
--- /dev/null
+{
+ "name": "jade",
+ "description": "Jade template engine",
+ "version": "0.13.0",
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "repository": "git://github.com/visionmedia/jade",
+ "main": "./index.js",
+ "bin": { "jade": "./bin/jade" },
+ "devDependencies": {
+ "expresso": "0.6.4",
+ "coffee-script": ">= 0.0.1",
+ "sass": ">= 0.0.1",
+ "less": ">= 0.0.1",
+ "markdown": ">= 0.0.1",
+ "stylus": ">= 0.0.1"
+ },
+ "scripts" : { "prepublish" : "npm prune" },
+ "engines": { "node": ">= 0.1.98" }
+}
\ No newline at end of file
--- /dev/null
+raw
+presentation
+test.coffee
+parser.output
+test/fixtures/underscore
+test/*.js
+examples/beautiful_code/parse.coffee
+*.gem
\ No newline at end of file
--- /dev/null
+fs = require 'fs'
+helpers = require './lib/helpers'
+CoffeeScript = require './lib/coffee-script'
+{spawn, exec} = require 'child_process'
+path = require 'path'
+
+# ANSI Terminal Colors.
+red = '\033[0;31m'
+green = '\033[0;32m'
+reset = '\033[0m'
+
+# Run a CoffeeScript through our node/coffee interpreter.
+run = (args) ->
+ proc = spawn 'bin/coffee', args
+ proc.stderr.on 'data', (buffer) -> puts buffer.toString()
+ proc.on 'exit', (status) -> process.exit(1) if status != 0
+
+# Log a message with a color.
+log = (message, color, explanation) ->
+ puts 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"
+ bin = "#{base}/bin"
+ node = "~/.node_libraries/coffee-script"
+ puts "Installing CoffeeScript to #{lib}"
+ puts "Linking to #{node}"
+ puts "Linking 'coffee' to #{bin}/coffee"
+ exec([
+ "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 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$/)
+ 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) ->
+ print stdout if stdout
+ print stderr if stderr
+ throw err if err
+
+
+task 'build:parser', 'rebuild the Jison parser (run build first)', ->
+ require 'jison'
+ parser = require('./lib/grammar').parser
+ js = parser.generate()
+ # TODO: Remove this when the Jison patch is released.
+ js = js.replace 'if (require.main === module)', "if (typeof module !== 'undefined' && require.main === module)"
+ fs.writeFile 'lib/parser.js', js
+
+
+task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', ->
+ 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:browser', 'rebuild the merged script for inclusion in the browser', ->
+ exec 'rake browser', (err) ->
+ throw err if err
+
+
+task 'doc:site', 'watch and continually rebuild the documentation for the website', ->
+ exec 'rake doc'
+
+
+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 (of everything in src)', ->
+ exec 'time bin/coffee -p src/ > /dev/null', (err, stdout, stderr) ->
+ print stderr
+
+task 'loc', 'count the lines of source code in the CoffeeScript compiler', ->
+ sources = ['src/coffee-script.coffee', 'src/grammar.coffee', 'src/helpers.coffee', 'src/lexer.coffee', 'src/nodes.coffee', 'src/rewriter.coffee', 'src/scope.coffee']
+ exec "cat #{ sources.join(' ') } | grep -v '^\\( *#\\|\\s*$\\)' | wc -l | tr -s ' '", (err, stdout) ->
+ print stdout
+
+
+runTests = (CoffeeScript) ->
+ startTime = Date.now()
+ passedTests = failedTests = 0
+ for all name, func of require 'assert'
+ global[name] = -> ++passedTests; 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', ->
+ 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
--- /dev/null
+Copyright (c) 2010 Jeremy Ashkenas
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- /dev/null
+=
+ {
+ } } {
+ { { } }
+ } }{ {
+ { }{ } } _____ __ __
+ ( }{ }{ { ) / ____| / _|/ _|
+ .- { { } { }} -. | | ___ | |_| |_ ___ ___
+ ( ( } { } { } } ) | | / _ \| _| _/ _ \/ _ \
+ |`-..________ ..-'| | |___| (_) | | | || __/ __/
+ | | \_____\___/|_| |_| \___|\___|
+ | ;--.
+ | (__ \ _____ _ _
+ | | ) ) / ____| (_) | |
+ | |/ / | (___ ___ _ __ _ _ __ | |_
+ | ( / \___ \ / __| '__| | '_ \| __|
+ | |/ ____) | (__| | | | |_) | |_
+ | | |_____/ \___|_| |_| .__/ \__|
+ `-.._________..-' | |
+ |_|
+
+
+ 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:
+ sudo 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
+
\ No newline at end of file
--- /dev/null
+require 'erb'
+require 'fileutils'
+require 'rake/testtask'
+require 'rubygems'
+require 'yui/compressor'
+
+HEADER = <<-EOS
+/**
+ * CoffeeScript Compiler v0.9.4
+ * http://coffeescript.org
+ *
+ * Copyright 2010, Jeremy Ashkenas
+ * Released under the MIT License
+ */
+EOS
+
+desc "Build the documentation page"
+task :doc do
+ source = 'documentation/index.html.erb'
+ child = fork { exec "bin/coffee -bcw -o documentation/js documentation/coffee/*.coffee" }
+ at_exit { Process.kill("INT", child) }
+ Signal.trap("INT") { exit }
+ loop do
+ mtime = File.stat(source).mtime
+ if !@mtime || mtime > @mtime
+ rendered = ERB.new(File.read(source)).result(binding)
+ File.open('index.html', 'w+') {|f| f.write(rendered) }
+ end
+ @mtime = mtime
+ sleep 1
+ end
+end
+
+desc "Build the single concatenated and minified script for the browser"
+task :browser do
+ sources = %w(helpers rewriter lexer parser scope nodes coffee-script browser)
+ code = sources.inject '' do |js, name|
+ js << <<-"JS"
+ require['./#{name}'] = new function(){
+ var exports = this;
+ #{ File.read "lib/#{name}.js" }
+ }
+ JS
+ end
+ code = YUI::JavaScriptCompressor.new.compress(<<-"JS")
+ this.CoffeeScript = function(){
+ function require(path){ return require[path] }
+ #{ code }
+ return require['./coffee-script']
+ }()
+ JS
+ File.open('extras/coffee-script.js', 'wb+') {|f| f.write(HEADER + code) }
+end
--- /dev/null
+#!/usr/bin/env node
+
+var path = require('path');
+var fs = require('fs');
+var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
+
+require(lib + '/helpers').extend(global, require('sys'));
+require(lib + '/cake').run();
--- /dev/null
+#!/usr/bin/env node
+
+var path = require('path');
+var fs = require('fs');
+var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
+
+require(lib + '/helpers').extend(global, require('sys'));
+require(lib + '/command').run();
--- /dev/null
+launch() if ignition is on
+
+volume = 10 if band isnt SpinalTap
+
+letTheWildRumpusBegin() unless answer is no
+
+if car.speed < limit then accelerate()
+
+winner = yes if pick in [47, 92, 13]
+
+print inspect "My name is " + @name
--- /dev/null
+# Eat lunch.
+lunch = eat food for food in ['toast', 'cheese', 'wine']
+
+# Naive collision detection.
+for roid, pos in asteroids
+ for roid2 in asteroids when roid isnt roid2
+ roid.explode() if roid.overlaps roid2
\ No newline at end of file
--- /dev/null
+###
+CoffeeScript Compiler v0.9.4
+Released under the MIT License
+###
\ No newline at end of file
--- /dev/null
+fs = require 'fs'
+
+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
\ No newline at end of file
--- /dev/null
+class Animal
+ constructor: (@name) ->
+
+ move: (meters) ->
+ alert @name + " moved " + meters + "m."
+
+class Snake extends Animal
+ move: ->
+ alert "Slithering..."
+ super 5
+
+class Horse extends Animal
+ move: ->
+ alert "Galloping..."
+ super 45
+
+sam = new Snake "Sammy the Python"
+tom = new Horse "Tommy the Palomino"
+
+sam.move()
+tom.move()
+
+
+
+
--- /dev/null
+cholesterol = 127
+
+healthy = 200 > cholesterol > 60
+
+
--- /dev/null
+mood = greatlyImproved if singing
+
+if happy and knowsIt
+ clapsHands()
+ chaChaCha()
+else
+ showIt()
+
+date = if friday then sue else jill
+
+options or= defaults
\ No newline at end of file
--- /dev/null
+hi = `function() {
+ return [document.title, "Hello JavaScript"].join(": ");
+}`
+
+
--- /dev/null
+solipsism = true if mind? and not world?
+
+speed ?= 140
+
+
+
+
+
--- /dev/null
+grade = (student) ->
+ if student.excellentWork
+ "A+"
+ else if student.okayStuff
+ if student.triedHard then "B" else "B-"
+ else
+ "C"
+
+eldest = if 24 > 21 then "Liz" else "Ike"
\ No newline at end of file
--- /dev/null
+six = (one = 1) + (two = 2) + (three = 3)
\ No newline at end of file
--- /dev/null
+# The first ten global properties.
+
+globals = (name for name of window)[0...10]
\ No newline at end of file
--- /dev/null
+alert(
+ try
+ nonexistent / undefined
+ catch error
+ "And the error is ... " + error
+)
\ No newline at end of file
--- /dev/null
+Account = (customer, cart) ->
+ @customer = customer
+ @cart = cart
+
+ $('.shopping_cart').bind 'click', (event) =>
+ @customer.purchase @cart
\ No newline at end of file
--- /dev/null
+square = (x) -> x * x
+cube = (x) -> square(x) * x
--- /dev/null
+html = '''
+ <strong>
+ cup of coffeescript
+ </strong>
+ '''
\ No newline at end of file
--- /dev/null
+author = "Wittgenstein"
+quote = "A picture is a fact. -- #{author}"
\ No newline at end of file
--- /dev/null
+sentence = "#{ 22 / 7 } is a decent approximation of π"
+
+sep = "[.\\/\\- ]"
+dates = /\d+#{sep}\d+#{sep}\d+/g
+
+
--- /dev/null
+weatherReport = (location) ->
+ # Make an Ajax request to fetch the weather...
+ [location, 72, "Mostly Sunny"]
+
+[city, temp, forecast] = weatherReport "Berkeley, CA"
\ No newline at end of file
--- /dev/null
+yearsOld = max: 10, ida: 9, tim: 11
+
+ages = for child, age of yearsOld
+ child + " is " + age
\ No newline at end of file
--- /dev/null
+futurists =
+ sculptor: "Umberto Boccioni"
+ painter: "Vladimir Burliuk"
+ poet:
+ name: "F.T. Marinetti"
+ address: [
+ "Via Roma 42R"
+ "Bellagio, Italy 22021"
+ ]
+
+{poet: {name, address: [street, city]}} = futurists
\ No newline at end of file
--- /dev/null
+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
\ No newline at end of file
--- /dev/null
+$('.account').css class: 'active'
\ No newline at end of file
--- /dev/null
+# Assignment:
+number = 42
+opposite = true
+
+# Conditions:
+number = -42 if opposite
+
+# Functions:
+square = (x) -> x * x
+
+# Arrays:
+list = [1, 2, 3, 4, 5]
+
+# Objects:
+math =
+ root: Math.sqrt
+ square: square
+ cube: (x) -> x * square x
+
+# Splats:
+race = (winner, runners...) ->
+ print winner, runners
+
+# Existence:
+alert "I knew it!" if elvis?
+
+# Array comprehensions:
+cubes = math.cube num for num in list
--- /dev/null
+theBait = 1000
+theSwitch = 0
+
+[theBait, theSwitch] = [theSwitch, theBait]
\ No newline at end of file
--- /dev/null
+tag = "<impossible>"
+
+[open, contents..., close] = tag.split("")
+
+
+
+
--- /dev/null
+String::dasherize = ->
+ this.replace /_/g, "-"
\ No newline at end of file
--- /dev/null
+countdown = num for num in [10..1]
+
+deliverEggs = ->
+ for i in [0...eggs.length] by 12
+ dozen = eggs[i...i+12]
+ deliver new eggCarton dozen
--- /dev/null
+outer = 1
+changeNumbers = ->
+ inner = -1
+ outer = 10
+inner = changeNumbers()
\ No newline at end of file
--- /dev/null
+numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+
+threeToSix = numbers[3..6]
+
+copy = numbers[0...numbers.length]
+
--- /dev/null
+lottery.drawWinner?().address?.zipcode
--- /dev/null
+gold = silver = rest = "unknown"
+
+awardMedals = (first, second, others...) ->
+ gold = first
+ silver = second
+ rest = others
+
+contenders = [
+ "Michael Phelps"
+ "Liu Xiang"
+ "Yao Ming"
+ "Allyson Felix"
+ "Shawn Johnson"
+ "Roman Sebrle"
+ "Guo Jingjing"
+ "Tyson Gay"
+ "Asafa Powell"
+ "Usain Bolt"
+]
+
+awardMedals contenders...
+
+alert "Gold: " + gold
+alert "Silver: " + silver
+alert "The Field: " + rest
\ No newline at end of file
--- /dev/null
+numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+
+numbers[3..6] = [-3, -4, -5, -6]
+
+
--- /dev/null
+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..."
+
+
--- /dev/null
+switch day
+ when "Mon" then go work
+ when "Tue" then go relax
+ when "Thu" then go iceFishing
+ when "Fri", "Sat"
+ if day is bingoDay
+ go bingo
+ go dancing
+ when "Sun" then go church
+ else go work
\ No newline at end of file
--- /dev/null
+try
+ allHellBreaksLoose()
+ catsAndDogsLivingTogether()
+catch error
+ print error
+finally
+ cleanUp()
\ No newline at end of file
--- /dev/null
+# Econ 101
+if this.studyingEconomics
+ buy() while supply > demand
+ sell() until supply > demand
+
+# Nursery Rhyme
+num = 6
+lyrics = while num -= 1
+ num + " little monkeys, jumping on the bed.
+ One fell out and bumped his head."
--- /dev/null
+body {
+ font-size: 13px;
+ line-height: 20px;
+ color: #191933;
+ font-family: "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif !important;
+}
+.container {
+ width: 950px;
+ margin: 0;
+ padding: 80px 0px 50px 50px;
+}
+p, li {
+ width: 625px;
+}
+a {
+ color: #000055;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin-top: 50px;
+}
+br.clear {
+ height: 0;
+ clear: both;
+}
+ul {
+ padding-left: 20px;
+}
+b.header {
+ color: #000055;
+ display: block;
+ margin: 40px 0 5px 0;
+ font-size: 16px;
+}
+li {
+ margin-bottom: 10px;
+}
+table {
+ margin: 16px 0 0 13px; padding: 0;
+ width: 625px;
+}
+ tr, td {
+ margin: 0; padding: 0;
+ }
+ td {
+ padding: 9px 15px 9px 0;
+ }
+code, pre, tt, textarea {
+ font-family: Monaco, Consolas, "Lucida Console", monospace;
+ font-size: 12px;
+ line-height: 18px;
+ color: #191955;
+ white-space: pre-wrap;
+ word-wrap: break-word;
+}
+ tt {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 85%;
+ padding: 0px 0.2em;
+ }
+ pre {
+ border-left: 6px solid #222255;
+ margin-left: 13px;
+ padding: 3px 0 3px 12px;
+ font-size: 12px;
+ }
+ pre.no_bar {
+ border-left: 0;
+ margin-left: 0;
+ padding-left: 0;
+ }
+div.code {
+ position: relative;
+ border: 1px solid #cacaca;
+ background: #fafaff;
+ 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;
+ right: 8px; bottom: 8px;
+ }
+ div.code pre, div.code textarea {
+ float: left;
+ width: 450px;
+ background: #fafaff;
+ border-left: 1px dotted #559;
+ padding: 0 0 0 12px;
+ margin: 0;
+ }
+ div.code pre:first-child {
+ border-left: 0;
+ }
+
+#fadeout {
+ z-index: 50;
+ position: fixed;
+ left: 0; top: 0; right: 0;
+ height: 100px;
+ background: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 255)), to(rgba(255, 255, 255, 0)));
+ background: -moz-linear-gradient(top, rgba(255, 255, 255, 255), rgba(255, 255, 255, 0));
+}
+
+#flybar {
+ position: fixed;
+ z-index: 100;
+ height: 50px;
+ min-width: 490px;
+ left: 40px; right: 40px; top: 25px;
+ padding-left: 235px;
+ background: #eee;
+ background: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#d0d0d0));
+ background: -moz-linear-gradient(top, #f5f5f5, #d0d0d0);
+ border: 1px solid #aaa;
+ -webkit-border-radius: 20px; -moz-border-radius: 20px; border-radius: 20px;
+ -webkit-box-shadow: 0 0 7px #aaa; -moz-box-shadow: 0 0 7px #aaa;
+}
+ #logo {
+ display: block;
+ width: 215px; height: 50px;
+ background: url('../images/logo.png');
+ position: absolute;
+ top: 0px; left: 10px;
+ }
+ #error {
+ position: absolute;
+ -webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px;
+ right: 15px; top: 15px; left: 730px;
+ height: 15px;
+ padding: 2px 5px;
+ background: #fdcdcc;
+ color: #864544;
+ border: 1px solid #864544;
+ font-size: 10px;
+ line-height: 15px;
+ overflow: hidden;
+ text-transform: uppercase;
+ }
+ .navigation {
+ height: 50px;
+ 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-left-width: 0;
+ cursor: pointer;
+ }
+ body.full_screen .navigation {
+ position: static;
+ }
+ .navigation.toc {
+ border-left-width: 1px;
+ }
+ .navigation:hover,
+ .navigation.active {
+ background: #eee;
+ background: -webkit-gradient(linear, left top, left bottom, from(#f0f0f0), to(#c0c0c0));
+ background: -moz-linear-gradient(top, #f0f0f0, #c0c0c0);
+ }
+ .navigation .button {
+ font-weight: bold;
+ }
+ .navigation .contents {
+ display: none;
+ position: absolute;
+ background: #fff;
+ 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 5px 10px #999; -moz-box-shadow: 0 5px 10px #999;
+ }
+ .navigation.active .contents {
+ display: block;
+ }
+ .navigation .contents.repl_wrapper {
+ left: -162px;
+ width: 700px;
+ padding: 0;
+ }
+ body.full_screen .navigation .contents.repl_wrapper {
+ position: fixed;
+ width: auto; height: auto;
+ left: 60px; top: 77px; right: 60px; bottom: 30px;
+ }
+ .navigation .contents.repl_wrapper .code {
+ -webkit-box-shadow: none; -moz-box-shadow: none;
+ background: transparent;
+ border: 0;
+ position: static;
+ }
+ body.full_screen .navigation .contents.repl_wrapper .code {
+ height: 100%;
+ padding: 0; margin: 0;
+ }
+ .navigation .code button {
+ bottom: 10px;
+ text-transform: none;
+ line-height: 14px;
+ left: auto; right: auto;
+ }
+ .navigation .code .run {
+ width: 40px;
+ right: 10px;
+ }
+ .navigation .code .full_screen, .navigation .code .minimize {
+ left: 10px;
+ display: none;
+ width: 90px;
+ }
+ body.minimized .code .full_screen, body.full_screen .code .minimize {
+ display: inline;
+ }
+ .navigation .contents a {
+ display: block;
+ width: 290px;
+ text-transform: none;
+ text-decoration: none;
+ font-weight: normal;
+ height: 12px;
+ line-height: 12px;
+ padding: 4px 10px;
+ }
+ .navigation .contents a:hover {
+ background: #f0f0f0;
+ }
+
+.bookmark {
+ display: block;
+ width: 0; height: 0;
+ position: relative;
+ top: -90px;
+}
+
+#repl_source, #repl_results {
+ background: transparent;
+ outline: none;
+ margin: 5px 0 20px;
+}
+ #repl_source_wrap {
+ margin-left: 5px;
+ height: 250px;
+ width: 307px;
+ position: relative;
+ float: left;
+ }
+ #repl_source {
+ width: 96%;
+ height: 250px;
+ border: 0;
+ resize: none;
+ }
+ #repl_results {
+ font-family: Monaco, Consolas, "Lucida Console", monospace;
+ text-transform: none;
+ font-weight: normal;
+ height: 260px;
+ margin-bottom: 25px;
+ overflow-y: auto;
+ width: 370px;
+ }
+ body.full_screen #repl_results, body.full_screen #repl_source_wrap {
+ width: auto; height: auto;
+ position: absolute;
+ 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%;
+ }
+ body.full_screen #repl_results {
+ left: 50%;
+ }
--- /dev/null
+pre.idle .InheritedClass {
+}
+pre.idle .TypeName {
+ color: #21439C;
+}
+pre.idle .Number {
+}
+pre.idle .LibraryVariable {
+ color: #A535AE;
+}
+pre.idle .Storage {
+ color: #FF5600;
+}
+pre.idle .line-numbers {
+ background-color: #BAD6FD;
+ color: #000000;
+}
+pre.idle {
+ background-color: #FFFFFF;
+ color: #000000;
+}
+pre.idle .StringInterpolation {
+ color: #990000;
+}
+pre.idle .TagName {
+}
+pre.idle .LibraryConstant {
+ color: #A535AE;
+}
+pre.idle .FunctionArgument {
+ color: #0076ad;
+}
+pre.idle .BuiltInConstant {
+ color: #A535AE;
+}
+pre.idle .Invalid {
+ background-color: #990000;
+ color: #FFFFFF;
+}
+pre.idle .LibraryClassType {
+ color: #A535AE;
+}
+pre.idle .LibraryFunction {
+ color: #A535AE;
+}
+pre.idle .TagAttribute {
+}
+pre.idle .Keyword {
+ color: #FF5600;
+}
+pre.idle .UserDefinedConstant {
+}
+pre.idle .String {
+ color: #00A33F;
+}
+pre.idle .FunctionName {
+ color: #21439C;
+}
+pre.idle .Variable {
+ color: #A535AE;
+}
+pre.idle .Comment {
+ color: #919191;
+}
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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">'./coffee-script'</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-2">#</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">-></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="octowrap"> <a class="octothorpe" href="#section-3">#</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="nx">options</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">(</span><span class="nb">Function</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="octowrap"> <a class="octothorpe" href="#section-4">#</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="octowrap"> <a class="octothorpe" href="#section-5">#</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">-></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">'Microsoft.XMLHTTP'</span><span class="p">)</span>
+ <span class="nx">xhr</span><span class="p">.</span><span class="nx">open</span> <span class="s1">'GET'</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">'text/plain'</span> <span class="k">if</span> <span class="s1">'overrideMimeType'</span> <span class="k">of</span> <span class="nx">xhr</span>
+ <span class="nv">xhr.onreadystatechange = </span><span class="o">-></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="octowrap"> <a class="octothorpe" href="#section-6">#</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">processScripts = </span><span class="o">-></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">'script'</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">'text/coffeescript'</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">setTimeout</span> <span class="o">-></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>
+<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">'DOMContentLoaded'</span><span class="p">,</span> <span class="nx">processScripts</span><span class="p">,</span> <span class="kc">false</span>
+<span class="k">else</span>
+ <span class="nx">attachEvent</span> <span class="s1">'onload'</span><span class="p">,</span> <span class="nx">processScripts</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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="octowrap"> <a class="octothorpe" href="#section-2">#</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">'fs'</span>
+<span class="nv">path = </span><span class="nx">require</span> <span class="s1">'path'</span>
+<span class="nv">helpers = </span><span class="nx">require</span><span class="p">(</span><span class="s1">'./helpers'</span><span class="p">).</span><span class="nx">helpers</span>
+<span class="nv">optparse = </span><span class="nx">require</span> <span class="s1">'./optparse'</span>
+<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s1">'./coffee-script'</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</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="octowrap"> <a class="octothorpe" href="#section-4">#</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="octowrap"> <a class="octothorpe" href="#section-5">#</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">-></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="octowrap"> <a class="octothorpe" href="#section-6">#</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">-></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="octowrap"> <a class="octothorpe" href="#section-7">#</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">-></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="octowrap"> <a class="octothorpe" href="#section-8">#</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">-></span>
+ <span class="nx">path</span><span class="p">.</span><span class="nx">exists</span> <span class="s1">'Cakefile'</span><span class="p">,</span> <span class="p">(</span><span class="nx">exists</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">"Cakefile not found in #{process.cwd()}"</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="mi">2</span><span class="p">...</span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">length</span><span class="p">]</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">'Cakefile'</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">'Cakefile'</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="octowrap"> <a class="octothorpe" href="#section-9">#</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">-></span>
+ <span class="nx">puts</span> <span class="s1">''</span>
+ <span class="k">for</span> <span class="nx">all</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">></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">' '</span><span class="p">)</span> <span class="k">else</span> <span class="s1">''</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">"# #{task.description}"</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nx">puts</span> <span class="s2">"cake #{name}#{spaces} #{desc}"</span>
+ <span class="nx">puts</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="octowrap"> <a class="octothorpe" href="#section-10">#</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">-></span>
+ <span class="nx">puts</span> <span class="s2">"No such task: \"#{task}\""</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>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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 tokenzing, 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">path = </span><span class="nx">require</span> <span class="s1">'path'</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">'./lexer'</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">'./parser'</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-2">#</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="nv">fs = </span><span class="nx">require</span> <span class="s1">'fs'</span>
+ <span class="nx">require</span><span class="p">.</span><span class="nx">extensions</span><span class="p">[</span><span class="s1">'.coffee'</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">-></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">'utf8'</span>
+ <span class="nv">module.filename = </span><span class="s2">"#{filename} (compiled)"</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">module</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">'.coffee'</span><span class="p">,</span> <span class="p">(</span><span class="nx">content</span><span class="p">)</span> <span class="o">-></span> <span class="nx">compile</span> <span class="nx">content</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</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">'0.9.4'</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</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="nx">options</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">options</span> <span class="o">or=</span> <span class="p">{}</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">"In #{options.fileName}, #{err.message}"</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-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</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="o">-></span>
+ <span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</a> </div> <p>Tokenize and parse a string of CoffeeScript code, 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">code</span><span class="p">)</span> <span class="o">-></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></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-7">#</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">-></span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-8">#</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-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</a> </div> <p>Set the filename</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">root.filename = __filename = </span><span class="s2">"#{options.fileName} (compiled)"</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</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-11"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-11">#</a> </div> <p>Compile</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">root</span><span class="p">.</span><span class="nx">_compile</span> <span class="nx">exports</span><span class="p">.</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></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-12">#</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">-></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">exports</span><span class="p">.</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></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-13">#</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-14"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-14">#</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">-></span>
+ <span class="nv">token = </span><span class="nx">@tokens</span><span class="p">[</span><span class="nx">@pos</span><span class="p">]</span> <span class="o">or</span> <span class="p">[</span><span class="s2">""</span><span class="p">]</span>
+ <span class="nx">@pos</span> <span class="o">+=</span> <span class="mi">1</span>
+ <span class="k">this</span><span class="p">.</span><span class="nv">yylineno = </span><span class="nx">token</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
+ <span class="k">this</span><span class="p">.</span><span class="nv">yytext = </span><span class="nx">token</span><span class="p">[</span><span class="mi">1</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">setInput</span><span class="o">:</span> <span class="p">(</span><span class="nx">tokens</span><span class="p">)</span> <span class="o">-></span>
+ <span class="vi">@tokens = </span><span class="nx">tokens</span>
+ <span class="vi">@pos = </span><span class="mi">0</span>
+ <span class="nx">upcomingInput</span><span class="o">:</span> <span class="o">-></span> <span class="s2">""</span>
+
+<span class="nv">parser.yy = </span><span class="nx">require</span> <span class="s1">'./nodes'</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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="octowrap"> <a class="octothorpe" href="#section-2">#</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">'fs'</span>
+<span class="nv">path = </span><span class="nx">require</span> <span class="s1">'path'</span>
+<span class="nv">optparse = </span><span class="nx">require</span> <span class="s1">'./optparse'</span>
+<span class="nv">CoffeeScript = </span><span class="nx">require</span> <span class="s1">'./coffee-script'</span>
+<span class="p">{</span><span class="nx">helpers</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">'./helpers'</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">'child_process'</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">'events'</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <p>Allow CoffeeScript to emit Node.js events, and add it to global scope.</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">global.CoffeeScript = </span><span class="nx">CoffeeScript</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</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">'''</span>
+<span class="s1"> coffee compiles CoffeeScript source files into JavaScript.</span>
+
+<span class="s1"> Usage:</span>
+<span class="s1"> coffee path/to/script.coffee</span>
+<span class="s1"> '''</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</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">'-c'</span><span class="p">,</span> <span class="s1">'--compile'</span><span class="p">,</span> <span class="s1">'compile to JavaScript and save as .js files'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-i'</span><span class="p">,</span> <span class="s1">'--interactive'</span><span class="p">,</span> <span class="s1">'run an interactive CoffeeScript REPL'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-o'</span><span class="p">,</span> <span class="s1">'--output [DIR]'</span><span class="p">,</span> <span class="s1">'set the directory for compiled JavaScript'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-w'</span><span class="p">,</span> <span class="s1">'--watch'</span><span class="p">,</span> <span class="s1">'watch scripts for changes, and recompile'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-p'</span><span class="p">,</span> <span class="s1">'--print'</span><span class="p">,</span> <span class="s1">'print the compiled JavaScript to stdout'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-l'</span><span class="p">,</span> <span class="s1">'--lint'</span><span class="p">,</span> <span class="s1">'pipe the compiled JavaScript through JSLint'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-s'</span><span class="p">,</span> <span class="s1">'--stdio'</span><span class="p">,</span> <span class="s1">'listen for and compile scripts over stdio'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-e'</span><span class="p">,</span> <span class="s1">'--eval'</span><span class="p">,</span> <span class="s1">'compile a string from the command line'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-r'</span><span class="p">,</span> <span class="s1">'--require [FILE*]'</span><span class="p">,</span> <span class="s1">'require a library before executing your script'</span><span class="p">]</span>
+ <span class="p">[</span> <span class="s1">'--no-wrap'</span><span class="p">,</span> <span class="s1">'compile without the top-level function wrapper'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-t'</span><span class="p">,</span> <span class="s1">'--tokens'</span><span class="p">,</span> <span class="s1">'print the tokens that the lexer produces'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-n'</span><span class="p">,</span> <span class="s1">'--nodes'</span><span class="p">,</span> <span class="s1">'print the parse tree that Jison produces'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-v'</span><span class="p">,</span> <span class="s1">'--version'</span><span class="p">,</span> <span class="s1">'display CoffeeScript version'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s1">'-h'</span><span class="p">,</span> <span class="s1">'--help'</span><span class="p">,</span> <span class="s1">'display this help message'</span><span class="p">]</span>
+<span class="p">]</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</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-7"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-7">#</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">-></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">'./repl'</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="s1">'console'</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">'./repl'</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">'--'</span>
+ <span class="nv">flags = </span><span class="p">[]</span>
+ <span class="k">if</span> <span class="nx">separator</span> <span class="o">>=</span> <span class="mi">0</span>
+ <span class="nv">flags = </span><span class="nx">sources</span><span class="p">[(</span><span class="nx">separator</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)...</span><span class="nx">sources</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span>
+ <span class="nv">sources = </span><span class="nx">sources</span><span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">separator</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="mi">1</span><span class="p">..</span><span class="nx">sources</span><span class="p">.</span><span class="nx">length</span><span class="p">].</span><span class="nx">concat</span> <span class="nx">flags</span>
+ <span class="nv">sources = </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="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-8"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-8">#</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">-></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">source</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">-></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">-></span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">"File not found: #{source}"</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">-></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">-></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">'.coffee'</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">-></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-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</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">-></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">'.'</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">'compile'</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">puts</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="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">'success'</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">print</span> <span class="nx">t</span><span class="p">.</span><span class="nx">output</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">output</span>
+ <span class="k">catch</span> <span class="nx">err</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</a> </div> <p>Avoid using 'error' as it is a special event -- if there is no handler,
+node will print a stack trace and exit the program.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">emit</span> <span class="s1">'failure'</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">'failure'</span><span class="p">).</span><span class="nx">length</span>
+ <span class="k">return</span> <span class="nx">puts</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">error</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="octowrap"> <a class="octothorpe" href="#section-11">#</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">-></span>
+ <span class="nv">code = </span><span class="s1">''</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">'data'</span><span class="p">,</span> <span class="p">(</span><span class="nx">buffer</span><span class="p">)</span> <span class="o">-></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">'end'</span><span class="p">,</span> <span class="o">-></span>
+ <span class="nx">compileScript</span> <span class="s1">'stdio'</span><span class="p">,</span> <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-12">#</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">-></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">-></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">-></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="octowrap"> <a class="octothorpe" href="#section-13">#</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">-></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">'.js'</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">-></span>
+ <span class="nv">js = </span><span class="s1">' '</span> <span class="k">if</span> <span class="nx">js</span><span class="p">.</span><span class="nx">length</span> <span class="o"><=</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">-></span>
+ <span class="nx">puts</span> <span class="s2">"Compiled #{source}"</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="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">-></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">"mkdir -p #{dir}"</span><span class="p">,</span> <span class="nx">compile</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-14">#</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">js</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">printIt = </span><span class="p">(</span><span class="nx">buffer</span><span class="p">)</span> <span class="o">-></span> <span class="nx">puts</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">'/../extras/jsl.conf'</span>
+ <span class="nv">jsl = </span><span class="nx">spawn</span> <span class="s1">'jsl'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'-nologo'</span><span class="p">,</span> <span class="s1">'-stdin'</span><span class="p">,</span> <span class="s1">'-conf'</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">'data'</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">'data'</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="octowrap"> <a class="octothorpe" href="#section-15">#</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">-></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">'\\n'</span><span class="p">)]</span>
+ <span class="s2">"[#{tag} #{value}]"</span>
+ <span class="nx">puts</span> <span class="nx">strings</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">' '</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-16">#</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">-></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">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="p">(</span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">...</span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">length</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="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></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-17">#</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">-></span>
+ <span class="nv">o = </span><span class="p">{</span><span class="nx">fileName</span><span class="p">}</span>
+ <span class="nv">o.noWrap = </span><span class="nx">opts</span><span class="p">[</span><span class="s1">'no-wrap'</span><span class="p">]</span>
+ <span class="nx">o</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-18">#</a> </div> <p>Print the <code>--help</code> usage message and exit.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">usage = </span><span class="o">-></span>
+ <span class="nx">puts</span> <span class="nx">optionParser</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="octowrap"> <a class="octothorpe" href="#section-19">#</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">-></span>
+ <span class="nx">puts</span> <span class="s2">"CoffeeScript version #{CoffeeScript.VERSION}"</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>
\ No newline at end of file
--- /dev/null
+/*--------------------- Layout and Typography ----------------------------*/
+body {
+ font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ font-size: 16px;
+ line-height: 24px;
+ 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: 40px 0 15px 0;
+}
+ h3, h4, h5, h6 {
+ margin-top: 20px;
+ }
+#container {
+ position: relative;
+}
+#background {
+ position: fixed;
+ top: 0; left: 575px; 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: 500px;
+ min-width: 500px;
+ min-height: 5px;
+ padding: 10px 25px 1px 50px;
+ 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;
+ }
+ .octowrap {
+ position: relative;
+ }
+ .octothorpe {
+ 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 .octothorpe {
+ opacity: 1;
+ }
+ td.code, th.code {
+ padding: 14px 15px 16px 50px;
+ 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 */
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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="octowrap"> <a class="octothorpe" href="#section-2">#</a> </div> <p>The only dependency is on the <strong>Jison.Parser</strong>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">Parser = </span><span class="nx">require</span><span class="p">(</span><span class="s1">'jison'</span><span class="p">).</span><span class="nx">Parser</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</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="octowrap"> <a class="octothorpe" href="#section-4">#</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="octowrap"> <a class="octothorpe" href="#section-5">#</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">-></span>
+ <span class="k">return</span> <span class="p">[</span><span class="nx">patternString</span><span class="p">,</span> <span class="s1">'$$ = $1;'</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="p">(</span><span class="nx">action</span> <span class="o">+</span> <span class="s1">''</span><span class="p">).</span><span class="nx">match</span><span class="p">(</span><span class="nx">unwrap</span><span class="p">)</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">"(#{action}())"</span>
+ <span class="nv">action = </span><span class="nx">action</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\b(?:[A-Z][a-z]+Node|Expressions)\b/g</span><span class="p">,</span> <span class="s1">'yy.$&'</span>
+ <span class="p">[</span><span class="nx">patternString</span><span class="p">,</span> <span class="s2">"$$ = #{action};"</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="octowrap"> <a class="octothorpe" href="#section-6">#</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="octowrap"> <a class="octothorpe" href="#section-7">#</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="octowrap"> <a class="octothorpe" href="#section-8">#</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="s2">""</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">Expressions</span>
+ <span class="nx">o</span> <span class="s2">"TERMINATOR"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">Expressions</span>
+ <span class="nx">o</span> <span class="s2">"Body"</span>
+ <span class="nx">o</span> <span class="s2">"Block TERMINATOR"</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</a> </div> <p>Any list of statements and expressions, seperated 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="s2">"Line"</span><span class="p">,</span> <span class="o">-></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="s2">"Body TERMINATOR Line"</span><span class="p">,</span> <span class="o">-></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="s2">"Body TERMINATOR"</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</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="s2">"Expression"</span>
+ <span class="nx">o</span> <span class="s2">"Statement"</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-11">#</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="s2">"Return"</span>
+ <span class="nx">o</span> <span class="s2">"Throw"</span>
+ <span class="nx">o</span> <span class="s2">"BREAK"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"CONTINUE"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"DEBUGGER"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-12">#</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="s2">"Value"</span>
+ <span class="nx">o</span> <span class="s2">"Call"</span>
+ <span class="nx">o</span> <span class="s2">"Code"</span>
+ <span class="nx">o</span> <span class="s2">"Operation"</span>
+ <span class="nx">o</span> <span class="s2">"Assign"</span>
+ <span class="nx">o</span> <span class="s2">"If"</span>
+ <span class="nx">o</span> <span class="s2">"Try"</span>
+ <span class="nx">o</span> <span class="s2">"While"</span>
+ <span class="nx">o</span> <span class="s2">"For"</span>
+ <span class="nx">o</span> <span class="s2">"Switch"</span>
+ <span class="nx">o</span> <span class="s2">"Extends"</span>
+ <span class="nx">o</span> <span class="s2">"Class"</span>
+ <span class="nx">o</span> <span class="s2">"Existence"</span>
+ <span class="nx">o</span> <span class="s2">"Comment"</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-13">#</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="s2">"INDENT Body OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"INDENT OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">Expressions</span>
+ <span class="nx">o</span> <span class="s2">"TERMINATOR Comment"</span><span class="p">,</span> <span class="o">-></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-14"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-14">#</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="s2">"IDENTIFIER"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-15">#</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="s2">"NUMBER"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"STRING"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-16">#</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="s2">"AlphaNumeric"</span>
+ <span class="nx">o</span> <span class="s2">"JS"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"REGEX"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"TRUE"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="kc">true</span>
+ <span class="nx">o</span> <span class="s2">"FALSE"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="kc">false</span>
+ <span class="nx">o</span> <span class="s2">"YES"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="kc">true</span>
+ <span class="nx">o</span> <span class="s2">"NO"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="kc">false</span>
+ <span class="nx">o</span> <span class="s2">"ON"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="kc">true</span>
+ <span class="nx">o</span> <span class="s2">"OFF"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="kc">false</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-17">#</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="s2">"Assignable = Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AssignNode</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
+ <span class="nx">o</span> <span class="s2">"Assignable = INDENT Expression OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AssignNode</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="octowrap"> <a class="octothorpe" href="#section-18">#</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="s2">"Identifier"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"AlphaNumeric"</span>
+ <span class="nx">o</span> <span class="s2">"Identifier : Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AssignNode</span> <span class="k">new</span> <span class="nx">ValueNode</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">'object'</span>
+ <span class="nx">o</span> <span class="s2">"AlphaNumeric : Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AssignNode</span> <span class="k">new</span> <span class="nx">ValueNode</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">'object'</span>
+ <span class="nx">o</span> <span class="s2">"Identifier : INDENT Expression OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AssignNode</span> <span class="k">new</span> <span class="nx">ValueNode</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">'object'</span>
+ <span class="nx">o</span> <span class="s2">"AlphaNumeric : INDENT Expression OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AssignNode</span> <span class="k">new</span> <span class="nx">ValueNode</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">'object'</span>
+ <span class="nx">o</span> <span class="s2">"Comment"</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-19">#</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="s2">"RETURN Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ReturnNode</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"RETURN"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ReturnNode</span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="s1">'null'</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-20">#</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="s2">"HERECOMMENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">CommentNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-21">#</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">Existence</span><span class="o">:</span> <span class="p">[</span>
+ <span class="nx">o</span> <span class="s2">"Expression ?"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ExistenceNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-22">#</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="s2">"PARAM_START ParamList PARAM_END FuncGlyph Block"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">CodeNode</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="s2">"FuncGlyph Block"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">CodeNode</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-23"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-23">#</a> </div> <p>CoffeeScript has two different symbols for functions. <code>-></code> is for ordinary
+functions, and <code>=></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="s2">"->"</span><span class="p">,</span> <span class="o">-></span> <span class="s1">'func'</span>
+ <span class="nx">o</span> <span class="s2">"=>"</span><span class="p">,</span> <span class="o">-></span> <span class="s1">'boundfunc'</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-24">#</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">''</span>
+ <span class="nx">o</span> <span class="s1">','</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-25">#</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="s2">""</span><span class="p">,</span> <span class="o">-></span> <span class="p">[]</span>
+ <span class="nx">o</span> <span class="s2">"Param"</span><span class="p">,</span> <span class="o">-></span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"ParamList , Param"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</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-26"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-26">#</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="s2">"PARAM"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"@ PARAM"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ParamNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="kc">true</span>
+ <span class="nx">o</span> <span class="s2">"PARAM . . ."</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ParamNode</span> <span class="nx">$1</span><span class="p">,</span> <span class="kc">false</span><span class="p">,</span> <span class="kc">true</span>
+ <span class="nx">o</span> <span class="s2">"@ PARAM . . ."</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ParamNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="kc">true</span><span class="p">,</span> <span class="kc">true</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-27">#</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="s2">"Expression . . ."</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">SplatNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-28">#</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="s2">"Identifier"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"Value Accessor"</span><span class="p">,</span> <span class="o">-></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="s2">"Invocation Accessor"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</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="s2">"ThisProperty"</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-29">#</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="s2">"SimpleAssignable"</span>
+ <span class="nx">o</span> <span class="s2">"Array"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"Object"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-30">#</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="s2">"Assignable"</span>
+ <span class="nx">o</span> <span class="s2">"Literal"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"Parenthetical"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"Range"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"This"</span>
+ <span class="nx">o</span> <span class="s2">"NULL"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="s1">'null'</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-31">#</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="s2">"PROPERTY_ACCESS Identifier"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AccessorNode</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"PROTOTYPE_ACCESS Identifier"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AccessorNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="s1">'prototype'</span>
+ <span class="nx">o</span> <span class="s2">"::"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AccessorNode</span><span class="p">(</span><span class="k">new</span> <span class="nx">LiteralNode</span><span class="p">(</span><span class="s1">'prototype'</span><span class="p">))</span>
+ <span class="nx">o</span> <span class="s2">"SOAK_ACCESS Identifier"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AccessorNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="s1">'soak'</span>
+ <span class="nx">o</span> <span class="s2">"Index"</span>
+ <span class="nx">o</span> <span class="s2">"Slice"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">SliceNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-32">#</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="s2">"INDEX_START Expression INDEX_END"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">IndexNode</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"INDEX_SOAK Index"</span><span class="p">,</span> <span class="o">-></span> <span class="nv">$2.soakNode = </span><span class="kc">yes</span><span class="p">;</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"INDEX_PROTO Index"</span><span class="p">,</span> <span class="o">-></span> <span class="nv">$2.proto = </span><span class="kc">yes</span><span class="p">;</span> <span class="nx">$2</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-33">#</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="s2">"{ AssignList OptComma }"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ObjectNode</span> <span class="nx">$2</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-34">#</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="s2">""</span><span class="p">,</span> <span class="o">-></span> <span class="p">[]</span>
+ <span class="nx">o</span> <span class="s2">"AssignObj"</span><span class="p">,</span> <span class="o">-></span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"AssignList , AssignObj"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="p">[</span><span class="nx">$3</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"AssignList OptComma TERMINATOR AssignObj"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="p">[</span><span class="nx">$4</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"AssignList OptComma INDENT AssignList OptComma OUTDENT"</span><span class="p">,</span> <span class="o">-></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-35"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-35">#</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="s2">"CLASS SimpleAssignable"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ClassNode</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"CLASS SimpleAssignable EXTENDS Value"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ClassNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$4</span>
+ <span class="nx">o</span> <span class="s2">"CLASS SimpleAssignable INDENT ClassBody OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ClassNode</span> <span class="nx">$2</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="s2">"CLASS SimpleAssignable EXTENDS Value INDENT ClassBody OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ClassNode</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="s2">"CLASS INDENT ClassBody OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ClassNode</span> <span class="s1">'__temp__'</span><span class="p">,</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-36">#</a> </div> <p>Assignments that can happen directly inside a class declaration.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ClassAssign</span><span class="o">:</span> <span class="p">[</span>
+ <span class="nx">o</span> <span class="s2">"AssignObj"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"ThisProperty : Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AssignNode</span> <span class="k">new</span> <span class="nx">ValueNode</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">'this'</span>
+ <span class="nx">o</span> <span class="s2">"ThisProperty : INDENT Expression OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">AssignNode</span> <span class="k">new</span> <span class="nx">ValueNode</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">'this'</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-37">#</a> </div> <p>A list of assignments to a class.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ClassBody</span><span class="o">:</span> <span class="p">[</span>
+ <span class="nx">o</span> <span class="s2">""</span><span class="p">,</span> <span class="o">-></span> <span class="p">[]</span>
+ <span class="nx">o</span> <span class="s2">"ClassAssign"</span><span class="p">,</span> <span class="o">-></span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"ClassBody TERMINATOR ClassAssign"</span><span class="p">,</span> <span class="o">-></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="s2">"{ ClassBody }"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$2</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-38">#</a> </div> <p>The two flavors of function call: normal, and object instantiation with <code>new</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Call</span><span class="o">:</span> <span class="p">[</span>
+ <span class="nx">o</span> <span class="s2">"Invocation"</span>
+ <span class="nx">o</span> <span class="s2">"NEW Invocation"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$2</span><span class="p">.</span><span class="nx">newInstance</span><span class="p">()</span>
+ <span class="nx">o</span> <span class="s2">"NEW Value"</span><span class="p">,</span> <span class="o">-></span> <span class="p">(</span><span class="k">new</span> <span class="nx">CallNode</span><span class="p">(</span><span class="nx">$2</span><span class="p">,</span> <span class="p">[])).</span><span class="nx">newInstance</span><span class="p">()</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-39">#</a> </div> <p>Extending an object by setting its prototype chain to reference a parent
+object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">Extends</span><span class="o">:</span> <span class="p">[</span>
+ <span class="nx">o</span> <span class="s2">"SimpleAssignable EXTENDS Value"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ExtendsNode</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-40"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-40">#</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="s2">"Value OptFuncExist Arguments"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">CallNode</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="s2">"Invocation OptFuncExist Arguments"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">CallNode</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="s2">"SUPER"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">CallNode</span> <span class="s1">'super'</span><span class="p">,</span> <span class="p">[</span><span class="k">new</span> <span class="nx">SplatNode</span><span class="p">(</span><span class="k">new</span> <span class="nx">LiteralNode</span><span class="p">(</span><span class="s1">'arguments'</span><span class="p">))]</span>
+ <span class="nx">o</span> <span class="s2">"SUPER Arguments"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">CallNode</span> <span class="s1">'super'</span><span class="p">,</span> <span class="nx">$2</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-41">#</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="s2">""</span><span class="p">,</span> <span class="o">-></span> <span class="kc">no</span>
+ <span class="nx">o</span> <span class="s2">"FUNC_EXIST"</span><span class="p">,</span> <span class="o">-></span> <span class="kc">yes</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-42">#</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="s2">"CALL_START CALL_END"</span><span class="p">,</span> <span class="o">-></span> <span class="p">[]</span>
+ <span class="nx">o</span> <span class="s2">"CALL_START ArgList OptComma CALL_END"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$2</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-43">#</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="s2">"THIS"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="s1">'this'</span>
+ <span class="nx">o</span> <span class="s2">"@"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="s1">'this'</span>
+ <span class="p">]</span>
+
+ <span class="nx">RangeDots</span><span class="o">:</span> <span class="p">[</span>
+ <span class="nx">o</span> <span class="s2">". ."</span><span class="p">,</span> <span class="o">-></span> <span class="s1">'inclusive'</span>
+ <span class="nx">o</span> <span class="s2">". . ."</span><span class="p">,</span> <span class="o">-></span> <span class="s1">'exclusive'</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-44">#</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="s2">"@ Identifier"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="k">new</span> <span class="nx">LiteralNode</span><span class="p">(</span><span class="s1">'this'</span><span class="p">),</span> <span class="p">[</span><span class="k">new</span> <span class="nx">AccessorNode</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-45"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-45">#</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="s2">"[ Expression RangeDots Expression ]"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">RangeNode</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-46"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-46">#</a> </div> <p>The slice literal.</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="s2">"INDEX_START Expression RangeDots Expression INDEX_END"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">RangeNode</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="s2">"INDEX_START Expression RangeDots INDEX_END"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">RangeNode</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="s2">"INDEX_START RangeDots Expression INDEX_END"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">RangeNode</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-47"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-47">#</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="s2">"[ ]"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ArrayNode</span> <span class="p">[]</span>
+ <span class="nx">o</span> <span class="s2">"[ ArgList OptComma ]"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ArrayNode</span> <span class="nx">$2</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-48">#</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="s2">"Arg"</span><span class="p">,</span> <span class="o">-></span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"ArgList , Arg"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="p">[</span><span class="nx">$3</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"ArgList OptComma TERMINATOR Arg"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span> <span class="p">[</span><span class="nx">$4</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"INDENT ArgList OptComma OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"ArgList OptComma INDENT ArgList OptComma OUTDENT"</span><span class="p">,</span> <span class="o">-></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-49"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-49">#</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="s2">"Expression"</span>
+ <span class="nx">o</span> <span class="s2">"Splat"</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-50">#</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="s2">"Expression"</span>
+ <span class="nx">o</span> <span class="s2">"SimpleArgs , Expression"</span><span class="p">,</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">$1</span> <span class="k">instanceof</span> <span class="nb">Array</span> <span class="k">then</span> <span class="nx">$1</span><span class="p">.</span><span class="nx">concat</span><span class="p">([</span><span class="nx">$3</span><span class="p">])</span> <span class="k">else</span> <span class="p">[</span><span class="nx">$1</span><span class="p">].</span><span class="nx">concat</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-51"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-51">#</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="s2">"TRY Block Catch"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">TryNode</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="s2">"TRY Block FINALLY Block"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">TryNode</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="s2">"TRY Block Catch FINALLY Block"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">TryNode</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-52"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-52">#</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="s2">"CATCH Identifier Block"</span><span class="p">,</span> <span class="o">-></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-53"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-53">#</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="s2">"THROW Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ThrowNode</span> <span class="nx">$2</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-54"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-54">#</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="s2">"( Line )"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ParentheticalNode</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"( )"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ParentheticalNode</span> <span class="k">new</span> <span class="nx">LiteralNode</span> <span class="s1">''</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-55"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-55">#</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="s2">"WHILE Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">WhileNode</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"WHILE Expression WHEN Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">WhileNode</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="s2">"UNTIL Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">WhileNode</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="s2">"UNTIL Expression WHEN Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">WhileNode</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-56"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-56">#</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="s2">"WhileSource Block"</span><span class="p">,</span> <span class="o">-></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="s2">"Statement WhileSource"</span><span class="p">,</span> <span class="o">-></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="s2">"Expression WhileSource"</span><span class="p">,</span> <span class="o">-></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="s2">"Loop"</span><span class="p">,</span> <span class="o">-></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="s2">"LOOP Block"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">WhileNode</span><span class="p">(</span><span class="k">new</span> <span class="nx">LiteralNode</span> <span class="s1">'true'</span><span class="p">).</span><span class="nx">addBody</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"LOOP Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">WhileNode</span><span class="p">(</span><span class="k">new</span> <span class="nx">LiteralNode</span> <span class="s1">'true'</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-57"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-57">#</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="s2">"Statement ForBody"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ForNode</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="s2">"Expression ForBody"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ForNode</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="s2">"ForBody Block"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ForNode</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="s2">"FOR Range"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">source</span><span class="o">:</span> <span class="k">new</span> <span class="nx">ValueNode</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="s2">"ForStart ForSource"</span><span class="p">,</span> <span class="o">-></span> <span class="nv">$2.raw = </span><span class="nx">$1</span><span class="p">.</span><span class="nx">raw</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="s2">"FOR ForVariables"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"FOR ALL ForVariables"</span><span class="p">,</span> <span class="o">-></span> <span class="nv">$3.raw = </span><span class="kc">true</span><span class="p">;</span> <span class="nx">$3</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-58"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-58">#</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="s2">"Identifier"</span>
+ <span class="nx">o</span> <span class="s2">"Array"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="nx">o</span> <span class="s2">"Object"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">$1</span>
+ <span class="p">]</span></pre></div> </td> </tr> <tr id="section-59"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-59">#</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="s2">"ForValue"</span><span class="p">,</span> <span class="o">-></span> <span class="p">[</span><span class="nx">$1</span><span class="p">]</span>
+ <span class="nx">o</span> <span class="s2">"ForValue , ForValue"</span><span class="p">,</span> <span class="o">-></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-60"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-60">#</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="s2">"IN Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">source</span><span class="o">:</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"OF Expression"</span><span class="p">,</span> <span class="o">-></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">true</span>
+ <span class="nx">o</span> <span class="s2">"IN Expression WHEN Expression"</span><span class="p">,</span> <span class="o">-></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="s2">"OF Expression WHEN Expression"</span><span class="p">,</span> <span class="o">-></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">true</span>
+ <span class="nx">o</span> <span class="s2">"IN Expression BY Expression"</span><span class="p">,</span> <span class="o">-></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="s2">"IN Expression WHEN Expression BY Expression"</span><span class="p">,</span> <span class="o">-></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="s2">"IN Expression BY Expression WHEN Expression"</span><span class="p">,</span> <span class="o">-></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="s2">"SWITCH Expression INDENT Whens OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">SwitchNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$4</span>
+ <span class="nx">o</span> <span class="s2">"SWITCH Expression INDENT Whens ELSE Block OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">SwitchNode</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="s2">"SWITCH INDENT Whens OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">SwitchNode</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">$3</span>
+ <span class="nx">o</span> <span class="s2">"SWITCH INDENT Whens ELSE Block OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">SwitchNode</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="s2">"When"</span>
+ <span class="nx">o</span> <span class="s2">"Whens When"</span><span class="p">,</span> <span class="o">-></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-61"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-61">#</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="s2">"LEADING_WHEN SimpleArgs Block"</span><span class="p">,</span> <span class="o">-></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="s2">"LEADING_WHEN SimpleArgs Block TERMINATOR"</span><span class="p">,</span> <span class="o">-></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-62"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-62">#</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="s2">"IF Expression Block"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">IfNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$3</span>
+ <span class="nx">o</span> <span class="s2">"UNLESS Expression Block"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">IfNode</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="s2">"IfBlock ELSE IF Expression Block"</span><span class="p">,</span> <span class="o">-></span> <span class="nx">$1</span><span class="p">.</span><span class="nx">addElse</span> <span class="p">(</span><span class="k">new</span> <span class="nx">IfNode</span><span class="p">(</span><span class="nx">$4</span><span class="p">,</span> <span class="nx">$5</span><span class="p">)).</span><span class="nx">forceStatement</span><span class="p">()</span>
+ <span class="nx">o</span> <span class="s2">"IfBlock ELSE Block"</span><span class="p">,</span> <span class="o">-></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-63"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-63">#</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="s2">"IfBlock"</span>
+ <span class="nx">o</span> <span class="s2">"Statement POST_IF Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">IfNode</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="s2">"Expression POST_IF Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">IfNode</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="s2">"Statement POST_UNLESS Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">IfNode</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="s2">"Expression POST_UNLESS Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">IfNode</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-64"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-64">#</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="s2">"UNARY Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$2</span>
+ <span class="nx">o</span><span class="p">(</span><span class="s2">"- Expression"</span><span class="p">,</span> <span class="p">(</span><span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span><span class="p">(</span><span class="s1">'-'</span><span class="p">,</span> <span class="nx">$2</span><span class="p">)),</span> <span class="p">{</span><span class="nx">prec</span><span class="o">:</span> <span class="s1">'UNARY'</span><span class="p">})</span>
+ <span class="nx">o</span><span class="p">(</span><span class="s2">"+ Expression"</span><span class="p">,</span> <span class="p">(</span><span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span><span class="p">(</span><span class="s1">'+'</span><span class="p">,</span> <span class="nx">$2</span><span class="p">)),</span> <span class="p">{</span><span class="nx">prec</span><span class="o">:</span> <span class="s1">'UNARY'</span><span class="p">})</span>
+
+ <span class="nx">o</span> <span class="s2">"-- Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'--'</span><span class="p">,</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"++ Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'++'</span><span class="p">,</span> <span class="nx">$2</span>
+ <span class="nx">o</span> <span class="s2">"Expression --"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'--'</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="s2">"Expression ++"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'++'</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="s2">"Expression ? Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'?'</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="s2">"Expression + Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'+'</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="s2">"Expression - Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'-'</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="s2">"Expression == Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'=='</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="s2">"Expression != Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'!='</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="s2">"Expression MATH Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</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="s2">"Expression SHIFT Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</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="s2">"Expression COMPARE Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</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="s2">"Expression LOGIC Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</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="s2">"Value COMPOUND_ASSIGN Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</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="s2">"Value COMPOUND_ASSIGN INDENT Expression OUTDENT"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$4</span>
+
+ <span class="nx">o</span> <span class="s2">"Expression IN Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">InNode</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$3</span>
+ <span class="nx">o</span> <span class="s2">"Expression OF Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'in'</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="s2">"Expression INSTANCEOF Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'instanceof'</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="s2">"Expression UNARY IN Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="k">new</span> <span class="nx">InNode</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$4</span>
+ <span class="nx">o</span> <span class="s2">"Expression UNARY OF Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="k">new</span> <span class="nx">ParentheticalNode</span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'in'</span><span class="p">,</span> <span class="nx">$1</span><span class="p">,</span> <span class="nx">$4</span>
+ <span class="nx">o</span> <span class="s2">"Expression UNARY INSTANCEOF Expression"</span><span class="p">,</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="nx">$2</span><span class="p">,</span> <span class="k">new</span> <span class="nx">ParentheticalNode</span> <span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'instanceof'</span><span class="p">,</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-65"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-65">#</a> </div> <h2>Precedence</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-66"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-66">#</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="s2">"right"</span><span class="p">,</span> <span class="s1">'?'</span><span class="p">,</span> <span class="s1">'NEW'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'CALL_START'</span><span class="p">,</span> <span class="s1">'CALL_END'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"nonassoc"</span><span class="p">,</span> <span class="s1">'++'</span><span class="p">,</span> <span class="s1">'--'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"right"</span><span class="p">,</span> <span class="s1">'UNARY'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'MATH'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'+'</span><span class="p">,</span> <span class="s1">'-'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'SHIFT'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'COMPARE'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'INSTANCEOF'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'=='</span><span class="p">,</span> <span class="s1">'!='</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'LOGIC'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"right"</span><span class="p">,</span> <span class="s1">'COMPOUND_ASSIGN'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"left"</span><span class="p">,</span> <span class="s1">'.'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"nonassoc"</span><span class="p">,</span> <span class="s1">'INDENT'</span><span class="p">,</span> <span class="s1">'OUTDENT'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"right"</span><span class="p">,</span> <span class="s1">'WHEN'</span><span class="p">,</span> <span class="s1">'LEADING_WHEN'</span><span class="p">,</span> <span class="s1">'IN'</span><span class="p">,</span> <span class="s1">'OF'</span><span class="p">,</span> <span class="s1">'BY'</span><span class="p">,</span> <span class="s1">'THROW'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"right"</span><span class="p">,</span> <span class="s1">'IF'</span><span class="p">,</span> <span class="s1">'UNLESS'</span><span class="p">,</span> <span class="s1">'ELSE'</span><span class="p">,</span> <span class="s1">'FOR'</span><span class="p">,</span> <span class="s1">'WHILE'</span><span class="p">,</span> <span class="s1">'UNTIL'</span><span class="p">,</span> <span class="s1">'LOOP'</span><span class="p">,</span> <span class="s1">'SUPER'</span><span class="p">,</span> <span class="s1">'CLASS'</span><span class="p">,</span> <span class="s1">'EXTENDS'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"right"</span><span class="p">,</span> <span class="s1">'='</span><span class="p">,</span> <span class="s1">':'</span><span class="p">,</span> <span class="s1">'RETURN'</span><span class="p">]</span>
+ <span class="p">[</span><span class="s2">"right"</span><span class="p">,</span> <span class="s1">'->'</span><span class="p">,</span> <span class="s1">'=>'</span><span class="p">,</span> <span class="s1">'UNLESS'</span><span class="p">,</span> <span class="s1">'POST_IF'</span><span class="p">,</span> <span class="s1">'POST_UNLESS'</span><span class="p">]</span>
+<span class="p">]</span></pre></div> </td> </tr> <tr id="section-67"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-67">#</a> </div> <h2>Wrapping Up</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-68"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-68">#</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">' '</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">"return #{alt[1]}"</span> <span class="k">if</span> <span class="nx">name</span> <span class="o">is</span> <span class="s1">'Root'</span>
+ <span class="nx">alt</span></pre></div> </td> </tr> <tr id="section-69"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-69">#</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">' '</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">'Root'</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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><span class="nv">helpers = exports.helpers = </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-2">#</a> </div> <p>Cross-browser indexOf, so that IE can join the party.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">helpers.indexOf = indexOf = </span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">item</span><span class="p">,</span> <span class="nx">from</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">array</span><span class="p">.</span><span class="nx">indexOf</span> <span class="nx">item</span><span class="p">,</span> <span class="nx">from</span> <span class="k">if</span> <span class="nx">array</span><span class="p">.</span><span class="nx">indexOf</span>
+ <span class="k">for</span> <span class="nx">other</span><span class="p">,</span> <span class="nx">index</span> <span class="k">in</span> <span class="nx">array</span>
+ <span class="k">if</span> <span class="nx">other</span> <span class="o">is</span> <span class="nx">item</span> <span class="o">and</span> <span class="p">(</span><span class="o">not</span> <span class="nx">from</span> <span class="o">or</span> <span class="p">(</span><span class="nx">from</span> <span class="o"><=</span> <span class="nx">index</span><span class="p">))</span>
+ <span class="k">return</span> <span class="nx">index</span>
+ <span class="o">-</span><span class="mi">1</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <p>Does a list include a value?</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">helpers.include = include = </span><span class="p">(</span><span class="nx">list</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">indexOf</span><span class="p">(</span><span class="nx">list</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</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">helpers.starts = 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">-></span>
+ <span class="nx">string</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="p">(</span><span class="nx">start</span> <span class="o">or</span> <span class="mi">0</span><span class="p">)</span> <span class="o">+</span> <span class="nx">literal</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="o">is</span> <span class="nx">literal</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</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">helpers.ends = 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">-></span>
+ <span class="nv">start = </span><span class="nx">string</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="nx">literal</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">?</span> <span class="mi">0</span><span class="p">)</span>
+ <span class="nx">string</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="nx">start</span> <span class="o">+</span> <span class="nx">literal</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="o">is</span> <span class="nx">literal</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</a> </div> <p>Trim out all falsy values from an array.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">helpers.compact = compact = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-></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-7"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-7">#</a> </div> <p>Count the number of occurences of a character in a string.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">helpers.count = 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">-></span>
+ <span class="nv">num = </span><span class="mi">0</span>
+ <span class="nv">pos = </span><span class="nx">indexOf</span> <span class="nx">string</span><span class="p">,</span> <span class="nx">letter</span>
+ <span class="k">while</span> <span class="nx">pos</span> <span class="o">isnt</span> <span class="o">-</span><span class="mi">1</span>
+ <span class="nx">num</span> <span class="o">+=</span> <span class="mi">1</span>
+ <span class="nv">pos = </span><span class="nx">indexOf</span> <span class="nx">string</span><span class="p">,</span> <span class="nx">letter</span><span class="p">,</span> <span class="nx">pos</span> <span class="o">+</span> <span class="mi">1</span>
+ <span class="nx">num</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-8">#</a> </div> <p>Merge objects, returning a fresh copy with attributes from both sides.
+Used every time <code>BaseNode#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">helpers.merge = 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">-></span>
+ <span class="nv">fresh = </span><span class="p">{}</span>
+ <span class="p">(</span><span class="nx">fresh</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="p">)</span> <span class="k">for</span> <span class="nx">all</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">options</span>
+ <span class="p">(</span><span class="nx">fresh</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="p">)</span> <span class="k">for</span> <span class="nx">all</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">overrides</span> <span class="k">if</span> <span class="nx">overrides</span>
+ <span class="nx">fresh</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</a> </div> <p>Extend a source object with the properties of another object (shallow copy).
+We use this to simulate Node's deprecated <code>process.mixin</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">helpers.extend = 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">-></span>
+ <span class="p">(</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="p">)</span> <span class="k">for</span> <span class="nx">all</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></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</a> </div> <p>Return a completely 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">helpers.flatten = flatten = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">memo = </span><span class="p">[]</span>
+ <span class="k">for</span> <span class="nx">item</span> <span class="k">in</span> <span class="nx">array</span>
+ <span class="k">if</span> <span class="nx">item</span> <span class="k">instanceof</span> <span class="nb">Array</span> <span class="k">then</span> <span class="nv">memo = </span><span class="nx">memo</span><span class="p">.</span><span class="nx">concat</span><span class="p">(</span><span class="nx">item</span><span class="p">)</span> <span class="k">else</span> <span class="nx">memo</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">item</span><span class="p">)</span>
+ <span class="nx">memo</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-11">#</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">helpers.del = 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">-></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> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</a> </div> <p>Loader for CoffeeScript as a Node.js library.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><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="p">)</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">'./coffee-script'</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html> <html> <head> <title>lexer.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 … <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> lexer.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-1">#</a> </div> <p>The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
+matches against the beginning of the source code. When a match is found,
+a token is produced, we consume the match, and start again. Tokens are in the
+form:</p>
+
+<pre><code>[tag, value, lineNumber]
+</code></pre>
+
+<p>Which is a format that can be fed directly into <a href="http://github.com/zaach/jison">Jison</a>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">Rewriter</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">'./rewriter'</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-2">#</a> </div> <p>Import the helpers we need.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">include</span><span class="p">,</span> <span class="nx">count</span><span class="p">,</span> <span class="nx">starts</span><span class="p">,</span> <span class="nx">compact</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./helpers'</span><span class="p">).</span><span class="nx">helpers</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <h2>The Lexer Class</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</a> </div> <p>The Lexer class reads a stream of CoffeeScript and divvys it up into tagged
+tokens. Some potential ambiguity in the grammar has been avoided by
+pushing some extra smarts into the Lexer.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.Lexer = </span><span class="nx">class</span> <span class="nx">Lexer</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</a> </div> <p><strong>tokenize</strong> is the Lexer's main method. Scan by attempting to match tokens
+one at a time, using a regular expression anchored at the start of the
+remaining code, or a custom recursive token-matching method
+(for interpolations). When the next token has been recorded, we move forward
+within the code past the token, and begin again.</p>
+
+<p>Each tokenizing method is responsible for incrementing <code>@i</code> by the number of
+characters it has consumed. <code>@i</code> can be thought of as our finger on the page
+of source.</p>
+
+<p>Before returning the token stream, run it through the <a href="rewriter.html">Rewriter</a>
+unless explicitly asked not to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">tokenize</span><span class="o">:</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">-></span>
+ <span class="nv">code = </span><span class="nx">code</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/(\r|\s+$)/g</span><span class="p">,</span> <span class="s1">''</span>
+ <span class="nv">o = </span><span class="nx">options</span> <span class="o">or</span> <span class="p">{}</span>
+ <span class="vi">@code = </span><span class="nx">code</span> <span class="c1"># The remainder of the source code.</span>
+ <span class="vi">@i = </span><span class="mi">0</span> <span class="c1"># Current character position we're parsing.</span>
+ <span class="vi">@line = </span><span class="nx">o</span><span class="p">.</span><span class="nx">line</span> <span class="o">or</span> <span class="mi">0</span> <span class="c1"># The current line.</span>
+ <span class="vi">@indent = </span><span class="mi">0</span> <span class="c1"># The current indentation level.</span>
+ <span class="vi">@indebt = </span><span class="mi">0</span> <span class="c1"># The over-indentation at the current level.</span>
+ <span class="vi">@outdebt = </span><span class="mi">0</span> <span class="c1"># The under-outdentation at the current level.</span>
+ <span class="vi">@indents = </span><span class="p">[]</span> <span class="c1"># The stack of all current indentation levels.</span>
+ <span class="vi">@tokens = </span><span class="p">[]</span> <span class="c1"># Stream of parsed tokens in the form ['TYPE', value, line]</span>
+ <span class="k">while</span> <span class="nx">@i</span> <span class="o"><</span> <span class="nx">@code</span><span class="p">.</span><span class="nx">length</span>
+ <span class="vi">@chunk = </span><span class="nx">@code</span><span class="p">[</span><span class="nx">@i</span><span class="p">..]</span>
+ <span class="nx">@extractNextToken</span><span class="p">()</span>
+ <span class="nx">@closeIndentation</span><span class="p">()</span>
+ <span class="k">return</span> <span class="nx">@tokens</span> <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">rewrite</span> <span class="o">is</span> <span class="kc">off</span>
+ <span class="p">(</span><span class="k">new</span> <span class="nx">Rewriter</span><span class="p">).</span><span class="nx">rewrite</span> <span class="nx">@tokens</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</a> </div> <p>At every position, run through this list of attempted matches,
+short-circuiting if any of them succeed. Their order determines precedence:
+<code>@literalToken</code> is the fallback catch-all.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">extractNextToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@identifierToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@commentToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@whitespaceToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@lineToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@heredocToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@stringToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@numberToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@regexToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@jsToken</span><span class="p">()</span>
+ <span class="k">return</span> <span class="nx">@literalToken</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-7">#</a> </div> <h2>Tokenizers</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-8">#</a> </div> <p>Matches identifying literals: variables, keywords, method names, etc.
+Check to ensure that JavaScript reserved words aren't being used as
+identifiers. Because CoffeeScript reserves a handful of keywords that are
+allowed in JavaScript, we're careful not to tag them as keywords when
+referenced as property names here, so you can still do <code>jQuery.is()</code> even
+though <code>is</code> means <code>===</code> otherwise.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">identifierToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">id = </span><span class="nx">@match</span> <span class="nx">IDENTIFIER</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">id</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">forcedIdentifier = </span><span class="nx">@tagAccessor</span><span class="p">()</span> <span class="o">or</span> <span class="nx">@match</span> <span class="nx">ASSIGNED</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="nv">tag = </span><span class="s1">'IDENTIFIER'</span>
+ <span class="nv">tag = </span><span class="nx">id</span><span class="p">.</span><span class="nx">toUpperCase</span><span class="p">()</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">JS_KEYWORDS</span><span class="p">,</span> <span class="nx">id</span><span class="p">)</span> <span class="o">or</span> <span class="p">(</span><span class="o">not</span> <span class="nx">forcedIdentifier</span> <span class="o">and</span> <span class="nx">include</span><span class="p">(</span><span class="nx">COFFEE_KEYWORDS</span><span class="p">,</span> <span class="nx">id</span><span class="p">))</span>
+ <span class="nv">tag = </span><span class="s1">'LEADING_WHEN'</span> <span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">'WHEN'</span> <span class="o">and</span> <span class="nx">include</span> <span class="nx">LINE_BREAK</span><span class="p">,</span> <span class="nx">@tag</span><span class="p">()</span>
+ <span class="nv">tag = </span><span class="s1">'ALL'</span> <span class="k">if</span> <span class="nx">id</span> <span class="o">is</span> <span class="s1">'all'</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">is</span> <span class="s1">'FOR'</span>
+ <span class="nv">tag = </span><span class="s1">'UNARY'</span> <span class="k">if</span> <span class="nx">include</span> <span class="nx">UNARY</span><span class="p">,</span> <span class="nx">tag</span>
+ <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">JS_FORBIDDEN</span><span class="p">,</span> <span class="nx">id</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">forcedIdentifier</span>
+ <span class="nv">tag = </span><span class="s1">'STRING'</span>
+ <span class="nv">id = </span><span class="s2">"\"#{id}\""</span>
+ <span class="k">if</span> <span class="nx">forcedIdentifier</span> <span class="o">is</span> <span class="s1">'accessor'</span>
+ <span class="nv">close_index = </span><span class="kc">true</span>
+ <span class="nx">@tokens</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span> <span class="k">if</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">isnt</span> <span class="s1">'@'</span>
+ <span class="nx">@token</span> <span class="s1">'INDEX_START'</span><span class="p">,</span> <span class="s1">'['</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">RESERVED</span><span class="p">,</span> <span class="nx">id</span><span class="p">)</span>
+ <span class="nx">@identifierError</span> <span class="nx">id</span>
+ <span class="nx">unless</span> <span class="nx">forcedIdentifier</span>
+ <span class="nv">tag = id = </span><span class="nx">CONVERSIONS</span><span class="p">[</span><span class="nx">id</span><span class="p">]</span> <span class="k">if</span> <span class="nx">include</span> <span class="nx">COFFEE_ALIASES</span><span class="p">,</span> <span class="nx">id</span>
+ <span class="nv">tag = </span><span class="s1">'LOGIC'</span> <span class="k">if</span> <span class="nx">include</span> <span class="nx">LOGIC</span><span class="p">,</span> <span class="nx">id</span>
+ <span class="nv">tag = </span><span class="s1">'UNARY'</span> <span class="k">if</span> <span class="nx">id</span> <span class="o">is</span> <span class="s1">'!'</span>
+ <span class="nx">@token</span> <span class="nx">tag</span><span class="p">,</span> <span class="nx">id</span>
+ <span class="nx">@token</span> <span class="s1">']'</span><span class="p">,</span> <span class="s1">']'</span> <span class="k">if</span> <span class="nx">close_index</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</a> </div> <p>Matches numbers, including decimals, hex, and exponential notation.
+Be careful not to interfere with ranges-in-progress.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">numberToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">number = </span><span class="nx">@match</span> <span class="nx">NUMBER</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">is</span> <span class="s1">'.'</span> <span class="o">and</span> <span class="nx">starts</span> <span class="nx">number</span><span class="p">,</span> <span class="s1">'.'</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">number</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nx">@token</span> <span class="s1">'NUMBER'</span><span class="p">,</span> <span class="nx">number</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</a> </div> <p>Matches strings, including multi-line strings. Ensures that quotation marks
+are balanced within the string's contents, and within nested interpolations.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">stringToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nx">starts</span><span class="p">(</span><span class="nx">@chunk</span><span class="p">,</span> <span class="s1">'"'</span><span class="p">)</span> <span class="o">or</span> <span class="nx">starts</span><span class="p">(</span><span class="nx">@chunk</span><span class="p">,</span> <span class="s2">"'"</span><span class="p">)</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">string =</span>
+ <span class="nx">@balancedToken</span><span class="p">([</span><span class="s1">'"'</span><span class="p">,</span> <span class="s1">'"'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'#{'</span><span class="p">,</span> <span class="s1">'}'</span><span class="p">])</span> <span class="o">or</span>
+ <span class="nx">@balancedToken</span> <span class="p">[</span><span class="s2">"'"</span><span class="p">,</span> <span class="s2">"'"</span><span class="p">]</span>
+ <span class="nx">@interpolateString</span> <span class="nx">string</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/\n/g</span><span class="p">,</span> <span class="s1">'\\\n'</span>
+ <span class="nx">@line</span> <span class="o">+=</span> <span class="nx">count</span> <span class="nx">string</span><span class="p">,</span> <span class="s2">"\n"</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">string</span><span class="p">.</span><span class="nx">length</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-11">#</a> </div> <p>Matches heredocs, adjusting indentation to the correct level, as heredocs
+preserve whitespace, but ignore indentation to the left.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">heredocToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">match = </span><span class="nx">@chunk</span><span class="p">.</span><span class="nx">match</span> <span class="nx">HEREDOC</span>
+ <span class="nv">quote = </span><span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">substr</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="nv">doc = </span><span class="nx">@sanitizeHeredoc</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">or</span> <span class="nx">match</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">or</span> <span class="s1">''</span><span class="p">,</span> <span class="p">{</span><span class="nx">quote</span><span class="p">}</span>
+ <span class="nx">@interpolateString</span> <span class="nx">quote</span> <span class="o">+</span> <span class="nx">doc</span> <span class="o">+</span> <span class="nx">quote</span><span class="p">,</span> <span class="nx">heredoc</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="nx">@line</span> <span class="o">+=</span> <span class="nx">count</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="s2">"\n"</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">length</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-12">#</a> </div> <p>Matches and consumes comments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">commentToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">match = </span><span class="nx">@chunk</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">COMMENT</span><span class="p">)</span>
+ <span class="nx">@line</span> <span class="o">+=</span> <span class="nx">count</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="s2">"\n"</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">match</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">length</span>
+ <span class="k">if</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
+ <span class="nx">@token</span> <span class="s1">'HERECOMMENT'</span><span class="p">,</span> <span class="nx">@sanitizeHeredoc</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
+ <span class="nx">herecomment</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">indent</span><span class="o">:</span> <span class="nb">Array</span><span class="p">(</span><span class="nx">@indent</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">' '</span><span class="p">)</span>
+ <span class="nx">@token</span> <span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s1">'\n'</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-13">#</a> </div> <p>Matches JavaScript interpolated directly into the source via backticks.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">jsToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nx">starts</span> <span class="nx">@chunk</span><span class="p">,</span> <span class="s1">'`'</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">script = </span><span class="nx">@balancedToken</span> <span class="p">[</span><span class="s1">'`'</span><span class="p">,</span> <span class="s1">'`'</span><span class="p">]</span>
+ <span class="nx">@token</span> <span class="s1">'JS'</span><span class="p">,</span> <span class="nx">script</span><span class="p">.</span><span class="nx">replace</span> <span class="nx">JS_CLEANER</span><span class="p">,</span> <span class="s1">''</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">script</span><span class="p">.</span><span class="nx">length</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-14">#</a> </div> <p>Matches regular expression literals. Lexing regular expressions is difficult
+to distinguish from division, so we borrow some basic heuristics from
+JavaScript and Ruby, borrow slash balancing from <code>@balancedToken</code>, and
+borrow interpolation from <code>@interpolateString</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">regexToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">first = </span><span class="nx">@chunk</span><span class="p">.</span><span class="nx">match</span> <span class="nx">REGEX_START</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">first</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">is</span> <span class="s1">' '</span> <span class="o">and</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">not</span> <span class="k">in</span> <span class="p">[</span><span class="s1">'CALL_START'</span><span class="p">,</span> <span class="s1">'='</span><span class="p">]</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">include</span> <span class="nx">NOT_REGEX</span><span class="p">,</span> <span class="nx">@tag</span><span class="p">()</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">regex = </span><span class="nx">@balancedToken</span> <span class="p">[</span><span class="s1">'/'</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">]</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">end = </span><span class="nx">@chunk</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="nx">regex</span><span class="p">.</span><span class="nx">length</span><span class="p">).</span><span class="nx">match</span> <span class="nx">REGEX_END</span>
+ <span class="nx">regex</span> <span class="o">+=</span> <span class="nv">flags = </span><span class="nx">end</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">if</span> <span class="nx">end</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
+ <span class="k">if</span> <span class="nx">regex</span><span class="p">.</span><span class="nx">match</span> <span class="nx">REGEX_INTERPOLATION</span>
+ <span class="nv">str = </span><span class="nx">regex</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">1</span><span class="p">).</span><span class="nx">split</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
+ <span class="nv">str = </span><span class="nx">str</span><span class="p">.</span><span class="nx">replace</span> <span class="nx">REGEX_ESCAPE</span><span class="p">,</span> <span class="p">(</span><span class="nx">escaped</span><span class="p">)</span> <span class="o">-></span> <span class="s1">'\\'</span> <span class="o">+</span> <span class="nx">escaped</span>
+ <span class="vi">@tokens = </span><span class="nx">@tokens</span><span class="p">.</span><span class="nx">concat</span> <span class="p">[[</span><span class="s1">'('</span><span class="p">,</span> <span class="s1">'('</span><span class="p">],</span> <span class="p">[</span><span class="s1">'NEW'</span><span class="p">,</span> <span class="s1">'new'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'IDENTIFIER'</span><span class="p">,</span> <span class="s1">'RegExp'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'CALL_START'</span><span class="p">,</span> <span class="s1">'('</span><span class="p">]]</span>
+ <span class="nx">@interpolateString</span> <span class="s2">"\"#{str}\""</span><span class="p">,</span> <span class="nx">escapeQuotes</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">@tokens</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">[</span><span class="s1">','</span><span class="p">,</span> <span class="s1">','</span><span class="p">],</span> <span class="p">[</span><span class="s1">'STRING'</span><span class="p">,</span> <span class="s2">"\"#{flags}\""</span><span class="p">]</span> <span class="k">if</span> <span class="nx">flags</span>
+ <span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">@tokens</span><span class="p">.</span><span class="nx">length</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">[</span><span class="s1">')'</span><span class="p">,</span> <span class="s1">')'</span><span class="p">],</span> <span class="p">[</span><span class="s1">')'</span><span class="p">,</span> <span class="s1">')'</span><span class="p">]</span>
+ <span class="k">else</span>
+ <span class="nx">@token</span> <span class="s1">'REGEX'</span><span class="p">,</span> <span class="nx">regex</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">regex</span><span class="p">.</span><span class="nx">length</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-15">#</a> </div> <p>Matches a token in which which the passed delimiter pairs must be correctly
+balanced (ie. strings, JS literals).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">balancedToken</span><span class="o">:</span> <span class="p">(</span><span class="nx">delimited</span><span class="p">...)</span> <span class="o">-></span>
+ <span class="nx">@balancedString</span> <span class="nx">@chunk</span><span class="p">,</span> <span class="nx">delimited</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-16">#</a> </div> <p>Matches newlines, indents, and outdents, and determines which is which.
+If we can detect that the current line is continued onto the the next line,
+then the newline is suppressed:</p>
+
+<pre><code>elements
+ .each( ... )
+ .map( ... )
+</code></pre>
+
+<p>Keeps track of the level of indentation, because a single outdent token
+can close multiple indents, so we need to know how far in we happen to be.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">lineToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">indent = </span><span class="nx">@match</span> <span class="nx">MULTI_DENT</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="nx">@line</span> <span class="o">+=</span> <span class="nx">count</span> <span class="nx">indent</span><span class="p">,</span> <span class="s2">"\n"</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">indent</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">prev = </span><span class="nx">@prev</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
+ <span class="nv">size = </span><span class="nx">indent</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">LAST_DENTS</span><span class="p">).</span><span class="nx">reverse</span><span class="p">()[</span><span class="mi">0</span><span class="p">].</span><span class="nx">match</span><span class="p">(</span><span class="nx">LAST_DENT</span><span class="p">)[</span><span class="mi">1</span><span class="p">].</span><span class="nx">length</span>
+ <span class="nv">nextCharacter = </span><span class="nx">@match</span> <span class="nx">NEXT_CHARACTER</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="nv">noNewlines = </span><span class="nx">nextCharacter</span> <span class="o">is</span> <span class="s1">'.'</span> <span class="o">or</span> <span class="nx">nextCharacter</span> <span class="o">is</span> <span class="s1">','</span> <span class="o">or</span> <span class="nx">@unfinished</span><span class="p">()</span>
+ <span class="k">if</span> <span class="nx">size</span> <span class="o">-</span> <span class="nx">@indebt</span> <span class="o">is</span> <span class="nx">@indent</span>
+ <span class="k">return</span> <span class="nx">@suppressNewlines</span><span class="p">()</span> <span class="k">if</span> <span class="nx">noNewlines</span>
+ <span class="k">return</span> <span class="nx">@newlineToken</span> <span class="nx">indent</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">size</span> <span class="o">></span> <span class="nx">@indent</span>
+ <span class="k">if</span> <span class="nx">noNewlines</span>
+ <span class="vi">@indebt = </span><span class="nx">size</span> <span class="o">-</span> <span class="nx">@indent</span>
+ <span class="k">return</span> <span class="nx">@suppressNewlines</span><span class="p">()</span>
+ <span class="nv">diff = </span><span class="nx">size</span> <span class="o">-</span> <span class="nx">@indent</span> <span class="o">+</span> <span class="nx">@outdebt</span>
+ <span class="nx">@token</span> <span class="s1">'INDENT'</span><span class="p">,</span> <span class="nx">diff</span>
+ <span class="nx">@indents</span><span class="p">.</span><span class="nx">push</span> <span class="nx">diff</span>
+ <span class="vi">@outdebt = @indebt = </span><span class="mi">0</span>
+ <span class="k">else</span>
+ <span class="vi">@indebt = </span><span class="mi">0</span>
+ <span class="nx">@outdentToken</span> <span class="nx">@indent</span> <span class="o">-</span> <span class="nx">size</span><span class="p">,</span> <span class="nx">noNewlines</span>
+ <span class="vi">@indent = </span><span class="nx">size</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-17">#</a> </div> <p>Record an outdent token or multiple tokens, if we happen to be moving back
+inwards past several recorded indents.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">outdentToken</span><span class="o">:</span> <span class="p">(</span><span class="nx">moveOut</span><span class="p">,</span> <span class="nx">noNewlines</span><span class="p">,</span> <span class="nx">close</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">while</span> <span class="nx">moveOut</span> <span class="o">></span> <span class="mi">0</span>
+ <span class="nv">len = </span><span class="nx">@indents</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="k">if</span> <span class="nx">@indents</span><span class="p">[</span><span class="nx">len</span><span class="p">]</span> <span class="o">is</span> <span class="kc">undefined</span>
+ <span class="nv">moveOut = </span><span class="mi">0</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">@indents</span><span class="p">[</span><span class="nx">len</span><span class="p">]</span> <span class="o">is</span> <span class="nx">@outdebt</span>
+ <span class="nx">moveOut</span> <span class="o">-=</span> <span class="nx">@outdebt</span>
+ <span class="vi">@outdebt = </span><span class="mi">0</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">@indents</span><span class="p">[</span><span class="nx">len</span><span class="p">]</span> <span class="o"><</span> <span class="nx">@outdebt</span>
+ <span class="nx">@outdebt</span> <span class="o">-=</span> <span class="nx">@indents</span><span class="p">[</span><span class="nx">len</span><span class="p">]</span>
+ <span class="nx">moveOut</span> <span class="o">-=</span> <span class="nx">@indents</span><span class="p">[</span><span class="nx">len</span><span class="p">]</span>
+ <span class="k">else</span>
+ <span class="nv">dent = </span><span class="nx">@indents</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
+ <span class="nx">dent</span> <span class="o">-=</span> <span class="nx">@outdebt</span>
+ <span class="nx">moveOut</span> <span class="o">-=</span> <span class="nx">dent</span>
+ <span class="vi">@outdebt = </span><span class="mi">0</span>
+ <span class="nx">@token</span> <span class="s1">'OUTDENT'</span><span class="p">,</span> <span class="nx">dent</span>
+ <span class="nx">@outdebt</span> <span class="o">-=</span> <span class="nx">moveOut</span> <span class="k">if</span> <span class="nx">dent</span>
+ <span class="nx">@token</span> <span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s2">"\n"</span> <span class="nx">unless</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">is</span> <span class="s1">'TERMINATOR'</span> <span class="o">or</span> <span class="nx">noNewlines</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-18">#</a> </div> <p>Matches and consumes non-meaningful whitespace. Tag the previous token
+as being "spaced", because there are some cases where it makes a difference.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">whitespaceToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">space = </span><span class="nx">@match</span> <span class="nx">WHITESPACE</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="nv">prev = </span><span class="nx">@prev</span><span class="p">()</span>
+ <span class="nv">prev.spaced = </span><span class="kc">true</span> <span class="k">if</span> <span class="nx">prev</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">space</span><span class="p">.</span><span class="nx">length</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-19">#</a> </div> <p>Generate a newline token. Consecutive newlines get merged together.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">newlineToken</span><span class="o">:</span> <span class="p">(</span><span class="nx">newlines</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@token</span> <span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s2">"\n"</span> <span class="nx">unless</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">is</span> <span class="s1">'TERMINATOR'</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-20">#</a> </div> <p>Use a <code>\</code> at a line-ending to suppress the newline.
+The slash is removed here once its job is done.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">suppressNewlines</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@tokens</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span> <span class="k">if</span> <span class="nx">@value</span><span class="p">()</span> <span class="o">is</span> <span class="s2">"\\"</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-21">#</a> </div> <p>We treat all other single characters as a token. Eg.: <code>( ) , . !</code>
+Multi-character operators are also literal tokens, so that Jison can assign
+the proper order of operations. There are some symbols that we tag specially
+here. <code>;</code> and newlines are both treated as a <code>TERMINATOR</code>, we distinguish
+parentheses that indicate a method call from regular parentheses, and so on.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">literalToken</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nv">match = </span><span class="nx">@chunk</span><span class="p">.</span><span class="nx">match</span> <span class="nx">OPERATOR</span>
+ <span class="nv">value = </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="nv">space = </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="nx">@tagParameters</span><span class="p">()</span> <span class="k">if</span> <span class="nx">value</span> <span class="o">and</span> <span class="nx">value</span><span class="p">.</span><span class="nx">match</span> <span class="nx">CODE</span>
+ <span class="nx">value</span> <span class="o">or=</span> <span class="nx">@chunk</span><span class="p">.</span><span class="nx">substr</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="nx">@i</span> <span class="o">+=</span> <span class="nx">value</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">spaced = </span><span class="p">(</span><span class="nv">prev = </span><span class="nx">@prev</span><span class="p">())</span> <span class="o">and</span> <span class="nx">prev</span><span class="p">.</span><span class="nx">spaced</span>
+ <span class="nv">tag = </span><span class="nx">value</span>
+ <span class="k">if</span> <span class="nx">value</span> <span class="o">is</span> <span class="s1">'='</span>
+ <span class="nx">@assignmentError</span><span class="p">()</span> <span class="k">if</span> <span class="nx">include</span> <span class="nx">JS_FORBIDDEN</span><span class="p">,</span> <span class="nx">@value</span><span class="p">()</span>
+ <span class="k">if</span> <span class="nx">@value</span><span class="p">()</span> <span class="k">in</span> <span class="p">[</span><span class="s1">'or'</span><span class="p">,</span> <span class="s1">'and'</span><span class="p">]</span>
+ <span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="nx">@tokens</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="mi">1</span><span class="p">,</span> <span class="p">[</span><span class="s1">'COMPOUND_ASSIGN'</span><span class="p">,</span> <span class="nx">CONVERSIONS</span><span class="p">[</span><span class="nx">@value</span><span class="p">()]</span> <span class="o">+</span> <span class="s1">'='</span><span class="p">,</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
+ <span class="k">return</span> <span class="kc">true</span>
+ <span class="k">if</span> <span class="nx">value</span> <span class="o">is</span> <span class="s1">';'</span> <span class="k">then</span> <span class="nv">tag = </span><span class="s1">'TERMINATOR'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">LOGIC</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="k">then</span> <span class="nv">tag = </span><span class="s1">'LOGIC'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">MATH</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="k">then</span> <span class="nv">tag = </span><span class="s1">'MATH'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">COMPARE</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="k">then</span> <span class="nv">tag = </span><span class="s1">'COMPARE'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">COMPOUND_ASSIGN</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="k">then</span> <span class="nv">tag = </span><span class="s1">'COMPOUND_ASSIGN'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">UNARY</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="k">then</span> <span class="nv">tag = </span><span class="s1">'UNARY'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">SHIFT</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="k">then</span> <span class="nv">tag = </span><span class="s1">'SHIFT'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">CALLABLE</span><span class="p">,</span> <span class="nx">@tag</span><span class="p">())</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">spaced</span>
+ <span class="k">if</span> <span class="nx">value</span> <span class="o">is</span> <span class="s1">'('</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">'FUNC_EXIST'</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">'?'</span>
+ <span class="nv">tag = </span><span class="s1">'CALL_START'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">value</span> <span class="o">is</span> <span class="s1">'['</span>
+ <span class="nv">tag = </span><span class="s1">'INDEX_START'</span>
+ <span class="nx">@tag</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'INDEX_SOAK'</span> <span class="k">if</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">is</span> <span class="s1">'?'</span>
+ <span class="nx">@tag</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'INDEX_PROTO'</span> <span class="k">if</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">is</span> <span class="s1">'::'</span>
+ <span class="nx">@token</span> <span class="nx">tag</span><span class="p">,</span> <span class="nx">value</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-22">#</a> </div> <h2>Token Manipulators</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-23">#</a> </div> <p>As we consume a new <code>IDENTIFIER</code>, look at the previous token to determine
+if it's a special kind of accessor. Return <code>true</code> if any type of accessor
+is the previous token.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">tagAccessor</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="p">(</span><span class="o">not</span> <span class="nv">prev = </span><span class="nx">@prev</span><span class="p">())</span> <span class="o">or</span> <span class="p">(</span><span class="nx">prev</span> <span class="o">and</span> <span class="nx">prev</span><span class="p">.</span><span class="nx">spaced</span><span class="p">)</span>
+ <span class="nv">accessor = </span><span class="k">if</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'::'</span>
+ <span class="nx">@tag</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'PROTOTYPE_ACCESS'</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'.'</span> <span class="o">and</span> <span class="o">not</span> <span class="p">(</span><span class="nx">@value</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">is</span> <span class="s1">'.'</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">@tag</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">is</span> <span class="s1">'?'</span>
+ <span class="nx">@tag</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">'SOAK_ACCESS'</span><span class="p">)</span>
+ <span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
+ <span class="k">else</span>
+ <span class="nx">@tag</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">'PROPERTY_ACCESS'</span>
+ <span class="k">else</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">'@'</span>
+ <span class="k">if</span> <span class="nx">accessor</span> <span class="k">then</span> <span class="s1">'accessor'</span> <span class="k">else</span> <span class="kc">false</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-24">#</a> </div> <p>Sanitize a heredoc or herecomment by escaping internal double quotes and
+erasing all external indentation on the left-hand side.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">sanitizeHeredoc</span><span class="o">:</span> <span class="p">(</span><span class="nx">doc</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">indent = </span><span class="nx">options</span><span class="p">.</span><span class="nx">indent</span>
+ <span class="k">return</span> <span class="nx">doc</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">herecomment</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">include</span> <span class="nx">doc</span><span class="p">,</span> <span class="s1">'\n'</span>
+ <span class="nx">unless</span> <span class="nx">options</span><span class="p">.</span><span class="nx">herecomment</span>
+ <span class="k">while</span> <span class="p">(</span><span class="nv">match = </span><span class="nx">HEREDOC_INDENT</span><span class="p">.</span><span class="nx">exec</span><span class="p">(</span><span class="nx">doc</span><span class="p">))</span> <span class="o">isnt</span> <span class="kc">null</span>
+ <span class="nv">attempt = </span><span class="k">if</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">?</span> <span class="k">then</span> <span class="nx">match</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="k">else</span> <span class="nx">match</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
+ <span class="nv">indent = </span><span class="nx">attempt</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">indent</span><span class="o">?</span> <span class="o">or</span> <span class="nx">attempt</span><span class="p">.</span><span class="nx">length</span> <span class="o"><</span> <span class="nx">indent</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nx">indent</span> <span class="o">or=</span> <span class="s1">''</span>
+ <span class="nv">doc = </span><span class="nx">doc</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"^"</span> <span class="o">+</span> <span class="nx">indent</span><span class="p">,</span> <span class="s1">'gm'</span><span class="p">),</span> <span class="s1">''</span><span class="p">)</span>
+ <span class="k">return</span> <span class="nx">doc</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">herecomment</span>
+ <span class="nv">doc = </span><span class="nx">doc</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">''</span><span class="p">)</span>
+ <span class="nx">doc</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">MULTILINER</span><span class="p">,</span> <span class="s2">"\\n"</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">quote</span><span class="p">,</span> <span class="s1">'g'</span><span class="p">),</span> <span class="s2">"\\#{options.quote}"</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-25">#</a> </div> <p>A source of ambiguity in our grammar used to be parameter lists in function
+definitions versus argument lists in function calls. Walk backwards, tagging
+parameters specially in order to make things easier for the parser.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">tagParameters</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">@tag</span><span class="p">()</span> <span class="o">isnt</span> <span class="s1">')'</span>
+ <span class="nv">i = </span><span class="mi">0</span>
+ <span class="nx">loop</span>
+ <span class="nx">i</span> <span class="o">+=</span> <span class="mi">1</span>
+ <span class="nv">tok = </span><span class="nx">@prev</span> <span class="nx">i</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">tok</span>
+ <span class="k">switch</span> <span class="nx">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+ <span class="k">when</span> <span class="s1">'IDENTIFIER'</span> <span class="k">then</span> <span class="nx">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'PARAM'</span>
+ <span class="k">when</span> <span class="s1">')'</span> <span class="k">then</span> <span class="nx">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'PARAM_END'</span>
+ <span class="k">when</span> <span class="s1">'('</span><span class="p">,</span> <span class="s1">'CALL_START'</span> <span class="k">then</span> <span class="k">return</span> <span class="nx">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'PARAM_START'</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-26">#</a> </div> <p>Close up all remaining open blocks at the end of the file.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">closeIndentation</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@outdentToken</span> <span class="nx">@indent</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-27">#</a> </div> <p>The error for when you try to use a forbidden word in JavaScript as
+an identifier.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">identifierError</span><span class="o">:</span> <span class="p">(</span><span class="nx">word</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">"SyntaxError: Reserved word \"#{word}\" on line #{@line + 1}"</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-28">#</a> </div> <p>The error for when you try to assign to a reserved word in JavaScript,
+like "function" or "default".</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">assignmentError</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">"SyntaxError: Reserved word \"#{@value()}\" on line #{@line + 1} can't be assigned"</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-29">#</a> </div> <p>Matches a balanced group such as a single or double-quoted string. Pass in
+a series of delimiters, all of which must be nested correctly within the
+contents of the string. This method allows us to have strings within
+interpolations within strings, ad infinitum.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">balancedString</span><span class="o">:</span> <span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="nx">delimited</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">options</span> <span class="o">or=</span> <span class="p">{}</span>
+ <span class="nv">slash = </span><span class="nx">delimited</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'/'</span>
+ <span class="nv">levels = </span><span class="p">[]</span>
+ <span class="nv">i = </span><span class="mi">0</span>
+ <span class="k">while</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">str</span><span class="p">.</span><span class="nx">length</span>
+ <span class="k">if</span> <span class="nx">levels</span><span class="p">.</span><span class="nx">length</span> <span class="o">and</span> <span class="nx">starts</span> <span class="nx">str</span><span class="p">,</span> <span class="s1">'\\'</span><span class="p">,</span> <span class="nx">i</span>
+ <span class="nx">i</span> <span class="o">+=</span> <span class="mi">1</span>
+ <span class="k">else</span>
+ <span class="k">for</span> <span class="nx">pair</span> <span class="k">in</span> <span class="nx">delimited</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="o">=</span> <span class="nx">pair</span>
+ <span class="k">if</span> <span class="nx">levels</span><span class="p">.</span><span class="nx">length</span> <span class="o">and</span> <span class="nx">starts</span><span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="nx">close</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">and</span> <span class="nx">levels</span><span class="p">[</span><span class="nx">levels</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">is</span> <span class="nx">pair</span>
+ <span class="nx">levels</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
+ <span class="nx">i</span> <span class="o">+=</span> <span class="nx">close</span><span class="p">.</span><span class="nx">length</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">unless</span> <span class="nx">levels</span><span class="p">.</span><span class="nx">length</span>
+ <span class="k">break</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">starts</span> <span class="nx">str</span><span class="p">,</span> <span class="nx">open</span><span class="p">,</span> <span class="nx">i</span>
+ <span class="nx">levels</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">pair</span><span class="p">)</span>
+ <span class="nx">i</span> <span class="o">+=</span> <span class="nx">open</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="k">break</span>
+ <span class="k">break</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">levels</span><span class="p">.</span><span class="nx">length</span> <span class="o">or</span> <span class="nx">slash</span> <span class="o">and</span> <span class="nx">starts</span> <span class="nx">str</span><span class="p">,</span> <span class="s1">'\n'</span><span class="p">,</span> <span class="nx">i</span>
+ <span class="nx">i</span> <span class="o">+=</span> <span class="mi">1</span>
+ <span class="k">if</span> <span class="nx">levels</span><span class="p">.</span><span class="nx">length</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">slash</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">"SyntaxError: Unterminated #{levels.pop()[0]} starting on line #{@line + 1}"</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">i</span> <span class="k">then</span> <span class="kc">false</span> <span class="k">else</span> <span class="nx">str</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-30">#</a> </div> <p>Expand variables and expressions inside double-quoted strings using
+<a href="http://wiki.ecmascript.org/doku.php?id=strawman:string_interpolation">ECMA Harmony's interpolation syntax</a>
+for substitution of bare variables as well as arbitrary expressions.</p>
+
+<pre><code>"Hello #{name.capitalize()}."
+</code></pre>
+
+<p>If it encounters an interpolation, this method will recursively create a
+new Lexer, tokenize the interpolated contents, and merge them into the
+token stream.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">interpolateString</span><span class="o">:</span> <span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">options</span> <span class="o">or=</span> <span class="p">{}</span>
+ <span class="k">if</span> <span class="nx">str</span><span class="p">.</span><span class="nx">length</span> <span class="o"><</span> <span class="mi">3</span> <span class="o">or</span> <span class="o">not</span> <span class="nx">starts</span> <span class="nx">str</span><span class="p">,</span> <span class="s1">'"'</span>
+ <span class="nx">@token</span> <span class="s1">'STRING'</span><span class="p">,</span> <span class="nx">str</span>
+ <span class="k">else</span>
+ <span class="nv">lexer = </span><span class="k">new</span> <span class="nx">Lexer</span>
+ <span class="nv">tokens = </span><span class="p">[]</span>
+ <span class="nv">quote = </span><span class="nx">str</span><span class="p">.</span><span class="nx">substring</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span>
+ <span class="p">[</span><span class="nx">i</span><span class="p">,</span> <span class="nx">pi</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
+ <span class="k">while</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">str</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="k">if</span> <span class="nx">starts</span> <span class="nx">str</span><span class="p">,</span> <span class="s1">'\\'</span><span class="p">,</span> <span class="nx">i</span>
+ <span class="nx">i</span> <span class="o">+=</span> <span class="mi">1</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nv">expr = </span><span class="nx">@balancedString</span><span class="p">(</span><span class="nx">str</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="nx">i</span><span class="p">),</span> <span class="p">[[</span><span class="s1">'#{'</span><span class="p">,</span> <span class="s1">'}'</span><span class="p">]])</span>
+ <span class="nx">tokens</span><span class="p">.</span><span class="nx">push</span> <span class="p">[</span><span class="s1">'STRING'</span><span class="p">,</span> <span class="nx">quote</span> <span class="o">+</span> <span class="nx">str</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="nx">pi</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">+</span> <span class="nx">quote</span><span class="p">]</span> <span class="k">if</span> <span class="nx">pi</span> <span class="o"><</span> <span class="nx">i</span>
+ <span class="nv">inner = </span><span class="nx">expr</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="nx">expr</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="k">if</span> <span class="nx">inner</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">inner = </span><span class="nx">inner</span><span class="p">.</span><span class="nx">replace</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s1">'\\\\'</span> <span class="o">+</span> <span class="nx">quote</span><span class="p">,</span> <span class="s1">'g'</span><span class="p">),</span> <span class="nx">quote</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">heredoc</span>
+ <span class="nv">nested = </span><span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="s2">"(#{inner})"</span><span class="p">,</span> <span class="nx">line</span><span class="o">:</span> <span class="nx">@line</span>
+ <span class="p">(</span><span class="nx">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">')'</span><span class="p">)</span> <span class="k">for</span> <span class="nx">tok</span><span class="p">,</span> <span class="nx">idx</span> <span class="k">in</span> <span class="nx">nested</span> <span class="k">when</span> <span class="nx">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'CALL_END'</span>
+ <span class="nx">nested</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
+ <span class="nx">tokens</span><span class="p">.</span><span class="nx">push</span> <span class="p">[</span><span class="s1">'TOKENS'</span><span class="p">,</span> <span class="nx">nested</span><span class="p">]</span>
+ <span class="k">else</span>
+ <span class="nx">tokens</span><span class="p">.</span><span class="nx">push</span> <span class="p">[</span><span class="s1">'STRING'</span><span class="p">,</span> <span class="nx">quote</span> <span class="o">+</span> <span class="nx">quote</span><span class="p">]</span>
+ <span class="nx">i</span> <span class="o">+=</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="nv">pi = </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>
+ <span class="nx">tokens</span><span class="p">.</span><span class="nx">push</span> <span class="p">[</span><span class="s1">'STRING'</span><span class="p">,</span> <span class="nx">quote</span> <span class="o">+</span> <span class="nx">str</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="nx">pi</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="o">+</span> <span class="nx">quote</span><span class="p">]</span> <span class="k">if</span> <span class="nx">pi</span> <span class="o"><</span> <span class="nx">i</span> <span class="o">and</span> <span class="nx">pi</span> <span class="o"><</span> <span class="nx">str</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="nx">tokens</span><span class="p">.</span><span class="nx">unshift</span> <span class="p">[</span><span class="s1">'STRING'</span><span class="p">,</span> <span class="s1">'""'</span><span class="p">]</span> <span class="nx">unless</span> <span class="nx">tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'STRING'</span>
+ <span class="nv">interpolated = </span><span class="nx">tokens</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">1</span>
+ <span class="nx">@token</span> <span class="s1">'('</span><span class="p">,</span> <span class="s1">'('</span> <span class="k">if</span> <span class="nx">interpolated</span>
+ <span class="k">for</span> <span class="nx">token</span><span class="p">,</span> <span class="nx">i</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="nx">token</span>
+ <span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">'TOKENS'</span>
+ <span class="vi">@tokens = </span><span class="nx">@tokens</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">value</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">'STRING'</span> <span class="o">and</span> <span class="nx">options</span><span class="p">.</span><span class="nx">escapeQuotes</span>
+ <span class="nv">escaped = </span><span class="nx">value</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nx">value</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="nx">replace</span><span class="p">(</span><span class="sr">/"/g</span><span class="p">,</span> <span class="s1">'\\"'</span><span class="p">)</span>
+ <span class="nx">@token</span> <span class="nx">tag</span><span class="p">,</span> <span class="s2">"\"#{escaped}\""</span>
+ <span class="k">else</span>
+ <span class="nx">@token</span> <span class="nx">tag</span><span class="p">,</span> <span class="nx">value</span>
+ <span class="nx">@token</span> <span class="s1">'+'</span><span class="p">,</span> <span class="s1">'+'</span> <span class="k">if</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">tokens</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="nx">@token</span> <span class="s1">')'</span><span class="p">,</span> <span class="s1">')'</span> <span class="k">if</span> <span class="nx">interpolated</span>
+ <span class="nx">tokens</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-31">#</a> </div> <h2>Helpers</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-32">#</a> </div> <p>Add a token to the results, taking note of the line number.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">token</span><span class="o">:</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="nx">@tokens</span><span class="p">.</span><span class="nx">push</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="nx">@line</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-33">#</a> </div> <p>Peek at a tag in the current token stream.</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">index</span><span class="p">,</span> <span class="nx">newTag</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">unless</span> <span class="nv">tok = </span><span class="nx">@prev</span> <span class="nx">index</span>
+ <span class="k">return</span> <span class="nx">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="nx">newTag</span> <span class="k">if</span> <span class="nx">newTag</span><span class="o">?</span>
+ <span class="nx">tok</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-34">#</a> </div> <p>Peek at a value in the current token stream.</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">index</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">unless</span> <span class="nv">tok = </span><span class="nx">@prev</span> <span class="nx">index</span>
+ <span class="k">return</span> <span class="nx">tok</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nx">val</span> <span class="k">if</span> <span class="nx">val</span><span class="o">?</span>
+ <span class="nx">tok</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-35">#</a> </div> <p>Peek at a previous token, entire.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">prev</span><span class="o">:</span> <span class="p">(</span><span class="nx">index</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@tokens</span><span class="p">[</span><span class="nx">@tokens</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="p">(</span><span class="nx">index</span> <span class="o">or</span> <span class="mi">1</span><span class="p">)]</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-36">#</a> </div> <p>Attempt to match a string against the current chunk, returning the indexed
+match if successful, and <code>false</code> otherwise.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">match</span><span class="o">:</span> <span class="p">(</span><span class="nx">regex</span><span class="p">,</span> <span class="nx">index</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="nx">unless</span> <span class="nv">m = </span><span class="nx">@chunk</span><span class="p">.</span><span class="nx">match</span> <span class="nx">regex</span>
+ <span class="k">if</span> <span class="nx">m</span> <span class="k">then</span> <span class="nx">m</span><span class="p">[</span><span class="nx">index</span><span class="p">]</span> <span class="k">else</span> <span class="kc">false</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-37">#</a> </div> <p>Are we in the midst of an unfinished expression?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">unfinished</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nv">prev = </span><span class="nx">@prev</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
+ <span class="nx">@value</span><span class="p">()</span> <span class="o">and</span> <span class="nx">@value</span><span class="p">().</span><span class="nx">match</span> <span class="o">and</span> <span class="nx">@value</span><span class="p">().</span><span class="nx">match</span><span class="p">(</span><span class="nx">NO_NEWLINE</span><span class="p">)</span> <span class="o">and</span>
+ <span class="nx">prev</span> <span class="o">and</span> <span class="p">(</span><span class="nx">prev</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">isnt</span> <span class="s1">'.'</span><span class="p">)</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@value</span><span class="p">().</span><span class="nx">match</span><span class="p">(</span><span class="nx">CODE</span><span class="p">)</span> <span class="o">and</span>
+ <span class="o">not</span> <span class="nx">@chunk</span><span class="p">.</span><span class="nx">match</span> <span class="nx">ASSIGNED</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-38">#</a> </div> <h2>Constants</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-39">#</a> </div> <p>Keywords that CoffeeScript shares in common with JavaScript.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">JS_KEYWORDS = </span><span class="p">[</span>
+ <span class="s2">"if"</span><span class="p">,</span> <span class="s2">"else"</span><span class="p">,</span>
+ <span class="s2">"true"</span><span class="p">,</span> <span class="s2">"false"</span><span class="p">,</span>
+ <span class="s2">"new"</span><span class="p">,</span> <span class="s2">"return"</span><span class="p">,</span>
+ <span class="s2">"try"</span><span class="p">,</span> <span class="s2">"catch"</span><span class="p">,</span> <span class="s2">"finally"</span><span class="p">,</span> <span class="s2">"throw"</span><span class="p">,</span>
+ <span class="s2">"break"</span><span class="p">,</span> <span class="s2">"continue"</span><span class="p">,</span>
+ <span class="s2">"for"</span><span class="p">,</span> <span class="s2">"in"</span><span class="p">,</span> <span class="s2">"while"</span><span class="p">,</span>
+ <span class="s2">"delete"</span><span class="p">,</span> <span class="s2">"instanceof"</span><span class="p">,</span> <span class="s2">"typeof"</span><span class="p">,</span>
+ <span class="s2">"switch"</span><span class="p">,</span> <span class="s2">"super"</span><span class="p">,</span> <span class="s2">"extends"</span><span class="p">,</span> <span class="s2">"class"</span><span class="p">,</span>
+ <span class="s2">"this"</span><span class="p">,</span> <span class="s2">"null"</span><span class="p">,</span> <span class="s2">"debugger"</span>
+<span class="p">]</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-40">#</a> </div> <p>CoffeeScript-only keywords, which we're more relaxed about allowing. They can't
+be used standalone, but you can reference them as an attached property.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">COFFEE_ALIASES = </span> <span class="p">[</span><span class="s2">"and"</span><span class="p">,</span> <span class="s2">"or"</span><span class="p">,</span> <span class="s2">"is"</span><span class="p">,</span> <span class="s2">"isnt"</span><span class="p">,</span> <span class="s2">"not"</span><span class="p">]</span>
+<span class="nv">COFFEE_KEYWORDS = </span><span class="nx">COFFEE_ALIASES</span><span class="p">.</span><span class="nx">concat</span> <span class="p">[</span>
+ <span class="s2">"then"</span><span class="p">,</span> <span class="s2">"unless"</span><span class="p">,</span> <span class="s2">"until"</span><span class="p">,</span> <span class="s2">"loop"</span><span class="p">,</span>
+ <span class="s2">"yes"</span><span class="p">,</span> <span class="s2">"no"</span><span class="p">,</span> <span class="s2">"on"</span><span class="p">,</span> <span class="s2">"off"</span><span class="p">,</span>
+ <span class="s2">"of"</span><span class="p">,</span> <span class="s2">"by"</span><span class="p">,</span> <span class="s2">"where"</span><span class="p">,</span> <span class="s2">"when"</span>
+<span class="p">]</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-41">#</a> </div> <p>The list of keywords that are reserved by JavaScript, but not used, or are
+used by CoffeeScript internally. We throw an error when these are encountered,
+to avoid having a JavaScript error at runtime.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">RESERVED = </span><span class="p">[</span>
+ <span class="s2">"case"</span><span class="p">,</span> <span class="s2">"default"</span><span class="p">,</span> <span class="s2">"do"</span><span class="p">,</span> <span class="s2">"function"</span><span class="p">,</span> <span class="s2">"var"</span><span class="p">,</span> <span class="s2">"void"</span><span class="p">,</span> <span class="s2">"with"</span><span class="p">,</span>
+ <span class="s2">"const"</span><span class="p">,</span> <span class="s2">"let"</span><span class="p">,</span> <span class="s2">"enum"</span><span class="p">,</span> <span class="s2">"export"</span><span class="p">,</span> <span class="s2">"import"</span><span class="p">,</span> <span class="s2">"native"</span><span class="p">,</span>
+ <span class="s2">"__hasProp"</span><span class="p">,</span> <span class="s2">"__extends"</span><span class="p">,</span> <span class="s2">"__slice"</span>
+<span class="p">]</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-42">#</a> </div> <p>The superset of both JavaScript keywords and reserved words, none of which may
+be used as identifiers or properties.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">JS_FORBIDDEN = </span><span class="nx">JS_KEYWORDS</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">RESERVED</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-43">#</a> </div> <p>Token matching regexes.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IDENTIFIER = </span><span class="sr">/^([a-zA-Z\$_](\w|\$)*)/</span>
+<span class="nv">NUMBER = </span><span class="sr">/^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b/i</span>
+<span class="nv">HEREDOC = </span><span class="sr">/^("{6}|'{6}|"{3}([\s\S]*?)\n?([ \t]*)"{3}|'{3}([\s\S]*?)\n?([ \t]*)'{3})/</span>
+<span class="nv">OPERATOR = </span><span class="sr">/^(-[\-=>]?|\+[+=]?|[*&|\/%=<>^:!?]+)([ \t]*)/</span>
+<span class="nv">WHITESPACE = </span><span class="sr">/^([ \t]+)/</span>
+<span class="nv">COMMENT = </span><span class="sr">/^(###([^#][\s\S]*?)(###[ \t]*\n|(###)?$)|(\s*#(?!##[^#])[^\n]*)+)/</span>
+<span class="nv">CODE = </span><span class="sr">/^((-|=)>)/</span>
+<span class="nv">MULTI_DENT = </span><span class="sr">/^((\n([ \t]*))+)(\.)?/</span>
+<span class="nv">LAST_DENTS = </span><span class="sr">/\n([ \t]*)/g</span>
+<span class="nv">LAST_DENT = </span><span class="sr">/\n([ \t]*)/</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-44">#</a> </div> <p>Regex-matching-regexes.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">REGEX_START = </span><span class="sr">/^\/([^\/])/</span>
+<span class="nv">REGEX_INTERPOLATION = </span><span class="sr">/([^\\]#\{.*[^\\]\})/</span>
+<span class="nv">REGEX_END = </span><span class="sr">/^(([imgy]{1,4})\b|\W|$)/</span>
+<span class="nv">REGEX_ESCAPE = </span><span class="sr">/\\[^\$]/g</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-45">#</a> </div> <p>Token cleaning regexes.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">JS_CLEANER = </span><span class="sr">/(^`|`$)/g</span>
+<span class="nv">MULTILINER = </span><span class="sr">/\n/g</span>
+<span class="nv">NO_NEWLINE = </span><span class="sr">/^([+\*&|\/\-%=<>!.\\][<>=&|]*|and|or|is|isnt|not|delete|typeof|instanceof)$/</span>
+<span class="nv">HEREDOC_INDENT = </span><span class="sr">/(\n+([ \t]*)|^([ \t]+))/g</span>
+<span class="nv">ASSIGNED = </span><span class="sr">/^\s*(([a-zA-Z\$_@]\w*|["'][^\r\n]+?["']|\d+)[ \t]*?[:=][^:=])/</span>
+<span class="nv">NEXT_CHARACTER = </span><span class="sr">/^\s*(\S)/</span></pre></div> </td> </tr> <tr id="section-46"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-46">#</a> </div> <p>Compound assignment tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">COMPOUND_ASSIGN = </span><span class="p">[</span><span class="s1">'-='</span><span class="p">,</span> <span class="s1">'+='</span><span class="p">,</span> <span class="s1">'/='</span><span class="p">,</span> <span class="s1">'*='</span><span class="p">,</span> <span class="s1">'%='</span><span class="p">,</span> <span class="s1">'||='</span><span class="p">,</span> <span class="s1">'&&='</span><span class="p">,</span> <span class="s1">'?='</span><span class="p">,</span> <span class="s1">'<<='</span><span class="p">,</span> <span class="s1">'>>='</span><span class="p">,</span> <span class="s1">'>>>='</span><span class="p">,</span> <span class="s1">'&='</span><span class="p">,</span> <span class="s1">'^='</span><span class="p">,</span> <span class="s1">'|='</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-47">#</a> </div> <p>Unary tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">UNARY = </span><span class="p">[</span><span class="s1">'UMINUS'</span><span class="p">,</span> <span class="s1">'UPLUS'</span><span class="p">,</span> <span class="s1">'!'</span><span class="p">,</span> <span class="s1">'!!'</span><span class="p">,</span> <span class="s1">'~'</span><span class="p">,</span> <span class="s1">'TYPEOF'</span><span class="p">,</span> <span class="s1">'DELETE'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-48">#</a> </div> <p>Logical tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">LOGIC = </span><span class="p">[</span><span class="s1">'&'</span><span class="p">,</span> <span class="s1">'|'</span><span class="p">,</span> <span class="s1">'^'</span><span class="p">,</span> <span class="s1">'&&'</span><span class="p">,</span> <span class="s1">'||'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-49"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-49">#</a> </div> <p>Bit-shifting tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">SHIFT = </span><span class="p">[</span><span class="s1">'<<'</span><span class="p">,</span> <span class="s1">'>>'</span><span class="p">,</span> <span class="s1">'>>>'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-50">#</a> </div> <p>Comparison tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">COMPARE = </span><span class="p">[</span><span class="s1">'<='</span><span class="p">,</span> <span class="s1">'<'</span><span class="p">,</span> <span class="s1">'>'</span><span class="p">,</span> <span class="s1">'>='</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-51">#</a> </div> <p>Mathmatical tokens.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">MATH = </span><span class="p">[</span><span class="s1">'*'</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">,</span> <span class="s1">'%'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-52">#</a> </div> <p>Tokens which a regular expression will never immediately follow, but which
+a division operator might.</p>
+
+<p>See: http://www.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions</p>
+
+<p>Our list is shorter, due to sans-parentheses method calls.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">NOT_REGEX = </span><span class="p">[</span><span class="s1">'NUMBER'</span><span class="p">,</span> <span class="s1">'REGEX'</span><span class="p">,</span> <span class="s1">'++'</span><span class="p">,</span> <span class="s1">'--'</span><span class="p">,</span> <span class="s1">'FALSE'</span><span class="p">,</span> <span class="s1">'NULL'</span><span class="p">,</span> <span class="s1">'TRUE'</span><span class="p">,</span> <span class="s1">']'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-53">#</a> </div> <p>Tokens which could legitimately be invoked or indexed. A opening
+parentheses or bracket following these tokens will be recorded as the start
+of a function invocation or indexing operation.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CALLABLE = </span><span class="p">[</span><span class="s1">'IDENTIFIER'</span><span class="p">,</span> <span class="s1">'SUPER'</span><span class="p">,</span> <span class="s1">')'</span><span class="p">,</span> <span class="s1">']'</span><span class="p">,</span> <span class="s1">'}'</span><span class="p">,</span> <span class="s1">'STRING'</span><span class="p">,</span> <span class="s1">'@'</span><span class="p">,</span> <span class="s1">'THIS'</span><span class="p">,</span> <span class="s1">'?'</span><span class="p">,</span> <span class="s1">'::'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-54"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-54">#</a> </div> <p>Tokens that, when immediately preceding a <code>WHEN</code>, indicate that the <code>WHEN</code>
+occurs at the start of a line. We disambiguate these from trailing whens to
+avoid an ambiguity in the grammar.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">LINE_BREAK = </span><span class="p">[</span><span class="s1">'INDENT'</span><span class="p">,</span> <span class="s1">'OUTDENT'</span><span class="p">,</span> <span class="s1">'TERMINATOR'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-55"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-55">#</a> </div> <p>Conversions from CoffeeScript operators into JavaScript ones.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">CONVERSIONS =</span>
+ <span class="s1">'and'</span><span class="o">:</span> <span class="s1">'&&'</span>
+ <span class="s1">'or'</span><span class="o">:</span> <span class="s1">'||'</span>
+ <span class="s1">'is'</span><span class="o">:</span> <span class="s1">'=='</span>
+ <span class="s1">'isnt'</span><span class="o">:</span> <span class="s1">'!='</span>
+ <span class="s1">'not'</span><span class="o">:</span> <span class="s1">'!'</span>
+ <span class="s1">'==='</span><span class="o">:</span> <span class="s1">'=='</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html> <html> <head> <title>nodes.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 … <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> nodes.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-1">#</a> </div> <p><code>nodes.coffee</code> contains all of the node classes for the syntax tree. Most
+nodes are created as the result of actions in the <a href="grammar.html">grammar</a>,
+but some are created by other nodes as a method of code generation. To convert
+the syntax tree into a string of JavaScript code, call <code>compile()</code> on the root.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">Scope</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s1">'./scope'</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-2">#</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">compact</span><span class="p">,</span> <span class="nx">flatten</span><span class="p">,</span> <span class="nx">merge</span><span class="p">,</span> <span class="nx">del</span><span class="p">,</span> <span class="nx">include</span><span class="p">,</span> <span class="nx">indexOf</span><span class="p">,</span> <span class="nx">starts</span><span class="p">,</span> <span class="nx">ends</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./helpers'</span><span class="p">).</span><span class="nx">helpers</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <h3>BaseNode</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</a> </div> <p>The <strong>BaseNode</strong> is the abstract base class for all nodes in the syntax tree.
+Each subclass implements the <code>compileNode</code> method, which performs the
+code generation for that node. To compile a node to JavaScript,
+call <code>compile</code> on it, which wraps <code>compileNode</code> in some generic extra smarts,
+to know when the generated code needs to be wrapped up in a closure.
+An options hash is passed and cloned throughout, containing information about
+the environment from higher in the tree (such as if a returned value is
+being requested by the surrounding function), information about the current
+scope, and indentation level.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.BaseNode = </span><span class="nx">class</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="o">-></span>
+ <span class="vi">@tags = </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</a> </div> <p>Common logic for determining whether to wrap this node in a closure before
+compiling it, or to compile directly. We need to wrap if this node is a
+<em>statement</em>, and it's not a <em>pureStatement</em>, and we're not at
+the top level of a block (which would be unnecessary), and we haven't
+already been asked to return the result (because statements know how to
+return results).</p>
+
+<p>If a Node is <em>topSensitive</em>, that means that it needs to compile differently
+depending on whether it's being used as part of a larger expression, or is a
+top-level statement within the function body.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compile</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="vi">@options = </span><span class="nx">merge</span> <span class="nx">o</span> <span class="o">or</span> <span class="p">{}</span>
+ <span class="vi">@tab = </span><span class="nx">o</span><span class="p">.</span><span class="nx">indent</span>
+ <span class="nx">del</span> <span class="nx">@options</span><span class="p">,</span> <span class="s1">'chainRoot'</span> <span class="nx">unless</span> <span class="k">this</span> <span class="k">instanceof</span> <span class="nx">AccessorNode</span> <span class="o">or</span> <span class="k">this</span> <span class="k">instanceof</span> <span class="nx">IndexNode</span>
+ <span class="nv">top = </span><span class="k">if</span> <span class="nx">@topSensitive</span><span class="p">()</span> <span class="k">then</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">top</span> <span class="k">else</span> <span class="nx">del</span> <span class="nx">@options</span><span class="p">,</span> <span class="s1">'top'</span>
+ <span class="nv">closure = </span><span class="nx">@isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@isPureStatement</span><span class="p">()</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">top</span> <span class="o">and</span>
+ <span class="o">not</span> <span class="nx">@options</span><span class="p">.</span><span class="nx">asStatement</span> <span class="o">and</span> <span class="k">this</span> <span class="o">not</span> <span class="k">instanceof</span> <span class="nx">CommentNode</span> <span class="o">and</span>
+ <span class="o">not</span> <span class="nx">@containsPureStatement</span><span class="p">()</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">startLevel</span><span class="p">()</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">o</span><span class="p">.</span><span class="nx">keepLevel</span>
+ <span class="nv">code = </span><span class="k">if</span> <span class="nx">closure</span> <span class="k">then</span> <span class="nx">@compileClosure</span><span class="p">(</span><span class="nx">@options</span><span class="p">)</span> <span class="k">else</span> <span class="nx">@compileNode</span><span class="p">(</span><span class="nx">@options</span><span class="p">)</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">endLevel</span><span class="p">()</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">o</span><span class="p">.</span><span class="nx">keepLevel</span>
+ <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</a> </div> <p>Statements converted into expressions via closure-wrapping share a scope
+object with their parent closure, to preserve the expected lexical scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileClosure</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="vi">@tab = </span><span class="nx">o</span><span class="p">.</span><span class="nx">indent</span>
+ <span class="nv">o.sharedScope = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span>
+ <span class="nx">ClosureNode</span><span class="p">.</span><span class="nx">wrap</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">compile</span> <span class="nx">o</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-7">#</a> </div> <p>If the code generation wishes to use the result of a complex expression
+in multiple places, ensure that the expression is only ever evaluated once,
+by assigning it to a temporary variable.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileReference</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">options</span> <span class="o">or=</span> <span class="p">{}</span>
+ <span class="nv">pair = </span><span class="k">if</span> <span class="o">not</span> <span class="p">(</span><span class="nx">@containsType</span><span class="p">(</span><span class="nx">CallNode</span><span class="p">)</span> <span class="o">or</span>
+ <span class="p">(</span><span class="k">this</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span> <span class="o">and</span> <span class="p">(</span><span class="o">not</span> <span class="p">(</span><span class="nx">@base</span> <span class="k">instanceof</span> <span class="nx">LiteralNode</span><span class="p">)</span> <span class="o">or</span> <span class="nx">@hasProperties</span><span class="p">())))</span>
+ <span class="p">[</span><span class="k">this</span><span class="p">,</span> <span class="k">this</span><span class="p">]</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="k">this</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span> <span class="o">and</span> <span class="nx">options</span><span class="p">.</span><span class="nx">assignment</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">cacheIndexes</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="k">else</span>
+ <span class="nv">reference = </span><span class="nx">literal</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'ref'</span>
+ <span class="nv">compiled = </span><span class="k">new</span> <span class="nx">AssignNode</span> <span class="nx">reference</span><span class="p">,</span> <span class="k">this</span>
+ <span class="p">[</span><span class="nx">compiled</span><span class="p">,</span> <span class="nx">reference</span><span class="p">]</span>
+ <span class="k">return</span> <span class="p">[</span><span class="nx">pair</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">),</span> <span class="nx">pair</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)]</span> <span class="k">if</span> <span class="nx">options</span><span class="p">.</span><span class="nx">precompile</span>
+ <span class="nx">pair</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-8">#</a> </div> <p>Convenience method to grab the current indentation level, plus tabbing in.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">idt</span><span class="o">:</span> <span class="p">(</span><span class="nx">tabs</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">idt = </span><span class="nx">@tab</span> <span class="o">or</span> <span class="s1">''</span>
+ <span class="nv">num = </span><span class="p">(</span><span class="nx">tabs</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="nx">idt</span> <span class="o">+=</span> <span class="nx">TAB</span> <span class="k">while</span> <span class="nx">num</span> <span class="o">-=</span> <span class="mi">1</span>
+ <span class="nx">idt</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</a> </div> <p>Construct a node that returns the current node's result.
+Note that this is overridden for smarter behavior for
+many statement nodes (eg IfNode, ForNode)...</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">new</span> <span class="nx">ReturnNode</span> <span class="k">this</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</a> </div> <p>Does this node, or any of its children, contain a node of a certain kind?
+Recursively traverses down the <em>children</em> of the nodes, yielding to a block
+and returning true when the block finds a match. <code>contains</code> does not cross
+scope boundaries.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">contains</span><span class="o">:</span> <span class="p">(</span><span class="nx">block</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">contains = </span><span class="kc">false</span>
+ <span class="nx">@traverseChildren</span> <span class="kc">false</span><span class="p">,</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">block</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span>
+ <span class="nv">contains = </span><span class="kc">true</span>
+ <span class="k">return</span> <span class="kc">false</span>
+ <span class="nx">contains</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-11">#</a> </div> <p>Is this node of a certain type, or does it contain the type?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">containsType</span><span class="o">:</span> <span class="p">(</span><span class="nx">type</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">this</span> <span class="k">instanceof</span> <span class="nx">type</span> <span class="o">or</span> <span class="nx">@contains</span> <span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="o">-></span> <span class="nx">n</span> <span class="k">instanceof</span> <span class="nx">type</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-12">#</a> </div> <p>Convenience for the most common use of contains. Does the node contain
+a pure statement?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">containsPureStatement</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@isPureStatement</span><span class="p">()</span> <span class="o">or</span> <span class="nx">@contains</span> <span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="o">-></span> <span class="nx">n</span><span class="p">.</span><span class="nx">isPureStatement</span> <span class="o">and</span> <span class="nx">n</span><span class="p">.</span><span class="nx">isPureStatement</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-13">#</a> </div> <p>Perform an in-order traversal of the AST. Crosses scope boundaries.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">traverse</span><span class="o">:</span> <span class="p">(</span><span class="nx">block</span><span class="p">)</span> <span class="o">-></span> <span class="nx">@traverseChildren</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">block</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-14">#</a> </div> <p><code>toString</code> representation of the node, for inspecting the parse tree.
+This is what <code>coffee --nodes</code> prints out.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">toString</span><span class="o">:</span> <span class="p">(</span><span class="nx">idt</span><span class="p">,</span> <span class="nx">override</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">idt</span> <span class="o">or=</span> <span class="s1">''</span>
+ <span class="nv">children = </span><span class="p">(</span><span class="nx">child</span><span class="p">.</span><span class="nx">toString</span> <span class="nx">idt</span> <span class="o">+</span> <span class="nx">TAB</span> <span class="k">for</span> <span class="nx">child</span> <span class="k">in</span> <span class="nx">@collectChildren</span><span class="p">()).</span><span class="nx">join</span><span class="p">(</span><span class="s1">''</span><span class="p">)</span>
+ <span class="s1">'\n'</span> <span class="o">+</span> <span class="nx">idt</span> <span class="o">+</span> <span class="p">(</span><span class="nx">override</span> <span class="o">or</span> <span class="nx">@class</span><span class="p">)</span> <span class="o">+</span> <span class="nx">children</span>
+
+ <span class="nx">eachChild</span><span class="o">:</span> <span class="p">(</span><span class="nx">func</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">unless</span> <span class="nx">@children</span>
+ <span class="k">for</span> <span class="nx">attr</span> <span class="k">in</span> <span class="nx">@children</span> <span class="k">when</span> <span class="k">this</span><span class="p">[</span><span class="nx">attr</span><span class="p">]</span>
+ <span class="k">for</span> <span class="nx">child</span> <span class="k">in</span> <span class="nx">flatten</span> <span class="p">[</span><span class="k">this</span><span class="p">[</span><span class="nx">attr</span><span class="p">]]</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">func</span><span class="p">(</span><span class="nx">child</span><span class="p">)</span> <span class="o">is</span> <span class="kc">false</span>
+
+ <span class="nx">collectChildren</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nv">nodes = </span><span class="p">[]</span>
+ <span class="nx">@eachChild</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="o">-></span> <span class="nx">nodes</span><span class="p">.</span><span class="nx">push</span> <span class="nx">node</span>
+ <span class="nx">nodes</span>
+
+ <span class="nx">traverseChildren</span><span class="o">:</span> <span class="p">(</span><span class="nx">crossScope</span><span class="p">,</span> <span class="nx">func</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@eachChild</span> <span class="p">(</span><span class="nx">child</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">func</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">)</span>
+ <span class="nx">child</span><span class="p">.</span><span class="nx">traverseChildren</span><span class="p">(</span><span class="nx">crossScope</span><span class="p">,</span> <span class="nx">func</span><span class="p">)</span> <span class="k">if</span> <span class="nx">child</span> <span class="k">instanceof</span> <span class="nx">BaseNode</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-15">#</a> </div> <p>Default implementations of the common node properties and methods. Nodes
+will override these with custom logic, if needed.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">class</span><span class="o">:</span> <span class="s1">'BaseNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[]</span>
+
+ <span class="nx">unwrap</span> <span class="o">:</span> <span class="o">-></span> <span class="k">this</span>
+ <span class="nx">isStatement</span> <span class="o">:</span> <span class="o">-></span> <span class="kc">no</span>
+ <span class="nx">isPureStatement</span> <span class="o">:</span> <span class="o">-></span> <span class="kc">no</span>
+ <span class="nx">topSensitive</span> <span class="o">:</span> <span class="o">-></span> <span class="kc">no</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-16">#</a> </div> <h3>Expressions</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-17">#</a> </div> <p>The expressions body is the list of expressions that forms the body of an
+indented block of code -- the implementation of a function, a clause in an
+<code>if</code>, <code>switch</code>, or <code>try</code>, and so on...</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.Expressions = </span><span class="nx">class</span> <span class="nx">Expressions</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'Expressions'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'expressions'</span><span class="p">]</span>
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">nodes</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="vi">@expressions = </span><span class="nx">compact</span> <span class="nx">flatten</span> <span class="nx">nodes</span> <span class="o">or</span> <span class="p">[]</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-18">#</a> </div> <p>Tack an expression on to the end of this expression list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">push</span><span class="o">:</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@expressions</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-19">#</a> </div> <p>Add an expression at the beginning of this expression list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">unshift</span><span class="o">:</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@expressions</span><span class="p">.</span><span class="nx">unshift</span><span class="p">(</span><span class="nx">node</span><span class="p">)</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-20">#</a> </div> <p>If this Expressions consists of just a single node, unwrap it by pulling
+it back out.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">unwrap</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@expressions</span><span class="p">.</span><span class="nx">length</span> <span class="o">is</span> <span class="mi">1</span> <span class="k">then</span> <span class="nx">@expressions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">else</span> <span class="k">this</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-21">#</a> </div> <p>Is this an empty block of code?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">empty</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@expressions</span><span class="p">.</span><span class="nx">length</span> <span class="o">is</span> <span class="mi">0</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-22">#</a> </div> <p>An Expressions node does not return its entire body, rather it
+ensures that the final expression is returned.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nv">idx = </span><span class="nx">@expressions</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="nv">last = </span><span class="nx">@expressions</span><span class="p">[</span><span class="nx">idx</span><span class="p">]</span>
+ <span class="nv">last = </span><span class="nx">@expressions</span><span class="p">[</span><span class="nx">idx</span> <span class="o">-=</span> <span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="nx">last</span> <span class="k">instanceof</span> <span class="nx">CommentNode</span>
+ <span class="k">return</span> <span class="k">this</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">last</span> <span class="o">or</span> <span class="nx">last</span> <span class="k">instanceof</span> <span class="nx">ReturnNode</span>
+ <span class="nx">@expressions</span><span class="p">[</span><span class="nx">idx</span><span class="p">]</span> <span class="o">=</span> <span class="nx">last</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">()</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-23">#</a> </div> <p>An <strong>Expressions</strong> is the only node that can serve as the root.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compile</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">o</span> <span class="o">or=</span> <span class="p">{}</span>
+ <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span> <span class="k">then</span> <span class="k">super</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="nx">@compileRoot</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">(</span><span class="nx">@compileExpression</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">o</span><span class="p">))</span> <span class="k">for</span> <span class="nx">node</span> <span class="k">in</span> <span class="nx">@expressions</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s2">"\n"</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-24">#</a> </div> <p>If we happen to be the top-level <strong>Expressions</strong>, wrap everything in
+a safety closure, unless requested not to.
+It would be better not to generate them in the first place, but for now,
+clean up obvious double-parentheses.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileRoot</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">o.indent = </span><span class="vi">@tab = </span><span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">noWrap</span> <span class="k">then</span> <span class="s1">''</span> <span class="k">else</span> <span class="nx">TAB</span>
+ <span class="nv">o.scope = </span><span class="k">new</span> <span class="nx">Scope</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="k">this</span><span class="p">,</span> <span class="kc">null</span><span class="p">)</span>
+ <span class="nv">code = </span><span class="nx">@compileWithDeclarations</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">code = </span><span class="nx">code</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">TRAILING_WHITESPACE</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">noWrap</span> <span class="k">then</span> <span class="nx">code</span> <span class="k">else</span> <span class="s2">"(function() {\n#{code}\n}).call(this);\n"</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-25">#</a> </div> <p>Compile the expressions body for the contents of a function, with
+declarations of all inner variables pushed up to the top.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileWithDeclarations</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">code = </span><span class="nx">@compileNode</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">code = </span><span class="s2">"#{@tab}var #{o.scope.compiledAssignments()};\n#{code}"</span> <span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">hasAssignments</span><span class="p">(</span><span class="k">this</span><span class="p">)</span>
+ <span class="nv">code = </span><span class="s2">"#{@tab}var #{o.scope.compiledDeclarations()};\n#{code}"</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">o</span><span class="p">.</span><span class="nx">globals</span> <span class="o">and</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">hasDeclarations</span><span class="p">(</span><span class="k">this</span><span class="p">)</span>
+ <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-26">#</a> </div> <p>Compiles a single expression within the expressions body. If we need to
+return the result, and it's an expression, simply return it. If it's a
+statement, ask the statement to do so.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileExpression</span><span class="o">:</span> <span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="vi">@tab = </span><span class="nx">o</span><span class="p">.</span><span class="nx">indent</span>
+ <span class="nv">compiledNode = </span><span class="nx">node</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">merge</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">top</span><span class="o">:</span> <span class="kc">true</span>
+ <span class="k">if</span> <span class="nx">node</span><span class="p">.</span><span class="nx">isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">then</span> <span class="nx">compiledNode</span> <span class="k">else</span> <span class="s2">"#{@idt()}#{compiledNode};"</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-27">#</a> </div> <p>Wrap up the given nodes as an <strong>Expressions</strong>, unless it already happens
+to be one.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">Expressions.wrap = </span><span class="p">(</span><span class="nx">nodes</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">nodes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="nx">nodes</span><span class="p">.</span><span class="nx">length</span> <span class="o">is</span> <span class="mi">1</span> <span class="o">and</span> <span class="nx">nodes</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">instanceof</span> <span class="nx">Expressions</span>
+ <span class="k">new</span> <span class="nx">Expressions</span><span class="p">(</span><span class="nx">nodes</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-28">#</a> </div> <h3>LiteralNode</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-29">#</a> </div> <p>Literals are static values that can be passed through directly into
+JavaScript without translation, such as: strings, numbers,
+<code>true</code>, <code>false</code>, <code>null</code>...</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.LiteralNode = </span><span class="nx">class</span> <span class="nx">LiteralNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'LiteralNode'</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@value</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@isStatement</span><span class="p">()</span> <span class="k">then</span> <span class="k">this</span> <span class="k">else</span> <span class="k">super</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-30">#</a> </div> <p>Break and continue must be treated as pure statements -- they lose their
+meaning when wrapped in a closure.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@value</span> <span class="o">is</span> <span class="s1">'break'</span> <span class="o">or</span> <span class="nx">@value</span> <span class="o">is</span> <span class="s1">'continue'</span> <span class="o">or</span> <span class="nx">@value</span> <span class="o">is</span> <span class="s1">'debugger'</span>
+ <span class="nx">isPureStatement</span><span class="o">:</span> <span class="nx">LiteralNode</span><span class="o">::</span><span class="nx">isStatement</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">idt = </span><span class="k">if</span> <span class="nx">@isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">then</span> <span class="nx">@idt</span><span class="p">()</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nv">end = </span><span class="k">if</span> <span class="nx">@isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">then</span> <span class="s1">';'</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nx">idt</span> <span class="o">+</span> <span class="nx">@value</span> <span class="o">+</span> <span class="nx">end</span>
+
+ <span class="nx">toString</span><span class="o">:</span> <span class="p">(</span><span class="nx">idt</span><span class="p">)</span> <span class="o">-></span>
+ <span class="s1">'"'</span> <span class="o">+</span> <span class="nx">@value</span> <span class="o">+</span> <span class="s1">'"'</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-31">#</a> </div> <h3>ReturnNode</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-32">#</a> </div> <p>A <code>return</code> is a <em>pureStatement</em> -- wrapping it in a closure wouldn't
+make sense.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ReturnNode = </span><span class="nx">class</span> <span class="nx">ReturnNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ReturnNode'</span>
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+ <span class="nx">isPureStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'expression'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@expression</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">this</span>
+
+ <span class="nx">compile</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">expr = </span><span class="nx">@expression</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">()</span>
+ <span class="k">return</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span> <span class="nx">unless</span> <span class="nx">expr</span> <span class="k">instanceof</span> <span class="nx">ReturnNode</span>
+ <span class="k">super</span> <span class="nx">o</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">o.asStatement = </span><span class="kc">true</span> <span class="k">if</span> <span class="nx">@expression</span><span class="p">.</span><span class="nx">isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="s2">"#{@tab}return #{@expression.compile(o)};"</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-33">#</a> </div> <h3>ValueNode</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-34">#</a> </div> <p>A value, variable or literal or parenthesized, indexed or dotted into,
+or vanilla.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ValueNode = </span><span class="nx">class</span> <span class="nx">ValueNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ValueNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'base'</span><span class="p">,</span> <span class="s1">'properties'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-35">#</a> </div> <p>A <strong>ValueNode</strong> has a base and a list of property accesses.</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">@base</span><span class="p">,</span> <span class="nx">@properties</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="nx">@properties</span> <span class="o">or=</span> <span class="p">[]</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-36">#</a> </div> <p>Add a property access to the list.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">push</span><span class="o">:</span> <span class="p">(</span><span class="nx">prop</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@properties</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">prop</span><span class="p">)</span>
+ <span class="k">this</span>
+
+ <span class="nx">hasProperties</span><span class="o">:</span> <span class="o">-></span>
+ <span class="o">!!</span><span class="nx">@properties</span><span class="p">.</span><span class="nx">length</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-37">#</a> </div> <p>Some boolean checks for the benefit of other nodes.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">isArray</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@base</span> <span class="k">instanceof</span> <span class="nx">ArrayNode</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@hasProperties</span><span class="p">()</span>
+
+ <span class="nx">isObject</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@base</span> <span class="k">instanceof</span> <span class="nx">ObjectNode</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@hasProperties</span><span class="p">()</span>
+
+ <span class="nx">isSplice</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@hasProperties</span><span class="p">()</span> <span class="o">and</span> <span class="nx">@properties</span><span class="p">[</span><span class="nx">@properties</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="k">instanceof</span> <span class="nx">SliceNode</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@hasProperties</span><span class="p">()</span> <span class="k">then</span> <span class="k">super</span><span class="p">()</span> <span class="k">else</span> <span class="nx">@base</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-38">#</a> </div> <p>The value can be unwrapped as its inner node, if there are no attached
+properties.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">unwrap</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@properties</span><span class="p">.</span><span class="nx">length</span> <span class="k">then</span> <span class="k">this</span> <span class="k">else</span> <span class="nx">@base</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-39">#</a> </div> <p>Values are considered to be statements if their base is a statement.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">isStatement</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@base</span><span class="p">.</span><span class="nx">isStatement</span> <span class="o">and</span> <span class="nx">@base</span><span class="p">.</span><span class="nx">isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@hasProperties</span><span class="p">()</span>
+
+ <span class="nx">isNumber</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@base</span> <span class="k">instanceof</span> <span class="nx">LiteralNode</span> <span class="o">and</span> <span class="nx">@base</span><span class="p">.</span><span class="nx">value</span><span class="p">.</span><span class="nx">match</span> <span class="nx">NUMBER</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-40">#</a> </div> <p>If the value node has indexes containing function calls, and the value node
+needs to be used twice, in compound assignment ... then we need to cache
+the value of the indexes.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">cacheIndexes</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">copy = </span><span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">@base</span><span class="p">,</span> <span class="nx">@properties</span><span class="p">[</span><span class="mi">0</span><span class="p">..]</span>
+ <span class="k">if</span> <span class="nx">@base</span> <span class="k">instanceof</span> <span class="nx">CallNode</span>
+ <span class="p">[</span><span class="nx">@base</span><span class="p">,</span> <span class="nx">copy</span><span class="p">.</span><span class="nx">base</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@base</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span>
+ <span class="k">for</span> <span class="nx">prop</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">copy</span><span class="p">.</span><span class="nx">properties</span>
+ <span class="k">if</span> <span class="nx">prop</span> <span class="k">instanceof</span> <span class="nx">IndexNode</span> <span class="o">and</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">contains</span><span class="p">((</span><span class="nx">n</span><span class="p">)</span> <span class="o">-></span> <span class="nx">n</span> <span class="k">instanceof</span> <span class="nx">CallNode</span><span class="p">)</span>
+ <span class="p">[</span><span class="nx">index</span><span class="p">,</span> <span class="nx">indexVar</span><span class="p">]</span> <span class="o">=</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">index</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span>
+ <span class="k">this</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">IndexNode</span> <span class="nx">index</span>
+ <span class="nx">copy</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">IndexNode</span> <span class="nx">indexVar</span>
+ <span class="p">[</span><span class="k">this</span><span class="p">,</span> <span class="nx">copy</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-41">#</a> </div> <p>Override compile to unwrap the value when possible.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compile</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">o</span><span class="p">.</span><span class="nx">top</span> <span class="o">or</span> <span class="nx">@properties</span><span class="p">.</span><span class="nx">length</span> <span class="k">then</span> <span class="k">super</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="nx">@base</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-42">#</a> </div> <p>We compile a value to JavaScript by compiling and joining each property.
+Things get much more insteresting if the chain of properties has <em>soak</em>
+operators <code>?.</code> interspersed. Then we have to take care not to accidentally
+evaluate a anything twice when building the soak chain.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">only = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'onlyFirst'</span>
+ <span class="nv">op = </span><span class="nx">@tags</span><span class="p">.</span><span class="nx">operation</span>
+ <span class="nv">props = </span><span class="k">if</span> <span class="nx">only</span> <span class="k">then</span> <span class="nx">@properties</span><span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">@properties</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="k">else</span> <span class="nx">@properties</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">chainRoot</span> <span class="o">or=</span> <span class="k">this</span>
+ <span class="k">for</span> <span class="nx">prop</span> <span class="k">in</span> <span class="nx">props</span>
+ <span class="nv">hasSoak = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">soakNode</span>
+ <span class="k">if</span> <span class="nx">hasSoak</span> <span class="o">and</span> <span class="nx">@containsType</span> <span class="nx">CallNode</span>
+ <span class="p">[</span><span class="nx">me</span><span class="p">,</span> <span class="nx">copy</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@cacheIndexes</span> <span class="nx">o</span>
+ <span class="vi">@base.parenthetical = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">@parenthetical</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">props</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">baseline = </span><span class="nx">@base</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="nv">baseline = </span><span class="s2">"(#{baseline})"</span> <span class="k">if</span> <span class="nx">@hasProperties</span><span class="p">()</span> <span class="o">and</span> <span class="p">(</span><span class="nx">@base</span> <span class="k">instanceof</span> <span class="nx">ObjectNode</span> <span class="o">or</span> <span class="nx">@isNumber</span><span class="p">())</span>
+ <span class="nv">complete = </span><span class="vi">@last = </span><span class="nx">baseline</span>
+
+ <span class="k">for</span> <span class="nx">prop</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">props</span>
+ <span class="vi">@source = </span><span class="nx">baseline</span>
+ <span class="k">if</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">soakNode</span>
+ <span class="k">if</span> <span class="nx">@base</span><span class="p">.</span><span class="nx">containsType</span><span class="p">(</span><span class="nx">CallNode</span><span class="p">)</span> <span class="o">and</span> <span class="nx">i</span> <span class="o">is</span> <span class="mi">0</span>
+ <span class="nv">temp = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'ref'</span>
+ <span class="nv">complete = </span><span class="s2">"(#{ baseline = temp } = (#{complete}))"</span>
+ <span class="nv">complete = </span><span class="k">if</span> <span class="nx">i</span> <span class="o">is</span> <span class="mi">0</span>
+ <span class="s2">"(typeof #{complete} === \"undefined\" || #{baseline} === null) ? undefined : "</span>
+ <span class="k">else</span>
+ <span class="s2">"#{complete} == null ? undefined : "</span>
+ <span class="nx">complete</span> <span class="o">+=</span> <span class="p">(</span><span class="nx">baseline</span> <span class="o">+=</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">))</span>
+ <span class="k">else</span>
+ <span class="nv">part = </span><span class="nx">prop</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">hasSoak</span> <span class="o">and</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">containsType</span> <span class="nx">CallNode</span>
+ <span class="nx">baseline</span> <span class="o">+=</span> <span class="nx">copy</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="k">else</span>
+ <span class="nx">baseline</span> <span class="o">+=</span> <span class="nx">part</span>
+ <span class="nx">complete</span> <span class="o">+=</span> <span class="nx">part</span>
+ <span class="vi">@last = </span><span class="nx">part</span>
+
+ <span class="k">if</span> <span class="nx">op</span> <span class="o">and</span> <span class="nx">@wrapped</span> <span class="k">then</span> <span class="s2">"(#{complete})"</span> <span class="k">else</span> <span class="nx">complete</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-43">#</a> </div> <h3>CommentNode</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-44">#</a> </div> <p>CoffeeScript passes through block comments as JavaScript block comments
+at the same position.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.CommentNode = </span><span class="nx">class</span> <span class="nx">CommentNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'CommentNode'</span>
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@comment</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">this</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@tab</span> <span class="o">+</span> <span class="s1">'/*'</span> <span class="o">+</span> <span class="nx">@comment</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\r?\n/g</span><span class="p">,</span> <span class="s1">'\n'</span> <span class="o">+</span> <span class="nx">@tab</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'*/'</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-45">#</a> </div> <h3>CallNode</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-46"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-46">#</a> </div> <p>Node for a function invocation. Takes care of converting <code>super()</code> calls into
+calls against the prototype's function of the same name.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.CallNode = </span><span class="nx">class</span> <span class="nx">CallNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'CallNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'variable'</span><span class="p">,</span> <span class="s1">'args'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">variable</span><span class="p">,</span> <span class="nx">@args</span><span class="p">,</span> <span class="nx">@exist</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="vi">@isNew = </span><span class="kc">false</span>
+ <span class="vi">@isSuper = </span><span class="nx">variable</span> <span class="o">is</span> <span class="s1">'super'</span>
+ <span class="vi">@variable = </span><span class="k">if</span> <span class="nx">@isSuper</span> <span class="k">then</span> <span class="kc">null</span> <span class="k">else</span> <span class="nx">variable</span>
+ <span class="nx">@args</span> <span class="o">or=</span> <span class="p">[]</span>
+ <span class="vi">@first = @last = </span><span class="s1">''</span>
+ <span class="vi">@compileSplatArguments = </span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">SplatNode</span><span class="p">.</span><span class="nx">compileSplattedArray</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">@args</span><span class="p">,</span> <span class="nx">o</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-47">#</a> </div> <p>Tag this invocation as creating a new instance.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">newInstance</span><span class="o">:</span> <span class="o">-></span>
+ <span class="vi">@isNew = </span><span class="kc">true</span>
+ <span class="k">this</span>
+
+ <span class="nx">prefix</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@isNew</span> <span class="k">then</span> <span class="s1">'new '</span> <span class="k">else</span> <span class="s1">''</span></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-48">#</a> </div> <p>Grab the reference to the superclass' implementation of the current method.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">superReference</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">"cannot call super outside of a function"</span> <span class="nx">unless</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">method</span>
+ <span class="nv">methname = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">method</span><span class="p">.</span><span class="nx">name</span>
+ <span class="nv">meth = </span><span class="k">if</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">method</span><span class="p">.</span><span class="nx">proto</span>
+ <span class="s2">"#{o.scope.method.proto}.__super__.#{methname}"</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">methname</span>
+ <span class="s2">"#{methname}.__super__.constructor"</span>
+ <span class="k">else</span> <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">"cannot call super on an anonymous function."</span></pre></div> </td> </tr> <tr id="section-49"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-49">#</a> </div> <p>Compile a vanilla function call.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">o.chainRoot = </span><span class="k">this</span> <span class="nx">unless</span> <span class="nx">o</span><span class="p">.</span><span class="nx">chainRoot</span>
+ <span class="nv">op = </span><span class="nx">@tags</span><span class="p">.</span><span class="nx">operation</span>
+ <span class="k">if</span> <span class="nx">@exist</span>
+ <span class="k">if</span> <span class="nx">@variable</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span> <span class="o">and</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">@variable</span><span class="p">.</span><span class="nx">properties</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="k">instanceof</span> <span class="nx">AccessorNode</span>
+ <span class="nv">methodAccessor = </span><span class="nx">@variable</span><span class="p">.</span><span class="nx">properties</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
+ <span class="p">[</span><span class="nx">first</span><span class="p">,</span> <span class="nx">meth</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span>
+ <span class="vi">@first = </span><span class="k">new</span> <span class="nx">ValueNode</span><span class="p">(</span><span class="nx">first</span><span class="p">,</span> <span class="p">[</span><span class="nx">methodAccessor</span><span class="p">]).</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="vi">@meth = </span><span class="k">new</span> <span class="nx">ValueNode</span><span class="p">(</span><span class="nx">meth</span><span class="p">,</span> <span class="p">[</span><span class="nx">methodAccessor</span><span class="p">]).</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="k">else</span>
+ <span class="p">[</span><span class="nx">@first</span><span class="p">,</span> <span class="nx">@meth</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">precompile</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="vi">@first = </span><span class="s2">"(typeof #{@first} === \"function\" ? "</span>
+ <span class="vi">@last = </span><span class="s2">" : undefined)"</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">@variable</span>
+ <span class="vi">@meth = </span><span class="nx">@variable</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">@args</span> <span class="k">when</span> <span class="nx">arg</span> <span class="k">instanceof</span> <span class="nx">SplatNode</span>
+ <span class="nv">code = </span><span class="nx">@compileSplat</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="nx">code</span>
+ <span class="nv">args = </span><span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">@args</span>
+ <span class="nv">arg.parenthetical = </span><span class="kc">true</span>
+ <span class="nx">arg</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="nv">code = </span><span class="k">if</span> <span class="nx">@isSuper</span>
+ <span class="nx">@compileSuper</span><span class="p">(</span><span class="nx">args</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">', '</span><span class="p">),</span> <span class="nx">o</span><span class="p">)</span>
+ <span class="k">else</span>
+ <span class="s2">"#{@first}#{@prefix()}#{@meth}(#{ args.join(', ') })#{@last}"</span>
+ <span class="k">if</span> <span class="nx">op</span> <span class="o">and</span> <span class="nx">@variable</span> <span class="o">and</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">wrapped</span> <span class="k">then</span> <span class="s2">"(#{code})"</span> <span class="k">else</span> <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-50">#</a> </div> <p><code>super()</code> is converted into a call against the superclass's implementation
+of the current function.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileSuper</span><span class="o">:</span> <span class="p">(</span><span class="nx">args</span><span class="p">,</span> <span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="s2">"#{@superReference(o)}.call(this#{ if args.length then ', ' else '' }#{args})"</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-51">#</a> </div> <p>If you call a function with a splat, it's converted into a JavaScript
+<code>.apply()</code> call to allow an array of arguments to be passed.
+If it's a constructor, then things get real tricky. We have to inject an
+inner constructor in order to be able to pass the varargs.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileSplat</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">meth = </span><span class="nx">@meth</span> <span class="o">or</span> <span class="nx">@superReference</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">obj = </span><span class="nx">@variable</span> <span class="o">and</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">source</span> <span class="o">or</span> <span class="s1">'this'</span>
+ <span class="k">if</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/\(/</span><span class="p">)</span>
+ <span class="nv">temp = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'ref'</span>
+ <span class="nv">obj = </span><span class="nx">temp</span>
+ <span class="nv">meth = </span><span class="s2">"(#{temp} = #{ @variable.source })#{ @variable.last }"</span>
+ <span class="k">if</span> <span class="nx">@isNew</span>
+ <span class="nv">mentionsArgs = </span><span class="kc">no</span>
+ <span class="k">for</span> <span class="nx">arg</span> <span class="k">in</span> <span class="nx">@args</span>
+ <span class="nx">arg</span><span class="p">.</span><span class="nx">contains</span> <span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="o">-></span> <span class="nx">mentionsArgs</span> <span class="o">or=</span> <span class="nx">n</span> <span class="k">instanceof</span> <span class="nx">LiteralNode</span> <span class="o">and</span> <span class="p">(</span><span class="nx">n</span><span class="p">.</span><span class="nx">value</span> <span class="o">is</span> <span class="s1">'arguments'</span><span class="p">)</span>
+ <span class="nx">utility</span> <span class="s1">'extends'</span>
+ <span class="nv">a = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'ctor'</span>
+ <span class="nv">b = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'ref'</span>
+ <span class="nv">c = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'result'</span>
+ <span class="s2">"""</span>
+
+<span class="s2">#DIVIDER</span>
+<span class="s2"> """</span>
+ <span class="k">else</span>
+ <span class="s2">"#{@first}#{@prefix()}#{meth}.apply(#{obj}, #{ @compileSplatArguments(o) })#{@last}"</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-52">#</a> </div> <p>{@first}(function() {
+{@idt(1)}var ctor = function(){};
+{@idt(1)}__extends(ctor, #{a} = #{meth});
+{@idt(1)}return typeof (#{c} = #{a}.apply(#{b} = new ctor, #{ @compileSplatArguments(o) })) === "object" ? #{c} : #{b};
+{@tab}}).#{ if mentionsArgs then 'apply(this, arguments)' else 'call(this)'}#{@last}</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-53">#</a> </div> <h3>ExtendsNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ExtendsNode = </span><span class="nx">class</span> <span class="nx">ExtendsNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ExtendsNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'child'</span><span class="p">,</span> <span class="s1">'parent'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@child</span><span class="p">,</span> <span class="nx">@parent</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-54"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-54">#</a> </div> <p>Node to extend an object's prototype with an ancestor object.
+After <code>goog.inherits</code> from the
+<a href="http://closure-library.googlecode.com/svn/docs/closureGoogBase.js.html">Closure Library</a>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">ref = </span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">literal</span> <span class="nx">utility</span> <span class="s1">'extends'</span>
+ <span class="p">(</span><span class="k">new</span> <span class="nx">CallNode</span> <span class="nx">ref</span><span class="p">,</span> <span class="p">[</span><span class="nx">@child</span><span class="p">,</span> <span class="nx">@parent</span><span class="p">]).</span><span class="nx">compile</span> <span class="nx">o</span></pre></div> </td> </tr> <tr id="section-55"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-55">#</a> </div> <p>Hooks one constructor into another's prototype chain.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-56"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-56">#</a> </div> <h3>AccessorNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.AccessorNode = </span><span class="nx">class</span> <span class="nx">AccessorNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'AccessorNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'name'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@name</span><span class="p">,</span> <span class="nx">tag</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="vi">@prototype = </span><span class="k">if</span> <span class="nx">tag</span> <span class="o">is</span> <span class="s1">'prototype'</span> <span class="k">then</span> <span class="s1">'.prototype'</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="vi">@soakNode = </span><span class="nx">tag</span> <span class="o">is</span> <span class="s1">'soak'</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">name = </span><span class="nx">@name</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">chainRoot</span><span class="p">.</span><span class="nx">wrapped</span> <span class="o">or=</span> <span class="nx">@soakNode</span>
+ <span class="nv">namePart = </span><span class="k">if</span> <span class="nx">name</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">IS_STRING</span><span class="p">)</span> <span class="k">then</span> <span class="s2">"[#{name}]"</span> <span class="k">else</span> <span class="s2">".#{name}"</span>
+ <span class="nx">@prototype</span> <span class="o">+</span> <span class="nx">namePart</span></pre></div> </td> </tr> <tr id="section-57"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-57">#</a> </div> <p>A <code>.</code> accessor into a property of a value, or the <code>::</code> shorthand for
+an accessor into the object's prototype.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-58"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-58">#</a> </div> <h3>IndexNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.IndexNode = </span><span class="nx">class</span> <span class="nx">IndexNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'IndexNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'index'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@index</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">chainRoot</span><span class="p">.</span><span class="nx">wrapped</span> <span class="o">or=</span> <span class="nx">@soakNode</span>
+ <span class="nv">idx = </span><span class="nx">@index</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="nv">prefix = </span><span class="k">if</span> <span class="nx">@proto</span> <span class="k">then</span> <span class="s1">'.prototype'</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="s2">"#{prefix}[#{idx}]"</span></pre></div> </td> </tr> <tr id="section-59"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-59">#</a> </div> <p>A <code>[ ... ]</code> indexed accessor into an array or object.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-60"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-60">#</a> </div> <h3>RangeNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.RangeNode = </span><span class="nx">class</span> <span class="nx">RangeNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'RangeNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'from'</span><span class="p">,</span> <span class="s1">'to'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@from</span><span class="p">,</span> <span class="nx">@to</span><span class="p">,</span> <span class="nx">tag</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="vi">@exclusive = </span><span class="nx">tag</span> <span class="o">is</span> <span class="s1">'exclusive'</span>
+ <span class="vi">@equals = </span><span class="k">if</span> <span class="nx">@exclusive</span> <span class="k">then</span> <span class="s1">''</span> <span class="k">else</span> <span class="s1">'='</span></pre></div> </td> </tr> <tr id="section-61"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-61">#</a> </div> <p>A range literal. Ranges can be used to extract portions (slices) of arrays,
+to specify a range for comprehensions, or as a value, to be expanded into the
+corresponding array of integers at runtime.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileVariables</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">o = </span><span class="nx">merge</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="nx">top</span><span class="o">:</span> <span class="kc">true</span><span class="p">)</span>
+ <span class="p">[</span><span class="nx">@from</span><span class="p">,</span> <span class="nx">@fromVar</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@from</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">precompile</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="p">[</span><span class="nx">@to</span><span class="p">,</span> <span class="nx">@toVar</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@to</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">precompile</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="p">[</span><span class="nx">@fromNum</span><span class="p">,</span> <span class="nx">@toNum</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">@fromVar</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">SIMPLENUM</span><span class="p">),</span> <span class="nx">@toVar</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">SIMPLENUM</span><span class="p">)]</span>
+ <span class="nv">parts = </span><span class="p">[]</span>
+ <span class="nx">parts</span><span class="p">.</span><span class="nx">push</span> <span class="nx">@from</span> <span class="k">if</span> <span class="nx">@from</span> <span class="o">isnt</span> <span class="nx">@fromVar</span>
+ <span class="nx">parts</span><span class="p">.</span><span class="nx">push</span> <span class="nx">@to</span> <span class="k">if</span> <span class="nx">@to</span> <span class="o">isnt</span> <span class="nx">@toVar</span>
+ <span class="k">if</span> <span class="nx">parts</span><span class="p">.</span><span class="nx">length</span> <span class="k">then</span> <span class="s2">"#{parts.join('; ')}; "</span> <span class="k">else</span> <span class="s1">''</span></pre></div> </td> </tr> <tr id="section-62"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-62">#</a> </div> <p>Compiles the range's source variables -- where it starts and where it ends.
+But only if they need to be cached to avoid double evaluation.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">@compileArray</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="nx">unless</span> <span class="nx">o</span><span class="p">.</span><span class="nx">index</span>
+ <span class="k">return</span> <span class="nx">@compileSimple</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@fromNum</span> <span class="o">and</span> <span class="nx">@toNum</span>
+ <span class="nv">idx = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'index'</span>
+ <span class="nv">step = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'step'</span>
+ <span class="nv">vars = </span><span class="s2">"#{idx} = #{@fromVar}"</span>
+ <span class="nv">intro = </span><span class="s2">"(#{@fromVar} <= #{@toVar} ? #{idx}"</span>
+ <span class="nv">compare = </span><span class="s2">"#{intro} <#{@equals} #{@toVar} : #{idx} >#{@equals} #{@toVar})"</span>
+ <span class="nv">stepPart = </span><span class="k">if</span> <span class="nx">step</span> <span class="k">then</span> <span class="nx">step</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="s1">'1'</span>
+ <span class="nv">incr = </span><span class="k">if</span> <span class="nx">step</span> <span class="k">then</span> <span class="s2">"#{idx} += #{stepPart}"</span> <span class="k">else</span> <span class="s2">"#{intro} += #{stepPart} : #{idx} -= #{stepPart})"</span>
+ <span class="s2">"#{vars}; #{compare}; #{incr}"</span></pre></div> </td> </tr> <tr id="section-63"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-63">#</a> </div> <p>When compiled normally, the range returns the contents of the <em>for loop</em>
+needed to iterate over the values in the range. Used by comprehensions.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileSimple</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">[</span><span class="nx">from</span><span class="p">,</span> <span class="nx">to</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">parseInt</span><span class="p">(</span><span class="nx">@fromNum</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">@toNum</span><span class="p">,</span> <span class="mi">10</span><span class="p">)]</span>
+ <span class="nv">idx = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'index'</span>
+ <span class="nv">step = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'step'</span>
+ <span class="nx">step</span> <span class="o">and=</span> <span class="s2">"#{idx} += #{step.compile(o)}"</span>
+ <span class="k">if</span> <span class="nx">from</span> <span class="o"><=</span> <span class="nx">to</span>
+ <span class="s2">"#{idx} = #{from}; #{idx} <#{@equals} #{to}; #{step or "</span><span class="c1">#{idx}++"}"</span>
+ <span class="k">else</span>
+ <span class="s2">"#{idx} = #{from}; #{idx} >#{@equals} #{to}; #{step or "</span><span class="c1">#{idx}--"}"</span></pre></div> </td> </tr> <tr id="section-64"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-64">#</a> </div> <p>Compile a simple range comprehension, with integers.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileArray</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">idt = </span><span class="nx">@idt</span> <span class="mi">1</span>
+ <span class="nv">vars = </span><span class="nx">@compileVariables</span> <span class="nx">merge</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">indent</span><span class="o">:</span> <span class="nx">idt</span>
+ <span class="k">if</span> <span class="nx">@fromNum</span> <span class="o">and</span> <span class="nx">@toNum</span> <span class="o">and</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">abs</span><span class="p">(</span><span class="o">+</span><span class="nx">@fromNum</span> <span class="o">-</span> <span class="o">+</span><span class="nx">@toNum</span><span class="p">)</span> <span class="o"><=</span> <span class="mi">20</span>
+ <span class="nv">range = </span><span class="p">[</span><span class="o">+</span><span class="nx">@fromNum</span><span class="p">..</span><span class="o">+</span><span class="nx">@toNum</span><span class="p">]</span>
+ <span class="nx">range</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span> <span class="k">if</span> <span class="nx">@exclusive</span>
+ <span class="k">return</span> <span class="s2">"[#{ range.join(', ') }]"</span>
+ <span class="nv">i = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'i'</span>
+ <span class="nv">result = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'result'</span>
+ <span class="nv">pre = </span><span class="s2">"\n#{idt}#{result} = []; #{vars}"</span>
+ <span class="k">if</span> <span class="nx">@fromNum</span> <span class="o">and</span> <span class="nx">@toNum</span>
+ <span class="nv">o.index = </span><span class="nx">i</span>
+ <span class="nv">body = </span><span class="nx">@compileSimple</span> <span class="nx">o</span>
+ <span class="k">else</span>
+ <span class="nv">clause = </span><span class="s2">"#{@fromVar} <= #{@toVar} ?"</span>
+ <span class="nv">body = </span><span class="s2">"var #{i} = #{@fromVar}; #{clause} #{i} <#{@equals} #{@toVar} : #{i} >#{@equals} #{@toVar}; #{clause} #{i} += 1 : #{i} -= 1"</span>
+ <span class="nv">post = </span><span class="s2">"{ #{result}.push(#{i}); }\n#{idt}return #{result};\n#{o.indent}"</span>
+ <span class="s2">"(function() {#{pre}\n#{idt}for (#{body})#{post}}).call(this)"</span></pre></div> </td> </tr> <tr id="section-65"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-65">#</a> </div> <p>When used as a value, expand the range into the equivalent array.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-66"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-66">#</a> </div> <h3>SliceNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.SliceNode = </span><span class="nx">class</span> <span class="nx">SliceNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'SliceNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'range'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@range</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">from = </span> <span class="k">if</span> <span class="nx">@range</span><span class="p">.</span><span class="nx">from</span> <span class="k">then</span> <span class="nx">@range</span><span class="p">.</span><span class="nx">from</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="s1">'0'</span>
+ <span class="nv">to = </span> <span class="k">if</span> <span class="nx">@range</span><span class="p">.</span><span class="nx">to</span> <span class="k">then</span> <span class="nx">@range</span><span class="p">.</span><span class="nx">to</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nx">to</span> <span class="o">+=</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">to</span> <span class="o">or</span> <span class="nx">@range</span><span class="p">.</span><span class="nx">exclusive</span> <span class="k">then</span> <span class="s1">''</span> <span class="k">else</span> <span class="s1">' + 1'</span>
+ <span class="nv">to = </span> <span class="s1">', '</span> <span class="o">+</span> <span class="nx">to</span> <span class="k">if</span> <span class="nx">to</span>
+ <span class="s2">".slice(#{from}#{to})"</span></pre></div> </td> </tr> <tr id="section-67"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-67">#</a> </div> <p>An array slice literal. Unlike JavaScript's <code>Array#slice</code>, the second parameter
+specifies the index of the end of the slice, just as the first parameter
+is the index of the beginning.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-68"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-68">#</a> </div> <h3>ObjectNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ObjectNode = </span><span class="nx">class</span> <span class="nx">ObjectNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ObjectNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'properties'</span><span class="p">]</span>
+
+ <span class="nx">topSensitive</span><span class="o">:</span> <span class="o">-></span> <span class="kc">true</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">props</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="vi">@objects = @properties = </span><span class="nx">props</span> <span class="o">or</span> <span class="p">[]</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">top = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'top'</span>
+ <span class="nv">o.indent = </span><span class="nx">@idt</span> <span class="mi">1</span>
+ <span class="nv">nonComments = </span><span class="nx">prop</span> <span class="k">for</span> <span class="nx">prop</span> <span class="k">in</span> <span class="nx">@properties</span> <span class="k">when</span> <span class="p">(</span><span class="nx">prop</span> <span class="o">not</span> <span class="k">instanceof</span> <span class="nx">CommentNode</span><span class="p">)</span>
+ <span class="nv">lastNoncom = </span> <span class="nx">nonComments</span><span class="p">[</span><span class="nx">nonComments</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="nv">props = </span><span class="k">for</span> <span class="nx">prop</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">@properties</span>
+ <span class="nv">join = </span><span class="s2">",\n"</span>
+ <span class="nv">join = </span><span class="s2">"\n"</span> <span class="k">if</span> <span class="p">(</span><span class="nx">prop</span> <span class="o">is</span> <span class="nx">lastNoncom</span><span class="p">)</span> <span class="o">or</span> <span class="p">(</span><span class="nx">prop</span> <span class="k">instanceof</span> <span class="nx">CommentNode</span><span class="p">)</span>
+ <span class="nv">join = </span><span class="s1">''</span> <span class="k">if</span> <span class="nx">i</span> <span class="o">is</span> <span class="nx">@properties</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="nv">indent = </span><span class="k">if</span> <span class="nx">prop</span> <span class="k">instanceof</span> <span class="nx">CommentNode</span> <span class="k">then</span> <span class="s1">''</span> <span class="k">else</span> <span class="nx">@idt</span> <span class="mi">1</span>
+ <span class="nv">prop = </span><span class="k">new</span> <span class="nx">AssignNode</span> <span class="nx">prop</span><span class="p">,</span> <span class="nx">prop</span><span class="p">,</span> <span class="s1">'object'</span> <span class="nx">unless</span> <span class="nx">prop</span> <span class="k">instanceof</span> <span class="nx">AssignNode</span> <span class="o">or</span> <span class="nx">prop</span> <span class="k">instanceof</span> <span class="nx">CommentNode</span>
+ <span class="nx">indent</span> <span class="o">+</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">+</span> <span class="nx">join</span>
+ <span class="nv">props = </span><span class="nx">props</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">''</span><span class="p">)</span>
+ <span class="nv">obj = </span><span class="s1">'{'</span> <span class="o">+</span> <span class="p">(</span><span class="k">if</span> <span class="nx">props</span> <span class="k">then</span> <span class="s1">'\n'</span> <span class="o">+</span> <span class="nx">props</span> <span class="o">+</span> <span class="s1">'\n'</span> <span class="o">+</span> <span class="nx">@idt</span><span class="p">()</span> <span class="k">else</span> <span class="s1">''</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'}'</span>
+ <span class="k">if</span> <span class="nx">top</span> <span class="k">then</span> <span class="s2">"(#{obj})"</span> <span class="k">else</span> <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-69"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-69">#</a> </div> <p>An object literal, nothing fancy.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-70"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-70">#</a> </div> <h3>ArrayNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ArrayNode = </span><span class="nx">class</span> <span class="nx">ArrayNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ArrayNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'objects'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@objects</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="nx">@objects</span> <span class="o">or=</span> <span class="p">[]</span>
+ <span class="vi">@compileSplatLiteral = </span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">SplatNode</span><span class="p">.</span><span class="nx">compileSplattedArray</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">@objects</span><span class="p">,</span> <span class="nx">o</span><span class="p">)</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">o.indent = </span><span class="nx">@idt</span> <span class="mi">1</span>
+ <span class="nv">objects = </span><span class="p">[]</span>
+ <span class="k">for</span> <span class="nx">obj</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">@objects</span>
+ <span class="nv">code = </span><span class="nx">obj</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">obj</span> <span class="k">instanceof</span> <span class="nx">SplatNode</span>
+ <span class="k">return</span> <span class="nx">@compileSplatLiteral</span> <span class="nx">o</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">obj</span> <span class="k">instanceof</span> <span class="nx">CommentNode</span>
+ <span class="nx">objects</span><span class="p">.</span><span class="nx">push</span> <span class="s2">"\n#{code}\n#{o.indent}"</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">i</span> <span class="o">is</span> <span class="nx">@objects</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="nx">objects</span><span class="p">.</span><span class="nx">push</span> <span class="nx">code</span>
+ <span class="k">else</span>
+ <span class="nx">objects</span><span class="p">.</span><span class="nx">push</span> <span class="s2">"#{code}, "</span>
+ <span class="nv">objects = </span><span class="nx">objects</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">''</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">indexOf</span><span class="p">(</span><span class="nx">objects</span><span class="p">,</span> <span class="s1">'\n'</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span>
+ <span class="s2">"[\n#{@idt(1)}#{objects}\n#{@tab}]"</span>
+ <span class="k">else</span>
+ <span class="s2">"[#{objects}]"</span></pre></div> </td> </tr> <tr id="section-71"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-71">#</a> </div> <p>An array literal.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-72"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-72">#</a> </div> <h3>ClassNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ClassNode = </span><span class="nx">class</span> <span class="nx">ClassNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ClassNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'variable'</span><span class="p">,</span> <span class="s1">'parent'</span><span class="p">,</span> <span class="s1">'properties'</span><span class="p">]</span>
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span></pre></div> </td> </tr> <tr id="section-73"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-73">#</a> </div> <p>The CoffeeScript class definition.</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">@variable</span><span class="p">,</span> <span class="nx">@parent</span><span class="p">,</span> <span class="nx">@properties</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="nx">@properties</span> <span class="o">or=</span> <span class="p">[]</span>
+ <span class="vi">@returns = </span><span class="kc">false</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="vi">@returns = </span><span class="kc">true</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-74"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-74">#</a> </div> <p>Initialize a <strong>ClassNode</strong> with its name, an optional superclass, and a
+list of prototype property assignments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="vi">@variable = </span><span class="nx">literal</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'ctor'</span> <span class="k">if</span> <span class="nx">@variable</span> <span class="o">is</span> <span class="s1">'__temp__'</span>
+ <span class="nv">extension = </span><span class="nx">@parent</span> <span class="o">and</span> <span class="k">new</span> <span class="nx">ExtendsNode</span><span class="p">(</span><span class="nx">@variable</span><span class="p">,</span> <span class="nx">@parent</span><span class="p">)</span>
+ <span class="nv">props = </span><span class="k">new</span> <span class="nx">Expressions</span>
+ <span class="nv">o.top = </span><span class="kc">true</span>
+ <span class="nv">me = </span><span class="kc">null</span>
+ <span class="nv">className = </span><span class="nx">@variable</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="nv">constScope = </span><span class="kc">null</span>
+
+ <span class="k">if</span> <span class="nx">@parent</span>
+ <span class="nv">applied = </span><span class="k">new</span> <span class="nx">ValueNode</span><span class="p">(</span><span class="nx">@parent</span><span class="p">,</span> <span class="p">[</span><span class="k">new</span> <span class="nx">AccessorNode</span><span class="p">(</span><span class="nx">literal</span><span class="p">(</span><span class="s1">'apply'</span><span class="p">))])</span>
+ <span class="nv">constructor = </span><span class="k">new</span> <span class="nx">CodeNode</span><span class="p">([],</span> <span class="k">new</span> <span class="nx">Expressions</span><span class="p">([</span>
+ <span class="k">new</span> <span class="nx">CallNode</span><span class="p">(</span><span class="nx">applied</span><span class="p">,</span> <span class="p">[</span><span class="nx">literal</span><span class="p">(</span><span class="s1">'this'</span><span class="p">),</span> <span class="nx">literal</span><span class="p">(</span><span class="s1">'arguments'</span><span class="p">)])</span>
+ <span class="p">]))</span>
+ <span class="k">else</span>
+ <span class="nv">constructor = </span><span class="k">new</span> <span class="nx">CodeNode</span>
+
+ <span class="k">for</span> <span class="nx">prop</span> <span class="k">in</span> <span class="nx">@properties</span>
+ <span class="p">[</span><span class="nx">pvar</span><span class="p">,</span> <span class="nx">func</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">prop</span><span class="p">.</span><span class="nx">variable</span><span class="p">,</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">value</span><span class="p">]</span>
+ <span class="k">if</span> <span class="nx">pvar</span> <span class="o">and</span> <span class="nx">pvar</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">value</span> <span class="o">is</span> <span class="s1">'constructor'</span> <span class="o">and</span> <span class="nx">func</span> <span class="k">instanceof</span> <span class="nx">CodeNode</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">"cannot define a constructor as a bound function."</span> <span class="k">if</span> <span class="nx">func</span><span class="p">.</span><span class="nx">bound</span>
+ <span class="nv">func.name = </span><span class="nx">className</span>
+ <span class="nx">func</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">push</span> <span class="k">new</span> <span class="nx">ReturnNode</span> <span class="nx">literal</span> <span class="s1">'this'</span>
+ <span class="vi">@variable = </span><span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">@variable</span>
+ <span class="vi">@variable.namespaced = </span><span class="nx">include</span> <span class="nx">func</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="s1">'.'</span>
+ <span class="nv">constructor = </span><span class="nx">func</span>
+ <span class="k">continue</span>
+ <span class="k">if</span> <span class="nx">func</span> <span class="k">instanceof</span> <span class="nx">CodeNode</span> <span class="o">and</span> <span class="nx">func</span><span class="p">.</span><span class="nx">bound</span>
+ <span class="k">if</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">context</span> <span class="o">is</span> <span class="s1">'this'</span>
+ <span class="nv">func.context = </span><span class="nx">className</span>
+ <span class="k">else</span>
+ <span class="nv">func.bound = </span><span class="kc">false</span>
+ <span class="nx">constScope</span> <span class="o">or=</span> <span class="k">new</span> <span class="nx">Scope</span><span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">,</span> <span class="nx">constructor</span><span class="p">.</span><span class="nx">body</span><span class="p">,</span> <span class="nx">constructor</span><span class="p">)</span>
+ <span class="nx">me</span> <span class="o">or=</span> <span class="nx">constScope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'this'</span>
+ <span class="nv">pname = </span><span class="nx">pvar</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nx">constructor</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">push</span> <span class="k">new</span> <span class="nx">ReturnNode</span> <span class="nx">literal</span> <span class="s1">'this'</span> <span class="k">if</span> <span class="nx">constructor</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">empty</span><span class="p">()</span>
+ <span class="nx">constructor</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">unshift</span> <span class="nx">literal</span> <span class="s2">"this.#{pname} = function(){ return #{className}.prototype.#{pname}.apply(#{me}, arguments); }"</span>
+ <span class="k">if</span> <span class="nx">pvar</span>
+ <span class="nv">access = </span><span class="k">if</span> <span class="nx">prop</span><span class="p">.</span><span class="nx">context</span> <span class="o">is</span> <span class="s1">'this'</span> <span class="k">then</span> <span class="nx">pvar</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">else</span> <span class="k">new</span> <span class="nx">AccessorNode</span><span class="p">(</span><span class="nx">pvar</span><span class="p">,</span> <span class="s1">'prototype'</span><span class="p">)</span>
+ <span class="nv">val = </span><span class="k">new</span> <span class="nx">ValueNode</span><span class="p">(</span><span class="nx">@variable</span><span class="p">,</span> <span class="p">[</span><span class="nx">access</span><span class="p">])</span>
+ <span class="nv">prop = </span><span class="k">new</span> <span class="nx">AssignNode</span><span class="p">(</span><span class="nx">val</span><span class="p">,</span> <span class="nx">func</span><span class="p">)</span>
+ <span class="nx">props</span><span class="p">.</span><span class="nx">push</span> <span class="nx">prop</span>
+
+ <span class="nx">constructor</span><span class="p">.</span><span class="nx">body</span><span class="p">.</span><span class="nx">unshift</span> <span class="nx">literal</span> <span class="s2">"#{me} = this"</span> <span class="k">if</span> <span class="nx">me</span>
+ <span class="nv">construct = </span><span class="nx">@idt</span><span class="p">()</span> <span class="o">+</span> <span class="p">(</span><span class="k">new</span> <span class="nx">AssignNode</span><span class="p">(</span><span class="nx">@variable</span><span class="p">,</span> <span class="nx">constructor</span><span class="p">)).</span><span class="nx">compile</span><span class="p">(</span><span class="nx">merge</span> <span class="nx">o</span><span class="p">,</span> <span class="p">{</span><span class="nx">sharedScope</span><span class="o">:</span> <span class="nx">constScope</span><span class="p">})</span> <span class="o">+</span> <span class="s1">';'</span>
+ <span class="nv">props = </span><span class="k">if</span> <span class="o">!</span><span class="nx">props</span><span class="p">.</span><span class="nx">empty</span><span class="p">()</span> <span class="k">then</span> <span class="s1">'\n'</span> <span class="o">+</span> <span class="nx">props</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nv">extension = </span><span class="k">if</span> <span class="nx">extension</span> <span class="k">then</span> <span class="s1">'\n'</span> <span class="o">+</span> <span class="nx">@idt</span><span class="p">()</span> <span class="o">+</span> <span class="nx">extension</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">+</span> <span class="s1">';'</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nv">returns = </span><span class="k">if</span> <span class="nx">@returns</span> <span class="k">then</span> <span class="s1">'\n'</span> <span class="o">+</span> <span class="k">new</span> <span class="nx">ReturnNode</span><span class="p">(</span><span class="nx">@variable</span><span class="p">).</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nx">construct</span> <span class="o">+</span> <span class="nx">extension</span> <span class="o">+</span> <span class="nx">props</span> <span class="o">+</span> <span class="nx">returns</span></pre></div> </td> </tr> <tr id="section-75"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-75">#</a> </div> <p>Instead of generating the JavaScript string directly, we build up the
+equivalent syntax tree and compile that, in pieces. You can see the
+constructor, property assignments, and inheritance getting built out below.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-76"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-76">#</a> </div> <h3>AssignNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.AssignNode = </span><span class="nx">class</span> <span class="nx">AssignNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span></pre></div> </td> </tr> <tr id="section-77"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-77">#</a> </div> <p>The <strong>AssignNode</strong> is used to assign a local variable to value, or to set the
+property of an object -- including within object literals.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">PROTO_ASSIGN</span><span class="o">:</span> <span class="sr">/^(\S+)\.prototype/</span>
+ <span class="nx">LEADING_DOT</span><span class="o">:</span> <span class="sr">/^\.(prototype\.)?/</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'AssignNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'variable'</span><span class="p">,</span> <span class="s1">'value'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@variable</span><span class="p">,</span> <span class="nx">@value</span><span class="p">,</span> <span class="nx">@context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">topSensitive</span><span class="o">:</span> <span class="o">-></span>
+ <span class="kc">true</span>
+
+ <span class="nx">isValue</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@variable</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@isStatement</span><span class="p">()</span>
+ <span class="k">return</span> <span class="k">new</span> <span class="nx">Expressions</span> <span class="p">[</span><span class="k">this</span><span class="p">,</span> <span class="k">new</span> <span class="nx">ReturnNode</span><span class="p">(</span><span class="nx">@variable</span><span class="p">)]</span>
+ <span class="k">else</span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@isValue</span><span class="p">()</span> <span class="o">and</span> <span class="p">(</span><span class="nx">@variable</span><span class="p">.</span><span class="nx">isArray</span><span class="p">()</span> <span class="o">or</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">isObject</span><span class="p">())</span></pre></div> </td> </tr> <tr id="section-78"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-78">#</a> </div> <p>Matchers for detecting prototype assignments.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">top = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'top'</span>
+ <span class="k">return</span> <span class="nx">@compilePatternMatch</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="k">return</span> <span class="nx">@compileSplice</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@isValue</span><span class="p">()</span> <span class="o">and</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">isSplice</span><span class="p">()</span>
+ <span class="nv">stmt = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'asStatement'</span>
+ <span class="nv">name = </span><span class="nx">@variable</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">last = </span><span class="k">if</span> <span class="nx">@isValue</span><span class="p">()</span> <span class="k">then</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">last</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">@LEADING_DOT</span><span class="p">,</span> <span class="s1">''</span><span class="p">)</span> <span class="k">else</span> <span class="nx">name</span>
+ <span class="nv">match = </span><span class="nx">name</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">@PROTO_ASSIGN</span><span class="p">)</span>
+ <span class="nv">proto = </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="k">if</span> <span class="nx">@value</span> <span class="k">instanceof</span> <span class="nx">CodeNode</span>
+ <span class="vi">@value.name = </span> <span class="nx">last</span> <span class="k">if</span> <span class="nx">last</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">IDENTIFIER</span><span class="p">)</span>
+ <span class="vi">@value.proto = </span><span class="nx">proto</span> <span class="k">if</span> <span class="nx">proto</span>
+ <span class="nv">val = </span><span class="nx">@value</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="k">return</span> <span class="s2">"#{name}: #{val}"</span> <span class="k">if</span> <span class="nx">@context</span> <span class="o">is</span> <span class="s1">'object'</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">find</span> <span class="nx">name</span> <span class="nx">unless</span> <span class="nx">@isValue</span><span class="p">()</span> <span class="o">and</span> <span class="p">(</span><span class="nx">@variable</span><span class="p">.</span><span class="nx">hasProperties</span><span class="p">()</span> <span class="o">or</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">namespaced</span><span class="p">)</span>
+ <span class="nv">val = </span><span class="s2">"#{name} = #{val}"</span>
+ <span class="k">return</span> <span class="s2">"#{@tab}#{val};"</span> <span class="k">if</span> <span class="nx">stmt</span>
+ <span class="k">if</span> <span class="nx">top</span> <span class="o">or</span> <span class="nx">@parenthetical</span> <span class="k">then</span> <span class="nx">val</span> <span class="k">else</span> <span class="s2">"(#{val})"</span></pre></div> </td> </tr> <tr id="section-79"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-79">#</a> </div> <p>Compile an assignment, delegating to <code>compilePatternMatch</code> or
+<code>compileSplice</code> if appropriate. Keep track of the name of the base object
+we've been assigned to, for correct internal references. If the variable
+has not been seen yet within the current scope, declare it.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compilePatternMatch</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">valVar = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'ref'</span>
+ <span class="nv">value = </span><span class="k">if</span> <span class="nx">@value</span><span class="p">.</span><span class="nx">isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">then</span> <span class="nx">ClosureNode</span><span class="p">.</span><span class="nx">wrap</span><span class="p">(</span><span class="nx">@value</span><span class="p">)</span> <span class="k">else</span> <span class="nx">@value</span>
+ <span class="nv">assigns = </span><span class="p">[</span><span class="s2">"#{@tab}#{valVar} = #{ value.compile(o) };"</span><span class="p">]</span>
+ <span class="nv">o.top = </span><span class="kc">true</span>
+ <span class="nv">o.asStatement = </span><span class="kc">true</span>
+ <span class="nv">splat = </span><span class="kc">false</span>
+ <span class="k">for</span> <span class="nx">obj</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">objects</span></pre></div> </td> </tr> <tr id="section-80"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-80">#</a> </div> <p>Brief implementation of recursive pattern matching, when assigning array or
+object literals to a value. Peeks at their properties to assign inner names.
+See the <a href="http://wiki.ecmascript.org/doku.php?id=harmony:destructuring">ECMAScript Harmony Wiki</a>
+for details.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">idx = </span><span class="nx">i</span>
+ <span class="k">if</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">isObject</span><span class="p">()</span>
+ <span class="k">if</span> <span class="nx">obj</span> <span class="k">instanceof</span> <span class="nx">AssignNode</span></pre></div> </td> </tr> <tr id="section-81"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-81">#</a> </div> <p>A regular array pattern-match.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">[</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">idx</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">obj</span><span class="p">.</span><span class="nx">value</span><span class="p">,</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">variable</span><span class="p">.</span><span class="nx">base</span><span class="p">]</span>
+ <span class="k">else</span></pre></div> </td> </tr> <tr id="section-82"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-82">#</a> </div> <p>A regular object pattern-match.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">idx = </span><span class="nx">obj</span>
+ <span class="k">if</span> <span class="o">not</span> <span class="p">(</span><span class="nx">obj</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span> <span class="o">or</span> <span class="nx">obj</span> <span class="k">instanceof</span> <span class="nx">SplatNode</span><span class="p">)</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s1">'pattern matching must use only identifiers on the left-hand side.'</span>
+ <span class="nv">isString = </span><span class="nx">idx</span><span class="p">.</span><span class="nx">value</span> <span class="o">and</span> <span class="nx">idx</span><span class="p">.</span><span class="nx">value</span><span class="p">.</span><span class="nx">match</span> <span class="nx">IS_STRING</span>
+ <span class="nv">accessClass = </span><span class="k">if</span> <span class="nx">isString</span> <span class="o">or</span> <span class="nx">@variable</span><span class="p">.</span><span class="nx">isArray</span><span class="p">()</span> <span class="k">then</span> <span class="nx">IndexNode</span> <span class="k">else</span> <span class="nx">AccessorNode</span>
+ <span class="k">if</span> <span class="nx">obj</span> <span class="k">instanceof</span> <span class="nx">SplatNode</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">splat</span>
+ <span class="nv">val = </span><span class="nx">literal</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">compileValue</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">valVar</span><span class="p">,</span>
+ <span class="p">(</span><span class="nv">oindex = </span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">@variable</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">objects</span><span class="p">,</span> <span class="nx">obj</span><span class="p">)),</span>
+ <span class="p">(</span><span class="nv">olength = </span><span class="nx">@variable</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">objects</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="o">-</span> <span class="nx">oindex</span> <span class="o">-</span> <span class="mi">1</span>
+ <span class="nv">splat = </span><span class="kc">true</span>
+ <span class="k">else</span>
+ <span class="nv">idx = </span><span class="nx">literal</span><span class="p">(</span><span class="k">if</span> <span class="nx">splat</span> <span class="k">then</span> <span class="s2">"#{valVar}.length - #{olength - idx}"</span> <span class="k">else</span> <span class="nx">idx</span><span class="p">)</span> <span class="k">if</span> <span class="k">typeof</span> <span class="nx">idx</span> <span class="o">isnt</span> <span class="s1">'object'</span>
+ <span class="nv">val = </span><span class="k">new</span> <span class="nx">ValueNode</span><span class="p">(</span><span class="nx">literal</span><span class="p">(</span><span class="nx">valVar</span><span class="p">),</span> <span class="p">[</span><span class="k">new</span> <span class="nx">accessClass</span><span class="p">(</span><span class="nx">idx</span><span class="p">)])</span>
+ <span class="nx">assigns</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="k">new</span> <span class="nx">AssignNode</span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">val</span><span class="p">).</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">))</span>
+ <span class="nv">code = </span><span class="nx">assigns</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s2">"\n"</span><span class="p">)</span>
+ <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-83"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-83">#</a> </div> <p>A shorthand <code>{a, b, c} = val</code> pattern-match.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileSplice</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">name = </span><span class="nx">@variable</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">merge</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">onlyFirst</span><span class="o">:</span> <span class="kc">true</span>
+ <span class="nv">l = </span><span class="nx">@variable</span><span class="p">.</span><span class="nx">properties</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">range = </span><span class="nx">@variable</span><span class="p">.</span><span class="nx">properties</span><span class="p">[</span><span class="nx">l</span> <span class="o">-</span> <span class="mi">1</span><span class="p">].</span><span class="nx">range</span>
+ <span class="nv">plus = </span><span class="k">if</span> <span class="nx">range</span><span class="p">.</span><span class="nx">exclusive</span> <span class="k">then</span> <span class="s1">''</span> <span class="k">else</span> <span class="s1">' + 1'</span>
+ <span class="nv">from = </span><span class="k">if</span> <span class="nx">range</span><span class="p">.</span><span class="nx">from</span> <span class="k">then</span> <span class="nx">range</span><span class="p">.</span><span class="nx">from</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="s1">'0'</span>
+ <span class="nv">to = </span><span class="k">if</span> <span class="nx">range</span><span class="p">.</span><span class="nx">to</span> <span class="k">then</span> <span class="nx">range</span><span class="p">.</span><span class="nx">to</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">+</span> <span class="s1">' - '</span> <span class="o">+</span> <span class="nx">from</span> <span class="o">+</span> <span class="nx">plus</span> <span class="k">else</span> <span class="s2">"#{name}.length"</span>
+ <span class="nv">val = </span><span class="nx">@value</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="s2">"#{name}.splice.apply(#{name}, [#{from}, #{to}].concat(#{val}))"</span></pre></div> </td> </tr> <tr id="section-84"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-84">#</a> </div> <p>Compile the assignment from an array splice literal, using JavaScript's
+<code>Array#splice</code> method.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-85"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-85">#</a> </div> <h3>CodeNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.CodeNode = </span><span class="nx">class</span> <span class="nx">CodeNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'CodeNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'params'</span><span class="p">,</span> <span class="s1">'body'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@params</span><span class="p">,</span> <span class="nx">@body</span><span class="p">,</span> <span class="nx">tag</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="nx">@params</span> <span class="o">or=</span> <span class="p">[]</span>
+ <span class="nx">@body</span> <span class="o">or=</span> <span class="k">new</span> <span class="nx">Expressions</span>
+ <span class="vi">@bound = </span><span class="nx">tag</span> <span class="o">is</span> <span class="s1">'boundfunc'</span>
+ <span class="vi">@context = </span><span class="s1">'this'</span> <span class="k">if</span> <span class="nx">@bound</span></pre></div> </td> </tr> <tr id="section-86"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-86">#</a> </div> <p>A function definition. This is the only node that creates a new Scope.
+When for the purposes of walking the contents of a function body, the CodeNode
+has no <em>children</em> -- they're within the inner scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">sharedScope = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'sharedScope'</span>
+ <span class="nv">top = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'top'</span>
+ <span class="nv">o.scope = </span><span class="nx">sharedScope</span> <span class="o">or</span> <span class="k">new</span> <span class="nx">Scope</span><span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">,</span> <span class="nx">@body</span><span class="p">,</span> <span class="k">this</span><span class="p">)</span>
+ <span class="nv">o.top = </span><span class="kc">true</span>
+ <span class="nv">o.indent = </span><span class="nx">@idt</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
+ <span class="nv">empty = </span><span class="nx">@body</span><span class="p">.</span><span class="nx">expressions</span><span class="p">.</span><span class="nx">length</span> <span class="o">is</span> <span class="mi">0</span>
+ <span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'noWrap'</span>
+ <span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'globals'</span>
+ <span class="nv">splat = </span><span class="kc">undefined</span>
+ <span class="nv">params = </span><span class="p">[]</span>
+ <span class="k">for</span> <span class="nx">param</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">@params</span>
+ <span class="k">if</span> <span class="nx">splat</span>
+ <span class="k">if</span> <span class="nx">param</span><span class="p">.</span><span class="nx">attach</span>
+ <span class="nv">param.assign = </span><span class="k">new</span> <span class="nx">AssignNode</span> <span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">literal</span><span class="p">(</span><span class="s1">'this'</span><span class="p">),</span> <span class="p">[</span><span class="k">new</span> <span class="nx">AccessorNode</span> <span class="nx">param</span><span class="p">.</span><span class="nx">value</span><span class="p">]</span>
+ <span class="nx">@body</span><span class="p">.</span><span class="nx">expressions</span><span class="p">.</span><span class="nx">splice</span> <span class="nx">splat</span><span class="p">.</span><span class="nx">index</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">param</span><span class="p">.</span><span class="nx">assign</span>
+ <span class="nx">splat</span><span class="p">.</span><span class="nx">trailings</span><span class="p">.</span><span class="nx">push</span> <span class="nx">param</span>
+ <span class="k">else</span>
+ <span class="k">if</span> <span class="nx">param</span><span class="p">.</span><span class="nx">attach</span>
+ <span class="p">{</span><span class="nx">value</span><span class="p">}</span> <span class="o">=</span> <span class="nx">param</span>
+ <span class="p">[</span><span class="nx">param</span><span class="p">,</span> <span class="nx">param</span><span class="p">.</span><span class="nx">splat</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">literal</span><span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'arg'</span><span class="p">),</span> <span class="nx">param</span><span class="p">.</span><span class="nx">splat</span><span class="p">]</span>
+ <span class="nx">@body</span><span class="p">.</span><span class="nx">unshift</span> <span class="k">new</span> <span class="nx">AssignNode</span> <span class="k">new</span> <span class="nx">ValueNode</span><span class="p">(</span><span class="nx">literal</span><span class="p">(</span><span class="s1">'this'</span><span class="p">),</span> <span class="p">[</span><span class="k">new</span> <span class="nx">AccessorNode</span> <span class="nx">value</span><span class="p">]),</span> <span class="nx">param</span>
+ <span class="k">if</span> <span class="nx">param</span><span class="p">.</span><span class="nx">splat</span>
+ <span class="nv">splat = </span><span class="k">new</span> <span class="nx">SplatNode</span> <span class="nx">param</span><span class="p">.</span><span class="nx">value</span>
+ <span class="nv">splat.index = </span><span class="nx">i</span>
+ <span class="nv">splat.trailings = </span><span class="p">[]</span>
+ <span class="nv">splat.arglength = </span><span class="nx">@params</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nx">@body</span><span class="p">.</span><span class="nx">unshift</span><span class="p">(</span><span class="nx">splat</span><span class="p">)</span>
+ <span class="k">else</span>
+ <span class="nx">params</span><span class="p">.</span><span class="nx">push</span> <span class="nx">param</span>
+ <span class="nv">params = </span><span class="p">(</span><span class="nx">param</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">for</span> <span class="nx">param</span> <span class="k">in</span> <span class="nx">params</span><span class="p">)</span>
+ <span class="nx">@body</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">()</span> <span class="nx">unless</span> <span class="nx">empty</span>
+ <span class="p">(</span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">parameter</span><span class="p">(</span><span class="nx">param</span><span class="p">))</span> <span class="k">for</span> <span class="nx">param</span> <span class="k">in</span> <span class="nx">params</span>
+ <span class="nv">code = </span><span class="k">if</span> <span class="nx">@body</span><span class="p">.</span><span class="nx">expressions</span><span class="p">.</span><span class="nx">length</span> <span class="k">then</span> <span class="s2">"\n#{ @body.compileWithDeclarations(o) }\n"</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nv">func = </span><span class="s2">"function(#{ params.join(', ') }) {#{code}#{ code and @tab }}"</span>
+ <span class="k">return</span> <span class="s2">"#{utility('bind')}(#{func}, #{@context})"</span> <span class="k">if</span> <span class="nx">@bound</span>
+ <span class="k">if</span> <span class="nx">top</span> <span class="k">then</span> <span class="s2">"(#{func})"</span> <span class="k">else</span> <span class="nx">func</span>
+
+ <span class="nx">topSensitive</span><span class="o">:</span> <span class="o">-></span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-87"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-87">#</a> </div> <p>Compilation creates a new scope unless explicitly asked to share with the
+outer scope. Handles splat parameters in the parameter list by peeking at
+the JavaScript <code>arguments</code> objects. If the function is bound with the <code>=></code>
+arrow, generates a wrapper that saves the current value of <code>this</code> through
+a closure.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">traverseChildren</span><span class="o">:</span> <span class="p">(</span><span class="nx">crossScope</span><span class="p">,</span> <span class="nx">func</span><span class="p">)</span> <span class="o">-></span> <span class="k">super</span><span class="p">(</span><span class="nx">crossScope</span><span class="p">,</span> <span class="nx">func</span><span class="p">)</span> <span class="k">if</span> <span class="nx">crossScope</span>
+
+ <span class="nx">toString</span><span class="o">:</span> <span class="p">(</span><span class="nx">idt</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">idt</span> <span class="o">or=</span> <span class="s1">''</span>
+ <span class="nv">children = </span><span class="p">(</span><span class="nx">child</span><span class="p">.</span><span class="nx">toString</span><span class="p">(</span><span class="nx">idt</span> <span class="o">+</span> <span class="nx">TAB</span><span class="p">)</span> <span class="k">for</span> <span class="nx">child</span> <span class="k">in</span> <span class="nx">@collectChildren</span><span class="p">()).</span><span class="nx">join</span><span class="p">(</span><span class="s1">''</span><span class="p">)</span>
+ <span class="s1">'\n'</span> <span class="o">+</span> <span class="nx">idt</span> <span class="o">+</span> <span class="nx">children</span></pre></div> </td> </tr> <tr id="section-88"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-88">#</a> </div> <p>Short-circuit traverseChildren method to prevent it from crossing scope boundaries
+unless crossScope is true</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-89"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-89">#</a> </div> <h3>ParamNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ParamNode = </span><span class="nx">class</span> <span class="nx">ParamNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ParamNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'name'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@name</span><span class="p">,</span> <span class="nx">@attach</span><span class="p">,</span> <span class="nx">@splat</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="vi">@value = </span><span class="nx">literal</span> <span class="nx">@name</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@value</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+
+ <span class="nx">toString</span><span class="o">:</span> <span class="p">(</span><span class="nx">idt</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@attach</span> <span class="k">then</span> <span class="p">(</span><span class="nx">literal</span> <span class="s1">'@'</span> <span class="o">+</span> <span class="nx">@name</span><span class="p">).</span><span class="nx">toString</span> <span class="nx">idt</span> <span class="k">else</span> <span class="nx">@value</span><span class="p">.</span><span class="nx">toString</span> <span class="nx">idt</span></pre></div> </td> </tr> <tr id="section-90"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-90">#</a> </div> <p>A parameter in a function definition. Beyond a typical Javascript parameter,
+these parameters can also attach themselves to the context of the function,
+as well as be a splat, gathering up a group of parameters into an array.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-91"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-91">#</a> </div> <h3>SplatNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.SplatNode = </span><span class="nx">class</span> <span class="nx">SplatNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'SplatNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'name'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="nv">name = </span><span class="nx">literal</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="nx">unless</span> <span class="nx">name</span><span class="p">.</span><span class="nx">compile</span>
+ <span class="vi">@name = </span><span class="nx">name</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@index</span><span class="o">?</span> <span class="k">then</span> <span class="nx">@compileParam</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="nx">@name</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-92"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-92">#</a> </div> <p>A splat, either as a parameter to a function, an argument to a call,
+or as part of a destructuring assignment.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileParam</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">name = </span><span class="nx">@name</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">find</span> <span class="nx">name</span>
+ <span class="nv">end = </span><span class="s1">''</span>
+ <span class="k">if</span> <span class="nx">@trailings</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">len = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'len'</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">assign</span> <span class="nx">len</span><span class="p">,</span> <span class="s2">"arguments.length"</span>
+ <span class="nv">variadic = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'result'</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">assign</span> <span class="nx">variadic</span><span class="p">,</span> <span class="nx">len</span> <span class="o">+</span> <span class="s1">' >= '</span> <span class="o">+</span> <span class="nx">@arglength</span>
+ <span class="nv">end = </span><span class="k">if</span> <span class="nx">@trailings</span><span class="p">.</span><span class="nx">length</span> <span class="k">then</span> <span class="s2">", #{len} - #{@trailings.length}"</span>
+ <span class="k">for</span> <span class="nx">trailing</span><span class="p">,</span> <span class="nx">idx</span> <span class="k">in</span> <span class="nx">@trailings</span>
+ <span class="k">if</span> <span class="nx">trailing</span><span class="p">.</span><span class="nx">attach</span>
+ <span class="nv">assign = </span><span class="nx">trailing</span><span class="p">.</span><span class="nx">assign</span>
+ <span class="nv">trailing = </span><span class="nx">literal</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'arg'</span>
+ <span class="nv">assign.value = </span><span class="nx">trailing</span>
+ <span class="nv">pos = </span><span class="nx">@trailings</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="nx">idx</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">assign</span><span class="p">(</span><span class="nx">trailing</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">),</span> <span class="s2">"arguments[#{variadic} ? #{len} - #{pos} : #{@index + idx}]"</span><span class="p">)</span>
+ <span class="s2">"#{name} = #{utility('slice')}.call(arguments, #{@index}#{end})"</span></pre></div> </td> </tr> <tr id="section-93"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-93">#</a> </div> <p>Compiling a parameter splat means recovering the parameters that succeed
+the splat in the parameter list, by slicing the arguments object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileValue</span><span class="o">:</span> <span class="p">(</span><span class="nx">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="nx">trailings</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">trail = </span><span class="k">if</span> <span class="nx">trailings</span> <span class="k">then</span> <span class="s2">", #{name}.length - #{trailings}"</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="s2">"#{utility 'slice'}.call(#{name}, #{index}#{trail})"</span></pre></div> </td> </tr> <tr id="section-94"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-94">#</a> </div> <p>A compiling a splat as a destructuring assignment means slicing arguments
+from the right-hand-side's corresponding array.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">@compileSplattedArray</span><span class="o">:</span> <span class="p">(</span><span class="nx">list</span><span class="p">,</span> <span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">args = </span><span class="p">[]</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">list</span>
+ <span class="nv">code = </span><span class="nx">arg</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="nv">prev = </span><span class="nx">args</span><span class="p">[</span><span class="nv">last = </span><span class="nx">args</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="k">if</span> <span class="nx">arg</span> <span class="o">not</span> <span class="k">instanceof</span> <span class="nx">SplatNode</span>
+ <span class="k">if</span> <span class="nx">prev</span> <span class="o">and</span> <span class="nx">starts</span><span class="p">(</span><span class="nx">prev</span><span class="p">,</span> <span class="s1">'['</span><span class="p">)</span> <span class="o">and</span> <span class="nx">ends</span><span class="p">(</span><span class="nx">prev</span><span class="p">,</span> <span class="s1">']'</span><span class="p">)</span>
+ <span class="nx">args</span><span class="p">[</span><span class="nx">last</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"#{prev.substr(0, prev.length - 1)}, #{code}]"</span>
+ <span class="k">continue</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">prev</span> <span class="o">and</span> <span class="nx">starts</span><span class="p">(</span><span class="nx">prev</span><span class="p">,</span> <span class="s1">'.concat(['</span><span class="p">)</span> <span class="o">and</span> <span class="nx">ends</span><span class="p">(</span><span class="nx">prev</span><span class="p">,</span> <span class="s1">'])'</span><span class="p">)</span>
+ <span class="nx">args</span><span class="p">[</span><span class="nx">last</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"#{prev.substr(0, prev.length - 2)}, #{code}])"</span>
+ <span class="k">continue</span>
+ <span class="k">else</span>
+ <span class="nv">code = </span><span class="s2">"[#{code}]"</span>
+ <span class="nx">args</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="k">if</span> <span class="nx">i</span> <span class="o">is</span> <span class="mi">0</span> <span class="k">then</span> <span class="nx">code</span> <span class="k">else</span> <span class="s2">".concat(#{code})"</span><span class="p">)</span>
+ <span class="nx">args</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">''</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-95"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-95">#</a> </div> <p>Utility function that converts arbitrary number of elements, mixed with
+splats, to a proper array</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-96"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-96">#</a> </div> <h3>WhileNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.WhileNode = </span><span class="nx">class</span> <span class="nx">WhileNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'WhileNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'condition'</span><span class="p">,</span> <span class="s1">'guard'</span><span class="p">,</span> <span class="s1">'body'</span><span class="p">]</span>
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">condition</span><span class="p">,</span> <span class="nx">opts</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="k">if</span> <span class="nx">opts</span> <span class="o">and</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">invert</span>
+ <span class="nv">condition = </span><span class="k">new</span> <span class="nx">ParentheticalNode</span> <span class="nx">condition</span> <span class="k">if</span> <span class="nx">condition</span> <span class="k">instanceof</span> <span class="nx">OpNode</span>
+ <span class="nv">condition = </span><span class="k">new</span> <span class="nx">OpNode</span><span class="p">(</span><span class="s1">'!'</span><span class="p">,</span> <span class="nx">condition</span><span class="p">)</span>
+ <span class="vi">@condition = </span><span class="nx">condition</span>
+ <span class="vi">@guard = </span><span class="nx">opts</span> <span class="o">and</span> <span class="nx">opts</span><span class="p">.</span><span class="nx">guard</span>
+
+ <span class="nx">addBody</span><span class="o">:</span> <span class="p">(</span><span class="nx">body</span><span class="p">)</span> <span class="o">-></span>
+ <span class="vi">@body = </span><span class="nx">body</span>
+ <span class="k">this</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="vi">@returns = </span><span class="kc">true</span>
+ <span class="k">this</span>
+
+ <span class="nx">topSensitive</span><span class="o">:</span> <span class="o">-></span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-97"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-97">#</a> </div> <p>A while loop, the only sort of low-level loop exposed by CoffeeScript. From
+it, all other loops can be manufactured. Useful in cases where you need more
+flexibility or more speed than a comprehension can provide.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">top = </span> <span class="nx">del</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="s1">'top'</span><span class="p">)</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@returns</span>
+ <span class="nv">o.indent = </span> <span class="nx">@idt</span> <span class="mi">1</span>
+ <span class="nv">o.top = </span> <span class="kc">true</span>
+ <span class="vi">@condition.parenthetical = </span><span class="kc">yes</span>
+ <span class="nv">cond = </span> <span class="nx">@condition</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">set = </span> <span class="s1">''</span>
+ <span class="nx">unless</span> <span class="nx">top</span>
+ <span class="nv">rvar = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'result'</span>
+ <span class="nv">set = </span><span class="s2">"#{@tab}#{rvar} = [];\n"</span>
+ <span class="vi">@body = </span><span class="nx">PushNode</span><span class="p">.</span><span class="nx">wrap</span><span class="p">(</span><span class="nx">rvar</span><span class="p">,</span> <span class="nx">@body</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@body</span>
+ <span class="nv">pre = </span><span class="s2">"#{set}#{@tab}while (#{cond})"</span>
+ <span class="vi">@body = </span><span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span><span class="p">([</span><span class="k">new</span> <span class="nx">IfNode</span><span class="p">(</span><span class="nx">@guard</span><span class="p">,</span> <span class="nx">@body</span><span class="p">)])</span> <span class="k">if</span> <span class="nx">@guard</span>
+ <span class="k">if</span> <span class="nx">@returns</span>
+ <span class="nv">post = </span><span class="s1">'\n'</span> <span class="o">+</span> <span class="k">new</span> <span class="nx">ReturnNode</span><span class="p">(</span><span class="nx">literal</span><span class="p">(</span><span class="nx">rvar</span><span class="p">)).</span><span class="nx">compile</span><span class="p">(</span><span class="nx">merge</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="nx">indent</span><span class="o">:</span> <span class="nx">@idt</span><span class="p">()))</span>
+ <span class="k">else</span>
+ <span class="nv">post = </span><span class="s1">''</span>
+ <span class="s2">"#{pre} {\n#{ @body.compile(o) }\n#{@tab}}#{post}"</span></pre></div> </td> </tr> <tr id="section-98"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-98">#</a> </div> <p>The main difference from a JavaScript <em>while</em> is that the CoffeeScript
+<em>while</em> can be used as a part of a larger expression -- while loops may
+return an array containing the computed result of each iteration.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-99"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-99">#</a> </div> <h3>OpNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.OpNode = </span><span class="nx">class</span> <span class="nx">OpNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span></pre></div> </td> </tr> <tr id="section-100"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-100">#</a> </div> <p>Simple Arithmetic and logical operations. Performs some conversion from
+CoffeeScript operations into their JavaScript equivalents.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">CONVERSIONS</span><span class="o">:</span>
+ <span class="s1">'=='</span><span class="o">:</span> <span class="s1">'==='</span>
+ <span class="s1">'!='</span><span class="o">:</span> <span class="s1">'!=='</span></pre></div> </td> </tr> <tr id="section-101"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-101">#</a> </div> <p>The map of conversions from CoffeeScript to JavaScript symbols.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">INVERSIONS</span><span class="o">:</span>
+ <span class="s1">'!=='</span><span class="o">:</span> <span class="s1">'==='</span>
+ <span class="s1">'==='</span><span class="o">:</span> <span class="s1">'!=='</span></pre></div> </td> </tr> <tr id="section-102"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-102">#</a> </div> <p>The map of invertible operators.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">CHAINABLE</span><span class="o">:</span> <span class="p">[</span><span class="s1">'<'</span><span class="p">,</span> <span class="s1">'>'</span><span class="p">,</span> <span class="s1">'>='</span><span class="p">,</span> <span class="s1">'<='</span><span class="p">,</span> <span class="s1">'==='</span><span class="p">,</span> <span class="s1">'!=='</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-103"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-103">#</a> </div> <p>The list of operators for which we perform
+<a href="http://docs.python.org/reference/expressions.html#notin">Python-style comparison chaining</a>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ASSIGNMENT</span><span class="o">:</span> <span class="p">[</span><span class="s1">'||='</span><span class="p">,</span> <span class="s1">'&&='</span><span class="p">,</span> <span class="s1">'?='</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-104"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-104">#</a> </div> <p>Our assignment operators that have no JavaScript equivalent.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">PREFIX_OPERATORS</span><span class="o">:</span> <span class="p">[</span><span class="s1">'typeof'</span><span class="p">,</span> <span class="s1">'delete'</span><span class="p">]</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'OpNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'first'</span><span class="p">,</span> <span class="s1">'second'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@operator</span><span class="p">,</span> <span class="nx">@first</span><span class="p">,</span> <span class="nx">@second</span><span class="p">,</span> <span class="nx">flip</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="vi">@operator = </span><span class="nx">@CONVERSIONS</span><span class="p">[</span><span class="nx">@operator</span><span class="p">]</span> <span class="o">or</span> <span class="nx">@operator</span>
+ <span class="vi">@flip = </span><span class="o">!!</span><span class="nx">flip</span>
+ <span class="k">if</span> <span class="nx">@first</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span> <span class="o">and</span> <span class="nx">@first</span><span class="p">.</span><span class="nx">base</span> <span class="k">instanceof</span> <span class="nx">ObjectNode</span>
+ <span class="vi">@first = </span><span class="k">new</span> <span class="nx">ParentheticalNode</span> <span class="nx">@first</span>
+ <span class="vi">@first.tags.operation = </span><span class="kc">yes</span>
+ <span class="vi">@second.tags.operation = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">@second</span>
+
+ <span class="nx">isUnary</span><span class="o">:</span> <span class="o">-></span>
+ <span class="o">not</span> <span class="nx">@second</span>
+
+ <span class="nx">isInvertible</span><span class="o">:</span> <span class="o">-></span>
+ <span class="p">(</span><span class="nx">@operator</span> <span class="k">in</span> <span class="p">[</span><span class="s1">'==='</span><span class="p">,</span> <span class="s1">'!=='</span><span class="p">])</span> <span class="o">and</span>
+ <span class="o">not</span> <span class="p">(</span><span class="nx">@first</span> <span class="k">instanceof</span> <span class="nx">OpNode</span><span class="p">)</span> <span class="o">and</span> <span class="o">not</span> <span class="p">(</span><span class="nx">@second</span> <span class="k">instanceof</span> <span class="nx">OpNode</span><span class="p">)</span>
+
+
+ <span class="nx">isMutator</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">ends</span><span class="p">(</span><span class="nx">@operator</span><span class="p">,</span> <span class="s1">'='</span><span class="p">)</span> <span class="o">and</span> <span class="o">not</span> <span class="p">(</span><span class="nx">@operator</span> <span class="k">in</span> <span class="p">[</span><span class="s1">'==='</span><span class="p">,</span> <span class="s1">'!=='</span><span class="p">])</span>
+
+ <span class="nx">isChainable</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">include</span><span class="p">(</span><span class="nx">@CHAINABLE</span><span class="p">,</span> <span class="nx">@operator</span><span class="p">)</span>
+
+ <span class="nx">invert</span><span class="o">:</span> <span class="o">-></span>
+ <span class="vi">@operator = </span><span class="nx">@INVERSIONS</span><span class="p">[</span><span class="nx">@operator</span><span class="p">]</span>
+
+ <span class="nx">toString</span><span class="o">:</span> <span class="p">(</span><span class="nx">idt</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">(</span><span class="nx">idt</span><span class="p">,</span> <span class="nx">@class</span> <span class="o">+</span> <span class="s1">' '</span> <span class="o">+</span> <span class="nx">@operator</span><span class="p">)</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">@compileChain</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@isChainable</span><span class="p">()</span> <span class="o">and</span> <span class="nx">@first</span><span class="p">.</span><span class="nx">unwrap</span><span class="p">()</span> <span class="k">instanceof</span> <span class="nx">OpNode</span> <span class="o">and</span> <span class="nx">@first</span><span class="p">.</span><span class="nx">unwrap</span><span class="p">().</span><span class="nx">isChainable</span><span class="p">()</span>
+ <span class="k">return</span> <span class="nx">@compileAssignment</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">indexOf</span><span class="p">(</span><span class="nx">@ASSIGNMENT</span><span class="p">,</span> <span class="nx">@operator</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span>
+ <span class="k">return</span> <span class="nx">@compileUnary</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@isUnary</span><span class="p">()</span>
+ <span class="k">return</span> <span class="nx">@compileExistence</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@operator</span> <span class="o">is</span> <span class="s1">'?'</span>
+ <span class="vi">@first = </span><span class="k">new</span> <span class="nx">ParentheticalNode</span><span class="p">(</span><span class="nx">@first</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@first</span> <span class="k">instanceof</span> <span class="nx">OpNode</span> <span class="o">and</span> <span class="nx">@first</span><span class="p">.</span><span class="nx">isMutator</span><span class="p">()</span>
+ <span class="vi">@second = </span><span class="k">new</span> <span class="nx">ParentheticalNode</span><span class="p">(</span><span class="nx">@second</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@second</span> <span class="k">instanceof</span> <span class="nx">OpNode</span> <span class="o">and</span> <span class="nx">@second</span><span class="p">.</span><span class="nx">isMutator</span><span class="p">()</span>
+ <span class="p">[</span><span class="nx">@first</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">),</span> <span class="nx">@operator</span><span class="p">,</span> <span class="nx">@second</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)].</span><span class="nx">join</span> <span class="s1">' '</span></pre></div> </td> </tr> <tr id="section-105"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-105">#</a> </div> <p>Operators must come before their operands with a space.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileChain</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">shared = </span><span class="nx">@first</span><span class="p">.</span><span class="nx">unwrap</span><span class="p">().</span><span class="nx">second</span>
+ <span class="p">[</span><span class="nx">@first</span><span class="p">.</span><span class="nx">second</span><span class="p">,</span> <span class="nx">shared</span><span class="p">]</span> <span class="o">=</span> <span class="nx">shared</span><span class="p">.</span><span class="nx">compileReference</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">shared</span><span class="p">.</span><span class="nx">containsType</span> <span class="nx">CallNode</span>
+ <span class="p">[</span><span class="nx">first</span><span class="p">,</span> <span class="nx">second</span><span class="p">,</span> <span class="nx">shared</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">@first</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">),</span> <span class="nx">@second</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">),</span> <span class="nx">shared</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)]</span>
+ <span class="s2">"(#{first}) && (#{shared} #{@operator} #{second})"</span></pre></div> </td> </tr> <tr id="section-106"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-106">#</a> </div> <p>Mimic Python's chained comparisons when multiple comparison operators are
+used sequentially. For example:</p>
+
+<pre><code>bin/coffee -e "puts 50 < 65 > 10"
+true
+</code></pre> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileAssignment</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">[</span><span class="nx">first</span><span class="p">,</span> <span class="nx">firstVar</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@first</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">precompile</span><span class="o">:</span> <span class="kc">yes</span><span class="p">,</span> <span class="nx">assignment</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="nv">second = </span><span class="nx">@second</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="nv">second = </span><span class="s2">"(#{second})"</span> <span class="k">if</span> <span class="nx">@second</span> <span class="k">instanceof</span> <span class="nx">OpNode</span>
+ <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">first</span><span class="p">)</span> <span class="k">if</span> <span class="nx">first</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="nx">IDENTIFIER</span><span class="p">)</span>
+ <span class="k">return</span> <span class="s2">"#{first} = #{ ExistenceNode.compileTest(o, literal(firstVar))[0] } ? #{firstVar} : #{second}"</span> <span class="k">if</span> <span class="nx">@operator</span> <span class="o">is</span> <span class="s1">'?='</span>
+ <span class="s2">"#{first} #{ @operator.substr(0, 2) } (#{firstVar} = #{second})"</span></pre></div> </td> </tr> <tr id="section-107"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-107">#</a> </div> <p>When compiling a conditional assignment, take care to ensure that the
+operands are only evaluated once, even though we have to reference them
+more than once.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileExistence</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">[</span><span class="nx">test</span><span class="p">,</span> <span class="nx">ref</span><span class="p">]</span> <span class="o">=</span> <span class="nx">ExistenceNode</span><span class="p">.</span><span class="nx">compileTest</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="nx">@first</span><span class="p">)</span>
+ <span class="s2">"#{test} ? #{ref} : #{ @second.compile(o) }"</span></pre></div> </td> </tr> <tr id="section-108"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-108">#</a> </div> <p>If this is an existence operator, we delegate to <code>ExistenceNode.compileTest</code>
+to give us the safe references for the variables.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileUnary</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">space = </span><span class="k">if</span> <span class="nx">indexOf</span><span class="p">(</span><span class="nx">@PREFIX_OPERATORS</span><span class="p">,</span> <span class="nx">@operator</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span> <span class="k">then</span> <span class="s1">' '</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nv">parts = </span><span class="p">[</span><span class="nx">@operator</span><span class="p">,</span> <span class="nx">space</span><span class="p">,</span> <span class="nx">@first</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)]</span>
+ <span class="nv">parts = </span><span class="nx">parts</span><span class="p">.</span><span class="nx">reverse</span><span class="p">()</span> <span class="k">if</span> <span class="nx">@flip</span>
+ <span class="nx">parts</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">''</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-109"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-109">#</a> </div> <p>Compile a unary <strong>OpNode</strong>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.InNode = </span><span class="nx">class</span> <span class="nx">InNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'InNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'object'</span><span class="p">,</span> <span class="s1">'array'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@object</span><span class="p">,</span> <span class="nx">@array</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">isArray</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@array</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span> <span class="o">and</span> <span class="nx">@array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">()</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">[</span><span class="nx">@obj1</span><span class="p">,</span> <span class="nx">@obj2</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@object</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">precompile</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="k">if</span> <span class="nx">@isArray</span><span class="p">()</span> <span class="k">then</span> <span class="nx">@compileOrTest</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="nx">@compileLoopTest</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+
+ <span class="nx">compileOrTest</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">tests = </span><span class="k">for</span> <span class="nx">item</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">@array</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">objects</span>
+ <span class="s2">"#{item.compile(o)} === #{if i then @obj2 else @obj1}"</span>
+ <span class="s2">"(#{tests.join(' || ')})"</span>
+
+ <span class="nx">compileLoopTest</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">[</span><span class="nx">@arr1</span><span class="p">,</span> <span class="nx">@arr2</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@array</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">precompile</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="p">[</span><span class="nx">i</span><span class="p">,</span> <span class="nx">l</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span><span class="p">(</span><span class="s1">'i'</span><span class="p">),</span> <span class="nx">o</span><span class="p">.</span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span><span class="p">(</span><span class="s1">'len'</span><span class="p">)]</span>
+ <span class="nv">prefix = </span><span class="k">if</span> <span class="nx">@obj1</span> <span class="o">isnt</span> <span class="nx">@obj2</span> <span class="k">then</span> <span class="nx">@obj1</span> <span class="o">+</span> <span class="s1">'; '</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="s2">"(function(){ #{prefix}for (var #{i}=0, #{l}=#{@arr1}.length; #{i}<#{l}; #{i}++) { if (#{@arr2}[#{i}] === #{@obj2}) return true; } return false; }).call(this)"</span></pre></div> </td> </tr> <tr id="section-110"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-110">#</a> </div> <h3>InNode</h3> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-111"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-111">#</a> </div> <h3>TryNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.TryNode = </span><span class="nx">class</span> <span class="nx">TryNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'TryNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'attempt'</span><span class="p">,</span> <span class="s1">'recovery'</span><span class="p">,</span> <span class="s1">'ensure'</span><span class="p">]</span>
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@attempt</span><span class="p">,</span> <span class="nx">@error</span><span class="p">,</span> <span class="nx">@recovery</span><span class="p">,</span> <span class="nx">@ensure</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="vi">@attempt = </span><span class="nx">@attempt</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">()</span> <span class="k">if</span> <span class="nx">@attempt</span>
+ <span class="vi">@recovery = </span><span class="nx">@recovery</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">()</span> <span class="k">if</span> <span class="nx">@recovery</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-112"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-112">#</a> </div> <p>A classic <em>try/catch/finally</em> block.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">o.indent = </span><span class="nx">@idt</span> <span class="mi">1</span>
+ <span class="nv">o.top = </span><span class="kc">true</span>
+ <span class="nv">attemptPart = </span><span class="nx">@attempt</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">errorPart = </span><span class="k">if</span> <span class="nx">@error</span> <span class="k">then</span> <span class="s2">" (#{ @error.compile(o) }) "</span> <span class="k">else</span> <span class="s1">' '</span>
+ <span class="nv">catchPart = </span><span class="k">if</span> <span class="nx">@recovery</span> <span class="k">then</span> <span class="s2">" catch#{errorPart}{\n#{ @recovery.compile(o) }\n#{@tab}}"</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nv">finallyPart = </span><span class="p">(</span><span class="nx">@ensure</span> <span class="o">or</span> <span class="s1">''</span><span class="p">)</span> <span class="o">and</span> <span class="s1">' finally {\n'</span> <span class="o">+</span> <span class="nx">@ensure</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">merge</span><span class="p">(</span><span class="nx">o</span><span class="p">))</span> <span class="o">+</span> <span class="s2">"\n#{@tab}}"</span>
+ <span class="s2">"#{@tab}try {\n#{attemptPart}\n#{@tab}}#{catchPart}#{finallyPart}"</span></pre></div> </td> </tr> <tr id="section-113"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-113">#</a> </div> <p>Compilation is more or less as you would expect -- the <em>finally</em> clause
+is optional, the <em>catch</em> is not.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-114"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-114">#</a> </div> <h3>ThrowNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ThrowNode = </span><span class="nx">class</span> <span class="nx">ThrowNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ThrowNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'expression'</span><span class="p">]</span>
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@expression</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-115"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-115">#</a> </div> <p>Simple node to throw an exception.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="k">this</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="s2">"#{@tab}throw #{@expression.compile(o)};"</span></pre></div> </td> </tr> <tr id="section-116"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-116">#</a> </div> <p>A <strong>ThrowNode</strong> is already a return, of sorts...</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-117"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-117">#</a> </div> <h3>ExistenceNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ExistenceNode = </span><span class="nx">class</span> <span class="nx">ExistenceNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ExistenceNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'expression'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@expression</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">test = </span><span class="nx">ExistenceNode</span><span class="p">.</span><span class="nx">compileTest</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="nx">@expression</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
+ <span class="k">if</span> <span class="nx">@parenthetical</span> <span class="k">then</span> <span class="nx">test</span><span class="p">.</span><span class="nx">substring</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nx">test</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="k">else</span> <span class="nx">test</span></pre></div> </td> </tr> <tr id="section-118"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-118">#</a> </div> <p>Checks a variable for existence -- not <em>null</em> and not <em>undefined</em>. This is
+similar to <code>.nil?</code> in Ruby, and avoids having to consult a JavaScript truth
+table.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">@compileTest</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="nx">variable</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">[</span><span class="nx">first</span><span class="p">,</span> <span class="nx">second</span><span class="p">]</span> <span class="o">=</span> <span class="nx">variable</span><span class="p">.</span><span class="nx">compileReference</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">precompile</span><span class="o">:</span> <span class="kc">yes</span>
+ <span class="p">[</span><span class="s2">"(typeof #{first} !== \"undefined\" && #{second} !== null)"</span><span class="p">,</span> <span class="nx">second</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-119"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-119">#</a> </div> <p>The meat of the <strong>ExistenceNode</strong> is in this static <code>compileTest</code> method
+because other nodes like to check the existence of their variables as well.
+Be careful not to double-evaluate anything.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-120"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-120">#</a> </div> <h3>ParentheticalNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ParentheticalNode = </span><span class="nx">class</span> <span class="nx">ParentheticalNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ParentheticalNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'expression'</span><span class="p">]</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@expression</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@expression</span><span class="p">.</span><span class="nx">isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@expression</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">()</span>
+
+ <span class="nx">topSensitive</span><span class="o">:</span> <span class="o">-></span>
+ <span class="kc">yes</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">top = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'top'</span>
+ <span class="vi">@expression.parenthetical = </span><span class="kc">true</span>
+ <span class="nv">code = </span><span class="nx">@expression</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="k">return</span> <span class="nx">code</span> <span class="k">if</span> <span class="nx">top</span> <span class="o">and</span> <span class="nx">@expression</span><span class="p">.</span><span class="nx">isPureStatement</span> <span class="nx">o</span>
+ <span class="k">if</span> <span class="nx">@parenthetical</span> <span class="o">or</span> <span class="nx">@isStatement</span> <span class="nx">o</span>
+ <span class="k">return</span> <span class="k">if</span> <span class="nx">top</span> <span class="k">then</span> <span class="nx">@tab</span> <span class="o">+</span> <span class="nx">code</span> <span class="o">+</span> <span class="s1">';'</span> <span class="k">else</span> <span class="nx">code</span>
+ <span class="s2">"(#{code})"</span></pre></div> </td> </tr> <tr id="section-121"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-121">#</a> </div> <p>An extra set of parentheses, specified explicitly in the source. At one time
+we tried to clean up the results by detecting and removing redundant
+parentheses, but no longer -- you can put in as many as you please.</p>
+
+<p>Parentheses are a good way to force any statement to become an expression.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-122"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-122">#</a> </div> <h3>ForNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.ForNode = </span><span class="nx">class</span> <span class="nx">ForNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'ForNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'body'</span><span class="p">,</span> <span class="s1">'source'</span><span class="p">,</span> <span class="s1">'guard'</span><span class="p">]</span>
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@body</span><span class="p">,</span> <span class="nx">source</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">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="nx">@index</span> <span class="o">or=</span> <span class="kc">null</span>
+ <span class="vi">@source = </span><span class="nx">source</span><span class="p">.</span><span class="nx">source</span>
+ <span class="vi">@guard = </span><span class="nx">source</span><span class="p">.</span><span class="nx">guard</span>
+ <span class="vi">@step = </span><span class="nx">source</span><span class="p">.</span><span class="nx">step</span>
+ <span class="vi">@raw = </span><span class="o">!!</span><span class="nx">source</span><span class="p">.</span><span class="nx">raw</span>
+ <span class="vi">@object = </span><span class="o">!!</span><span class="nx">source</span><span class="p">.</span><span class="nx">object</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">=</span> <span class="p">[</span><span class="nx">@index</span><span class="p">,</span> <span class="nx">@name</span><span class="p">]</span> <span class="k">if</span> <span class="nx">@object</span>
+ <span class="vi">@pattern = </span><span class="nx">@name</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">'index cannot be a pattern matching expression'</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@index</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span>
+ <span class="vi">@returns = </span><span class="kc">false</span>
+
+ <span class="nx">topSensitive</span><span class="o">:</span> <span class="o">-></span>
+ <span class="kc">true</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="vi">@returns = </span><span class="kc">true</span>
+ <span class="k">this</span>
+
+ <span class="nx">compileReturnValue</span><span class="o">:</span> <span class="p">(</span><span class="nx">val</span><span class="p">,</span> <span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="s1">'\n'</span> <span class="o">+</span> <span class="k">new</span> <span class="nx">ReturnNode</span><span class="p">(</span><span class="nx">literal</span><span class="p">(</span><span class="nx">val</span><span class="p">)).</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">if</span> <span class="nx">@returns</span>
+ <span class="k">return</span> <span class="s1">'\n'</span> <span class="o">+</span> <span class="nx">val</span> <span class="k">if</span> <span class="nx">val</span>
+ <span class="s1">''</span></pre></div> </td> </tr> <tr id="section-123"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-123">#</a> </div> <p>CoffeeScript's replacement for the <em>for</em> loop is our array and object
+comprehensions, that compile into <em>for</em> loops here. They also act as an
+expression, able to return the result of each filtered iteration.</p>
+
+<p>Unlike Python array comprehensions, they can be multi-line, and you can pass
+the current index of the loop as a second parameter. Unlike Ruby blocks,
+you can map and filter in a single pass.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">topLevel = </span><span class="nx">del</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="s1">'top'</span><span class="p">)</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@returns</span>
+ <span class="nv">range = </span><span class="nx">@source</span> <span class="k">instanceof</span> <span class="nx">ValueNode</span> <span class="o">and</span> <span class="nx">@source</span><span class="p">.</span><span class="nx">base</span> <span class="k">instanceof</span> <span class="nx">RangeNode</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@source</span><span class="p">.</span><span class="nx">properties</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">source = </span><span class="k">if</span> <span class="nx">range</span> <span class="k">then</span> <span class="nx">@source</span><span class="p">.</span><span class="nx">base</span> <span class="k">else</span> <span class="nx">@source</span>
+ <span class="nv">codeInBody = </span><span class="nx">@body</span><span class="p">.</span><span class="nx">contains</span> <span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="o">-></span> <span class="nx">n</span> <span class="k">instanceof</span> <span class="nx">CodeNode</span>
+ <span class="nv">scope = </span><span class="nx">o</span><span class="p">.</span><span class="nx">scope</span>
+ <span class="nv">name = </span><span class="p">(</span><span class="nx">@name</span> <span class="o">and</span> <span class="nx">@name</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">))</span> <span class="o">or</span> <span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'i'</span>
+ <span class="nv">index = </span><span class="nx">@index</span> <span class="o">and</span> <span class="nx">@index</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">o</span>
+ <span class="nx">scope</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">immediate</span><span class="o">:</span> <span class="kc">yes</span><span class="p">)</span> <span class="k">if</span> <span class="nx">name</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@pattern</span> <span class="o">and</span> <span class="p">(</span><span class="nx">range</span> <span class="o">or</span> <span class="o">not</span> <span class="nx">codeInBody</span><span class="p">)</span>
+ <span class="nx">scope</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">index</span><span class="p">,</span> <span class="nx">immediate</span><span class="o">:</span> <span class="kc">yes</span><span class="p">)</span> <span class="k">if</span> <span class="nx">index</span>
+ <span class="nv">rvar = </span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'result'</span> <span class="nx">unless</span> <span class="nx">topLevel</span>
+ <span class="nv">ivar = </span><span class="k">if</span> <span class="nx">codeInBody</span> <span class="k">then</span> <span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'i'</span> <span class="k">else</span> <span class="k">if</span> <span class="nx">range</span> <span class="k">then</span> <span class="nx">name</span> <span class="k">else</span> <span class="nx">index</span> <span class="o">or</span> <span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'i'</span>
+ <span class="nv">varPart = </span><span class="s1">''</span>
+ <span class="nv">guardPart = </span><span class="s1">''</span>
+ <span class="nv">body = </span><span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span><span class="p">([</span><span class="nx">@body</span><span class="p">])</span>
+ <span class="k">if</span> <span class="nx">range</span>
+ <span class="nv">sourcePart = </span><span class="nx">source</span><span class="p">.</span><span class="nx">compileVariables</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">forPart = </span><span class="nx">source</span><span class="p">.</span><span class="nx">compile</span> <span class="nx">merge</span> <span class="nx">o</span><span class="p">,</span> <span class="nx">index</span><span class="o">:</span> <span class="nx">ivar</span><span class="p">,</span> <span class="nx">step</span><span class="o">:</span> <span class="nx">@step</span>
+ <span class="k">else</span>
+ <span class="nv">svar = </span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'ref'</span>
+ <span class="nv">sourcePart = </span><span class="s2">"#{svar} = #{ @source.compile(o) };"</span>
+ <span class="k">if</span> <span class="nx">@pattern</span>
+ <span class="nv">namePart = </span><span class="k">new</span> <span class="nx">AssignNode</span><span class="p">(</span><span class="nx">@name</span><span class="p">,</span> <span class="nx">literal</span><span class="p">(</span><span class="s2">"#{svar}[#{ivar}]"</span><span class="p">)).</span><span class="nx">compile</span><span class="p">(</span><span class="nx">merge</span> <span class="nx">o</span><span class="p">,</span> <span class="p">{</span><span class="nx">indent</span><span class="o">:</span> <span class="nx">@idt</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="nx">top</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">keepLevel</span><span class="o">:</span> <span class="kc">yes</span><span class="p">})</span> <span class="o">+</span> <span class="s1">'\n'</span>
+ <span class="k">else</span>
+ <span class="nv">namePart = </span><span class="s2">"#{name} = #{svar}[#{ivar}]"</span> <span class="k">if</span> <span class="nx">name</span>
+ <span class="nx">unless</span> <span class="nx">@object</span>
+ <span class="nv">lvar = </span><span class="nx">scope</span><span class="p">.</span><span class="nx">freeVariable</span> <span class="s1">'len'</span>
+ <span class="nv">stepPart = </span><span class="k">if</span> <span class="nx">@step</span> <span class="k">then</span> <span class="s2">"#{ivar} += #{ @step.compile(o) }"</span> <span class="k">else</span> <span class="s2">"#{ivar}++"</span>
+ <span class="nv">forPart = </span><span class="s2">"#{ivar} = 0, #{lvar} = #{svar}.length; #{ivar} < #{lvar}; #{stepPart}"</span>
+ <span class="nv">sourcePart = </span><span class="p">(</span><span class="k">if</span> <span class="nx">rvar</span> <span class="k">then</span> <span class="s2">"#{rvar} = []; "</span> <span class="k">else</span> <span class="s1">''</span><span class="p">)</span> <span class="o">+</span> <span class="nx">sourcePart</span>
+ <span class="nv">sourcePart = </span><span class="k">if</span> <span class="nx">sourcePart</span> <span class="k">then</span> <span class="s2">"#{@tab}#{sourcePart}\n#{@tab}"</span> <span class="k">else</span> <span class="nx">@tab</span>
+ <span class="nv">returnResult = </span><span class="nx">@compileReturnValue</span><span class="p">(</span><span class="nx">rvar</span><span class="p">,</span> <span class="nx">o</span><span class="p">)</span>
+
+ <span class="nv">body = </span><span class="nx">PushNode</span><span class="p">.</span><span class="nx">wrap</span><span class="p">(</span><span class="nx">rvar</span><span class="p">,</span> <span class="nx">body</span><span class="p">)</span> <span class="nx">unless</span> <span class="nx">topLevel</span>
+ <span class="k">if</span> <span class="nx">@guard</span>
+ <span class="nv">body = </span><span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span><span class="p">([</span><span class="k">new</span> <span class="nx">IfNode</span><span class="p">(</span><span class="nx">@guard</span><span class="p">,</span> <span class="nx">body</span><span class="p">)])</span>
+ <span class="k">if</span> <span class="nx">codeInBody</span>
+ <span class="nx">body</span><span class="p">.</span><span class="nx">unshift</span> <span class="nx">literal</span> <span class="s2">"var #{name} = #{ivar}"</span> <span class="k">if</span> <span class="nx">range</span>
+ <span class="nx">body</span><span class="p">.</span><span class="nx">unshift</span> <span class="nx">literal</span> <span class="s2">"var #{namePart}"</span> <span class="k">if</span> <span class="nx">namePart</span>
+ <span class="nx">body</span><span class="p">.</span><span class="nx">unshift</span> <span class="nx">literal</span> <span class="s2">"var #{index} = #{ivar}"</span> <span class="k">if</span> <span class="nx">index</span>
+ <span class="nv">body = </span><span class="nx">ClosureNode</span><span class="p">.</span><span class="nx">wrap</span><span class="p">(</span><span class="nx">body</span><span class="p">,</span> <span class="kc">true</span><span class="p">)</span>
+ <span class="k">else</span>
+ <span class="nv">varPart = </span><span class="p">(</span><span class="nx">namePart</span> <span class="o">or</span> <span class="s1">''</span><span class="p">)</span> <span class="o">and</span> <span class="p">(</span><span class="k">if</span> <span class="nx">@pattern</span> <span class="k">then</span> <span class="nx">namePart</span> <span class="k">else</span> <span class="s2">"#{@idt(1)}#{namePart};\n"</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">@object</span>
+ <span class="nv">forPart = </span><span class="s2">"#{ivar} in #{svar}"</span>
+ <span class="nv">guardPart = </span><span class="s2">"\n#{@idt(1)}if (!#{utility('hasProp')}.call(#{svar}, #{ivar})) continue;"</span> <span class="nx">unless</span> <span class="nx">@raw</span>
+ <span class="nv">body = </span><span class="nx">body</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">merge</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="p">{</span><span class="nx">indent</span><span class="o">:</span> <span class="nx">@idt</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="nx">top</span><span class="o">:</span> <span class="kc">true</span><span class="p">}))</span>
+ <span class="nv">vars = </span><span class="k">if</span> <span class="nx">range</span> <span class="k">then</span> <span class="nx">name</span> <span class="k">else</span> <span class="s2">"#{name}, #{ivar}"</span>
+ <span class="s2">"#{sourcePart}for (#{forPart}) {#{guardPart}\n#{varPart}#{body}\n#{@tab}}#{returnResult}"</span></pre></div> </td> </tr> <tr id="section-124"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-124">#</a> </div> <p>Welcome to the hairiest method in all of CoffeeScript. Handles the inner
+loop, filtering, stepping, and result saving for array, object, and range
+comprehensions. Some of the generated code can be shared in common, and
+some cannot.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-125"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-125">#</a> </div> <h3>SwitchNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.SwitchNode = </span><span class="nx">class</span> <span class="nx">SwitchNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'SwitchNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'subject'</span><span class="p">,</span> <span class="s1">'cases'</span><span class="p">,</span> <span class="s1">'otherwise'</span><span class="p">]</span>
+
+ <span class="nx">isStatement</span><span class="o">:</span> <span class="o">-></span> <span class="kc">yes</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@subject</span><span class="p">,</span> <span class="nx">@cases</span><span class="p">,</span> <span class="nx">@otherwise</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">super</span><span class="p">()</span>
+ <span class="vi">@tags.subjectless = </span><span class="o">!</span><span class="nx">@subject</span>
+ <span class="nx">@subject</span> <span class="o">or=</span> <span class="nx">literal</span> <span class="s1">'true'</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">pair</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="nx">makeReturn</span><span class="p">()</span> <span class="k">for</span> <span class="nx">pair</span> <span class="k">in</span> <span class="nx">@cases</span>
+ <span class="nx">@otherwise</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">()</span> <span class="k">if</span> <span class="nx">@otherwise</span>
+ <span class="k">this</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">idt = o.indent = </span><span class="nx">@idt</span> <span class="mi">2</span>
+ <span class="nv">o.top = </span><span class="kc">yes</span>
+ <span class="nv">code = </span><span class="s2">"#{ @tab }switch (#{ @subject.compile o }) {"</span>
+ <span class="k">for</span> <span class="nx">pair</span> <span class="k">in</span> <span class="nx">@cases</span>
+ <span class="p">[</span><span class="nx">conditions</span><span class="p">,</span> <span class="nx">block</span><span class="p">]</span> <span class="o">=</span> <span class="nx">pair</span>
+ <span class="nv">exprs = </span><span class="nx">block</span><span class="p">.</span><span class="nx">expressions</span>
+ <span class="k">for</span> <span class="nx">condition</span> <span class="k">in</span> <span class="nx">flatten</span> <span class="p">[</span><span class="nx">conditions</span><span class="p">]</span>
+ <span class="nv">condition = </span><span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'!!'</span><span class="p">,</span> <span class="k">new</span> <span class="nx">ParentheticalNode</span> <span class="nx">condition</span> <span class="k">if</span> <span class="nx">@tags</span><span class="p">.</span><span class="nx">subjectless</span>
+ <span class="nx">code</span> <span class="o">+=</span> <span class="s2">"\n#{ @idt(1) }case #{ condition.compile o }:"</span>
+ <span class="nx">code</span> <span class="o">+=</span> <span class="s2">"\n#{ block.compile o }"</span>
+ <span class="nx">code</span> <span class="o">+=</span> <span class="s2">"\n#{ idt }break;"</span> <span class="nx">unless</span> <span class="nx">exprs</span><span class="p">[</span><span class="nx">exprs</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="k">instanceof</span> <span class="nx">ReturnNode</span>
+ <span class="k">if</span> <span class="nx">@otherwise</span>
+ <span class="nx">code</span> <span class="o">+=</span> <span class="s2">"\n#{ @idt(1) }default:\n#{ @otherwise.compile o }"</span>
+ <span class="nx">code</span> <span class="o">+=</span> <span class="s2">"\n#{ @tab }}"</span>
+ <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-126"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-126">#</a> </div> <p>A JavaScript <em>switch</em> statement. Converts into a returnable expression on-demand.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-127"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-127">#</a> </div> <h3>IfNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.IfNode = </span><span class="nx">class</span> <span class="nx">IfNode</span> <span class="k">extends</span> <span class="nx">BaseNode</span>
+
+ <span class="nx">class</span><span class="o">:</span> <span class="s1">'IfNode'</span>
+ <span class="nx">children</span><span class="o">:</span> <span class="p">[</span><span class="s1">'condition'</span><span class="p">,</span> <span class="s1">'body'</span><span class="p">,</span> <span class="s1">'elseBody'</span><span class="p">,</span> <span class="s1">'assigner'</span><span class="p">]</span>
+
+ <span class="nx">topSensitive</span><span class="o">:</span> <span class="o">-></span> <span class="kc">true</span>
+
+ <span class="nx">constructor</span><span class="o">:</span> <span class="p">(</span><span class="nx">@condition</span><span class="p">,</span> <span class="nx">@body</span><span class="p">,</span> <span class="nx">@tags</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@tags</span> <span class="o">or=</span> <span class="p">{}</span>
+ <span class="k">if</span> <span class="nx">@tags</span><span class="p">.</span><span class="nx">invert</span>
+ <span class="k">if</span> <span class="nx">@condition</span> <span class="k">instanceof</span> <span class="nx">OpNode</span> <span class="o">and</span> <span class="nx">@condition</span><span class="p">.</span><span class="nx">isInvertible</span><span class="p">()</span>
+ <span class="nx">@condition</span><span class="p">.</span><span class="nx">invert</span><span class="p">()</span>
+ <span class="k">else</span>
+ <span class="vi">@condition = </span><span class="k">new</span> <span class="nx">OpNode</span> <span class="s1">'!'</span><span class="p">,</span> <span class="k">new</span> <span class="nx">ParentheticalNode</span> <span class="nx">@condition</span>
+ <span class="vi">@elseBody = </span><span class="kc">null</span>
+ <span class="vi">@isChain = </span><span class="kc">false</span>
+
+ <span class="nx">bodyNode</span><span class="o">:</span> <span class="o">-></span> <span class="nx">@body</span><span class="o">?</span><span class="p">.</span><span class="nx">unwrap</span><span class="p">()</span>
+ <span class="nx">elseBodyNode</span><span class="o">:</span> <span class="o">-></span> <span class="nx">@elseBody</span><span class="o">?</span><span class="p">.</span><span class="nx">unwrap</span><span class="p">()</span>
+
+ <span class="nx">forceStatement</span><span class="o">:</span> <span class="o">-></span>
+ <span class="vi">@tags.statement = </span><span class="kc">true</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-128"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-128">#</a> </div> <p><em>If/else</em> statements. Acts as an expression by pushing down requested returns
+to the last line of each clause.</p>
+
+<p>Single-expression <strong>IfNodes</strong> are compiled into ternary operators if possible,
+because ternaries are already proper expressions, and don't need conversion.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">addElse</span><span class="o">:</span> <span class="p">(</span><span class="nx">elseBody</span><span class="p">,</span> <span class="nx">statement</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@isChain</span>
+ <span class="nx">@elseBodyNode</span><span class="p">().</span><span class="nx">addElse</span> <span class="nx">elseBody</span><span class="p">,</span> <span class="nx">statement</span>
+ <span class="k">else</span>
+ <span class="vi">@isChain = </span><span class="nx">elseBody</span> <span class="k">instanceof</span> <span class="nx">IfNode</span>
+ <span class="vi">@elseBody = </span><span class="nx">@ensureExpressions</span> <span class="nx">elseBody</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-129"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-129">#</a> </div> <p>Rewrite a chain of <strong>IfNodes</strong> to add a default case as the final <em>else</em>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">isStatement</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@statement</span> <span class="o">or=</span> <span class="o">!!</span><span class="p">((</span><span class="nx">o</span> <span class="o">and</span> <span class="nx">o</span><span class="p">.</span><span class="nx">top</span><span class="p">)</span> <span class="o">or</span> <span class="nx">@tags</span><span class="p">.</span><span class="nx">statement</span> <span class="o">or</span> <span class="nx">@bodyNode</span><span class="p">().</span><span class="nx">isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">or</span> <span class="p">(</span><span class="nx">@elseBody</span> <span class="o">and</span> <span class="nx">@elseBodyNode</span><span class="p">().</span><span class="nx">isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)))</span>
+
+ <span class="nx">compileCondition</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">conditions = </span><span class="nx">flatten</span> <span class="p">[</span><span class="nx">@condition</span><span class="p">]</span>
+ <span class="nx">conditions</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nv">parenthetical = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">conditions</span><span class="p">.</span><span class="nx">length</span> <span class="o">is</span> <span class="mi">1</span>
+ <span class="p">(</span><span class="nx">cond</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">for</span> <span class="nx">cond</span> <span class="k">in</span> <span class="nx">conditions</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s1">' || '</span><span class="p">)</span>
+
+ <span class="nx">compileNode</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">then</span> <span class="nx">@compileStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="nx">@compileTernary</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+
+ <span class="nx">makeReturn</span><span class="o">:</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">@isStatement</span><span class="p">()</span>
+ <span class="nx">@body</span> <span class="o">and=</span> <span class="nx">@ensureExpressions</span><span class="p">(</span><span class="nx">@body</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">())</span>
+ <span class="nx">@elseBody</span> <span class="o">and=</span> <span class="nx">@ensureExpressions</span><span class="p">(</span><span class="nx">@elseBody</span><span class="p">.</span><span class="nx">makeReturn</span><span class="p">())</span>
+ <span class="k">this</span>
+ <span class="k">else</span>
+ <span class="k">new</span> <span class="nx">ReturnNode</span> <span class="k">this</span>
+
+ <span class="nx">ensureExpressions</span><span class="o">:</span> <span class="p">(</span><span class="nx">node</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">node</span> <span class="k">instanceof</span> <span class="nx">Expressions</span> <span class="k">then</span> <span class="nx">node</span> <span class="k">else</span> <span class="k">new</span> <span class="nx">Expressions</span> <span class="p">[</span><span class="nx">node</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-130"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-130">#</a> </div> <p>The <strong>IfNode</strong> only compiles into a statement if either of its bodies needs
+to be a statement. Otherwise a ternary is safe.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileStatement</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">top = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'top'</span>
+ <span class="nv">child = </span><span class="nx">del</span> <span class="nx">o</span><span class="p">,</span> <span class="s1">'chainChild'</span>
+ <span class="nv">condO = </span><span class="nx">merge</span> <span class="nx">o</span>
+ <span class="nv">o.indent = </span><span class="nx">@idt</span> <span class="mi">1</span>
+ <span class="nv">o.top = </span><span class="kc">true</span>
+ <span class="nv">ifDent = </span><span class="k">if</span> <span class="nx">child</span> <span class="o">or</span> <span class="p">(</span><span class="nx">top</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">@isStatement</span><span class="p">(</span><span class="nx">o</span><span class="p">))</span> <span class="k">then</span> <span class="s1">''</span> <span class="k">else</span> <span class="nx">@idt</span><span class="p">()</span>
+ <span class="nv">comDent = </span><span class="k">if</span> <span class="nx">child</span> <span class="k">then</span> <span class="nx">@idt</span><span class="p">()</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="nv">body = </span><span class="nx">@body</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">ifPart = </span><span class="s2">"#{ifDent}if (#{ @compileCondition(condO) }) {\n#{body}\n#{@tab}}"</span>
+ <span class="k">return</span> <span class="nx">ifPart</span> <span class="nx">unless</span> <span class="nx">@elseBody</span>
+ <span class="nv">elsePart = </span><span class="k">if</span> <span class="nx">@isChain</span>
+ <span class="s1">' else '</span> <span class="o">+</span> <span class="nx">@elseBodyNode</span><span class="p">().</span><span class="nx">compile</span><span class="p">(</span><span class="nx">merge</span><span class="p">(</span><span class="nx">o</span><span class="p">,</span> <span class="p">{</span><span class="nx">indent</span><span class="o">:</span> <span class="nx">@idt</span><span class="p">(),</span> <span class="nx">chainChild</span><span class="o">:</span> <span class="kc">true</span><span class="p">}))</span>
+ <span class="k">else</span>
+ <span class="s2">" else {\n#{ @elseBody.compile(o) }\n#{@tab}}"</span>
+ <span class="s2">"#{ifPart}#{elsePart}"</span></pre></div> </td> </tr> <tr id="section-131"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-131">#</a> </div> <p>Compile the <strong>IfNode</strong> as a regular <em>if-else</em> statement. Flattened chains
+force inner <em>else</em> bodies into statement form.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compileTernary</span><span class="o">:</span> <span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">@bodyNode</span><span class="p">().</span><span class="nv">tags.operation = </span><span class="vi">@condition.tags.operation = </span><span class="kc">yes</span>
+ <span class="nx">@elseBodyNode</span><span class="p">().</span><span class="nv">tags.operation = </span><span class="kc">yes</span> <span class="k">if</span> <span class="nx">@elseBody</span>
+ <span class="nv">ifPart = </span><span class="nx">@condition</span><span class="p">.</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="o">+</span> <span class="s1">' ? '</span> <span class="o">+</span> <span class="nx">@bodyNode</span><span class="p">().</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span>
+ <span class="nv">elsePart = </span><span class="k">if</span> <span class="nx">@elseBody</span> <span class="k">then</span> <span class="nx">@elseBodyNode</span><span class="p">().</span><span class="nx">compile</span><span class="p">(</span><span class="nx">o</span><span class="p">)</span> <span class="k">else</span> <span class="s1">'null'</span>
+ <span class="nv">code = </span><span class="s2">"#{ifPart} : #{elsePart}"</span>
+ <span class="k">if</span> <span class="nx">@tags</span><span class="p">.</span><span class="nx">operation</span> <span class="k">then</span> <span class="s2">"(#{code})"</span> <span class="k">else</span> <span class="nx">code</span></pre></div> </td> </tr> <tr id="section-132"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-132">#</a> </div> <p>Compile the IfNode as a ternary operator.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-133"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-133">#</a> </div> <h2>Faux-Nodes</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-134"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-134">#</a> </div> <h3>PushNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">PushNode = exports.PushNode =</span>
+ <span class="nx">wrap</span><span class="o">:</span> <span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">expressions</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">expr = </span><span class="nx">expressions</span><span class="p">.</span><span class="nx">unwrap</span><span class="p">()</span>
+ <span class="k">return</span> <span class="nx">expressions</span> <span class="k">if</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">isPureStatement</span><span class="p">()</span> <span class="o">or</span> <span class="nx">expr</span><span class="p">.</span><span class="nx">containsPureStatement</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="k">new</span> <span class="nx">CallNode</span><span class="p">(</span>
+ <span class="k">new</span> <span class="nx">ValueNode</span><span class="p">(</span><span class="nx">literal</span><span class="p">(</span><span class="nx">array</span><span class="p">),</span> <span class="p">[</span><span class="k">new</span> <span class="nx">AccessorNode</span><span class="p">(</span><span class="nx">literal</span><span class="p">(</span><span class="s1">'push'</span><span class="p">))]),</span> <span class="p">[</span><span class="nx">expr</span><span class="p">]</span>
+ <span class="p">)])</span></pre></div> </td> </tr> <tr id="section-135"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-135">#</a> </div> <p>Faux-nodes are never created by the grammar, but are used during code
+generation to generate other combinations of nodes. The <strong>PushNode</strong> creates
+the tree for <code>array.push(value)</code>, which is helpful for recording the result
+arrays from comprehensions.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-136"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-136">#</a> </div> <h3>ClosureNode</h3> </td> <td class="code"> <div class="highlight"><pre><span class="nv">ClosureNode = exports.ClosureNode =</span></pre></div> </td> </tr> <tr id="section-137"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-137">#</a> </div> <p>A faux-node used to wrap an expressions body in a closure.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">wrap</span><span class="o">:</span> <span class="p">(</span><span class="nx">expressions</span><span class="p">,</span> <span class="nx">statement</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">expressions</span> <span class="k">if</span> <span class="nx">expressions</span><span class="p">.</span><span class="nx">containsPureStatement</span><span class="p">()</span>
+ <span class="nv">func = </span><span class="k">new</span> <span class="nx">ParentheticalNode</span><span class="p">(</span><span class="k">new</span> <span class="nx">CodeNode</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">expressions</span><span class="p">])))</span>
+ <span class="nv">args = </span><span class="p">[]</span>
+ <span class="nv">mentionsArgs = </span><span class="nx">expressions</span><span class="p">.</span><span class="nx">contains</span> <span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">n</span> <span class="k">instanceof</span> <span class="nx">LiteralNode</span> <span class="o">and</span> <span class="p">(</span><span class="nx">n</span><span class="p">.</span><span class="nx">value</span> <span class="o">is</span> <span class="s1">'arguments'</span><span class="p">)</span>
+ <span class="nv">mentionsThis = </span><span class="nx">expressions</span><span class="p">.</span><span class="nx">contains</span> <span class="p">(</span><span class="nx">n</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">(</span><span class="nx">n</span> <span class="k">instanceof</span> <span class="nx">LiteralNode</span> <span class="o">and</span> <span class="p">(</span><span class="nx">n</span><span class="p">.</span><span class="nx">value</span> <span class="o">is</span> <span class="s1">'this'</span><span class="p">))</span> <span class="o">or</span>
+ <span class="p">(</span><span class="nx">n</span> <span class="k">instanceof</span> <span class="nx">CodeNode</span> <span class="o">and</span> <span class="nx">n</span><span class="p">.</span><span class="nx">bound</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">mentionsArgs</span> <span class="o">or</span> <span class="nx">mentionsThis</span>
+ <span class="nv">meth = </span><span class="nx">literal</span><span class="p">(</span><span class="k">if</span> <span class="nx">mentionsArgs</span> <span class="k">then</span> <span class="s1">'apply'</span> <span class="k">else</span> <span class="s1">'call'</span><span class="p">)</span>
+ <span class="nv">args = </span><span class="p">[</span><span class="nx">literal</span><span class="p">(</span><span class="s1">'this'</span><span class="p">)]</span>
+ <span class="nx">args</span><span class="p">.</span><span class="nx">push</span> <span class="nx">literal</span> <span class="s1">'arguments'</span> <span class="k">if</span> <span class="nx">mentionsArgs</span>
+ <span class="nv">func = </span><span class="k">new</span> <span class="nx">ValueNode</span> <span class="nx">func</span><span class="p">,</span> <span class="p">[</span><span class="k">new</span> <span class="nx">AccessorNode</span><span class="p">(</span><span class="nx">meth</span><span class="p">)]</span>
+ <span class="nv">call = </span><span class="k">new</span> <span class="nx">CallNode</span><span class="p">(</span><span class="nx">func</span><span class="p">,</span> <span class="nx">args</span><span class="p">)</span>
+ <span class="k">if</span> <span class="nx">statement</span> <span class="k">then</span> <span class="nx">Expressions</span><span class="p">.</span><span class="nx">wrap</span><span class="p">([</span><span class="nx">call</span><span class="p">])</span> <span class="k">else</span> <span class="nx">call</span></pre></div> </td> </tr> <tr id="section-138"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-138">#</a> </div> <p>Wrap the expressions body, unless it contains a pure statement,
+in which case, no dice. If the body mentions <code>this</code> or <code>arguments</code>,
+then make sure that the closure wrapper preserves the original values.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">UTILITIES =</span></pre></div> </td> </tr> <tr id="section-139"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-139">#</a> </div> <h2>Utility Functions</h2> </td> <td class="code"> <div class="highlight"><pre> <span class="k">extends</span><span class="o">:</span> <span class="s2">"""</span>
+<span class="s2"> function(child, parent) {</span>
+<span class="s2"> var ctor = function(){};</span>
+<span class="s2"> ctor.prototype = parent.prototype;</span>
+<span class="s2"> child.prototype = new ctor();</span>
+<span class="s2"> child.prototype.constructor = child;</span>
+<span class="s2"> if (typeof parent.extended === "</span><span class="nx">function</span><span class="s2">") parent.extended(child);</span>
+<span class="s2"> child.__super__ = parent.prototype;</span>
+<span class="s2"> }</span>
+<span class="s2"> """</span></pre></div> </td> </tr> <tr id="section-140"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-140">#</a> </div> <p>Correctly set up a prototype chain for inheritance, including a reference
+to the superclass for <code>super()</code> calls. See:
+<a href="http://closure-library.googlecode.com/svn/docs/closureGoogBase.js.source.html#line1206">goog.inherits</a>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">bind</span><span class="o">:</span> <span class="s2">"""</span>
+<span class="s2"> function(func, context) {</span>
+<span class="s2"> return function(){ return func.apply(context, arguments); };</span>
+<span class="s2"> }</span>
+<span class="s2"> """</span></pre></div> </td> </tr> <tr id="section-141"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-141">#</a> </div> <p>Create a function bound to the current value of "this".</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">hasProp</span><span class="o">:</span> <span class="s1">'Object.prototype.hasOwnProperty'</span>
+ <span class="nx">slice</span><span class="o">:</span> <span class="s1">'Array.prototype.slice'</span></pre></div> </td> </tr> <tr id="section-142"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-142">#</a> </div> <p>Shortcuts to speed up the lookup time for native functions.</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-143"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-143">#</a> </div> <h2>Constants</h2> </td> <td class="code"> <div class="highlight"><pre><span class="nv">TAB = </span><span class="s1">' '</span></pre></div> </td> </tr> <tr id="section-144"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-144">#</a> </div> <p>Tabs are two spaces for pretty printing.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">TRAILING_WHITESPACE = </span><span class="sr">/[ \t]+$/gm</span></pre></div> </td> </tr> <tr id="section-145"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-145">#</a> </div> <p>Trim out all trailing whitespace, so that the generated code plays nice
+with Git.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IDENTIFIER = </span><span class="sr">/^[a-zA-Z\$_](\w|\$)*$/</span>
+<span class="nv">NUMBER = </span><span class="sr">/^(((\b0(x|X)[0-9a-fA-F]+)|((\b[0-9]+(\.[0-9]+)?|\.[0-9]+)(e[+\-]?[0-9]+)?)))\b$/i</span>
+<span class="nv">SIMPLENUM = </span><span class="sr">/^-?\d+$/</span></pre></div> </td> </tr> <tr id="section-146"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-146">#</a> </div> <p>Keep these identifier regexes in sync with the Lexer.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">IS_STRING = </span><span class="sr">/^['"]/</span></pre></div> </td> </tr> <tr id="section-147"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-147">#</a> </div> <p>Is a literal value a string?</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-148"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-148">#</a> </div> <h2>Utility Functions</h2> </td> <td class="code"> <div class="highlight"><pre><span class="nv">literal = </span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">new</span> <span class="nx">LiteralNode</span><span class="p">(</span><span class="nx">name</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-149"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-149">#</a> </div> <p>Handy helper for a generating LiteralNode.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">utility = </span><span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">ref = </span><span class="s2">"__#{name}"</span>
+ <span class="nx">Scope</span><span class="p">.</span><span class="nx">root</span><span class="p">.</span><span class="nx">assign</span> <span class="nx">ref</span><span class="p">,</span> <span class="nx">UTILITIES</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span>
+ <span class="nx">ref</span>
+
+</pre></div> </td> </tr> <tr id="section-150"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-150">#</a> </div> <p>Helper for ensuring that utility functions are assigned at the top level.</p> </td> <td class="code"> <div class="highlight"><pre>undefined</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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="octowrap"> <a class="octothorpe" href="#section-2">#</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">-></span>
+ <span class="vi">@banner = </span><span class="nx">banner</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="octowrap"> <a class="octothorpe" href="#section-3">#</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 remaning 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">-></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">"unrecognized option: #{arg}"</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">i</span><span class="p">...</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span>
+ <span class="k">break</span>
+ <span class="nx">options</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</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">-></span>
+ <span class="nv">lines = </span><span class="p">[</span><span class="s1">'Available options:'</span><span class="p">]</span>
+ <span class="nx">lines</span><span class="p">.</span><span class="nx">unshift</span> <span class="s2">"#{@banner}\n"</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">></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">' '</span><span class="p">)</span> <span class="k">else</span> <span class="s1">''</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">', '</span> <span class="k">else</span> <span class="s1">' '</span>
+ <span class="nx">lines</span><span class="p">.</span><span class="nx">push</span> <span class="s1">' '</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">"\n#{ lines.join('\n') }\n"</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</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="octowrap"> <a class="octothorpe" href="#section-6">#</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="octowrap"> <a class="octothorpe" href="#section-7">#</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">-></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"><</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="octowrap"> <a class="octothorpe" href="#section-8">#</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="nx">options</span><span class="p">)</span> <span class="o">-></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="nx">options</span> <span class="o">or=</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="octowrap"> <a class="octothorpe" href="#section-9">#</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">-></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">'-'</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">''</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>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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> puts "#{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="octowrap"> <a class="octothorpe" href="#section-2">#</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">'./coffee-script'</span>
+<span class="nv">helpers = </span><span class="nx">require</span><span class="p">(</span><span class="s1">'./helpers'</span><span class="p">).</span><span class="nx">helpers</span>
+<span class="nv">readline = </span><span class="nx">require</span> <span class="s1">'readline'</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</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="octowrap"> <a class="octothorpe" href="#section-4">#</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">-></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-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</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">-></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">noWrap</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">globals</span><span class="o">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nx">fileName</span><span class="o">:</span> <span class="s1">'repl'</span>
+ <span class="nx">puts</span> <span class="nx">inspect</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">puts</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="nx">repl</span><span class="p">.</span><span class="nx">prompt</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</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">'coffee> '</span>
+<span class="nx">stdio</span><span class="p">.</span><span class="kc">on</span> <span class="s1">'data'</span><span class="p">,</span> <span class="p">(</span><span class="nx">buffer</span><span class="p">)</span> <span class="o">-></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">'close'</span><span class="p">,</span> <span class="o">-></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">'line'</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>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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="octowrap"> <a class="octothorpe" href="#section-2">#</a> </div> <p>Import the helpers we need.</p> </td> <td class="code"> <div class="highlight"><pre><span class="p">{</span><span class="nx">include</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./helpers'</span><span class="p">).</span><span class="nx">helpers</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</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="nv">exports.Rewriter = </span><span class="nx">class</span> <span class="nx">Rewriter</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</a> </div> <p>Helpful snippet for debugging:
+ puts (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-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</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">-></span>
+ <span class="vi">@tokens = </span><span class="nx">tokens</span>
+ <span class="nx">@adjustComments</span><span class="p">()</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-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</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">-></span>
+ <span class="nv">i = </span><span class="mi">0</span>
+ <span class="nx">loop</span>
+ <span class="k">break</span> <span class="nx">unless</span> <span class="nx">@tokens</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span>
+ <span class="nv">move = </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">@tokens</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">i</span>
+ <span class="nx">i</span> <span class="o">+=</span> <span class="nx">move</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">-></span>
+ <span class="nv">levels = </span><span class="mi">0</span>
+ <span class="nx">loop</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"><</span> <span class="mi">0</span>
+ <span class="nx">levels</span> <span class="o">+=</span> <span class="mi">1</span> <span class="k">if</span> <span class="nx">include</span> <span class="nx">EXPRESSION_START</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">levels</span> <span class="o">-=</span> <span class="mi">1</span> <span class="k">if</span> <span class="nx">include</span> <span class="nx">EXPRESSION_END</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">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-7"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-7">#</a> </div> <p>Massage newlines and indentations so that comments don't have to be
+correctly indented, or appear on a line of their own.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">adjustComments</span><span class="o">:</span> <span class="o">-></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">-></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">'HERECOMMENT'</span>
+ <span class="p">[</span><span class="nx">before</span><span class="p">,</span> <span class="nx">prev</span><span class="p">,</span> <span class="nx">post</span><span class="p">,</span> <span class="nx">after</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nx">@tokens</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="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">@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">@tokens</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">if</span> <span class="nx">after</span> <span class="o">and</span> <span class="nx">after</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'INDENT'</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">1</span>
+ <span class="k">if</span> <span class="nx">before</span> <span class="o">and</span> <span class="nx">before</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'OUTDENT'</span> <span class="o">and</span> <span class="nx">post</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="o">is</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">'TERMINATOR'</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">1</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">after</span>
+ <span class="k">else</span> <span class="k">if</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="o">not</span> <span class="k">in</span> <span class="p">[</span><span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s1">'INDENT'</span><span class="p">,</span> <span class="s1">'OUTDENT'</span><span class="p">]</span>
+ <span class="k">if</span> <span class="nx">post</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">'TERMINATOR'</span> <span class="o">and</span> <span class="nx">after</span> <span class="o">and</span> <span class="nx">after</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'OUTDENT'</span>
+ <span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</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="mi">0</span><span class="p">,</span> <span class="nx">@tokens</span><span class="p">.</span><span class="nx">splice</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="mi">2</span><span class="p">)...)</span>
+ <span class="k">if</span> <span class="nx">@tokens</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="mi">0</span><span class="p">]</span> <span class="o">isnt</span> <span class="s1">'TERMINATOR'</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="p">[</span><span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s2">"\n"</span><span class="p">,</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</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="p">[</span><span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s2">"\n"</span><span class="p">,</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
+ <span class="k">return</span> <span class="mi">2</span>
+ <span class="k">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-8">#</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">-></span>
+ <span class="nx">@tokens</span><span class="p">.</span><span class="nx">shift</span><span class="p">()</span> <span class="k">while</span> <span class="nx">@tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">and</span> <span class="nx">@tokens</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'TERMINATOR'</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</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">-></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">-></span>
+ <span class="k">return</span> <span class="mi">1</span> <span class="nx">unless</span> <span class="nx">include</span><span class="p">(</span><span class="nx">EXPRESSION_CLOSE</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">1</span><span class="p">))</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="o">is</span> <span class="s1">'TERMINATOR'</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></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</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">-></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">-></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">'CALL_START'</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">-></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="k">in</span> <span class="p">[</span><span class="s1">')'</span><span class="p">,</span> <span class="s1">'CALL_END'</span><span class="p">])</span> <span class="o">or</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">'OUTDENT'</span> <span class="o">and</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="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">')'</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">-></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">'OUTDENT'</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">idx</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'CALL_END'</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">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-11">#</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">-></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">-></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">'INDEX_START'</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">-></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">']'</span><span class="p">,</span> <span class="s1">'INDEX_END'</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">-></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">'INDEX_END'</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">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-12">#</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">-></span>
+ <span class="nv">stack = </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">-></span>
+ <span class="k">if</span> <span class="nx">include</span> <span class="nx">EXPRESSION_START</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">stack</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="k">if</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">'INDENT'</span> <span class="o">and</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">1</span><span class="p">)</span> <span class="o">is</span> <span class="s1">'{'</span><span class="p">))</span> <span class="k">then</span> <span class="s1">'{'</span> <span class="k">else</span> <span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
+ <span class="k">if</span> <span class="nx">include</span> <span class="nx">EXPRESSION_END</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">stack</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span>
+ <span class="nv">last = </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="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">':'</span> <span class="o">and</span> <span class="p">(</span><span class="o">not</span> <span class="nx">last</span> <span class="o">or</span> <span class="nx">last</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">isnt</span> <span class="s1">'{'</span><span class="p">)</span>
+ <span class="nx">stack</span><span class="p">.</span><span class="nx">push</span> <span class="s1">'{'</span>
+ <span class="nv">idx = </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="s1">'@'</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">if</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">'HERECOMMENT'</span>
+ <span class="nv">tok = </span><span class="p">[</span><span class="s1">'{'</span><span class="p">,</span> <span class="s1">'{'</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="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">-></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">slice</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">4</span><span class="p">)</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="s1">'HERECOMMENT'</span> <span class="k">in</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">1</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">1</span><span class="p">)]</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="k">in</span> <span class="p">[</span><span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s1">'OUTDENT'</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">and</span> <span class="nx">two</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">':'</span><span class="p">)</span> <span class="o">or</span> <span class="p">(</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">is</span> <span class="s1">'@'</span> <span class="o">and</span> <span class="nx">three</span> <span class="o">and</span> <span class="nx">three</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">':'</span><span class="p">)))</span> <span class="o">or</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">','</span> <span class="o">and</span> <span class="nx">one</span> <span class="o">and</span> <span class="p">(</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">'IDENTIFIER'</span><span class="p">,</span> <span class="s1">'STRING'</span><span class="p">,</span> <span class="s1">'@'</span><span class="p">,</span> <span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s1">'OUTDENT'</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">-></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">'}'</span><span class="p">,</span> <span class="s1">'}'</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="mi">2</span><span class="p">,</span> <span class="nx">condition</span><span class="p">,</span> <span class="nx">action</span>
+ <span class="k">return</span> <span class="mi">2</span>
+ <span class="k">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-13">#</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">-></span>
+ <span class="nv">classLine = </span><span class="kc">no</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">-></span>
+ <span class="nv">classLine = </span><span class="kc">yes</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">'CLASS'</span>
+ <span class="nv">prev = </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="nv">next = </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="nv">idx = </span><span class="mi">1</span>
+ <span class="nv">callObject = </span><span class="o">not</span> <span class="nx">classLine</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="o">is</span> <span class="s1">'INDENT'</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">'{'</span> <span class="o">and</span> <span class="nx">prev</span> <span class="o">and</span> <span class="nx">include</span><span class="p">(</span><span class="nx">IMPLICIT_FUNC</span><span class="p">,</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
+ <span class="nv">idx = </span><span class="mi">2</span> <span class="k">if</span> <span class="nx">callObject</span>
+ <span class="nv">seenSingle = </span><span class="kc">no</span>
+ <span class="nv">classLine = </span><span class="kc">no</span> <span class="k">if</span> <span class="nx">include</span><span class="p">(</span><span class="nx">LINEBREAKS</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="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">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'?'</span>
+ <span class="k">if</span> <span class="nx">prev</span> <span class="o">and</span> <span class="p">(</span><span class="nx">prev</span><span class="p">.</span><span class="nx">spaced</span> <span class="o">and</span> <span class="p">(</span><span class="nx">include</span><span class="p">(</span><span class="nx">IMPLICIT_FUNC</span><span class="p">,</span> <span class="nx">prev</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">or</span> <span class="nx">prev</span><span class="p">.</span><span class="nx">call</span><span class="p">)</span> <span class="o">and</span> <span class="nx">include</span><span class="p">(</span><span class="nx">IMPLICIT_CALL</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">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">'UNARY'</span> <span class="o">and</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">1</span><span class="p">)</span> <span class="k">in</span> <span class="p">[</span><span class="s1">'IN'</span><span class="p">,</span> <span class="s1">'OF'</span><span class="p">,</span> <span class="s1">'INSTANCEOF'</span><span class="p">])))</span> <span class="o">or</span> <span class="nx">callObject</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">'CALL_START'</span><span class="p">,</span> <span class="s1">'('</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">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">-></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="nv">seenSingle = </span><span class="kc">yes</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="p">[</span><span class="s1">'IF'</span><span class="p">,</span> <span class="s1">'ELSE'</span><span class="p">,</span> <span class="s1">'UNLESS'</span><span class="p">,</span> <span class="s1">'->'</span><span class="p">,</span> <span class="s1">'=>'</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="p">(</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">@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="mi">0</span><span class="p">]</span> <span class="o">isnt</span> <span class="s1">','</span> <span class="o">and</span> <span class="nx">include</span><span class="p">(</span><span class="nx">IMPLICIT_END</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">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">'INDENT'</span> <span class="o">and</span> <span class="p">(</span><span class="nx">include</span><span class="p">(</span><span class="nx">IMPLICIT_BLOCK</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">1</span><span class="p">))</span> <span class="o">or</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="s1">'CLASS'</span> <span class="o">or</span> <span class="p">(</span><span class="nx">post</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">'{'</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">'PROPERTY_ACCESS'</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">'OUTDENT'</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">-></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">'OUTDENT'</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">'CALL_END'</span><span class="p">,</span> <span class="s1">')'</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="nx">idx</span><span class="p">,</span> <span class="nx">condition</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">'FUNC_EXIST'</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">'?'</span>
+ <span class="k">return</span> <span class="mi">2</span>
+ <span class="k">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-14">#</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">-></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">-></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">'ELSE'</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">'OUTDENT'</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">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'CATCH'</span> <span class="o">and</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">is</span> <span class="s1">'TERMINATOR'</span> <span class="o">or</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="s1">'FINALLY'</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">include</span><span class="p">(</span><span class="nx">SINGLE_LINERS</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">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">'INDENT'</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">'ELSE'</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">'IF'</span><span class="p">)</span>
+ <span class="nv">starter = </span><span class="nx">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">'THEN'</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">-></span>
+ <span class="p">(</span><span class="nx">include</span><span class="p">(</span><span class="nx">SINGLE_CLOSERS</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">and</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">';'</span><span class="p">)</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">'ELSE'</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">'IF'</span><span class="p">,</span> <span class="s1">'THEN'</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">-></span>
+ <span class="nv">idx = </span><span class="k">if</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="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">','</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="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">token</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'THEN'</span>
+ <span class="k">return</span> <span class="mi">2</span>
+ <span class="k">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-15">#</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">-></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">-></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="p">[</span><span class="s1">'IF'</span><span class="p">,</span> <span class="s1">'UNLESS'</span><span class="p">]</span>
+ <span class="nv">original = </span><span class="nx">token</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">-></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">'TERMINATOR'</span><span class="p">,</span> <span class="s1">'INDENT'</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">-></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">'POST_'</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">'INDENT'</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">return</span> <span class="mi">1</span>
+ <span class="k">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-16">#</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">-></span>
+ <span class="nv">levels = </span><span class="p">{}</span>
+ <span class="nv">openLine = </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">-></span>
+ <span class="k">for</span> <span class="nx">pair</span> <span class="k">in</span> <span class="nx">pairs</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="o">=</span> <span class="nx">pair</span>
+ <span class="nx">levels</span><span class="p">[</span><span class="nx">open</span><span class="p">]</span> <span class="o">or=</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="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="mi">0</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">1</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">1</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="nx">close</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">"too many #{token[1]} on line #{token[2] + 1}"</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="mi">0</span>
+ <span class="k">return</span> <span class="mi">1</span>
+ <span class="nv">unclosed = </span><span class="nx">key</span> <span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span> <span class="k">of</span> <span class="nx">levels</span> <span class="k">when</span> <span class="nx">value</span> <span class="o">></span> <span class="mi">0</span>
+ <span class="k">if</span> <span class="nx">unclosed</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nv">open = </span><span class="nx">unclosed</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+ <span class="nv">line = </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="mi">1</span>
+ <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span> <span class="s2">"unclosed #{open} on line #{line}"</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-17">#</a> </div> <p>We'd like to support syntax like this:</p>
+
+<pre><code>el.click((event) ->
+ 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">-></span>
+ <span class="nv">stack = </span><span class="p">[]</span>
+ <span class="nv">debt = </span><span class="p">{}</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="p">)</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">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="o">-></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">inv = </span><span class="nx">INVERSES</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="k">if</span> <span class="nx">include</span> <span class="nx">EXPRESSION_START</span><span class="p">,</span> <span class="nx">tag</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">else</span> <span class="k">if</span> <span class="nx">include</span> <span class="nx">EXPRESSION_END</span><span class="p">,</span> <span class="nx">tag</span>
+ <span class="k">if</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">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="k">else</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">'INDENT'</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">@tokens</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">?</span><span class="p">[</span><span class="mi">0</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="p">(</span><span class="nx">match</span><span class="p">)</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="k">return</span> <span class="mi">1</span>
+ <span class="k">else</span>
+ <span class="k">return</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-18">#</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">-></span>
+ <span class="p">[[</span><span class="s1">'INDENT'</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">'OUTDENT'</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-19"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-19">#</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">-></span>
+ <span class="nx">@tokens</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">and</span> <span class="nx">@tokens</span><span class="p">[</span><span class="nx">i</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-20">#</a> </div> <h2>Constants</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-21">#</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="s1">'('</span><span class="p">,</span> <span class="s1">')'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'['</span><span class="p">,</span> <span class="s1">']'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'{'</span><span class="p">,</span> <span class="s1">'}'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'INDENT'</span><span class="p">,</span> <span class="s1">'OUTDENT'</span><span class="p">],</span>
+ <span class="p">[</span><span class="s1">'PARAM_START'</span><span class="p">,</span> <span class="s1">'PARAM_END'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'CALL_START'</span><span class="p">,</span> <span class="s1">'CALL_END'</span><span class="p">],</span> <span class="p">[</span><span class="s1">'INDEX_START'</span><span class="p">,</span> <span class="s1">'INDEX_END'</span><span class="p">]]</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-22">#</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>
+<span class="k">for</span> <span class="nx">pair</span> <span class="k">in</span> <span class="nx">BALANCED_PAIRS</span>
+ <span class="nx">INVERSES</span><span class="p">[</span><span class="nx">pair</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="nx">pair</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+ <span class="nx">INVERSES</span><span class="p">[</span><span class="nx">pair</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="nx">pair</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-23">#</a> </div> <p>The tokens that signal the start of a balanced pair.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">EXPRESSION_START = </span><span class="nx">pair</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="nx">pair</span> <span class="k">in</span> <span class="nx">BALANCED_PAIRS</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-24">#</a> </div> <p>The tokens that signal the end of a balanced pair.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">EXPRESSION_END = </span><span class="nx">pair</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="nx">pair</span> <span class="k">in</span> <span class="nx">BALANCED_PAIRS</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-25">#</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">'CATCH'</span><span class="p">,</span> <span class="s1">'WHEN'</span><span class="p">,</span> <span class="s1">'ELSE'</span><span class="p">,</span> <span class="s1">'FINALLY'</span><span class="p">].</span><span class="nx">concat</span> <span class="nx">EXPRESSION_END</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-26">#</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">'IDENTIFIER'</span><span class="p">,</span> <span class="s1">'SUPER'</span><span class="p">,</span> <span class="s1">')'</span><span class="p">,</span> <span class="s1">'CALL_END'</span><span class="p">,</span> <span class="s1">']'</span><span class="p">,</span> <span class="s1">'INDEX_END'</span><span class="p">,</span> <span class="s1">'@'</span><span class="p">,</span> <span class="s1">'THIS'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-27">#</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">'IDENTIFIER'</span><span class="p">,</span> <span class="s1">'NUMBER'</span><span class="p">,</span> <span class="s1">'STRING'</span><span class="p">,</span> <span class="s1">'JS'</span><span class="p">,</span> <span class="s1">'REGEX'</span><span class="p">,</span> <span class="s1">'NEW'</span><span class="p">,</span> <span class="s1">'PARAM_START'</span><span class="p">,</span> <span class="s1">'CLASS'</span><span class="p">,</span>
+ <span class="s1">'IF'</span><span class="p">,</span> <span class="s1">'UNLESS'</span><span class="p">,</span> <span class="s1">'TRY'</span><span class="p">,</span> <span class="s1">'SWITCH'</span><span class="p">,</span> <span class="s1">'THIS'</span><span class="p">,</span> <span class="s1">'NULL'</span><span class="p">,</span> <span class="s1">'UNARY'</span>
+ <span class="s1">'TRUE'</span><span class="p">,</span> <span class="s1">'FALSE'</span><span class="p">,</span> <span class="s1">'YES'</span><span class="p">,</span> <span class="s1">'NO'</span><span class="p">,</span> <span class="s1">'ON'</span><span class="p">,</span> <span class="s1">'OFF'</span><span class="p">,</span>
+ <span class="s1">'@'</span><span class="p">,</span> <span class="s1">'->'</span><span class="p">,</span> <span class="s1">'=>'</span><span class="p">,</span> <span class="s1">'['</span><span class="p">,</span> <span class="s1">'('</span><span class="p">,</span> <span class="s1">'{'</span>
+<span class="p">]</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-28">#</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">'->'</span><span class="p">,</span> <span class="s1">'=>'</span><span class="p">,</span> <span class="s1">'{'</span><span class="p">,</span> <span class="s1">'['</span><span class="p">,</span> <span class="s1">','</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-29">#</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">'POST_IF'</span><span class="p">,</span> <span class="s1">'POST_UNLESS'</span><span class="p">,</span> <span class="s1">'FOR'</span><span class="p">,</span> <span class="s1">'WHILE'</span><span class="p">,</span> <span class="s1">'UNTIL'</span><span class="p">,</span> <span class="s1">'LOOP'</span><span class="p">,</span> <span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s1">'INDENT'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-30">#</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">'ELSE'</span><span class="p">,</span> <span class="s2">"->"</span><span class="p">,</span> <span class="s2">"=>"</span><span class="p">,</span> <span class="s1">'TRY'</span><span class="p">,</span> <span class="s1">'FINALLY'</span><span class="p">,</span> <span class="s1">'THEN'</span><span class="p">]</span>
+<span class="nv">SINGLE_CLOSERS = </span><span class="p">[</span><span class="s1">'TERMINATOR'</span><span class="p">,</span> <span class="s1">'CATCH'</span><span class="p">,</span> <span class="s1">'FINALLY'</span><span class="p">,</span> <span class="s1">'ELSE'</span><span class="p">,</span> <span class="s1">'OUTDENT'</span><span class="p">,</span> <span class="s1">'LEADING_WHEN'</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-31">#</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">'TERMINATOR'</span><span class="p">,</span> <span class="s1">'INDENT'</span><span class="p">,</span> <span class="s1">'OUTDENT'</span><span class="p">]</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!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 … <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="octowrap"> <a class="octothorpe" href="#section-1">#</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="octowrap"> <a class="octothorpe" href="#section-2">#</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="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'./helpers'</span><span class="p">).</span><span class="nx">helpers</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="octowrap"> <a class="octothorpe" href="#section-3">#</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="octowrap"> <a class="octothorpe" href="#section-4">#</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">-></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">=</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="vi">@variables = </span><span class="p">{}</span>
+ <span class="k">if</span> <span class="nx">@parent</span>
+ <span class="vi">@garbage = </span><span class="nx">@parent</span><span class="p">.</span><span class="nx">garbage</span>
+ <span class="k">else</span>
+ <span class="vi">@garbage = </span><span class="p">[]</span>
+ <span class="nv">Scope.root = </span><span class="k">this</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</a> </div> <p>Create a new garbage level</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">startLevel</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@garbage</span><span class="p">.</span><span class="nx">push</span> <span class="p">[]</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</a> </div> <p>Return to the previous garbage level and erase referenced temporary
+variables in current level from scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">endLevel</span><span class="o">:</span> <span class="o">-></span>
+ <span class="p">(</span><span class="nx">@variables</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'reuse'</span><span class="p">)</span> <span class="k">for</span> <span class="nx">name</span> <span class="k">in</span> <span class="nx">@garbage</span><span class="p">.</span><span class="nx">pop</span><span class="p">()</span> <span class="k">when</span> <span class="nx">@variables</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">is</span> <span class="s1">'var'</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-7">#</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">-></span>
+ <span class="k">return</span> <span class="kc">true</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">@variables</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'var'</span>
+ <span class="kc">false</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-8">#</a> </div> <p>Test variables and return true the first time fn(v, k) returns true</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">any</span><span class="o">:</span> <span class="p">(</span><span class="nx">fn</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">for</span> <span class="nx">v</span><span class="p">,</span> <span class="nx">k</span> <span class="k">of</span> <span class="nx">@variables</span> <span class="k">when</span> <span class="nx">fn</span><span class="p">(</span><span class="nx">v</span><span class="p">,</span> <span class="nx">k</span><span class="p">)</span>
+ <span class="k">return</span> <span class="kc">true</span>
+ <span class="k">return</span> <span class="kc">false</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</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">-></span>
+ <span class="nx">@variables</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'param'</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</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">options</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">immediate = </span><span class="nb">Object</span><span class="o">::</span><span class="nx">hasOwnProperty</span><span class="p">.</span><span class="nx">call</span> <span class="nx">@variables</span><span class="p">,</span> <span class="nx">name</span>
+ <span class="k">return</span> <span class="nx">immediate</span> <span class="k">if</span> <span class="nx">immediate</span> <span class="o">or</span> <span class="p">(</span><span class="nx">options</span> <span class="o">and</span> <span class="nx">options</span><span class="p">.</span><span class="nx">immediate</span><span class="p">)</span>
+ <span class="o">!!</span><span class="p">(</span><span class="nx">@parent</span> <span class="o">and</span> <span class="nx">@parent</span><span class="p">.</span><span class="nx">check</span><span class="p">(</span><span class="nx">name</span><span class="p">))</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-11">#</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">type</span><span class="p">,</span> <span class="nx">index</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">type</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">1</span>
+ <span class="s1">'_'</span> <span class="o">+</span> <span class="nx">type</span> <span class="o">+</span> <span class="k">if</span> <span class="nx">index</span> <span class="o">></span> <span class="mi">1</span> <span class="k">then</span> <span class="nx">index</span> <span class="k">else</span> <span class="s1">''</span>
+ <span class="k">else</span>
+ <span class="s1">'_'</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">type</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">'a'</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-12">#</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">-></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="o">and</span> <span class="nx">@variables</span><span class="p">[</span><span class="nx">temp</span><span class="p">]</span> <span class="o">isnt</span> <span class="s1">'reuse'</span>
+ <span class="nx">@variables</span><span class="p">[</span><span class="nx">temp</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'var'</span>
+ <span class="nx">@garbage</span><span class="p">[</span><span class="nx">@garbage</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="nx">push</span> <span class="nx">temp</span> <span class="k">if</span> <span class="nx">@garbage</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nx">temp</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-13">#</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">-></span>
+ <span class="nx">@variables</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</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></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-14">#</a> </div> <p>Does this scope reference any variables that need to be declared in the
+given function body?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">hasDeclarations</span><span class="o">:</span> <span class="p">(</span><span class="nx">body</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">body</span> <span class="o">is</span> <span class="nx">@expressions</span> <span class="o">and</span> <span class="nx">@any</span> <span class="p">(</span><span class="nx">k</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="o">-></span> <span class="nx">val</span> <span class="o">is</span> <span class="s1">'var'</span> <span class="o">or</span> <span class="nx">val</span> <span class="o">is</span> <span class="s1">'reuse'</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-15">#</a> </div> <p>Does this scope reference any assignments that need to be declared at the
+top of the given function body?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">hasAssignments</span><span class="o">:</span> <span class="p">(</span><span class="nx">body</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">body</span> <span class="o">is</span> <span class="nx">@expressions</span> <span class="o">and</span> <span class="nx">@any</span> <span class="p">(</span><span class="nx">k</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="o">-></span> <span class="nx">val</span><span class="p">.</span><span class="nx">assigned</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-16">#</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">-></span>
+ <span class="p">(</span><span class="nx">key</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">@variables</span> <span class="k">when</span> <span class="nx">val</span> <span class="o">is</span> <span class="s1">'var'</span> <span class="o">or</span> <span class="nx">val</span> <span class="o">is</span> <span class="s1">'reuse'</span><span class="p">).</span><span class="nx">sort</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-17">#</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">-></span>
+ <span class="s2">"#{key} = #{val.value}"</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">@variables</span> <span class="k">when</span> <span class="nx">val</span><span class="p">.</span><span class="nx">assigned</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-18">#</a> </div> <p>Compile the JavaScript for all of the variable declarations in this scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compiledDeclarations</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@declaredVariables</span><span class="p">().</span><span class="nx">join</span> <span class="s1">', '</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-19">#</a> </div> <p>Compile the JavaScript forall of the variable assignments in this scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">compiledAssignments</span><span class="o">:</span> <span class="o">-></span>
+ <span class="nx">@assignedVariables</span><span class="p">().</span><span class="nx">join</span> <span class="s1">', '</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html> <html> <head> <title>underscore.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> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> underscore.coffee </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-1">#</a> </div> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-2">#</a> </div> <p><strong>Underscore.coffee
+(c) 2010 Jeremy Ashkenas, DocumentCloud Inc.</strong>
+Underscore is freely distributable under the terms of the
+<a href="http://en.wikipedia.org/wiki/MIT_License">MIT license</a>.
+Portions of Underscore are inspired by or borrowed from
+<a href="http://prototypejs.org/api">Prototype.js</a>, Oliver Steele's
+<a href="http://osteele.com">Functional</a>, and John Resig's
+<a href="http://ejohn.com">Micro-Templating</a>.
+For all details and documentation:
+http://documentcloud.github.com/underscore/</p> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <h2>Baseline setup</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</a> </div> <p>Establish the root object, <code>window</code> in the browser, or <code>global</code> on the server.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">root = </span><span class="k">this</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-5">#</a> </div> <p>Save the previous value of the <code>_</code> variable.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">previousUnderscore = </span><span class="nx">root</span><span class="p">.</span><span class="nx">_</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-6">#</a> </div> <p>Establish the object that gets thrown to break out of a loop iteration.
+<code>StopIteration</code> is SOP on Mozilla.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">breaker = </span><span class="k">if</span> <span class="k">typeof</span><span class="p">(</span><span class="nx">StopIteration</span><span class="p">)</span> <span class="o">is</span> <span class="s1">'undefined'</span> <span class="k">then</span> <span class="s1">'__break__'</span> <span class="k">else</span> <span class="nx">StopIteration</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-7">#</a> </div> <p>Helper function to escape <strong>RegExp</strong> contents, because JS doesn't have one.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">escapeRegExp = </span><span class="p">(</span><span class="nx">string</span><span class="p">)</span> <span class="o">-></span> <span class="nx">string</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/([.*+?^${}()|[\]\/\\])/g</span><span class="p">,</span> <span class="s1">'\\$1'</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-8">#</a> </div> <p>Save bytes in the minified (but not gzipped) version:</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">ArrayProto = </span><span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span>
+ <span class="nv">ObjProto = </span><span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-9">#</a> </div> <p>Create quick reference variables for speed access to core prototypes.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">slice = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">slice</span>
+ <span class="nv">unshift = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">unshift</span>
+ <span class="nv">toString = </span><span class="nx">ObjProto</span><span class="p">.</span><span class="nx">toString</span>
+ <span class="nv">hasOwnProperty = </span><span class="nx">ObjProto</span><span class="p">.</span><span class="nx">hasOwnProperty</span>
+ <span class="nv">propertyIsEnumerable = </span><span class="nx">ObjProto</span><span class="p">.</span><span class="nx">propertyIsEnumerable</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-10">#</a> </div> <p>All <strong>ECMA5</strong> native implementations we hope to use are declared here.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">nativeForEach = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">forEach</span>
+ <span class="nv">nativeMap = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">map</span>
+ <span class="nv">nativeReduce = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">reduce</span>
+ <span class="nv">nativeReduceRight = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">reduceRight</span>
+ <span class="nv">nativeFilter = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">filter</span>
+ <span class="nv">nativeEvery = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">every</span>
+ <span class="nv">nativeSome = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">some</span>
+ <span class="nv">nativeIndexOf = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">indexOf</span>
+ <span class="nv">nativeLastIndexOf = </span><span class="nx">ArrayProto</span><span class="p">.</span><span class="nx">lastIndexOf</span>
+ <span class="nv">nativeIsArray = </span><span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span>
+ <span class="nv">nativeKeys = </span><span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-11">#</a> </div> <p>Create a safe reference to the Underscore object for use below.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_ = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="k">new</span> <span class="nx">wrapper</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-12">#</a> </div> <p>Export the Underscore object for <strong>CommonJS</strong>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="k">typeof</span><span class="p">(</span><span class="nx">exports</span><span class="p">)</span> <span class="o">!=</span> <span class="s1">'undefined'</span> <span class="k">then</span> <span class="nv">exports._ = </span><span class="nx">_</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-13">#</a> </div> <p>Export Underscore to global scope.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">root._ = </span><span class="nx">_</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-14">#</a> </div> <p>Current version.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.VERSION = </span><span class="s1">'1.1.0'</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-15">#</a> </div> <h2>Collection Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-16">#</a> </div> <p>The cornerstone, an <strong>each</strong> implementation.
+Handles objects implementing <strong>forEach</strong>, arrays, and raw objects.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.each = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">try</span>
+ <span class="k">if</span> <span class="nx">nativeForEach</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">forEach</span> <span class="o">is</span> <span class="nx">nativeForEach</span>
+ <span class="nx">obj</span><span class="p">.</span><span class="nx">forEach</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span>
+ <span class="k">else</span> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isNumber</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">length</span>
+ <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">i</span><span class="p">],</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">obj</span><span class="p">)</span> <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">obj</span><span class="p">.</span><span class="nx">length</span><span class="p">]</span>
+ <span class="k">else</span>
+ <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">val</span><span class="p">,</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">obj</span><span class="p">)</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">obj</span>
+ <span class="k">catch</span> <span class="nx">e</span>
+ <span class="k">throw</span> <span class="nx">e</span> <span class="k">if</span> <span class="nx">e</span> <span class="o">isnt</span> <span class="nx">breaker</span>
+ <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-17">#</a> </div> <p>Return the results of applying the iterator to each element. Use JavaScript
+1.6's version of <strong>map</strong>, if possible.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.map = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="k">if</span> <span class="nx">nativeMap</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">map</span> <span class="o">is</span> <span class="nx">nativeMap</span>
+ <span class="nv">results = </span><span class="p">[]</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">results</span><span class="p">.</span><span class="nx">push</span> <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span>
+ <span class="nx">results</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-18">#</a> </div> <p><strong>Reduce</strong> builds up a single result from a list of values. Also known as
+<strong>inject</strong>, or <strong>foldl</strong>. Uses JavaScript 1.8's version of <strong>reduce</strong>, if possible.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.reduce = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">memo</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">nativeReduce</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">reduce</span> <span class="o">is</span> <span class="nx">nativeReduce</span>
+ <span class="nv">iterator = </span><span class="nx">_</span><span class="p">.</span><span class="nx">bind</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span> <span class="k">if</span> <span class="nx">context</span>
+ <span class="k">return</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">reduce</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">memo</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">memo = </span><span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">memo</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span>
+ <span class="nx">memo</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-19">#</a> </div> <p>The right-associative version of <strong>reduce</strong>, also known as <strong>foldr</strong>. Uses
+JavaScript 1.8's version of <strong>reduceRight</strong>, if available.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.reduceRight = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">memo</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">nativeReduceRight</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">reduceRight</span> <span class="o">is</span> <span class="nx">nativeReduceRight</span>
+ <span class="nv">iterator = </span><span class="nx">_</span><span class="p">.</span><span class="nx">bind</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span> <span class="k">if</span> <span class="nx">context</span>
+ <span class="k">return</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">reduceRight</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">memo</span>
+ <span class="nv">reversed = </span><span class="nx">_</span><span class="p">.</span><span class="nx">clone</span><span class="p">(</span><span class="nx">_</span><span class="p">.</span><span class="nx">toArray</span><span class="p">(</span><span class="nx">obj</span><span class="p">)).</span><span class="nx">reverse</span><span class="p">()</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">reduce</span> <span class="nx">reversed</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">memo</span><span class="p">,</span> <span class="nx">context</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-20">#</a> </div> <p>Return the first value which passes a truth test.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.detect = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">result = </span><span class="kc">null</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span>
+ <span class="nv">result = </span><span class="nx">value</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">breakLoop</span><span class="p">()</span>
+ <span class="nx">result</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-21">#</a> </div> <p>Return all the elements that pass a truth test. Use JavaScript 1.6's
+<strong>filter</strong>, if it exists.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.filter = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">filter</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span> <span class="k">if</span> <span class="nx">nativeFilter</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">filter</span> <span class="o">is</span> <span class="nx">nativeFilter</span>
+ <span class="nv">results = </span><span class="p">[]</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">results</span><span class="p">.</span><span class="nx">push</span> <span class="nx">value</span> <span class="k">if</span> <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span>
+ <span class="nx">results</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-22">#</a> </div> <p>Return all the elements for which a truth test fails.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.reject = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">results = </span><span class="p">[]</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">results</span><span class="p">.</span><span class="nx">push</span> <span class="nx">value</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span> <span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span>
+ <span class="nx">results</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-23">#</a> </div> <p>Determine whether all of the elements match a truth test. Delegate to
+JavaScript 1.6's <strong>every</strong>, if it is present.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.every = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">iterator</span> <span class="o">||=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">identity</span>
+ <span class="k">return</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">every</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span> <span class="k">if</span> <span class="nx">nativeEvery</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">every</span> <span class="o">is</span> <span class="nx">nativeEvery</span>
+ <span class="nv">result = </span><span class="kc">true</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">breakLoop</span><span class="p">()</span> <span class="nx">unless</span> <span class="p">(</span><span class="nv">result = </span><span class="nx">result</span> <span class="o">and</span> <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">))</span>
+ <span class="nx">result</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-24">#</a> </div> <p>Determine if at least one element in the object matches a truth test. Use
+JavaScript 1.6's <strong>some</strong>, if it exists.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.some = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">iterator</span> <span class="o">||=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">identity</span>
+ <span class="k">return</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">some</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span> <span class="k">if</span> <span class="nx">nativeSome</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">some</span> <span class="o">is</span> <span class="nx">nativeSome</span>
+ <span class="nv">result = </span><span class="kc">false</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">breakLoop</span><span class="p">()</span> <span class="k">if</span> <span class="p">(</span><span class="nv">result = </span><span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">))</span>
+ <span class="nx">result</span></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-25">#</a> </div> <p>Determine if a given value is included in the array or object,
+based on <code>===</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.include = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">target</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">_</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">target</span><span class="p">)</span> <span class="o">isnt</span> <span class="o">-</span><span class="mi">1</span> <span class="k">if</span> <span class="nx">nativeIndexOf</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">indexOf</span> <span class="o">is</span> <span class="nx">nativeIndexOf</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">obj</span>
+ <span class="k">return</span> <span class="kc">true</span> <span class="k">if</span> <span class="nx">val</span> <span class="o">is</span> <span class="nx">target</span>
+ <span class="kc">false</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-26">#</a> </div> <p>Invoke a method with arguments on every item in a collection.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.invoke = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">method</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">args = </span><span class="nx">_</span><span class="p">.</span><span class="nx">rest</span> <span class="nx">arguments</span><span class="p">,</span> <span class="mi">2</span>
+ <span class="p">(</span><span class="k">if</span> <span class="nx">method</span> <span class="k">then</span> <span class="nx">val</span><span class="p">[</span><span class="nx">method</span><span class="p">]</span> <span class="k">else</span> <span class="nx">val</span><span class="p">).</span><span class="nx">apply</span><span class="p">(</span><span class="nx">val</span><span class="p">,</span> <span class="nx">args</span><span class="p">)</span> <span class="k">for</span> <span class="nx">val</span> <span class="k">in</span> <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-27">#</a> </div> <p>Convenience version of a common use case of <strong>map</strong>: fetching a property.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.pluck = </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">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="o">-></span> <span class="nx">val</span><span class="p">[</span><span class="nx">key</span><span class="p">])</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-28">#</a> </div> <p>Return the maximum item or (item-based computation).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.max = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">max</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nb">Math</span><span class="p">,</span> <span class="nx">obj</span><span class="p">)</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">iterator</span> <span class="o">and</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span>
+ <span class="nv">result = </span><span class="nx">computed</span><span class="o">:</span> <span class="o">-</span><span class="kc">Infinity</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">computed = </span><span class="k">if</span> <span class="nx">iterator</span> <span class="k">then</span> <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="k">else</span> <span class="nx">value</span>
+ <span class="nx">computed</span> <span class="o">>=</span> <span class="nx">result</span><span class="p">.</span><span class="nx">computed</span> <span class="o">and</span> <span class="p">(</span><span class="nv">result = </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">computed</span><span class="o">:</span> <span class="nx">computed</span><span class="p">})</span>
+ <span class="nx">result</span><span class="p">.</span><span class="nx">value</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-29">#</a> </div> <p>Return the minimum element (or element-based computation).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.min = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">min</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nb">Math</span><span class="p">,</span> <span class="nx">obj</span><span class="p">)</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">iterator</span> <span class="o">and</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span>
+ <span class="nv">result = </span><span class="nx">computed</span><span class="o">:</span> <span class="kc">Infinity</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">computed = </span><span class="k">if</span> <span class="nx">iterator</span> <span class="k">then</span> <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="k">else</span> <span class="nx">value</span>
+ <span class="nx">computed</span> <span class="o"><</span> <span class="nx">result</span><span class="p">.</span><span class="nx">computed</span> <span class="o">and</span> <span class="p">(</span><span class="nv">result = </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">computed</span><span class="o">:</span> <span class="nx">computed</span><span class="p">})</span>
+ <span class="nx">result</span><span class="p">.</span><span class="nx">value</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-30">#</a> </div> <p>Sort the object's values by a criterion produced by an iterator.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.sortBy = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">pluck</span><span class="p">(((</span><span class="nx">_</span><span class="p">.</span><span class="nx">map</span> <span class="nx">obj</span><span class="p">,</span> <span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)</span> <span class="o">-></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">criteria</span><span class="o">:</span> <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">list</span><span class="p">)}</span>
+ <span class="p">).</span><span class="nx">sort</span><span class="p">((</span><span class="nx">left</span><span class="p">,</span> <span class="nx">right</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">a = </span><span class="nx">left</span><span class="p">.</span><span class="nx">criteria</span><span class="p">;</span> <span class="nv">b = </span><span class="nx">right</span><span class="p">.</span><span class="nx">criteria</span>
+ <span class="k">if</span> <span class="nx">a</span> <span class="o"><</span> <span class="nx">b</span> <span class="k">then</span> <span class="o">-</span><span class="mi">1</span> <span class="k">else</span> <span class="k">if</span> <span class="nx">a</span> <span class="o">></span> <span class="nx">b</span> <span class="k">then</span> <span class="mi">1</span> <span class="k">else</span> <span class="mi">0</span>
+ <span class="p">)),</span> <span class="s1">'value'</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-31">#</a> </div> <p>Use a comparator function to figure out at what index an object should
+be inserted so as to maintain order. Uses binary search.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.sortedIndex = </span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">obj</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">iterator</span> <span class="o">||=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">identity</span>
+ <span class="nv">low = </span> <span class="mi">0</span>
+ <span class="nv">high = </span><span class="nx">array</span><span class="p">.</span><span class="nx">length</span>
+ <span class="k">while</span> <span class="nx">low</span> <span class="o"><</span> <span class="nx">high</span>
+ <span class="nv">mid = </span><span class="p">(</span><span class="nx">low</span> <span class="o">+</span> <span class="nx">high</span><span class="p">)</span> <span class="o">>></span> <span class="mi">1</span>
+ <span class="k">if</span> <span class="nx">iterator</span><span class="p">(</span><span class="nx">array</span><span class="p">[</span><span class="nx">mid</span><span class="p">])</span> <span class="o"><</span> <span class="nx">iterator</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="k">then</span> <span class="nv">low = </span><span class="nx">mid</span> <span class="o">+</span> <span class="mi">1</span> <span class="k">else</span> <span class="nv">high = </span><span class="nx">mid</span>
+ <span class="nx">low</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-32">#</a> </div> <p>Convert anything iterable into a real, live array.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.toArray = </span><span class="p">(</span><span class="nx">iterable</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="p">[]</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">iterable</span><span class="p">)</span>
+ <span class="k">return</span> <span class="nx">iterable</span><span class="p">.</span><span class="nx">toArray</span><span class="p">()</span> <span class="k">if</span> <span class="p">(</span><span class="nx">iterable</span><span class="p">.</span><span class="nx">toArray</span><span class="p">)</span>
+ <span class="k">return</span> <span class="nx">iterable</span> <span class="k">if</span> <span class="p">(</span><span class="nx">_</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">iterable</span><span class="p">))</span>
+ <span class="k">return</span> <span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">iterable</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="nx">_</span><span class="p">.</span><span class="nx">isArguments</span><span class="p">(</span><span class="nx">iterable</span><span class="p">))</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">values</span><span class="p">(</span><span class="nx">iterable</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-33">#</a> </div> <p>Return the number of elements in an object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.size = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="nx">_</span><span class="p">.</span><span class="nx">toArray</span><span class="p">(</span><span class="nx">obj</span><span class="p">).</span><span class="nx">length</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-34">#</a> </div> <h2>Array Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-35">#</a> </div> <p>Get the first element of an array. Passing <code>n</code> will return the first N
+values in the array. Aliased as <strong>head</strong>. The <code>guard</code> check allows it to work
+with <strong>map</strong>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.first = </span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">n</span><span class="p">,</span> <span class="nx">guard</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">n</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">guard</span> <span class="k">then</span> <span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">n</span><span class="p">)</span> <span class="k">else</span> <span class="nx">array</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-36">#</a> </div> <p>Returns everything but the first entry of the array. Aliased as <strong>tail</strong>.
+Especially useful on the arguments object. Passing an <code>index</code> will return
+the rest of the values in the array from that index onward. The <code>guard</code>
+check allows it to work with <strong>map</strong>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.rest = </span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">index</span><span class="p">,</span> <span class="nx">guard</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isUndefined</span><span class="p">(</span><span class="nx">index</span><span class="p">)</span> <span class="o">or</span> <span class="nx">guard</span> <span class="k">then</span> <span class="mi">1</span> <span class="k">else</span> <span class="nx">index</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-37">#</a> </div> <p>Get the last element of an array.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.last = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-></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="mi">1</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-38">#</a> </div> <p>Trim out all falsy values from an array.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.compact = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-></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-39"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-39">#</a> </div> <p>Return a completely flattened version of an array.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.flatten = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">reduce</span> <span class="nx">array</span><span class="p">,</span> <span class="p">(</span><span class="nx">memo</span><span class="p">,</span> <span class="nx">value</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">memo</span><span class="p">.</span><span class="nx">concat</span><span class="p">(</span><span class="nx">_</span><span class="p">.</span><span class="nx">flatten</span><span class="p">(</span><span class="nx">value</span><span class="p">))</span> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isArray</span> <span class="nx">value</span>
+ <span class="nx">memo</span><span class="p">.</span><span class="nx">push</span> <span class="nx">value</span>
+ <span class="nx">memo</span>
+ <span class="p">,</span> <span class="p">[]</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-40">#</a> </div> <p>Return a version of the array that does not contain the specified value(s).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.without = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">values = </span><span class="nx">_</span><span class="p">.</span><span class="nx">rest</span> <span class="nx">arguments</span>
+ <span class="nx">val</span> <span class="k">for</span> <span class="nx">val</span> <span class="k">in</span> <span class="nx">_</span><span class="p">.</span><span class="nx">toArray</span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="k">when</span> <span class="o">not</span> <span class="nx">_</span><span class="p">.</span><span class="nx">include</span> <span class="nx">values</span><span class="p">,</span> <span class="nx">val</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-41">#</a> </div> <p>Produce a duplicate-free version of the array. If the array has already
+been sorted, you have the option of using a faster algorithm.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.uniq = </span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">isSorted</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">memo = </span><span class="p">[]</span>
+ <span class="k">for</span> <span class="nx">el</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">_</span><span class="p">.</span><span class="nx">toArray</span> <span class="nx">array</span>
+ <span class="nx">memo</span><span class="p">.</span><span class="nx">push</span> <span class="nx">el</span> <span class="k">if</span> <span class="nx">i</span> <span class="o">is</span> <span class="mi">0</span> <span class="o">||</span> <span class="p">(</span><span class="k">if</span> <span class="nx">isSorted</span> <span class="o">is</span> <span class="kc">true</span> <span class="k">then</span> <span class="nx">_</span><span class="p">.</span><span class="nx">last</span><span class="p">(</span><span class="nx">memo</span><span class="p">)</span> <span class="o">isnt</span> <span class="nx">el</span> <span class="k">else</span> <span class="o">not</span> <span class="nx">_</span><span class="p">.</span><span class="nx">include</span><span class="p">(</span><span class="nx">memo</span><span class="p">,</span> <span class="nx">el</span><span class="p">))</span>
+ <span class="nx">memo</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-42">#</a> </div> <p>Produce an array that contains every item shared between all the
+passed-in arrays.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.intersect = </span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">rest = </span><span class="nx">_</span><span class="p">.</span><span class="nx">rest</span> <span class="nx">arguments</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">select</span> <span class="nx">_</span><span class="p">.</span><span class="nx">uniq</span><span class="p">(</span><span class="nx">array</span><span class="p">),</span> <span class="p">(</span><span class="nx">item</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">all</span> <span class="nx">rest</span><span class="p">,</span> <span class="p">(</span><span class="nx">other</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">other</span><span class="p">,</span> <span class="nx">item</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-43">#</a> </div> <p>Zip together multiple lists into a single array -- elements that share
+an index go together.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.zip = </span><span class="o">-></span>
+ <span class="nv">length = </span> <span class="nx">_</span><span class="p">.</span><span class="nx">max</span> <span class="nx">_</span><span class="p">.</span><span class="nx">pluck</span> <span class="nx">arguments</span><span class="p">,</span> <span class="s1">'length'</span>
+ <span class="nv">results = </span><span class="k">new</span> <span class="nb">Array</span> <span class="nx">length</span>
+ <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">length</span><span class="p">]</span>
+ <span class="nx">results</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">pluck</span> <span class="nx">arguments</span><span class="p">,</span> <span class="nb">String</span> <span class="nx">i</span>
+ <span class="nx">results</span></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-44">#</a> </div> <p>If the browser doesn't supply us with <strong>indexOf</strong> (I'm looking at you, MSIE),
+we need this function. Return the position of the first occurence of an
+item in an array, or -1 if the item is not included in the array.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.indexOf = </span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">item</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">array</span><span class="p">.</span><span class="nx">indexOf</span> <span class="nx">item</span> <span class="k">if</span> <span class="nx">nativeIndexOf</span> <span class="o">and</span> <span class="nx">array</span><span class="p">.</span><span class="nx">indexOf</span> <span class="o">is</span> <span class="nx">nativeIndexOf</span>
+ <span class="nv">i = </span><span class="mi">0</span><span class="p">;</span> <span class="nv">l = </span><span class="nx">array</span><span class="p">.</span><span class="nx">length</span>
+ <span class="k">while</span> <span class="nx">l</span> <span class="o">-</span> <span class="nx">i</span>
+ <span class="k">if</span> <span class="nx">array</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">is</span> <span class="nx">item</span> <span class="k">then</span> <span class="k">return</span> <span class="nx">i</span> <span class="k">else</span> <span class="nx">i</span><span class="o">++</span>
+ <span class="o">-</span><span class="mi">1</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-45">#</a> </div> <p>Provide JavaScript 1.6's <strong>lastIndexOf</strong>, delegating to the native function,
+if possible.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.lastIndexOf = </span><span class="p">(</span><span class="nx">array</span><span class="p">,</span> <span class="nx">item</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">array</span><span class="p">.</span><span class="nx">lastIndexOf</span><span class="p">(</span><span class="nx">item</span><span class="p">)</span> <span class="k">if</span> <span class="nx">nativeLastIndexOf</span> <span class="o">and</span> <span class="nx">array</span><span class="p">.</span><span class="nx">lastIndexOf</span> <span class="o">is</span> <span class="nx">nativeLastIndexOf</span>
+ <span class="nv">i = </span><span class="nx">array</span><span class="p">.</span><span class="nx">length</span>
+ <span class="k">while</span> <span class="nx">i</span>
+ <span class="k">if</span> <span class="nx">array</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">is</span> <span class="nx">item</span> <span class="k">then</span> <span class="k">return</span> <span class="nx">i</span> <span class="k">else</span> <span class="nx">i</span><span class="o">--</span>
+ <span class="o">-</span><span class="mi">1</span></pre></div> </td> </tr> <tr id="section-46"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-46">#</a> </div> <p>Generate an integer Array containing an arithmetic progression. A port of
+<a href="http://docs.python.org/library/functions.html#range">the native Python <strong>range</strong> function</a>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.range = </span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="nx">stop</span><span class="p">,</span> <span class="nx">step</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">a = </span><span class="nx">arguments</span>
+ <span class="nv">solo = </span><span class="nx">a</span><span class="p">.</span><span class="nx">length</span> <span class="o"><=</span> <span class="mi">1</span>
+ <span class="nv">i = start = </span><span class="k">if</span> <span class="nx">solo</span> <span class="k">then</span> <span class="mi">0</span> <span class="k">else</span> <span class="nx">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+ <span class="nv">stop = </span><span class="k">if</span> <span class="nx">solo</span> <span class="k">then</span> <span class="nx">a</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">else</span> <span class="nx">a</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+ <span class="nv">step = </span><span class="nx">a</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">or</span> <span class="mi">1</span>
+ <span class="nv">len = </span><span class="nb">Math</span><span class="p">.</span><span class="nx">ceil</span><span class="p">((</span><span class="nx">stop</span> <span class="o">-</span> <span class="nx">start</span><span class="p">)</span> <span class="o">/</span> <span class="nx">step</span><span class="p">)</span>
+ <span class="k">return</span> <span class="p">[]</span> <span class="k">if</span> <span class="nx">len</span> <span class="o"><=</span> <span class="mi">0</span>
+ <span class="nv">range = </span><span class="k">new</span> <span class="nb">Array</span> <span class="nx">len</span>
+ <span class="nv">idx = </span><span class="mi">0</span>
+ <span class="nx">loop</span>
+ <span class="k">return</span> <span class="nx">range</span> <span class="k">if</span> <span class="p">(</span><span class="k">if</span> <span class="nx">step</span> <span class="o">></span> <span class="mi">0</span> <span class="k">then</span> <span class="nx">i</span> <span class="o">-</span> <span class="nx">stop</span> <span class="k">else</span> <span class="nx">stop</span> <span class="o">-</span> <span class="nx">i</span><span class="p">)</span> <span class="o">>=</span> <span class="mi">0</span>
+ <span class="nx">range</span><span class="p">[</span><span class="nx">idx</span><span class="p">]</span> <span class="o">=</span> <span class="nx">i</span>
+ <span class="nx">idx</span><span class="o">++</span>
+ <span class="nx">i</span><span class="o">+=</span> <span class="nx">step</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-47">#</a> </div> <h2>Function Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-48">#</a> </div> <p>Create a function bound to a given object (assigning <code>this</code>, and arguments,
+optionally). Binding with arguments is also known as <strong>curry</strong>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.bind = </span><span class="p">(</span><span class="nx">func</span><span class="p">,</span> <span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">args = </span><span class="nx">_</span><span class="p">.</span><span class="nx">rest</span> <span class="nx">arguments</span><span class="p">,</span> <span class="mi">2</span>
+ <span class="o">-></span> <span class="nx">func</span><span class="p">.</span><span class="nx">apply</span> <span class="nx">obj</span> <span class="o">or</span> <span class="nx">root</span><span class="p">,</span> <span class="nx">args</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">arguments</span></pre></div> </td> </tr> <tr id="section-49"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-49">#</a> </div> <p>Bind all of an object's methods to that object. Useful for ensuring that
+all callbacks defined on an object belong to it.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.bindAll = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">funcs = </span><span class="k">if</span> <span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">1</span> <span class="k">then</span> <span class="nx">_</span><span class="p">.</span><span class="nx">rest</span><span class="p">(</span><span class="nx">arguments</span><span class="p">)</span> <span class="k">else</span> <span class="nx">_</span><span class="p">.</span><span class="nx">functions</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="nx">funcs</span><span class="p">,</span> <span class="p">(</span><span class="nx">f</span><span class="p">)</span> <span class="o">-></span> <span class="nx">obj</span><span class="p">[</span><span class="nx">f</span><span class="p">]</span> <span class="o">=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">bind</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">f</span><span class="p">],</span> <span class="nx">obj</span>
+ <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-50"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-50">#</a> </div> <p>Delays a function for the given number of milliseconds, and then calls
+it with the arguments supplied.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.delay = </span><span class="p">(</span><span class="nx">func</span><span class="p">,</span> <span class="nx">wait</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">args = </span><span class="nx">_</span><span class="p">.</span><span class="nx">rest</span> <span class="nx">arguments</span><span class="p">,</span> <span class="mi">2</span>
+ <span class="nx">setTimeout</span><span class="p">((</span><span class="o">-></span> <span class="nx">func</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">func</span><span class="p">,</span> <span class="nx">args</span><span class="p">)),</span> <span class="nx">wait</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-51"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-51">#</a> </div> <p>Memoize an expensive function by storing its results.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.memoize = </span><span class="p">(</span><span class="nx">func</span><span class="p">,</span> <span class="nx">hasher</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">memo = </span><span class="p">{}</span>
+ <span class="nx">hasher</span> <span class="o">or=</span> <span class="nx">_</span><span class="p">.</span><span class="nx">identity</span>
+ <span class="o">-></span>
+ <span class="nv">key = </span><span class="nx">hasher</span><span class="p">.</span><span class="nx">apply</span> <span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span>
+ <span class="k">return</span> <span class="nx">memo</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="k">if</span> <span class="nx">key</span> <span class="k">of</span> <span class="nx">memo</span>
+ <span class="nx">memo</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">func</span><span class="p">.</span><span class="nx">apply</span> <span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span></pre></div> </td> </tr> <tr id="section-52"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-52">#</a> </div> <p>Defers a function, scheduling it to run after the current call stack has
+cleared.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.defer = </span><span class="p">(</span><span class="nx">func</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">delay</span><span class="p">.</span><span class="nx">apply</span> <span class="nx">_</span><span class="p">,</span> <span class="p">[</span><span class="nx">func</span><span class="p">,</span> <span class="mi">1</span><span class="p">].</span><span class="nx">concat</span> <span class="nx">_</span><span class="p">.</span><span class="nx">rest</span> <span class="nx">arguments</span></pre></div> </td> </tr> <tr id="section-53"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-53">#</a> </div> <p>Returns the first function passed as an argument to the second,
+allowing you to adjust arguments, run code before and after, and
+conditionally execute the original function.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.wrap = </span><span class="p">(</span><span class="nx">func</span><span class="p">,</span> <span class="nx">wrapper</span><span class="p">)</span> <span class="o">-></span>
+ <span class="o">-></span> <span class="nx">wrapper</span><span class="p">.</span><span class="nx">apply</span> <span class="nx">wrapper</span><span class="p">,</span> <span class="p">[</span><span class="nx">func</span><span class="p">].</span><span class="nx">concat</span> <span class="nx">arguments</span></pre></div> </td> </tr> <tr id="section-54"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-54">#</a> </div> <p>Returns a function that is the composition of a list of functions, each
+consuming the return value of the function that follows.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.compose = </span><span class="o">-></span>
+ <span class="nv">funcs = </span><span class="nx">arguments</span>
+ <span class="o">-></span>
+ <span class="nv">args = </span><span class="nx">arguments</span>
+ <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[(</span><span class="nx">funcs</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="mi">0</span><span class="p">]</span>
+ <span class="nv">args = </span><span class="p">[</span><span class="nx">funcs</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">args</span><span class="p">)]</span>
+ <span class="nx">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-55"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-55">#</a> </div> <h2>Object Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-56"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-56">#</a> </div> <p>Retrieve the names of an object's properties.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.keys = </span><span class="nx">nativeKeys</span> <span class="o">or</span> <span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">_</span><span class="p">.</span><span class="nx">range</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">length</span> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span>
+ <span class="nx">key</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">obj</span></pre></div> </td> </tr> <tr id="section-57"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-57">#</a> </div> <p>Retrieve the values of an object's properties.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.values = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">map</span> <span class="nx">obj</span><span class="p">,</span> <span class="nx">_</span><span class="p">.</span><span class="nx">identity</span></pre></div> </td> </tr> <tr id="section-58"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-58">#</a> </div> <p>Return a sorted list of the function names available in Underscore.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.functions = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">filter</span><span class="p">(</span><span class="nx">_</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">obj</span><span class="p">),</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="o">-></span> <span class="nx">_</span><span class="p">.</span><span class="nx">isFunction</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="nx">sort</span><span class="p">()</span></pre></div> </td> </tr> <tr id="section-59"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-59">#</a> </div> <p>Extend a given object with all of the properties in a source object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.extend = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">for</span> <span class="nx">source</span> <span class="k">in</span> <span class="nx">_</span><span class="p">.</span><span class="nx">rest</span><span class="p">(</span><span class="nx">arguments</span><span class="p">)</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">=</span> <span class="nx">val</span><span class="p">)</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">source</span>
+ <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-60"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-60">#</a> </div> <p>Create a (shallow-cloned) duplicate of an object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.clone = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">slice</span> <span class="mi">0</span> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isArray</span> <span class="nx">obj</span>
+ <span class="nx">_</span><span class="p">.</span><span class="nx">extend</span> <span class="p">{},</span> <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-61"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-61">#</a> </div> <p>Invokes interceptor with the obj, and then returns obj.
+The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.tap = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">interceptor</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">interceptor</span> <span class="nx">obj</span>
+ <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-62"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-62">#</a> </div> <p>Perform a deep comparison to check if two objects are equal.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isEqual = </span><span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span> <span class="o">-></span></pre></div> </td> </tr> <tr id="section-63"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-63">#</a> </div> <p>Check object identity.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="kc">true</span> <span class="k">if</span> <span class="nx">a</span> <span class="o">is</span> <span class="nx">b</span></pre></div> </td> </tr> <tr id="section-64"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-64">#</a> </div> <p>Different types?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">atype = </span><span class="k">typeof</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span> <span class="nv">btype = </span><span class="k">typeof</span><span class="p">(</span><span class="nx">b</span><span class="p">)</span>
+ <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">atype</span> <span class="o">isnt</span> <span class="nx">btype</span></pre></div> </td> </tr> <tr id="section-65"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-65">#</a> </div> <p>Basic equality test (watch out for coercions).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="kc">true</span> <span class="k">if</span> <span class="o">`</span><span class="nx">a</span> <span class="o">==</span> <span class="nx">b</span><span class="o">`</span></pre></div> </td> </tr> <tr id="section-66"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-66">#</a> </div> <p>One is falsy and the other truthy.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">a</span> <span class="o">and</span> <span class="nx">b</span><span class="p">)</span> <span class="o">or</span> <span class="p">(</span><span class="nx">a</span> <span class="o">and</span> <span class="o">!</span><span class="nx">b</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-67"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-67">#</a> </div> <p>One of them implements an <code>isEqual()</code>?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">a</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="nx">b</span><span class="p">)</span> <span class="k">if</span> <span class="nx">a</span><span class="p">.</span><span class="nx">isEqual</span></pre></div> </td> </tr> <tr id="section-68"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-68">#</a> </div> <p>Check dates' integer values.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">a</span><span class="p">.</span><span class="nx">getTime</span><span class="p">()</span> <span class="o">is</span> <span class="nx">b</span><span class="p">.</span><span class="nx">getTime</span><span class="p">()</span> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isDate</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="o">and</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isDate</span><span class="p">(</span><span class="nx">b</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-69"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-69">#</a> </div> <p>Both are NaN?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nb">isNaN</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="o">and</span> <span class="nx">_</span><span class="p">.</span><span class="nb">isNaN</span><span class="p">(</span><span class="nx">b</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-70"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-70">#</a> </div> <p>Compare regular expressions.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isRegExp</span><span class="p">(</span><span class="nx">a</span><span class="p">)</span> <span class="o">and</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isRegExp</span><span class="p">(</span><span class="nx">b</span><span class="p">)</span>
+ <span class="k">return</span> <span class="nx">a</span><span class="p">.</span><span class="nx">source</span> <span class="o">is</span> <span class="nx">b</span><span class="p">.</span><span class="nx">source</span> <span class="o">and</span>
+ <span class="nx">a</span><span class="p">.</span><span class="nx">global</span> <span class="o">is</span> <span class="nx">b</span><span class="p">.</span><span class="nx">global</span> <span class="o">and</span>
+ <span class="nx">a</span><span class="p">.</span><span class="nx">ignoreCase</span> <span class="o">is</span> <span class="nx">b</span><span class="p">.</span><span class="nx">ignoreCase</span> <span class="o">and</span>
+ <span class="nx">a</span><span class="p">.</span><span class="nx">multiline</span> <span class="o">is</span> <span class="nx">b</span><span class="p">.</span><span class="nx">multiline</span></pre></div> </td> </tr> <tr id="section-71"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-71">#</a> </div> <p>If a is not an object by this point, we can't handle it.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">atype</span> <span class="o">isnt</span> <span class="s1">'object'</span></pre></div> </td> </tr> <tr id="section-72"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-72">#</a> </div> <p>Check for different array lengths before comparing contents.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">a</span><span class="p">.</span><span class="nx">length</span> <span class="o">and</span> <span class="p">(</span><span class="nx">a</span><span class="p">.</span><span class="nx">length</span> <span class="o">isnt</span> <span class="nx">b</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-73"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-73">#</a> </div> <p>Nothing else worked, deep compare the contents.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">aKeys = </span><span class="nx">_</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">a</span><span class="p">);</span> <span class="nv">bKeys = </span><span class="nx">_</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">b</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-74"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-74">#</a> </div> <p>Different object sizes?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="kc">false</span> <span class="k">if</span> <span class="nx">aKeys</span><span class="p">.</span><span class="nx">length</span> <span class="o">isnt</span> <span class="nx">bKeys</span><span class="p">.</span><span class="nx">length</span></pre></div> </td> </tr> <tr id="section-75"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-75">#</a> </div> <p>Recursive comparison of contents.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="p">(</span><span class="k">return</span> <span class="kc">false</span><span class="p">)</span> <span class="k">for</span> <span class="nx">all</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">val</span> <span class="k">of</span> <span class="nx">a</span> <span class="k">when</span> <span class="o">!</span><span class="p">(</span><span class="nx">key</span> <span class="k">of</span> <span class="nx">b</span><span class="p">)</span> <span class="o">or</span> <span class="o">!</span><span class="nx">_</span><span class="p">.</span><span class="nx">isEqual</span><span class="p">(</span><span class="nx">val</span><span class="p">,</span> <span class="nx">b</span><span class="p">[</span><span class="nx">key</span><span class="p">])</span>
+ <span class="kc">true</span></pre></div> </td> </tr> <tr id="section-76"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-76">#</a> </div> <p>Is a given array or object empty?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isEmpty = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">return</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">length</span> <span class="o">is</span> <span class="mi">0</span> <span class="k">if</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">or</span> <span class="nx">_</span><span class="p">.</span><span class="nx">isString</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span>
+ <span class="p">(</span><span class="k">return</span> <span class="kc">false</span><span class="p">)</span> <span class="k">for</span> <span class="nx">key</span> <span class="k">of</span> <span class="nx">obj</span> <span class="k">when</span> <span class="nx">hasOwnProperty</span><span class="p">.</span><span class="nx">call</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="kc">true</span></pre></div> </td> </tr> <tr id="section-77"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-77">#</a> </div> <p>Is a given value a DOM element?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isElement = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="nx">obj</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">nodeType</span> <span class="o">is</span> <span class="mi">1</span></pre></div> </td> </tr> <tr id="section-78"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-78">#</a> </div> <p>Is a given value an array?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isArray = </span><span class="nx">nativeIsArray</span> <span class="o">or</span> <span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="o">!!</span><span class="p">(</span><span class="nx">obj</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">concat</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">unshift</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">callee</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-79"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-79">#</a> </div> <p>Is a given variable an arguments object?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isArguments = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="nx">obj</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">callee</span></pre></div> </td> </tr> <tr id="section-80"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-80">#</a> </div> <p>Is the given value a function?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isFunction = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="o">!!</span><span class="p">(</span><span class="nx">obj</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">constructor</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">call</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">apply</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-81"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-81">#</a> </div> <p>Is the given value a string?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isString = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="o">!!</span><span class="p">(</span><span class="nx">obj</span> <span class="o">is</span> <span class="s1">''</span> <span class="o">or</span> <span class="p">(</span><span class="nx">obj</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">charCodeAt</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">substr</span><span class="p">))</span></pre></div> </td> </tr> <tr id="section-82"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-82">#</a> </div> <p>Is a given value a number?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isNumber = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="p">(</span><span class="nx">obj</span> <span class="o">is</span> <span class="o">+</span><span class="nx">obj</span><span class="p">)</span> <span class="o">or</span> <span class="nx">toString</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">is</span> <span class="s1">'[object Number]'</span></pre></div> </td> </tr> <tr id="section-83"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-83">#</a> </div> <p>Is a given value a boolean?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isBoolean = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="nx">obj</span> <span class="o">is</span> <span class="kc">true</span> <span class="o">or</span> <span class="nx">obj</span> <span class="o">is</span> <span class="kc">false</span></pre></div> </td> </tr> <tr id="section-84"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-84">#</a> </div> <p>Is a given value a Date?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isDate = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="o">!!</span><span class="p">(</span><span class="nx">obj</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">getTimezoneOffset</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">setUTCFullYear</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-85"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-85">#</a> </div> <p>Is the given value a regular expression?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isRegExp = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="o">!!</span><span class="p">(</span><span class="nx">obj</span> <span class="o">and</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">exec</span> <span class="o">and</span> <span class="p">(</span><span class="nx">obj</span><span class="p">.</span><span class="nx">ignoreCase</span> <span class="o">or</span> <span class="nx">obj</span><span class="p">.</span><span class="nx">ignoreCase</span> <span class="o">is</span> <span class="kc">false</span><span class="p">))</span></pre></div> </td> </tr> <tr id="section-86"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-86">#</a> </div> <p>Is the given value NaN -- this one is interesting. <code>NaN != NaN</code>, and
+<code>isNaN(undefined) == true</code>, so we make sure it's a number first.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isNaN = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="nx">_</span><span class="p">.</span><span class="nx">isNumber</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">and</span> <span class="nb">window</span><span class="p">.</span><span class="nb">isNaN</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-87"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-87">#</a> </div> <p>Is a given value equal to null?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isNull = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="nx">obj</span> <span class="o">is</span> <span class="kc">null</span></pre></div> </td> </tr> <tr id="section-88"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-88">#</a> </div> <p>Is a given variable undefined?</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.isUndefined = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span> <span class="k">typeof</span> <span class="nx">obj</span> <span class="o">is</span> <span class="s1">'undefined'</span></pre></div> </td> </tr> <tr id="section-89"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-89">#</a> </div> <h2>Utility Functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-90"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-90">#</a> </div> <p>Run Underscore.js in noConflict mode, returning the <code>_</code> variable to its
+previous owner. Returns a reference to the Underscore object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.noConflict = </span><span class="o">-></span>
+ <span class="nv">root._ = </span><span class="nx">previousUnderscore</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-91"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-91">#</a> </div> <p>Keep the identity function around for default iterators.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.identity = </span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="o">-></span> <span class="nx">value</span></pre></div> </td> </tr> <tr id="section-92"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-92">#</a> </div> <p>Run a function <code>n</code> times.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.times = </span><span class="p">(</span><span class="nx">n</span><span class="p">,</span> <span class="nx">iterator</span><span class="p">,</span> <span class="nx">context</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">iterator</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">context</span><span class="p">,</span> <span class="nx">i</span><span class="p">)</span> <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">...</span><span class="nx">n</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-93"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-93">#</a> </div> <p>Break out of the middle of an iteration.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.breakLoop = </span><span class="o">-></span> <span class="k">throw</span> <span class="nx">breaker</span></pre></div> </td> </tr> <tr id="section-94"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-94">#</a> </div> <p>Add your own custom functions to the Underscore object, ensuring that
+they're correctly added to the OOP wrapper as well.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.mixin = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">for</span> <span class="nx">name</span> <span class="k">in</span> <span class="nx">_</span><span class="p">.</span><span class="nx">functions</span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span>
+ <span class="nx">addToWrapper</span> <span class="nx">name</span><span class="p">,</span> <span class="nx">_</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="nx">obj</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span></pre></div> </td> </tr> <tr id="section-95"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-95">#</a> </div> <p>Generate a unique integer id (unique within the entire client session).
+Useful for temporary DOM ids.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">idCounter = </span><span class="mi">0</span>
+ <span class="nv">_.uniqueId = </span><span class="p">(</span><span class="nx">prefix</span><span class="p">)</span> <span class="o">-></span>
+ <span class="p">(</span><span class="nx">prefix</span> <span class="o">or</span> <span class="s1">''</span><span class="p">)</span> <span class="o">+</span> <span class="nx">idCounter</span><span class="o">++</span></pre></div> </td> </tr> <tr id="section-96"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-96">#</a> </div> <p>By default, Underscore uses <strong>ERB</strong>-style template delimiters, change the
+following template settings to use alternative delimiters.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.templateSettings = </span><span class="p">{</span>
+ <span class="nx">start</span><span class="o">:</span> <span class="s1">'<%'</span>
+ <span class="nx">end</span><span class="o">:</span> <span class="s1">'%>'</span>
+ <span class="nx">interpolate</span><span class="o">:</span> <span class="sr">/<%=(.+?)%>/g</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-97"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-97">#</a> </div> <p>JavaScript templating a-la <strong>ERB</strong>, pilfered from John Resig's
+<em>Secrets of the JavaScript Ninja</em>, page 83.
+Single-quote fix from Rick Strahl.
+With alterations for arbitrary delimiters, and to preserve whitespace.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.template = </span><span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="nx">data</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">c = </span><span class="nx">_</span><span class="p">.</span><span class="nx">templateSettings</span>
+ <span class="nv">endMatch = </span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"'(?=[^"</span><span class="o">+</span><span class="nx">c</span><span class="p">.</span><span class="nx">end</span><span class="p">.</span><span class="nx">substr</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="s2">"]*"</span><span class="o">+</span><span class="nx">escapeRegExp</span><span class="p">(</span><span class="nx">c</span><span class="p">.</span><span class="nx">end</span><span class="p">)</span><span class="o">+</span><span class="s2">")"</span><span class="p">,</span><span class="s2">"g"</span><span class="p">)</span>
+ <span class="nv">fn = </span><span class="k">new</span> <span class="nb">Function</span> <span class="s1">'obj'</span><span class="p">,</span>
+ <span class="s1">'var p=[],print=function(){p.push.apply(p,arguments);};'</span> <span class="o">+</span>
+ <span class="s1">'with(obj||{}){p.push(\''</span> <span class="o">+</span>
+ <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\r/g</span><span class="p">,</span> <span class="s1">'\\r'</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\n/g</span><span class="p">,</span> <span class="s1">'\\n'</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\t/g</span><span class="p">,</span> <span class="s1">'\\t'</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">endMatch</span><span class="p">,</span><span class="s2">"✄"</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"'"</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s2">"\\'"</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">"✄"</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s2">"'"</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">c</span><span class="p">.</span><span class="nx">interpolate</span><span class="p">,</span> <span class="s2">"',$1,'"</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="nx">c</span><span class="p">.</span><span class="nx">start</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s2">"');"</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="nx">c</span><span class="p">.</span><span class="nx">end</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s2">"p.push('"</span><span class="p">)</span> <span class="o">+</span>
+ <span class="s2">"');}return p.join('');"</span>
+ <span class="k">if</span> <span class="nx">data</span> <span class="k">then</span> <span class="nx">fn</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="k">else</span> <span class="nx">fn</span></pre></div> </td> </tr> <tr id="section-98"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-98">#</a> </div> <h2>Aliases</h2> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">_.forEach = </span><span class="nx">_</span><span class="p">.</span><span class="nx">each</span>
+ <span class="nv">_.foldl = _.inject = </span><span class="nx">_</span><span class="p">.</span><span class="nx">reduce</span>
+ <span class="nv">_.foldr = </span><span class="nx">_</span><span class="p">.</span><span class="nx">reduceRight</span>
+ <span class="nv">_.select = </span><span class="nx">_</span><span class="p">.</span><span class="nx">filter</span>
+ <span class="nv">_.all = </span><span class="nx">_</span><span class="p">.</span><span class="nx">every</span>
+ <span class="nv">_.any = </span><span class="nx">_</span><span class="p">.</span><span class="nx">some</span>
+ <span class="nv">_.contains = </span><span class="nx">_</span><span class="p">.</span><span class="nx">include</span>
+ <span class="nv">_.head = </span><span class="nx">_</span><span class="p">.</span><span class="nx">first</span>
+ <span class="nv">_.tail = </span><span class="nx">_</span><span class="p">.</span><span class="nx">rest</span>
+ <span class="nv">_.methods = </span><span class="nx">_</span><span class="p">.</span><span class="nx">functions</span></pre></div> </td> </tr> <tr id="section-99"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-99">#</a> </div> <h2>Setup the OOP Wrapper</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-100"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-100">#</a> </div> <p>If Underscore is called as a function, it returns a wrapped object that
+can be used OO-style. This wrapper holds altered versions of all the
+underscore functions. Wrapped objects may be chained.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">wrapper = </span><span class="p">(</span><span class="nx">obj</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">this</span><span class="p">.</span><span class="nv">_wrapped = </span><span class="nx">obj</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-101"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-101">#</a> </div> <p>Helper function to continue chaining intermediate results.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">result = </span><span class="p">(</span><span class="nx">obj</span><span class="p">,</span> <span class="nx">chain</span><span class="p">)</span> <span class="o">-></span>
+ <span class="k">if</span> <span class="nx">chain</span> <span class="k">then</span> <span class="nx">_</span><span class="p">(</span><span class="nx">obj</span><span class="p">).</span><span class="nx">chain</span><span class="p">()</span> <span class="k">else</span> <span class="nx">obj</span></pre></div> </td> </tr> <tr id="section-102"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-102">#</a> </div> <p>A method to easily add functions to the OOP wrapper.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">addToWrapper = </span><span class="p">(</span><span class="nx">name</span><span class="p">,</span> <span class="nx">func</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nx">wrapper</span><span class="p">.</span><span class="nx">prototype</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="o">-></span>
+ <span class="nv">args = </span><span class="nx">_</span><span class="p">.</span><span class="nx">toArray</span> <span class="nx">arguments</span>
+ <span class="nx">unshift</span><span class="p">.</span><span class="nx">call</span> <span class="nx">args</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">_wrapped</span>
+ <span class="nx">result</span> <span class="nx">func</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nx">_</span><span class="p">,</span> <span class="nx">args</span><span class="p">),</span> <span class="k">this</span><span class="p">.</span><span class="nx">_chain</span></pre></div> </td> </tr> <tr id="section-103"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-103">#</a> </div> <p>Add all of the Underscore functions to the wrapper object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_</span><span class="p">.</span><span class="nx">mixin</span> <span class="nx">_</span></pre></div> </td> </tr> <tr id="section-104"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-104">#</a> </div> <p>Add all mutator Array functions to the wrapper.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="p">[</span><span class="s1">'pop'</span><span class="p">,</span> <span class="s1">'push'</span><span class="p">,</span> <span class="s1">'reverse'</span><span class="p">,</span> <span class="s1">'shift'</span><span class="p">,</span> <span class="s1">'sort'</span><span class="p">,</span> <span class="s1">'splice'</span><span class="p">,</span> <span class="s1">'unshift'</span><span class="p">],</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">method = </span><span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span>
+ <span class="nx">wrapper</span><span class="p">.</span><span class="nx">prototype</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="o">-></span>
+ <span class="nx">method</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_wrapped</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">)</span>
+ <span class="nx">result</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_wrapped</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">_chain</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-105"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-105">#</a> </div> <p>Add all accessor Array functions to the wrapper.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">_</span><span class="p">.</span><span class="nx">each</span> <span class="p">[</span><span class="s1">'concat'</span><span class="p">,</span> <span class="s1">'join'</span><span class="p">,</span> <span class="s1">'slice'</span><span class="p">],</span> <span class="p">(</span><span class="nx">name</span><span class="p">)</span> <span class="o">-></span>
+ <span class="nv">method = </span><span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span>
+ <span class="nx">wrapper</span><span class="p">.</span><span class="nx">prototype</span><span class="p">[</span><span class="nx">name</span><span class="p">]</span> <span class="o">=</span> <span class="o">-></span>
+ <span class="nx">result</span><span class="p">(</span><span class="nx">method</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">_wrapped</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">),</span> <span class="k">this</span><span class="p">.</span><span class="nx">_chain</span><span class="p">)</span></pre></div> </td> </tr> <tr id="section-106"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-106">#</a> </div> <p>Start chaining a wrapped Underscore object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">wrapper::chain = </span><span class="o">-></span>
+ <span class="k">this</span><span class="p">.</span><span class="nv">_chain = </span><span class="kc">true</span>
+ <span class="k">this</span></pre></div> </td> </tr> <tr id="section-107"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-107">#</a> </div> <p>Extracts the result from a wrapped and chained object.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nv">wrapper::value = </span><span class="o">-></span> <span class="k">this</span><span class="p">.</span><span class="nx">_wrapped</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
\ No newline at end of file
--- /dev/null
+<%
+ require 'uv'
+ def code_for(file, executable=false)
+ return '' unless File.exists?("documentation/js/#{file}.js")
+ cs = File.read("documentation/coffee/#{file}.coffee")
+ js = File.read("documentation/js/#{file}.js")
+ cshtml = Uv.parse(cs, 'xhtml', 'coffeescript', false, 'idle', false)
+ jshtml = Uv.parse(js, 'xhtml', 'javascript', false, 'idle', false)
+ append = executable == true ? '' : "alert(#{executable});"
+ run = executable == true ? 'run' : "run: #{executable}"
+ button = executable ? "<button onclick='javascript: #{js};#{append}'>#{run}</button>" : ''
+ "<div class='code'>#{cshtml}#{jshtml}#{button}<br class='clear' /></div>"
+ end
+%>
+
+
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>CoffeeScript</title>
+ <link rel="stylesheet" type="text/css" href="documentation/css/docs.css" />
+ <link rel="stylesheet" type="text/css" href="documentation/css/idle.css" />
+ <link rel="shortcut icon" href="documentation/images/favicon.ico" />
+</head>
+<body class="minimized">
+
+ <div id="fadeout"></div>
+
+ <div id="flybar">
+ <a id="logo" href="#top"> </a>
+ <div class="navigation toc">
+ <div class="button">
+ Table of Contents
+ </div>
+ <div class="contents">
+ <a href="#overview">Mini Overview</a>
+ <a href="#installation">Installation and Usage</a>
+ <a href="#language">Language Reference</a>
+ <a href="#whitespace">Significant Whitespace</a>
+ <a href="#functions">Functions and Invocation</a>
+ <a href="#objects_and_arrays">Objects and Arrays</a>
+ <a href="#lexical_scope">Lexical Scoping and Variable Safety</a>
+ <a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
+ <a href="#aliases">Aliases</a>
+ <a href="#splats">Splats...</a>
+ <a href="#while">While, Until, and Loop</a>
+ <a href="#comprehensions">Comprehensions (Arrays, Objects, and Ranges)</a>
+ <a href="#slice_splice">Array Slicing and Splicing with Ranges</a>
+ <a href="#expressions">Everything is an Expression</a>
+ <a href="#existence">The Existential Operator</a>
+ <a href="#classes">Classes, Inheritance, and Super</a>
+ <a href="#pattern_matching">Pattern Matching</a>
+ <a href="#fat_arrow">Function Binding</a>
+ <a href="#embedded">Embedded JavaScript</a>
+ <a href="#switch">The Switch Statement</a>
+ <a href="#try">Try/Catch/Finally</a>
+ <a href="#comparisons">Chained Comparisons</a>
+ <a href="#interpolation">String and RegExp Interpolation</a>
+ <a href="#heredocs">Multiline Strings, Heredocs, and Block Comments</a>
+ <a href="#cake">Cake, and Cakefiles</a>
+ <a href="#scripts">"text/coffeescript" Script Tags</a>
+ <a href="#resources">Resources</a>
+ <a href="#webchat">Web Chat (IRC)</a>
+ <a href="#change_log">Change Log</a>
+ </div>
+ </div>
+ <div class="navigation try">
+ <div class="button">
+ Try CoffeeScript
+ </div>
+ <div class="contents repl_wrapper">
+ <div class="code">
+ <div id="repl_source_wrap"><textarea id="repl_source" rows="100">alert "Hello CoffeeScript!"</textarea></div>
+ <pre id="repl_results"></pre>
+ <button class="full_screen">go full screen</button>
+ <button class="minimize">minimize</button>
+ <button class="run">run</button>
+ <br class="clear" />
+ </div>
+ </div>
+ </div>
+ <div class="navigation annotated">
+ <div class="button">
+ Annotated Source
+ </div>
+ <div class="contents">
+ <a href="documentation/docs/grammar.html">Grammar Rules — src/grammar</a>
+ <a href="documentation/docs/lexer.html">Lexing Tokens — src/lexer</a>
+ <a href="documentation/docs/rewriter.html">The Rewriter — src/rewriter</a>
+ <a href="documentation/docs/nodes.html">The Syntax Tree — src/nodes</a>
+ <a href="documentation/docs/scope.html">Lexical Scope — src/scope</a>
+ <a href="documentation/docs/helpers.html">Helpers & Utility Functions — src/helpers</a>
+ <a href="documentation/docs/coffee-script.html">The CoffeeScript Module — src/coffee-script</a>
+ <a href="documentation/docs/cake.html">Cake & Cakefiles — src/cake</a>
+ <a href="documentation/docs/command.html">"coffee" Command-Line Utility — src/command</a>
+ <a href="documentation/docs/optparse.html">Option Parsing — src/optparse</a>
+ <a href="documentation/docs/repl.html">Interactive REPL — src/repl</a>
+ </div>
+ </div>
+ <div id="error" style="display:none;"></div>
+ </div>
+
+ <div class="container">
+ <span class="bookmark" id="top"></span>
+
+ <p>
+ CoffeeScript is a little language that compiles into JavaScript. Think
+ of it as JavaScript's less ostentatious kid brother — the same genes,
+ roughly the same height, but a different sense of style. Apart from a handful of
+ bonus goodies, statements in CoffeeScript correspond one-to-one with their
+ equivalent in JavaScript, it's just another way of saying it.
+ </p>
+
+ <p>
+ <b>Disclaimer:</b>
+ CoffeeScript is just for fun. Until it reaches 1.0, <i>there are no guarantees
+ that the syntax won't change between versions.</i> That said,
+ it compiles into clean JavaScript (the good parts) that can use existing
+ JavaScript libraries seamlessly, and passes through
+ <a href="http://www.jslint.com/">JSLint</a> without warnings. The compiled
+ output is pretty-printed and quite readable.
+ </p>
+
+ <p>
+ <b>Latest Version:</b>
+ <a href="http://github.com/jashkenas/coffee-script/tarball/0.9.4">0.9.4</a>
+ </p>
+
+ <h2>
+ <span id="overview" class="bookmark"></span>
+ Mini Overview
+ </h2>
+
+ <p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p>
+
+ <%= code_for('overview', 'cubes') %>
+
+ <p>
+ For a longer CoffeeScript example, check out
+ <a href="documentation/docs/underscore.html">Underscore.coffee</a>, a port
+ of the <a href="http://documentcloud.github.com/underscore/">Underscore.js</a>
+ library of helper functions. Underscore.coffee can pass the entire Underscore.js
+ test suite. The CoffeeScript version is faster than the original for a number
+ of methods (in general, due to the speed of CoffeeScript's array comprehensions), and
+ after being minified and gzipped, is only 241 bytes larger than the original
+ JavaScript version.
+ Additional examples are included in the source repository, inside the
+ <a href="http://github.com/jashkenas/coffee-script/tree/master/examples/">examples</a> folder.
+ </p>
+
+ <h2>
+ <span id="installation" class="bookmark"></span>
+ Installation and Usage
+ </h2>
+
+ <p>
+ The CoffeeScript compiler is written in pure CoffeeScript, using a
+ <a href="documentation/docs/grammar.html">small DSL</a>
+ on top of the <a href="http://github.com/zaach/jison">Jison parser generator</a>, and is available
+ as a <a href="http://nodejs.org/">Node.js</a> utility. The core compiler however,
+ does not depend on Node, and can be run in other server-side-JavaScript environments,
+ or in the browser (see "Try CoffeeScript", above).
+ </p>
+
+ <p>
+ To install, first make sure you have a working copy of the latest tagged version of
+ <a href="http://nodejs.org/">Node.js</a>, currently <b>0.1.102</b> or higher.
+ Then clone the CoffeeScript
+ <a href="http://github.com/jashkenas/coffee-script">source repository</a>
+ from GitHub, or download the latest
+ release: <a href="http://github.com/jashkenas/coffee-script/tarball/0.9.4">0.9.4</a>.
+ To install the CoffeeScript compiler system-wide
+ under <tt>/usr/local</tt>, open the directory and run:
+ </p>
+
+ <pre>
+sudo bin/cake install</pre>
+
+ <p>
+ Alternatively, if you already have the
+ <a href="http://npmjs.org/">Node Package Manager</a> installed,
+ you can use that to grab the latest CoffeeScript:
+ </p>
+
+ <pre>
+sudo npm install coffee-script</pre>
+
+ <p>
+ Both of these provide the <tt>coffee</tt> command, which will execute CoffeeScripts
+ under Node.js by default, but is also used to compile CoffeeScript
+ <tt>.coffee</tt> files into JavaScript, or to run an an interactive REPL.
+ When compiling to JavaScript, <tt>coffee</tt> writes the output
+ as <tt>.js</tt> files in the same directory by default, but output
+ can be customized with the following options:
+ </p>
+
+ <table>
+ <tr>
+ <td><code>-c, --compile</code></td>
+ <td>
+ Compile a <tt>.coffee</tt> script into a <tt>.js</tt> JavaScript file
+ of the same name.
+ </td>
+ </tr>
+ <tr>
+ <td width="25%"><code>-i, --interactive</code></td>
+ <td>
+ Launch an interactive CoffeeScript session to try short snippets.
+ More pleasant if wrapped with
+ <a href="http://utopia.knoware.nl/~hlub/uck/rlwrap/rlwrap.html">rlwrap</a>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-o, --output [DIR]</code></td>
+ <td>
+ Write out all compiled JavaScript files into the specified directory.
+ Use in conjunction with <tt>--compile</tt> or <tt>--watch</tt>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-w, --watch</code></td>
+ <td>
+ Watch the modification times of the coffee-scripts, recompiling as
+ soon as a change occurs.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-p, --print</code></td>
+ <td>
+ Instead of writing out the JavaScript as a file, print it
+ directly to <b>stdout</b>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-l, --lint</code></td>
+ <td>
+ If the <tt>jsl</tt>
+ (<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
+ command is installed, use it
+ to check the compilation of a CoffeeScript file. (Handy in
+ conjunction with <br /> <tt>--watch</tt>)
+ </td>
+ </tr>
+ <tr>
+ <td><code>-s, --stdio</code></td>
+ <td>
+ Pipe in CoffeeScript to STDIN and get back JavaScript over STDOUT.
+ Good for use with processes written in other languages. An example:<br />
+ <tt>cat src/cake.coffee | coffee -sc</tt>
+ </td>
+ </tr>
+ <tr>
+ <td><code>-e, --eval</code></td>
+ <td>
+ Compile and print a little snippet of CoffeeScript directly from the
+ command line. For example:<br /><tt>coffee -e "puts num for num in [10..1]"</tt>
+ </td>
+ </tr>
+ <tr>
+ <td><code>-r, --require</code></td>
+ <td>
+ Load a library before compiling or executing your script. Can be used
+ to hook in to the compiler (to add Growl notifications, for example).
+ </td>
+ </tr>
+ <tr>
+ <td><code>-b, --bare</code></td>
+ <td>
+ Compile the JavaScript without the top-level function safety wrapper.
+ (Used for CoffeeScript as a Node.js module.)
+ </td>
+ </tr>
+ <tr>
+ <td><code>-t, --tokens</code></td>
+ <td>
+ Instead of parsing the CoffeeScript, just lex it, and print out the
+ token stream: <tt>[IDENTIFIER square] [ASSIGN =] [PARAM_START (]</tt> ...
+ </td>
+ </tr>
+ <tr>
+ <td><code>-n, --nodes</code></td>
+ <td>
+ Instead of compiling the CoffeeScript, just lex and parse it, and print
+ out the parse tree:
+<pre class="no_bar">
+Expressions
+ Assign
+ Value "square"
+ Code "x"
+ Op *
+ Value "x"
+ Value "x"</pre>
+ </td>
+ </tr>
+ </table>
+
+ <p>
+ <b>Examples:</b>
+ </p>
+
+ <pre>
+coffee -c path/to/script.coffee
+coffee --interactive
+coffee --watch --lint experimental.coffee
+coffee --print app/scripts/*.coffee > concatenation.js</pre>
+
+ <h2>
+ <span id="language" class="bookmark"></span>
+ Language Reference
+ </h2>
+
+ <p>
+ <i>
+ This reference is structured so that it can be read from top to bottom,
+ if you like. Later sections use ideas and syntax previously introduced.
+ Familiarity with JavaScript is assumed.
+ In all of the following examples, the source CoffeeScript is provided on
+ the left, and the direct compilation into JavaScript is on the right.
+ </i>
+ </p>
+
+ <p>
+ <i>
+ Many of the examples can be run (where it makes sense) by pressing the "run"
+ button towards the bottom right. You can also paste examples into
+ "Try CoffeeScript" in the toolbar, and play with them from there.
+ </i>
+ <p>
+ <span id="whitespace" class="bookmark"></span>
+ <b class="header">Significant Whitespace</b>
+ CoffeeScript uses Python-style significant whitespace: You don't need to
+ use semicolons <tt>;</tt> to terminate expressions, ending
+ the line will do just as well. Semicolons can still be used to fit
+ multiple expressions onto a single line. Instead of using curly braces
+ <tt>{ }</tt> to delimit blocks of code (like <a href="#functions">functions</a>,
+ <a href="#conditionals">if-statements</a>,
+ <a href="#switch">switch</a>, and <a href="#try">try/catch</a>),
+ use indentation.
+ </p>
+
+ <p>
+ You don't need to use parentheses to invoke a function if you're passing
+ arguments:<br /><tt>print "coffee"</tt>. Implicit parentheses wrap forwards
+ to the end of the line, or block expression.
+ </p>
+
+ <p>
+ You can use newlines to break up your expression into smaller pieces,
+ as long as CoffeeScript can determine that the line hasn't finished yet,
+ because it ends with an operator or a dot ... seen most commonly
+ in jQuery-chaining style JavaScript.
+ </p>
+
+ <p>
+ <span id="functions" class="bookmark"></span>
+ <b class="header">Functions and Invocation</b>
+ Functions are defined by a list of parameters, an arrow, and the
+ function body. The empty function looks like this: <tt>-></tt>
+ </p>
+ <%= code_for('functions', 'cube(5)') %>
+
+ <p>
+ <span id="objects_and_arrays" class="bookmark"></span>
+ <b class="header">Objects and Arrays</b>
+ Object and Array literals look very similar to their JavaScript cousins.
+ When you spread out each property on a separate line, the commas are
+ optional. Implicit objects may be created with indentation instead of
+ brackets, winding up looking quite similar to YAML.
+ </p>
+ <%= code_for('objects_and_arrays', 'song.join(",")') %>
+ <p>
+ In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties
+ of an object, without quoting them as strings. CoffeeScript notices and quotes
+ them for you, so you don't have to worry about it (say, when using jQuery).
+ </p>
+ <%= code_for('objects_reserved') %>
+
+ <p>
+ <span id="lexical_scope" class="bookmark"></span>
+ <b class="header">Lexical Scoping and Variable Safety</b>
+ The CoffeeScript compiler takes care to make sure that all of your variables
+ are properly declared within lexical scope — you never need to write
+ <tt>var</tt> yourself.
+ </p>
+ <%= code_for('scope', 'inner') %>
+ <p>
+ Notice how all of the variable declarations have been pushed up to
+ the top of the closest scope, the first time they appear.
+ <b>outer</b> is not redeclared within the inner function, because it's
+ already in scope; <b>inner</b> within the function, on the other hand,
+ should not be able to change the value of the external variable of the same name, and
+ therefore has a declaration of its own.
+ </p>
+ <p>
+ This behavior is effectively identical to Ruby's scope for local variables.
+ Because you don't have direct access to the <tt>var</tt> keyword,
+ it's impossible to shadow an outer variable on purpose, you may only refer
+ to it. So be careful that you're not reusing the name of an external
+ variable accidentally, if you're writing a deeply nested function.
+ </p>
+ <p>
+ Although suppressed within this documentation for clarity, all
+ CoffeeScript output is wrapped in an anonymous function:
+ <tt>(function(){ ... })();</tt> This safety wrapper, combined with the
+ automatic generation of the <tt>var</tt> keyword, make it exceedingly difficult
+ to pollute the global namespace by accident.
+ </p>
+ <p>
+ If you'd like to create top-level variables for other scripts to use,
+ attach them as properties on <b>window</b>, or on the <b>exports</b>
+ object in CommonJS. The <b>existential operator</b> (covered below), gives you a
+ reliable way to figure out where to add them, if you're targeting both
+ CommonJS and the browser: <tt>root = exports ? this</tt>
+ </p>
+
+ <p>
+ <span id="conditionals" class="bookmark"></span>
+ <b class="header">If, Else, Unless, and Conditional Assignment</b>
+ <b>If/else</b> statements can be written without the use of parentheses and
+ curly brackets. As with functions and other block expressions,
+ multi-line conditionals are delimited by indentation. There's also a handy
+ postfix form, with the <tt>if</tt> or <tt>unless</tt> at the end.
+ </p>
+ <p>
+ CoffeeScript can compile <b>if</b> statements into JavaScript expressions,
+ using the ternary operator when possible, and closure wrapping otherwise. There
+ is no explicit ternary statement in CoffeeScript — you simply use
+ a regular <b>if</b> statement inline.
+ </p>
+ <%= code_for('conditionals') %>
+
+ <p>
+ <span id="aliases" class="bookmark"></span>
+ <b class="header">Aliases</b>
+ Because the <tt>==</tt> operator frequently causes undesirable coercion,
+ is intransitive, and has a different meaning than in other languages,
+ CoffeeScript compiles <tt>==</tt> into <tt>===</tt>, and <tt>!=</tt> into
+ <tt>!==</tt>.
+ In addition, <tt>is</tt> compiles into <tt>===</tt>,
+ and <tt>isnt</tt> into <tt>!==</tt>.
+ </p>
+ <p>
+ You can use <tt>not</tt> as an alias for <tt>!</tt>.
+ </p>
+ <p>
+ For logic, <tt>and</tt> compiles to <tt>&&</tt>, and <tt>or</tt>
+ into <tt>||</tt>.
+ </p>
+ <p>
+ Instead of a newline or semicolon, <tt>then</tt> can be used to separate
+ conditions from expressions, in <b>while</b>,
+ <b>if</b>/<b>else</b>, and <b>switch</b>/<b>when</b> statements.
+ </p>
+ <p>
+ As in <a href="http://yaml.org/">YAML</a>, <tt>on</tt> and <tt>yes</tt>
+ are the same as boolean <tt>true</tt>, while <tt>off</tt> and <tt>no</tt> are boolean <tt>false</tt>.
+ </p>
+ <p>
+ For single-line statements, <tt>unless</tt> can be used as the inverse of <tt>if</tt>.
+ </p>
+ <p>
+ As a shortcut for <tt>this.property</tt>, you can use <tt>@property</tt>.
+ </p>
+ <p>
+ You can use <tt>in</tt> to test for array presence, and <tt>of</tt> to
+ test for JavaScript object-key presence.
+ </p>
+ <%= code_for('aliases') %>
+
+ <p>
+ <span id="splats" class="bookmark"></span>
+ <b class="header">Splats...</b>
+ The JavaScript <b>arguments object</b> is a useful way to work with
+ functions that accept variable numbers of arguments. CoffeeScript provides
+ splats <tt>...</tt>, both for function definition as well as invocation,
+ making variable numbers of arguments a little bit more palatable.
+ </p>
+ <%= code_for('splats', true) %>
+
+ <p>
+ <span id="while" class="bookmark"></span>
+ <b class="header">While, Until, and Loop</b>
+ The only low-level loop that CoffeeScript provides is the <b>while</b> loop. The
+ main difference from JavaScript is that the <b>while</b> loop can be used
+ as an expression, returning an array containing the result of each iteration
+ through the loop.
+ </p>
+ <%= code_for('while', 'lyrics.join("\n")') %>
+ <p>
+ For readability, the <b>until</b> keyword is equivalent to <tt>while not</tt>,
+ and the <b>loop</b> keyword is equivalent to <tt>while true</tt>.
+ Other JavaScript loops, such as <b>for</b> loops and <b>do-while</b> loops
+ can be mimicked by variations on <b>loop</b>, but the hope is that you
+ won't need to do that with CoffeeScript, either because you're using
+ <b>each</b> (<b>forEach</b>) style iterators, or...
+ </p>
+
+ <p>
+ <span id="comprehensions" class="bookmark"></span>
+ <b class="header">Comprehensions (Arrays, Objects, and Ranges)</b>
+ For your looping needs, CoffeeScript provides array comprehensions
+ similar to Python's. They replace (and compile into) <b>for</b> loops, with
+ optional guard clauses and the value of the current array index.
+ Unlike for loops, array comprehensions are expressions, and can be returned
+ and assigned. They should be able to handle most places where you otherwise
+ would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>.
+ </p>
+ <%= code_for('array_comprehensions') %>
+ <p>
+ If you know the start and end of your loop, or would like to step through
+ in fixed-size increments, you can use a range to specify the start and
+ end of your comprehension.
+ </p>
+ <%= code_for('range_comprehensions', 'countdown') %>
+ <p>
+ Comprehensions can also be used to iterate over the keys and values in
+ an object. Use <tt>of</tt> to signal comprehension over the properties of
+ an object instead of the values in an array.
+ </p>
+ <%= code_for('object_comprehensions', 'ages.join(", ")') %>
+ <p>
+ By default, object comprehensions are safe, and use a <tt>hasOwnProperty</tt>
+ check to make sure that you're dealing with properties on the current
+ object. If you'd like the regular JavaScript <br /><tt>for (key in obj) ...</tt>
+ loop, for speed or for another reason, you can use <br />
+ <tt>for all key, value of object</tt> in CoffeeScript.
+ </p>
+
+ <p>
+ <span id="slice_splice" class="bookmark"></span>
+ <b class="header">Array Slicing and Splicing with Ranges</b>
+ CoffeeScript borrows Ruby's
+ <a href="http://ruby-doc.org/core/classes/Range.html">range syntax</a>
+ for extracting slices of arrays. With two dots (<tt>3..5</tt>), the range
+ is inclusive: the first argument is the index of the first element in
+ the slice, and the second is the index of the last one. Three dots signify
+ a range that excludes the end.
+ </p>
+ <%= code_for('slices', 'copy') %>
+ <p>
+ The same syntax can be used with assignment to replace a segment of an
+ array with new values (to splice it).
+ </p>
+ <%= code_for('splices', 'numbers') %>
+
+ <p>
+ <span id="expressions" class="bookmark"></span>
+ <b class="header">Everything is an Expression (at least, as much as possible)</b>
+ You might have noticed how even though we don't add return statements
+ to CoffeeScript functions, they nonetheless return their final value.
+ The CoffeeScript compiler tries to make sure that all statements in the
+ language can be used as expressions. Watch how the <tt>return</tt> gets
+ pushed down into each possible branch of execution, in the function
+ below.
+ </p>
+ <%= code_for('expressions', 'eldest') %>
+ <p>
+ Even though functions will always return their final value, it's both possible
+ and encouraged to return early from a function body writing out the explicit
+ return (<tt>return value</tt>), when you know that you're done.
+ </p>
+ <p>
+ Because variable declarations occur at the top of scope, assignment can
+ be used within expressions, even for variables that haven't been seen before:
+ </p>
+ <%= code_for('expressions_assignment', 'six') %>
+ <p>
+ Things that would otherwise be statements in JavaScript, when used
+ as part of an expression in CoffeeScript, are converted into expressions
+ by wrapping them in a closure. This lets you do useful things, like assign
+ the result of a comprehension to a variable:
+ </p>
+ <%= code_for('expressions_comprehension', 'globals') %>
+ <p>
+ As well as silly things, like passing a <b>try/catch</b> statement directly
+ into a function call:
+ </p>
+ <%= code_for('expressions_try', true) %>
+ <p>
+ There are a handful of statements in JavaScript that can't be meaningfully
+ converted into expressions, namely <tt>break</tt>, <tt>continue</tt>,
+ and <tt>return</tt>. If you make use of them within a block of code,
+ CoffeeScript won't try to perform the conversion.
+ </p>
+
+ <p>
+ <span id="existence" class="bookmark"></span>
+ <b class="header">The Existential Operator</b>
+ It's a little difficult to check for the existence of a variable in
+ JavaScript. <tt>if (variable) ...</tt> comes close, but fails for zero,
+ the empty string, and false. CoffeeScript's existential operator <tt>?</tt> returns true unless
+ a variable is <b>null</b> or <b>undefined</b>, which makes it analogous
+ to Ruby's <tt>nil?</tt>
+ </p>
+ <p>
+ It can also be used for safer conditional assignment than <tt>||=</tt>
+ provides, for cases where you may be handling numbers or strings.
+ </p>
+ <%= code_for('existence', 'speed') %>
+ <p>
+ The accessor variant of the existential operator <tt>?.</tt> can be used to soak
+ up null references in a chain of properties. Use it instead
+ of the dot accessor <tt>.</tt> in cases where the base value may be <b>null</b>
+ or <b>undefined</b>. If all of the properties exist then you'll get the expected
+ result, if the chain is broken, <b>undefined</b> is returned instead of
+ the <b>TypeError</b> that would be raised otherwise.
+ </p>
+ <%= code_for('soaks') %>
+ <p>
+ Soaking up nulls is similar to Ruby's
+ <a href="http://andand.rubyforge.org/">andand gem</a>, and to the
+ <a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29">safe navigation operator</a>
+ in Groovy.
+ </p>
+
+ <p>
+ <span id="classes" class="bookmark"></span>
+ <b class="header">Classes, Inheritance, and Super</b>
+ JavaScript's prototypal inheritance has always been a bit of a
+ brain-bender, with a whole family tree of libraries that provide a cleaner
+ syntax for classical inheritance on top of JavaScript's prototypes:
+ <a href="http://code.google.com/p/base2/">Base2</a>,
+ <a href="http://prototypejs.org/">Prototype.js</a>,
+ <a href="http://jsclass.jcoglan.com/">JS.Class</a>, etc.
+ The libraries provide syntactic sugar, but the built-in inheritance would
+ be completely usable if it weren't for a couple of small exceptions:
+ it's awkward to call <b>super</b> (the prototype object's
+ implementation of the current function), and it's awkward to correctly
+ set the prototype chain.
+ </p>
+ <p>
+ Instead of repetitively attaching functions to a prototype, CoffeeScript
+ provides a basic <tt>class</tt> structure that allows you to name your class,
+ set the superclass, assign prototypal properties, and define the constructor,
+ in a single assignable expression.
+ </p>
+ <%= code_for('classes', true) %>
+ <p>
+ If structuring your prototypes classically isn't your cup of tea, CoffeeScript
+ provides a couple of lower-level conveniences. The <tt>extends</tt> operator
+ helps with proper prototype setup, <tt>::</tt> gives you
+ quick access to an object's prototype, and <tt>super()</tt>
+ is converted into a call against the immediate ancestor's method of the same name.
+ </p>
+ <%= code_for('prototypes', '"one_two".dasherize()') %>
+ <p>
+ Finally, you may assign Class-level (static) properties within a class
+ definition by using<br /><tt>@property: value</tt>
+ </p>
+
+ <p>
+ <span id="pattern_matching" class="bookmark"></span>
+ <b class="header">Pattern Matching (Destructuring Assignment)</b>
+ To make extracting values from complex arrays and objects more convenient,
+ CoffeeScript implements ECMAScript Harmony's proposed
+ <a href="http://wiki.ecmascript.org/doku.php?id=harmony:destructuring">destructuring assignment</a>
+ syntax. When you assign an array or object literal to a value, CoffeeScript
+ breaks up and matches both sides against each other, assigning the values
+ on the right to the variables on the left. In the simplest case, it can be
+ used for parallel assignment:
+ </p>
+ <%= code_for('parallel_assignment', 'theBait') %>
+ <p>
+ But it's also helpful for dealing with functions that return multiple
+ values.
+ </p>
+ <%= code_for('multiple_return_values', 'forecast') %>
+ <p>
+ Pattern matching can be used with any depth of array and object nesting,
+ to help pull out deeply nested properties.
+ </p>
+ <%= code_for('object_extraction', 'name + " — " + street') %>
+ <p>
+ Pattern matching can even be combined with splats.
+ </p>
+ <%= code_for('patterns_and_splats', 'contents.join("")') %>
+
+ <p>
+ <span id="fat_arrow" class="bookmark"></span>
+ <b class="header">Function binding</b>
+ In JavaScript, the <tt>this</tt> keyword is dynamically scoped to mean the
+ object that the current function is attached to. If you pass a function as
+ as callback, or attach it to a different object, the original value of <tt>this</tt>
+ will be lost. If you're not familiar with this behavior,
+ <a href="http://www.digital-web.com/articles/scope_in_javascript/">this Digital Web article</a>
+ gives a good overview of the quirks.
+ </p>
+ <p>
+ The fat arrow <tt>=></tt> can be used to both define a function, and to bind
+ it to the current value of <tt>this</tt>, right on the spot. This is helpful
+ when using callback-based libraries like Prototype or jQuery, for creating
+ iterator functions to pass to <tt>each</tt>, or event-handler functions
+ to use with <tt>bind</tt>. Functions created with the fat arrow are able to access
+ properties of the <tt>this</tt> where they're defined.
+ </p>
+ <%= code_for('fat_arrow') %>
+ <p>
+ If we had used <tt>-></tt> in the callback above, <tt>@customer</tt> would
+ have referred to the undefined "customer" property of the DOM element,
+ and trying to call <tt>purchase()</tt> on it would have raised an exception.
+ </p>
+
+ <p>
+ <span id="embedded" class="bookmark"></span>
+ <b class="header">Embedded JavaScript</b>
+ Hopefully, you'll never need to use it, but if you ever need to intersperse
+ snippets of JavaScript within your CoffeeScript, you can
+ use backticks to pass it straight through.
+ </p>
+ <%= code_for('embedded', 'hi()') %>
+
+ <p>
+ <span id="switch" class="bookmark"></span>
+ <b class="header">Switch/When/Else</b>
+ <b>Switch</b> statements in JavaScript are a bit awkward. You need to
+ remember to <b>break</b> at the end of every <b>case</b> statement to
+ avoid accidentally falling through to the default case.
+ CoffeeScript prevents accidental fall-through, and can convert the <tt>switch</tt>
+ into a returnable, assignable expression. The format is: <tt>switch</tt> condition,
+ <tt>when</tt> clauses, <tt>else</tt> the default case.
+ </p>
+ <p>
+ As in Ruby, <b>switch</b> statements in CoffeeScript can take multiple
+ values for each <b>when</b> clause. If any of the values match, the clause
+ runs.
+ </p>
+ <%= code_for('switch') %>
+
+ <p>
+ <span id="try" class="bookmark"></span>
+ <b class="header">Try/Catch/Finally</b>
+ Try/catch statements are just about the same as JavaScript (although
+ they work as expressions).
+ </p>
+ <%= code_for('try') %>
+
+ <p>
+ <span id="comparisons" class="bookmark"></span>
+ <b class="header">Chained Comparisons</b>
+ CoffeeScript borrows
+ <a href="http://docs.python.org/reference/expressions.html#notin">chained comparisons</a>
+ from Python — making it easy to test if a value falls within a
+ certain range.
+ </p>
+ <%= code_for('comparisons', 'healthy') %>
+
+ <p>
+ <span id="interpolation" class="bookmark"></span>
+ <b class="header">String and RegExp Interpolation</b>
+ Ruby-style string interpolation is included in CoffeeScript. Double-quoted
+ strings allow for interpolated values, while single-quoted strings are literal.
+ </p>
+ <%= code_for('interpolation', 'quote') %>
+ <p>
+ And arbitrary expressions can be interpolated by using brackets <tt>#{ ... }</tt><br />
+ Interpolation works the same way within regular expressions.
+ </p>
+ <%= code_for('interpolation_expression', 'sentence') %>
+
+ <p>
+ <span id="heredocs" class="bookmark"></span>
+ <b class="header">Multiline Strings, Heredocs, and Block Comments</b>
+ Multiline strings are allowed in CoffeeScript.
+ </p>
+ <%= code_for('strings', 'mobyDick') %>
+ <p>
+ Heredocs can be used to hold formatted or indentation-sensitive text
+ (or, if you just don't feel like escaping quotes and apostrophes). The
+ indentation level that begins the heredoc is maintained throughout, so
+ you can keep it all aligned with the body of your code.
+ </p>
+ <%= code_for('heredocs') %>
+ <p>
+ Double-quoted heredocs, like double-quoted strings, allow interpolation.
+ </p>
+ <p>
+ Sometimes you'd like to pass a block comment through to the generated
+ JavaScript. For example, when you need to embed a licensing header at
+ the top of a file. Block comments, which mirror the synax for heredocs,
+ are preserved in the generated code.
+ </p>
+ <%= code_for('block_comment') %>
+
+ <h2>
+ <span id="cake" class="bookmark"></span>
+ Cake, and Cakefiles
+ </h2>
+
+ <p>
+ CoffeeScript includes a simple build system similar to
+ <a href="http://www.gnu.org/software/make/">Make</a> and
+ <a href="http://rake.rubyforge.org/">Rake</a>. Naturally,
+ it's called Cake, and is used for the build and test tasks for the CoffeeScript
+ language itself. Tasks are defined in a file named <tt>Cakefile</tt>, and
+ can be invoked by running <tt>cake taskname</tt> from within the directory.
+ To print a list of all the tasks and options, just run <tt>cake</tt>.
+ </p>
+
+ <p>
+ Task definitions are written in CoffeeScript, so you can put arbitrary code
+ in your Cakefile. Define a task with a name, a long description, and the
+ function to invoke when the task is run. If your task takes a command-line
+ option, you can define the option with short and long flags, and it will
+ be made available in the <tt>options</tt> object. Here's a task that uses
+ the Node.js API to rebuild CoffeeScript's parser:
+ </p>
+ <%= code_for('cake_tasks') %>
+ <p>
+ If you need to invoke one task before another — for example, running
+ <tt>build</tt> before <tt>test</tt>, you can use the <tt>invoke</tt> function:
+ <tt>invoke 'build'</tt>
+ </p>
+
+ <h2>
+ <span id="scripts" class="bookmark"></span>
+ "text/coffeescript" Script Tags
+ </h2>
+
+ <p>
+ While it's not recommended for serious use, CoffeeScripts may be included
+ directly within the browser using <tt><script type="text/coffeescript"></tt>
+ tags. The source includes a compressed and minified version of the compiler
+ (<a href="extras/coffee-script.js">Download current version here, 43k when gzipped</a>)
+ as <tt>extras/coffee-script.js</tt>. Include this file on a page with
+ inline CoffeeScript tags, and it will compile and evaluate them in order.
+ </p>
+
+ <p>
+ In fact, the little bit of glue script that runs "Try CoffeeScript" above,
+ as well as jQuery for the menu, is implemented in just this way.
+ View source and look at the bottom of the page to see the example.
+ Including the script also gives you access to <tt>CoffeeScript.compile()</tt>
+ so you can pop open Firebug and try compiling some strings.
+ </p>
+
+ <p>
+ The usual caveats about CoffeeScript apply — your inline scripts will
+ run within a closure wrapper, so if you want to expose global variables or
+ functions, attach them to the <tt>window</tt> object.
+ </p>
+
+ <h2>
+ <span id="resources" class="bookmark"></span>
+ Resources
+ </h2>
+
+ <ul>
+ <li>
+ <a href="http://github.com/jashkenas/coffee-script/">Source Code</a><br />
+ Use <tt>bin/coffee</tt> to test your changes,<br />
+ <tt>bin/cake test</tt> to run the test suite,<br />
+ <tt>bin/cake build</tt> to rebuild the CoffeeScript compiler, and <br />
+ <tt>bin/cake build:parser</tt> to regenerate the Jison parser if you're
+ working on the grammar. <br /><br />
+ <tt>git checkout lib && bin/cake build:full</tt> is a good command to run when you're working
+ on the core language. It'll refresh the lib directory
+ (in case you broke something), build your altered compiler, use that to
+ rebuild itself (a good sanity test) and then run all of the tests. If
+ they pass, there's a good chance you've made a successful change.
+ </li>
+ <li>
+ <a href="http://github.com/jashkenas/coffee-script/issues">CoffeeScript Issues</a><br />
+ Bugs reports, feature requests, and general discussion all belong here.
+ </li>
+ <li>
+ If you'd like to chat, stop by <tt>#coffeescript</tt> on Freenode in the
+ IRC client of your choice, or on
+ <a href="http://webchat.freenode.net/">webchat.freenode.net</a>.
+ </li>
+ <li>
+ <b>yeungda</b>'s <a href="http://github.com/yeungda/jcoffeescript">JCoffeeScript</a>
+ — A Java Library that uses Rhino to compile CoffeeScript, allowing
+ compilation within Java projects or on systems that Node.js doesn't support.
+ </li>
+ <li>
+ <b>defunkt</b>'s <a href="http://github.com/defunkt/coffee-mode">CoffeeScript Major Mode</a>
+ — a Emacs major mode that provides syntax highlighting, indentation
+ support, and some bonus commands.
+ </li>
+ <li>
+ <b>jashkenas</b>'s <a href="http://github.com/jashkenas/coffee-script-tmbundle">CoffeeScript TextMate Bundle</a>
+ — which provides syntax highlighting, snippet expansion, and the
+ ability to run bits of CoffeeScript from within TextMate itself.
+ </li>
+ <li>
+ <b>kchmck</b>'s <a href="http://github.com/kchmck/vim-coffee-script">Vim CoffeeScript</a>
+ — which adds Vim syntax highlighting and indentation support.
+ </li>
+ <li>
+ <b>wavded</b>'s <a href="http://github.com/wavded/gedit-coffeescript">gedit-coffeescript</a>
+ — a CoffeeScript syntax highlighter for the gedit text editor.
+ </li>
+ <li>
+ <b>yeungda</b>'s <a href="http://yeungda.github.com/coffeescript-idea/">coffeescript-idea</a>
+ — a plugin for IntelliJ IDEA and RubyMine providing syntax highlighting.
+ </li>
+ <li>
+ <b>mattly</b>'s <a href="http://github.com/mattly/rack-coffee">rack-coffee</a>
+ — a small Rack middleware for serving CoffeeScript files as
+ compiled JavaScript on the fly.
+ </li>
+ <li>
+ <b>jnicklas</b>'s <a href="http://github.com/jnicklas/bistro_car">BistroCar</a>
+ — a plugin that serves and bundles CoffeeScript from within your
+ Rails application.
+ </li>
+ <li>
+ <b>dsc</b>'s <a href="http://github.com/dsc/coffeecup">CoffeeCup</a>
+ — a Python WSGI middleware that compiles CoffeeScript to JavaScript
+ on-demand during development.
+ </li>
+ <li>
+ <b>sutto</b>'s <a href="http://github.com/Sutto/barista">Barista</a>
+ — a BistroCar alternative that integrates well with
+ <a href="http://documentcloud.github.com/jammit">Jammit</a> and Rails 3.
+ </li>
+ <li>
+ <b>inem</b> and <b>gerad</b>'s <a href="http://github.com/gerad/coffee-haml-filter">coffee-haml-filter</a>
+ — a custom filter for rendering CoffeeScript inline within
+ <a href="http://haml-lang.com/">HAML</a> templates.
+ </li>
+ <li>
+ <b>chrislloyd</b>'s <a href="http://github.com/chrislloyd/roast">Roast</a>
+ — a CoffeeScript compiler plug-in that allows you to include external
+ source files.
+ </li>
+ <li>
+ <b>andrzejsliwa</b>'s <a href="http://github.com/andrzejsliwa/coffeeapp">CoffeeApp</a>
+ — a CoffeeScript wrapper for CouchApps, web applications served
+ directly from CouchDB.
+ </li>
+ <li>
+ <b>mauricemach</b>'s <a href="http://github.com/mauricemach/coffeekup">CoffeeKup</a>
+ — Markup as CoffeeScript. After _why's
+ <a href="http://markaby.github.com/">Markaby</a>.
+ </li>
+ <li>
+ <b>jashkenas</b>'s <a href="http://jashkenas.github.com/docco/">Docco</a>
+ — a quick-and-dirty literate-programming-style documentation generator
+ for CoffeeScript. Used to produce the annotated source.
+ </li>
+ </ul>
+
+ <h2>
+ <span id="webchat" class="bookmark"></span>
+ Web Chat (IRC)
+ </h2>
+
+ <p>
+ Quick help and advice can usually be found in the CoffeeScript IRC room.
+ Join <tt>#coffeescript</tt> on <tt>irc.freenode.net</tt>, or click the
+ button below to open a webchat session on this page.
+ </p>
+
+ <p>
+ <button id="open_webchat">click to open #coffeescript</button>
+ </p>
+
+ <h2>
+ <span id="change_log" class="bookmark"></span>
+ Change Log
+ </h2>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.4</b>
+ CoffeeScript now uses appropriately-named temporary variables, and recycles
+ their references after use. Added <tt>require.extensions</tt> support for
+ <b>Node.js 0.3</b>. Loading CoffeeScript in the browser now adds just a
+ single <tt>CoffeeScript</tt> object to global scope.
+ Fixes for implicit object and block comment edge cases.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.3</b>
+ CoffeeScript <tt>switch</tt> statements now compile into JS <tt>switch</tt>
+ statements — they previously compiled into <tt>if/else</tt> chains
+ for JavaScript 1.3 compatibility.
+ Soaking a function invocation is now supported. Users of the RubyMine
+ editor should now be able to use <tt>--watch</tt> mode.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.2</b>
+ Specifying the start and end of a range literal is now optional, eg. <tt>array[3..]</tt>.
+ You can now say <tt>a not instanceof b</tt>.
+ Fixed important bugs with nested significant and non-significant indentation (Issue #637).
+ Added a <tt>--require</tt> flag that allows you to hook into the <tt>coffee</tt> command.
+ Added a custom <tt>jsl.conf</tt> file for our preferred JavaScriptLint setup.
+ Sped up Jison grammar compilation time by flattening rules for operations.
+ Block comments can now be used with JavaScript-minifier-friendly syntax.
+ Added JavaScript's compound assignment bitwise operators. Bugfixes to
+ implicit object literals with leading number and string keys, as the subject
+ of implicit calls, and as part of compound assignment.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.1</b>
+ Bugfix release for <b>0.9.1</b>. Greatly improves the handling of mixed
+ implicit objects, implicit function calls, and implicit indentation.
+ String and regex interpolation is now strictly <tt>#{ ... }</tt> (Ruby style).
+ The compiler now takes a <tt>--require</tt> flag, which specifies scripts
+ to run before compilation.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.0</b>
+ The CoffeeScript <b>0.9</b> series is considered to be a release candidate
+ for <b>1.0</b>; let's give her a shakedown cruise. <b>0.9.0</b> introduces a massive
+ backwards-incompatible change: Assignment now uses <tt>=</tt>, and object
+ literals use <tt>:</tt>, as in JavaScript. This allows us to have implicit
+ object literals, and YAML-style object definitions. Half assignments are
+ removed, in favor of <tt>+=</tt>, <tt>or=</tt>, and friends.
+ Interpolation now uses a hash mark <tt>#</tt> instead of the dollar sign
+ <tt>$</tt> — because dollar signs may be part of a valid JS identifier.
+ Downwards range comprehensions are now safe again, and are optimized to
+ straight for loops when created with integer endpoints.
+ A fast, unguarded form of object comprehension was added:
+ <tt>for all key, value of object</tt>. Mentioning the <tt>super</tt> keyword
+ with no arguments now forwards all arguments passed to the function,
+ as in Ruby. If you extend class <tt>B</tt> from parent class <tt>A</tt>, if
+ <tt>A</tt> has an <tt>extended</tt> method defined, it will be called, passing in <tt>B</tt> —
+ this enables static inheritance, among other things. Cleaner output for
+ functions bound with the fat arrow. <tt>@variables</tt> can now be used
+ in parameter lists, with the parameter being automatically set as a property
+ on the object — useful in constructors and setter functions.
+ Constructor functions can now take splats.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.7.2</b>
+ Quick bugfix (right after 0.7.1) for a problem that prevented <tt>coffee</tt>
+ command-line options from being parsed in some circumstances.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.7.1</b>
+ Block-style comments are now passed through and printed as JavaScript block
+ comments -- making them useful for licenses and copyright headers. Better
+ support for running coffee scripts standalone via hashbangs.
+ Improved syntax errors for tokens that are not in the grammar.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.7.0</b>
+ Official CoffeeScript variable style is now camelCase, as in JavaScript.
+ Reserved words are now allowed as object keys, and will be quoted for you.
+ Range comprehensions now generate cleaner code, but you have to specify <tt>by -1</tt>
+ if you'd like to iterate downward. Reporting of syntax errors is greatly
+ improved from the previous release. Running <tt>coffee</tt> with no arguments
+ now launches the REPL, with Readline support. The <tt><-</tt> bind operator
+ has been removed from CoffeeScript. The <tt>loop</tt> keyword was added,
+ which is equivalent to a <tt>while true</tt> loop. Comprehensions that contain
+ closures will now close over their variables, like the semantics of a <tt>forEach</tt>.
+ You can now use bound function in class definitions (bound to the instance).
+ For consistency, <tt>a in b</tt> is now an array presence check, and <tt>a of b</tt>
+ is an object-key check. Comments are no longer passed through to the generated
+ JavaScript.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.6.2</b>
+ The <tt>coffee</tt> command will now preserve directory structure when
+ compiling a directory full of scripts. Fixed two omissions that were preventing
+ the CoffeeScript compiler from running live within Internet Explorer.
+ There's now a syntax for block comments, similar in spirit to CoffeeScript's heredocs.
+ ECMA Harmony DRY-style pattern matching is now supported, where the name
+ of the property is the same as the name of the value: <tt>{name, length}: func</tt>.
+ Pattern matching is now allowed within comprehension variables. <tt>unless</tt>
+ is now allowed in block form. <tt>until</tt> loops were added, as the inverse
+ of <tt>while</tt> loops. <tt>switch</tt> statements are now allowed without
+ switch object clauses. Compatible
+ with Node.js <b>v0.1.95</b>.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.6.1</b>
+ Upgraded CoffeeScript for compatibility with the new Node.js <b>v0.1.90</b>
+ series.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.6.0</b>
+ Trailing commas are now allowed, a-la Python. Static
+ properties may be assigned directly within class definitions,
+ using <tt>@property</tt> notation.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.6</b>
+ Interpolation can now be used within regular expressions and heredocs, as well as
+ strings. Added the <tt><-</tt> bind operator.
+ Allowing assignment to half-expressions instead of special <tt>||=</tt>-style
+ operators. The arguments object is no longer automatically converted into
+ an array. After requiring <tt>coffee-script</tt>, Node.js can now directly
+ load <tt>.coffee</tt> files, thanks to <b>registerExtension</b>. Multiple
+ splats can now be used in function calls, arrays, and pattern matching.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.5</b>
+ String interpolation, contributed by
+ <a href="http://github.com/StanAngeloff">Stan Angeloff</a>.
+ Since <tt>--run</tt> has been the default since <b>0.5.3</b>, updating
+ <tt>--stdio</tt> and <tt>--eval</tt> to run by default, pass <tt>--compile</tt>
+ as well if you'd like to print the result.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.4</b>
+ Bugfix that corrects the Node.js global constants <tt>__filename</tt> and
+ <tt>__dirname</tt>. Tweaks for more flexible parsing of nested function
+ literals and improperly-indented comments. Updates for the latest Node.js API.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.3</b>
+ CoffeeScript now has a syntax for defining classes. Many of the core
+ components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them.
+ Cakefiles can use <tt>optparse.coffee</tt> to define options for tasks.
+ <tt>--run</tt> is now the default flag for the <tt>coffee</tt> command,
+ use <tt>--compile</tt> to save JavaScripts. Bugfix for an ambiguity between
+ RegExp literals and chained divisions.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.2</b>
+ Added a compressed version of the compiler for inclusion in web pages as
+ <br /><tt>extras/coffee-script.js</tt>. It'll automatically run any script tags
+ with type <tt>text/coffeescript</tt> for you. Added a <tt>--stdio</tt> option
+ to the <tt>coffee</tt> command, for piped-in compiles.
+ </p>
+
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.1</b>
+ Improvements to null soaking with the existential operator, including
+ soaks on indexed properties. Added conditions to <tt>while</tt> loops,
+ so you can use them as filters with <tt>when</tt>, in the same manner as
+ comprehensions.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.0</b>
+ CoffeeScript 0.5.0 is a major release, While there are no language changes,
+ the Ruby compiler has been removed in favor of a self-hosting
+ compiler written in pure CoffeeScript.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.3.2</b>
+ <tt>@property</tt> is now a shorthand for <tt>this.property</tt>.<br />
+ Switched the default JavaScript engine from Narwhal to Node.js. Pass
+ the <tt>--narwhal</tt> flag if you'd like to continue using it.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.3.0</b>
+ CoffeeScript 0.3 includes major syntax changes:
+ <br />
+ The function symbol was changed to
+ <tt>-></tt>, and the bound function symbol is now <tt>=></tt>.
+ <br />
+ Parameter lists in function definitions must now be wrapped in parentheses.
+ <br />
+ Added property soaking, with the <tt>?.</tt> operator.
+ <br />
+ Made parentheses optional, when invoking functions with arguments.
+ <br />
+ Removed the obsolete block literal syntax.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.6</b>
+ Added Python-style chained comparisons, the conditional existence
+ operator <tt>?=</tt>, and some examples from <i>Beautiful Code</i>.
+ Bugfixes relating to statement-to-expression conversion, arguments-to-array
+ conversion, and the TextMate syntax highlighter.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.5</b>
+ The conditions in switch statements can now take multiple values at once —
+ If any of them are true, the case will run. Added the long arrow <tt>==></tt>,
+ which defines and immediately binds a function to <tt>this</tt>. While loops can
+ now be used as expressions, in the same way that comprehensions can. Splats
+ can be used within pattern matches to soak up the rest of an array.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.4</b>
+ Added ECMAScript Harmony style destructuring assignment, for dealing with
+ extracting values from nested arrays and objects. Added indentation-sensitive
+ heredocs for nicely formatted strings or chunks of code.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.3</b>
+ Axed the unsatisfactory <tt>ino</tt> keyword, replacing it with <tt>of</tt> for
+ object comprehensions. They now look like: <tt>for prop, value of object</tt>.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.2</b>
+ When performing a comprehension over an object, use <tt>ino</tt>, instead
+ of <tt>in</tt>, which helps us generate smaller, more efficient code at
+ compile time.
+ <br />
+ Added <tt>::</tt> as a shorthand for saying <tt>.prototype.</tt>
+ <br />
+ The "splat" symbol has been changed from a prefix asterisk <tt>*</tt>, to
+ a postfix ellipsis <tt>...</tt>
+ <br />
+ Added JavaScript's <tt>in</tt> operator,
+ empty <tt>return</tt> statements, and empty <tt>while</tt> loops.
+ <br />
+ Constructor functions that start with capital letters now include a
+ safety check to make sure that the new instance of the object is returned.
+ <br />
+ The <tt>extends</tt> keyword now functions identically to <tt>goog.inherits</tt>
+ in Google's Closure Library.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.1</b>
+ Arguments objects are now converted into real arrays when referenced.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.0</b>
+ Major release. Significant whitespace. Better statement-to-expression
+ conversion. Splats. Splice literals. Object comprehensions. Blocks.
+ The existential operator. Many thanks to all the folks who posted issues,
+ with special thanks to
+ <a href="http://github.com/liamoc">Liam O'Connor-Davis</a> for whitespace
+ and expression help.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.6</b>
+ Bugfix for running <tt>coffee --interactive</tt> and <tt>--run</tt>
+ from outside of the CoffeeScript directory. Bugfix for nested
+ function/if-statements.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.5</b>
+ Array slice literals and array comprehensions can now both take Ruby-style
+ ranges to specify the start and end. JavaScript variable declaration is
+ now pushed up to the top of the scope, making all assignment statements into
+ expressions. You can use <tt>\</tt> to escape newlines.
+ The <tt>coffee-script</tt> command is now called <tt>coffee</tt>.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.4</b>
+ The official CoffeeScript extension is now <tt>.coffee</tt> instead of
+ <tt>.cs</tt>, which properly belongs to
+ <a href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)">C#</a>.
+ Due to popular demand, you can now also use <tt>=</tt> to assign. Unlike
+ JavaScript, <tt>=</tt> can also be used within object literals, interchangeably
+ with <tt>:</tt>. Made a grammatical fix for chained function calls
+ like <tt>func(1)(2)(3)(4)</tt>. Inheritance and super no longer use
+ <tt>__proto__</tt>, so they should be IE-compatible now.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.3</b>
+ The <tt>coffee</tt> command now includes <tt>--interactive</tt>,
+ which launches an interactive CoffeeScript session, and <tt>--run</tt>,
+ which directly compiles and executes a script. Both options depend on a
+ working installation of Narwhal.
+ The <tt>aint</tt> keyword has been replaced by <tt>isnt</tt>, which goes
+ together a little smoother with <tt>is</tt>.
+ Quoted strings are now allowed as identifiers within object literals: eg.
+ <tt>{"5+5": 10}</tt>.
+ All assignment operators now use a colon: <tt>+:</tt>, <tt>-:</tt>,
+ <tt>*:</tt>, etc.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.2</b>
+ Fixed a bug with calling <tt>super()</tt> through more than one level of
+ inheritance, with the re-addition of the <tt>extends</tt> keyword.
+ Added experimental <a href="http://narwhaljs.org/">Narwhal</a>
+ support (as a Tusk package), contributed by
+ <a href="http://tlrobinson.net/">Tom Robinson</a>, including
+ <b>bin/cs</b> as a CoffeeScript REPL and interpreter.
+ New <tt>--no-wrap</tt> option to suppress the safety function
+ wrapper.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.1</b>
+ Added <tt>instanceof</tt> and <tt>typeof</tt> as operators.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.0</b>
+ Initial CoffeeScript release.
+ </p>
+
+ </div>
+
+ <script type="text/coffeescript">
+
+ # Set up the compilation function, to run when you stop typing.
+ compile_source = ->
+ source = $('#repl_source').val()
+ window.compiled_js = ''
+ try
+ window.compiled_js = CoffeeScript.compile source, bare: on
+ $('#repl_results').text window.compiled_js
+ $('#error').hide()
+ catch error
+ $('#error').text(error.message).show()
+
+ # Listen for keypresses and recompile.
+ $('#repl_source').keyup -> compile_source()
+
+ # Eval the compiled js.
+ $('button.run').click ->
+ try
+ eval window.compiled_js
+ catch error then alert error
+
+ current_nav = null
+
+ # Helper to hide the menus.
+ close_menus = ->
+ if current_nav
+ current_nav.removeClass 'active'
+ document.body.className = 'minimized'
+ current_nav = null
+
+ # Bind navigation buttons to open the menus.
+ $('.navigation').click (e) ->
+ return if e.target.tagName.toLowerCase() is 'a'
+ if this isnt (current_nav and current_nav[0])
+ close_menus()
+ current_nav = $(this)
+ current_nav.addClass 'active'
+ false
+
+ $(document.body).click -> close_menus()
+
+ $('.navigation .full_screen').click ->
+ document.body.className = 'full_screen'
+
+ $('.navigation .minimize').click ->
+ document.body.className = 'minimized'
+
+ $('#open_webchat').click ->
+ $(this).replaceWith $('<iframe src="http://webchat.freenode.net/?channels=coffeescript" width="625" height="400"></iframe>')
+
+ compile_source()
+
+ </script>
+
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+ <script src="extras/coffee-script.js"></script>
+
+</body>
+</html>
--- /dev/null
+var volume, winner;
+if (ignition === true) {
+ launch();
+}
+if (band !== SpinalTap) {
+ volume = 10;
+}
+if (answer !== false) {
+ letTheWildRumpusBegin();
+}
+if (car.speed < limit) {
+ accelerate();
+}
+if ((47 === pick || 92 === pick || 13 === pick)) {
+ winner = true;
+}
+print(inspect("My name is " + this.name));
\ No newline at end of file
--- /dev/null
+var _i, _len, _len2, _ref, _result, food, lunch, pos, roid, roid2;
+lunch = (function() {
+ _result = []; _ref = ['toast', 'cheese', 'wine'];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ food = _ref[_i];
+ _result.push(eat(food));
+ }
+ return _result;
+})();
+for (pos = 0, _len = asteroids.length; pos < _len; pos++) {
+ roid = asteroids[pos];
+ for (_i = 0, _len2 = asteroids.length; _i < _len2; _i++) {
+ roid2 = asteroids[_i];
+ if (roid !== roid2) {
+ if (roid.overlaps(roid2)) {
+ roid.explode();
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+CoffeeScript Compiler v0.9.4
+Released under the MIT License
+*/
\ No newline at end of file
--- /dev/null
+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);
+});
\ No newline at end of file
--- /dev/null
+var Animal, Horse, Snake, sam, tom;
+var __extends = function(child, parent) {
+ var ctor = function() {};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+};
+Animal = (function() {
+ return function Animal(_arg) {
+ this.name = _arg;
+ return this;
+ };
+})();
+Animal.prototype.move = function(meters) {
+ return alert(this.name + " moved " + meters + "m.");
+};
+Snake = (function() {
+ return function Snake() {
+ return Animal.apply(this, arguments);
+ };
+})();
+__extends(Snake, Animal);
+Snake.prototype.move = function() {
+ alert("Slithering...");
+ return Snake.__super__.move.call(this, 5);
+};
+Horse = (function() {
+ return function Horse() {
+ return Animal.apply(this, arguments);
+ };
+})();
+__extends(Horse, Animal);
+Horse.prototype.move = function() {
+ alert("Galloping...");
+ return Horse.__super__.move.call(this, 45);
+};
+sam = new Snake("Sammy the Python");
+tom = new Horse("Tommy the Palomino");
+sam.move();
+tom.move();
\ No newline at end of file
--- /dev/null
+var cholesterol, healthy;
+cholesterol = 127;
+healthy = (200 > cholesterol) && (cholesterol > 60);
\ No newline at end of file
--- /dev/null
+var date, mood, options;
+if (singing) {
+ mood = greatlyImproved;
+}
+if (happy && knowsIt) {
+ clapsHands();
+ chaChaCha();
+} else {
+ showIt();
+}
+date = friday ? sue : jill;
+options || (options = defaults);
\ No newline at end of file
--- /dev/null
+var hi;
+hi = function() {
+ return [document.title, "Hello JavaScript"].join(": ");
+};
\ No newline at end of file
--- /dev/null
+var solipsism, speed;
+if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
+ solipsism = true;
+}
+(typeof speed !== "undefined" && speed !== null) ? speed : (speed = 140);
\ No newline at end of file
--- /dev/null
+var eldest, grade;
+grade = function(student) {
+ return student.excellentWork ? "A+" : (student.okayStuff ? (student.triedHard ? "B" : "B-") : "C");
+};
+eldest = 24 > 21 ? "Liz" : "Ike";
\ No newline at end of file
--- /dev/null
+var one, six, three, two;
+six = (one = 1) + (two = 2) + (three = 3);
\ No newline at end of file
--- /dev/null
+var _result, globals, name;
+var __hasProp = Object.prototype.hasOwnProperty;
+globals = (function() {
+ _result = [];
+ for (name in window) {
+ if (!__hasProp.call(window, name)) continue;
+ _result.push(name);
+ }
+ return _result;
+})().slice(0, 10);
\ No newline at end of file
--- /dev/null
+alert((function() {
+ try {
+ return nonexistent / undefined;
+ } catch (error) {
+ return "And the error is ... " + error;
+ }
+})());
\ No newline at end of file
--- /dev/null
+var Account;
+var __bind = function(func, context) {
+ return function() { return func.apply(context, 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));
+};
\ No newline at end of file
--- /dev/null
+var cube, square;
+square = function(x) {
+ return x * x;
+};
+cube = function(x) {
+ return square(x) * x;
+};
\ No newline at end of file
--- /dev/null
+var html;
+html = '<strong>\n cup of coffeescript\n</strong>';
\ No newline at end of file
--- /dev/null
+var author, quote;
+author = "Wittgenstein";
+quote = ("A picture is a fact. -- " + author);
\ No newline at end of file
--- /dev/null
+var dates, sentence, sep;
+sentence = ("" + (22 / 7) + " is a decent approximation of π");
+sep = "[.\\/\\- ]";
+dates = /\d+#{sep}\d+#{sep}\d+/g;
\ No newline at end of file
--- /dev/null
+var _ref, city, forecast, temp, weatherReport;
+weatherReport = function(location) {
+ return [location, 72, "Mostly Sunny"];
+};
+_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];
\ No newline at end of file
--- /dev/null
+var _result, age, ages, child, yearsOld;
+var __hasProp = Object.prototype.hasOwnProperty;
+yearsOld = {
+ max: 10,
+ ida: 9,
+ tim: 11
+};
+ages = (function() {
+ _result = [];
+ for (child in yearsOld) {
+ if (!__hasProp.call(yearsOld, child)) continue;
+ age = yearsOld[child];
+ _result.push(child + " is " + age);
+ }
+ return _result;
+})();
\ No newline at end of file
--- /dev/null
+var _ref, _ref2, city, futurists, name, street;
+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];
\ No newline at end of file
--- /dev/null
+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
+ }
+};
\ No newline at end of file
--- /dev/null
+$('.account').css({
+ "class": 'active'
+});
\ No newline at end of file
--- /dev/null
+var _i, _len, _result, cubes, list, math, num, number, opposite, race, square;
+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);
+ }
+};
+race = function(winner) {
+ var runners;
+ runners = __slice.call(arguments, 1);
+ return print(winner, runners);
+};
+if (typeof elvis !== "undefined" && elvis !== null) {
+ alert("I knew it!");
+}
+cubes = (function() {
+ _result = [];
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
+ num = list[_i];
+ _result.push(math.cube(num));
+ }
+ return _result;
+})();
\ No newline at end of file
--- /dev/null
+var _ref, theBait, theSwitch;
+theBait = 1000;
+theSwitch = 0;
+_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];
\ No newline at end of file
--- /dev/null
+var _ref, close, contents, open, tag;
+var __slice = Array.prototype.slice;
+tag = "<impossible>";
+_ref = tag.split(""), open = _ref[0], contents = __slice.call(_ref, 1, _ref.length - 1), close = _ref[_ref.length - 1];
\ No newline at end of file
--- /dev/null
+String.prototype.dasherize = function() {
+ return this.replace(/_/g, "-");
+};
\ No newline at end of file
--- /dev/null
+var _result, countdown, deliverEggs, num;
+countdown = (function() {
+ _result = [];
+ for (num = 10; num >= 1; num--) {
+ _result.push(num);
+ }
+ return _result;
+})();
+deliverEggs = function() {
+ var _ref, _result2, dozen, i;
+ _result2 = []; _ref = eggs.length;
+ for (i = 0; (0 <= _ref ? i < _ref : i > _ref); i += 12) {
+ _result2.push((function() {
+ dozen = eggs.slice(i, i + 12);
+ return deliver(new eggCarton(dozen));
+ })());
+ }
+ return _result2;
+};
\ No newline at end of file
--- /dev/null
+var changeNumbers, inner, outer;
+outer = 1;
+changeNumbers = function() {
+ var inner;
+ inner = -1;
+ return (outer = 10);
+};
+inner = changeNumbers();
\ No newline at end of file
--- /dev/null
+var copy, numbers, threeToSix;
+numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+threeToSix = numbers.slice(3, 6 + 1);
+copy = numbers.slice(0, numbers.length);
\ No newline at end of file
--- /dev/null
+var _ref, _ref2;
+(((_ref = lottery.drawWinner()) != null) ? (((_ref2 = _ref.address) != null) ? _ref2.zipcode : undefined) : undefined);
\ No newline at end of file
--- /dev/null
+var awardMedals, contenders, gold, rest, silver;
+var __slice = Array.prototype.slice;
+gold = (silver = (rest = "unknown"));
+awardMedals = function(first, second) {
+ var others;
+ others = __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(awardMedals, contenders);
+alert("Gold: " + gold);
+alert("Silver: " + silver);
+alert("The Field: " + rest);
\ No newline at end of file
--- /dev/null
+var _ref, numbers;
+numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+([].splice.apply(numbers, [3, 6 - 3 + 1].concat(_ref = [-3, -4, -5, -6])), _ref);
\ No newline at end of file
--- /dev/null
+var mobyDick;
+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...";
\ No newline at end of file
--- /dev/null
+switch (day) {
+ case "Mon":
+ go(work);
+ break;
+ case "Tue":
+ go(relax);
+ break;
+ case "Thu":
+ go(iceFishing);
+ break;
+ case "Fri":
+ case "Sat":
+ if (day === bingoDay) {
+ go(bingo);
+ go(dancing);
+ }
+ break;
+ case "Sun":
+ go(church);
+ break;
+ default:
+ go(work);
+}
\ No newline at end of file
--- /dev/null
+try {
+ allHellBreaksLoose();
+ catsAndDogsLivingTogether();
+} catch (error) {
+ print(error);
+} finally {
+ cleanUp();
+}
\ No newline at end of file
--- /dev/null
+var _result, lyrics, num;
+if (this.studyingEconomics) {
+ while (supply > demand) {
+ buy();
+ }
+ while (!(supply > demand)) {
+ sell();
+ }
+}
+num = 6;
+lyrics = (function() {
+ _result = [];
+ while (num -= 1) {
+ _result.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
+ }
+ return _result;
+})();
\ No newline at end of file
--- /dev/null
+# Beautiful Code, Chapter 6.
+# The implementation of binary search that is tested.
+
+# Return the index of an element in a sorted list. (or -1, if not present)
+index = (list, target) ->
+ [low, high] = [0, list.length]
+ while low < high
+ mid = (low + high) >> 1
+ val = list[mid]
+ return mid if val is target
+ if val < target then low = mid + 1 else high = mid
+ return -1
+
+puts 2 is index [10, 20, 30, 40, 50], 30
+puts 4 is index [-97, 35, 67, 88, 1200], 1200
+puts 0 is index [0, 45, 70], 0
\ No newline at end of file
--- /dev/null
+# Beautiful Code, Chapter 3.
+# Produces the expected runtime of Quicksort, for every integer from 1 to N.
+
+runtime = (N) ->
+ [sum, t] = [0, 0]
+ for n in [1..N]
+ sum += 2 * t
+ t = n - 1 + sum / n
+ t
+
+puts runtime(3) is 2.6666666666666665
+puts runtime(5) is 7.4
+puts runtime(8) is 16.92142857142857
--- /dev/null
+# Beautiful Code, Chapter 1.
+# Implements a regular expression matcher that supports character matches,
+# '.', '^', '$', and '*'.
+
+# Search for the regexp anywhere in the text.
+match = (regexp, text) ->
+ return match_here(regexp.slice(1), text) if regexp[0] is '^'
+ while text
+ return true if match_here(regexp, text)
+ text = text.slice(1)
+ false
+
+# Search for the regexp at the beginning of the text.
+match_here = (regexp, text) ->
+ [cur, next] = [regexp[0], regexp[1]]
+ if regexp.length is 0 then return true
+ if next is '*' then return match_star(cur, regexp.slice(2), text)
+ if cur is '$' and not next then return text.length is 0
+ if text and (cur is '.' or cur is text[0]) then return match_here(regexp.slice(1), text.slice(1))
+ false
+
+# Search for a kleene star match at the beginning of the text.
+match_star = (c, regexp, text) ->
+ loop
+ return true if match_here(regexp, text)
+ return false unless text and (text[0] is c or c is '.')
+ text = text.slice(1)
+
+puts match("ex", "some text")
+puts match("s..t", "spit")
+puts match("^..t", "buttercup")
+puts match("i..$", "cherries")
+puts match("o*m", "vrooooommm!")
+puts match("^hel*o$", "hellllllo")
\ No newline at end of file
--- /dev/null
+# After wycats' http://yehudakatz.com/2010/02/07/the-building-blocks-of-ruby/
+
+# Sinatra.
+get '/hello', ->
+ 'Hello World'
+
+
+# Append.
+append = (location, data) ->
+ path = new Pathname location
+ throw new Error("Location does not exist") unless path.exists()
+
+ File.open path, 'a', (file) ->
+ file.puts YAML.dump data
+
+ data
+
+
+# Rubinius' File.open implementation.
+File.open = (path, mode, block) ->
+ io = new File path, mode
+
+ return io unless block
+
+ try
+ block io
+ finally
+ io.close() unless io.closed()
+
+
+# Write.
+write = (location, data) ->
+ path = new Pathname location
+ raise "Location does not exist" unless path.exists()
+
+ File.open path, 'w', (file) ->
+ return false if Digest.MD5.hexdigest(file.read()) is data.hash()
+ file.puts YAML.dump data
+ true
+
+
+# Rails' respond_to.
+index = ->
+ people = Person.find 'all'
+
+ respond_to (format) ->
+ format.html()
+ format.xml -> render xml: people.xml()
+
+
+# Synchronization.
+synchronize = (block) ->
+ lock()
+ try block() finally unlock()
--- /dev/null
+# Functions:
+square = (x) -> x * x
+
+sum = (x, y) -> x + y
+
+odd = (x) -> x % 2 isnt 0
+
+even = (x) -> x % 2 is 0
+
+run_loop = ->
+ fire_events((e) -> e.stopPropagation())
+ listen()
+ wait()
+
+# Objects:
+dense_object_literal = {one: 1, two: 2, three: 3}
+
+spaced_out_multiline_object =
+ pi: 3.14159
+ list: [1, 2, 3, 4]
+ regex: /match[ing](every|thing|\/)/gi
+ three: new Idea
+
+ inner_obj:
+ freedom: -> _.freedom()
+
+# Arrays:
+stooges = [{moe: 45}, {curly: 43}, {larry: 46}]
+
+exponents = [((x) -> x), ((x) -> x * x), ((x) -> x * x * x)]
+
+empty = []
+
+multiline = [
+ 'line one'
+ 'line two'
+]
+
+# Conditionals and ternaries.
+if submarine.shields_up
+ full_speed_ahead()
+ fire_torpedos()
+else if submarine.sinking
+ abandon_ship()
+else
+ run_away()
+
+eldest = if 25 > 21 then liz else marge
+
+decoration = medal_of_honor if war_hero
+
+go_to_sleep() unless coffee
+
+# Returning early:
+race = ->
+ run()
+ walk()
+ crawl()
+ if tired then return sleep()
+ race()
+
+# Conditional assignment:
+good or= evil
+wine and= cheese
+
+# Nested property access and calls.
+((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position['top'].offset('x')
+
+a = b = c = 5
+
+# Embedded JavaScript.
+callback(
+ `function(e) { e.stop(); }`
+)
+
+# Try/Catch/Finally/Throw.
+try
+ all_hell_breaks_loose()
+ dogs_and_cats_living_together()
+ throw "up"
+catch error
+ print(error)
+finally
+ clean_up()
+
+try all_hell_breaks_loose() catch error then print(error) finally clean_up()
+
+# While loops, break and continue.
+while demand > supply
+ sell()
+ restock()
+
+while supply > demand then buy()
+
+loop
+ break if broken
+ continue if continuing
+
+# Unary operators.
+!!true
+
+# Lexical scoping.
+v_1 = 5
+change_a_and_set_b = ->
+ v_1 = 10
+ v_2 = 15
+v_2 = 20
+
+# Array comprehensions.
+supper = food.capitalize() for food in ['toast', 'cheese', 'wine']
+
+drink bottle for bottle, i in ['soda', 'wine', 'lemonade'] when even i
+
+# Switch statements ("else" serves as a default).
+activity = switch day
+ when "Tuesday" then eat_breakfast()
+ when "Sunday" then go_to_church()
+ when "Saturday" then go_to_the_park()
+ when "Wednesday"
+ if day is bingo_day
+ go_to_bingo()
+ else
+ eat_breakfast()
+ go_to_work()
+ eat_dinner()
+ else go_to_work()
+
+# Semicolons can optionally be used instead of newlines.
+wednesday = -> eat_breakfast(); go_to_work(); eat_dinner()
+
+# Array slice literals.
+zero_to_nine = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+three_to_six = zero_to_nine[3..6]
+
+# Multiline strings with inner quotes.
+story = "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
+sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
+aliquam erat volutpat. Ut wisi enim ad."
+
+# Inheritance and calling super.
+class Animal
+ constructor: (@name) ->
+
+ move: (meters) ->
+ alert this.name + " moved " + meters + "m."
+
+class Snake extends Animal
+ move: ->
+ alert 'Slithering...'
+ super 5
+
+class Horse extends Animal
+ move: ->
+ alert 'Galloping...'
+ super 45
+
+sam = new Snake "Sammy the Snake"
+tom = new Horse "Tommy the Horse"
+
+sam.move()
+tom.move()
+
+# Numbers.
+a_googol = 1e100
+hex = 0xff0000
+negative = -1.0
+infinity = Infinity
+nan = NaN
+
+# Deleting.
+delete secret.identity
\ No newline at end of file
--- /dev/null
+Ported from Nicholas Zakas' collection of computer science fundamentals, written
+in JavaScript. Originals available here:
+
+http://github.com/nzakas/computer-science-in-javascript
--- /dev/null
+# Uses a binary search algorithm to locate a value in the specified array.
+binary_search = (items, value) ->
+
+ start = 0
+ stop = items.length - 1
+ pivot = Math.floor (start + stop) / 2
+
+ while items[pivot] isnt value and start < stop
+
+ # Adjust the search area.
+ stop = pivot - 1 if value < items[pivot]
+ start = pivot + 1 if value > items[pivot]
+
+ # Recalculate the pivot.
+ pivot = Math.floor (stop + start) / 2
+
+ # Make sure we've found the correct value.
+ if items[pivot] is value then pivot else -1
+
+
+# Test the function.
+puts 2 is binary_search [10, 20, 30, 40, 50], 30
+puts 4 is binary_search [-97, 35, 67, 88, 1200], 1200
+puts 0 is binary_search [0, 45, 70], 0
+puts(-1 is binary_search [0, 45, 70], 10)
\ No newline at end of file
--- /dev/null
+# A bubble sort implementation, sorting the given array in-place.
+bubble_sort = (list) ->
+ for i in [0...list.length]
+ for j in [0...list.length - i]
+ [list[j], list[j+1]] = [list[j+1], list[j]] if list[j] > list[j+1]
+ list
+
+
+# Test the function.
+puts bubble_sort([3, 2, 1]).join(' ') is '1 2 3'
+puts bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
\ No newline at end of file
--- /dev/null
+# "Classic" linked list implementation that doesn't keep track of its size.
+class LinkedList
+
+ constructor: ->
+ this._head = null # Pointer to the first item in the list.
+
+
+ # Appends some data to the end of the list. This method traverses the existing
+ # list and places the value at the end in a new node.
+ add: (data) ->
+
+ # Create a new node object to wrap the data.
+ node = data: data, next: null
+
+ current = this._head or= node
+
+ if this._head isnt node
+ (current = current.next) while current.next
+ current.next = node
+
+ this
+
+
+ # Retrieves the data at the given position in the list.
+ item: (index) ->
+
+ # Check for out-of-bounds values.
+ return null if index < 0
+
+ current = this._head or null
+ i = -1
+
+ # Advance through the list.
+ (current = current.next) while current and index > (i += 1)
+
+ # Return null if we've reached the end.
+ current and current.data
+
+
+ # Remove the item from the given location in the list.
+ remove: (index) ->
+
+ # Check for out-of-bounds values.
+ return null if index < 0
+
+ current = this._head or null
+ i = -1
+
+ # Special case: removing the first item.
+ if index is 0
+ this._head = current.next
+ else
+
+ # Find the right location.
+ ([previous, current] = [current, current.next]) while index > (i += 1)
+
+ # Skip over the item to remove.
+ previous.next = current.next
+
+ # Return the value.
+ current and current.data
+
+
+ # Calculate the number of items in the list.
+ size: ->
+ current = this._head
+ count = 0
+
+ while current
+ count += 1
+ current = current.next
+
+ count
+
+
+ # Convert the list into an array.
+ toArray: ->
+ result = []
+ current = this._head
+
+ while current
+ result.push current.data
+ current = current.next
+
+ result
+
+
+ # The string representation of the linked list.
+ toString: -> this.toArray().toString()
+
+
+# Tests.
+list = new LinkedList
+
+list.add("Hi")
+puts list.size() is 1
+puts list.item(0) is "Hi"
+puts list.item(1) is null
+
+list = new LinkedList
+list.add("zero").add("one").add("two")
+puts list.size() is 3
+puts list.item(2) is "two"
+puts list.remove(1) is "one"
+puts list.item(0) is "zero"
+puts list.item(1) is "two"
+puts list.size() is 2
+puts list.item(-10) is null
--- /dev/null
+# Use the Luhn algorithm to validate a numeric identifier, such as credit card
+# numbers, national insurance numbers, etc.
+# See: http://en.wikipedia.org/wiki/Luhn_algorithm
+
+is_valid_identifier = (identifier) ->
+
+ sum = 0
+ alt = false
+
+ for i in [(identifier.length - 1)..0]
+
+ # Get the next digit.
+ num = parseInt identifier.charAt(i), 10
+
+ # If it's not a valid number, abort.
+ return false if isNaN(num)
+
+ # If it's an alternate number...
+ if alt
+ num *= 2
+ num = (num % 10) + 1 if num > 9
+
+ # Flip the alternate bit.
+ alt = !alt
+
+ # Add to the rest of the sum.
+ sum += num
+
+ # Determine if it's valid.
+ sum % 10 is 0
+
+
+# Tests.
+puts is_valid_identifier("49927398716") is true
+puts is_valid_identifier("4408041234567893") is true
+puts is_valid_identifier("4408041234567890") is false
--- /dev/null
+# Sorts an array in ascending natural order using merge sort.
+merge_sort = (list) ->
+
+ return list if list.length is 1
+
+ result = []
+ pivot = Math.floor list.length / 2
+ left = merge_sort list.slice 0, pivot
+ right = merge_sort list.slice pivot
+
+ while left.length and right.length
+ result.push(if left[0] < right[0] then left.shift() else right.shift())
+
+ result.concat(left).concat(right)
+
+
+# Test the function.
+puts merge_sort([3, 2, 1]).join(' ') is '1 2 3'
+puts merge_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
\ No newline at end of file
--- /dev/null
+# An in-place selection sort.
+selection_sort = (list) ->
+ len = list.length
+
+ # For each item in the list.
+ for i in [0...len]
+
+ # Set the minimum to this position.
+ min = i
+
+ # Check the rest of the array to see if anything is smaller.
+ (min = j if list[j] < list[min]) for j in [(i+1)...len]
+
+ # Swap if a smaller item has been found.
+ [list[i], list[min]] = [list[min], list[i]] if i isnt min
+
+ # The list is now sorted.
+ list
+
+
+# Test the function.
+puts selection_sort([3, 2, 1]).join(' ') is '1 2 3'
+puts selection_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
\ No newline at end of file
--- /dev/null
+# Examples from the Poignant Guide.
+
+# ['toast', 'cheese', 'wine'].each { |food| print food.capitalize }
+
+['toast', 'wine', 'cheese'].each (food) -> print food.capitalize()
+
+
+
+# class LotteryTicket
+# def picks; @picks; end
+# def picks=(var); @picks = var; end
+# def purchased; @purchased; end
+# def purchased=(var); @purchased = var; end
+# end
+
+LotteryTicket =
+ get_picks: -> @picks
+ set_picks: (@picks) ->
+ get_purchased: -> @purchase
+ set_purchased: (@purchased) ->
+
+
+
+# class << LotteryDraw
+# def play
+# result = LotteryTicket.new_random
+# winners = {}
+# @@tickets.each do |buyer, ticket_list|
+# ticket_list.each do |ticket|
+# score = ticket.score( result )
+# next if score.zero?
+# winners[buyer] ||= []
+# winners[buyer] << [ ticket, score ]
+# end
+# end
+# @@tickets.clear
+# winners
+# end
+# end
+
+LotteryDraw =
+ play: ->
+ result = LotteryTicket.new_random()
+ winners = {}
+ this.tickets.each (buyer, ticket_list) ->
+ ticket_list.each (ticket) ->
+ score = ticket.score result
+ return if score is 0
+ winners[buyer] or= []
+ winners[buyer].push [ticket, score]
+ this.tickets = {}
+ winners
+
+
+
+# module WishScanner
+# def scan_for_a_wish
+# wish = self.read.detect do |thought|
+# thought.index( 'wish: ' ) == 0
+# end
+# wish.gsub( 'wish: ', '' )
+# end
+# end
+
+WishScanner =
+ scan_for_a_wish: ->
+ wish = this.read().detect (thought) -> thought.index('wish: ') is 0
+ wish.replace 'wish: ', ''
+
+
+
+# class Creature
+#
+# # This method applies a hit taken during a fight.
+# def hit( damage )
+# p_up = rand( charisma )
+# if p_up % 9 == 7
+# @life += p_up / 4
+# puts "[#{ self.class } magick powers up #{ p_up }!]"
+# end
+# @life -= damage
+# puts "[#{ self.class } has died.]" if @life <= 0
+# end
+#
+# # This method takes one turn in a fight.
+# def fight( enemy, weapon )
+# if life <= 0
+# puts "[#{ self.class } is too dead to fight!]"
+# return
+# end
+#
+# # Attack the opponent
+# your_hit = rand( strength + weapon )
+# puts "[You hit with #{ your_hit } points of damage!]"
+# enemy.hit( your_hit )
+#
+# # Retaliation
+# p enemy
+# if enemy.life > 0
+# enemy_hit = rand( enemy.strength + enemy.weapon )
+# puts "[Your enemy hit with #{ enemy_hit } points of damage!]"
+# self.hit( enemy_hit )
+# end
+# end
+#
+# end
+
+Creature =
+
+ # This method applies a hit taken during a fight.
+ hit: (damage) ->
+ p_up = Math.rand this.charisma
+ if p_up % 9 is 7
+ this.life += p_up / 4
+ puts "[" + this.name + " magick powers up " + p_up + "!]"
+ this.life -= damage
+ if this.life <= 0 then puts "[" + this.name + " has died.]"
+
+ # This method takes one turn in a fight.
+ fight: (enemy, weapon) ->
+ if this.life <= 0 then return puts "[" + this.name + "is too dead to fight!]"
+
+ # Attack the opponent.
+ your_hit = Math.rand this.strength + weapon
+ puts "[You hit with " + your_hit + "points of damage!]"
+ enemy.hit your_hit
+
+ # Retaliation.
+ puts enemy
+ if enemy.life > 0
+ enemy_hit = Math.rand enemy.strength + enemy.weapon
+ puts "[Your enemy hit with " + enemy_hit + "points of damage!]"
+ this.hit enemy_hit
+
+
+
+# # Get evil idea and swap in code words
+# print "Enter your new idea: "
+# idea = gets
+# code_words.each do |real, code|
+# idea.gsub!( real, code )
+# end
+#
+# # Save the jibberish to a new file
+# print "File encoded. Please enter a name for this idea: "
+# idea_name = gets.strip
+# File::open( "idea-" + idea_name + ".txt", "w" ) do |f|
+# f << idea
+# end
+
+# Get evil idea and swap in code words
+print "Enter your new idea: "
+idea = gets()
+code_words.each (real, code) -> idea.replace(real, code)
+
+# Save the jibberish to a new file
+print "File encoded. Please enter a name for this idea: "
+idea_name = gets().strip()
+File.open "idea-" + idea_name + '.txt', 'w', (file) -> file.write idea
+
+
+
+# def wipe_mutterings_from( sentence )
+# unless sentence.respond_to? :include?
+# raise ArgumentError,
+# "cannot wipe mutterings from a #{ sentence.class }"
+# end
+# while sentence.include? '('
+# open = sentence.index( '(' )
+# close = sentence.index( ')', open )
+# sentence[open..close] = '' if close
+# end
+# end
+
+wipe_mutterings_from = (sentence) ->
+ throw new Error "cannot wipe mutterings" unless sentence.indexOf
+ while sentence.indexOf('(') >= 0
+ open = sentence.indexOf('(') - 1
+ close = sentence.indexOf(')') + 1
+ sentence = sentence[0..open] + sentence[close..sentence.length]
+ sentence
--- /dev/null
+# Examples from _why's Potion, the Readme and "Potion: A Short Pamphlet".
+
+# 5 times: "Odelay!" print.
+
+print "Odelay!" for [1..5]
+
+
+# add = (x, y): x + y.
+# add(2, 4) string print
+
+add = (x, y) -> x + y
+print add 2, 4
+
+
+# loop: 'quaff' print.
+
+loop print 'quaff'
+
+
+# ('cheese', 'bread', 'mayo') at (1) print
+
+print ['cheese', 'bread', 'mayo'][1]
+
+
+# (language='Potion', pointless=true) at (key='language') print
+
+print {language: 'Potion', pointless: true}['language']
+
+
+# minus = (x, y): x - y.
+# minus (y=10, x=6)
+
+minus = (x, y) -> x - y
+minus 6, 10
+
+
+# foods = ('cheese', 'bread', 'mayo')
+# foods (2)
+
+foods = ['cheese', 'bread', 'mayo']
+foods[2]
+
+
+# (dog='canine', cat='feline', fox='vulpine') each (key, val):
+# (key, ' is a ', val) join print.
+
+for key, val of {dog: 'canine', cat: 'feline', fox: 'vulpine'}
+ print key + ' is a ' + val
+
+
+# Person = class: /name, /age, /sex.
+# Person print = ():
+# ('My name is ', /name, '.') join print.
+
+class Person
+ print: ->
+ print 'My name is ' + @name + '.'
+
+
+# p = Person ()
+# p /name string print
+
+p = new Person
+print p.name
+
+
+# Policeman = Person class (rank): /rank = rank.
+# Policeman print = ():
+# ('My name is ', /name, ' and I'm a ', /rank, '.') join print.
+#
+# Policeman ('Constable') print
+
+class Policeman extends Person
+ constructor: (@rank) ->
+
+ print: ->
+ print 'My name is ' + @name + " and I'm a " + @rank + '.'
+
+print new Policeman 'Constable'
+
+
+# app = [window (width=200, height=400)
+# [para 'Welcome.', button 'OK']]
+# app first name
+
+app =
+ window:
+ width: 200
+ height: 200
+ para: 'Welcome.'
+ button: 'OK'
+
+app.window
+
+
+# x = 1
+# y = 2
+#
+# x = 1, y = 2
+
+x = 1
+y = 2
+
+x = 1; y = 2
+
+
+# table = (language='Potion'
+# pointless=true)
+
+table =
+ language: 'Potion'
+ pointless: yes
+
+
+# # this foul business...
+# String length = (): 10.
+
+# this foul business...
+String::length = -> 10
+
+
+# block = :
+# 'potion' print.
+
+block = ->
+ print 'potion'
+
+
+# if (age > 100): 'ancient'.
+
+if age > 100 then 'ancient'
+
+
+# author =
+# if (title == 'Jonathan Strange & Mr. Norrell'):
+# 'Susanna Clarke'.
+# elsif (title == 'The Star Diaries'):
+# 'Stanislaw Lem'.
+# elsif (title == 'The Slynx'):
+# 'Tatyana Tolstaya'.
+# else:
+# '... probably Philip K. Dick'.
+
+switch author
+ when 'Jonathan Strange & Mr. Norrell'
+ 'Susanna Clarke'
+ when 'The Star Diaries'
+ 'Stanislaw Lem'
+ when 'The Slynx'
+ 'Tatyana Tolstaya'
+ else
+ '... probably Philip K. Dick'
+
+
+# count = 8
+# while (count > 0):
+# 'quaff' print
+# count--.
+
+count = 8
+while count > 0
+ print 'quaff'
+ count--
+
+
+# 1 to 5 (a):
+# a string print.
+
+print a for a in [1..5]
+
+
+# if (3 ?gender):
+# "Huh? Numbers are sexed? That's amazing." print.
+
+if (3).gender?
+ print "Huh? Numbers are sexed? That's amazing."
+
+
+# HomePage get = (url):
+# session = url query ? at ('session').
+
+HomePage::get = (url) ->
+ session = url.query.session if url.query?
+
+
+# BTree = class: /left, /right.
+# b = BTree ()
+# b /left = BTree ()
+# b /right = BTree ()
+
+BTree = ->
+b = new BTree
+b.left = new BTree
+b.right = new BTree
+
+
+# BTree = class: /left, /right.
+# b = BTree ()
+#
+# if (b ? /left):
+# 'left path found!' print.
+
+BTree = ->
+b = new BTree
+
+print 'left path found!' if b.left?
--- /dev/null
+
+ # **Underscore.coffee
+ # (c) 2010 Jeremy Ashkenas, DocumentCloud Inc.**
+ # Underscore is freely distributable under the terms of the
+ # [MIT license](http://en.wikipedia.org/wiki/MIT_License).
+ # Portions of Underscore are inspired by or borrowed from
+ # [Prototype.js](http://prototypejs.org/api), Oliver Steele's
+ # [Functional](http://osteele.com), and John Resig's
+ # [Micro-Templating](http://ejohn.org).
+ # For all details and documentation:
+ # http://documentcloud.github.com/underscore/
+
+
+ # Baseline setup
+ # --------------
+
+ # Establish the root object, `window` in the browser, or `global` on the server.
+ root = this
+
+
+ # Save the previous value of the `_` variable.
+ previousUnderscore = root._
+
+
+ # Establish the object that gets thrown to break out of a loop iteration.
+ # `StopIteration` is SOP on Mozilla.
+ breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration
+
+
+ # Helper function to escape **RegExp** contents, because JS doesn't have one.
+ escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1')
+
+
+ # Save bytes in the minified (but not gzipped) version:
+ ArrayProto = Array.prototype
+ ObjProto = Object.prototype
+
+
+ # Create quick reference variables for speed access to core prototypes.
+ slice = ArrayProto.slice
+ unshift = ArrayProto.unshift
+ toString = ObjProto.toString
+ hasOwnProperty = ObjProto.hasOwnProperty
+ propertyIsEnumerable = ObjProto.propertyIsEnumerable
+
+
+ # All **ECMA5** native implementations we hope to use are declared here.
+ nativeForEach = ArrayProto.forEach
+ nativeMap = ArrayProto.map
+ nativeReduce = ArrayProto.reduce
+ nativeReduceRight = ArrayProto.reduceRight
+ nativeFilter = ArrayProto.filter
+ nativeEvery = ArrayProto.every
+ nativeSome = ArrayProto.some
+ nativeIndexOf = ArrayProto.indexOf
+ nativeLastIndexOf = ArrayProto.lastIndexOf
+ nativeIsArray = Array.isArray
+ nativeKeys = Object.keys
+
+
+ # Create a safe reference to the Underscore object for use below.
+ _ = (obj) -> new wrapper(obj)
+
+
+ # Export the Underscore object for **CommonJS**.
+ if typeof(exports) != 'undefined' then exports._ = _
+
+
+ # Export Underscore to global scope.
+ root._ = _
+
+
+ # Current version.
+ _.VERSION = '1.1.0'
+
+
+ # Collection Functions
+ # --------------------
+
+ # The cornerstone, an **each** implementation.
+ # Handles objects implementing **forEach**, arrays, and raw objects.
+ _.each = (obj, iterator, context) ->
+ try
+ if nativeForEach and obj.forEach is nativeForEach
+ obj.forEach iterator, context
+ else if _.isNumber obj.length
+ iterator.call(context, obj[i], i, obj) for i in [0...obj.length]
+ else
+ iterator.call(context, val, key, obj) for key, val of obj
+ catch e
+ throw e if e isnt breaker
+ obj
+
+
+ # Return the results of applying the iterator to each element. Use JavaScript
+ # 1.6's version of **map**, if possible.
+ _.map = (obj, iterator, context) ->
+ return obj.map(iterator, context) if nativeMap and obj.map is nativeMap
+ results = []
+ _.each obj, (value, index, list) ->
+ results.push iterator.call context, value, index, list
+ results
+
+
+ # **Reduce** builds up a single result from a list of values. Also known as
+ # **inject**, or **foldl**. Uses JavaScript 1.8's version of **reduce**, if possible.
+ _.reduce = (obj, iterator, memo, context) ->
+ if nativeReduce and obj.reduce is nativeReduce
+ iterator = _.bind iterator, context if context
+ return obj.reduce iterator, memo
+ _.each obj, (value, index, list) ->
+ memo = iterator.call context, memo, value, index, list
+ memo
+
+
+ # The right-associative version of **reduce**, also known as **foldr**. Uses
+ # JavaScript 1.8's version of **reduceRight**, if available.
+ _.reduceRight = (obj, iterator, memo, context) ->
+ if nativeReduceRight and obj.reduceRight is nativeReduceRight
+ iterator = _.bind iterator, context if context
+ return obj.reduceRight iterator, memo
+ reversed = _.clone(_.toArray(obj)).reverse()
+ _.reduce reversed, iterator, memo, context
+
+
+ # Return the first value which passes a truth test.
+ _.detect = (obj, iterator, context) ->
+ result = null
+ _.each obj, (value, index, list) ->
+ if iterator.call context, value, index, list
+ result = value
+ _.breakLoop()
+ result
+
+
+ # Return all the elements that pass a truth test. Use JavaScript 1.6's
+ # **filter**, if it exists.
+ _.filter = (obj, iterator, context) ->
+ return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter
+ results = []
+ _.each obj, (value, index, list) ->
+ results.push value if iterator.call context, value, index, list
+ results
+
+
+ # Return all the elements for which a truth test fails.
+ _.reject = (obj, iterator, context) ->
+ results = []
+ _.each obj, (value, index, list) ->
+ results.push value if not iterator.call context, value, index, list
+ results
+
+
+ # Determine whether all of the elements match a truth test. Delegate to
+ # JavaScript 1.6's **every**, if it is present.
+ _.every = (obj, iterator, context) ->
+ iterator ||= _.identity
+ return obj.every iterator, context if nativeEvery and obj.every is nativeEvery
+ result = true
+ _.each obj, (value, index, list) ->
+ _.breakLoop() unless (result = result and iterator.call(context, value, index, list))
+ result
+
+
+ # Determine if at least one element in the object matches a truth test. Use
+ # JavaScript 1.6's **some**, if it exists.
+ _.some = (obj, iterator, context) ->
+ iterator ||= _.identity
+ return obj.some iterator, context if nativeSome and obj.some is nativeSome
+ result = false
+ _.each obj, (value, index, list) ->
+ _.breakLoop() if (result = iterator.call(context, value, index, list))
+ result
+
+
+ # Determine if a given value is included in the array or object,
+ # based on `===`.
+ _.include = (obj, target) ->
+ return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf
+ for key, val of obj
+ return true if val is target
+ false
+
+
+ # Invoke a method with arguments on every item in a collection.
+ _.invoke = (obj, method) ->
+ args = _.rest arguments, 2
+ (if method then val[method] else val).apply(val, args) for val in obj
+
+
+ # Convenience version of a common use case of **map**: fetching a property.
+ _.pluck = (obj, key) ->
+ _.map(obj, (val) -> val[key])
+
+
+ # Return the maximum item or (item-based computation).
+ _.max = (obj, iterator, context) ->
+ return Math.max.apply(Math, obj) if not iterator and _.isArray(obj)
+ result = computed: -Infinity
+ _.each obj, (value, index, list) ->
+ computed = if iterator then iterator.call(context, value, index, list) else value
+ computed >= result.computed and (result = {value: value, computed: computed})
+ result.value
+
+
+ # Return the minimum element (or element-based computation).
+ _.min = (obj, iterator, context) ->
+ return Math.min.apply(Math, obj) if not iterator and _.isArray(obj)
+ result = computed: Infinity
+ _.each obj, (value, index, list) ->
+ computed = if iterator then iterator.call(context, value, index, list) else value
+ computed < result.computed and (result = {value: value, computed: computed})
+ result.value
+
+
+ # Sort the object's values by a criterion produced by an iterator.
+ _.sortBy = (obj, iterator, context) ->
+ _.pluck(((_.map obj, (value, index, list) ->
+ {value: value, criteria: iterator.call(context, value, index, list)}
+ ).sort((left, right) ->
+ a = left.criteria; b = right.criteria
+ if a < b then -1 else if a > b then 1 else 0
+ )), 'value')
+
+
+ # Use a comparator function to figure out at what index an object should
+ # be inserted so as to maintain order. Uses binary search.
+ _.sortedIndex = (array, obj, iterator) ->
+ iterator ||= _.identity
+ low = 0
+ high = array.length
+ while low < high
+ mid = (low + high) >> 1
+ if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid
+ low
+
+
+ # Convert anything iterable into a real, live array.
+ _.toArray = (iterable) ->
+ return [] if (!iterable)
+ return iterable.toArray() if (iterable.toArray)
+ return iterable if (_.isArray(iterable))
+ return slice.call(iterable) if (_.isArguments(iterable))
+ _.values(iterable)
+
+
+ # Return the number of elements in an object.
+ _.size = (obj) -> _.toArray(obj).length
+
+
+ # Array Functions
+ # ---------------
+
+ # Get the first element of an array. Passing `n` will return the first N
+ # values in the array. Aliased as **head**. The `guard` check allows it to work
+ # with **map**.
+ _.first = (array, n, guard) ->
+ if n and not guard then slice.call(array, 0, n) else array[0]
+
+
+ # Returns everything but the first entry of the array. Aliased as **tail**.
+ # Especially useful on the arguments object. Passing an `index` will return
+ # the rest of the values in the array from that index onward. The `guard`
+ # check allows it to work with **map**.
+ _.rest = (array, index, guard) ->
+ slice.call(array, if _.isUndefined(index) or guard then 1 else index)
+
+
+ # Get the last element of an array.
+ _.last = (array) -> array[array.length - 1]
+
+
+ # Trim out all falsy values from an array.
+ _.compact = (array) -> item for item in array when item
+
+
+ # Return a completely flattened version of an array.
+ _.flatten = (array) ->
+ _.reduce array, (memo, value) ->
+ return memo.concat(_.flatten(value)) if _.isArray value
+ memo.push value
+ memo
+ , []
+
+
+ # Return a version of the array that does not contain the specified value(s).
+ _.without = (array) ->
+ values = _.rest arguments
+ val for val in _.toArray(array) when not _.include values, val
+
+
+ # Produce a duplicate-free version of the array. If the array has already
+ # been sorted, you have the option of using a faster algorithm.
+ _.uniq = (array, isSorted) ->
+ memo = []
+ for el, i in _.toArray array
+ memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el))
+ memo
+
+
+ # Produce an array that contains every item shared between all the
+ # passed-in arrays.
+ _.intersect = (array) ->
+ rest = _.rest arguments
+ _.select _.uniq(array), (item) ->
+ _.all rest, (other) ->
+ _.indexOf(other, item) >= 0
+
+
+ # Zip together multiple lists into a single array -- elements that share
+ # an index go together.
+ _.zip = ->
+ length = _.max _.pluck arguments, 'length'
+ results = new Array length
+ for i in [0...length]
+ results[i] = _.pluck arguments, String i
+ results
+
+
+ # If the browser doesn't supply us with **indexOf** (I'm looking at you, MSIE),
+ # we need this function. Return the position of the first occurence of an
+ # item in an array, or -1 if the item is not included in the array.
+ _.indexOf = (array, item) ->
+ return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf
+ i = 0; l = array.length
+ while l - i
+ if array[i] is item then return i else i++
+ -1
+
+
+ # Provide JavaScript 1.6's **lastIndexOf**, delegating to the native function,
+ # if possible.
+ _.lastIndexOf = (array, item) ->
+ return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf
+ i = array.length
+ while i
+ if array[i] is item then return i else i--
+ -1
+
+
+ # Generate an integer Array containing an arithmetic progression. A port of
+ # [the native Python **range** function](http://docs.python.org/library/functions.html#range).
+ _.range = (start, stop, step) ->
+ a = arguments
+ solo = a.length <= 1
+ i = start = if solo then 0 else a[0]
+ stop = if solo then a[0] else a[1]
+ step = a[2] or 1
+ len = Math.ceil((stop - start) / step)
+ return [] if len <= 0
+ range = new Array len
+ idx = 0
+ loop
+ return range if (if step > 0 then i - stop else stop - i) >= 0
+ range[idx] = i
+ idx++
+ i+= step
+
+
+ # Function Functions
+ # ------------------
+
+ # Create a function bound to a given object (assigning `this`, and arguments,
+ # optionally). Binding with arguments is also known as **curry**.
+ _.bind = (func, obj) ->
+ args = _.rest arguments, 2
+ -> func.apply obj or root, args.concat arguments
+
+
+ # Bind all of an object's methods to that object. Useful for ensuring that
+ # all callbacks defined on an object belong to it.
+ _.bindAll = (obj) ->
+ funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj)
+ _.each funcs, (f) -> obj[f] = _.bind obj[f], obj
+ obj
+
+
+ # Delays a function for the given number of milliseconds, and then calls
+ # it with the arguments supplied.
+ _.delay = (func, wait) ->
+ args = _.rest arguments, 2
+ setTimeout((-> func.apply(func, args)), wait)
+
+
+ # Memoize an expensive function by storing its results.
+ _.memoize = (func, hasher) ->
+ memo = {}
+ hasher or= _.identity
+ ->
+ key = hasher.apply this, arguments
+ return memo[key] if key of memo
+ memo[key] = func.apply this, arguments
+
+
+ # Defers a function, scheduling it to run after the current call stack has
+ # cleared.
+ _.defer = (func) ->
+ _.delay.apply _, [func, 1].concat _.rest arguments
+
+
+ # Returns the first function passed as an argument to the second,
+ # allowing you to adjust arguments, run code before and after, and
+ # conditionally execute the original function.
+ _.wrap = (func, wrapper) ->
+ -> wrapper.apply wrapper, [func].concat arguments
+
+
+ # Returns a function that is the composition of a list of functions, each
+ # consuming the return value of the function that follows.
+ _.compose = ->
+ funcs = arguments
+ ->
+ args = arguments
+ for i in [(funcs.length - 1)..0]
+ args = [funcs[i].apply(this, args)]
+ args[0]
+
+
+ # Object Functions
+ # ----------------
+
+ # Retrieve the names of an object's properties.
+ _.keys = nativeKeys or (obj) ->
+ return _.range 0, obj.length if _.isArray(obj)
+ key for key, val of obj
+
+
+ # Retrieve the values of an object's properties.
+ _.values = (obj) ->
+ _.map obj, _.identity
+
+
+ # Return a sorted list of the function names available in Underscore.
+ _.functions = (obj) ->
+ _.filter(_.keys(obj), (key) -> _.isFunction(obj[key])).sort()
+
+
+ # Extend a given object with all of the properties in a source object.
+ _.extend = (obj) ->
+ for source in _.rest(arguments)
+ (obj[key] = val) for key, val of source
+ obj
+
+
+ # Create a (shallow-cloned) duplicate of an object.
+ _.clone = (obj) ->
+ return obj.slice 0 if _.isArray obj
+ _.extend {}, obj
+
+
+ # Invokes interceptor with the obj, and then returns obj.
+ # The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
+ _.tap = (obj, interceptor) ->
+ interceptor obj
+ obj
+
+
+ # Perform a deep comparison to check if two objects are equal.
+ _.isEqual = (a, b) ->
+ # Check object identity.
+ return true if a is b
+ # Different types?
+ atype = typeof(a); btype = typeof(b)
+ return false if atype isnt btype
+ # Basic equality test (watch out for coercions).
+ return true if `a == b`
+ # One is falsy and the other truthy.
+ return false if (!a and b) or (a and !b)
+ # One of them implements an `isEqual()`?
+ return a.isEqual(b) if a.isEqual
+ # Check dates' integer values.
+ return a.getTime() is b.getTime() if _.isDate(a) and _.isDate(b)
+ # Both are NaN?
+ return false if _.isNaN(a) and _.isNaN(b)
+ # Compare regular expressions.
+ if _.isRegExp(a) and _.isRegExp(b)
+ return a.source is b.source and
+ a.global is b.global and
+ a.ignoreCase is b.ignoreCase and
+ a.multiline is b.multiline
+ # If a is not an object by this point, we can't handle it.
+ return false if atype isnt 'object'
+ # Check for different array lengths before comparing contents.
+ return false if a.length and (a.length isnt b.length)
+ # Nothing else worked, deep compare the contents.
+ aKeys = _.keys(a); bKeys = _.keys(b)
+ # Different object sizes?
+ return false if aKeys.length isnt bKeys.length
+ # Recursive comparison of contents.
+ (return false) for all key, val of a when !(key of b) or !_.isEqual(val, b[key])
+ true
+
+
+ # Is a given array or object empty?
+ _.isEmpty = (obj) ->
+ return obj.length is 0 if _.isArray(obj) or _.isString(obj)
+ (return false) for key of obj when hasOwnProperty.call(obj, key)
+ true
+
+
+ # Is a given value a DOM element?
+ _.isElement = (obj) -> obj and obj.nodeType is 1
+
+
+ # Is a given value an array?
+ _.isArray = nativeIsArray or (obj) -> !!(obj and obj.concat and obj.unshift and not obj.callee)
+
+
+ # Is a given variable an arguments object?
+ _.isArguments = (obj) -> obj and obj.callee
+
+
+ # Is the given value a function?
+ _.isFunction = (obj) -> !!(obj and obj.constructor and obj.call and obj.apply)
+
+
+ # Is the given value a string?
+ _.isString = (obj) -> !!(obj is '' or (obj and obj.charCodeAt and obj.substr))
+
+
+ # Is a given value a number?
+ _.isNumber = (obj) -> (obj is +obj) or toString.call(obj) is '[object Number]'
+
+
+ # Is a given value a boolean?
+ _.isBoolean = (obj) -> obj is true or obj is false
+
+
+ # Is a given value a Date?
+ _.isDate = (obj) -> !!(obj and obj.getTimezoneOffset and obj.setUTCFullYear)
+
+
+ # Is the given value a regular expression?
+ _.isRegExp = (obj) -> !!(obj and obj.exec and (obj.ignoreCase or obj.ignoreCase is false))
+
+
+ # Is the given value NaN -- this one is interesting. `NaN != NaN`, and
+ # `isNaN(undefined) == true`, so we make sure it's a number first.
+ _.isNaN = (obj) -> _.isNumber(obj) and window.isNaN(obj)
+
+
+ # Is a given value equal to null?
+ _.isNull = (obj) -> obj is null
+
+
+ # Is a given variable undefined?
+ _.isUndefined = (obj) -> typeof obj is 'undefined'
+
+
+ # Utility Functions
+ # -----------------
+
+ # Run Underscore.js in noConflict mode, returning the `_` variable to its
+ # previous owner. Returns a reference to the Underscore object.
+ _.noConflict = ->
+ root._ = previousUnderscore
+ this
+
+
+ # Keep the identity function around for default iterators.
+ _.identity = (value) -> value
+
+
+ # Run a function `n` times.
+ _.times = (n, iterator, context) ->
+ iterator.call(context, i) for i in [0...n]
+
+
+ # Break out of the middle of an iteration.
+ _.breakLoop = -> throw breaker
+
+
+ # Add your own custom functions to the Underscore object, ensuring that
+ # they're correctly added to the OOP wrapper as well.
+ _.mixin = (obj) ->
+ for name in _.functions(obj)
+ addToWrapper name, _[name] = obj[name]
+
+
+ # Generate a unique integer id (unique within the entire client session).
+ # Useful for temporary DOM ids.
+ idCounter = 0
+ _.uniqueId = (prefix) ->
+ (prefix or '') + idCounter++
+
+
+ # By default, Underscore uses **ERB**-style template delimiters, change the
+ # following template settings to use alternative delimiters.
+ _.templateSettings = {
+ start: '<%'
+ end: '%>'
+ interpolate: /<%=(.+?)%>/g
+ }
+
+
+ # JavaScript templating a-la **ERB**, pilfered from John Resig's
+ # *Secrets of the JavaScript Ninja*, page 83.
+ # Single-quote fix from Rick Strahl.
+ # With alterations for arbitrary delimiters, and to preserve whitespace.
+ _.template = (str, data) ->
+ c = _.templateSettings
+ endMatch = new RegExp("'(?=[^"+c.end.substr(0, 1)+"]*"+escapeRegExp(c.end)+")","g")
+ fn = new Function 'obj',
+ 'var p=[],print=function(){p.push.apply(p,arguments);};' +
+ 'with(obj||{}){p.push(\'' +
+ str.replace(/\r/g, '\\r')
+ .replace(/\n/g, '\\n')
+ .replace(/\t/g, '\\t')
+ .replace(endMatch,"✄")
+ .split("'").join("\\'")
+ .split("✄").join("'")
+ .replace(c.interpolate, "',$1,'")
+ .split(c.start).join("');")
+ .split(c.end).join("p.push('") +
+ "');}return p.join('');"
+ if data then fn(data) else fn
+
+
+ # Aliases
+ # -------
+
+ _.forEach = _.each
+ _.foldl = _.inject = _.reduce
+ _.foldr = _.reduceRight
+ _.select = _.filter
+ _.all = _.every
+ _.any = _.some
+ _.contains = _.include
+ _.head = _.first
+ _.tail = _.rest
+ _.methods = _.functions
+
+
+ # Setup the OOP Wrapper
+ # ---------------------
+
+ # If Underscore is called as a function, it returns a wrapped object that
+ # can be used OO-style. This wrapper holds altered versions of all the
+ # underscore functions. Wrapped objects may be chained.
+ wrapper = (obj) ->
+ this._wrapped = obj
+ this
+
+
+ # Helper function to continue chaining intermediate results.
+ result = (obj, chain) ->
+ if chain then _(obj).chain() else obj
+
+
+ # A method to easily add functions to the OOP wrapper.
+ addToWrapper = (name, func) ->
+ wrapper.prototype[name] = ->
+ args = _.toArray arguments
+ unshift.call args, this._wrapped
+ result func.apply(_, args), this._chain
+
+
+ # Add all of the Underscore functions to the wrapper object.
+ _.mixin _
+
+
+ # Add all mutator Array functions to the wrapper.
+ _.each ['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], (name) ->
+ method = Array.prototype[name]
+ wrapper.prototype[name] = ->
+ method.apply(this._wrapped, arguments)
+ result(this._wrapped, this._chain)
+
+
+ # Add all accessor Array functions to the wrapper.
+ _.each ['concat', 'join', 'slice'], (name) ->
+ method = Array.prototype[name]
+ wrapper.prototype[name] = ->
+ result(method.apply(this._wrapped, arguments), this._chain)
+
+
+ # Start chaining a wrapped Underscore object.
+ wrapper::chain = ->
+ this._chain = true
+ this
+
+
+ # Extracts the result from a wrapped and chained object.
+ wrapper::value = -> this._wrapped
--- /dev/null
+# Contributed by Jason Huggins
+
+sys = require 'sys'
+http = require 'http'
+
+server = http.createServer (req, res) ->
+ res.writeHeader 200, 'Content-Type': 'text/plain'
+ res.write 'Hello, World!'
+ res.end()
+
+server.listen 3000
+
+sys.puts "Server running at http://localhost:3000/"
--- /dev/null
+EXTRAS:
+
+"extras/coffee-script.js" is a concatenated and compressed version of the
+CoffeeScript compiler. To use it in the browser, include the script after any
+inline script tags of type "text/coffeescript" on the page. It will compile
+and evaluate all of the scripts in order.
+
--- /dev/null
+/**
+ * CoffeeScript Compiler v0.9.4
+ * http://coffeescript.org
+ *
+ * Copyright 2010, Jeremy Ashkenas
+ * Released under the MIT License
+ */
+this.CoffeeScript=function(){function require(path){return require[path]}require["./helpers"]=new function(){var exports=this;(function(){var extend,flatten,indexOf;indexOf=(exports.indexOf=Array.indexOf||(Array.prototype.indexOf?function(array,item,from){return array.indexOf(item,from)}:function(array,item,from){var _len,index,other;for(index=0,_len=array.length;index<_len;index++){other=array[index];if(other===item&&(!from||(from<=index))){return index}}return -1}));exports.include=function(list,value){return indexOf(list,value)>=0};exports.starts=function(string,literal,start){return literal===string.substr(start,literal.length)};exports.ends=function(string,literal,back){var len;len=literal.length;return literal===string.substr(string.length-len-(back||0),len)};exports.compact=function(array){var _i,_len,_result,item;_result=[];for(_i=0,_len=array.length;_i<_len;_i++){item=array[_i];if(item){_result.push(item)}}return _result};exports.count=function(string,letter){var num,pos;num=(pos=0);while(pos=1+string.indexOf(letter,pos)){num++}return num};exports.merge=function(options,overrides){return extend(extend({},options),overrides)};extend=(exports.extend=function(object,properties){var key,val;for(key in properties){val=properties[key];object[key]=val}return object});exports.flatten=(flatten=function(array){var _i,_len,element,flattened;flattened=[];for(_i=0,_len=array.length;_i<_len;_i++){element=array[_i];if(element instanceof Array){flattened=flattened.concat(flatten(element))}else{flattened.push(element)}}return flattened});exports.del=function(obj,key){var val;val=obj[key];delete obj[key];return val};exports.last=function(array,back){return array[array.length-(back||0)-1]}}).call(this)};require["./rewriter"]=new function(){var exports=this;(function(){var BALANCED_PAIRS,EXPRESSION_CLOSE,EXPRESSION_END,EXPRESSION_START,IMPLICIT_BLOCK,IMPLICIT_CALL,IMPLICIT_END,IMPLICIT_FUNC,INVERSES,LINEBREAKS,SINGLE_CLOSERS,SINGLE_LINERS,_i,_len,_ref,include,left,rite;include=require("./helpers").include;exports.Rewriter=(function(){function Rewriter(){}return Rewriter})();exports.Rewriter.prototype.rewrite=function(_arg){this.tokens=_arg;this.adjustComments();this.removeLeadingNewlines();this.removeMidExpressionNewlines();this.closeOpenCalls();this.closeOpenIndexes();this.addImplicitIndentation();this.tagPostfixConditionals();this.addImplicitBraces();this.addImplicitParentheses();this.ensureBalance(BALANCED_PAIRS);this.rewriteClosingParens();return this.tokens};exports.Rewriter.prototype.scanTokens=function(block){var i,token,tokens;tokens=this.tokens;i=0;while(token=tokens[i]){i+=block.call(this,token,i,tokens)}return true};exports.Rewriter.prototype.detectEnd=function(i,condition,action){var levels,token,tokens;tokens=this.tokens;levels=0;while(token=tokens[i]){if(levels===0&&condition.call(this,token,i)){return action.call(this,token,i)}if(!token||levels<0){return action.call(this,token,i-1)}if(include(EXPRESSION_START,token[0])){levels+=1}else{if(include(EXPRESSION_END,token[0])){levels-=1}}i+=1}return i-1};exports.Rewriter.prototype.adjustComments=function(){return this.scanTokens(function(token,i,tokens){var _ref,after,before,post,prev;if(token[0]!=="HERECOMMENT"){return 1}before=tokens[i-2];prev=tokens[i-1];post=tokens[i+1];after=tokens[i+2];if(((after!=null)?after[0]:undefined)==="INDENT"){tokens.splice(i+2,1);if(((before!=null)?before[0]:undefined)==="OUTDENT"&&((post!=null)?post[0]:undefined)==="TERMINATOR"){tokens.splice(i-2,1)}else{tokens.splice(i,0,after)}}else{if(prev&&!((_ref=prev[0])==="TERMINATOR"||_ref==="INDENT"||_ref==="OUTDENT")){if(((post!=null)?post[0]:undefined)==="TERMINATOR"&&((after!=null)?after[0]:undefined)==="OUTDENT"){tokens.splice.apply(tokens,[i+2,0].concat(tokens.splice(i,2)));if(tokens[i+2][0]!=="TERMINATOR"){tokens.splice(i+2,0,["TERMINATOR","\n",prev[2]])}}else{tokens.splice(i,0,["TERMINATOR","\n",prev[2]])}return 2}}return 1})};exports.Rewriter.prototype.removeLeadingNewlines=function(){var _len,_ref,i,tag;for(i=0,_len=(_ref=this.tokens).length;i<_len;i++){tag=_ref[i][0];if(tag!=="TERMINATOR"){break}}return i?this.tokens.splice(0,i):undefined};exports.Rewriter.prototype.removeMidExpressionNewlines=function(){return this.scanTokens(function(token,i,tokens){if(!(token[0]==="TERMINATOR"&&include(EXPRESSION_CLOSE,this.tag(i+1)))){return 1}tokens.splice(i,1);return 0})};exports.Rewriter.prototype.closeOpenCalls=function(){var action,condition;condition=function(token,i){var _ref;return((_ref=token[0])===")"||_ref==="CALL_END")||token[0]==="OUTDENT"&&this.tag(i-1)===")"};action=function(token,i){return(this.tokens[token[0]==="OUTDENT"?i-1:i][0]="CALL_END")};return this.scanTokens(function(token,i){if(token[0]==="CALL_START"){this.detectEnd(i+1,condition,action)}return 1})};exports.Rewriter.prototype.closeOpenIndexes=function(){var action,condition;condition=function(token,i){var _ref;return((_ref=token[0])==="]"||_ref==="INDEX_END")};action=function(token,i){return(token[0]="INDEX_END")};return this.scanTokens(function(token,i){if(token[0]==="INDEX_START"){this.detectEnd(i+1,condition,action)}return 1})};exports.Rewriter.prototype.addImplicitBraces=function(){var action,condition,stack;stack=[];condition=function(token,i){var _ref,_ref2,one,tag,three,two;if(("HERECOMMENT"===this.tag(i+1)||"HERECOMMENT"===this.tag(i-1))){return false}_ref=this.tokens.slice(i+1,i+4),one=_ref[0],two=_ref[1],three=_ref[2];tag=token[0];return(tag==="TERMINATOR"||tag==="OUTDENT")&&!(((two!=null)?two[0]:undefined)===":"||((one!=null)?one[0]:undefined)==="@"&&((three!=null)?three[0]:undefined)===":")||tag===","&&!((_ref2=((one!=null)?one[0]:undefined))==="IDENTIFIER"||_ref2==="NUMBER"||_ref2==="STRING"||_ref2==="@"||_ref2==="TERMINATOR"||_ref2==="OUTDENT")};action=function(token,i){return this.tokens.splice(i,0,["}","}",token[2]])};return this.scanTokens(function(token,i,tokens){var idx,tag,tok;if(include(EXPRESSION_START,tag=token[0])){stack.push(tag==="INDENT"&&this.tag(i-1)==="{"?"{":tag);return 1}if(include(EXPRESSION_END,tag)){stack.pop();return 1}if(!(tag===":"&&stack[stack.length-1]!=="{")){return 1}stack.push("{");idx=this.tag(i-2)==="@"?i-2:i-1;if(this.tag(idx-2)==="HERECOMMENT"){idx-=2}tok=["{","{",token[2]];tok.generated=true;tokens.splice(idx,0,tok);this.detectEnd(i+2,condition,action);return 2})};exports.Rewriter.prototype.addImplicitParentheses=function(){var action,classLine;classLine=false;action=function(token,i){var idx;idx=token[0]==="OUTDENT"?i+1:i;return this.tokens.splice(idx,0,["CALL_END",")",token[2]])};return this.scanTokens(function(token,i,tokens){var callObject,next,prev,seenSingle,tag;tag=token[0];if(tag==="CLASS"){classLine=true}prev=tokens[i-1];next=tokens[i+1];callObject=!classLine&&tag==="INDENT"&&next&&next.generated&&next[0]==="{"&&prev&&include(IMPLICIT_FUNC,prev[0]);seenSingle=false;if(include(LINEBREAKS,tag)){classLine=false}if(prev&&!prev.spaced&&tag==="?"){token.call=true}if(!(callObject||((prev!=null)?prev.spaced:undefined)&&(prev.call||include(IMPLICIT_FUNC,prev[0]))&&include(IMPLICIT_CALL,tag))){return 1}tokens.splice(i,0,["CALL_START","(",token[2]]);this.detectEnd(i+(callObject?2:1),function(token,i){var post;if(!seenSingle&&token.fromThen){return true}tag=token[0];if((tag==="IF"||tag==="ELSE"||tag==="UNLESS"||tag==="->"||tag==="=>")){seenSingle=true}if(tag==="PROPERTY_ACCESS"&&this.tag(i-1)==="OUTDENT"){return true}return !token.generated&&this.tag(i-1)!==","&&include(IMPLICIT_END,tag)&&(tag!=="INDENT"||(this.tag(i-2)!=="CLASS"&&!include(IMPLICIT_BLOCK,this.tag(i-1))&&!((post=this.tokens[i+1])&&post.generated&&post[0]==="{")))},action);if(prev[0]==="?"){prev[0]="FUNC_EXIST"}return 2})};exports.Rewriter.prototype.addImplicitIndentation=function(){return this.scanTokens(function(token,i,tokens){var _ref,_ref2,action,condition,indent,outdent,starter,tag;tag=token[0];if(tag==="ELSE"&&this.tag(i-1)!=="OUTDENT"){tokens.splice.apply(tokens,[i,0].concat(this.indentation(token)));return 2}if(tag==="CATCH"&&((_ref=this.tag(i+2))==="TERMINATOR"||_ref==="FINALLY")){tokens.splice.apply(tokens,[i+2,0].concat(this.indentation(token)));return 4}if(include(SINGLE_LINERS,tag)&&this.tag(i+1)!=="INDENT"&&!(tag==="ELSE"&&this.tag(i+1)==="IF")){starter=tag;_ref2=this.indentation(token),indent=_ref2[0],outdent=_ref2[1];if(starter==="THEN"){indent.fromThen=true}indent.generated=(outdent.generated=true);tokens.splice(i+1,0,indent);condition=function(token,i){return token[1]!==";"&&include(SINGLE_CLOSERS,token[0])&&!(token[0]==="ELSE"&&!(starter==="IF"||starter==="THEN"))};action=function(token,i){return this.tokens.splice(this.tag(i-1)===","?i-1:i,0,outdent)};this.detectEnd(i+2,condition,action);if(tag==="THEN"){tokens.splice(i,1)}return 1}return 1})};exports.Rewriter.prototype.tagPostfixConditionals=function(){var condition;condition=function(token,i){var _ref;return((_ref=token[0])==="TERMINATOR"||_ref==="INDENT")};return this.scanTokens(function(token,i){var _ref,original;if(!((_ref=token[0])==="IF"||_ref==="UNLESS")){return 1}original=token;this.detectEnd(i+1,condition,function(token,i){return token[0]!=="INDENT"?(original[0]="POST_"+original[0]):undefined});return 1})};exports.Rewriter.prototype.ensureBalance=function(pairs){var _result,key,levels,open,openLine,unclosed,value;levels={};openLine={};this.scanTokens(function(token,i){var _i,_len,_ref,_ref2,close,open,tag;tag=token[0];for(_i=0,_len=(_ref=pairs).length;_i<_len;_i++){_ref2=_ref[_i],open=_ref2[0],close=_ref2[1];levels[open]|=0;if(tag===open){if(levels[open]===0){openLine[open]=token[2]}levels[open]+=1}else{if(tag===close){levels[open]-=1}}if(levels[open]<0){throw Error("too many "+(token[1])+" on line "+(token[2]+1))}}return 1});unclosed=(function(){_result=[];for(key in levels){value=levels[key];if(value>0){_result.push(key)}}return _result})();if(unclosed.length){throw Error("unclosed "+(open=unclosed[0])+" on line "+(openLine[open]+1))}};exports.Rewriter.prototype.rewriteClosingParens=function(){var debt,key,stack;stack=[];debt={};for(key in INVERSES){(debt[key]=0)}return this.scanTokens(function(token,i,tokens){var inv,match,mtag,oppos,tag,val;if(include(EXPRESSION_START,tag=token[0])){stack.push(token);return 1}if(!include(EXPRESSION_END,tag)){return 1}if(debt[(inv=INVERSES[tag])]>0){debt[inv]-=1;tokens.splice(i,1);return 0}match=stack.pop();mtag=match[0];oppos=INVERSES[mtag];if(tag===oppos){return 1}debt[mtag]+=1;val=[oppos,mtag==="INDENT"?match[1]:oppos];if(this.tag(i+2)===mtag){tokens.splice(i+3,0,val);stack.push(match)}else{tokens.splice(i,0,val)}return 1})};exports.Rewriter.prototype.indentation=function(token){return[["INDENT",2,token[2]],["OUTDENT",2,token[2]]]};exports.Rewriter.prototype.tag=function(i){var _ref;return(((_ref=this.tokens[i])!=null)?_ref[0]:undefined)};BALANCED_PAIRS=[["(",")"],["[","]"],["{","}"],["INDENT","OUTDENT"],["CALL_START","CALL_END"],["PARAM_START","PARAM_END"],["INDEX_START","INDEX_END"]];INVERSES={};EXPRESSION_START=[];EXPRESSION_END=[];for(_i=0,_len=BALANCED_PAIRS.length;_i<_len;_i++){_ref=BALANCED_PAIRS[_i],left=_ref[0],rite=_ref[1];EXPRESSION_START.push(INVERSES[rite]=left);EXPRESSION_END.push(INVERSES[left]=rite)}EXPRESSION_CLOSE=["CATCH","WHEN","ELSE","FINALLY"].concat(EXPRESSION_END);IMPLICIT_FUNC=["IDENTIFIER","SUPER",")","CALL_END","]","INDEX_END","@","THIS"];IMPLICIT_CALL=["IDENTIFIER","NUMBER","STRING","JS","REGEX","NEW","PARAM_START","CLASS","IF","UNLESS","TRY","SWITCH","THIS","BOOL","UNARY","@","->","=>","[","(","{"];IMPLICIT_BLOCK=["->","=>","{","[",","];IMPLICIT_END=["POST_IF","POST_UNLESS","FOR","WHILE","UNTIL","LOOP","TERMINATOR","INDENT"];SINGLE_LINERS=["ELSE","->","=>","TRY","FINALLY","THEN"];SINGLE_CLOSERS=["TERMINATOR","CATCH","FINALLY","ELSE","OUTDENT","LEADING_WHEN"];LINEBREAKS=["TERMINATOR","INDENT","OUTDENT"]}).call(this)};require["./lexer"]=new function(){var exports=this;(function(){var ASSIGNED,BOOL,CALLABLE,CODE,COFFEE_ALIASES,COFFEE_KEYWORDS,COMMENT,COMPARE,COMPOUND_ASSIGN,HEREDOC,HEREDOC_INDENT,HEREGEX,HEREGEX_OMIT,IDENTIFIER,INDEXABLE,JSTOKEN,JS_FORBIDDEN,JS_KEYWORDS,LEADING_SPACES,LINE_BREAK,LOGIC,Lexer,MATH,MULTILINER,MULTI_DENT,NEXT_CHARACTER,NEXT_ELLIPSIS,NOT_REGEX,NO_NEWLINE,NUMBER,OPERATOR,REGEX,RELATION,RESERVED,Rewriter,SHIFT,SIMPLESTR,TRAILING_SPACES,UNARY,WHITESPACE,_ref,compact,count,include,last,op,starts;Rewriter=require("./rewriter").Rewriter;_ref=require("./helpers"),include=_ref.include,count=_ref.count,starts=_ref.starts,compact=_ref.compact,last=_ref.last;exports.Lexer=(function(){Lexer=(function(){function Lexer(){}return Lexer})();Lexer.prototype.tokenize=function(code,options){var o;code=code.replace(/\r/g,"").replace(TRAILING_SPACES,"");o=options||{};this.code=code;this.i=0;this.line=o.line||0;this.indent=0;this.indebt=0;this.outdebt=0;this.seenFor=false;this.indents=[];this.tokens=[];while(this.chunk=code.slice(this.i)){this.identifierToken()||this.commentToken()||this.whitespaceToken()||this.lineToken()||this.heredocToken()||this.stringToken()||this.numberToken()||this.regexToken()||this.jsToken()||this.literalToken()}this.closeIndentation();if(o.rewrite===false){return this.tokens}return(new Rewriter).rewrite(this.tokens)};Lexer.prototype.identifierToken=function(){var colon,forcedIdentifier,id,input,match,tag;if(!(match=IDENTIFIER.exec(this.chunk))){return false}input=match[0],id=match[1],colon=match[2];this.i+=input.length;if(id==="all"&&this.tag()==="FOR"){this.token("ALL",id);return true}forcedIdentifier=colon||this.tagAccessor();tag="IDENTIFIER";if(include(JS_KEYWORDS,id)||!forcedIdentifier&&include(COFFEE_KEYWORDS,id)){tag=id.toUpperCase();if(tag==="WHEN"&&include(LINE_BREAK,this.tag())){tag="LEADING_WHEN"}else{if(tag==="FOR"){this.seenFor=true}else{if(include(UNARY,tag)){tag="UNARY"}else{if(include(RELATION,tag)){if(tag!=="INSTANCEOF"&&this.seenFor){this.seenFor=false;tag="FOR"+tag}else{tag="RELATION";if(this.value()==="!"){this.tokens.pop();id="!"+id}}}}}}}if(include(JS_FORBIDDEN,id)){if(forcedIdentifier){tag="IDENTIFIER";id=new String(id);id.reserved=true}else{if(include(RESERVED,id)){this.identifierError(id)}}}if(!forcedIdentifier){if(COFFEE_ALIASES.hasOwnProperty(id)){tag=(id=COFFEE_ALIASES[id])}if(id==="!"){tag="UNARY"}else{if(include(LOGIC,id)){tag="LOGIC"}else{if(include(BOOL,tag)){id=tag.toLowerCase();tag="BOOL"}}}}this.token(tag,id);if(colon){this.token(":",":")}return true};Lexer.prototype.numberToken=function(){var match,number;if(!(match=NUMBER.exec(this.chunk))){return false}number=match[0];if(this.tag()==="."&&number.charAt(0)==="."){return false}this.i+=number.length;this.token("NUMBER",number);return true};Lexer.prototype.stringToken=function(){var match,string;switch(this.chunk.charAt(0)){case"'":if(!(match=SIMPLESTR.exec(this.chunk))){return false}this.token("STRING",(string=match[0]).replace(MULTILINER,"\\\n"));break;case'"':if(!(string=this.balancedString(this.chunk,[['"','"'],["#{","}"]]))){return false}if(0<string.indexOf("#{",1)){this.interpolateString(string.slice(1,-1))}else{this.token("STRING",this.escapeLines(string))}break;default:return false}this.line+=count(string,"\n");this.i+=string.length;return true};Lexer.prototype.heredocToken=function(){var doc,heredoc,match,quote;if(!(match=HEREDOC.exec(this.chunk))){return false}heredoc=match[0];quote=heredoc.charAt(0);doc=this.sanitizeHeredoc(match[2],{quote:quote,indent:null});if(quote==='"'&&(0<=doc.indexOf("#{"))){this.interpolateString(doc,{heredoc:true})}else{this.token("STRING",this.makeString(doc,quote,true))}this.line+=count(heredoc,"\n");this.i+=heredoc.length;return true};Lexer.prototype.commentToken=function(){var comment,here,match;if(!(match=this.chunk.match(COMMENT))){return false}comment=match[0],here=match[1];this.line+=count(comment,"\n");this.i+=comment.length;if(here){this.token("HERECOMMENT",this.sanitizeHeredoc(here,{herecomment:true,indent:Array(this.indent+1).join(" ")}));this.token("TERMINATOR","\n")}return true};Lexer.prototype.jsToken=function(){var match,script;if(!(this.chunk.charAt(0)==="`"&&(match=JSTOKEN.exec(this.chunk)))){return false}this.token("JS",(script=match[0]).slice(1,-1));this.i+=script.length;return true};Lexer.prototype.regexToken=function(){var match;if(this.chunk.charAt(0)!=="/"){return false}if(match=HEREGEX.exec(this.chunk)){return this.heregexToken(match)}if(include(NOT_REGEX,this.tag())){return false}if(!(match=REGEX.exec(this.chunk))){return false}this.token("REGEX",match[0]);this.i+=match[0].length;return true};Lexer.prototype.heregexToken=function(match){var _i,_len,_ref2,_ref3,_ref4,_this,body,flags,heregex,re,tag,tokens,value;heregex=match[0],body=match[1],flags=match[2];this.i+=heregex.length;if(0>body.indexOf("#{")){re=body.replace(HEREGEX_OMIT,"").replace(/\//g,"\\/");this.token("REGEX","/"+(re||"(?:)")+"/"+flags);return true}this.token("IDENTIFIER","RegExp");this.tokens.push(["CALL_START","("]);tokens=[];for(_i=0,_len=(_ref2=this.interpolateString(body,{regex:true})).length;_i<_len;_i++){_ref3=_ref2[_i],tag=_ref3[0],value=_ref3[1];if(tag==="TOKENS"){tokens.push.apply(tokens,value)}else{if(!(value=value.replace(HEREGEX_OMIT,""))){continue}value=value.replace(/\\/g,"\\\\");tokens.push(["STRING",this.makeString(value,'"',true)])}tokens.push(["+","+"])}tokens.pop();if((((_ref4=tokens[0])!=null)?_ref4[0]:undefined)!=="STRING"){this.tokens.push(["STRING",'""'],["+","+"])}(_this=this.tokens).push.apply(_this,tokens);if(flags){this.tokens.push([",",","],["STRING",'"'+flags+'"'])}this.token(")",")");return true};Lexer.prototype.lineToken=function(){var diff,indent,match,nextCharacter,noNewlines,prev,size;if(!(match=MULTI_DENT.exec(this.chunk))){return false}indent=match[0];this.line+=count(indent,"\n");this.i+=indent.length;prev=last(this.tokens,1);size=indent.length-1-indent.lastIndexOf("\n");nextCharacter=NEXT_CHARACTER.exec(this.chunk)[1];noNewlines=((nextCharacter==="."||nextCharacter===",")&&!NEXT_ELLIPSIS.test(this.chunk))||this.unfinished();if(size-this.indebt===this.indent){if(noNewlines){return this.suppressNewlines()}return this.newlineToken(indent)}else{if(size>this.indent){if(noNewlines){this.indebt=size-this.indent;return this.suppressNewlines()}diff=size-this.indent+this.outdebt;this.token("INDENT",diff);this.indents.push(diff);this.outdebt=(this.indebt=0)}else{this.indebt=0;this.outdentToken(this.indent-size,noNewlines)}}this.indent=size;return true};Lexer.prototype.outdentToken=function(moveOut,noNewlines,close){var dent,len;while(moveOut>0){len=this.indents.length-1;if(this.indents[len]===undefined){moveOut=0}else{if(this.indents[len]===this.outdebt){moveOut-=this.outdebt;this.outdebt=0}else{if(this.indents[len]<this.outdebt){this.outdebt-=this.indents[len];moveOut-=this.indents[len]}else{dent=this.indents.pop()-this.outdebt;moveOut-=dent;this.outdebt=0;this.token("OUTDENT",dent)}}}}if(dent){this.outdebt-=moveOut}if(!(this.tag()==="TERMINATOR"||noNewlines)){this.token("TERMINATOR","\n")}return true};Lexer.prototype.whitespaceToken=function(){var match,prev;if(!(match=WHITESPACE.exec(this.chunk))){return false}prev=last(this.tokens);if(prev){prev.spaced=true}this.i+=match[0].length;return true};Lexer.prototype.newlineToken=function(newlines){if(this.tag()!=="TERMINATOR"){this.token("TERMINATOR","\n")}return true};Lexer.prototype.suppressNewlines=function(){if(this.value()==="\\"){this.tokens.pop()}return true};Lexer.prototype.literalToken=function(){var _ref2,match,prev,tag,value;if(match=OPERATOR.exec(this.chunk)){value=match[0];if(CODE.test(value)){this.tagParameters()}}else{value=this.chunk.charAt(0)}this.i+=value.length;tag=value;prev=last(this.tokens);if(value==="="&&prev){if(!prev[1].reserved&&include(JS_FORBIDDEN,prev[1])){this.assignmentError()}if(((_ref2=prev[1])==="||"||_ref2==="&&")){prev[0]="COMPOUND_ASSIGN";prev[1]+="=";return true}}if(";"===value){tag="TERMINATOR"}else{if(include(LOGIC,value)){tag="LOGIC"}else{if(include(MATH,value)){tag="MATH"}else{if(include(COMPARE,value)){tag="COMPARE"}else{if(include(COMPOUND_ASSIGN,value)){tag="COMPOUND_ASSIGN"}else{if(include(UNARY,value)){tag="UNARY"}else{if(include(SHIFT,value)){tag="SHIFT"}else{if(value==="?"&&((prev!=null)?prev.spaced:undefined)){tag="LOGIC"}else{if(prev&&!prev.spaced){if(value==="("&&include(CALLABLE,prev[0])){if(prev[0]==="?"){prev[0]="FUNC_EXIST"}tag="CALL_START"}else{if(value==="["&&include(INDEXABLE,prev[0])){tag="INDEX_START";switch(prev[0]){case"?":prev[0]="INDEX_SOAK";break;case"::":prev[0]="INDEX_PROTO";break}}}}}}}}}}}}this.token(tag,value);return true};Lexer.prototype.tagAccessor=function(){var prev;if(!(prev=last(this.tokens))||prev.spaced){return false}if(prev[1]==="::"){this.tag(0,"PROTOTYPE_ACCESS")}else{if(prev[1]==="."&&this.value(1)!=="."){if(this.tag(1)==="?"){this.tag(0,"SOAK_ACCESS");this.tokens.splice(-2,1)}else{this.tag(0,"PROPERTY_ACCESS")}}else{return prev[0]==="@"}}return true};Lexer.prototype.sanitizeHeredoc=function(doc,options){var _ref2,attempt,herecomment,indent,match;indent=options.indent,herecomment=options.herecomment;if(herecomment&&0>doc.indexOf("\n")){return doc}if(!herecomment){while(match=HEREDOC_INDENT.exec(doc)){attempt=match[1];if(indent===null||(0<(_ref2=attempt.length))&&(_ref2<indent.length)){indent=attempt}}}if(indent){doc=doc.replace(RegExp("\\n"+indent,"g"),"\n")}if(!herecomment){doc=doc.replace(/^\n/,"")}return doc};Lexer.prototype.tagParameters=function(){var i,tok;if(this.tag()!==")"){return}i=this.tokens.length;while(tok=this.tokens[--i]){switch(tok[0]){case"IDENTIFIER":tok[0]="PARAM";break;case")":tok[0]="PARAM_END";break;case"(":case"CALL_START":tok[0]="PARAM_START";return true}}return true};Lexer.prototype.closeIndentation=function(){return this.outdentToken(this.indent)};Lexer.prototype.identifierError=function(word){throw SyntaxError('Reserved word "'+word+'" on line '+(this.line+1))};Lexer.prototype.assignmentError=function(){throw SyntaxError('Reserved word "'+(this.value())+'" on line '+(this.line+1)+" can't be assigned")};Lexer.prototype.balancedString=function(str,delimited,options){var _i,_len,close,i,levels,open,pair,slen;options||(options={});levels=[];i=0;slen=str.length;while(i<slen){if(levels.length&&str.charAt(i)==="\\"){i+=1}else{for(_i=0,_len=delimited.length;_i<_len;_i++){pair=delimited[_i];open=pair[0],close=pair[1];if(levels.length&&starts(str,close,i)&&last(levels)===pair){levels.pop();i+=close.length-1;if(!levels.length){i+=1}break}if(starts(str,open,i)){levels.push(pair);i+=open.length-1;break}}}if(!levels.length){break}i+=1}if(levels.length){throw SyntaxError("Unterminated "+(levels.pop()[0])+" starting on line "+(this.line+1))}return !i?false:str.slice(0,i)};Lexer.prototype.interpolateString=function(str,options){var _len,_ref2,_ref3,_this,expr,heredoc,i,inner,interpolated,letter,nested,pi,regex,tag,tokens,value;_ref2=options||(options={}),heredoc=_ref2.heredoc,regex=_ref2.regex;tokens=[];pi=0;i=-1;while(letter=str.charAt(i+=1)){if(letter==="\\"){i+=1;continue}if(!(letter==="#"&&str.charAt(i+1)==="{"&&(expr=this.balancedString(str.slice(i+1),[["{","}"]])))){continue}if(pi<i){tokens.push(["TO_BE_STRING",str.slice(pi,i)])}inner=expr.slice(1,-1).replace(LEADING_SPACES,"").replace(TRAILING_SPACES,"");if(inner.length){nested=new Lexer().tokenize(inner,{line:this.line,rewrite:false});nested.pop();if(nested.length>1){nested.unshift(["(","("]);nested.push([")",")"])}tokens.push(["TOKENS",nested])}i+=expr.length;pi=i+1}if((i>pi)&&(pi<str.length)){tokens.push(["TO_BE_STRING",str.slice(pi)])}if(regex){return tokens}if(!tokens.length){return this.token("STRING",'""')}if(tokens[0][0]!=="TO_BE_STRING"){tokens.unshift(["",""])}if(interpolated=tokens.length>1){this.token("(","(")}for(i=0,_len=tokens.length;i<_len;i++){_ref3=tokens[i],tag=_ref3[0],value=_ref3[1];if(i){this.token("+","+")}if(tag==="TOKENS"){(_this=this.tokens).push.apply(_this,value)}else{this.token("STRING",this.makeString(value,'"',heredoc))}}if(interpolated){this.token(")",")")}return tokens};Lexer.prototype.token=function(tag,value){return this.tokens.push([tag,value,this.line])};Lexer.prototype.tag=function(index,tag){var tok;return(tok=last(this.tokens,index))&&((tag!=null)?(tok[0]=tag):tok[0])};Lexer.prototype.value=function(index,val){var tok;return(tok=last(this.tokens,index))&&((val!=null)?(tok[1]=val):tok[1])};Lexer.prototype.unfinished=function(){var prev,value;return(prev=last(this.tokens,1))&&prev[0]!=="."&&(value=this.value())&&!value.reserved&&NO_NEWLINE.test(value)&&!CODE.test(value)&&!ASSIGNED.test(this.chunk)};Lexer.prototype.escapeLines=function(str,heredoc){return str.replace(MULTILINER,heredoc?"\\n":"")};Lexer.prototype.makeString=function(body,quote,heredoc){if(!body){return quote+quote}body=body.replace(/\\([\s\S])/g,function(match,contents){return(contents==="\n"||contents===quote)?contents:match});body=body.replace(RegExp(""+quote,"g"),"\\$&");return quote+this.escapeLines(body,heredoc)+quote};return Lexer})();JS_KEYWORDS=["true","false","null","this","new","delete","typeof","in","instanceof","return","throw","break","continue","debugger","if","else","switch","for","while","try","catch","finally","class","extends","super"];COFFEE_KEYWORDS=["then","unless","until","loop","of","by","when"];for(op in (COFFEE_ALIASES={and:"&&",or:"||",is:"==",isnt:"!=",not:"!",yes:"TRUE",no:"FALSE",on:"TRUE",off:"FALSE"})){COFFEE_KEYWORDS.push(op)}COFFEE_ALIASES["==="]="==";RESERVED=["case","default","do","function","var","void","with","const","let","enum","export","import","native","__hasProp","__extends","__slice"];JS_FORBIDDEN=JS_KEYWORDS.concat(RESERVED);IDENTIFIER=/^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/;NUMBER=/^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i;HEREDOC=/^("""|''')([\s\S]*?)(?:\n[ \t]*)?\1/;OPERATOR=/^(?:-[-=>]?|\+[+=]?|\.\.\.?|[*&|\/%=<>^:!?]+)/;WHITESPACE=/^[ \t]+/;COMMENT=/^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;CODE=/^[-=]>/;MULTI_DENT=/^(?:\n[ \t]*)+/;SIMPLESTR=/^'[^\\']*(?:\\.[^\\']*)*'/;JSTOKEN=/^`[^\\`]*(?:\\.[^\\`]*)*`/;REGEX=/^\/(?!\s)(?:[^[\/\n\\]+|\\[\s\S]|\[([^\]\n\\]+|\\[\s\S])*])+\/[imgy]{0,4}(?![A-Za-z])/;HEREGEX=/^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?![A-Za-z])/;HEREGEX_OMIT=/\s+(?:#.*)?/g;MULTILINER=/\n/g;HEREDOC_INDENT=/\n+([ \t]*)/g;ASSIGNED=/^\s*@?[$A-Za-z_][$\w]*[ \t]*?[:=][^:=>]/;NEXT_CHARACTER=/^\s*(\S?)/;NEXT_ELLIPSIS=/^\s*\.\.\.?/;LEADING_SPACES=/^\s+/;TRAILING_SPACES=/\s+$/;NO_NEWLINE=/^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/;COMPOUND_ASSIGN=["-=","+=","/=","*=","%=","||=","&&=","?=","<<=",">>=",">>>=","&=","^=","|="];UNARY=["UMINUS","UPLUS","!","!!","~","NEW","TYPEOF","DELETE"];LOGIC=["&","|","^","&&","||"];SHIFT=["<<",">>",">>>"];COMPARE=["<=","<",">",">="];MATH=["*","/","%"];RELATION=["IN","OF","INSTANCEOF"];BOOL=["TRUE","FALSE","NULL"];NOT_REGEX=["NUMBER","REGEX","BOOL","++","--","]"];CALLABLE=["IDENTIFIER","STRING","REGEX",")","]","}","?","::","@","THIS","SUPER"];INDEXABLE=CALLABLE.concat("NUMBER","BOOL");LINE_BREAK=["INDENT","OUTDENT","TERMINATOR"]}).call(this)};require["./parser"]=new function(){var exports=this;var parser=(function(){var parser={trace:function trace(){},yy:{},symbols_:{error:2,Root:3,TERMINATOR:4,Body:5,Block:6,Line:7,Expression:8,Statement:9,Return:10,Throw:11,BREAK:12,CONTINUE:13,DEBUGGER:14,Value:15,Invocation:16,Code:17,Operation:18,Assign:19,If:20,Try:21,While:22,For:23,Switch:24,Extends:25,Class:26,Existence:27,Comment:28,INDENT:29,OUTDENT:30,Identifier:31,IDENTIFIER:32,AlphaNumeric:33,NUMBER:34,STRING:35,Literal:36,JS:37,REGEX:38,BOOL:39,Assignable:40,"=":41,AssignObj:42,ThisProperty:43,":":44,RETURN:45,HERECOMMENT:46,"?":47,PARAM_START:48,ParamList:49,PARAM_END:50,FuncGlyph:51,"->":52,"=>":53,OptComma:54,",":55,Param:56,PARAM:57,"@":58,"...":59,Splat:60,SimpleAssignable:61,Accessor:62,Array:63,Object:64,Parenthetical:65,Range:66,This:67,PROPERTY_ACCESS:68,PROTOTYPE_ACCESS:69,"::":70,SOAK_ACCESS:71,Index:72,Slice:73,INDEX_START:74,INDEX_END:75,INDEX_SOAK:76,INDEX_PROTO:77,"{":78,AssignList:79,"}":80,CLASS:81,EXTENDS:82,ClassBody:83,ClassAssign:84,OptFuncExist:85,Arguments:86,SUPER:87,FUNC_EXIST:88,CALL_START:89,CALL_END:90,ArgList:91,THIS:92,RangeDots:93,"..":94,"[":95,"]":96,Arg:97,SimpleArgs:98,TRY:99,Catch:100,FINALLY:101,CATCH:102,THROW:103,"(":104,")":105,WhileSource:106,WHILE:107,WHEN:108,UNTIL:109,Loop:110,LOOP:111,ForBody:112,FOR:113,ForStart:114,ForSource:115,ForVariables:116,ALL:117,ForValue:118,FORIN:119,FOROF:120,BY:121,SWITCH:122,Whens:123,ELSE:124,When:125,LEADING_WHEN:126,IfBlock:127,IF:128,UNLESS:129,POST_IF:130,POST_UNLESS:131,UNARY:132,"-":133,"+":134,"--":135,"++":136,"==":137,"!=":138,MATH:139,SHIFT:140,COMPARE:141,LOGIC:142,COMPOUND_ASSIGN:143,RELATION:144,"$accept":0,"$end":1},terminals_:{"2":"error","4":"TERMINATOR","12":"BREAK","13":"CONTINUE","14":"DEBUGGER","29":"INDENT","30":"OUTDENT","32":"IDENTIFIER","34":"NUMBER","35":"STRING","37":"JS","38":"REGEX","39":"BOOL","41":"=","44":":","45":"RETURN","46":"HERECOMMENT","47":"?","48":"PARAM_START","50":"PARAM_END","52":"->","53":"=>","55":",","57":"PARAM","58":"@","59":"...","68":"PROPERTY_ACCESS","69":"PROTOTYPE_ACCESS","70":"::","71":"SOAK_ACCESS","74":"INDEX_START","75":"INDEX_END","76":"INDEX_SOAK","77":"INDEX_PROTO","78":"{","80":"}","81":"CLASS","82":"EXTENDS","87":"SUPER","88":"FUNC_EXIST","89":"CALL_START","90":"CALL_END","92":"THIS","94":"..","95":"[","96":"]","99":"TRY","101":"FINALLY","102":"CATCH","103":"THROW","104":"(","105":")","107":"WHILE","108":"WHEN","109":"UNTIL","111":"LOOP","113":"FOR","117":"ALL","119":"FORIN","120":"FOROF","121":"BY","122":"SWITCH","124":"ELSE","126":"LEADING_WHEN","128":"IF","129":"UNLESS","130":"POST_IF","131":"POST_UNLESS","132":"UNARY","133":"-","134":"+","135":"--","136":"++","137":"==","138":"!=","139":"MATH","140":"SHIFT","141":"COMPARE","142":"LOGIC","143":"COMPOUND_ASSIGN","144":"RELATION"},productions_:[0,[3,0],[3,1],[3,1],[3,2],[5,1],[5,3],[5,2],[7,1],[7,1],[9,1],[9,1],[9,1],[9,1],[9,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[6,3],[6,2],[6,2],[31,1],[33,1],[33,1],[36,1],[36,1],[36,1],[36,1],[19,3],[19,5],[42,1],[42,1],[42,1],[42,3],[42,3],[42,5],[42,5],[42,1],[10,2],[10,1],[28,1],[27,2],[17,5],[17,2],[51,1],[51,1],[54,0],[54,1],[49,0],[49,1],[49,3],[56,1],[56,2],[56,2],[56,3],[60,2],[61,1],[61,2],[61,2],[61,1],[40,1],[40,1],[40,1],[15,1],[15,1],[15,1],[15,1],[15,1],[62,2],[62,2],[62,1],[62,2],[62,1],[62,1],[72,3],[72,2],[72,2],[64,4],[79,0],[79,1],[79,3],[79,4],[79,6],[26,2],[26,4],[26,5],[26,7],[26,4],[26,1],[26,3],[26,6],[84,1],[84,3],[84,5],[83,0],[83,1],[83,3],[83,3],[25,3],[16,3],[16,3],[16,1],[16,2],[85,0],[85,1],[86,2],[86,4],[67,1],[67,1],[93,1],[93,1],[43,2],[66,5],[73,5],[73,4],[73,4],[63,2],[63,4],[91,1],[91,3],[91,4],[91,4],[91,6],[97,1],[97,1],[98,1],[98,3],[21,2],[21,3],[21,4],[21,5],[100,3],[11,2],[65,3],[65,2],[106,2],[106,4],[106,2],[106,4],[22,2],[22,2],[22,2],[22,1],[110,2],[110,2],[23,2],[23,2],[23,2],[112,2],[112,2],[114,2],[114,3],[118,1],[118,1],[118,1],[116,1],[116,3],[115,2],[115,2],[115,4],[115,4],[115,4],[115,6],[115,6],[24,5],[24,7],[24,4],[24,6],[123,1],[123,2],[125,3],[125,4],[127,3],[127,3],[127,5],[127,3],[20,1],[20,3],[20,3],[20,3],[20,3],[18,2],[18,2],[18,2],[18,2],[18,2],[18,2],[18,2],[18,3],[18,3],[18,3],[18,3],[18,3],[18,3],[18,3],[18,3],[18,3],[18,5],[18,3]],performAction:function anonymous(yytext,yyleng,yylineno,yy){var $$=arguments[5],$0=arguments[5].length;switch(arguments[4]){case 1:return this.$=new yy.Expressions;break;case 2:return this.$=new yy.Expressions;break;case 3:return this.$=$$[$0-1+1-1];break;case 4:return this.$=$$[$0-2+1-1];break;case 5:this.$=yy.Expressions.wrap([$$[$0-1+1-1]]);break;case 6:this.$=$$[$0-3+1-1].push($$[$0-3+3-1]);break;case 7:this.$=$$[$0-2+1-1];break;case 8:this.$=$$[$0-1+1-1];break;case 9:this.$=$$[$0-1+1-1];break;case 10:this.$=$$[$0-1+1-1];break;case 11:this.$=$$[$0-1+1-1];break;case 12:this.$=new yy.Literal($$[$0-1+1-1]);break;case 13:this.$=new yy.Literal($$[$0-1+1-1]);break;case 14:this.$=new yy.Literal($$[$0-1+1-1]);break;case 15:this.$=$$[$0-1+1-1];break;case 16:this.$=$$[$0-1+1-1];break;case 17:this.$=$$[$0-1+1-1];break;case 18:this.$=$$[$0-1+1-1];break;case 19:this.$=$$[$0-1+1-1];break;case 20:this.$=$$[$0-1+1-1];break;case 21:this.$=$$[$0-1+1-1];break;case 22:this.$=$$[$0-1+1-1];break;case 23:this.$=$$[$0-1+1-1];break;case 24:this.$=$$[$0-1+1-1];break;case 25:this.$=$$[$0-1+1-1];break;case 26:this.$=$$[$0-1+1-1];break;case 27:this.$=$$[$0-1+1-1];break;case 28:this.$=$$[$0-1+1-1];break;case 29:this.$=$$[$0-3+2-1];break;case 30:this.$=new yy.Expressions;break;case 31:this.$=yy.Expressions.wrap([$$[$0-2+2-1]]);break;case 32:this.$=new yy.Literal($$[$0-1+1-1]);break;case 33:this.$=new yy.Literal($$[$0-1+1-1]);break;case 34:this.$=new yy.Literal($$[$0-1+1-1]);break;case 35:this.$=$$[$0-1+1-1];break;case 36:this.$=new yy.Literal($$[$0-1+1-1]);break;case 37:this.$=new yy.Literal($$[$0-1+1-1]);break;case 38:this.$=new yy.Literal($$[$0-1+1-1]);break;case 39:this.$=new yy.Assign($$[$0-3+1-1],$$[$0-3+3-1]);break;case 40:this.$=new yy.Assign($$[$0-5+1-1],$$[$0-5+4-1]);break;case 41:this.$=new yy.Value($$[$0-1+1-1]);break;case 42:this.$=$$[$0-1+1-1];break;case 43:this.$=$$[$0-1+1-1];break;case 44:this.$=new yy.Assign(new yy.Value($$[$0-3+1-1]),$$[$0-3+3-1],"object");break;case 45:this.$=new yy.Assign(new yy.Value($$[$0-3+1-1]),$$[$0-3+3-1],"object");break;case 46:this.$=new yy.Assign(new yy.Value($$[$0-5+1-1]),$$[$0-5+4-1],"object");break;case 47:this.$=new yy.Assign(new yy.Value($$[$0-5+1-1]),$$[$0-5+4-1],"object");break;case 48:this.$=$$[$0-1+1-1];break;case 49:this.$=new yy.Return($$[$0-2+2-1]);break;case 50:this.$=new yy.Return;break;case 51:this.$=new yy.Comment($$[$0-1+1-1]);break;case 52:this.$=new yy.Existence($$[$0-2+1-1]);break;case 53:this.$=new yy.Code($$[$0-5+2-1],$$[$0-5+5-1],$$[$0-5+4-1]);break;case 54:this.$=new yy.Code([],$$[$0-2+2-1],$$[$0-2+1-1]);break;case 55:this.$="func";break;case 56:this.$="boundfunc";break;case 57:this.$=$$[$0-1+1-1];break;case 58:this.$=$$[$0-1+1-1];break;case 59:this.$=[];break;case 60:this.$=[$$[$0-1+1-1]];break;case 61:this.$=$$[$0-3+1-1].concat($$[$0-3+3-1]);break;case 62:this.$=new yy.Literal($$[$0-1+1-1]);break;case 63:this.$=new yy.Param($$[$0-2+2-1],true);break;case 64:this.$=new yy.Param($$[$0-2+1-1],false,true);break;case 65:this.$=new yy.Param($$[$0-3+2-1],true,true);break;case 66:this.$=new yy.Splat($$[$0-2+1-1]);break;case 67:this.$=new yy.Value($$[$0-1+1-1]);break;case 68:this.$=$$[$0-2+1-1].push($$[$0-2+2-1]);break;case 69:this.$=new yy.Value($$[$0-2+1-1],[$$[$0-2+2-1]]);break;case 70:this.$=$$[$0-1+1-1];break;case 71:this.$=$$[$0-1+1-1];break;case 72:this.$=new yy.Value($$[$0-1+1-1]);break;case 73:this.$=new yy.Value($$[$0-1+1-1]);break;case 74:this.$=$$[$0-1+1-1];break;case 75:this.$=new yy.Value($$[$0-1+1-1]);break;case 76:this.$=new yy.Value($$[$0-1+1-1]);break;case 77:this.$=new yy.Value($$[$0-1+1-1]);break;case 78:this.$=$$[$0-1+1-1];break;case 79:this.$=new yy.Accessor($$[$0-2+2-1]);break;case 80:this.$=new yy.Accessor($$[$0-2+2-1],"prototype");break;case 81:this.$=new yy.Accessor(new yy.Literal("prototype"));break;case 82:this.$=new yy.Accessor($$[$0-2+2-1],"soak");break;case 83:this.$=$$[$0-1+1-1];break;case 84:this.$=new yy.Slice($$[$0-1+1-1]);break;case 85:this.$=new yy.Index($$[$0-3+2-1]);break;case 86:this.$=(function(){$$[$0-2+2-1].soakNode=true;return $$[$0-2+2-1]}());break;case 87:this.$=(function(){$$[$0-2+2-1].proto=true;return $$[$0-2+2-1]}());break;case 88:this.$=new yy.ObjectLiteral($$[$0-4+2-1]);break;case 89:this.$=[];break;case 90:this.$=[$$[$0-1+1-1]];break;case 91:this.$=$$[$0-3+1-1].concat($$[$0-3+3-1]);break;case 92:this.$=$$[$0-4+1-1].concat($$[$0-4+4-1]);break;case 93:this.$=$$[$0-6+1-1].concat($$[$0-6+4-1]);break;case 94:this.$=new yy.Class($$[$0-2+2-1]);break;case 95:this.$=new yy.Class($$[$0-4+2-1],$$[$0-4+4-1]);break;case 96:this.$=new yy.Class($$[$0-5+2-1],null,$$[$0-5+4-1]);break;case 97:this.$=new yy.Class($$[$0-7+2-1],$$[$0-7+4-1],$$[$0-7+6-1]);break;case 98:this.$=new yy.Class("__temp__",null,$$[$0-4+3-1]);break;case 99:this.$=new yy.Class("__temp__",null,new yy.Expressions);break;case 100:this.$=new yy.Class("__temp__",$$[$0-3+3-1],new yy.Expressions);break;case 101:this.$=new yy.Class("__temp__",$$[$0-6+3-1],$$[$0-6+5-1]);break;case 102:this.$=$$[$0-1+1-1];break;case 103:this.$=new yy.Assign(new yy.Value($$[$0-3+1-1]),$$[$0-3+3-1],"this");break;case 104:this.$=new yy.Assign(new yy.Value($$[$0-5+1-1]),$$[$0-5+4-1],"this");break;case 105:this.$=[];break;case 106:this.$=[$$[$0-1+1-1]];break;case 107:this.$=$$[$0-3+1-1].concat($$[$0-3+3-1]);break;case 108:this.$=$$[$0-3+2-1];break;case 109:this.$=new yy.Extends($$[$0-3+1-1],$$[$0-3+3-1]);break;case 110:this.$=new yy.Call($$[$0-3+1-1],$$[$0-3+3-1],$$[$0-3+2-1]);break;case 111:this.$=new yy.Call($$[$0-3+1-1],$$[$0-3+3-1],$$[$0-3+2-1]);break;case 112:this.$=new yy.Call("super",[new yy.Splat(new yy.Literal("arguments"))]);break;case 113:this.$=new yy.Call("super",$$[$0-2+2-1]);break;case 114:this.$=false;break;case 115:this.$=true;break;case 116:this.$=[];break;case 117:this.$=$$[$0-4+2-1];break;case 118:this.$=new yy.Value(new yy.Literal("this"));break;case 119:this.$=new yy.Value(new yy.Literal("this"));break;case 120:this.$="inclusive";break;case 121:this.$="exclusive";break;case 122:this.$=new yy.Value(new yy.Literal("this"),[new yy.Accessor($$[$0-2+2-1])],"this");break;case 123:this.$=new yy.Range($$[$0-5+2-1],$$[$0-5+4-1],$$[$0-5+3-1]);break;case 124:this.$=new yy.Range($$[$0-5+2-1],$$[$0-5+4-1],$$[$0-5+3-1]);break;case 125:this.$=new yy.Range($$[$0-4+2-1],null,$$[$0-4+3-1]);break;case 126:this.$=new yy.Range(null,$$[$0-4+3-1],$$[$0-4+2-1]);break;case 127:this.$=new yy.ArrayLiteral([]);break;case 128:this.$=new yy.ArrayLiteral($$[$0-4+2-1]);break;case 129:this.$=[$$[$0-1+1-1]];break;case 130:this.$=$$[$0-3+1-1].concat($$[$0-3+3-1]);break;case 131:this.$=$$[$0-4+1-1].concat($$[$0-4+4-1]);break;case 132:this.$=$$[$0-4+2-1];break;case 133:this.$=$$[$0-6+1-1].concat($$[$0-6+4-1]);break;case 134:this.$=$$[$0-1+1-1];break;case 135:this.$=$$[$0-1+1-1];break;case 136:this.$=$$[$0-1+1-1];break;case 137:this.$=[].concat($$[$0-3+1-1],$$[$0-3+3-1]);break;case 138:this.$=new yy.Try($$[$0-2+2-1]);break;case 139:this.$=new yy.Try($$[$0-3+2-1],$$[$0-3+3-1][0],$$[$0-3+3-1][1]);break;case 140:this.$=new yy.Try($$[$0-4+2-1],null,null,$$[$0-4+4-1]);break;case 141:this.$=new yy.Try($$[$0-5+2-1],$$[$0-5+3-1][0],$$[$0-5+3-1][1],$$[$0-5+5-1]);break;case 142:this.$=[$$[$0-3+2-1],$$[$0-3+3-1]];break;case 143:this.$=new yy.Throw($$[$0-2+2-1]);break;case 144:this.$=new yy.Parens($$[$0-3+2-1]);break;case 145:this.$=new yy.Parens(new yy.Literal(""));break;case 146:this.$=new yy.While($$[$0-2+2-1]);break;case 147:this.$=new yy.While($$[$0-4+2-1],{guard:$$[$0-4+4-1]});break;case 148:this.$=new yy.While($$[$0-2+2-1],{invert:true});break;case 149:this.$=new yy.While($$[$0-4+2-1],{invert:true,guard:$$[$0-4+4-1]});break;case 150:this.$=$$[$0-2+1-1].addBody($$[$0-2+2-1]);break;case 151:this.$=$$[$0-2+2-1].addBody(yy.Expressions.wrap([$$[$0-2+1-1]]));break;case 152:this.$=$$[$0-2+2-1].addBody(yy.Expressions.wrap([$$[$0-2+1-1]]));break;case 153:this.$=$$[$0-1+1-1];break;case 154:this.$=new yy.While(new yy.Literal("true")).addBody($$[$0-2+2-1]);break;case 155:this.$=new yy.While(new yy.Literal("true")).addBody(yy.Expressions.wrap([$$[$0-2+2-1]]));break;case 156:this.$=new yy.For($$[$0-2+1-1],$$[$0-2+2-1],$$[$0-2+2-1].vars[0],$$[$0-2+2-1].vars[1]);break;case 157:this.$=new yy.For($$[$0-2+1-1],$$[$0-2+2-1],$$[$0-2+2-1].vars[0],$$[$0-2+2-1].vars[1]);break;case 158:this.$=new yy.For($$[$0-2+2-1],$$[$0-2+1-1],$$[$0-2+1-1].vars[0],$$[$0-2+1-1].vars[1]);break;case 159:this.$={source:new yy.Value($$[$0-2+2-1]),vars:[]};break;case 160:this.$=(function(){$$[$0-2+2-1].raw=$$[$0-2+1-1].raw;$$[$0-2+2-1].vars=$$[$0-2+1-1];return $$[$0-2+2-1]}());break;case 161:this.$=$$[$0-2+2-1];break;case 162:this.$=(function(){$$[$0-3+3-1].raw=true;return $$[$0-3+3-1]}());break;case 163:this.$=$$[$0-1+1-1];break;case 164:this.$=new yy.Value($$[$0-1+1-1]);break;case 165:this.$=new yy.Value($$[$0-1+1-1]);break;case 166:this.$=[$$[$0-1+1-1]];break;case 167:this.$=[$$[$0-3+1-1],$$[$0-3+3-1]];break;case 168:this.$={source:$$[$0-2+2-1]};break;case 169:this.$={source:$$[$0-2+2-1],object:true};break;case 170:this.$={source:$$[$0-4+2-1],guard:$$[$0-4+4-1]};break;case 171:this.$={source:$$[$0-4+2-1],guard:$$[$0-4+4-1],object:true};break;case 172:this.$={source:$$[$0-4+2-1],step:$$[$0-4+4-1]};break;case 173:this.$={source:$$[$0-6+2-1],guard:$$[$0-6+4-1],step:$$[$0-6+6-1]};break;case 174:this.$={source:$$[$0-6+2-1],step:$$[$0-6+4-1],guard:$$[$0-6+6-1]};break;case 175:this.$=new yy.Switch($$[$0-5+2-1],$$[$0-5+4-1]);break;case 176:this.$=new yy.Switch($$[$0-7+2-1],$$[$0-7+4-1],$$[$0-7+6-1]);break;case 177:this.$=new yy.Switch(null,$$[$0-4+3-1]);break;case 178:this.$=new yy.Switch(null,$$[$0-6+3-1],$$[$0-6+5-1]);break;case 179:this.$=$$[$0-1+1-1];break;case 180:this.$=$$[$0-2+1-1].concat($$[$0-2+2-1]);break;case 181:this.$=[[$$[$0-3+2-1],$$[$0-3+3-1]]];break;case 182:this.$=[[$$[$0-4+2-1],$$[$0-4+3-1]]];break;case 183:this.$=new yy.If($$[$0-3+2-1],$$[$0-3+3-1]);break;case 184:this.$=new yy.If($$[$0-3+2-1],$$[$0-3+3-1],{invert:true});break;case 185:this.$=$$[$0-5+1-1].addElse(new yy.If($$[$0-5+4-1],$$[$0-5+5-1]));break;case 186:this.$=$$[$0-3+1-1].addElse($$[$0-3+3-1]);break;case 187:this.$=$$[$0-1+1-1];break;case 188:this.$=new yy.If($$[$0-3+3-1],yy.Expressions.wrap([$$[$0-3+1-1]]),{statement:true});break;case 189:this.$=new yy.If($$[$0-3+3-1],yy.Expressions.wrap([$$[$0-3+1-1]]),{statement:true});break;case 190:this.$=new yy.If($$[$0-3+3-1],yy.Expressions.wrap([$$[$0-3+1-1]]),{statement:true,invert:true});break;case 191:this.$=new yy.If($$[$0-3+3-1],yy.Expressions.wrap([$$[$0-3+1-1]]),{statement:true,invert:true});break;case 192:this.$=new yy.Op($$[$0-2+1-1],$$[$0-2+2-1]);break;case 193:this.$=new yy.Op("-",$$[$0-2+2-1]);break;case 194:this.$=new yy.Op("+",$$[$0-2+2-1]);break;case 195:this.$=new yy.Op("--",$$[$0-2+2-1]);break;case 196:this.$=new yy.Op("++",$$[$0-2+2-1]);break;case 197:this.$=new yy.Op("--",$$[$0-2+1-1],null,true);break;case 198:this.$=new yy.Op("++",$$[$0-2+1-1],null,true);break;case 199:this.$=new yy.Op("+",$$[$0-3+1-1],$$[$0-3+3-1]);break;case 200:this.$=new yy.Op("-",$$[$0-3+1-1],$$[$0-3+3-1]);break;case 201:this.$=new yy.Op("==",$$[$0-3+1-1],$$[$0-3+3-1]);break;case 202:this.$=new yy.Op("!=",$$[$0-3+1-1],$$[$0-3+3-1]);break;case 203:this.$=new yy.Op($$[$0-3+2-1],$$[$0-3+1-1],$$[$0-3+3-1]);break;case 204:this.$=new yy.Op($$[$0-3+2-1],$$[$0-3+1-1],$$[$0-3+3-1]);break;case 205:this.$=new yy.Op($$[$0-3+2-1],$$[$0-3+1-1],$$[$0-3+3-1]);break;case 206:this.$=new yy.Op($$[$0-3+2-1],$$[$0-3+1-1],$$[$0-3+3-1]);break;case 207:this.$=new yy.Op($$[$0-3+2-1],$$[$0-3+1-1],$$[$0-3+3-1]);break;case 208:this.$=new yy.Op($$[$0-5+2-1],$$[$0-5+1-1],$$[$0-5+4-1]);break;case 209:this.$=$$[$0-3+2-1].charAt(0)==="!"?($$[$0-3+2-1]==="!in"?new yy.Op("!",new yy.In($$[$0-3+1-1],$$[$0-3+3-1])):new yy.Op("!",new yy.Parens(new yy.Op($$[$0-3+2-1].slice(1),$$[$0-3+1-1],$$[$0-3+3-1])))):($$[$0-3+2-1]==="in"?new yy.In($$[$0-3+1-1],$$[$0-3+3-1]):new yy.Op($$[$0-3+2-1],$$[$0-3+1-1],$$[$0-3+3-1]));break}},table:[{"1":[2,1],"3":1,"4":[1,2],"5":3,"6":4,"7":5,"8":7,"9":8,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,6],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[3]},{"1":[2,2],"28":77,"46":[1,49]},{"1":[2,3],"4":[1,78]},{"4":[1,79]},{"1":[2,5],"4":[2,5],"30":[2,5]},{"5":80,"7":5,"8":7,"9":8,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"30":[1,81],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,8],"4":[2,8],"30":[2,8],"47":[1,97],"105":[2,8],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,9],"4":[2,9],"30":[2,9],"105":[2,9],"106":100,"107":[1,66],"109":[1,67],"112":101,"113":[1,69],"114":70,"130":[1,98],"131":[1,99]},{"1":[2,15],"4":[2,15],"29":[2,15],"30":[2,15],"47":[2,15],"55":[2,15],"59":[2,15],"62":104,"68":[1,106],"69":[1,107],"70":[1,108],"71":[1,109],"72":110,"73":111,"74":[1,112],"75":[2,15],"76":[1,113],"77":[1,114],"80":[2,15],"85":102,"88":[1,105],"89":[2,114],"90":[2,15],"94":[2,15],"96":[2,15],"105":[2,15],"107":[2,15],"108":[2,15],"109":[2,15],"113":[2,15],"121":[2,15],"130":[2,15],"131":[2,15],"133":[2,15],"134":[2,15],"135":[2,15],"136":[2,15],"137":[2,15],"138":[2,15],"139":[2,15],"140":[2,15],"141":[2,15],"142":[2,15],"143":[1,103],"144":[2,15]},{"1":[2,16],"4":[2,16],"29":[2,16],"30":[2,16],"47":[2,16],"55":[2,16],"59":[2,16],"62":116,"68":[1,106],"69":[1,107],"70":[1,108],"71":[1,109],"72":110,"73":111,"74":[1,112],"75":[2,16],"76":[1,113],"77":[1,114],"80":[2,16],"85":115,"88":[1,105],"89":[2,114],"90":[2,16],"94":[2,16],"96":[2,16],"105":[2,16],"107":[2,16],"108":[2,16],"109":[2,16],"113":[2,16],"121":[2,16],"130":[2,16],"131":[2,16],"133":[2,16],"134":[2,16],"135":[2,16],"136":[2,16],"137":[2,16],"138":[2,16],"139":[2,16],"140":[2,16],"141":[2,16],"142":[2,16],"144":[2,16]},{"1":[2,17],"4":[2,17],"29":[2,17],"30":[2,17],"47":[2,17],"55":[2,17],"59":[2,17],"75":[2,17],"80":[2,17],"90":[2,17],"94":[2,17],"96":[2,17],"105":[2,17],"107":[2,17],"108":[2,17],"109":[2,17],"113":[2,17],"121":[2,17],"130":[2,17],"131":[2,17],"133":[2,17],"134":[2,17],"135":[2,17],"136":[2,17],"137":[2,17],"138":[2,17],"139":[2,17],"140":[2,17],"141":[2,17],"142":[2,17],"144":[2,17]},{"1":[2,18],"4":[2,18],"29":[2,18],"30":[2,18],"47":[2,18],"55":[2,18],"59":[2,18],"75":[2,18],"80":[2,18],"90":[2,18],"94":[2,18],"96":[2,18],"105":[2,18],"107":[2,18],"108":[2,18],"109":[2,18],"113":[2,18],"121":[2,18],"130":[2,18],"131":[2,18],"133":[2,18],"134":[2,18],"135":[2,18],"136":[2,18],"137":[2,18],"138":[2,18],"139":[2,18],"140":[2,18],"141":[2,18],"142":[2,18],"144":[2,18]},{"1":[2,19],"4":[2,19],"29":[2,19],"30":[2,19],"47":[2,19],"55":[2,19],"59":[2,19],"75":[2,19],"80":[2,19],"90":[2,19],"94":[2,19],"96":[2,19],"105":[2,19],"107":[2,19],"108":[2,19],"109":[2,19],"113":[2,19],"121":[2,19],"130":[2,19],"131":[2,19],"133":[2,19],"134":[2,19],"135":[2,19],"136":[2,19],"137":[2,19],"138":[2,19],"139":[2,19],"140":[2,19],"141":[2,19],"142":[2,19],"144":[2,19]},{"1":[2,20],"4":[2,20],"29":[2,20],"30":[2,20],"47":[2,20],"55":[2,20],"59":[2,20],"75":[2,20],"80":[2,20],"90":[2,20],"94":[2,20],"96":[2,20],"105":[2,20],"107":[2,20],"108":[2,20],"109":[2,20],"113":[2,20],"121":[2,20],"130":[2,20],"131":[2,20],"133":[2,20],"134":[2,20],"135":[2,20],"136":[2,20],"137":[2,20],"138":[2,20],"139":[2,20],"140":[2,20],"141":[2,20],"142":[2,20],"144":[2,20]},{"1":[2,21],"4":[2,21],"29":[2,21],"30":[2,21],"47":[2,21],"55":[2,21],"59":[2,21],"75":[2,21],"80":[2,21],"90":[2,21],"94":[2,21],"96":[2,21],"105":[2,21],"107":[2,21],"108":[2,21],"109":[2,21],"113":[2,21],"121":[2,21],"130":[2,21],"131":[2,21],"133":[2,21],"134":[2,21],"135":[2,21],"136":[2,21],"137":[2,21],"138":[2,21],"139":[2,21],"140":[2,21],"141":[2,21],"142":[2,21],"144":[2,21]},{"1":[2,22],"4":[2,22],"29":[2,22],"30":[2,22],"47":[2,22],"55":[2,22],"59":[2,22],"75":[2,22],"80":[2,22],"90":[2,22],"94":[2,22],"96":[2,22],"105":[2,22],"107":[2,22],"108":[2,22],"109":[2,22],"113":[2,22],"121":[2,22],"130":[2,22],"131":[2,22],"133":[2,22],"134":[2,22],"135":[2,22],"136":[2,22],"137":[2,22],"138":[2,22],"139":[2,22],"140":[2,22],"141":[2,22],"142":[2,22],"144":[2,22]},{"1":[2,23],"4":[2,23],"29":[2,23],"30":[2,23],"47":[2,23],"55":[2,23],"59":[2,23],"75":[2,23],"80":[2,23],"90":[2,23],"94":[2,23],"96":[2,23],"105":[2,23],"107":[2,23],"108":[2,23],"109":[2,23],"113":[2,23],"121":[2,23],"130":[2,23],"131":[2,23],"133":[2,23],"134":[2,23],"135":[2,23],"136":[2,23],"137":[2,23],"138":[2,23],"139":[2,23],"140":[2,23],"141":[2,23],"142":[2,23],"144":[2,23]},{"1":[2,24],"4":[2,24],"29":[2,24],"30":[2,24],"47":[2,24],"55":[2,24],"59":[2,24],"75":[2,24],"80":[2,24],"90":[2,24],"94":[2,24],"96":[2,24],"105":[2,24],"107":[2,24],"108":[2,24],"109":[2,24],"113":[2,24],"121":[2,24],"130":[2,24],"131":[2,24],"133":[2,24],"134":[2,24],"135":[2,24],"136":[2,24],"137":[2,24],"138":[2,24],"139":[2,24],"140":[2,24],"141":[2,24],"142":[2,24],"144":[2,24]},{"1":[2,25],"4":[2,25],"29":[2,25],"30":[2,25],"47":[2,25],"55":[2,25],"59":[2,25],"75":[2,25],"80":[2,25],"90":[2,25],"94":[2,25],"96":[2,25],"105":[2,25],"107":[2,25],"108":[2,25],"109":[2,25],"113":[2,25],"121":[2,25],"130":[2,25],"131":[2,25],"133":[2,25],"134":[2,25],"135":[2,25],"136":[2,25],"137":[2,25],"138":[2,25],"139":[2,25],"140":[2,25],"141":[2,25],"142":[2,25],"144":[2,25]},{"1":[2,26],"4":[2,26],"29":[2,26],"30":[2,26],"47":[2,26],"55":[2,26],"59":[2,26],"75":[2,26],"80":[2,26],"90":[2,26],"94":[2,26],"96":[2,26],"105":[2,26],"107":[2,26],"108":[2,26],"109":[2,26],"113":[2,26],"121":[2,26],"130":[2,26],"131":[2,26],"133":[2,26],"134":[2,26],"135":[2,26],"136":[2,26],"137":[2,26],"138":[2,26],"139":[2,26],"140":[2,26],"141":[2,26],"142":[2,26],"144":[2,26]},{"1":[2,27],"4":[2,27],"29":[2,27],"30":[2,27],"47":[2,27],"55":[2,27],"59":[2,27],"75":[2,27],"80":[2,27],"90":[2,27],"94":[2,27],"96":[2,27],"105":[2,27],"107":[2,27],"108":[2,27],"109":[2,27],"113":[2,27],"121":[2,27],"130":[2,27],"131":[2,27],"133":[2,27],"134":[2,27],"135":[2,27],"136":[2,27],"137":[2,27],"138":[2,27],"139":[2,27],"140":[2,27],"141":[2,27],"142":[2,27],"144":[2,27]},{"1":[2,28],"4":[2,28],"29":[2,28],"30":[2,28],"47":[2,28],"55":[2,28],"59":[2,28],"75":[2,28],"80":[2,28],"90":[2,28],"94":[2,28],"96":[2,28],"105":[2,28],"107":[2,28],"108":[2,28],"109":[2,28],"113":[2,28],"121":[2,28],"130":[2,28],"131":[2,28],"133":[2,28],"134":[2,28],"135":[2,28],"136":[2,28],"137":[2,28],"138":[2,28],"139":[2,28],"140":[2,28],"141":[2,28],"142":[2,28],"144":[2,28]},{"1":[2,10],"4":[2,10],"30":[2,10],"105":[2,10],"107":[2,10],"109":[2,10],"113":[2,10],"130":[2,10],"131":[2,10]},{"1":[2,11],"4":[2,11],"30":[2,11],"105":[2,11],"107":[2,11],"109":[2,11],"113":[2,11],"130":[2,11],"131":[2,11]},{"1":[2,12],"4":[2,12],"30":[2,12],"105":[2,12],"107":[2,12],"109":[2,12],"113":[2,12],"130":[2,12],"131":[2,12]},{"1":[2,13],"4":[2,13],"30":[2,13],"105":[2,13],"107":[2,13],"109":[2,13],"113":[2,13],"130":[2,13],"131":[2,13]},{"1":[2,14],"4":[2,14],"30":[2,14],"105":[2,14],"107":[2,14],"109":[2,14],"113":[2,14],"130":[2,14],"131":[2,14]},{"1":[2,74],"4":[2,74],"29":[2,74],"30":[2,74],"41":[1,117],"47":[2,74],"55":[2,74],"59":[2,74],"68":[2,74],"69":[2,74],"70":[2,74],"71":[2,74],"74":[2,74],"75":[2,74],"76":[2,74],"77":[2,74],"80":[2,74],"88":[2,74],"89":[2,74],"90":[2,74],"94":[2,74],"96":[2,74],"105":[2,74],"107":[2,74],"108":[2,74],"109":[2,74],"113":[2,74],"121":[2,74],"130":[2,74],"131":[2,74],"133":[2,74],"134":[2,74],"135":[2,74],"136":[2,74],"137":[2,74],"138":[2,74],"139":[2,74],"140":[2,74],"141":[2,74],"142":[2,74],"143":[2,74],"144":[2,74]},{"1":[2,75],"4":[2,75],"29":[2,75],"30":[2,75],"47":[2,75],"55":[2,75],"59":[2,75],"68":[2,75],"69":[2,75],"70":[2,75],"71":[2,75],"74":[2,75],"75":[2,75],"76":[2,75],"77":[2,75],"80":[2,75],"88":[2,75],"89":[2,75],"90":[2,75],"94":[2,75],"96":[2,75],"105":[2,75],"107":[2,75],"108":[2,75],"109":[2,75],"113":[2,75],"121":[2,75],"130":[2,75],"131":[2,75],"133":[2,75],"134":[2,75],"135":[2,75],"136":[2,75],"137":[2,75],"138":[2,75],"139":[2,75],"140":[2,75],"141":[2,75],"142":[2,75],"143":[2,75],"144":[2,75]},{"1":[2,76],"4":[2,76],"29":[2,76],"30":[2,76],"47":[2,76],"55":[2,76],"59":[2,76],"68":[2,76],"69":[2,76],"70":[2,76],"71":[2,76],"74":[2,76],"75":[2,76],"76":[2,76],"77":[2,76],"80":[2,76],"88":[2,76],"89":[2,76],"90":[2,76],"94":[2,76],"96":[2,76],"105":[2,76],"107":[2,76],"108":[2,76],"109":[2,76],"113":[2,76],"121":[2,76],"130":[2,76],"131":[2,76],"133":[2,76],"134":[2,76],"135":[2,76],"136":[2,76],"137":[2,76],"138":[2,76],"139":[2,76],"140":[2,76],"141":[2,76],"142":[2,76],"143":[2,76],"144":[2,76]},{"1":[2,77],"4":[2,77],"29":[2,77],"30":[2,77],"47":[2,77],"55":[2,77],"59":[2,77],"68":[2,77],"69":[2,77],"70":[2,77],"71":[2,77],"74":[2,77],"75":[2,77],"76":[2,77],"77":[2,77],"80":[2,77],"88":[2,77],"89":[2,77],"90":[2,77],"94":[2,77],"96":[2,77],"105":[2,77],"107":[2,77],"108":[2,77],"109":[2,77],"113":[2,77],"121":[2,77],"130":[2,77],"131":[2,77],"133":[2,77],"134":[2,77],"135":[2,77],"136":[2,77],"137":[2,77],"138":[2,77],"139":[2,77],"140":[2,77],"141":[2,77],"142":[2,77],"143":[2,77],"144":[2,77]},{"1":[2,78],"4":[2,78],"29":[2,78],"30":[2,78],"47":[2,78],"55":[2,78],"59":[2,78],"68":[2,78],"69":[2,78],"70":[2,78],"71":[2,78],"74":[2,78],"75":[2,78],"76":[2,78],"77":[2,78],"80":[2,78],"88":[2,78],"89":[2,78],"90":[2,78],"94":[2,78],"96":[2,78],"105":[2,78],"107":[2,78],"108":[2,78],"109":[2,78],"113":[2,78],"121":[2,78],"130":[2,78],"131":[2,78],"133":[2,78],"134":[2,78],"135":[2,78],"136":[2,78],"137":[2,78],"138":[2,78],"139":[2,78],"140":[2,78],"141":[2,78],"142":[2,78],"143":[2,78],"144":[2,78]},{"1":[2,112],"4":[2,112],"29":[2,112],"30":[2,112],"47":[2,112],"55":[2,112],"59":[2,112],"68":[2,112],"69":[2,112],"70":[2,112],"71":[2,112],"74":[2,112],"75":[2,112],"76":[2,112],"77":[2,112],"80":[2,112],"86":118,"88":[2,112],"89":[1,119],"90":[2,112],"94":[2,112],"96":[2,112],"105":[2,112],"107":[2,112],"108":[2,112],"109":[2,112],"113":[2,112],"121":[2,112],"130":[2,112],"131":[2,112],"133":[2,112],"134":[2,112],"135":[2,112],"136":[2,112],"137":[2,112],"138":[2,112],"139":[2,112],"140":[2,112],"141":[2,112],"142":[2,112],"144":[2,112]},{"49":120,"50":[2,59],"55":[2,59],"56":121,"57":[1,122],"58":[1,123]},{"4":[1,125],"6":124,"29":[1,6]},{"8":126,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":128,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":129,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":130,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":131,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,187],"4":[2,187],"29":[2,187],"30":[2,187],"47":[2,187],"55":[2,187],"59":[2,187],"75":[2,187],"80":[2,187],"90":[2,187],"94":[2,187],"96":[2,187],"105":[2,187],"107":[2,187],"108":[2,187],"109":[2,187],"113":[2,187],"121":[2,187],"124":[1,132],"130":[2,187],"131":[2,187],"133":[2,187],"134":[2,187],"135":[2,187],"136":[2,187],"137":[2,187],"138":[2,187],"139":[2,187],"140":[2,187],"141":[2,187],"142":[2,187],"144":[2,187]},{"4":[1,125],"6":133,"29":[1,6]},{"4":[1,125],"6":134,"29":[1,6]},{"1":[2,153],"4":[2,153],"29":[2,153],"30":[2,153],"47":[2,153],"55":[2,153],"59":[2,153],"75":[2,153],"80":[2,153],"90":[2,153],"94":[2,153],"96":[2,153],"105":[2,153],"107":[2,153],"108":[2,153],"109":[2,153],"113":[2,153],"121":[2,153],"130":[2,153],"131":[2,153],"133":[2,153],"134":[2,153],"135":[2,153],"136":[2,153],"137":[2,153],"138":[2,153],"139":[2,153],"140":[2,153],"141":[2,153],"142":[2,153],"144":[2,153]},{"4":[1,125],"6":135,"29":[1,6]},{"8":136,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,137],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,71],"4":[2,71],"29":[2,71],"30":[2,71],"41":[2,71],"47":[2,71],"55":[2,71],"59":[2,71],"68":[2,71],"69":[2,71],"70":[2,71],"71":[2,71],"74":[2,71],"75":[2,71],"76":[2,71],"77":[2,71],"80":[2,71],"82":[1,138],"88":[2,71],"89":[2,71],"90":[2,71],"94":[2,71],"96":[2,71],"105":[2,71],"107":[2,71],"108":[2,71],"109":[2,71],"113":[2,71],"121":[2,71],"130":[2,71],"131":[2,71],"133":[2,71],"134":[2,71],"135":[2,71],"136":[2,71],"137":[2,71],"138":[2,71],"139":[2,71],"140":[2,71],"141":[2,71],"142":[2,71],"143":[2,71],"144":[2,71]},{"1":[2,99],"4":[2,99],"15":142,"16":143,"29":[1,140],"30":[2,99],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":144,"43":72,"47":[2,99],"55":[2,99],"58":[1,61],"59":[2,99],"61":139,"63":52,"64":53,"65":30,"66":31,"67":32,"75":[2,99],"78":[1,73],"80":[2,99],"82":[1,141],"87":[1,33],"90":[2,99],"92":[1,60],"94":[2,99],"95":[1,59],"96":[2,99],"104":[1,58],"105":[2,99],"107":[2,99],"108":[2,99],"109":[2,99],"113":[2,99],"121":[2,99],"130":[2,99],"131":[2,99],"133":[2,99],"134":[2,99],"135":[2,99],"136":[2,99],"137":[2,99],"138":[2,99],"139":[2,99],"140":[2,99],"141":[2,99],"142":[2,99],"144":[2,99]},{"1":[2,51],"4":[2,51],"29":[2,51],"30":[2,51],"47":[2,51],"55":[2,51],"59":[2,51],"75":[2,51],"80":[2,51],"90":[2,51],"94":[2,51],"96":[2,51],"101":[2,51],"102":[2,51],"105":[2,51],"107":[2,51],"108":[2,51],"109":[2,51],"113":[2,51],"121":[2,51],"124":[2,51],"126":[2,51],"130":[2,51],"131":[2,51],"133":[2,51],"134":[2,51],"135":[2,51],"136":[2,51],"137":[2,51],"138":[2,51],"139":[2,51],"140":[2,51],"141":[2,51],"142":[2,51],"144":[2,51]},{"1":[2,50],"4":[2,50],"8":145,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"30":[2,50],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"105":[2,50],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"130":[2,50],"131":[2,50],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":146,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,72],"4":[2,72],"29":[2,72],"30":[2,72],"41":[2,72],"47":[2,72],"55":[2,72],"59":[2,72],"68":[2,72],"69":[2,72],"70":[2,72],"71":[2,72],"74":[2,72],"75":[2,72],"76":[2,72],"77":[2,72],"80":[2,72],"88":[2,72],"89":[2,72],"90":[2,72],"94":[2,72],"96":[2,72],"105":[2,72],"107":[2,72],"108":[2,72],"109":[2,72],"113":[2,72],"121":[2,72],"130":[2,72],"131":[2,72],"133":[2,72],"134":[2,72],"135":[2,72],"136":[2,72],"137":[2,72],"138":[2,72],"139":[2,72],"140":[2,72],"141":[2,72],"142":[2,72],"143":[2,72],"144":[2,72]},{"1":[2,73],"4":[2,73],"29":[2,73],"30":[2,73],"41":[2,73],"47":[2,73],"55":[2,73],"59":[2,73],"68":[2,73],"69":[2,73],"70":[2,73],"71":[2,73],"74":[2,73],"75":[2,73],"76":[2,73],"77":[2,73],"80":[2,73],"88":[2,73],"89":[2,73],"90":[2,73],"94":[2,73],"96":[2,73],"105":[2,73],"107":[2,73],"108":[2,73],"109":[2,73],"113":[2,73],"121":[2,73],"130":[2,73],"131":[2,73],"133":[2,73],"134":[2,73],"135":[2,73],"136":[2,73],"137":[2,73],"138":[2,73],"139":[2,73],"140":[2,73],"141":[2,73],"142":[2,73],"143":[2,73],"144":[2,73]},{"1":[2,35],"4":[2,35],"29":[2,35],"30":[2,35],"47":[2,35],"55":[2,35],"59":[2,35],"68":[2,35],"69":[2,35],"70":[2,35],"71":[2,35],"74":[2,35],"75":[2,35],"76":[2,35],"77":[2,35],"80":[2,35],"88":[2,35],"89":[2,35],"90":[2,35],"94":[2,35],"96":[2,35],"105":[2,35],"107":[2,35],"108":[2,35],"109":[2,35],"113":[2,35],"121":[2,35],"130":[2,35],"131":[2,35],"133":[2,35],"134":[2,35],"135":[2,35],"136":[2,35],"137":[2,35],"138":[2,35],"139":[2,35],"140":[2,35],"141":[2,35],"142":[2,35],"143":[2,35],"144":[2,35]},{"1":[2,36],"4":[2,36],"29":[2,36],"30":[2,36],"47":[2,36],"55":[2,36],"59":[2,36],"68":[2,36],"69":[2,36],"70":[2,36],"71":[2,36],"74":[2,36],"75":[2,36],"76":[2,36],"77":[2,36],"80":[2,36],"88":[2,36],"89":[2,36],"90":[2,36],"94":[2,36],"96":[2,36],"105":[2,36],"107":[2,36],"108":[2,36],"109":[2,36],"113":[2,36],"121":[2,36],"130":[2,36],"131":[2,36],"133":[2,36],"134":[2,36],"135":[2,36],"136":[2,36],"137":[2,36],"138":[2,36],"139":[2,36],"140":[2,36],"141":[2,36],"142":[2,36],"143":[2,36],"144":[2,36]},{"1":[2,37],"4":[2,37],"29":[2,37],"30":[2,37],"47":[2,37],"55":[2,37],"59":[2,37],"68":[2,37],"69":[2,37],"70":[2,37],"71":[2,37],"74":[2,37],"75":[2,37],"76":[2,37],"77":[2,37],"80":[2,37],"88":[2,37],"89":[2,37],"90":[2,37],"94":[2,37],"96":[2,37],"105":[2,37],"107":[2,37],"108":[2,37],"109":[2,37],"113":[2,37],"121":[2,37],"130":[2,37],"131":[2,37],"133":[2,37],"134":[2,37],"135":[2,37],"136":[2,37],"137":[2,37],"138":[2,37],"139":[2,37],"140":[2,37],"141":[2,37],"142":[2,37],"143":[2,37],"144":[2,37]},{"1":[2,38],"4":[2,38],"29":[2,38],"30":[2,38],"47":[2,38],"55":[2,38],"59":[2,38],"68":[2,38],"69":[2,38],"70":[2,38],"71":[2,38],"74":[2,38],"75":[2,38],"76":[2,38],"77":[2,38],"80":[2,38],"88":[2,38],"89":[2,38],"90":[2,38],"94":[2,38],"96":[2,38],"105":[2,38],"107":[2,38],"108":[2,38],"109":[2,38],"113":[2,38],"121":[2,38],"130":[2,38],"131":[2,38],"133":[2,38],"134":[2,38],"135":[2,38],"136":[2,38],"137":[2,38],"138":[2,38],"139":[2,38],"140":[2,38],"141":[2,38],"142":[2,38],"143":[2,38],"144":[2,38]},{"7":147,"8":7,"9":8,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"105":[1,148],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":149,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"91":151,"92":[1,60],"95":[1,59],"96":[1,150],"97":152,"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,118],"4":[2,118],"29":[2,118],"30":[2,118],"47":[2,118],"55":[2,118],"59":[2,118],"68":[2,118],"69":[2,118],"70":[2,118],"71":[2,118],"74":[2,118],"75":[2,118],"76":[2,118],"77":[2,118],"80":[2,118],"88":[2,118],"89":[2,118],"90":[2,118],"94":[2,118],"96":[2,118],"105":[2,118],"107":[2,118],"108":[2,118],"109":[2,118],"113":[2,118],"121":[2,118],"130":[2,118],"131":[2,118],"133":[2,118],"134":[2,118],"135":[2,118],"136":[2,118],"137":[2,118],"138":[2,118],"139":[2,118],"140":[2,118],"141":[2,118],"142":[2,118],"143":[2,118],"144":[2,118]},{"1":[2,119],"4":[2,119],"29":[2,119],"30":[2,119],"31":155,"32":[1,76],"47":[2,119],"55":[2,119],"59":[2,119],"68":[2,119],"69":[2,119],"70":[2,119],"71":[2,119],"74":[2,119],"75":[2,119],"76":[2,119],"77":[2,119],"80":[2,119],"88":[2,119],"89":[2,119],"90":[2,119],"94":[2,119],"96":[2,119],"105":[2,119],"107":[2,119],"108":[2,119],"109":[2,119],"113":[2,119],"121":[2,119],"130":[2,119],"131":[2,119],"133":[2,119],"134":[2,119],"135":[2,119],"136":[2,119],"137":[2,119],"138":[2,119],"139":[2,119],"140":[2,119],"141":[2,119],"142":[2,119],"143":[2,119],"144":[2,119]},{"4":[2,55],"29":[2,55]},{"4":[2,56],"29":[2,56]},{"8":156,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":157,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":158,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":159,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[1,125],"6":160,"8":161,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,6],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"31":166,"32":[1,76],"63":167,"64":168,"66":162,"78":[1,73],"95":[1,59],"116":163,"117":[1,164],"118":165},{"115":169,"119":[1,170],"120":[1,171]},{"1":[2,67],"4":[2,67],"29":[2,67],"30":[2,67],"41":[2,67],"47":[2,67],"55":[2,67],"59":[2,67],"68":[2,67],"69":[2,67],"70":[2,67],"71":[2,67],"74":[2,67],"75":[2,67],"76":[2,67],"77":[2,67],"80":[2,67],"82":[2,67],"88":[2,67],"89":[2,67],"90":[2,67],"94":[2,67],"96":[2,67],"105":[2,67],"107":[2,67],"108":[2,67],"109":[2,67],"113":[2,67],"121":[2,67],"130":[2,67],"131":[2,67],"133":[2,67],"134":[2,67],"135":[2,67],"136":[2,67],"137":[2,67],"138":[2,67],"139":[2,67],"140":[2,67],"141":[2,67],"142":[2,67],"143":[2,67],"144":[2,67]},{"1":[2,70],"4":[2,70],"29":[2,70],"30":[2,70],"41":[2,70],"47":[2,70],"55":[2,70],"59":[2,70],"68":[2,70],"69":[2,70],"70":[2,70],"71":[2,70],"74":[2,70],"75":[2,70],"76":[2,70],"77":[2,70],"80":[2,70],"82":[2,70],"88":[2,70],"89":[2,70],"90":[2,70],"94":[2,70],"96":[2,70],"105":[2,70],"107":[2,70],"108":[2,70],"109":[2,70],"113":[2,70],"121":[2,70],"130":[2,70],"131":[2,70],"133":[2,70],"134":[2,70],"135":[2,70],"136":[2,70],"137":[2,70],"138":[2,70],"139":[2,70],"140":[2,70],"141":[2,70],"142":[2,70],"143":[2,70],"144":[2,70]},{"4":[2,89],"28":177,"29":[2,89],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":173,"43":176,"46":[1,49],"55":[2,89],"58":[1,178],"79":172,"80":[2,89]},{"1":[2,33],"4":[2,33],"29":[2,33],"30":[2,33],"44":[2,33],"47":[2,33],"55":[2,33],"59":[2,33],"68":[2,33],"69":[2,33],"70":[2,33],"71":[2,33],"74":[2,33],"75":[2,33],"76":[2,33],"77":[2,33],"80":[2,33],"88":[2,33],"89":[2,33],"90":[2,33],"94":[2,33],"96":[2,33],"105":[2,33],"107":[2,33],"108":[2,33],"109":[2,33],"113":[2,33],"121":[2,33],"130":[2,33],"131":[2,33],"133":[2,33],"134":[2,33],"135":[2,33],"136":[2,33],"137":[2,33],"138":[2,33],"139":[2,33],"140":[2,33],"141":[2,33],"142":[2,33],"143":[2,33],"144":[2,33]},{"1":[2,34],"4":[2,34],"29":[2,34],"30":[2,34],"44":[2,34],"47":[2,34],"55":[2,34],"59":[2,34],"68":[2,34],"69":[2,34],"70":[2,34],"71":[2,34],"74":[2,34],"75":[2,34],"76":[2,34],"77":[2,34],"80":[2,34],"88":[2,34],"89":[2,34],"90":[2,34],"94":[2,34],"96":[2,34],"105":[2,34],"107":[2,34],"108":[2,34],"109":[2,34],"113":[2,34],"121":[2,34],"130":[2,34],"131":[2,34],"133":[2,34],"134":[2,34],"135":[2,34],"136":[2,34],"137":[2,34],"138":[2,34],"139":[2,34],"140":[2,34],"141":[2,34],"142":[2,34],"143":[2,34],"144":[2,34]},{"1":[2,32],"4":[2,32],"29":[2,32],"30":[2,32],"41":[2,32],"44":[2,32],"47":[2,32],"55":[2,32],"59":[2,32],"68":[2,32],"69":[2,32],"70":[2,32],"71":[2,32],"74":[2,32],"75":[2,32],"76":[2,32],"77":[2,32],"80":[2,32],"82":[2,32],"88":[2,32],"89":[2,32],"90":[2,32],"94":[2,32],"96":[2,32],"105":[2,32],"107":[2,32],"108":[2,32],"109":[2,32],"113":[2,32],"119":[2,32],"120":[2,32],"121":[2,32],"130":[2,32],"131":[2,32],"133":[2,32],"134":[2,32],"135":[2,32],"136":[2,32],"137":[2,32],"138":[2,32],"139":[2,32],"140":[2,32],"141":[2,32],"142":[2,32],"143":[2,32],"144":[2,32]},{"1":[2,31],"4":[2,31],"29":[2,31],"30":[2,31],"47":[2,31],"55":[2,31],"59":[2,31],"75":[2,31],"80":[2,31],"90":[2,31],"94":[2,31],"96":[2,31],"101":[2,31],"102":[2,31],"105":[2,31],"107":[2,31],"108":[2,31],"109":[2,31],"113":[2,31],"121":[2,31],"124":[2,31],"126":[2,31],"130":[2,31],"131":[2,31],"133":[2,31],"134":[2,31],"135":[2,31],"136":[2,31],"137":[2,31],"138":[2,31],"139":[2,31],"140":[2,31],"141":[2,31],"142":[2,31],"144":[2,31]},{"1":[2,7],"4":[2,7],"7":179,"8":7,"9":8,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"30":[2,7],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,4]},{"4":[1,78],"30":[1,180]},{"1":[2,30],"4":[2,30],"29":[2,30],"30":[2,30],"47":[2,30],"55":[2,30],"59":[2,30],"75":[2,30],"80":[2,30],"90":[2,30],"94":[2,30],"96":[2,30],"101":[2,30],"102":[2,30],"105":[2,30],"107":[2,30],"108":[2,30],"109":[2,30],"113":[2,30],"121":[2,30],"124":[2,30],"126":[2,30],"130":[2,30],"131":[2,30],"133":[2,30],"134":[2,30],"135":[2,30],"136":[2,30],"137":[2,30],"138":[2,30],"139":[2,30],"140":[2,30],"141":[2,30],"142":[2,30],"144":[2,30]},{"1":[2,197],"4":[2,197],"29":[2,197],"30":[2,197],"47":[2,197],"55":[2,197],"59":[2,197],"75":[2,197],"80":[2,197],"90":[2,197],"94":[2,197],"96":[2,197],"105":[2,197],"107":[2,197],"108":[2,197],"109":[2,197],"113":[2,197],"121":[2,197],"130":[2,197],"131":[2,197],"133":[2,197],"134":[2,197],"135":[2,197],"136":[2,197],"137":[2,197],"138":[2,197],"139":[2,197],"140":[2,197],"141":[2,197],"142":[2,197],"144":[2,197]},{"1":[2,198],"4":[2,198],"29":[2,198],"30":[2,198],"47":[2,198],"55":[2,198],"59":[2,198],"75":[2,198],"80":[2,198],"90":[2,198],"94":[2,198],"96":[2,198],"105":[2,198],"107":[2,198],"108":[2,198],"109":[2,198],"113":[2,198],"121":[2,198],"130":[2,198],"131":[2,198],"133":[2,198],"134":[2,198],"135":[2,198],"136":[2,198],"137":[2,198],"138":[2,198],"139":[2,198],"140":[2,198],"141":[2,198],"142":[2,198],"144":[2,198]},{"8":181,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":182,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":183,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":184,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":185,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":186,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":187,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":188,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":189,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":190,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":191,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,152],"4":[2,152],"29":[2,152],"30":[2,152],"47":[2,152],"55":[2,152],"59":[2,152],"75":[2,152],"80":[2,152],"90":[2,152],"94":[2,152],"96":[2,152],"105":[2,152],"107":[2,152],"108":[2,152],"109":[2,152],"113":[2,152],"121":[2,152],"130":[2,152],"131":[2,152],"133":[2,152],"134":[2,152],"135":[2,152],"136":[2,152],"137":[2,152],"138":[2,152],"139":[2,152],"140":[2,152],"141":[2,152],"142":[2,152],"144":[2,152]},{"1":[2,157],"4":[2,157],"29":[2,157],"30":[2,157],"47":[2,157],"55":[2,157],"59":[2,157],"75":[2,157],"80":[2,157],"90":[2,157],"94":[2,157],"96":[2,157],"105":[2,157],"107":[2,157],"108":[2,157],"109":[2,157],"113":[2,157],"121":[2,157],"130":[2,157],"131":[2,157],"133":[2,157],"134":[2,157],"135":[2,157],"136":[2,157],"137":[2,157],"138":[2,157],"139":[2,157],"140":[2,157],"141":[2,157],"142":[2,157],"144":[2,157]},{"1":[2,52],"4":[2,52],"29":[2,52],"30":[2,52],"47":[2,52],"55":[2,52],"59":[2,52],"75":[2,52],"80":[2,52],"90":[2,52],"94":[2,52],"96":[2,52],"105":[2,52],"107":[2,52],"108":[2,52],"109":[2,52],"113":[2,52],"121":[2,52],"130":[2,52],"131":[2,52],"133":[2,52],"134":[2,52],"135":[2,52],"136":[2,52],"137":[2,52],"138":[2,52],"139":[2,52],"140":[2,52],"141":[2,52],"142":[2,52],"144":[2,52]},{"8":192,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":193,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,151],"4":[2,151],"29":[2,151],"30":[2,151],"47":[2,151],"55":[2,151],"59":[2,151],"75":[2,151],"80":[2,151],"90":[2,151],"94":[2,151],"96":[2,151],"105":[2,151],"107":[2,151],"108":[2,151],"109":[2,151],"113":[2,151],"121":[2,151],"130":[2,151],"131":[2,151],"133":[2,151],"134":[2,151],"135":[2,151],"136":[2,151],"137":[2,151],"138":[2,151],"139":[2,151],"140":[2,151],"141":[2,151],"142":[2,151],"144":[2,151]},{"1":[2,156],"4":[2,156],"29":[2,156],"30":[2,156],"47":[2,156],"55":[2,156],"59":[2,156],"75":[2,156],"80":[2,156],"90":[2,156],"94":[2,156],"96":[2,156],"105":[2,156],"107":[2,156],"108":[2,156],"109":[2,156],"113":[2,156],"121":[2,156],"130":[2,156],"131":[2,156],"133":[2,156],"134":[2,156],"135":[2,156],"136":[2,156],"137":[2,156],"138":[2,156],"139":[2,156],"140":[2,156],"141":[2,156],"142":[2,156],"144":[2,156]},{"86":194,"89":[1,119]},{"8":195,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,196],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,68],"4":[2,68],"29":[2,68],"30":[2,68],"41":[2,68],"47":[2,68],"55":[2,68],"59":[2,68],"68":[2,68],"69":[2,68],"70":[2,68],"71":[2,68],"74":[2,68],"75":[2,68],"76":[2,68],"77":[2,68],"80":[2,68],"82":[2,68],"88":[2,68],"89":[2,68],"90":[2,68],"94":[2,68],"96":[2,68],"105":[2,68],"107":[2,68],"108":[2,68],"109":[2,68],"113":[2,68],"121":[2,68],"130":[2,68],"131":[2,68],"133":[2,68],"134":[2,68],"135":[2,68],"136":[2,68],"137":[2,68],"138":[2,68],"139":[2,68],"140":[2,68],"141":[2,68],"142":[2,68],"143":[2,68],"144":[2,68]},{"89":[2,115]},{"31":197,"32":[1,76]},{"31":198,"32":[1,76]},{"1":[2,81],"4":[2,81],"29":[2,81],"30":[2,81],"41":[2,81],"47":[2,81],"55":[2,81],"59":[2,81],"68":[2,81],"69":[2,81],"70":[2,81],"71":[2,81],"74":[2,81],"75":[2,81],"76":[2,81],"77":[2,81],"80":[2,81],"82":[2,81],"88":[2,81],"89":[2,81],"90":[2,81],"94":[2,81],"96":[2,81],"105":[2,81],"107":[2,81],"108":[2,81],"109":[2,81],"113":[2,81],"121":[2,81],"130":[2,81],"131":[2,81],"133":[2,81],"134":[2,81],"135":[2,81],"136":[2,81],"137":[2,81],"138":[2,81],"139":[2,81],"140":[2,81],"141":[2,81],"142":[2,81],"143":[2,81],"144":[2,81]},{"31":199,"32":[1,76]},{"1":[2,83],"4":[2,83],"29":[2,83],"30":[2,83],"41":[2,83],"47":[2,83],"55":[2,83],"59":[2,83],"68":[2,83],"69":[2,83],"70":[2,83],"71":[2,83],"74":[2,83],"75":[2,83],"76":[2,83],"77":[2,83],"80":[2,83],"82":[2,83],"88":[2,83],"89":[2,83],"90":[2,83],"94":[2,83],"96":[2,83],"105":[2,83],"107":[2,83],"108":[2,83],"109":[2,83],"113":[2,83],"121":[2,83],"130":[2,83],"131":[2,83],"133":[2,83],"134":[2,83],"135":[2,83],"136":[2,83],"137":[2,83],"138":[2,83],"139":[2,83],"140":[2,83],"141":[2,83],"142":[2,83],"143":[2,83],"144":[2,83]},{"1":[2,84],"4":[2,84],"29":[2,84],"30":[2,84],"41":[2,84],"47":[2,84],"55":[2,84],"59":[2,84],"68":[2,84],"69":[2,84],"70":[2,84],"71":[2,84],"74":[2,84],"75":[2,84],"76":[2,84],"77":[2,84],"80":[2,84],"82":[2,84],"88":[2,84],"89":[2,84],"90":[2,84],"94":[2,84],"96":[2,84],"105":[2,84],"107":[2,84],"108":[2,84],"109":[2,84],"113":[2,84],"121":[2,84],"130":[2,84],"131":[2,84],"133":[2,84],"134":[2,84],"135":[2,84],"136":[2,84],"137":[2,84],"138":[2,84],"139":[2,84],"140":[2,84],"141":[2,84],"142":[2,84],"143":[2,84],"144":[2,84]},{"8":200,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"59":[1,203],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"93":201,"94":[1,202],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"72":204,"74":[1,205],"76":[1,113],"77":[1,114]},{"72":206,"74":[1,205],"76":[1,113],"77":[1,114]},{"86":207,"89":[1,119]},{"1":[2,69],"4":[2,69],"29":[2,69],"30":[2,69],"41":[2,69],"47":[2,69],"55":[2,69],"59":[2,69],"68":[2,69],"69":[2,69],"70":[2,69],"71":[2,69],"74":[2,69],"75":[2,69],"76":[2,69],"77":[2,69],"80":[2,69],"82":[2,69],"88":[2,69],"89":[2,69],"90":[2,69],"94":[2,69],"96":[2,69],"105":[2,69],"107":[2,69],"108":[2,69],"109":[2,69],"113":[2,69],"121":[2,69],"130":[2,69],"131":[2,69],"133":[2,69],"134":[2,69],"135":[2,69],"136":[2,69],"137":[2,69],"138":[2,69],"139":[2,69],"140":[2,69],"141":[2,69],"142":[2,69],"143":[2,69],"144":[2,69]},{"8":208,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,209],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,113],"4":[2,113],"29":[2,113],"30":[2,113],"47":[2,113],"55":[2,113],"59":[2,113],"68":[2,113],"69":[2,113],"70":[2,113],"71":[2,113],"74":[2,113],"75":[2,113],"76":[2,113],"77":[2,113],"80":[2,113],"88":[2,113],"89":[2,113],"90":[2,113],"94":[2,113],"96":[2,113],"105":[2,113],"107":[2,113],"108":[2,113],"109":[2,113],"113":[2,113],"121":[2,113],"130":[2,113],"131":[2,113],"133":[2,113],"134":[2,113],"135":[2,113],"136":[2,113],"137":[2,113],"138":[2,113],"139":[2,113],"140":[2,113],"141":[2,113],"142":[2,113],"144":[2,113]},{"8":212,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"90":[1,210],"91":211,"92":[1,60],"95":[1,59],"97":152,"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"50":[1,213],"55":[1,214]},{"50":[2,60],"55":[2,60]},{"50":[2,62],"55":[2,62],"59":[1,215]},{"57":[1,216]},{"1":[2,54],"4":[2,54],"29":[2,54],"30":[2,54],"47":[2,54],"55":[2,54],"59":[2,54],"75":[2,54],"80":[2,54],"90":[2,54],"94":[2,54],"96":[2,54],"105":[2,54],"107":[2,54],"108":[2,54],"109":[2,54],"113":[2,54],"121":[2,54],"130":[2,54],"131":[2,54],"133":[2,54],"134":[2,54],"135":[2,54],"136":[2,54],"137":[2,54],"138":[2,54],"139":[2,54],"140":[2,54],"141":[2,54],"142":[2,54],"144":[2,54]},{"28":77,"46":[1,49]},{"1":[2,192],"4":[2,192],"29":[2,192],"30":[2,192],"47":[1,97],"55":[2,192],"59":[2,192],"75":[2,192],"80":[2,192],"90":[2,192],"94":[2,192],"96":[2,192],"105":[2,192],"106":95,"107":[2,192],"108":[2,192],"109":[2,192],"112":96,"113":[2,192],"114":70,"121":[2,192],"130":[2,192],"131":[2,192],"133":[2,192],"134":[2,192],"135":[1,82],"136":[1,83],"137":[2,192],"138":[2,192],"139":[2,192],"140":[2,192],"141":[2,192],"142":[2,192],"144":[2,192]},{"106":100,"107":[1,66],"109":[1,67],"112":101,"113":[1,69],"114":70,"130":[1,98],"131":[1,99]},{"1":[2,193],"4":[2,193],"29":[2,193],"30":[2,193],"47":[1,97],"55":[2,193],"59":[2,193],"75":[2,193],"80":[2,193],"90":[2,193],"94":[2,193],"96":[2,193],"105":[2,193],"106":95,"107":[2,193],"108":[2,193],"109":[2,193],"112":96,"113":[2,193],"114":70,"121":[2,193],"130":[2,193],"131":[2,193],"133":[2,193],"134":[2,193],"135":[1,82],"136":[1,83],"137":[2,193],"138":[2,193],"139":[2,193],"140":[2,193],"141":[2,193],"142":[2,193],"144":[2,193]},{"1":[2,194],"4":[2,194],"29":[2,194],"30":[2,194],"47":[1,97],"55":[2,194],"59":[2,194],"75":[2,194],"80":[2,194],"90":[2,194],"94":[2,194],"96":[2,194],"105":[2,194],"106":95,"107":[2,194],"108":[2,194],"109":[2,194],"112":96,"113":[2,194],"114":70,"121":[2,194],"130":[2,194],"131":[2,194],"133":[2,194],"134":[2,194],"135":[1,82],"136":[1,83],"137":[2,194],"138":[2,194],"139":[2,194],"140":[2,194],"141":[2,194],"142":[2,194],"144":[2,194]},{"1":[2,195],"4":[2,195],"29":[2,195],"30":[2,195],"47":[2,195],"55":[2,195],"59":[2,195],"75":[2,195],"80":[2,195],"90":[2,195],"94":[2,195],"96":[2,195],"105":[2,195],"106":95,"107":[2,195],"108":[2,195],"109":[2,195],"112":96,"113":[2,195],"114":70,"121":[2,195],"130":[2,195],"131":[2,195],"133":[2,195],"134":[2,195],"137":[2,195],"138":[2,195],"139":[2,195],"140":[2,195],"141":[2,195],"142":[2,195],"144":[2,195]},{"1":[2,196],"4":[2,196],"29":[2,196],"30":[2,196],"47":[2,196],"55":[2,196],"59":[2,196],"75":[2,196],"80":[2,196],"90":[2,196],"94":[2,196],"96":[2,196],"105":[2,196],"106":95,"107":[2,196],"108":[2,196],"109":[2,196],"112":96,"113":[2,196],"114":70,"121":[2,196],"130":[2,196],"131":[2,196],"133":[2,196],"134":[2,196],"137":[2,196],"138":[2,196],"139":[2,196],"140":[2,196],"141":[2,196],"142":[2,196],"144":[2,196]},{"4":[1,125],"6":218,"29":[1,6],"128":[1,217]},{"1":[2,138],"4":[2,138],"29":[2,138],"30":[2,138],"47":[2,138],"55":[2,138],"59":[2,138],"75":[2,138],"80":[2,138],"90":[2,138],"94":[2,138],"96":[2,138],"100":219,"101":[1,220],"102":[1,221],"105":[2,138],"107":[2,138],"108":[2,138],"109":[2,138],"113":[2,138],"121":[2,138],"130":[2,138],"131":[2,138],"133":[2,138],"134":[2,138],"135":[2,138],"136":[2,138],"137":[2,138],"138":[2,138],"139":[2,138],"140":[2,138],"141":[2,138],"142":[2,138],"144":[2,138]},{"1":[2,150],"4":[2,150],"29":[2,150],"30":[2,150],"47":[2,150],"55":[2,150],"59":[2,150],"75":[2,150],"80":[2,150],"90":[2,150],"94":[2,150],"96":[2,150],"105":[2,150],"107":[2,150],"108":[2,150],"109":[2,150],"113":[2,150],"121":[2,150],"130":[2,150],"131":[2,150],"133":[2,150],"134":[2,150],"135":[2,150],"136":[2,150],"137":[2,150],"138":[2,150],"139":[2,150],"140":[2,150],"141":[2,150],"142":[2,150],"144":[2,150]},{"1":[2,158],"4":[2,158],"29":[2,158],"30":[2,158],"47":[2,158],"55":[2,158],"59":[2,158],"75":[2,158],"80":[2,158],"90":[2,158],"94":[2,158],"96":[2,158],"105":[2,158],"107":[2,158],"108":[2,158],"109":[2,158],"113":[2,158],"121":[2,158],"130":[2,158],"131":[2,158],"133":[2,158],"134":[2,158],"135":[2,158],"136":[2,158],"137":[2,158],"138":[2,158],"139":[2,158],"140":[2,158],"141":[2,158],"142":[2,158],"144":[2,158]},{"29":[1,222],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"123":223,"125":224,"126":[1,225]},{"15":226,"16":143,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":144,"43":72,"58":[1,61],"61":227,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"87":[1,33],"92":[1,60],"95":[1,59],"104":[1,58]},{"1":[2,94],"4":[2,94],"29":[1,229],"30":[2,94],"47":[2,94],"55":[2,94],"59":[2,94],"68":[2,71],"69":[2,71],"70":[2,71],"71":[2,71],"74":[2,71],"75":[2,94],"76":[2,71],"77":[2,71],"80":[2,94],"82":[1,228],"88":[2,71],"89":[2,71],"90":[2,94],"94":[2,94],"96":[2,94],"105":[2,94],"107":[2,94],"108":[2,94],"109":[2,94],"113":[2,94],"121":[2,94],"130":[2,94],"131":[2,94],"133":[2,94],"134":[2,94],"135":[2,94],"136":[2,94],"137":[2,94],"138":[2,94],"139":[2,94],"140":[2,94],"141":[2,94],"142":[2,94],"144":[2,94]},{"4":[2,105],"28":177,"30":[2,105],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"83":230,"84":231},{"15":235,"16":143,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":144,"43":72,"58":[1,61],"61":227,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"87":[1,33],"92":[1,60],"95":[1,59],"104":[1,58]},{"62":104,"68":[1,106],"69":[1,107],"70":[1,108],"71":[1,109],"72":110,"73":111,"74":[1,112],"76":[1,113],"77":[1,114],"85":102,"88":[1,105],"89":[2,114]},{"62":116,"68":[1,106],"69":[1,107],"70":[1,108],"71":[1,109],"72":110,"73":111,"74":[1,112],"76":[1,113],"77":[1,114],"85":115,"88":[1,105],"89":[2,114]},{"1":[2,74],"4":[2,74],"29":[2,74],"30":[2,74],"47":[2,74],"55":[2,74],"59":[2,74],"68":[2,74],"69":[2,74],"70":[2,74],"71":[2,74],"74":[2,74],"75":[2,74],"76":[2,74],"77":[2,74],"80":[2,74],"88":[2,74],"89":[2,74],"90":[2,74],"94":[2,74],"96":[2,74],"105":[2,74],"107":[2,74],"108":[2,74],"109":[2,74],"113":[2,74],"121":[2,74],"130":[2,74],"131":[2,74],"133":[2,74],"134":[2,74],"135":[2,74],"136":[2,74],"137":[2,74],"138":[2,74],"139":[2,74],"140":[2,74],"141":[2,74],"142":[2,74],"144":[2,74]},{"1":[2,49],"4":[2,49],"30":[2,49],"47":[1,97],"105":[2,49],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[2,49],"131":[2,49],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,143],"4":[2,143],"30":[2,143],"47":[1,97],"105":[2,143],"106":95,"107":[2,143],"109":[2,143],"112":96,"113":[2,143],"114":70,"130":[2,143],"131":[2,143],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"105":[1,236]},{"1":[2,145],"4":[2,145],"29":[2,145],"30":[2,145],"47":[2,145],"55":[2,145],"59":[2,145],"68":[2,145],"69":[2,145],"70":[2,145],"71":[2,145],"74":[2,145],"75":[2,145],"76":[2,145],"77":[2,145],"80":[2,145],"88":[2,145],"89":[2,145],"90":[2,145],"94":[2,145],"96":[2,145],"105":[2,145],"107":[2,145],"108":[2,145],"109":[2,145],"113":[2,145],"121":[2,145],"130":[2,145],"131":[2,145],"133":[2,145],"134":[2,145],"135":[2,145],"136":[2,145],"137":[2,145],"138":[2,145],"139":[2,145],"140":[2,145],"141":[2,145],"142":[2,145],"143":[2,145],"144":[2,145]},{"4":[2,134],"29":[2,134],"47":[1,97],"55":[2,134],"59":[1,238],"93":237,"94":[1,202],"96":[2,134],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,127],"4":[2,127],"29":[2,127],"30":[2,127],"41":[2,127],"47":[2,127],"55":[2,127],"59":[2,127],"68":[2,127],"69":[2,127],"70":[2,127],"71":[2,127],"74":[2,127],"75":[2,127],"76":[2,127],"77":[2,127],"80":[2,127],"88":[2,127],"89":[2,127],"90":[2,127],"94":[2,127],"96":[2,127],"105":[2,127],"107":[2,127],"108":[2,127],"109":[2,127],"113":[2,127],"119":[2,127],"120":[2,127],"121":[2,127],"130":[2,127],"131":[2,127],"133":[2,127],"134":[2,127],"135":[2,127],"136":[2,127],"137":[2,127],"138":[2,127],"139":[2,127],"140":[2,127],"141":[2,127],"142":[2,127],"143":[2,127],"144":[2,127]},{"4":[2,57],"29":[2,57],"54":239,"55":[1,240],"96":[2,57]},{"4":[2,129],"29":[2,129],"30":[2,129],"55":[2,129],"90":[2,129],"96":[2,129]},{"8":212,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"91":241,"92":[1,60],"95":[1,59],"97":152,"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,135],"29":[2,135],"30":[2,135],"55":[2,135],"90":[2,135],"96":[2,135]},{"1":[2,122],"4":[2,122],"29":[2,122],"30":[2,122],"41":[2,122],"44":[2,122],"47":[2,122],"55":[2,122],"59":[2,122],"68":[2,122],"69":[2,122],"70":[2,122],"71":[2,122],"74":[2,122],"75":[2,122],"76":[2,122],"77":[2,122],"80":[2,122],"82":[2,122],"88":[2,122],"89":[2,122],"90":[2,122],"94":[2,122],"96":[2,122],"105":[2,122],"107":[2,122],"108":[2,122],"109":[2,122],"113":[2,122],"121":[2,122],"130":[2,122],"131":[2,122],"133":[2,122],"134":[2,122],"135":[2,122],"136":[2,122],"137":[2,122],"138":[2,122],"139":[2,122],"140":[2,122],"141":[2,122],"142":[2,122],"143":[2,122],"144":[2,122]},{"4":[1,125],"6":242,"29":[1,6],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"4":[1,125],"6":243,"29":[1,6],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,146],"4":[2,146],"29":[2,146],"30":[2,146],"47":[1,97],"55":[2,146],"59":[2,146],"75":[2,146],"80":[2,146],"90":[2,146],"94":[2,146],"96":[2,146],"105":[2,146],"106":95,"107":[1,66],"108":[1,244],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,146],"130":[2,146],"131":[2,146],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,148],"4":[2,148],"29":[2,148],"30":[2,148],"47":[1,97],"55":[2,148],"59":[2,148],"75":[2,148],"80":[2,148],"90":[2,148],"94":[2,148],"96":[2,148],"105":[2,148],"106":95,"107":[1,66],"108":[1,245],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,148],"130":[2,148],"131":[2,148],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,154],"4":[2,154],"29":[2,154],"30":[2,154],"47":[2,154],"55":[2,154],"59":[2,154],"75":[2,154],"80":[2,154],"90":[2,154],"94":[2,154],"96":[2,154],"105":[2,154],"107":[2,154],"108":[2,154],"109":[2,154],"113":[2,154],"121":[2,154],"130":[2,154],"131":[2,154],"133":[2,154],"134":[2,154],"135":[2,154],"136":[2,154],"137":[2,154],"138":[2,154],"139":[2,154],"140":[2,154],"141":[2,154],"142":[2,154],"144":[2,154]},{"1":[2,155],"4":[2,155],"29":[2,155],"30":[2,155],"47":[1,97],"55":[2,155],"59":[2,155],"75":[2,155],"80":[2,155],"90":[2,155],"94":[2,155],"96":[2,155],"105":[2,155],"106":95,"107":[1,66],"108":[2,155],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,155],"130":[2,155],"131":[2,155],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,159],"4":[2,159],"29":[2,159],"30":[2,159],"47":[2,159],"55":[2,159],"59":[2,159],"75":[2,159],"80":[2,159],"90":[2,159],"94":[2,159],"96":[2,159],"105":[2,159],"107":[2,159],"108":[2,159],"109":[2,159],"113":[2,159],"121":[2,159],"130":[2,159],"131":[2,159],"133":[2,159],"134":[2,159],"135":[2,159],"136":[2,159],"137":[2,159],"138":[2,159],"139":[2,159],"140":[2,159],"141":[2,159],"142":[2,159],"144":[2,159]},{"119":[2,161],"120":[2,161]},{"31":166,"32":[1,76],"63":167,"64":168,"78":[1,73],"95":[1,247],"116":246,"118":165},{"55":[1,248],"119":[2,166],"120":[2,166]},{"55":[2,163],"119":[2,163],"120":[2,163]},{"55":[2,164],"119":[2,164],"120":[2,164]},{"55":[2,165],"119":[2,165],"120":[2,165]},{"1":[2,160],"4":[2,160],"29":[2,160],"30":[2,160],"47":[2,160],"55":[2,160],"59":[2,160],"75":[2,160],"80":[2,160],"90":[2,160],"94":[2,160],"96":[2,160],"105":[2,160],"107":[2,160],"108":[2,160],"109":[2,160],"113":[2,160],"121":[2,160],"130":[2,160],"131":[2,160],"133":[2,160],"134":[2,160],"135":[2,160],"136":[2,160],"137":[2,160],"138":[2,160],"139":[2,160],"140":[2,160],"141":[2,160],"142":[2,160],"144":[2,160]},{"8":249,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":250,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,57],"29":[2,57],"54":251,"55":[1,252],"80":[2,57]},{"4":[2,90],"29":[2,90],"30":[2,90],"55":[2,90],"80":[2,90]},{"4":[2,41],"29":[2,41],"30":[2,41],"44":[1,253],"55":[2,41],"80":[2,41]},{"4":[2,42],"29":[2,42],"30":[2,42],"44":[1,254],"55":[2,42],"80":[2,42]},{"4":[2,43],"29":[2,43],"30":[2,43],"55":[2,43],"80":[2,43]},{"4":[2,48],"29":[2,48],"30":[2,48],"55":[2,48],"80":[2,48]},{"31":155,"32":[1,76]},{"1":[2,6],"4":[2,6],"30":[2,6]},{"1":[2,29],"4":[2,29],"29":[2,29],"30":[2,29],"47":[2,29],"55":[2,29],"59":[2,29],"75":[2,29],"80":[2,29],"90":[2,29],"94":[2,29],"96":[2,29],"101":[2,29],"102":[2,29],"105":[2,29],"107":[2,29],"108":[2,29],"109":[2,29],"113":[2,29],"121":[2,29],"124":[2,29],"126":[2,29],"130":[2,29],"131":[2,29],"133":[2,29],"134":[2,29],"135":[2,29],"136":[2,29],"137":[2,29],"138":[2,29],"139":[2,29],"140":[2,29],"141":[2,29],"142":[2,29],"144":[2,29]},{"1":[2,199],"4":[2,199],"29":[2,199],"30":[2,199],"47":[1,97],"55":[2,199],"59":[2,199],"75":[2,199],"80":[2,199],"90":[2,199],"94":[2,199],"96":[2,199],"105":[2,199],"106":95,"107":[2,199],"108":[2,199],"109":[2,199],"112":96,"113":[2,199],"114":70,"121":[2,199],"130":[2,199],"131":[2,199],"133":[2,199],"134":[2,199],"135":[1,82],"136":[1,83],"137":[2,199],"138":[2,199],"139":[1,88],"140":[2,199],"141":[2,199],"142":[2,199],"144":[2,199]},{"1":[2,200],"4":[2,200],"29":[2,200],"30":[2,200],"47":[1,97],"55":[2,200],"59":[2,200],"75":[2,200],"80":[2,200],"90":[2,200],"94":[2,200],"96":[2,200],"105":[2,200],"106":95,"107":[2,200],"108":[2,200],"109":[2,200],"112":96,"113":[2,200],"114":70,"121":[2,200],"130":[2,200],"131":[2,200],"133":[2,200],"134":[2,200],"135":[1,82],"136":[1,83],"137":[2,200],"138":[2,200],"139":[1,88],"140":[2,200],"141":[2,200],"142":[2,200],"144":[2,200]},{"1":[2,201],"4":[2,201],"29":[2,201],"30":[2,201],"47":[1,97],"55":[2,201],"59":[2,201],"75":[2,201],"80":[2,201],"90":[2,201],"94":[2,201],"96":[2,201],"105":[2,201],"106":95,"107":[2,201],"108":[2,201],"109":[2,201],"112":96,"113":[2,201],"114":70,"121":[2,201],"130":[2,201],"131":[2,201],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[2,201],"138":[2,201],"139":[1,88],"140":[1,89],"141":[1,90],"142":[2,201],"144":[1,92]},{"1":[2,202],"4":[2,202],"29":[2,202],"30":[2,202],"47":[1,97],"55":[2,202],"59":[2,202],"75":[2,202],"80":[2,202],"90":[2,202],"94":[2,202],"96":[2,202],"105":[2,202],"106":95,"107":[2,202],"108":[2,202],"109":[2,202],"112":96,"113":[2,202],"114":70,"121":[2,202],"130":[2,202],"131":[2,202],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[2,202],"138":[2,202],"139":[1,88],"140":[1,89],"141":[1,90],"142":[2,202],"144":[1,92]},{"1":[2,203],"4":[2,203],"29":[2,203],"30":[2,203],"47":[1,97],"55":[2,203],"59":[2,203],"75":[2,203],"80":[2,203],"90":[2,203],"94":[2,203],"96":[2,203],"105":[2,203],"106":95,"107":[2,203],"108":[2,203],"109":[2,203],"112":96,"113":[2,203],"114":70,"121":[2,203],"130":[2,203],"131":[2,203],"133":[2,203],"134":[2,203],"135":[1,82],"136":[1,83],"137":[2,203],"138":[2,203],"139":[2,203],"140":[2,203],"141":[2,203],"142":[2,203],"144":[2,203]},{"1":[2,204],"4":[2,204],"29":[2,204],"30":[2,204],"47":[1,97],"55":[2,204],"59":[2,204],"75":[2,204],"80":[2,204],"90":[2,204],"94":[2,204],"96":[2,204],"105":[2,204],"106":95,"107":[2,204],"108":[2,204],"109":[2,204],"112":96,"113":[2,204],"114":70,"121":[2,204],"130":[2,204],"131":[2,204],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[2,204],"138":[2,204],"139":[1,88],"140":[2,204],"141":[2,204],"142":[2,204],"144":[2,204]},{"1":[2,205],"4":[2,205],"29":[2,205],"30":[2,205],"47":[1,97],"55":[2,205],"59":[2,205],"75":[2,205],"80":[2,205],"90":[2,205],"94":[2,205],"96":[2,205],"105":[2,205],"106":95,"107":[2,205],"108":[2,205],"109":[2,205],"112":96,"113":[2,205],"114":70,"121":[2,205],"130":[2,205],"131":[2,205],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[2,205],"138":[2,205],"139":[1,88],"140":[1,89],"141":[2,205],"142":[2,205],"144":[2,205]},{"1":[2,206],"4":[2,206],"29":[2,206],"30":[2,206],"47":[1,97],"55":[2,206],"59":[2,206],"75":[2,206],"80":[2,206],"90":[2,206],"94":[2,206],"96":[2,206],"105":[2,206],"106":95,"107":[2,206],"108":[2,206],"109":[2,206],"112":96,"113":[2,206],"114":70,"121":[2,206],"130":[2,206],"131":[2,206],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[2,206],"144":[1,92]},{"1":[2,209],"4":[2,209],"29":[2,209],"30":[2,209],"47":[1,97],"55":[2,209],"59":[2,209],"75":[2,209],"80":[2,209],"90":[2,209],"94":[2,209],"96":[2,209],"105":[2,209],"106":95,"107":[2,209],"108":[2,209],"109":[2,209],"112":96,"113":[2,209],"114":70,"121":[2,209],"130":[2,209],"131":[2,209],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[2,209],"138":[2,209],"139":[1,88],"140":[1,89],"141":[1,90],"142":[2,209],"144":[2,209]},{"1":[2,189],"4":[2,189],"29":[2,189],"30":[2,189],"47":[1,97],"55":[2,189],"59":[2,189],"75":[2,189],"80":[2,189],"90":[2,189],"94":[2,189],"96":[2,189],"105":[2,189],"106":95,"107":[1,66],"108":[2,189],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,189],"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,191],"4":[2,191],"29":[2,191],"30":[2,191],"47":[1,97],"55":[2,191],"59":[2,191],"75":[2,191],"80":[2,191],"90":[2,191],"94":[2,191],"96":[2,191],"105":[2,191],"106":95,"107":[1,66],"108":[2,191],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,191],"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,188],"4":[2,188],"29":[2,188],"30":[2,188],"47":[1,97],"55":[2,188],"59":[2,188],"75":[2,188],"80":[2,188],"90":[2,188],"94":[2,188],"96":[2,188],"105":[2,188],"106":95,"107":[1,66],"108":[2,188],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,188],"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,190],"4":[2,190],"29":[2,190],"30":[2,190],"47":[1,97],"55":[2,190],"59":[2,190],"75":[2,190],"80":[2,190],"90":[2,190],"94":[2,190],"96":[2,190],"105":[2,190],"106":95,"107":[1,66],"108":[2,190],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,190],"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,110],"4":[2,110],"29":[2,110],"30":[2,110],"47":[2,110],"55":[2,110],"59":[2,110],"68":[2,110],"69":[2,110],"70":[2,110],"71":[2,110],"74":[2,110],"75":[2,110],"76":[2,110],"77":[2,110],"80":[2,110],"88":[2,110],"89":[2,110],"90":[2,110],"94":[2,110],"96":[2,110],"105":[2,110],"107":[2,110],"108":[2,110],"109":[2,110],"113":[2,110],"121":[2,110],"130":[2,110],"131":[2,110],"133":[2,110],"134":[2,110],"135":[2,110],"136":[2,110],"137":[2,110],"138":[2,110],"139":[2,110],"140":[2,110],"141":[2,110],"142":[2,110],"144":[2,110]},{"1":[2,207],"4":[2,207],"29":[2,207],"30":[2,207],"47":[1,97],"55":[2,207],"59":[2,207],"75":[2,207],"80":[2,207],"90":[2,207],"94":[2,207],"96":[2,207],"105":[2,207],"106":95,"107":[2,207],"108":[2,207],"109":[2,207],"112":96,"113":[2,207],"114":70,"121":[2,207],"130":[2,207],"131":[2,207],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"8":255,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,79],"4":[2,79],"29":[2,79],"30":[2,79],"41":[2,79],"47":[2,79],"55":[2,79],"59":[2,79],"68":[2,79],"69":[2,79],"70":[2,79],"71":[2,79],"74":[2,79],"75":[2,79],"76":[2,79],"77":[2,79],"80":[2,79],"82":[2,79],"88":[2,79],"89":[2,79],"90":[2,79],"94":[2,79],"96":[2,79],"105":[2,79],"107":[2,79],"108":[2,79],"109":[2,79],"113":[2,79],"121":[2,79],"130":[2,79],"131":[2,79],"133":[2,79],"134":[2,79],"135":[2,79],"136":[2,79],"137":[2,79],"138":[2,79],"139":[2,79],"140":[2,79],"141":[2,79],"142":[2,79],"143":[2,79],"144":[2,79]},{"1":[2,80],"4":[2,80],"29":[2,80],"30":[2,80],"41":[2,80],"47":[2,80],"55":[2,80],"59":[2,80],"68":[2,80],"69":[2,80],"70":[2,80],"71":[2,80],"74":[2,80],"75":[2,80],"76":[2,80],"77":[2,80],"80":[2,80],"82":[2,80],"88":[2,80],"89":[2,80],"90":[2,80],"94":[2,80],"96":[2,80],"105":[2,80],"107":[2,80],"108":[2,80],"109":[2,80],"113":[2,80],"121":[2,80],"130":[2,80],"131":[2,80],"133":[2,80],"134":[2,80],"135":[2,80],"136":[2,80],"137":[2,80],"138":[2,80],"139":[2,80],"140":[2,80],"141":[2,80],"142":[2,80],"143":[2,80],"144":[2,80]},{"1":[2,82],"4":[2,82],"29":[2,82],"30":[2,82],"41":[2,82],"47":[2,82],"55":[2,82],"59":[2,82],"68":[2,82],"69":[2,82],"70":[2,82],"71":[2,82],"74":[2,82],"75":[2,82],"76":[2,82],"77":[2,82],"80":[2,82],"82":[2,82],"88":[2,82],"89":[2,82],"90":[2,82],"94":[2,82],"96":[2,82],"105":[2,82],"107":[2,82],"108":[2,82],"109":[2,82],"113":[2,82],"121":[2,82],"130":[2,82],"131":[2,82],"133":[2,82],"134":[2,82],"135":[2,82],"136":[2,82],"137":[2,82],"138":[2,82],"139":[2,82],"140":[2,82],"141":[2,82],"142":[2,82],"143":[2,82],"144":[2,82]},{"47":[1,97],"59":[1,203],"75":[1,256],"93":257,"94":[1,202],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"8":258,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"12":[2,120],"13":[2,120],"14":[2,120],"32":[2,120],"34":[2,120],"35":[2,120],"37":[2,120],"38":[2,120],"39":[2,120],"45":[2,120],"46":[2,120],"48":[2,120],"52":[2,120],"53":[2,120],"58":[2,120],"75":[2,120],"78":[2,120],"81":[2,120],"87":[2,120],"92":[2,120],"95":[2,120],"99":[2,120],"103":[2,120],"104":[2,120],"107":[2,120],"109":[2,120],"111":[2,120],"113":[2,120],"122":[2,120],"128":[2,120],"129":[2,120],"132":[2,120],"133":[2,120],"134":[2,120],"135":[2,120],"136":[2,120]},{"12":[2,121],"13":[2,121],"14":[2,121],"32":[2,121],"34":[2,121],"35":[2,121],"37":[2,121],"38":[2,121],"39":[2,121],"45":[2,121],"46":[2,121],"48":[2,121],"52":[2,121],"53":[2,121],"58":[2,121],"75":[2,121],"78":[2,121],"81":[2,121],"87":[2,121],"92":[2,121],"95":[2,121],"99":[2,121],"103":[2,121],"104":[2,121],"107":[2,121],"109":[2,121],"111":[2,121],"113":[2,121],"122":[2,121],"128":[2,121],"129":[2,121],"132":[2,121],"133":[2,121],"134":[2,121],"135":[2,121],"136":[2,121]},{"1":[2,86],"4":[2,86],"29":[2,86],"30":[2,86],"41":[2,86],"47":[2,86],"55":[2,86],"59":[2,86],"68":[2,86],"69":[2,86],"70":[2,86],"71":[2,86],"74":[2,86],"75":[2,86],"76":[2,86],"77":[2,86],"80":[2,86],"82":[2,86],"88":[2,86],"89":[2,86],"90":[2,86],"94":[2,86],"96":[2,86],"105":[2,86],"107":[2,86],"108":[2,86],"109":[2,86],"113":[2,86],"121":[2,86],"130":[2,86],"131":[2,86],"133":[2,86],"134":[2,86],"135":[2,86],"136":[2,86],"137":[2,86],"138":[2,86],"139":[2,86],"140":[2,86],"141":[2,86],"142":[2,86],"143":[2,86],"144":[2,86]},{"8":259,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,87],"4":[2,87],"29":[2,87],"30":[2,87],"41":[2,87],"47":[2,87],"55":[2,87],"59":[2,87],"68":[2,87],"69":[2,87],"70":[2,87],"71":[2,87],"74":[2,87],"75":[2,87],"76":[2,87],"77":[2,87],"80":[2,87],"82":[2,87],"88":[2,87],"89":[2,87],"90":[2,87],"94":[2,87],"96":[2,87],"105":[2,87],"107":[2,87],"108":[2,87],"109":[2,87],"113":[2,87],"121":[2,87],"130":[2,87],"131":[2,87],"133":[2,87],"134":[2,87],"135":[2,87],"136":[2,87],"137":[2,87],"138":[2,87],"139":[2,87],"140":[2,87],"141":[2,87],"142":[2,87],"143":[2,87],"144":[2,87]},{"1":[2,111],"4":[2,111],"29":[2,111],"30":[2,111],"47":[2,111],"55":[2,111],"59":[2,111],"68":[2,111],"69":[2,111],"70":[2,111],"71":[2,111],"74":[2,111],"75":[2,111],"76":[2,111],"77":[2,111],"80":[2,111],"88":[2,111],"89":[2,111],"90":[2,111],"94":[2,111],"96":[2,111],"105":[2,111],"107":[2,111],"108":[2,111],"109":[2,111],"113":[2,111],"121":[2,111],"130":[2,111],"131":[2,111],"133":[2,111],"134":[2,111],"135":[2,111],"136":[2,111],"137":[2,111],"138":[2,111],"139":[2,111],"140":[2,111],"141":[2,111],"142":[2,111],"144":[2,111]},{"1":[2,39],"4":[2,39],"29":[2,39],"30":[2,39],"47":[1,97],"55":[2,39],"59":[2,39],"75":[2,39],"80":[2,39],"90":[2,39],"94":[2,39],"96":[2,39],"105":[2,39],"106":95,"107":[1,66],"108":[2,39],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,39],"130":[2,39],"131":[2,39],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"8":260,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,116],"4":[2,116],"29":[2,116],"30":[2,116],"47":[2,116],"55":[2,116],"59":[2,116],"68":[2,116],"69":[2,116],"70":[2,116],"71":[2,116],"74":[2,116],"75":[2,116],"76":[2,116],"77":[2,116],"80":[2,116],"88":[2,116],"89":[2,116],"90":[2,116],"94":[2,116],"96":[2,116],"105":[2,116],"107":[2,116],"108":[2,116],"109":[2,116],"113":[2,116],"121":[2,116],"130":[2,116],"131":[2,116],"133":[2,116],"134":[2,116],"135":[2,116],"136":[2,116],"137":[2,116],"138":[2,116],"139":[2,116],"140":[2,116],"141":[2,116],"142":[2,116],"144":[2,116]},{"4":[2,57],"29":[2,57],"54":261,"55":[1,240],"90":[2,57]},{"4":[2,134],"29":[2,134],"30":[2,134],"47":[1,97],"55":[2,134],"59":[1,262],"90":[2,134],"96":[2,134],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"51":263,"52":[1,62],"53":[1,63]},{"56":264,"57":[1,122],"58":[1,123]},{"50":[2,64],"55":[2,64]},{"50":[2,63],"55":[2,63],"59":[1,265]},{"8":266,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,186],"4":[2,186],"29":[2,186],"30":[2,186],"47":[2,186],"55":[2,186],"59":[2,186],"75":[2,186],"80":[2,186],"90":[2,186],"94":[2,186],"96":[2,186],"105":[2,186],"107":[2,186],"108":[2,186],"109":[2,186],"113":[2,186],"121":[2,186],"124":[2,186],"130":[2,186],"131":[2,186],"133":[2,186],"134":[2,186],"135":[2,186],"136":[2,186],"137":[2,186],"138":[2,186],"139":[2,186],"140":[2,186],"141":[2,186],"142":[2,186],"144":[2,186]},{"1":[2,139],"4":[2,139],"29":[2,139],"30":[2,139],"47":[2,139],"55":[2,139],"59":[2,139],"75":[2,139],"80":[2,139],"90":[2,139],"94":[2,139],"96":[2,139],"101":[1,267],"105":[2,139],"107":[2,139],"108":[2,139],"109":[2,139],"113":[2,139],"121":[2,139],"130":[2,139],"131":[2,139],"133":[2,139],"134":[2,139],"135":[2,139],"136":[2,139],"137":[2,139],"138":[2,139],"139":[2,139],"140":[2,139],"141":[2,139],"142":[2,139],"144":[2,139]},{"4":[1,125],"6":268,"29":[1,6]},{"31":269,"32":[1,76]},{"123":270,"125":224,"126":[1,225]},{"30":[1,271],"124":[1,272],"125":273,"126":[1,225]},{"30":[2,179],"124":[2,179],"126":[2,179]},{"8":275,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"98":274,"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,109],"4":[2,109],"29":[2,109],"30":[2,109],"47":[2,109],"55":[2,109],"59":[2,109],"62":104,"68":[1,106],"69":[1,107],"70":[1,108],"71":[1,109],"72":110,"73":111,"74":[1,112],"75":[2,109],"76":[1,113],"77":[1,114],"80":[2,109],"85":102,"88":[1,105],"89":[2,114],"90":[2,109],"94":[2,109],"96":[2,109],"105":[2,109],"107":[2,109],"108":[2,109],"109":[2,109],"113":[2,109],"121":[2,109],"130":[2,109],"131":[2,109],"133":[2,109],"134":[2,109],"135":[2,109],"136":[2,109],"137":[2,109],"138":[2,109],"139":[2,109],"140":[2,109],"141":[2,109],"142":[2,109],"144":[2,109]},{"1":[2,71],"4":[2,71],"29":[2,71],"30":[2,71],"47":[2,71],"55":[2,71],"59":[2,71],"68":[2,71],"69":[2,71],"70":[2,71],"71":[2,71],"74":[2,71],"75":[2,71],"76":[2,71],"77":[2,71],"80":[2,71],"88":[2,71],"89":[2,71],"90":[2,71],"94":[2,71],"96":[2,71],"105":[2,71],"107":[2,71],"108":[2,71],"109":[2,71],"113":[2,71],"121":[2,71],"130":[2,71],"131":[2,71],"133":[2,71],"134":[2,71],"135":[2,71],"136":[2,71],"137":[2,71],"138":[2,71],"139":[2,71],"140":[2,71],"141":[2,71],"142":[2,71],"144":[2,71]},{"15":276,"16":143,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":144,"43":72,"58":[1,61],"61":227,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"87":[1,33],"92":[1,60],"95":[1,59],"104":[1,58]},{"4":[2,105],"28":177,"30":[2,105],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"83":277,"84":231},{"4":[1,279],"30":[1,278]},{"4":[2,106],"30":[2,106],"80":[2,106]},{"4":[2,105],"28":177,"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"80":[2,105],"83":280,"84":231},{"4":[2,102],"30":[2,102],"80":[2,102]},{"4":[2,43],"30":[2,43],"44":[1,281],"80":[2,43]},{"1":[2,100],"4":[2,100],"29":[1,282],"30":[2,100],"47":[2,100],"55":[2,100],"59":[2,100],"62":104,"68":[1,106],"69":[1,107],"70":[1,108],"71":[1,109],"72":110,"73":111,"74":[1,112],"75":[2,100],"76":[1,113],"77":[1,114],"80":[2,100],"85":102,"88":[1,105],"89":[2,114],"90":[2,100],"94":[2,100],"96":[2,100],"105":[2,100],"107":[2,100],"108":[2,100],"109":[2,100],"113":[2,100],"121":[2,100],"130":[2,100],"131":[2,100],"133":[2,100],"134":[2,100],"135":[2,100],"136":[2,100],"137":[2,100],"138":[2,100],"139":[2,100],"140":[2,100],"141":[2,100],"142":[2,100],"144":[2,100]},{"1":[2,144],"4":[2,144],"29":[2,144],"30":[2,144],"47":[2,144],"55":[2,144],"59":[2,144],"68":[2,144],"69":[2,144],"70":[2,144],"71":[2,144],"74":[2,144],"75":[2,144],"76":[2,144],"77":[2,144],"80":[2,144],"88":[2,144],"89":[2,144],"90":[2,144],"94":[2,144],"96":[2,144],"105":[2,144],"107":[2,144],"108":[2,144],"109":[2,144],"113":[2,144],"121":[2,144],"130":[2,144],"131":[2,144],"133":[2,144],"134":[2,144],"135":[2,144],"136":[2,144],"137":[2,144],"138":[2,144],"139":[2,144],"140":[2,144],"141":[2,144],"142":[2,144],"143":[2,144],"144":[2,144]},{"8":283,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,66],"12":[2,121],"13":[2,121],"14":[2,121],"29":[2,66],"32":[2,121],"34":[2,121],"35":[2,121],"37":[2,121],"38":[2,121],"39":[2,121],"45":[2,121],"46":[2,121],"48":[2,121],"52":[2,121],"53":[2,121],"55":[2,66],"58":[2,121],"78":[2,121],"81":[2,121],"87":[2,121],"92":[2,121],"95":[2,121],"96":[2,66],"99":[2,121],"103":[2,121],"104":[2,121],"107":[2,121],"109":[2,121],"111":[2,121],"113":[2,121],"122":[2,121],"128":[2,121],"129":[2,121],"132":[2,121],"133":[2,121],"134":[2,121],"135":[2,121],"136":[2,121]},{"4":[1,285],"29":[1,286],"96":[1,284]},{"4":[2,58],"8":212,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[2,58],"30":[2,58],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"90":[2,58],"92":[1,60],"95":[1,59],"96":[2,58],"97":287,"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,57],"29":[2,57],"30":[2,57],"54":288,"55":[1,240]},{"1":[2,183],"4":[2,183],"29":[2,183],"30":[2,183],"47":[2,183],"55":[2,183],"59":[2,183],"75":[2,183],"80":[2,183],"90":[2,183],"94":[2,183],"96":[2,183],"105":[2,183],"107":[2,183],"108":[2,183],"109":[2,183],"113":[2,183],"121":[2,183],"124":[2,183],"130":[2,183],"131":[2,183],"133":[2,183],"134":[2,183],"135":[2,183],"136":[2,183],"137":[2,183],"138":[2,183],"139":[2,183],"140":[2,183],"141":[2,183],"142":[2,183],"144":[2,183]},{"1":[2,184],"4":[2,184],"29":[2,184],"30":[2,184],"47":[2,184],"55":[2,184],"59":[2,184],"75":[2,184],"80":[2,184],"90":[2,184],"94":[2,184],"96":[2,184],"105":[2,184],"107":[2,184],"108":[2,184],"109":[2,184],"113":[2,184],"121":[2,184],"124":[2,184],"130":[2,184],"131":[2,184],"133":[2,184],"134":[2,184],"135":[2,184],"136":[2,184],"137":[2,184],"138":[2,184],"139":[2,184],"140":[2,184],"141":[2,184],"142":[2,184],"144":[2,184]},{"8":289,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":290,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"119":[2,162],"120":[2,162]},{"8":212,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"91":151,"92":[1,60],"95":[1,59],"96":[1,150],"97":152,"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"31":166,"32":[1,76],"63":167,"64":168,"78":[1,73],"95":[1,247],"118":291},{"1":[2,168],"4":[2,168],"29":[2,168],"30":[2,168],"47":[1,97],"55":[2,168],"59":[2,168],"75":[2,168],"80":[2,168],"90":[2,168],"94":[2,168],"96":[2,168],"105":[2,168],"106":95,"107":[2,168],"108":[1,292],"109":[2,168],"112":96,"113":[2,168],"114":70,"121":[1,293],"130":[2,168],"131":[2,168],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,169],"4":[2,169],"29":[2,169],"30":[2,169],"47":[1,97],"55":[2,169],"59":[2,169],"75":[2,169],"80":[2,169],"90":[2,169],"94":[2,169],"96":[2,169],"105":[2,169],"106":95,"107":[2,169],"108":[1,294],"109":[2,169],"112":96,"113":[2,169],"114":70,"121":[2,169],"130":[2,169],"131":[2,169],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"4":[1,296],"29":[1,297],"80":[1,295]},{"4":[2,58],"28":177,"29":[2,58],"30":[2,58],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":298,"43":176,"46":[1,49],"58":[1,178],"80":[2,58]},{"8":299,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,300],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":301,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,302],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"30":[1,303],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,85],"4":[2,85],"29":[2,85],"30":[2,85],"41":[2,85],"47":[2,85],"55":[2,85],"59":[2,85],"68":[2,85],"69":[2,85],"70":[2,85],"71":[2,85],"74":[2,85],"75":[2,85],"76":[2,85],"77":[2,85],"80":[2,85],"82":[2,85],"88":[2,85],"89":[2,85],"90":[2,85],"94":[2,85],"96":[2,85],"105":[2,85],"107":[2,85],"108":[2,85],"109":[2,85],"113":[2,85],"121":[2,85],"130":[2,85],"131":[2,85],"133":[2,85],"134":[2,85],"135":[2,85],"136":[2,85],"137":[2,85],"138":[2,85],"139":[2,85],"140":[2,85],"141":[2,85],"142":[2,85],"143":[2,85],"144":[2,85]},{"8":304,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"75":[1,305],"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"47":[1,97],"75":[1,306],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"47":[1,97],"75":[1,256],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"30":[1,307],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"4":[1,285],"29":[1,286],"90":[1,308]},{"4":[2,66],"29":[2,66],"30":[2,66],"55":[2,66],"90":[2,66],"96":[2,66]},{"4":[1,125],"6":309,"29":[1,6]},{"50":[2,61],"55":[2,61]},{"50":[2,65],"55":[2,65]},{"4":[1,125],"6":310,"29":[1,6],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"4":[1,125],"6":311,"29":[1,6]},{"1":[2,140],"4":[2,140],"29":[2,140],"30":[2,140],"47":[2,140],"55":[2,140],"59":[2,140],"75":[2,140],"80":[2,140],"90":[2,140],"94":[2,140],"96":[2,140],"105":[2,140],"107":[2,140],"108":[2,140],"109":[2,140],"113":[2,140],"121":[2,140],"130":[2,140],"131":[2,140],"133":[2,140],"134":[2,140],"135":[2,140],"136":[2,140],"137":[2,140],"138":[2,140],"139":[2,140],"140":[2,140],"141":[2,140],"142":[2,140],"144":[2,140]},{"4":[1,125],"6":312,"29":[1,6]},{"30":[1,313],"124":[1,314],"125":273,"126":[1,225]},{"1":[2,177],"4":[2,177],"29":[2,177],"30":[2,177],"47":[2,177],"55":[2,177],"59":[2,177],"75":[2,177],"80":[2,177],"90":[2,177],"94":[2,177],"96":[2,177],"105":[2,177],"107":[2,177],"108":[2,177],"109":[2,177],"113":[2,177],"121":[2,177],"130":[2,177],"131":[2,177],"133":[2,177],"134":[2,177],"135":[2,177],"136":[2,177],"137":[2,177],"138":[2,177],"139":[2,177],"140":[2,177],"141":[2,177],"142":[2,177],"144":[2,177]},{"4":[1,125],"6":315,"29":[1,6]},{"30":[2,180],"124":[2,180],"126":[2,180]},{"4":[1,125],"6":316,"29":[1,6],"55":[1,317]},{"4":[2,136],"29":[2,136],"47":[1,97],"55":[2,136],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,95],"4":[2,95],"29":[1,318],"30":[2,95],"47":[2,95],"55":[2,95],"59":[2,95],"62":104,"68":[1,106],"69":[1,107],"70":[1,108],"71":[1,109],"72":110,"73":111,"74":[1,112],"75":[2,95],"76":[1,113],"77":[1,114],"80":[2,95],"85":102,"88":[1,105],"89":[2,114],"90":[2,95],"94":[2,95],"96":[2,95],"105":[2,95],"107":[2,95],"108":[2,95],"109":[2,95],"113":[2,95],"121":[2,95],"130":[2,95],"131":[2,95],"133":[2,95],"134":[2,95],"135":[2,95],"136":[2,95],"137":[2,95],"138":[2,95],"139":[2,95],"140":[2,95],"141":[2,95],"142":[2,95],"144":[2,95]},{"4":[1,279],"30":[1,319]},{"1":[2,98],"4":[2,98],"29":[2,98],"30":[2,98],"47":[2,98],"55":[2,98],"59":[2,98],"75":[2,98],"80":[2,98],"90":[2,98],"94":[2,98],"96":[2,98],"105":[2,98],"107":[2,98],"108":[2,98],"109":[2,98],"113":[2,98],"121":[2,98],"130":[2,98],"131":[2,98],"133":[2,98],"134":[2,98],"135":[2,98],"136":[2,98],"137":[2,98],"138":[2,98],"139":[2,98],"140":[2,98],"141":[2,98],"142":[2,98],"144":[2,98]},{"28":177,"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"84":320},{"4":[1,279],"80":[1,321]},{"8":322,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,323],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,105],"28":177,"30":[2,105],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"83":324,"84":231},{"47":[1,97],"96":[1,325],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,128],"4":[2,128],"29":[2,128],"30":[2,128],"41":[2,128],"47":[2,128],"55":[2,128],"59":[2,128],"68":[2,128],"69":[2,128],"70":[2,128],"71":[2,128],"74":[2,128],"75":[2,128],"76":[2,128],"77":[2,128],"80":[2,128],"88":[2,128],"89":[2,128],"90":[2,128],"94":[2,128],"96":[2,128],"105":[2,128],"107":[2,128],"108":[2,128],"109":[2,128],"113":[2,128],"119":[2,128],"120":[2,128],"121":[2,128],"130":[2,128],"131":[2,128],"133":[2,128],"134":[2,128],"135":[2,128],"136":[2,128],"137":[2,128],"138":[2,128],"139":[2,128],"140":[2,128],"141":[2,128],"142":[2,128],"143":[2,128],"144":[2,128]},{"8":212,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"97":326,"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":212,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"91":327,"92":[1,60],"95":[1,59],"97":152,"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,130],"29":[2,130],"30":[2,130],"55":[2,130],"90":[2,130],"96":[2,130]},{"4":[1,285],"29":[1,286],"30":[1,328]},{"1":[2,147],"4":[2,147],"29":[2,147],"30":[2,147],"47":[1,97],"55":[2,147],"59":[2,147],"75":[2,147],"80":[2,147],"90":[2,147],"94":[2,147],"96":[2,147],"105":[2,147],"106":95,"107":[1,66],"108":[2,147],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,147],"130":[2,147],"131":[2,147],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,149],"4":[2,149],"29":[2,149],"30":[2,149],"47":[1,97],"55":[2,149],"59":[2,149],"75":[2,149],"80":[2,149],"90":[2,149],"94":[2,149],"96":[2,149],"105":[2,149],"106":95,"107":[1,66],"108":[2,149],"109":[1,67],"112":96,"113":[1,69],"114":70,"121":[2,149],"130":[2,149],"131":[2,149],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"119":[2,167],"120":[2,167]},{"8":329,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":330,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":331,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,88],"4":[2,88],"29":[2,88],"30":[2,88],"41":[2,88],"47":[2,88],"55":[2,88],"59":[2,88],"68":[2,88],"69":[2,88],"70":[2,88],"71":[2,88],"74":[2,88],"75":[2,88],"76":[2,88],"77":[2,88],"80":[2,88],"88":[2,88],"89":[2,88],"90":[2,88],"94":[2,88],"96":[2,88],"105":[2,88],"107":[2,88],"108":[2,88],"109":[2,88],"113":[2,88],"119":[2,88],"120":[2,88],"121":[2,88],"130":[2,88],"131":[2,88],"133":[2,88],"134":[2,88],"135":[2,88],"136":[2,88],"137":[2,88],"138":[2,88],"139":[2,88],"140":[2,88],"141":[2,88],"142":[2,88],"143":[2,88],"144":[2,88]},{"28":177,"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":332,"43":176,"46":[1,49],"58":[1,178]},{"4":[2,89],"28":177,"29":[2,89],"30":[2,89],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":173,"43":176,"46":[1,49],"55":[2,89],"58":[1,178],"79":333},{"4":[2,91],"29":[2,91],"30":[2,91],"55":[2,91],"80":[2,91]},{"4":[2,44],"29":[2,44],"30":[2,44],"47":[1,97],"55":[2,44],"80":[2,44],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"8":334,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,45],"29":[2,45],"30":[2,45],"47":[1,97],"55":[2,45],"80":[2,45],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"8":335,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,208],"4":[2,208],"29":[2,208],"30":[2,208],"47":[2,208],"55":[2,208],"59":[2,208],"75":[2,208],"80":[2,208],"90":[2,208],"94":[2,208],"96":[2,208],"105":[2,208],"107":[2,208],"108":[2,208],"109":[2,208],"113":[2,208],"121":[2,208],"130":[2,208],"131":[2,208],"133":[2,208],"134":[2,208],"135":[2,208],"136":[2,208],"137":[2,208],"138":[2,208],"139":[2,208],"140":[2,208],"141":[2,208],"142":[2,208],"144":[2,208]},{"47":[1,97],"75":[1,336],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,125],"4":[2,125],"29":[2,125],"30":[2,125],"41":[2,125],"47":[2,125],"55":[2,125],"59":[2,125],"68":[2,125],"69":[2,125],"70":[2,125],"71":[2,125],"74":[2,125],"75":[2,125],"76":[2,125],"77":[2,125],"80":[2,125],"82":[2,125],"88":[2,125],"89":[2,125],"90":[2,125],"94":[2,125],"96":[2,125],"105":[2,125],"107":[2,125],"108":[2,125],"109":[2,125],"113":[2,125],"121":[2,125],"130":[2,125],"131":[2,125],"133":[2,125],"134":[2,125],"135":[2,125],"136":[2,125],"137":[2,125],"138":[2,125],"139":[2,125],"140":[2,125],"141":[2,125],"142":[2,125],"143":[2,125],"144":[2,125]},{"1":[2,126],"4":[2,126],"29":[2,126],"30":[2,126],"41":[2,126],"47":[2,126],"55":[2,126],"59":[2,126],"68":[2,126],"69":[2,126],"70":[2,126],"71":[2,126],"74":[2,126],"75":[2,126],"76":[2,126],"77":[2,126],"80":[2,126],"82":[2,126],"88":[2,126],"89":[2,126],"90":[2,126],"94":[2,126],"96":[2,126],"105":[2,126],"107":[2,126],"108":[2,126],"109":[2,126],"113":[2,126],"121":[2,126],"130":[2,126],"131":[2,126],"133":[2,126],"134":[2,126],"135":[2,126],"136":[2,126],"137":[2,126],"138":[2,126],"139":[2,126],"140":[2,126],"141":[2,126],"142":[2,126],"143":[2,126],"144":[2,126]},{"1":[2,40],"4":[2,40],"29":[2,40],"30":[2,40],"47":[2,40],"55":[2,40],"59":[2,40],"75":[2,40],"80":[2,40],"90":[2,40],"94":[2,40],"96":[2,40],"105":[2,40],"107":[2,40],"108":[2,40],"109":[2,40],"113":[2,40],"121":[2,40],"130":[2,40],"131":[2,40],"133":[2,40],"134":[2,40],"135":[2,40],"136":[2,40],"137":[2,40],"138":[2,40],"139":[2,40],"140":[2,40],"141":[2,40],"142":[2,40],"144":[2,40]},{"1":[2,117],"4":[2,117],"29":[2,117],"30":[2,117],"47":[2,117],"55":[2,117],"59":[2,117],"68":[2,117],"69":[2,117],"70":[2,117],"71":[2,117],"74":[2,117],"75":[2,117],"76":[2,117],"77":[2,117],"80":[2,117],"88":[2,117],"89":[2,117],"90":[2,117],"94":[2,117],"96":[2,117],"105":[2,117],"107":[2,117],"108":[2,117],"109":[2,117],"113":[2,117],"121":[2,117],"130":[2,117],"131":[2,117],"133":[2,117],"134":[2,117],"135":[2,117],"136":[2,117],"137":[2,117],"138":[2,117],"139":[2,117],"140":[2,117],"141":[2,117],"142":[2,117],"144":[2,117]},{"1":[2,53],"4":[2,53],"29":[2,53],"30":[2,53],"47":[2,53],"55":[2,53],"59":[2,53],"75":[2,53],"80":[2,53],"90":[2,53],"94":[2,53],"96":[2,53],"105":[2,53],"107":[2,53],"108":[2,53],"109":[2,53],"113":[2,53],"121":[2,53],"130":[2,53],"131":[2,53],"133":[2,53],"134":[2,53],"135":[2,53],"136":[2,53],"137":[2,53],"138":[2,53],"139":[2,53],"140":[2,53],"141":[2,53],"142":[2,53],"144":[2,53]},{"1":[2,185],"4":[2,185],"29":[2,185],"30":[2,185],"47":[2,185],"55":[2,185],"59":[2,185],"75":[2,185],"80":[2,185],"90":[2,185],"94":[2,185],"96":[2,185],"105":[2,185],"107":[2,185],"108":[2,185],"109":[2,185],"113":[2,185],"121":[2,185],"124":[2,185],"130":[2,185],"131":[2,185],"133":[2,185],"134":[2,185],"135":[2,185],"136":[2,185],"137":[2,185],"138":[2,185],"139":[2,185],"140":[2,185],"141":[2,185],"142":[2,185],"144":[2,185]},{"1":[2,141],"4":[2,141],"29":[2,141],"30":[2,141],"47":[2,141],"55":[2,141],"59":[2,141],"75":[2,141],"80":[2,141],"90":[2,141],"94":[2,141],"96":[2,141],"105":[2,141],"107":[2,141],"108":[2,141],"109":[2,141],"113":[2,141],"121":[2,141],"130":[2,141],"131":[2,141],"133":[2,141],"134":[2,141],"135":[2,141],"136":[2,141],"137":[2,141],"138":[2,141],"139":[2,141],"140":[2,141],"141":[2,141],"142":[2,141],"144":[2,141]},{"1":[2,142],"4":[2,142],"29":[2,142],"30":[2,142],"47":[2,142],"55":[2,142],"59":[2,142],"75":[2,142],"80":[2,142],"90":[2,142],"94":[2,142],"96":[2,142],"101":[2,142],"105":[2,142],"107":[2,142],"108":[2,142],"109":[2,142],"113":[2,142],"121":[2,142],"130":[2,142],"131":[2,142],"133":[2,142],"134":[2,142],"135":[2,142],"136":[2,142],"137":[2,142],"138":[2,142],"139":[2,142],"140":[2,142],"141":[2,142],"142":[2,142],"144":[2,142]},{"1":[2,175],"4":[2,175],"29":[2,175],"30":[2,175],"47":[2,175],"55":[2,175],"59":[2,175],"75":[2,175],"80":[2,175],"90":[2,175],"94":[2,175],"96":[2,175],"105":[2,175],"107":[2,175],"108":[2,175],"109":[2,175],"113":[2,175],"121":[2,175],"130":[2,175],"131":[2,175],"133":[2,175],"134":[2,175],"135":[2,175],"136":[2,175],"137":[2,175],"138":[2,175],"139":[2,175],"140":[2,175],"141":[2,175],"142":[2,175],"144":[2,175]},{"4":[1,125],"6":337,"29":[1,6]},{"30":[1,338]},{"4":[1,339],"30":[2,181],"124":[2,181],"126":[2,181]},{"8":340,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,105],"28":177,"30":[2,105],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"83":341,"84":231},{"1":[2,96],"4":[2,96],"29":[2,96],"30":[2,96],"47":[2,96],"55":[2,96],"59":[2,96],"75":[2,96],"80":[2,96],"90":[2,96],"94":[2,96],"96":[2,96],"105":[2,96],"107":[2,96],"108":[2,96],"109":[2,96],"113":[2,96],"121":[2,96],"130":[2,96],"131":[2,96],"133":[2,96],"134":[2,96],"135":[2,96],"136":[2,96],"137":[2,96],"138":[2,96],"139":[2,96],"140":[2,96],"141":[2,96],"142":[2,96],"144":[2,96]},{"4":[2,107],"30":[2,107],"80":[2,107]},{"4":[2,108],"30":[2,108],"80":[2,108]},{"4":[2,103],"30":[2,103],"47":[1,97],"80":[2,103],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"8":342,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[1,279],"30":[1,343]},{"1":[2,123],"4":[2,123],"29":[2,123],"30":[2,123],"47":[2,123],"55":[2,123],"59":[2,123],"68":[2,123],"69":[2,123],"70":[2,123],"71":[2,123],"74":[2,123],"75":[2,123],"76":[2,123],"77":[2,123],"80":[2,123],"88":[2,123],"89":[2,123],"90":[2,123],"94":[2,123],"96":[2,123],"105":[2,123],"107":[2,123],"108":[2,123],"109":[2,123],"113":[2,123],"121":[2,123],"130":[2,123],"131":[2,123],"133":[2,123],"134":[2,123],"135":[2,123],"136":[2,123],"137":[2,123],"138":[2,123],"139":[2,123],"140":[2,123],"141":[2,123],"142":[2,123],"143":[2,123],"144":[2,123]},{"4":[2,131],"29":[2,131],"30":[2,131],"55":[2,131],"90":[2,131],"96":[2,131]},{"4":[2,57],"29":[2,57],"30":[2,57],"54":344,"55":[1,240]},{"4":[2,132],"29":[2,132],"30":[2,132],"55":[2,132],"90":[2,132],"96":[2,132]},{"1":[2,170],"4":[2,170],"29":[2,170],"30":[2,170],"47":[1,97],"55":[2,170],"59":[2,170],"75":[2,170],"80":[2,170],"90":[2,170],"94":[2,170],"96":[2,170],"105":[2,170],"106":95,"107":[2,170],"108":[2,170],"109":[2,170],"112":96,"113":[2,170],"114":70,"121":[1,345],"130":[2,170],"131":[2,170],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,172],"4":[2,172],"29":[2,172],"30":[2,172],"47":[1,97],"55":[2,172],"59":[2,172],"75":[2,172],"80":[2,172],"90":[2,172],"94":[2,172],"96":[2,172],"105":[2,172],"106":95,"107":[2,172],"108":[1,346],"109":[2,172],"112":96,"113":[2,172],"114":70,"121":[2,172],"130":[2,172],"131":[2,172],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,171],"4":[2,171],"29":[2,171],"30":[2,171],"47":[1,97],"55":[2,171],"59":[2,171],"75":[2,171],"80":[2,171],"90":[2,171],"94":[2,171],"96":[2,171],"105":[2,171],"106":95,"107":[2,171],"108":[2,171],"109":[2,171],"112":96,"113":[2,171],"114":70,"121":[2,171],"130":[2,171],"131":[2,171],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"4":[2,92],"29":[2,92],"30":[2,92],"55":[2,92],"80":[2,92]},{"4":[2,57],"29":[2,57],"30":[2,57],"54":347,"55":[1,252]},{"30":[1,348],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"30":[1,349],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,124],"4":[2,124],"29":[2,124],"30":[2,124],"41":[2,124],"47":[2,124],"55":[2,124],"59":[2,124],"68":[2,124],"69":[2,124],"70":[2,124],"71":[2,124],"74":[2,124],"75":[2,124],"76":[2,124],"77":[2,124],"80":[2,124],"82":[2,124],"88":[2,124],"89":[2,124],"90":[2,124],"94":[2,124],"96":[2,124],"105":[2,124],"107":[2,124],"108":[2,124],"109":[2,124],"113":[2,124],"121":[2,124],"130":[2,124],"131":[2,124],"133":[2,124],"134":[2,124],"135":[2,124],"136":[2,124],"137":[2,124],"138":[2,124],"139":[2,124],"140":[2,124],"141":[2,124],"142":[2,124],"143":[2,124],"144":[2,124]},{"30":[1,350]},{"1":[2,178],"4":[2,178],"29":[2,178],"30":[2,178],"47":[2,178],"55":[2,178],"59":[2,178],"75":[2,178],"80":[2,178],"90":[2,178],"94":[2,178],"96":[2,178],"105":[2,178],"107":[2,178],"108":[2,178],"109":[2,178],"113":[2,178],"121":[2,178],"130":[2,178],"131":[2,178],"133":[2,178],"134":[2,178],"135":[2,178],"136":[2,178],"137":[2,178],"138":[2,178],"139":[2,178],"140":[2,178],"141":[2,178],"142":[2,178],"144":[2,178]},{"30":[2,182],"124":[2,182],"126":[2,182]},{"4":[2,137],"29":[2,137],"47":[1,97],"55":[2,137],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"4":[1,279],"30":[1,351]},{"30":[1,352],"47":[1,97],"106":95,"107":[1,66],"109":[1,67],"112":96,"113":[1,69],"114":70,"130":[1,93],"131":[1,94],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,101],"4":[2,101],"29":[2,101],"30":[2,101],"47":[2,101],"55":[2,101],"59":[2,101],"75":[2,101],"80":[2,101],"90":[2,101],"94":[2,101],"96":[2,101],"105":[2,101],"107":[2,101],"108":[2,101],"109":[2,101],"113":[2,101],"121":[2,101],"130":[2,101],"131":[2,101],"133":[2,101],"134":[2,101],"135":[2,101],"136":[2,101],"137":[2,101],"138":[2,101],"139":[2,101],"140":[2,101],"141":[2,101],"142":[2,101],"144":[2,101]},{"4":[1,285],"29":[1,286],"30":[1,353]},{"8":354,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":355,"9":127,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":71,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":72,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":47,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,42],"103":[1,51],"104":[1,58],"106":43,"107":[1,66],"109":[1,67],"110":44,"111":[1,68],"112":45,"113":[1,69],"114":70,"122":[1,46],"127":41,"128":[1,64],"129":[1,65],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[1,296],"29":[1,297],"30":[1,356]},{"4":[2,46],"29":[2,46],"30":[2,46],"55":[2,46],"80":[2,46]},{"4":[2,47],"29":[2,47],"30":[2,47],"55":[2,47],"80":[2,47]},{"1":[2,176],"4":[2,176],"29":[2,176],"30":[2,176],"47":[2,176],"55":[2,176],"59":[2,176],"75":[2,176],"80":[2,176],"90":[2,176],"94":[2,176],"96":[2,176],"105":[2,176],"107":[2,176],"108":[2,176],"109":[2,176],"113":[2,176],"121":[2,176],"130":[2,176],"131":[2,176],"133":[2,176],"134":[2,176],"135":[2,176],"136":[2,176],"137":[2,176],"138":[2,176],"139":[2,176],"140":[2,176],"141":[2,176],"142":[2,176],"144":[2,176]},{"1":[2,97],"4":[2,97],"29":[2,97],"30":[2,97],"47":[2,97],"55":[2,97],"59":[2,97],"75":[2,97],"80":[2,97],"90":[2,97],"94":[2,97],"96":[2,97],"105":[2,97],"107":[2,97],"108":[2,97],"109":[2,97],"113":[2,97],"121":[2,97],"130":[2,97],"131":[2,97],"133":[2,97],"134":[2,97],"135":[2,97],"136":[2,97],"137":[2,97],"138":[2,97],"139":[2,97],"140":[2,97],"141":[2,97],"142":[2,97],"144":[2,97]},{"4":[2,104],"30":[2,104],"80":[2,104]},{"4":[2,133],"29":[2,133],"30":[2,133],"55":[2,133],"90":[2,133],"96":[2,133]},{"1":[2,173],"4":[2,173],"29":[2,173],"30":[2,173],"47":[1,97],"55":[2,173],"59":[2,173],"75":[2,173],"80":[2,173],"90":[2,173],"94":[2,173],"96":[2,173],"105":[2,173],"106":95,"107":[2,173],"108":[2,173],"109":[2,173],"112":96,"113":[2,173],"114":70,"121":[2,173],"130":[2,173],"131":[2,173],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"1":[2,174],"4":[2,174],"29":[2,174],"30":[2,174],"47":[1,97],"55":[2,174],"59":[2,174],"75":[2,174],"80":[2,174],"90":[2,174],"94":[2,174],"96":[2,174],"105":[2,174],"106":95,"107":[2,174],"108":[2,174],"109":[2,174],"112":96,"113":[2,174],"114":70,"121":[2,174],"130":[2,174],"131":[2,174],"133":[1,85],"134":[1,84],"135":[1,82],"136":[1,83],"137":[1,86],"138":[1,87],"139":[1,88],"140":[1,89],"141":[1,90],"142":[1,91],"144":[1,92]},{"4":[2,93],"29":[2,93],"30":[2,93],"55":[2,93],"80":[2,93]}],defaultActions:{"79":[2,4],"105":[2,115]},parseError:function parseError(str,hash){throw new Error(str)},parse:function parse(input){var self=this,stack=[0],vstack=[null],table=this.table,yytext="",yylineno=0,yyleng=0,shifts=0,reductions=0,recovering=0,TERROR=2,EOF=1;this.lexer.setInput(input);this.lexer.yy=this.yy;this.yy.lexer=this.lexer;var parseError=this.yy.parseError=typeof this.yy.parseError=="function"?this.yy.parseError:this.parseError;function popStack(n){stack.length=stack.length-2*n;vstack.length=vstack.length-n}function checkRecover(st){for(var p in table[st]){if(p==TERROR){return true}}return false}function lex(){var token;token=self.lexer.lex()||1;if(typeof token!=="number"){token=self.symbols_[token]||token}return token}var symbol,preErrorSymbol,state,action,a,r,yyval={},p,len,newState,expected,recovered=false;while(true){state=stack[stack.length-1];if(this.defaultActions[state]){action=this.defaultActions[state]}else{if(symbol==null){symbol=lex()}action=table[state]&&table[state][symbol]}if(typeof action==="undefined"||!action.length||!action[0]){if(!recovering){expected=[];for(p in table[state]){if(this.terminals_[p]&&p>2){expected.push("'"+this.terminals_[p]+"'")}}if(this.lexer.showPosition){parseError.call(this,"Parse error on line "+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(", "),{text:this.lexer.match,token:this.terminals_[symbol]||symbol,line:this.lexer.yylineno,expected:expected})}else{parseError.call(this,"Parse error on line "+(yylineno+1)+": Unexpected '"+(this.terminals_[symbol]||symbol)+"'",{text:this.lexer.match,token:this.terminals_[symbol]||symbol,line:this.lexer.yylineno,expected:expected})}}if(recovering==3){if(symbol==EOF){throw"Parsing halted."}yyleng=this.lexer.yyleng;yytext=this.lexer.yytext;yylineno=this.lexer.yylineno;symbol=lex()}while(1){if(checkRecover(state)){break}if(state==0){throw"Parsing halted."}popStack(1);state=stack[stack.length-1]}preErrorSymbol=symbol;symbol=TERROR;state=stack[stack.length-1];action=table[state]&&table[state][TERROR];recovering=3}if(action[0] instanceof Array&&action.length>1){throw new Error("Parse Error: multiple actions possible at state: "+state+", token: "+symbol)}a=action;switch(a[0]){case 1:shifts++;stack.push(symbol);vstack.push(this.lexer.yytext);stack.push(a[1]);symbol=null;if(!preErrorSymbol){yyleng=this.lexer.yyleng;yytext=this.lexer.yytext;yylineno=this.lexer.yylineno;if(recovering>0){recovering--}}else{symbol=preErrorSymbol;preErrorSymbol=null}break;case 2:reductions++;len=this.productions_[a[1]][1];yyval.$=vstack[vstack.length-len];r=this.performAction.call(yyval,yytext,yyleng,yylineno,this.yy,a[1],vstack);if(typeof r!=="undefined"){return r}if(len){stack=stack.slice(0,-1*len*2);vstack=vstack.slice(0,-1*len)}stack.push(this.productions_[a[1]][0]);vstack.push(yyval.$);newState=table[stack[stack.length-2]][stack[stack.length-1]];stack.push(newState);break;case 3:this.reductionCount=reductions;this.shiftCount=shifts;return true}}return true}};return parser})();if(typeof require!=="undefined"){exports.parser=parser;exports.parse=function(){return parser.parse.apply(parser,arguments)};exports.main=function commonjsMain(args){if(!args[1]){throw new Error("Usage: "+args[0]+" FILE")}if(typeof process!=="undefined"){var source=require("fs").readFileSync(require("path").join(process.cwd(),args[1]),"utf8")}else{var cwd=require("file").path(require("file").cwd());var source=cwd.join(args[1]).read({charset:"utf-8"})}return exports.parser.parse(source)};if(typeof module!=="undefined"&&require.main===module){exports.main(typeof process!=="undefined"?process.argv.slice(1):require("system").args)}}};require["./scope"]=new function(){var exports=this;(function(){var Scope,_ref,extend,last;var __hasProp=Object.prototype.hasOwnProperty;_ref=require("./helpers"),extend=_ref.extend,last=_ref.last;exports.Scope=(function(){Scope=(function(){function Scope(_arg,_arg2,_arg3){this.method=_arg3;this.expressions=_arg2;this.parent=_arg;this.variables={"arguments":"arguments"};if(this.parent){this.garbage=this.parent.garbage}else{this.garbage=[];Scope.root=this}return this}return Scope})();Scope.root=null;Scope.prototype.startLevel=function(){return this.garbage.push([])};Scope.prototype.endLevel=function(){var _i,_len,_ref2,_result,name,vars;vars=this.variables;_result=[];for(_i=0,_len=(_ref2=this.garbage.pop()).length;_i<_len;_i++){name=_ref2[_i];if(vars[name]==="var"){_result.push(vars[name]="reuse")}}return _result};Scope.prototype.find=function(name,options){if(this.check(name,options)){return true}this.variables[name]="var";return false};Scope.prototype.any=function(fn){var _ref2,k,v;for(v in _ref2=this.variables){if(!__hasProp.call(_ref2,v)){continue}k=_ref2[v];if(fn(v,k)){return true}}return false};Scope.prototype.parameter=function(name){return(this.variables[name]="param")};Scope.prototype.check=function(name,options){var _ref2,immediate;immediate=Object.prototype.hasOwnProperty.call(this.variables,name);if(immediate||((options!=null)?options.immediate:undefined)){return immediate}return !!(((_ref2=this.parent)!=null)?_ref2.check(name):undefined)};Scope.prototype.temporary=function(type,index){return type.length>1?"_"+type+(index>1?index:""):"_"+(index+parseInt(type,36)).toString(36).replace(/\d/g,"a")};Scope.prototype.freeVariable=function(type){var index,temp;index=0;while(this.check(temp=this.temporary(type,index))&&this.variables[temp]!=="reuse"){index++}this.variables[temp]="var";if(this.garbage.length){last(this.garbage).push(temp)}return temp};Scope.prototype.assign=function(name,value){return(this.variables[name]={value:value,assigned:true})};Scope.prototype.hasDeclarations=function(body){return body===this.expressions&&this.any(function(k,val){return(val==="var"||val==="reuse")})};Scope.prototype.hasAssignments=function(body){return body===this.expressions&&this.any(function(k,val){return val.assigned})};Scope.prototype.declaredVariables=function(){var _ref2,_result,key,val;return(function(){_result=[];for(key in _ref2=this.variables){if(!__hasProp.call(_ref2,key)){continue}val=_ref2[key];if((val==="var"||val==="reuse")){_result.push(key)}}return _result}).call(this).sort()};Scope.prototype.assignedVariables=function(){var _ref2,_result,key,val;_result=[];for(key in _ref2=this.variables){if(!__hasProp.call(_ref2,key)){continue}val=_ref2[key];if(val.assigned){_result.push(""+key+" = "+(val.value))}}return _result};Scope.prototype.compiledDeclarations=function(){return this.declaredVariables().join(", ")};Scope.prototype.compiledAssignments=function(){return this.assignedVariables().join(", ")};return Scope}).call(this)}).call(this)};require["./nodes"]=new function(){var exports=this;(function(){var Accessor,ArrayLiteral,Assign,Base,Call,Class,Closure,Code,Comment,Existence,Expressions,Extends,For,IDENTIFIER,IS_STRING,If,In,Index,Literal,NO,NUMBER,ObjectLiteral,Op,Param,Parens,Push,Range,Return,SIMPLENUM,Scope,Slice,Splat,Switch,TAB,THIS,TRAILING_WHITESPACE,Throw,Try,UTILITIES,Value,While,YES,_ref,compact,del,ends,flatten,include,last,merge,starts,utility;var __extends=function(child,parent){function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;if(typeof parent.extended==="function"){parent.extended(child)}child.__super__=parent.prototype};Scope=require("./scope").Scope;_ref=require("./helpers"),compact=_ref.compact,flatten=_ref.flatten,merge=_ref.merge,del=_ref.del,include=_ref.include,starts=_ref.starts,ends=_ref.ends,last=_ref.last;YES=function(){return true};NO=function(){return false};THIS=function(){return this};exports.Base=(function(){Base=(function(){function Base(){this.tags={};return this}return Base})();Base.prototype.compile=function(o){var closure,code,top;this.options=o?merge(o):{};this.tab=o.indent;top=this.topSensitive()?this.options.top:del(this.options,"top");closure=this.isStatement(o)&&!this.isPureStatement()&&!top&&!this.options.asStatement&&!(this instanceof Comment)&&!this.containsPureStatement();code=closure?this.compileClosure(this.options):this.compileNode(this.options);return code};Base.prototype.compileClosure=function(o){o.sharedScope=o.scope;return Closure.wrap(this).compile(o)};Base.prototype.compileReference=function(o,options){var _len,compiled,i,node,pair,reference;pair=(function(){if(!this.isComplex()){return[this,this]}else{reference=new Literal(o.scope.freeVariable("ref"));compiled=new Assign(reference,this);return[compiled,reference]}}).call(this);if(((options!=null)?options.precompile:undefined)){for(i=0,_len=pair.length;i<_len;i++){node=pair[i];(pair[i]=node.compile(o))}}return pair};Base.prototype.idt=function(tabs){var idt,num;idt=this.tab||"";num=(tabs||0)+1;while(num-=1){idt+=TAB}return idt};Base.prototype.makeReturn=function(){return new Return(this)};Base.prototype.contains=function(block){var contains;contains=false;this.traverseChildren(false,function(node){if(block(node)){contains=true;return false}});return contains};Base.prototype.containsType=function(type){return this instanceof type||this.contains(function(node){return node instanceof type})};Base.prototype.containsPureStatement=function(){return this.isPureStatement()||this.contains(function(node){return node.isPureStatement()})};Base.prototype.traverse=function(block){return this.traverseChildren(true,block)};Base.prototype.toString=function(idt,override){var _i,_len,_ref2,_result,child,children,klass;idt||(idt="");children=(function(){_result=[];for(_i=0,_len=(_ref2=this.collectChildren()).length;_i<_len;_i++){child=_ref2[_i];_result.push(child.toString(idt+TAB))}return _result}).call(this).join("");klass=override||this.constructor.name+(this.soakNode||this.exist?"?":"");return"\n"+idt+klass+children};Base.prototype.eachChild=function(func){var _i,_j,_len,_len2,_ref2,_ref3,_result,attr,child;if(!this.children){return}_result=[];for(_i=0,_len=(_ref2=this.children).length;_i<_len;_i++){attr=_ref2[_i];if(this[attr]){for(_j=0,_len2=(_ref3=flatten([this[attr]])).length;_j<_len2;_j++){child=_ref3[_j];if(func(child)===false){return}}}}return _result};Base.prototype.collectChildren=function(){var nodes;nodes=[];this.eachChild(function(node){return nodes.push(node)});return nodes};Base.prototype.traverseChildren=function(crossScope,func){return this.eachChild(function(child){if(func(child)===false){return false}return crossScope||!(child instanceof Code)?child.traverseChildren(crossScope,func):undefined})};Base.prototype.invert=function(){return new Op("!",this)};Base.prototype.children=[];Base.prototype.unwrap=THIS;Base.prototype.isStatement=NO;Base.prototype.isPureStatement=NO;Base.prototype.isComplex=YES;Base.prototype.topSensitive=NO;Base.prototype.assigns=NO;return Base})();exports.Expressions=(function(){Expressions=(function(){function Expressions(nodes){Expressions.__super__.constructor.call(this);this.expressions=compact(flatten(nodes||[]));return this}return Expressions})();__extends(Expressions,Base);Expressions.prototype.children=["expressions"];Expressions.prototype.isStatement=YES;Expressions.prototype.push=function(node){this.expressions.push(node);return this};Expressions.prototype.unshift=function(node){this.expressions.unshift(node);return this};Expressions.prototype.unwrap=function(){return this.expressions.length===1?this.expressions[0]:this};Expressions.prototype.empty=function(){return this.expressions.length===0};Expressions.prototype.makeReturn=function(){var end,idx;end=this.expressions[(idx=this.expressions.length-1)];if(end instanceof Comment){end=this.expressions[idx-=1]}if(end&&!(end instanceof Return)){this.expressions[idx]=end.makeReturn()}return this};Expressions.prototype.compile=function(o){o||(o={});return o.scope?Expressions.__super__.compile.call(this,o):this.compileRoot(o)};Expressions.prototype.compileNode=function(o){var _i,_len,_ref2,_result,node;return(function(){_result=[];for(_i=0,_len=(_ref2=this.expressions).length;_i<_len;_i++){node=_ref2[_i];_result.push(this.compileExpression(node,merge(o)))}return _result}).call(this).join("\n")};Expressions.prototype.compileRoot=function(o){var code;o.indent=(this.tab=o.bare?"":TAB);o.scope=new Scope(null,this,null);code=this.compileWithDeclarations(o);code=code.replace(TRAILING_WHITESPACE,"");return o.bare?code:("(function() {\n"+code+"\n}).call(this);\n")};Expressions.prototype.compileWithDeclarations=function(o){var code;code=this.compileNode(o);if(o.scope.hasAssignments(this)){code=(""+(this.tab)+"var "+(o.scope.compiledAssignments().replace(/\n/g,"$&"+this.tab))+";\n"+code)}if(!o.globals&&o.scope.hasDeclarations(this)){code=(""+(this.tab)+"var "+(o.scope.compiledDeclarations())+";\n"+code)}return code};Expressions.prototype.compileExpression=function(node,o){var compiledNode;this.tab=o.indent;node.tags.front=true;compiledNode=node.compile(merge(o,{top:true}));return node.isStatement(o)?compiledNode:(""+(this.idt())+compiledNode+";")};return Expressions})();Expressions.wrap=function(nodes){if(nodes.length===1&&nodes[0] instanceof Expressions){return nodes[0]}return new Expressions(nodes)};exports.Literal=(function(){Literal=(function(){function Literal(_arg){this.value=_arg;Literal.__super__.constructor.call(this);return this}return Literal})();__extends(Literal,Base);Literal.prototype.makeReturn=function(){return this.isStatement()?this:Literal.__super__.makeReturn.call(this)};Literal.prototype.isStatement=function(){var _ref2;return((_ref2=this.value)==="break"||_ref2==="continue"||_ref2==="debugger")};Literal.prototype.isPureStatement=Literal.prototype.isStatement;Literal.prototype.isComplex=NO;Literal.prototype.isReserved=function(){return !!this.value.reserved};Literal.prototype.assigns=function(name){return name===this.value};Literal.prototype.compileNode=function(o){var end,idt,val;idt=this.isStatement(o)?this.idt():"";end=this.isStatement(o)?";":"";val=this.isReserved()?('"'+(this.value)+'"'):this.value;return idt+val+end};Literal.prototype.toString=function(){return' "'+this.value+'"'};return Literal})();exports.Return=(function(){Return=(function(){function Return(_arg){this.expression=_arg;Return.__super__.constructor.call(this);return this}return Return})();__extends(Return,Base);Return.prototype.isStatement=YES;Return.prototype.isPureStatement=YES;Return.prototype.children=["expression"];Return.prototype.makeReturn=THIS;Return.prototype.compile=function(o){var _ref2,expr;expr=(((_ref2=this.expression)!=null)?_ref2.makeReturn():undefined);if(expr&&(!(expr instanceof Return))){return expr.compile(o)}return Return.__super__.compile.call(this,o)};Return.prototype.compileNode=function(o){var expr;expr="";if(this.expression){if(this.expression.isStatement(o)){o.asStatement=true}expr=" "+this.expression.compile(o)}return""+(this.tab)+"return"+expr+";"};return Return})();exports.Value=(function(){Value=(function(){function Value(_arg,_arg2,tag){this.properties=_arg2;this.base=_arg;Value.__super__.constructor.call(this);this.properties||(this.properties=[]);if(tag){this.tags[tag]=true}return this}return Value})();__extends(Value,Base);Value.prototype.children=["base","properties"];Value.prototype.push=function(prop){this.properties.push(prop);return this};Value.prototype.hasProperties=function(){return !!this.properties.length};Value.prototype.isArray=function(){return this.base instanceof ArrayLiteral&&!this.properties.length};Value.prototype.isObject=function(){return this.base instanceof ObjectLiteral&&!this.properties.length};Value.prototype.isSplice=function(){return last(this.properties) instanceof Slice};Value.prototype.isComplex=function(){return this.base.isComplex()||this.hasProperties()};Value.prototype.assigns=function(name){return !this.properties.length&&this.base.assigns(name)};Value.prototype.makeReturn=function(){return this.properties.length?Value.__super__.makeReturn.call(this):this.base.makeReturn()};Value.prototype.unwrap=function(){return this.properties.length?this:this.base};Value.prototype.isStatement=function(o){return this.base.isStatement(o)&&!this.properties.length};Value.prototype.isSimpleNumber=function(){return this.base instanceof Literal&&SIMPLENUM.test(this.base.value)};Value.prototype.cacheReference=function(o){var base,bref,name,nref;name=last(this.properties);if(!this.base.isComplex()&&this.properties.length<2&&!((name!=null)?name.isComplex():undefined)){return[this,this]}base=new Value(this.base,this.properties.slice(0,-1));if(base.isComplex()){bref=new Literal(o.scope.freeVariable("base"));base=new Value(new Parens(new Assign(bref,base)))}if(!name){return[base,bref]}if(name.isComplex()){nref=new Literal(o.scope.freeVariable("name"));name=new Index(new Assign(nref,name.index));nref=new Index(nref)}return[base.push(name),new Value(bref||base.base,[nref||name])]};Value.prototype.compile=function(o){this.base.tags.front=this.tags.front;return !o.top||this.properties.length?Value.__super__.compile.call(this,o):this.base.compile(o)};Value.prototype.compileNode=function(o){var _i,_len,code,ex,prop,props;if(ex=this.unfoldSoak(o)){return ex.compile(o)}props=this.properties;if(this.parenthetical&&!props.length){this.base.parenthetical=true}code=this.base.compile(o);if(props[0] instanceof Accessor&&this.isSimpleNumber()){code=("("+code+")")}for(_i=0,_len=props.length;_i<_len;_i++){prop=props[_i];(code+=prop.compile(o))}return code};Value.prototype.unfoldSoak=function(o){var _len,_ref2,fst,i,ifn,prop,ref,snd;if(this.base.soakNode){Array.prototype.push.apply(this.base.body.properties,this.properties);return this.base}for(i=0,_len=(_ref2=this.properties).length;i<_len;i++){prop=_ref2[i];if(prop.soakNode){prop.soakNode=false;fst=new Value(this.base,this.properties.slice(0,i));snd=new Value(this.base,this.properties.slice(i));if(fst.isComplex()){ref=new Literal(o.scope.freeVariable("ref"));fst=new Parens(new Assign(ref,fst));snd.base=ref}ifn=new If(new Existence(fst),snd,{operation:true});ifn.soakNode=true;return ifn}}return null};Value.unfoldSoak=function(o,parent,name){var ifnode,node;node=parent[name];if(node instanceof If&&node.soakNode){ifnode=node}else{if(node instanceof Value){ifnode=node.unfoldSoak(o)}}if(!ifnode){return}parent[name]=ifnode.body;ifnode.body=new Value(parent);return ifnode};return Value}).call(this);exports.Comment=(function(){Comment=(function(){function Comment(_arg){this.comment=_arg;Comment.__super__.constructor.call(this);return this}return Comment})();__extends(Comment,Base);Comment.prototype.isStatement=YES;Comment.prototype.makeReturn=THIS;Comment.prototype.compileNode=function(o){return this.tab+"/*"+this.comment.replace(/\n/g,"\n"+this.tab)+"*/"};return Comment})();exports.Call=(function(){Call=(function(){function Call(variable,_arg,_arg2){this.exist=_arg2;this.args=_arg;Call.__super__.constructor.call(this);this.isNew=false;this.isSuper=variable==="super";this.variable=this.isSuper?null:variable;this.args||(this.args=[]);return this}return Call})();__extends(Call,Base);Call.prototype.children=["variable","args"];Call.prototype.compileSplatArguments=function(o){return Splat.compileSplattedArray(this.args,o)};Call.prototype.newInstance=function(){this.isNew=true;return this};Call.prototype.prefix=function(){return this.isNew?"new ":""};Call.prototype.superReference=function(o){var method,name;method=o.scope.method;if(!method){throw Error("cannot call super outside of a function")}name=method.name;if(!name){throw Error("cannot call super on an anonymous function.")}return method.klass?(""+(method.klass)+".__super__."+name):(""+name+".__super__.constructor")};Call.prototype.unfoldSoak=function(o){var _i,_len,_ref2,call,list,node;call=this;list=[];while(true){if(call.variable instanceof Call){list.push(call);call=call.variable;continue}if(!(call.variable instanceof Value)){break}list.push(call);if(!((call=call.variable.base) instanceof Call)){break}}for(_i=0,_len=(_ref2=list.reverse()).length;_i<_len;_i++){call=_ref2[_i];if(node){if(call.variable instanceof Call){call.variable=node}else{call.variable.base=node}}node=Value.unfoldSoak(o,call,"variable")}return node};Call.prototype.compileNode=function(o){var _i,_j,_len,_len2,_ref2,_ref3,_ref4,_ref5,_result,arg,args,left,node,rite,val;if(node=this.unfoldSoak(o)){return node.compile(o)}(((_ref2=this.variable)!=null)?(_ref2.tags.front=this.tags.front):undefined);if(this.exist){if(val=this.variable){if(!(val instanceof Value)){val=new Value(val)}_ref3=val.cacheReference(o),left=_ref3[0],rite=_ref3[1];rite=new Call(rite,this.args)}else{left=new Literal(this.superReference(o));rite=new Call(new Value(left),this.args);rite.isNew=this.isNew}left=("typeof "+(left.compile(o))+' !== "function"');rite=rite.compile(o);return("("+left+" ? undefined : "+rite+")")}for(_i=0,_len=(_ref4=this.args).length;_i<_len;_i++){arg=_ref4[_i];if(arg instanceof Splat){return this.compileSplat(o)}}args=(function(){_result=[];for(_j=0,_len2=(_ref5=this.args).length;_j<_len2;_j++){arg=_ref5[_j];_result.push((arg.parenthetical=true)&&arg.compile(o))}return _result}).call(this).join(", ");return this.isSuper?this.compileSuper(args,o):(""+(this.prefix())+(this.variable.compile(o))+"("+args+")")};Call.prototype.compileSuper=function(args,o){return""+(this.superReference(o))+".call(this"+(args.length?", ":"")+args+")"};Call.prototype.compileSplat=function(o){var base,fun,idt,name,ref,splatargs;splatargs=this.compileSplatArguments(o);if(this.isSuper){return(""+(this.superReference(o))+".apply(this, "+splatargs+")")}if(!this.isNew){if(!((base=this.variable) instanceof Value)){base=new Value(base)}if((name=base.properties.pop())&&base.isComplex()){ref=o.scope.freeVariable("this");fun=("("+ref+" = "+(base.compile(o))+")"+(name.compile(o)))}else{fun=(ref=base.compile(o));if(name){fun+=name.compile(o)}}return(""+fun+".apply("+ref+", "+splatargs+")")}idt=this.idt(1);return"(function(func, args, ctor) {\n"+idt+"ctor.prototype = func.prototype;\n"+idt+"var child = new ctor, result = func.apply(child, args);\n"+idt+'return typeof result === "object" ? result : child;\n'+(this.tab)+"})("+(this.variable.compile(o))+", "+splatargs+", function() {})"};return Call})();exports.Extends=(function(){Extends=(function(){function Extends(_arg,_arg2){this.parent=_arg2;this.child=_arg;Extends.__super__.constructor.call(this);return this}return Extends})();__extends(Extends,Base);Extends.prototype.children=["child","parent"];Extends.prototype.compileNode=function(o){var ref;ref=new Value(new Literal(utility("extends")));return(new Call(ref,[this.child,this.parent])).compile(o)};return Extends})();exports.Accessor=(function(){Accessor=(function(){function Accessor(_arg,tag){this.name=_arg;Accessor.__super__.constructor.call(this);this.prototype=tag==="prototype"?".prototype":"";this.soakNode=tag==="soak";return this}return Accessor})();__extends(Accessor,Base);Accessor.prototype.children=["name"];Accessor.prototype.compileNode=function(o){var name,namePart;name=this.name.compile(o);namePart=name.match(IS_STRING)?("["+name+"]"):("."+name);return this.prototype+namePart};Accessor.prototype.isComplex=NO;return Accessor})();exports.Index=(function(){Index=(function(){function Index(_arg){this.index=_arg;Index.__super__.constructor.call(this);return this}return Index})();__extends(Index,Base);Index.prototype.children=["index"];Index.prototype.compileNode=function(o){var idx,prefix;idx=this.index.compile(o);prefix=this.proto?".prototype":"";return""+prefix+"["+idx+"]"};Index.prototype.isComplex=function(){return this.index.isComplex()};return Index})();exports.Range=(function(){Range=(function(){function Range(_arg,_arg2,tag){this.to=_arg2;this.from=_arg;Range.__super__.constructor.call(this);this.exclusive=tag==="exclusive";this.equals=this.exclusive?"":"=";return this}return Range})();__extends(Range,Base);Range.prototype.children=["from","to"];Range.prototype.compileVariables=function(o){var _ref2,_ref3,_ref4,parts;o=merge(o,{top:true});_ref2=this.from.compileReference(o,{precompile:true}),this.from=_ref2[0],this.fromVar=_ref2[1];_ref3=this.to.compileReference(o,{precompile:true}),this.to=_ref3[0],this.toVar=_ref3[1];_ref4=[this.fromVar.match(SIMPLENUM),this.toVar.match(SIMPLENUM)],this.fromNum=_ref4[0],this.toNum=_ref4[1];parts=[];if(this.from!==this.fromVar){parts.push(this.from)}return this.to!==this.toVar?parts.push(this.to):undefined};Range.prototype.compileNode=function(o){var compare,idx,incr,intro,step,stepPart,vars;this.compileVariables(o);if(!o.index){return this.compileArray(o)}if(this.fromNum&&this.toNum){return this.compileSimple(o)}idx=del(o,"index");step=del(o,"step");vars=(""+idx+" = "+(this.from))+(this.to!==this.toVar?(", "+(this.to)):"");intro=("("+(this.fromVar)+" <= "+(this.toVar)+" ? "+idx);compare=(""+intro+" <"+(this.equals)+" "+(this.toVar)+" : "+idx+" >"+(this.equals)+" "+(this.toVar)+")");stepPart=step?step.compile(o):"1";incr=step?(""+idx+" += "+stepPart):(""+intro+" += "+stepPart+" : "+idx+" -= "+stepPart+")");return""+vars+"; "+compare+"; "+incr};Range.prototype.compileSimple=function(o){var _ref2,from,idx,step,to;_ref2=[+this.fromNum,+this.toNum],from=_ref2[0],to=_ref2[1];idx=del(o,"index");step=del(o,"step");step&&(step=(""+idx+" += "+(step.compile(o))));return from<=to?(""+idx+" = "+from+"; "+idx+" <"+(this.equals)+" "+to+"; "+(step||(""+idx+"++"))):(""+idx+" = "+from+"; "+idx+" >"+(this.equals)+" "+to+"; "+(step||(""+idx+"--")))};Range.prototype.compileArray=function(o){var _i,_ref2,_ref3,_result,body,clause,i,idt,post,pre,range,result,vars;if(this.fromNum&&this.toNum&&(Math.abs(this.fromNum-this.toNum)<=20)){range=(function(){_result=[];for(var _i=_ref2=+this.fromNum,_ref3=+this.toNum;_ref2<=_ref3?_i<=_ref3:_i>=_ref3;_ref2<=_ref3?_i+=1:_i-=1){_result.push(_i)}return _result}).call(this);if(this.exclusive){range.pop()}return("["+(range.join(", "))+"]")}idt=this.idt(1);i=o.scope.freeVariable("i");result=o.scope.freeVariable("result");pre=("\n"+idt+result+" = [];");if(this.fromNum&&this.toNum){o.index=i;body=this.compileSimple(o)}else{vars=(""+i+" = "+(this.from))+(this.to!==this.toVar?(", "+(this.to)):"");clause=(""+(this.fromVar)+" <= "+(this.toVar)+" ?");body=("var "+vars+"; "+clause+" "+i+" <"+(this.equals)+" "+(this.toVar)+" : "+i+" >"+(this.equals)+" "+(this.toVar)+"; "+clause+" "+i+" += 1 : "+i+" -= 1")}post=("{ "+result+".push("+i+"); }\n"+idt+"return "+result+";\n"+(o.indent));return"(function() {"+pre+"\n"+idt+"for ("+body+")"+post+"}).call(this)"};return Range})();exports.Slice=(function(){Slice=(function(){function Slice(_arg){this.range=_arg;Slice.__super__.constructor.call(this);return this}return Slice})();__extends(Slice,Base);Slice.prototype.children=["range"];Slice.prototype.compileNode=function(o){var from,to;from=this.range.from?this.range.from.compile(o):"0";to=this.range.to?this.range.to.compile(o):"";to+=(!to||this.range.exclusive?"":" + 1");if(to){to=", "+to}return".slice("+from+to+")"};return Slice})();exports.ObjectLiteral=(function(){ObjectLiteral=(function(){function ObjectLiteral(props){ObjectLiteral.__super__.constructor.call(this);this.objects=(this.properties=props||[]);return this}return ObjectLiteral})();__extends(ObjectLiteral,Base);ObjectLiteral.prototype.children=["properties"];ObjectLiteral.prototype.compileNode=function(o){var _i,_len,_ref2,_result,i,indent,join,lastNoncom,nonComments,obj,prop,props,top;top=del(o,"top");o.indent=this.idt(1);nonComments=(function(){_result=[];for(_i=0,_len=(_ref2=this.properties).length;_i<_len;_i++){prop=_ref2[_i];if(!(prop instanceof Comment)){_result.push(prop)}}return _result}).call(this);lastNoncom=last(nonComments);props=(function(){_result=[];for(i=0,_len=(_ref2=this.properties).length;i<_len;i++){prop=_ref2[i];_result.push((function(){join=i===this.properties.length-1?"":(prop===lastNoncom||prop instanceof Comment?"\n":",\n");indent=prop instanceof Comment?"":this.idt(1);if(prop instanceof Value&&prop.tags["this"]){prop=new Assign(prop.properties[0].name,prop,"object")}else{if(!(prop instanceof Assign)&&!(prop instanceof Comment)){prop=new Assign(prop,prop,"object")}}return indent+prop.compile(o)+join}).call(this))}return _result}).call(this);props=props.join("");obj=("{"+(props?"\n"+props+"\n"+this.idt():"")+"}");return this.tags.front?("("+obj+")"):obj};ObjectLiteral.prototype.assigns=function(name){var _i,_len,_ref2,prop;for(_i=0,_len=(_ref2=this.properties).length;_i<_len;_i++){prop=_ref2[_i];if(prop.assigns(name)){return true}}return false};return ObjectLiteral})();exports.ArrayLiteral=(function(){ArrayLiteral=(function(){function ArrayLiteral(_arg){this.objects=_arg;ArrayLiteral.__super__.constructor.call(this);this.objects||(this.objects=[]);return this}return ArrayLiteral})();__extends(ArrayLiteral,Base);ArrayLiteral.prototype.children=["objects"];ArrayLiteral.prototype.compileSplatLiteral=function(o){return Splat.compileSplattedArray(this.objects,o)};ArrayLiteral.prototype.compileNode=function(o){var _i,_len,_len2,_ref2,_ref3,code,i,obj,objects;o.indent=this.idt(1);for(_i=0,_len=(_ref2=this.objects).length;_i<_len;_i++){obj=_ref2[_i];if(obj instanceof Splat){return this.compileSplatLiteral(o)}}objects=[];for(i=0,_len2=(_ref3=this.objects).length;i<_len2;i++){obj=_ref3[i];code=obj.compile(o);objects.push(obj instanceof Comment?("\n"+code+"\n"+(o.indent)):(i===this.objects.length-1?code:code+", "))}objects=objects.join("");return 0<objects.indexOf("\n")?("[\n"+(o.indent)+objects+"\n"+(this.tab)+"]"):("["+objects+"]")};ArrayLiteral.prototype.assigns=function(name){var _i,_len,_ref2,obj;for(_i=0,_len=(_ref2=this.objects).length;_i<_len;_i++){obj=_ref2[_i];if(obj.assigns(name)){return true}}return false};return ArrayLiteral})();exports.Class=(function(){Class=(function(){function Class(variable,_arg,_arg2){this.properties=_arg2;this.parent=_arg;Class.__super__.constructor.call(this);this.variable=variable==="__temp__"?new Literal(variable):variable;this.properties||(this.properties=[]);this.returns=false;return this}return Class})();__extends(Class,Base);Class.prototype.children=["variable","parent","properties"];Class.prototype.isStatement=YES;Class.prototype.makeReturn=function(){this.returns=true;return this};Class.prototype.compileNode=function(o){var _i,_len,_ref2,_ref3,_ref4,access,applied,apply,className,constScope,construct,constructor,extension,func,me,pname,prop,props,pvar,ref,returns,val,variable;variable=this.variable;if(variable.value==="__temp__"){variable=new Literal(o.scope.freeVariable("ctor"))}extension=this.parent&&new Extends(variable,this.parent);props=new Expressions;o.top=true;me=null;className=variable.compile(o);constScope=null;if(this.parent){applied=new Value(this.parent,[new Accessor(new Literal("apply"))]);constructor=new Code([],new Expressions([new Call(applied,[new Literal("this"),new Literal("arguments")])]))}else{constructor=new Code}for(_i=0,_len=(_ref2=this.properties).length;_i<_len;_i++){prop=_ref2[_i];_ref3=[prop.variable,prop.value],pvar=_ref3[0],func=_ref3[1];if(pvar&&pvar.base.value==="constructor"){if(!(func instanceof Code)){_ref4=func.compileReference(o),func=_ref4[0],ref=_ref4[1];if(func!==ref){props.push(func)}apply=new Call(new Value(ref,[new Accessor(new Literal("apply"))]),[new Literal("this"),new Literal("arguments")]);func=new Code([],new Expressions([apply]))}if(func.bound){throw new Error("cannot define a constructor as a bound function.")}func.name=className;func.body.push(new Return(new Literal("this")));variable=new Value(variable);variable.namespaced=0<className.indexOf(".");constructor=func;continue}if(func instanceof Code&&func.bound){if(prop.context==="this"){func.context=className}else{func.bound=false;constScope||(constScope=new Scope(o.scope,constructor.body,constructor));me||(me=constScope.freeVariable("this"));pname=pvar.compile(o);if(constructor.body.empty()){constructor.body.push(new Return(new Literal("this")))}constructor.body.unshift(new Literal("this."+pname+" = function(){ return "+className+".prototype."+pname+".apply("+me+", arguments); }"))}}if(pvar){access=prop.context==="this"?pvar.base.properties[0]:new Accessor(pvar,"prototype");val=new Value(variable,[access]);prop=new Assign(val,func)}props.push(prop)}constructor.className=className.match(/[\w\d\$_]+$/);if(me){constructor.body.unshift(new Literal(""+me+" = this"))}construct=this.idt()+new Assign(variable,constructor).compile(merge(o,{sharedScope:constScope}))+";";props=!props.empty()?"\n"+props.compile(o):"";extension=extension?"\n"+this.idt()+extension.compile(o)+";":"";returns=this.returns?"\n"+new Return(variable).compile(o):"";return construct+extension+props+returns};return Class})();exports.Assign=(function(){Assign=(function(){function Assign(_arg,_arg2,_arg3){this.context=_arg3;this.value=_arg2;this.variable=_arg;Assign.__super__.constructor.call(this);return this}return Assign})();__extends(Assign,Base);Assign.prototype.METHOD_DEF=/^(?:(\S+)\.prototype\.)?([$A-Za-z_][$\w]*)$/;Assign.prototype.children=["variable","value"];Assign.prototype.topSensitive=YES;Assign.prototype.isValue=function(){return this.variable instanceof Value};Assign.prototype.compileNode=function(o){var ifn,isValue,match,name,stmt,top,val;if(isValue=this.isValue()){if(this.variable.isArray()||this.variable.isObject()){return this.compilePatternMatch(o)}if(this.variable.isSplice()){return this.compileSplice(o)}if(ifn=Value.unfoldSoak(o,this,"variable")){delete o.top;return ifn.compile(o)}}top=del(o,"top");stmt=del(o,"asStatement");name=this.variable.compile(o);if(this.value instanceof Code&&(match=this.METHOD_DEF.exec(name))){this.value.name=match[2];this.value.klass=match[1]}val=this.value.compile(o);if(this.context==="object"){return(""+name+": "+val)}if(!(isValue&&(this.variable.hasProperties()||this.variable.namespaced))){o.scope.find(name)}val=(""+name+" = "+val);if(stmt){return(""+(this.tab)+val+";")}return top||this.parenthetical?val:("("+val+")")};Assign.prototype.compilePatternMatch=function(o){var _len,_ref2,_ref3,accessClass,assigns,code,i,idx,isObject,obj,objects,olength,otop,ref,splat,top,val,valVar,value;if((value=this.value).isStatement(o)){value=Closure.wrap(value)}objects=this.variable.base.objects;if(!(olength=objects.length)){return value.compile(o)}isObject=this.variable.isObject();if(o.top&&olength===1&&!((obj=objects[0]) instanceof Splat)){if(obj instanceof Assign){_ref2=obj,idx=_ref2.variable.base,obj=_ref2.value}else{idx=isObject?(obj.tags["this"]?obj.properties[0].name:obj):new Literal(0)}if(!(value instanceof Value)){value=new Value(value)}accessClass=IDENTIFIER.test(idx.value)?Accessor:Index;value.properties.push(new accessClass(idx));return new Assign(obj,value).compile(o)}top=del(o,"top");otop=merge(o,{top:true});valVar=value.compile(o);assigns=[];splat=false;if(!IDENTIFIER.test(valVar)||this.variable.assigns(valVar)){assigns.push(""+(ref=o.scope.freeVariable("ref"))+" = "+valVar);valVar=ref}for(i=0,_len=objects.length;i<_len;i++){obj=objects[i];idx=i;if(isObject){if(obj instanceof Assign){_ref3=obj,idx=_ref3.variable.base,obj=_ref3.value}else{idx=obj.tags["this"]?obj.properties[0].name:obj}}if(!(obj instanceof Value||obj instanceof Splat)){throw new Error("pattern matching must use only identifiers on the left-hand side.")}accessClass=isObject&&IDENTIFIER.test(idx.value)?Accessor:Index;if(!splat&&obj instanceof Splat){val=new Literal(obj.compileValue(o,valVar,i,olength-i-1));splat=true}else{if(typeof idx!=="object"){idx=new Literal(splat?(""+valVar+".length - "+(olength-idx)):idx)}val=new Value(new Literal(valVar),[new accessClass(idx)])}assigns.push(new Assign(obj,val).compile(otop))}if(!top){assigns.push(valVar)}code=assigns.join(", ");return top||this.parenthetical?code:("("+code+")")};Assign.prototype.compileSplice=function(o){var from,name,plus,range,ref,to,val;range=this.variable.properties.pop().range;name=this.variable.compile(o);plus=range.exclusive?"":" + 1";from=range.from?range.from.compile(o):"0";to=range.to?range.to.compile(o)+" - "+from+plus:(""+name+".length");ref=o.scope.freeVariable("ref");val=this.value.compile(o);return"([].splice.apply("+name+", ["+from+", "+to+"].concat("+ref+" = "+val+")), "+ref+")"};Assign.prototype.assigns=function(name){return this[this.context==="object"?"value":"variable"].assigns(name)};return Assign})();exports.Code=(function(){Code=(function(){function Code(_arg,_arg2,tag){this.body=_arg2;this.params=_arg;Code.__super__.constructor.call(this);this.params||(this.params=[]);this.body||(this.body=new Expressions);this.bound=tag==="boundfunc";if(this.bound){this.context="this"}return this}return Code})();__extends(Code,Base);Code.prototype.children=["params","body"];Code.prototype.compileNode=function(o){var _i,_len,_len2,_ref2,_ref3,_result,close,code,empty,func,i,open,param,params,sharedScope,splat,top,value;sharedScope=del(o,"sharedScope");top=del(o,"top");o.scope=sharedScope||new Scope(o.scope,this.body,this);o.top=true;o.indent=this.idt(1);empty=this.body.expressions.length===0;delete o.bare;delete o.globals;splat=undefined;params=[];for(i=0,_len=(_ref2=this.params).length;i<_len;i++){param=_ref2[i];if(splat){if(param.attach){param.assign=new Assign(new Value(new Literal("this"),[new Accessor(param.value)]));this.body.expressions.splice(splat.index+1,0,param.assign)}splat.trailings.push(param)}else{if(param.attach){value=param.value;_ref3=[new Literal(o.scope.freeVariable("arg")),param.splat],param=_ref3[0],param.splat=_ref3[1];this.body.unshift(new Assign(new Value(new Literal("this"),[new Accessor(value)]),param))}if(param.splat){splat=new Splat(param.value);splat.index=i;splat.trailings=[];splat.arglength=this.params.length;this.body.unshift(splat)}else{params.push(param)}}}o.scope.startLevel();params=(function(){_result=[];for(_i=0,_len2=params.length;_i<_len2;_i++){param=params[_i];_result.push(param.compile(o))}return _result})();if(!empty){this.body.makeReturn()}for(_i=0,_len2=params.length;_i<_len2;_i++){param=params[_i];(o.scope.parameter(param))}if(this.className){o.indent=this.idt(2)}code=this.body.expressions.length?("\n"+(this.body.compileWithDeclarations(o))+"\n"):"";open=this.className?("(function() {\n"+(this.idt(1))+"function "+(this.className)+"("):"function(";close=this.className?(""+(code&&this.idt(1))+"};\n"+(this.idt(1))+"return "+(this.className)+";\n"+(this.tab)+"})()"):(""+(code&&this.tab)+"}");func=(""+open+(params.join(", "))+") {"+code+close);o.scope.endLevel();if(this.bound){return(""+(utility("bind"))+"("+func+", "+(this.context)+")")}return this.tags.front?("("+func+")"):func};Code.prototype.traverseChildren=function(crossScope,func){return crossScope?Code.__super__.traverseChildren.call(this,crossScope,func):undefined};return Code})();exports.Param=(function(){Param=(function(){function Param(_arg,_arg2,_arg3){this.splat=_arg3;this.attach=_arg2;this.name=_arg;Param.__super__.constructor.call(this);this.value=new Literal(this.name);return this}return Param})();__extends(Param,Base);Param.prototype.children=["name"];Param.prototype.compileNode=function(o){return this.value.compile(o)};Param.prototype.toString=function(){var name;name=this.name;if(this.attach){name="@"+name}if(this.splat){name+="..."}return new Literal(name).toString()};return Param})();exports.Splat=(function(){Splat=(function(){function Splat(name){Splat.__super__.constructor.call(this);this.name=name.compile?name:new Literal(name);return this}return Splat})();__extends(Splat,Base);Splat.prototype.children=["name"];Splat.prototype.assigns=function(name){return this.name.assigns(name)};Splat.prototype.compileNode=function(o){return(this.index!=null)?this.compileParam(o):this.name.compile(o)};Splat.prototype.compileParam=function(o){var _len,_ref2,assign,end,idx,len,name,pos,trailing,variadic;name=this.name.compile(o);o.scope.find(name);end="";if(this.trailings.length){len=o.scope.freeVariable("len");o.scope.assign(len,"arguments.length");variadic=o.scope.freeVariable("result");o.scope.assign(variadic,len+" >= "+this.arglength);end=this.trailings.length?(", "+len+" - "+(this.trailings.length)):undefined;for(idx=0,_len=(_ref2=this.trailings).length;idx<_len;idx++){trailing=_ref2[idx];if(trailing.attach){assign=trailing.assign;trailing=new Literal(o.scope.freeVariable("arg"));assign.value=trailing}pos=this.trailings.length-idx;o.scope.assign(trailing.compile(o),"arguments["+variadic+" ? "+len+" - "+pos+" : "+(this.index+idx)+"]")}}return""+name+" = "+(utility("slice"))+".call(arguments, "+(this.index)+end+")"};Splat.prototype.compileValue=function(o,name,index,trailings){var trail;trail=trailings?(", "+name+".length - "+trailings):"";return""+(utility("slice"))+".call("+name+", "+index+trail+")"};Splat.compileSplattedArray=function(list,o){var _len,arg,args,code,end,i,prev;args=[];end=-1;for(i=0,_len=list.length;i<_len;i++){arg=list[i];code=arg.compile(o);prev=args[end];if(!(arg instanceof Splat)){if(prev&&starts(prev,"[")&&ends(prev,"]")){args[end]=(""+(prev.slice(0,-1))+", "+code+"]");continue}if(prev&&starts(prev,".concat([")&&ends(prev,"])")){args[end]=(""+(prev.slice(0,-2))+", "+code+"])");continue}code=("["+code+"]")}args[++end]=i===0?code:(".concat("+code+")")}return args.join("")};return Splat}).call(this);exports.While=(function(){While=(function(){function While(condition,opts){While.__super__.constructor.call(this);this.condition=((opts!=null)?opts.invert:undefined)?condition.invert():condition;this.guard=((opts!=null)?opts.guard:undefined);return this}return While})();__extends(While,Base);While.prototype.children=["condition","guard","body"];While.prototype.isStatement=YES;While.prototype.addBody=function(body){this.body=body;return this};While.prototype.makeReturn=function(){this.returns=true;return this};While.prototype.topSensitive=YES;While.prototype.compileNode=function(o){var cond,post,pre,rvar,set,top;top=del(o,"top")&&!this.returns;o.indent=this.idt(1);this.condition.parenthetical=true;cond=this.condition.compile(o);o.top=true;set="";if(!top){rvar=o.scope.freeVariable("result");set=(""+(this.tab)+rvar+" = [];\n");if(this.body){this.body=Push.wrap(rvar,this.body)}}pre=(""+set+(this.tab)+"while ("+cond+")");if(this.guard){this.body=Expressions.wrap([new If(this.guard,this.body)])}if(this.returns){post="\n"+new Return(new Literal(rvar)).compile(merge(o,{indent:this.idt()}))}else{post=""}return""+pre+" {\n"+(this.body.compile(o))+"\n"+(this.tab)+"}"+post};return While})();exports.Op=(function(){Op=(function(){function Op(op,first,second,flip){if(op==="new"){if(first instanceof Call){return first.newInstance()}if(first instanceof Code&&first.bound){first=new Parens(first)}}Op.__super__.constructor.call(this);this.operator=this.CONVERSIONS[op]||op;(this.first=first).tags.operation=true;if(second){(this.second=second).tags.operation=true}this.flip=!!flip;return this}return Op})();__extends(Op,Base);Op.prototype.CONVERSIONS={"==":"===","!=":"!==",of:"in"};Op.prototype.INVERSIONS={"!==":"===","===":"!=="};Op.prototype.CHAINABLE=["<",">",">=","<=","===","!=="];Op.prototype.ASSIGNMENT=["||=","&&=","?="];Op.prototype.PREFIX_OPERATORS=["new","typeof","delete"];Op.prototype.children=["first","second"];Op.prototype.isUnary=function(){return !this.second};Op.prototype.isComplex=function(){return this.operator!=="!"||this.first.isComplex()};Op.prototype.isMutator=function(){var _ref2;return ends(this.operator,"=")&&!((_ref2=this.operator)==="==="||_ref2==="!==")};Op.prototype.isChainable=function(){return include(this.CHAINABLE,this.operator)};Op.prototype.invert=function(){var _ref2;if(((_ref2=this.operator)==="==="||_ref2==="!==")){this.operator=this.INVERSIONS[this.operator];return this}else{return this.second?new Parens(this).invert():Op.__super__.invert.call(this)}};Op.prototype.toString=function(idt){return Op.__super__.toString.call(this,idt,this.constructor.name+" "+this.operator)};Op.prototype.compileNode=function(o){if(this.second){this.first.tags.front=this.tags.front}if(this.isChainable()&&this.first.unwrap() instanceof Op&&this.first.unwrap().isChainable()){return this.compileChain(o)}if(include(this.ASSIGNMENT,this.operator)){return this.compileAssignment(o)}if(this.isUnary()){return this.compileUnary(o)}if(this.operator==="?"){return this.compileExistence(o)}if(this.first instanceof Op&&this.first.isMutator()){this.first=new Parens(this.first)}if(this.second instanceof Op&&this.second.isMutator()){this.second=new Parens(this.second)}return[this.first.compile(o),this.operator,this.second.compile(o)].join(" ")};Op.prototype.compileChain=function(o){var _ref2,_ref3,first,second,shared;shared=this.first.unwrap().second;_ref2=shared.compileReference(o),this.first.second=_ref2[0],shared=_ref2[1];_ref3=[this.first.compile(o),this.second.compile(o),shared.compile(o)],first=_ref3[0],second=_ref3[1],shared=_ref3[2];return"("+first+") && ("+shared+" "+(this.operator)+" "+second+")"};Op.prototype.compileAssignment=function(o){var _ref2,left,rite;_ref2=this.first.cacheReference(o),left=_ref2[0],rite=_ref2[1];rite=new Assign(rite,this.second);return new Op(this.operator.slice(0,-1),left,rite).compile(o)};Op.prototype.compileExistence=function(o){var fst,ref;if(this.first.isComplex()){ref=o.scope.freeVariable("ref");fst=new Parens(new Assign(new Literal(ref),this.first))}else{fst=this.first;ref=fst.compile(o)}return new Existence(fst).compile(o)+(" ? "+ref+" : "+(this.second.compile(o)))};Op.prototype.compileUnary=function(o){var parts,space;space=include(this.PREFIX_OPERATORS,this.operator)?" ":"";parts=[this.operator,space,this.first.compile(o)];return(this.flip?parts.reverse():parts).join("")};return Op})();exports.In=(function(){In=(function(){function In(_arg,_arg2){this.array=_arg2;this.object=_arg;In.__super__.constructor.call(this);return this}return In})();__extends(In,Base);In.prototype.children=["object","array"];In.prototype.isArray=function(){return this.array instanceof Value&&this.array.isArray()};In.prototype.compileNode=function(o){var _ref2;_ref2=this.object.compileReference(o,{precompile:true}),this.obj1=_ref2[0],this.obj2=_ref2[1];return this.isArray()?this.compileOrTest(o):this.compileLoopTest(o)};In.prototype.compileOrTest=function(o){var _len,_ref2,_result,i,item,tests;tests=(function(){_result=[];for(i=0,_len=(_ref2=this.array.base.objects).length;i<_len;i++){item=_ref2[i];_result.push(""+(i?this.obj2:this.obj1)+" === "+(item.compile(o)))}return _result}).call(this);return"("+(tests.join(" || "))+")"};In.prototype.compileLoopTest=function(o){var _ref2,_ref3,i,l,prefix;_ref2=this.array.compileReference(o,{precompile:true}),this.arr1=_ref2[0],this.arr2=_ref2[1];_ref3=[o.scope.freeVariable("i"),o.scope.freeVariable("len")],i=_ref3[0],l=_ref3[1];prefix=this.obj1!==this.obj2?this.obj1+"; ":"";return"(function(){ "+prefix+"for (var "+i+"=0, "+l+"="+(this.arr1)+".length; "+i+"<"+l+"; "+i+"++) { if ("+(this.arr2)+"["+i+"] === "+(this.obj2)+") return true; } return false; }).call(this)"};return In})();exports.Try=(function(){Try=(function(){function Try(_arg,_arg2,_arg3,_arg4){this.ensure=_arg4;this.recovery=_arg3;this.error=_arg2;this.attempt=_arg;Try.__super__.constructor.call(this);return this}return Try})();__extends(Try,Base);Try.prototype.children=["attempt","recovery","ensure"];Try.prototype.isStatement=YES;Try.prototype.makeReturn=function(){if(this.attempt){this.attempt=this.attempt.makeReturn()}if(this.recovery){this.recovery=this.recovery.makeReturn()}return this};Try.prototype.compileNode=function(o){var attemptPart,catchPart,errorPart,finallyPart;o.indent=this.idt(1);o.top=true;attemptPart=this.attempt.compile(o);errorPart=this.error?(" ("+(this.error.compile(o))+") "):" ";catchPart=this.recovery?(" catch"+errorPart+"{\n"+(this.recovery.compile(o))+"\n"+(this.tab)+"}"):(!(this.ensure||this.recovery)?" catch (_e) {}":"");finallyPart=(this.ensure||"")&&" finally {\n"+this.ensure.compile(merge(o))+("\n"+(this.tab)+"}");return""+(this.tab)+"try {\n"+attemptPart+"\n"+(this.tab)+"}"+catchPart+finallyPart};return Try})();exports.Throw=(function(){Throw=(function(){function Throw(_arg){this.expression=_arg;Throw.__super__.constructor.call(this);return this}return Throw})();__extends(Throw,Base);Throw.prototype.children=["expression"];Throw.prototype.isStatement=YES;Throw.prototype.makeReturn=THIS;Throw.prototype.compileNode=function(o){return""+(this.tab)+"throw "+(this.expression.compile(o))+";"};return Throw})();exports.Existence=(function(){Existence=(function(){function Existence(_arg){this.expression=_arg;Existence.__super__.constructor.call(this);return this}return Existence})();__extends(Existence,Base);Existence.prototype.children=["expression"];Existence.prototype.compileNode=function(o){var code;code=this.expression.compile(o);code=IDENTIFIER.test(code)&&!o.scope.check(code)?("typeof "+code+' !== "undefined" && '+code+" !== null"):(""+code+" != null");return this.parenthetical?code:("("+code+")")};return Existence})();exports.Parens=(function(){Parens=(function(){function Parens(_arg){this.expression=_arg;Parens.__super__.constructor.call(this);return this}return Parens})();__extends(Parens,Base);Parens.prototype.children=["expression"];Parens.prototype.isStatement=function(o){return this.expression.isStatement(o)};Parens.prototype.isComplex=function(){return this.expression.isComplex()};Parens.prototype.topSensitive=YES;Parens.prototype.makeReturn=function(){return this.expression.makeReturn()};Parens.prototype.compileNode=function(o){var code,top;top=del(o,"top");this.expression.parenthetical=true;code=this.expression.compile(o);if(top&&this.expression.isPureStatement(o)){return code}if(this.parenthetical||this.isStatement(o)){return top?this.tab+code+";":code}return"("+code+")"};return Parens})();exports.For=(function(){For=(function(){function For(_arg,source,_arg2,_arg3){var _ref2;this.index=_arg3;this.name=_arg2;this.body=_arg;For.__super__.constructor.call(this);this.source=source.source,this.guard=source.guard,this.step=source.step;this.raw=!!source.raw;this.object=!!source.object;if(this.object){_ref2=[this.index,this.name],this.name=_ref2[0],this.index=_ref2[1]}this.pattern=this.name instanceof Value;if(this.index instanceof Value){throw new Error("index cannot be a pattern matching expression")}this.returns=false;return this}return For})();__extends(For,Base);For.prototype.children=["body","source","guard"];For.prototype.isStatement=YES;For.prototype.topSensitive=YES;For.prototype.makeReturn=function(){this.returns=true;return this};For.prototype.compileReturnValue=function(val,o){if(this.returns){return"\n"+new Return(new Literal(val)).compile(o)}if(val){return"\n"+val}return""};For.prototype.compileNode=function(o){var body,codeInBody,forPart,guardPart,idt1,index,ivar,lvar,name,namePart,range,ref,resultPart,returnResult,rvar,scope,source,sourcePart,stepPart,svar,topLevel,varPart,vars;topLevel=del(o,"top")&&!this.returns;range=this.source instanceof Value&&this.source.base instanceof Range&&!this.source.properties.length;source=range?this.source.base:this.source;codeInBody=this.body.contains(function(node){return node instanceof Code});scope=o.scope;name=this.name&&this.name.compile(o);index=this.index&&this.index.compile(o);if(name&&!this.pattern&&(range||!codeInBody)){scope.find(name,{immediate:true})}if(index){scope.find(index,{immediate:true})}if(!topLevel){rvar=scope.freeVariable("result")}ivar=range?name:index;if(!ivar||codeInBody){ivar=scope.freeVariable("i")}varPart="";guardPart="";body=Expressions.wrap([this.body]);idt1=this.idt(1);if(range){forPart=source.compile(merge(o,{index:ivar,step:this.step}))}else{svar=(sourcePart=this.source.compile(o));if((name||!this.raw)&&!(IDENTIFIER.test(svar)&&scope.check(svar,{immediate:true}))){sourcePart=(""+(ref=scope.freeVariable("ref"))+" = "+svar);if(!this.object){sourcePart=("("+sourcePart+")")}svar=ref}namePart=this.pattern?new Assign(this.name,new Literal(""+svar+"["+ivar+"]")).compile(merge(o,{top:true})):(name?(""+name+" = "+svar+"["+ivar+"]"):undefined);if(!this.object){lvar=scope.freeVariable("len");stepPart=this.step?(""+ivar+" += "+(this.step.compile(o))):(""+ivar+"++");forPart=(""+ivar+" = 0, "+lvar+" = "+sourcePart+".length; "+ivar+" < "+lvar+"; "+stepPart)}}resultPart=rvar?(""+(this.tab)+rvar+" = [];\n"):"";returnResult=this.compileReturnValue(rvar,o);if(!topLevel){body=Push.wrap(rvar,body)}if(this.guard){body=Expressions.wrap([new If(this.guard,body)])}if(codeInBody){if(range){body.unshift(new Literal("var "+name+" = "+ivar))}if(namePart){body.unshift(new Literal("var "+namePart))}if(index){body.unshift(new Literal("var "+index+" = "+ivar))}body=Closure.wrap(body,true)}else{if(namePart){varPart=(""+idt1+namePart+";\n")}}if(this.object){forPart=(""+ivar+" in "+sourcePart);if(!this.raw){guardPart=("\n"+idt1+"if (!"+(utility("hasProp"))+".call("+svar+", "+ivar+")) continue;")}}body=body.compile(merge(o,{indent:idt1,top:true}));vars=range?name:(""+name+", "+ivar);return""+resultPart+(this.tab)+"for ("+forPart+") {"+guardPart+"\n"+varPart+body+"\n"+(this.tab)+"}"+returnResult};return For})();exports.Switch=(function(){Switch=(function(){function Switch(_arg,_arg2,_arg3){this.otherwise=_arg3;this.cases=_arg2;this.subject=_arg;Switch.__super__.constructor.call(this);this.tags.subjectless=!this.subject;this.subject||(this.subject=new Literal("true"));return this}return Switch})();__extends(Switch,Base);Switch.prototype.children=["subject","cases","otherwise"];Switch.prototype.isStatement=YES;Switch.prototype.makeReturn=function(){var _i,_len,_ref2,pair;for(_i=0,_len=(_ref2=this.cases).length;_i<_len;_i++){pair=_ref2[_i];pair[1].makeReturn()}if(this.otherwise){this.otherwise.makeReturn()}return this};Switch.prototype.compileNode=function(o){var _i,_j,_len,_len2,_ref2,_ref3,block,code,condition,conditions,exprs,idt,pair;idt=(o.indent=this.idt(2));o.top=true;code=(""+(this.tab)+"switch ("+(this.subject.compile(o))+") {");for(_i=0,_len=(_ref2=this.cases).length;_i<_len;_i++){pair=_ref2[_i];conditions=pair[0],block=pair[1];exprs=block.expressions;for(_j=0,_len2=(_ref3=flatten([conditions])).length;_j<_len2;_j++){condition=_ref3[_j];if(this.tags.subjectless){condition=new Op("!!",new Parens(condition))}code+=("\n"+(this.idt(1))+"case "+(condition.compile(o))+":")}code+=("\n"+(block.compile(o)));if(!(last(exprs) instanceof Return)){code+=("\n"+idt+"break;")}}if(this.otherwise){code+=("\n"+(this.idt(1))+"default:\n"+(this.otherwise.compile(o)))}code+=("\n"+(this.tab)+"}");return code};return Switch})();exports.If=(function(){If=(function(){function If(condition,_arg,_arg2){this.tags=_arg2;this.body=_arg;this.tags||(this.tags={});this.condition=this.tags.invert?condition.invert():condition;this.elseBody=null;this.isChain=false;return this}return If})();__extends(If,Base);If.prototype.children=["condition","body","elseBody","assigner"];If.prototype.topSensitive=YES;If.prototype.bodyNode=function(){var _ref2;return(((_ref2=this.body)!=null)?_ref2.unwrap():undefined)};If.prototype.elseBodyNode=function(){var _ref2;return(((_ref2=this.elseBody)!=null)?_ref2.unwrap():undefined)};If.prototype.addElse=function(elseBody){if(this.isChain){this.elseBodyNode().addElse(elseBody)}else{this.isChain=elseBody instanceof If;this.elseBody=this.ensureExpressions(elseBody)}return this};If.prototype.isStatement=function(o){var _ref2;return this.statement||(this.statement=((o!=null)?o.top:undefined)||this.bodyNode().isStatement(o)||(((_ref2=this.elseBodyNode())!=null)?_ref2.isStatement(o):undefined))};If.prototype.compileCondition=function(o){this.condition.parenthetical=true;return this.condition.compile(o)};If.prototype.compileNode=function(o){return this.isStatement(o)?this.compileStatement(o):this.compileExpression(o)};If.prototype.makeReturn=function(){if(this.isStatement()){this.body&&(this.body=this.ensureExpressions(this.body.makeReturn()));this.elseBody&&(this.elseBody=this.ensureExpressions(this.elseBody.makeReturn()));return this}else{return new Return(this)}};If.prototype.ensureExpressions=function(node){return node instanceof Expressions?node:new Expressions([node])};If.prototype.compileStatement=function(o){var child,condO,ifPart,top;top=del(o,"top");child=del(o,"chainChild");condO=merge(o);o.indent=this.idt(1);o.top=true;ifPart=("if ("+(this.compileCondition(condO))+") {\n"+(this.body.compile(o))+"\n"+(this.tab)+"}");if(!child){ifPart=this.tab+ifPart}if(!this.elseBody){return ifPart}return ifPart+(this.isChain?" else "+this.elseBodyNode().compile(merge(o,{indent:this.tab,chainChild:true})):(" else {\n"+(this.elseBody.compile(o))+"\n"+(this.tab)+"}"))};If.prototype.compileExpression=function(o){var code,elsePart,ifPart;this.bodyNode().tags.operation=(this.condition.tags.operation=true);if(this.elseBody){this.elseBodyNode().tags.operation=true}ifPart=this.condition.compile(o)+" ? "+this.bodyNode().compile(o);elsePart=this.elseBody?this.elseBodyNode().compile(o):"undefined";code=(""+ifPart+" : "+elsePart);return this.tags.operation?("("+code+")"):code};return If})();Push={wrap:function(name,expressions){if(expressions.empty()||expressions.containsPureStatement()){return expressions}return Expressions.wrap([new Call(new Value(new Literal(name),[new Accessor(new Literal("push"))]),[expressions.unwrap()])])}};Closure={wrap:function(expressions,statement){var args,call,func,mentionsArgs,meth;if(expressions.containsPureStatement()){return expressions}func=new Parens(new Code([],Expressions.wrap([expressions])));args=[];if((mentionsArgs=expressions.contains(this.literalArgs))||(expressions.contains(this.literalThis))){meth=new Literal(mentionsArgs?"apply":"call");args=[new Literal("this")];if(mentionsArgs){args.push(new Literal("arguments"))}func=new Value(func,[new Accessor(meth)])}call=new Call(func,args);return statement?Expressions.wrap([call]):call},literalArgs:function(node){return node instanceof Literal&&node.value==="arguments"},literalThis:function(node){return node instanceof Literal&&node.value==="this"||node instanceof Code&&node.bound}};UTILITIES={"extends":'function(child, parent) {\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n if (typeof parent.extended === "function") parent.extended(child);\n child.__super__ = parent.prototype;\n}',bind:"function(func, context) {\n return function() { return func.apply(context, arguments); };\n}",hasProp:"Object.prototype.hasOwnProperty",slice:"Array.prototype.slice"};TAB=" ";TRAILING_WHITESPACE=/[ \t]+$/gm;IDENTIFIER=/^[$A-Za-z_][$\w]*$/;NUMBER=/^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?$/i;SIMPLENUM=/^[+-]?\d+$/;IS_STRING=/^['"]/;utility=function(name){var ref;ref=("__"+name);Scope.root.assign(ref,UTILITIES[name]);return ref}}).call(this)};require["./coffee-script"]=new function(){var exports=this;(function(){var Lexer,compile,fs,lexer,parser,path;path=require("path");Lexer=require("./lexer").Lexer;parser=require("./parser").parser;if(require.extensions){fs=require("fs");require.extensions[".coffee"]=function(module,filename){var content;content=compile(fs.readFileSync(filename,"utf8"));return module._compile(content,filename)}}else{if(require.registerExtension){require.registerExtension(".coffee",function(content){return compile(content)})}}exports.VERSION="0.9.4";exports.helpers=require("./helpers");exports.compile=(compile=function(code,options){options||(options={});try{return(parser.parse(lexer.tokenize(code))).compile(options)}catch(err){if(options.fileName){err.message=("In "+(options.fileName)+", "+(err.message))}throw err}});exports.tokens=function(code,options){return lexer.tokenize(code,options)};exports.nodes=function(code,options){return parser.parse(lexer.tokenize(code,options))};exports.run=function(code,options){var root;root=module;while(root.parent){root=root.parent}root.filename=options.fileName;if(root.moduleCache){root.moduleCache={}}return path.extname(root.filename)!==".coffee"||require.extensions?root._compile(exports.compile(code,options),root.filename):root._compile(code,root.filename)};exports.eval=function(code,options){var __dirname,__filename;__filename=options.fileName;__dirname=path.dirname(__filename);return eval(exports.compile(code,options))};lexer=new Lexer;parser.lexer={lex:function(){var token;token=this.tokens[this.pos]||[""];this.pos+=1;this.yylineno=token[2];this.yytext=token[1];return token[0]},setInput:function(tokens){this.tokens=tokens;return(this.pos=0)},upcomingInput:function(){return""}};parser.yy=require("./nodes")}).call(this)};require["./browser"]=new function(){var exports=this;(function(){var CoffeeScript,runScripts;CoffeeScript=require("./coffee-script");CoffeeScript.require=require;CoffeeScript.eval=function(code,options){return eval(CoffeeScript.compile(code,options))};CoffeeScript.run=function(code,options){((options!=null)?(options.bare=true):undefined);return Function(CoffeeScript.compile(code,options))()};if(!(typeof window!=="undefined"&&window!==null)){return}CoffeeScript.load=function(url,options){var xhr;xhr=new (window.ActiveXObject||XMLHttpRequest)("Microsoft.XMLHTTP");xhr.open("GET",url,true);if("overrideMimeType" in xhr){xhr.overrideMimeType("text/plain")}xhr.onreadystatechange=function(){return xhr.readyState===4?CoffeeScript.run(xhr.responseText,options):undefined};return xhr.send(null)};runScripts=function(){var _i,_len,_ref;for(_i=0,_len=(_ref=document.getElementsByTagName("script")).length;_i<_len;_i++){(function(){var script=_ref[_i];return script.type==="text/coffeescript"?(script.src?CoffeeScript.load(script.src):setTimeout(function(){return CoffeeScript.run(script.innerHTML)})):undefined})()}return null};if(window.addEventListener){addEventListener("DOMContentLoaded",runScripts,false)}else{attachEvent("onload",runScripts)}}).call(this)};return require["./coffee-script"]}();
\ No newline at end of file
--- /dev/null
+# JavaScriptLint configuration file for CoffeeScript.
+
++no_return_value # function {0} does not always return a value
++duplicate_formal # duplicate formal argument {0}
+-equal_as_assign # test for equality (==) mistyped as assignment (=)?{0}
++var_hides_arg # variable {0} hides argument
++redeclared_var # redeclaration of {0} {1}
+-anon_no_return_value # anonymous function does not always return a value
++missing_semicolon # missing semicolon
++meaningless_block # meaningless block; curly braces have no impact
+-comma_separated_stmts # multiple statements separated by commas (use semicolons?)
++unreachable_code # unreachable code
++missing_break # missing break statement
++missing_break_for_last_case # missing break statement for last case in switch
+-comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==)
+-inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement
++useless_void # use of the void type may be unnecessary (void is always undefined)
++multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs
++use_of_label # use of label
+-block_without_braces # block statement without curly braces
++leading_decimal_point # leading decimal point may indicate a number or an object member
++trailing_decimal_point # trailing decimal point may indicate a number or an object member
++octal_number # leading zeros make an octal number
++nested_comment # nested comment
++misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma
++ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement
++empty_statement # empty statement or extra semicolon
+-missing_option_explicit # the "option explicit" control comment is missing
++partial_option_explicit # the "option explicit" control comment, if used, must be in the first script tag
++dup_option_explicit # duplicate "option explicit" control comment
++useless_assign # useless assignment
++ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity
++ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent)
+-missing_default_case # missing default case in switch statement
++duplicate_case_in_switch # duplicate case in switch statements
++default_not_at_end # the default case is not at the end of the switch statement
++legacy_cc_not_understood # couldn't understand control comment using /*@keyword@*/ syntax
++jsl_cc_not_understood # couldn't understand control comment using /*jsl:keyword*/ syntax
++useless_comparison # useless comparison; comparing identical expressions
++with_statement # with statement hides undeclared variables; use temporary variable instead
++trailing_comma_in_array # extra comma is not recommended in array initializers
++assign_to_function_call # assignment to a function call
++parseint_missing_radix # parseInt missing radix parameter
++lambda_assign_requires_semicolon
--- /dev/null
+
+
+
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>CoffeeScript</title>
+ <link rel="stylesheet" type="text/css" href="documentation/css/docs.css" />
+ <link rel="stylesheet" type="text/css" href="documentation/css/idle.css" />
+ <link rel="shortcut icon" href="documentation/images/favicon.ico" />
+</head>
+<body class="minimized">
+
+ <div id="fadeout"></div>
+
+ <div id="flybar">
+ <a id="logo" href="#top"> </a>
+ <div class="navigation toc">
+ <div class="button">
+ Table of Contents
+ </div>
+ <div class="contents">
+ <a href="#overview">Mini Overview</a>
+ <a href="#installation">Installation and Usage</a>
+ <a href="#language">Language Reference</a>
+ <a href="#whitespace">Significant Whitespace</a>
+ <a href="#functions">Functions and Invocation</a>
+ <a href="#objects_and_arrays">Objects and Arrays</a>
+ <a href="#lexical_scope">Lexical Scoping and Variable Safety</a>
+ <a href="#conditionals">If, Else, Unless, and Conditional Assignment</a>
+ <a href="#aliases">Aliases</a>
+ <a href="#splats">Splats...</a>
+ <a href="#while">While, Until, and Loop</a>
+ <a href="#comprehensions">Comprehensions (Arrays, Objects, and Ranges)</a>
+ <a href="#slice_splice">Array Slicing and Splicing with Ranges</a>
+ <a href="#expressions">Everything is an Expression</a>
+ <a href="#existence">The Existential Operator</a>
+ <a href="#classes">Classes, Inheritance, and Super</a>
+ <a href="#pattern_matching">Pattern Matching</a>
+ <a href="#fat_arrow">Function Binding</a>
+ <a href="#embedded">Embedded JavaScript</a>
+ <a href="#switch">The Switch Statement</a>
+ <a href="#try">Try/Catch/Finally</a>
+ <a href="#comparisons">Chained Comparisons</a>
+ <a href="#interpolation">String and RegExp Interpolation</a>
+ <a href="#heredocs">Multiline Strings, Heredocs, and Block Comments</a>
+ <a href="#cake">Cake, and Cakefiles</a>
+ <a href="#scripts">"text/coffeescript" Script Tags</a>
+ <a href="#resources">Resources</a>
+ <a href="#webchat">Web Chat (IRC)</a>
+ <a href="#change_log">Change Log</a>
+ </div>
+ </div>
+ <div class="navigation try">
+ <div class="button">
+ Try CoffeeScript
+ </div>
+ <div class="contents repl_wrapper">
+ <div class="code">
+ <div id="repl_source_wrap"><textarea id="repl_source" rows="100">alert "Hello CoffeeScript!"</textarea></div>
+ <pre id="repl_results"></pre>
+ <button class="full_screen">go full screen</button>
+ <button class="minimize">minimize</button>
+ <button class="run">run</button>
+ <br class="clear" />
+ </div>
+ </div>
+ </div>
+ <div class="navigation annotated">
+ <div class="button">
+ Annotated Source
+ </div>
+ <div class="contents">
+ <a href="documentation/docs/grammar.html">Grammar Rules — src/grammar</a>
+ <a href="documentation/docs/lexer.html">Lexing Tokens — src/lexer</a>
+ <a href="documentation/docs/rewriter.html">The Rewriter — src/rewriter</a>
+ <a href="documentation/docs/nodes.html">The Syntax Tree — src/nodes</a>
+ <a href="documentation/docs/scope.html">Lexical Scope — src/scope</a>
+ <a href="documentation/docs/helpers.html">Helpers & Utility Functions — src/helpers</a>
+ <a href="documentation/docs/coffee-script.html">The CoffeeScript Module — src/coffee-script</a>
+ <a href="documentation/docs/cake.html">Cake & Cakefiles — src/cake</a>
+ <a href="documentation/docs/command.html">"coffee" Command-Line Utility — src/command</a>
+ <a href="documentation/docs/optparse.html">Option Parsing — src/optparse</a>
+ <a href="documentation/docs/repl.html">Interactive REPL — src/repl</a>
+ </div>
+ </div>
+ <div id="error" style="display:none;"></div>
+ </div>
+
+ <div class="container">
+ <span class="bookmark" id="top"></span>
+
+ <p>
+ CoffeeScript is a little language that compiles into JavaScript. Think
+ of it as JavaScript's less ostentatious kid brother — the same genes,
+ roughly the same height, but a different sense of style. Apart from a handful of
+ bonus goodies, statements in CoffeeScript correspond one-to-one with their
+ equivalent in JavaScript, it's just another way of saying it.
+ </p>
+
+ <p>
+ <b>Disclaimer:</b>
+ CoffeeScript is just for fun. Until it reaches 1.0, <i>there are no guarantees
+ that the syntax won't change between versions.</i> That said,
+ it compiles into clean JavaScript (the good parts) that can use existing
+ JavaScript libraries seamlessly, and passes through
+ <a href="http://www.jslint.com/">JSLint</a> without warnings. The compiled
+ output is pretty-printed and quite readable.
+ </p>
+
+ <p>
+ <b>Latest Version:</b>
+ <a href="http://github.com/jashkenas/coffee-script/tarball/0.9.4">0.9.4</a>
+ </p>
+
+ <h2>
+ <span id="overview" class="bookmark"></span>
+ Mini Overview
+ </h2>
+
+ <p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p>
+
+ <div class='code'><pre class="idle"><span class="Comment"><span class="Comment">#</span> Assignment:</span>
+number <span class="Keyword">=</span> <span class="Number">42</span>
+opposite <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>
+
+<span class="Comment"><span class="Comment">#</span> Conditions:</span>
+number <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">42</span> <span class="Keyword">if</span> opposite
+
+<span class="Comment"><span class="Comment">#</span> Functions:</span>
+<span class="FunctionName">square </span><span class="Keyword">=</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">x</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> x <span class="Keyword">*</span> x
+
+<span class="Comment"><span class="Comment">#</span> Arrays:</span>
+list <span class="Keyword">=</span> [<span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>]
+
+<span class="Comment"><span class="Comment">#</span> Objects:</span>
+math <span class="Keyword">=</span>
+ root: Math.sqrt
+ square: square
+ <span class="FunctionName">cube</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">x</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> x <span class="Keyword">*</span> square x
+
+<span class="Comment"><span class="Comment">#</span> Splats:</span>
+<span class="FunctionName">race </span><span class="Keyword">=</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">winner, runners...</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
+ print winner, runners
+
+<span class="Comment"><span class="Comment">#</span> Existence:</span>
+alert <span class="String"><span class="String">"</span>I knew it!<span class="String">"</span></span> <span class="Keyword">if</span> elvis<span class="Keyword">?</span>
+
+<span class="Comment"><span class="Comment">#</span> Array comprehensions:</span>
+cubes <span class="Keyword">=</span> math.cube num <span class="Keyword">for</span> num <span class="Keyword">in</span> list
+</pre><pre class="idle"><span class="Storage">var</span> _i, _len, _result, cubes, list, math, num, number, opposite, race, square;
+<span class="Storage">var</span> __slice <span class="Keyword">=</span> <span class="LibraryClassType">Array</span>.<span class="LibraryConstant">prototype</span>.slice;
+number <span class="Keyword">=</span> <span class="Number">42</span>;
+opposite <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
+<span class="Keyword">if</span> (opposite) {
+ number <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">42</span>;
+}
+<span class="FunctionName">square</span> = <span class="Storage">function</span>(<span class="FunctionArgument">x</span>) {
+ <span class="Keyword">return</span> x <span class="Keyword">*</span> x;
+};
+list <span class="Keyword">=</span> [<span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>];
+math <span class="Keyword">=</span> {
+ root: <span class="LibraryClassType">Math</span>.sqrt,
+ square: square,
+ <span class="FunctionName">cube</span>: <span class="Storage">function</span>(<span class="FunctionArgument">x</span>) {
+ <span class="Keyword">return</span> x <span class="Keyword">*</span> square(x);
+ }
+};
+<span class="FunctionName">race</span> = <span class="Storage">function</span>(<span class="FunctionArgument">winner</span>) {
+ <span class="Storage">var</span> runners;
+ runners <span class="Keyword">=</span> __slice.<span class="LibraryFunction">call</span>(arguments, <span class="Number">1</span>);
+ <span class="Keyword">return</span> <span class="LibraryFunction">print</span>(winner, runners);
+};
+<span class="Keyword">if</span> (<span class="Keyword">typeof</span> elvis <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> elvis <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) {
+ <span class="LibraryFunction">alert</span>(<span class="String"><span class="String">"</span>I knew it!<span class="String">"</span></span>);
+}
+cubes <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ _result <span class="Keyword">=</span> [];
+ <span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _len <span class="Keyword">=</span> list.<span class="LibraryConstant">length</span>; _i <span class="Keyword"><</span> _len; _i<span class="Keyword">++</span>) {
+ num <span class="Keyword">=</span> list[_i];
+ _result.<span class="LibraryFunction">push</span>(math.cube(num));
+ }
+ <span class="Keyword">return</span> _result;
+})();
+</pre><button onclick='javascript: var _i, _len, _result, cubes, list, math, num, number, opposite, race, square;
+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);
+ }
+};
+race = function(winner) {
+ var runners;
+ runners = __slice.call(arguments, 1);
+ return print(winner, runners);
+};
+if (typeof elvis !== "undefined" && elvis !== null) {
+ alert("I knew it!");
+}
+cubes = (function() {
+ _result = [];
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
+ num = list[_i];
+ _result.push(math.cube(num));
+ }
+ return _result;
+})();;alert(cubes);'>run: cubes</button><br class='clear' /></div>
+
+ <p>
+ For a longer CoffeeScript example, check out
+ <a href="documentation/docs/underscore.html">Underscore.coffee</a>, a port
+ of the <a href="http://documentcloud.github.com/underscore/">Underscore.js</a>
+ library of helper functions. Underscore.coffee can pass the entire Underscore.js
+ test suite. The CoffeeScript version is faster than the original for a number
+ of methods (in general, due to the speed of CoffeeScript's array comprehensions), and
+ after being minified and gzipped, is only 241 bytes larger than the original
+ JavaScript version.
+ Additional examples are included in the source repository, inside the
+ <a href="http://github.com/jashkenas/coffee-script/tree/master/examples/">examples</a> folder.
+ </p>
+
+ <h2>
+ <span id="installation" class="bookmark"></span>
+ Installation and Usage
+ </h2>
+
+ <p>
+ The CoffeeScript compiler is written in pure CoffeeScript, using a
+ <a href="documentation/docs/grammar.html">small DSL</a>
+ on top of the <a href="http://github.com/zaach/jison">Jison parser generator</a>, and is available
+ as a <a href="http://nodejs.org/">Node.js</a> utility. The core compiler however,
+ does not depend on Node, and can be run in other server-side-JavaScript environments,
+ or in the browser (see "Try CoffeeScript", above).
+ </p>
+
+ <p>
+ To install, first make sure you have a working copy of the latest tagged version of
+ <a href="http://nodejs.org/">Node.js</a>, currently <b>0.1.102</b> or higher.
+ Then clone the CoffeeScript
+ <a href="http://github.com/jashkenas/coffee-script">source repository</a>
+ from GitHub, or download the latest
+ release: <a href="http://github.com/jashkenas/coffee-script/tarball/0.9.4">0.9.4</a>.
+ To install the CoffeeScript compiler system-wide
+ under <tt>/usr/local</tt>, open the directory and run:
+ </p>
+
+ <pre>
+sudo bin/cake install</pre>
+
+ <p>
+ Alternatively, if you already have the
+ <a href="http://npmjs.org/">Node Package Manager</a> installed,
+ you can use that to grab the latest CoffeeScript:
+ </p>
+
+ <pre>
+sudo npm install coffee-script</pre>
+
+ <p>
+ Both of these provide the <tt>coffee</tt> command, which will execute CoffeeScripts
+ under Node.js by default, but is also used to compile CoffeeScript
+ <tt>.coffee</tt> files into JavaScript, or to run an an interactive REPL.
+ When compiling to JavaScript, <tt>coffee</tt> writes the output
+ as <tt>.js</tt> files in the same directory by default, but output
+ can be customized with the following options:
+ </p>
+
+ <table>
+ <tr>
+ <td><code>-c, --compile</code></td>
+ <td>
+ Compile a <tt>.coffee</tt> script into a <tt>.js</tt> JavaScript file
+ of the same name.
+ </td>
+ </tr>
+ <tr>
+ <td width="25%"><code>-i, --interactive</code></td>
+ <td>
+ Launch an interactive CoffeeScript session to try short snippets.
+ More pleasant if wrapped with
+ <a href="http://utopia.knoware.nl/~hlub/uck/rlwrap/rlwrap.html">rlwrap</a>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-o, --output [DIR]</code></td>
+ <td>
+ Write out all compiled JavaScript files into the specified directory.
+ Use in conjunction with <tt>--compile</tt> or <tt>--watch</tt>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-w, --watch</code></td>
+ <td>
+ Watch the modification times of the coffee-scripts, recompiling as
+ soon as a change occurs.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-p, --print</code></td>
+ <td>
+ Instead of writing out the JavaScript as a file, print it
+ directly to <b>stdout</b>.
+ </td>
+ </tr>
+ <tr>
+ <td><code>-l, --lint</code></td>
+ <td>
+ If the <tt>jsl</tt>
+ (<a href="http://www.javascriptlint.com/">JavaScript Lint</a>)
+ command is installed, use it
+ to check the compilation of a CoffeeScript file. (Handy in
+ conjunction with <br /> <tt>--watch</tt>)
+ </td>
+ </tr>
+ <tr>
+ <td><code>-s, --stdio</code></td>
+ <td>
+ Pipe in CoffeeScript to STDIN and get back JavaScript over STDOUT.
+ Good for use with processes written in other languages. An example:<br />
+ <tt>cat src/cake.coffee | coffee -sc</tt>
+ </td>
+ </tr>
+ <tr>
+ <td><code>-e, --eval</code></td>
+ <td>
+ Compile and print a little snippet of CoffeeScript directly from the
+ command line. For example:<br /><tt>coffee -e "puts num for num in [10..1]"</tt>
+ </td>
+ </tr>
+ <tr>
+ <td><code>-r, --require</code></td>
+ <td>
+ Load a library before compiling or executing your script. Can be used
+ to hook in to the compiler (to add Growl notifications, for example).
+ </td>
+ </tr>
+ <tr>
+ <td><code>-b, --bare</code></td>
+ <td>
+ Compile the JavaScript without the top-level function safety wrapper.
+ (Used for CoffeeScript as a Node.js module.)
+ </td>
+ </tr>
+ <tr>
+ <td><code>-t, --tokens</code></td>
+ <td>
+ Instead of parsing the CoffeeScript, just lex it, and print out the
+ token stream: <tt>[IDENTIFIER square] [ASSIGN =] [PARAM_START (]</tt> ...
+ </td>
+ </tr>
+ <tr>
+ <td><code>-n, --nodes</code></td>
+ <td>
+ Instead of compiling the CoffeeScript, just lex and parse it, and print
+ out the parse tree:
+<pre class="no_bar">
+Expressions
+ Assign
+ Value "square"
+ Code "x"
+ Op *
+ Value "x"
+ Value "x"</pre>
+ </td>
+ </tr>
+ </table>
+
+ <p>
+ <b>Examples:</b>
+ </p>
+
+ <pre>
+coffee -c path/to/script.coffee
+coffee --interactive
+coffee --watch --lint experimental.coffee
+coffee --print app/scripts/*.coffee > concatenation.js</pre>
+
+ <h2>
+ <span id="language" class="bookmark"></span>
+ Language Reference
+ </h2>
+
+ <p>
+ <i>
+ This reference is structured so that it can be read from top to bottom,
+ if you like. Later sections use ideas and syntax previously introduced.
+ Familiarity with JavaScript is assumed.
+ In all of the following examples, the source CoffeeScript is provided on
+ the left, and the direct compilation into JavaScript is on the right.
+ </i>
+ </p>
+
+ <p>
+ <i>
+ Many of the examples can be run (where it makes sense) by pressing the "run"
+ button towards the bottom right. You can also paste examples into
+ "Try CoffeeScript" in the toolbar, and play with them from there.
+ </i>
+ <p>
+ <span id="whitespace" class="bookmark"></span>
+ <b class="header">Significant Whitespace</b>
+ CoffeeScript uses Python-style significant whitespace: You don't need to
+ use semicolons <tt>;</tt> to terminate expressions, ending
+ the line will do just as well. Semicolons can still be used to fit
+ multiple expressions onto a single line. Instead of using curly braces
+ <tt>{ }</tt> to delimit blocks of code (like <a href="#functions">functions</a>,
+ <a href="#conditionals">if-statements</a>,
+ <a href="#switch">switch</a>, and <a href="#try">try/catch</a>),
+ use indentation.
+ </p>
+
+ <p>
+ You don't need to use parentheses to invoke a function if you're passing
+ arguments:<br /><tt>print "coffee"</tt>. Implicit parentheses wrap forwards
+ to the end of the line, or block expression.
+ </p>
+
+ <p>
+ You can use newlines to break up your expression into smaller pieces,
+ as long as CoffeeScript can determine that the line hasn't finished yet,
+ because it ends with an operator or a dot ... seen most commonly
+ in jQuery-chaining style JavaScript.
+ </p>
+
+ <p>
+ <span id="functions" class="bookmark"></span>
+ <b class="header">Functions and Invocation</b>
+ Functions are defined by a list of parameters, an arrow, and the
+ function body. The empty function looks like this: <tt>-></tt>
+ </p>
+ <div class='code'><pre class="idle"><span class="FunctionName">square </span><span class="Keyword">=</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">x</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> x <span class="Keyword">*</span> x
+<span class="FunctionName">cube </span><span class="Keyword">=</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">x</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> square(x) <span class="Keyword">*</span> x
+</pre><pre class="idle"><span class="Storage">var</span> cube, square;
+<span class="FunctionName">square</span> = <span class="Storage">function</span>(<span class="FunctionArgument">x</span>) {
+ <span class="Keyword">return</span> x <span class="Keyword">*</span> x;
+};
+<span class="FunctionName">cube</span> = <span class="Storage">function</span>(<span class="FunctionArgument">x</span>) {
+ <span class="Keyword">return</span> square(x) <span class="Keyword">*</span> x;
+};
+</pre><button onclick='javascript: var cube, square;
+square = function(x) {
+ return x * x;
+};
+cube = function(x) {
+ return square(x) * x;
+};;alert(cube(5));'>run: cube(5)</button><br class='clear' /></div>
+
+ <p>
+ <span id="objects_and_arrays" class="bookmark"></span>
+ <b class="header">Objects and Arrays</b>
+ Object and Array literals look very similar to their JavaScript cousins.
+ When you spread out each property on a separate line, the commas are
+ optional. Implicit objects may be created with indentation instead of
+ brackets, winding up looking quite similar to YAML.
+ </p>
+ <div class='code'><pre class="idle">song <span class="Keyword">=</span> [<span class="String"><span class="String">"</span>do<span class="String">"</span></span>, <span class="String"><span class="String">"</span>re<span class="String">"</span></span>, <span class="String"><span class="String">"</span>mi<span class="String">"</span></span>, <span class="String"><span class="String">"</span>fa<span class="String">"</span></span>, <span class="String"><span class="String">"</span>so<span class="String">"</span></span>]
+
+singers <span class="Keyword">=</span> {Jagger: <span class="String"><span class="String">"</span>Rock<span class="String">"</span></span>, Elvis: <span class="String"><span class="String">"</span>Roll<span class="String">"</span></span>}
+
+matrix <span class="Keyword">=</span> [
+ <span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">1</span>
+ <span class="Number">0</span>, <span class="Number">0</span>, <span class="Number">1</span>
+ <span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">0</span>
+]
+
+kids <span class="Keyword">=</span>
+ brother:
+ name: <span class="String"><span class="String">"</span>Max<span class="String">"</span></span>
+ age: <span class="Number">11</span>
+ sister:
+ name: <span class="String"><span class="String">"</span>Ida<span class="String">"</span></span>
+ age: <span class="Number">9</span>
+</pre><pre class="idle"><span class="Storage">var</span> kids, matrix, singers, song;
+song <span class="Keyword">=</span> [<span class="String"><span class="String">"</span>do<span class="String">"</span></span>, <span class="String"><span class="String">"</span>re<span class="String">"</span></span>, <span class="String"><span class="String">"</span>mi<span class="String">"</span></span>, <span class="String"><span class="String">"</span>fa<span class="String">"</span></span>, <span class="String"><span class="String">"</span>so<span class="String">"</span></span>];
+singers <span class="Keyword">=</span> {
+ Jagger: <span class="String"><span class="String">"</span>Rock<span class="String">"</span></span>,
+ Elvis: <span class="String"><span class="String">"</span>Roll<span class="String">"</span></span>
+};
+matrix <span class="Keyword">=</span> [<span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">0</span>, <span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">1</span>, <span class="Number">0</span>];
+kids <span class="Keyword">=</span> {
+ brother: {
+ name: <span class="String"><span class="String">"</span>Max<span class="String">"</span></span>,
+ age: <span class="Number">11</span>
+ },
+ sister: {
+ name: <span class="String"><span class="String">"</span>Ida<span class="String">"</span></span>,
+ age: <span class="Number">9</span>
+ }
+};
+</pre><button onclick='javascript: 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
+ }
+};;alert(song.join(","));'>run: song.join(",")</button><br class='clear' /></div>
+ <p>
+ In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties
+ of an object, without quoting them as strings. CoffeeScript notices and quotes
+ them for you, so you don't have to worry about it (say, when using jQuery).
+ </p>
+ <div class='code'><pre class="idle">$(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).css class: <span class="String"><span class="String">'</span>active<span class="String">'</span></span>
+</pre><pre class="idle"><span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.account<span class="String">'</span></span>).css({
+ <span class="String"><span class="String">"</span>class<span class="String">"</span></span>: <span class="String"><span class="String">'</span>active<span class="String">'</span></span>
+});
+</pre><br class='clear' /></div>
+
+ <p>
+ <span id="lexical_scope" class="bookmark"></span>
+ <b class="header">Lexical Scoping and Variable Safety</b>
+ The CoffeeScript compiler takes care to make sure that all of your variables
+ are properly declared within lexical scope — you never need to write
+ <tt>var</tt> yourself.
+ </p>
+ <div class='code'><pre class="idle">outer <span class="Keyword">=</span> <span class="Number">1</span>
+<span class="FunctionName">changeNumbers </span><span class="Keyword">=</span> <span class="Storage">-></span>
+ inner <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">1</span>
+ outer <span class="Keyword">=</span> <span class="Number">10</span>
+inner <span class="Keyword">=</span> changeNumbers()
+</pre><pre class="idle"><span class="Storage">var</span> changeNumbers, inner, outer;
+outer <span class="Keyword">=</span> <span class="Number">1</span>;
+<span class="FunctionName">changeNumbers</span> = <span class="Storage">function</span>() {
+ <span class="Storage">var</span> inner;
+ inner <span class="Keyword">=</span> <span class="Keyword">-</span><span class="Number">1</span>;
+ <span class="Keyword">return</span> (outer <span class="Keyword">=</span> <span class="Number">10</span>);
+};
+inner <span class="Keyword">=</span> changeNumbers();
+</pre><button onclick='javascript: var changeNumbers, inner, outer;
+outer = 1;
+changeNumbers = function() {
+ var inner;
+ inner = -1;
+ return (outer = 10);
+};
+inner = changeNumbers();;alert(inner);'>run: inner</button><br class='clear' /></div>
+ <p>
+ Notice how all of the variable declarations have been pushed up to
+ the top of the closest scope, the first time they appear.
+ <b>outer</b> is not redeclared within the inner function, because it's
+ already in scope; <b>inner</b> within the function, on the other hand,
+ should not be able to change the value of the external variable of the same name, and
+ therefore has a declaration of its own.
+ </p>
+ <p>
+ This behavior is effectively identical to Ruby's scope for local variables.
+ Because you don't have direct access to the <tt>var</tt> keyword,
+ it's impossible to shadow an outer variable on purpose, you may only refer
+ to it. So be careful that you're not reusing the name of an external
+ variable accidentally, if you're writing a deeply nested function.
+ </p>
+ <p>
+ Although suppressed within this documentation for clarity, all
+ CoffeeScript output is wrapped in an anonymous function:
+ <tt>(function(){ ... })();</tt> This safety wrapper, combined with the
+ automatic generation of the <tt>var</tt> keyword, make it exceedingly difficult
+ to pollute the global namespace by accident.
+ </p>
+ <p>
+ If you'd like to create top-level variables for other scripts to use,
+ attach them as properties on <b>window</b>, or on the <b>exports</b>
+ object in CommonJS. The <b>existential operator</b> (covered below), gives you a
+ reliable way to figure out where to add them, if you're targeting both
+ CommonJS and the browser: <tt>root = exports ? this</tt>
+ </p>
+
+ <p>
+ <span id="conditionals" class="bookmark"></span>
+ <b class="header">If, Else, Unless, and Conditional Assignment</b>
+ <b>If/else</b> statements can be written without the use of parentheses and
+ curly brackets. As with functions and other block expressions,
+ multi-line conditionals are delimited by indentation. There's also a handy
+ postfix form, with the <tt>if</tt> or <tt>unless</tt> at the end.
+ </p>
+ <p>
+ CoffeeScript can compile <b>if</b> statements into JavaScript expressions,
+ using the ternary operator when possible, and closure wrapping otherwise. There
+ is no explicit ternary statement in CoffeeScript — you simply use
+ a regular <b>if</b> statement inline.
+ </p>
+ <div class='code'><pre class="idle">mood <span class="Keyword">=</span> greatlyImproved <span class="Keyword">if</span> singing
+
+<span class="Keyword">if</span> happy <span class="Keyword">and</span> knowsIt
+ clapsHands()
+ chaChaCha()
+<span class="Keyword">else</span>
+ showIt()
+
+date <span class="Keyword">=</span> <span class="Keyword">if</span> friday <span class="Keyword">then</span> sue <span class="Keyword">else</span> jill
+
+options or<span class="Keyword">=</span> defaults
+</pre><pre class="idle"><span class="Storage">var</span> date, mood, options;
+<span class="Keyword">if</span> (singing) {
+ mood <span class="Keyword">=</span> greatlyImproved;
+}
+<span class="Keyword">if</span> (happy <span class="Keyword">&</span><span class="Keyword">&</span> knowsIt) {
+ clapsHands();
+ chaChaCha();
+} <span class="Keyword">else</span> {
+ showIt();
+}
+date <span class="Keyword">=</span> friday ? sue : jill;
+options <span class="Keyword">||</span> (options <span class="Keyword">=</span> defaults);
+</pre><br class='clear' /></div>
+
+ <p>
+ <span id="aliases" class="bookmark"></span>
+ <b class="header">Aliases</b>
+ Because the <tt>==</tt> operator frequently causes undesirable coercion,
+ is intransitive, and has a different meaning than in other languages,
+ CoffeeScript compiles <tt>==</tt> into <tt>===</tt>, and <tt>!=</tt> into
+ <tt>!==</tt>.
+ In addition, <tt>is</tt> compiles into <tt>===</tt>,
+ and <tt>isnt</tt> into <tt>!==</tt>.
+ </p>
+ <p>
+ You can use <tt>not</tt> as an alias for <tt>!</tt>.
+ </p>
+ <p>
+ For logic, <tt>and</tt> compiles to <tt>&&</tt>, and <tt>or</tt>
+ into <tt>||</tt>.
+ </p>
+ <p>
+ Instead of a newline or semicolon, <tt>then</tt> can be used to separate
+ conditions from expressions, in <b>while</b>,
+ <b>if</b>/<b>else</b>, and <b>switch</b>/<b>when</b> statements.
+ </p>
+ <p>
+ As in <a href="http://yaml.org/">YAML</a>, <tt>on</tt> and <tt>yes</tt>
+ are the same as boolean <tt>true</tt>, while <tt>off</tt> and <tt>no</tt> are boolean <tt>false</tt>.
+ </p>
+ <p>
+ For single-line statements, <tt>unless</tt> can be used as the inverse of <tt>if</tt>.
+ </p>
+ <p>
+ As a shortcut for <tt>this.property</tt>, you can use <tt>@property</tt>.
+ </p>
+ <p>
+ You can use <tt>in</tt> to test for array presence, and <tt>of</tt> to
+ test for JavaScript object-key presence.
+ </p>
+ <div class='code'><pre class="idle">launch() <span class="Keyword">if</span> ignition <span class="Keyword">is</span> <span class="BuiltInConstant">on</span>
+
+volume <span class="Keyword">=</span> <span class="Number">10</span> <span class="Keyword">if</span> band <span class="Keyword">isnt</span> SpinalTap
+
+letTheWildRumpusBegin() <span class="Keyword">unless</span> answer <span class="Keyword">is</span> <span class="BuiltInConstant">no</span>
+
+<span class="Keyword">if</span> car.speed <span class="Keyword"><</span> limit <span class="Keyword">then</span> accelerate()
+
+winner <span class="Keyword">=</span> <span class="BuiltInConstant">yes</span> <span class="Keyword">if</span> pick <span class="Keyword">in</span> [<span class="Number">47</span>, <span class="Number">92</span>, <span class="Number">13</span>]
+
+print inspect <span class="String"><span class="String">"</span>My name is <span class="String">"</span></span> <span class="Keyword">+</span> <span class="Variable">@name</span>
+</pre><pre class="idle"><span class="Storage">var</span> volume, winner;
+<span class="Keyword">if</span> (ignition <span class="Keyword">===</span> <span class="BuiltInConstant">true</span>) {
+ launch();
+}
+<span class="Keyword">if</span> (band <span class="Keyword">!</span><span class="Keyword">==</span> SpinalTap) {
+ volume <span class="Keyword">=</span> <span class="Number">10</span>;
+}
+<span class="Keyword">if</span> (answer <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">false</span>) {
+ letTheWildRumpusBegin();
+}
+<span class="Keyword">if</span> (car.speed <span class="Keyword"><</span> limit) {
+ accelerate();
+}
+<span class="Keyword">if</span> ((<span class="Number">47</span> <span class="Keyword">===</span> pick <span class="Keyword">||</span> <span class="Number">92</span> <span class="Keyword">===</span> pick <span class="Keyword">||</span> <span class="Number">13</span> <span class="Keyword">===</span> pick)) {
+ winner <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
+}
+<span class="LibraryFunction">print</span>(inspect(<span class="String"><span class="String">"</span>My name is <span class="String">"</span></span> <span class="Keyword">+</span> <span class="Variable">this</span>.<span class="LibraryConstant">name</span>));
+</pre><br class='clear' /></div>
+
+ <p>
+ <span id="splats" class="bookmark"></span>
+ <b class="header">Splats...</b>
+ The JavaScript <b>arguments object</b> is a useful way to work with
+ functions that accept variable numbers of arguments. CoffeeScript provides
+ splats <tt>...</tt>, both for function definition as well as invocation,
+ making variable numbers of arguments a little bit more palatable.
+ </p>
+ <div class='code'><pre class="idle">gold <span class="Keyword">=</span> silver <span class="Keyword">=</span> rest <span class="Keyword">=</span> <span class="String"><span class="String">"</span>unknown<span class="String">"</span></span>
+
+<span class="FunctionName">awardMedals </span><span class="Keyword">=</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">first, second, others...</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
+ gold <span class="Keyword">=</span> first
+ silver <span class="Keyword">=</span> second
+ rest <span class="Keyword">=</span> others
+
+contenders <span class="Keyword">=</span> [
+ <span class="String"><span class="String">"</span>Michael Phelps<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Liu Xiang<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Yao Ming<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Allyson Felix<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Shawn Johnson<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Roman Sebrle<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Guo Jingjing<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Tyson Gay<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Asafa Powell<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Usain Bolt<span class="String">"</span></span>
+]
+
+awardMedals contenders...
+
+alert <span class="String"><span class="String">"</span>Gold: <span class="String">"</span></span> <span class="Keyword">+</span> gold
+alert <span class="String"><span class="String">"</span>Silver: <span class="String">"</span></span> <span class="Keyword">+</span> silver
+alert <span class="String"><span class="String">"</span>The Field: <span class="String">"</span></span> <span class="Keyword">+</span> rest
+</pre><pre class="idle"><span class="Storage">var</span> awardMedals, contenders, gold, rest, silver;
+<span class="Storage">var</span> __slice <span class="Keyword">=</span> <span class="LibraryClassType">Array</span>.<span class="LibraryConstant">prototype</span>.slice;
+gold <span class="Keyword">=</span> (silver <span class="Keyword">=</span> (rest <span class="Keyword">=</span> <span class="String"><span class="String">"</span>unknown<span class="String">"</span></span>));
+<span class="FunctionName">awardMedals</span> = <span class="Storage">function</span>(<span class="FunctionArgument">first, second</span>) {
+ <span class="Storage">var</span> others;
+ others <span class="Keyword">=</span> __slice.<span class="LibraryFunction">call</span>(arguments, <span class="Number">2</span>);
+ gold <span class="Keyword">=</span> first;
+ silver <span class="Keyword">=</span> second;
+ <span class="Keyword">return</span> (rest <span class="Keyword">=</span> others);
+};
+contenders <span class="Keyword">=</span> [<span class="String"><span class="String">"</span>Michael Phelps<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Liu Xiang<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Yao Ming<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Allyson Felix<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Shawn Johnson<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Roman Sebrle<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Guo Jingjing<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Tyson Gay<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Asafa Powell<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Usain Bolt<span class="String">"</span></span>];
+awardMedals.<span class="LibraryFunction">apply</span>(awardMedals, contenders);
+<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">"</span>Gold: <span class="String">"</span></span> <span class="Keyword">+</span> gold);
+<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">"</span>Silver: <span class="String">"</span></span> <span class="Keyword">+</span> silver);
+<span class="LibraryFunction">alert</span>(<span class="String"><span class="String">"</span>The Field: <span class="String">"</span></span> <span class="Keyword">+</span> rest);
+</pre><button onclick='javascript: var awardMedals, contenders, gold, rest, silver;
+var __slice = Array.prototype.slice;
+gold = (silver = (rest = "unknown"));
+awardMedals = function(first, second) {
+ var others;
+ others = __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(awardMedals, contenders);
+alert("Gold: " + gold);
+alert("Silver: " + silver);
+alert("The Field: " + rest);;'>run</button><br class='clear' /></div>
+
+ <p>
+ <span id="while" class="bookmark"></span>
+ <b class="header">While, Until, and Loop</b>
+ The only low-level loop that CoffeeScript provides is the <b>while</b> loop. The
+ main difference from JavaScript is that the <b>while</b> loop can be used
+ as an expression, returning an array containing the result of each iteration
+ through the loop.
+ </p>
+ <div class='code'><pre class="idle"><span class="Comment"><span class="Comment">#</span> Econ 101</span>
+<span class="Keyword">if</span> <span class="Variable">this</span>.studyingEconomics
+ buy() <span class="Keyword">while</span> supply <span class="Keyword">></span> demand
+ sell() <span class="Keyword">until</span> supply <span class="Keyword">></span> demand
+
+<span class="Comment"><span class="Comment">#</span> Nursery Rhyme</span>
+num <span class="Keyword">=</span> <span class="Number">6</span>
+lyrics <span class="Keyword">=</span> <span class="Keyword">while</span> num <span class="Keyword">-</span><span class="Keyword">=</span> <span class="Number">1</span>
+ num <span class="Keyword">+</span> <span class="String"><span class="String">"</span> little monkeys, jumping on the bed.</span>
+<span class="String"> One fell out and bumped his head.<span class="String">"</span></span>
+</pre><pre class="idle"><span class="Storage">var</span> _result, lyrics, num;
+<span class="Keyword">if</span> (<span class="Variable">this</span>.studyingEconomics) {
+ <span class="Keyword">while</span> (supply <span class="Keyword">></span> demand) {
+ buy();
+ }
+ <span class="Keyword">while</span> (<span class="Keyword">!</span>(supply <span class="Keyword">></span> demand)) {
+ sell();
+ }
+}
+num <span class="Keyword">=</span> <span class="Number">6</span>;
+lyrics <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ _result <span class="Keyword">=</span> [];
+ <span class="Keyword">while</span> (num <span class="Keyword">-</span><span class="Keyword">=</span> <span class="Number">1</span>) {
+ _result.<span class="LibraryFunction">push</span>(num <span class="Keyword">+</span> <span class="String"><span class="String">"</span> little monkeys, jumping on the bed. One fell out and bumped his head.<span class="String">"</span></span>);
+ }
+ <span class="Keyword">return</span> _result;
+})();
+</pre><button onclick='javascript: var _result, lyrics, num;
+if (this.studyingEconomics) {
+ while (supply > demand) {
+ buy();
+ }
+ while (!(supply > demand)) {
+ sell();
+ }
+}
+num = 6;
+lyrics = (function() {
+ _result = [];
+ while (num -= 1) {
+ _result.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
+ }
+ return _result;
+})();;alert(lyrics.join("\n"));'>run: lyrics.join("\n")</button><br class='clear' /></div>
+ <p>
+ For readability, the <b>until</b> keyword is equivalent to <tt>while not</tt>,
+ and the <b>loop</b> keyword is equivalent to <tt>while true</tt>.
+ Other JavaScript loops, such as <b>for</b> loops and <b>do-while</b> loops
+ can be mimicked by variations on <b>loop</b>, but the hope is that you
+ won't need to do that with CoffeeScript, either because you're using
+ <b>each</b> (<b>forEach</b>) style iterators, or...
+ </p>
+
+ <p>
+ <span id="comprehensions" class="bookmark"></span>
+ <b class="header">Comprehensions (Arrays, Objects, and Ranges)</b>
+ For your looping needs, CoffeeScript provides array comprehensions
+ similar to Python's. They replace (and compile into) <b>for</b> loops, with
+ optional guard clauses and the value of the current array index.
+ Unlike for loops, array comprehensions are expressions, and can be returned
+ and assigned. They should be able to handle most places where you otherwise
+ would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>.
+ </p>
+ <div class='code'><pre class="idle"><span class="Comment"><span class="Comment">#</span> Eat lunch.</span>
+lunch <span class="Keyword">=</span> eat food <span class="Keyword">for</span> food <span class="Keyword">in</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>]
+
+<span class="Comment"><span class="Comment">#</span> Naive collision detection.</span>
+<span class="Keyword">for</span> roid, pos <span class="Keyword">in</span> asteroids
+ <span class="Keyword">for</span> roid2 <span class="Keyword">in</span> asteroids <span class="Keyword">when</span> roid <span class="Keyword">isnt</span> roid2
+ roid.explode() <span class="Keyword">if</span> roid.overlaps roid2
+</pre><pre class="idle"><span class="Storage">var</span> _i, _len, _len2, _ref, _result, food, lunch, pos, roid, roid2;
+lunch <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ _result <span class="Keyword">=</span> []; _ref <span class="Keyword">=</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>];
+ <span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _len <span class="Keyword">=</span> _ref.<span class="LibraryConstant">length</span>; _i <span class="Keyword"><</span> _len; _i<span class="Keyword">++</span>) {
+ food <span class="Keyword">=</span> _ref[_i];
+ _result.<span class="LibraryFunction">push</span>(eat(food));
+ }
+ <span class="Keyword">return</span> _result;
+})();
+<span class="Keyword">for</span> (pos <span class="Keyword">=</span> <span class="Number">0</span>, _len <span class="Keyword">=</span> asteroids.<span class="LibraryConstant">length</span>; pos <span class="Keyword"><</span> _len; pos<span class="Keyword">++</span>) {
+ roid <span class="Keyword">=</span> asteroids[pos];
+ <span class="Keyword">for</span> (_i <span class="Keyword">=</span> <span class="Number">0</span>, _len2 <span class="Keyword">=</span> asteroids.<span class="LibraryConstant">length</span>; _i <span class="Keyword"><</span> _len2; _i<span class="Keyword">++</span>) {
+ roid2 <span class="Keyword">=</span> asteroids[_i];
+ <span class="Keyword">if</span> (roid <span class="Keyword">!</span><span class="Keyword">==</span> roid2) {
+ <span class="Keyword">if</span> (roid.overlaps(roid2)) {
+ roid.explode();
+ }
+ }
+ }
+}
+</pre><br class='clear' /></div>
+ <p>
+ If you know the start and end of your loop, or would like to step through
+ in fixed-size increments, you can use a range to specify the start and
+ end of your comprehension.
+ </p>
+ <div class='code'><pre class="idle">countdown <span class="Keyword">=</span> num <span class="Keyword">for</span> num <span class="Keyword">in</span> [<span class="Number">10</span>..<span class="Number">1</span>]
+
+<span class="FunctionName">deliverEggs </span><span class="Keyword">=</span> <span class="Storage">-></span>
+ <span class="Keyword">for</span> i <span class="Keyword">in</span> [<span class="Number">0</span>...eggs.length] <span class="Keyword">by</span> <span class="Number">12</span>
+ dozen <span class="Keyword">=</span> eggs[i...i<span class="Keyword">+</span><span class="Number">12</span>]
+ deliver <span class="Keyword">new</span> <span class="TypeName">eggCarton</span> dozen
+</pre><pre class="idle"><span class="Storage">var</span> _result, countdown, deliverEggs, num;
+countdown <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ _result <span class="Keyword">=</span> [];
+ <span class="Keyword">for</span> (num <span class="Keyword">=</span> <span class="Number">10</span>; num <span class="Keyword">>=</span> <span class="Number">1</span>; num<span class="Keyword">--</span>) {
+ _result.<span class="LibraryFunction">push</span>(num);
+ }
+ <span class="Keyword">return</span> _result;
+})();
+<span class="FunctionName">deliverEggs</span> = <span class="Storage">function</span>() {
+ <span class="Storage">var</span> _ref, _result2, dozen, i;
+ _result2 <span class="Keyword">=</span> []; _ref <span class="Keyword">=</span> eggs.<span class="LibraryConstant">length</span>;
+ <span class="Keyword">for</span> (i <span class="Keyword">=</span> <span class="Number">0</span>; (<span class="Number">0</span> <span class="Keyword"><=</span> _ref ? i <span class="Keyword"><</span> _ref : i <span class="Keyword">></span> _ref); i <span class="Keyword">+</span><span class="Keyword">=</span> <span class="Number">12</span>) {
+ _result2.<span class="LibraryFunction">push</span>((<span class="Storage">function</span>() {
+ dozen <span class="Keyword">=</span> eggs.<span class="LibraryFunction">slice</span>(i, i <span class="Keyword">+</span> <span class="Number">12</span>);
+ <span class="Keyword">return</span> deliver(<span class="Keyword">new</span> <span class="TypeName">eggCarton</span>(dozen));
+ })());
+ }
+ <span class="Keyword">return</span> _result2;
+};
+</pre><button onclick='javascript: var _result, countdown, deliverEggs, num;
+countdown = (function() {
+ _result = [];
+ for (num = 10; num >= 1; num--) {
+ _result.push(num);
+ }
+ return _result;
+})();
+deliverEggs = function() {
+ var _ref, _result2, dozen, i;
+ _result2 = []; _ref = eggs.length;
+ for (i = 0; (0 <= _ref ? i < _ref : i > _ref); i += 12) {
+ _result2.push((function() {
+ dozen = eggs.slice(i, i + 12);
+ return deliver(new eggCarton(dozen));
+ })());
+ }
+ return _result2;
+};;alert(countdown);'>run: countdown</button><br class='clear' /></div>
+ <p>
+ Comprehensions can also be used to iterate over the keys and values in
+ an object. Use <tt>of</tt> to signal comprehension over the properties of
+ an object instead of the values in an array.
+ </p>
+ <div class='code'><pre class="idle">yearsOld <span class="Keyword">=</span> max: <span class="Number">10</span>, ida: <span class="Number">9</span>, tim: <span class="Number">11</span>
+
+ages <span class="Keyword">=</span> <span class="Keyword">for</span> child, age <span class="Keyword">of</span> yearsOld
+ child <span class="Keyword">+</span> <span class="String"><span class="String">"</span> is <span class="String">"</span></span> <span class="Keyword">+</span> age
+</pre><pre class="idle"><span class="Storage">var</span> _result, age, ages, child, yearsOld;
+<span class="Storage">var</span> __hasProp <span class="Keyword">=</span> <span class="LibraryClassType">Object</span>.<span class="LibraryConstant">prototype</span>.hasOwnProperty;
+yearsOld <span class="Keyword">=</span> {
+ max: <span class="Number">10</span>,
+ ida: <span class="Number">9</span>,
+ tim: <span class="Number">11</span>
+};
+ages <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ _result <span class="Keyword">=</span> [];
+ <span class="Keyword">for</span> (child <span class="Keyword">in</span> yearsOld) {
+ <span class="Keyword">if</span> (<span class="Keyword">!</span>__hasProp.<span class="LibraryFunction">call</span>(yearsOld, child)) <span class="Keyword">continue</span>;
+ age <span class="Keyword">=</span> yearsOld[child];
+ _result.<span class="LibraryFunction">push</span>(child <span class="Keyword">+</span> <span class="String"><span class="String">"</span> is <span class="String">"</span></span> <span class="Keyword">+</span> age);
+ }
+ <span class="Keyword">return</span> _result;
+})();
+</pre><button onclick='javascript: var _result, age, ages, child, yearsOld;
+var __hasProp = Object.prototype.hasOwnProperty;
+yearsOld = {
+ max: 10,
+ ida: 9,
+ tim: 11
+};
+ages = (function() {
+ _result = [];
+ for (child in yearsOld) {
+ if (!__hasProp.call(yearsOld, child)) continue;
+ age = yearsOld[child];
+ _result.push(child + " is " + age);
+ }
+ return _result;
+})();;alert(ages.join(", "));'>run: ages.join(", ")</button><br class='clear' /></div>
+ <p>
+ By default, object comprehensions are safe, and use a <tt>hasOwnProperty</tt>
+ check to make sure that you're dealing with properties on the current
+ object. If you'd like the regular JavaScript <br /><tt>for (key in obj) ...</tt>
+ loop, for speed or for another reason, you can use <br />
+ <tt>for all key, value of object</tt> in CoffeeScript.
+ </p>
+
+ <p>
+ <span id="slice_splice" class="bookmark"></span>
+ <b class="header">Array Slicing and Splicing with Ranges</b>
+ CoffeeScript borrows Ruby's
+ <a href="http://ruby-doc.org/core/classes/Range.html">range syntax</a>
+ for extracting slices of arrays. With two dots (<tt>3..5</tt>), the range
+ is inclusive: the first argument is the index of the first element in
+ the slice, and the second is the index of the last one. Three dots signify
+ a range that excludes the end.
+ </p>
+ <div class='code'><pre class="idle">numbers <span class="Keyword">=</span> [<span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>, <span class="Number">6</span>, <span class="Number">7</span>, <span class="Number">8</span>, <span class="Number">9</span>]
+
+threeToSix <span class="Keyword">=</span> numbers[<span class="Number">3</span>..<span class="Number">6</span>]
+
+copy <span class="Keyword">=</span> numbers[<span class="Number">0</span>...numbers.length]
+
+</pre><pre class="idle"><span class="Storage">var</span> copy, numbers, threeToSix;
+numbers <span class="Keyword">=</span> [<span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>, <span class="Number">6</span>, <span class="Number">7</span>, <span class="Number">8</span>, <span class="Number">9</span>];
+threeToSix <span class="Keyword">=</span> numbers.<span class="LibraryFunction">slice</span>(<span class="Number">3</span>, <span class="Number">6</span> <span class="Keyword">+</span> <span class="Number">1</span>);
+copy <span class="Keyword">=</span> numbers.<span class="LibraryFunction">slice</span>(<span class="Number">0</span>, numbers.<span class="LibraryConstant">length</span>);
+</pre><button onclick='javascript: var copy, numbers, threeToSix;
+numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+threeToSix = numbers.slice(3, 6 + 1);
+copy = numbers.slice(0, numbers.length);;alert(copy);'>run: copy</button><br class='clear' /></div>
+ <p>
+ The same syntax can be used with assignment to replace a segment of an
+ array with new values (to splice it).
+ </p>
+ <div class='code'><pre class="idle">numbers <span class="Keyword">=</span> [<span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>, <span class="Number">6</span>, <span class="Number">7</span>, <span class="Number">8</span>, <span class="Number">9</span>]
+
+numbers[<span class="Number">3</span>..<span class="Number">6</span>] <span class="Keyword">=</span> [<span class="Keyword">-</span><span class="Number">3</span>, <span class="Keyword">-</span><span class="Number">4</span>, <span class="Keyword">-</span><span class="Number">5</span>, <span class="Keyword">-</span><span class="Number">6</span>]
+
+
+</pre><pre class="idle"><span class="Storage">var</span> _ref, numbers;
+numbers <span class="Keyword">=</span> [<span class="Number">0</span>, <span class="Number">1</span>, <span class="Number">2</span>, <span class="Number">3</span>, <span class="Number">4</span>, <span class="Number">5</span>, <span class="Number">6</span>, <span class="Number">7</span>, <span class="Number">8</span>, <span class="Number">9</span>];
+([].splice.<span class="LibraryFunction">apply</span>(numbers, [<span class="Number">3</span>, <span class="Number">6</span> <span class="Keyword">-</span> <span class="Number">3</span> <span class="Keyword">+</span> <span class="Number">1</span>].<span class="LibraryFunction">concat</span>(_ref <span class="Keyword">=</span> [<span class="Keyword">-</span><span class="Number">3</span>, <span class="Keyword">-</span><span class="Number">4</span>, <span class="Keyword">-</span><span class="Number">5</span>, <span class="Keyword">-</span><span class="Number">6</span>])), _ref);
+</pre><button onclick='javascript: var _ref, numbers;
+numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+([].splice.apply(numbers, [3, 6 - 3 + 1].concat(_ref = [-3, -4, -5, -6])), _ref);;alert(numbers);'>run: numbers</button><br class='clear' /></div>
+
+ <p>
+ <span id="expressions" class="bookmark"></span>
+ <b class="header">Everything is an Expression (at least, as much as possible)</b>
+ You might have noticed how even though we don't add return statements
+ to CoffeeScript functions, they nonetheless return their final value.
+ The CoffeeScript compiler tries to make sure that all statements in the
+ language can be used as expressions. Watch how the <tt>return</tt> gets
+ pushed down into each possible branch of execution, in the function
+ below.
+ </p>
+ <div class='code'><pre class="idle"><span class="FunctionName">grade </span><span class="Keyword">=</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">student</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
+ <span class="Keyword">if</span> student.excellentWork
+ <span class="String"><span class="String">"</span>A+<span class="String">"</span></span>
+ <span class="Keyword">else</span> <span class="Keyword">if</span> student.okayStuff
+ <span class="Keyword">if</span> student.triedHard <span class="Keyword">then</span> <span class="String"><span class="String">"</span>B<span class="String">"</span></span> <span class="Keyword">else</span> <span class="String"><span class="String">"</span>B-<span class="String">"</span></span>
+ <span class="Keyword">else</span>
+ <span class="String"><span class="String">"</span>C<span class="String">"</span></span>
+
+eldest <span class="Keyword">=</span> <span class="Keyword">if</span> <span class="Number">24</span> <span class="Keyword">></span> <span class="Number">21</span> <span class="Keyword">then</span> <span class="String"><span class="String">"</span>Liz<span class="String">"</span></span> <span class="Keyword">else</span> <span class="String"><span class="String">"</span>Ike<span class="String">"</span></span>
+</pre><pre class="idle"><span class="Storage">var</span> eldest, grade;
+<span class="FunctionName">grade</span> = <span class="Storage">function</span>(<span class="FunctionArgument">student</span>) {
+ <span class="Keyword">return</span> student.excellentWork ? <span class="String"><span class="String">"</span>A+<span class="String">"</span></span> : (student.okayStuff ? (student.triedHard ? <span class="String"><span class="String">"</span>B<span class="String">"</span></span> : <span class="String"><span class="String">"</span>B-<span class="String">"</span></span>) : <span class="String"><span class="String">"</span>C<span class="String">"</span></span>);
+};
+eldest <span class="Keyword">=</span> <span class="Number">24</span> <span class="Keyword">></span> <span class="Number">21</span> ? <span class="String"><span class="String">"</span>Liz<span class="String">"</span></span> : <span class="String"><span class="String">"</span>Ike<span class="String">"</span></span>;
+</pre><button onclick='javascript: var eldest, grade;
+grade = function(student) {
+ return student.excellentWork ? "A+" : (student.okayStuff ? (student.triedHard ? "B" : "B-") : "C");
+};
+eldest = 24 > 21 ? "Liz" : "Ike";;alert(eldest);'>run: eldest</button><br class='clear' /></div>
+ <p>
+ Even though functions will always return their final value, it's both possible
+ and encouraged to return early from a function body writing out the explicit
+ return (<tt>return value</tt>), when you know that you're done.
+ </p>
+ <p>
+ Because variable declarations occur at the top of scope, assignment can
+ be used within expressions, even for variables that haven't been seen before:
+ </p>
+ <div class='code'><pre class="idle">six <span class="Keyword">=</span> (one <span class="Keyword">=</span> <span class="Number">1</span>) <span class="Keyword">+</span> (two <span class="Keyword">=</span> <span class="Number">2</span>) <span class="Keyword">+</span> (three <span class="Keyword">=</span> <span class="Number">3</span>)
+</pre><pre class="idle"><span class="Storage">var</span> one, six, three, two;
+six <span class="Keyword">=</span> (one <span class="Keyword">=</span> <span class="Number">1</span>) <span class="Keyword">+</span> (two <span class="Keyword">=</span> <span class="Number">2</span>) <span class="Keyword">+</span> (three <span class="Keyword">=</span> <span class="Number">3</span>);
+</pre><button onclick='javascript: var one, six, three, two;
+six = (one = 1) + (two = 2) + (three = 3);;alert(six);'>run: six</button><br class='clear' /></div>
+ <p>
+ Things that would otherwise be statements in JavaScript, when used
+ as part of an expression in CoffeeScript, are converted into expressions
+ by wrapping them in a closure. This lets you do useful things, like assign
+ the result of a comprehension to a variable:
+ </p>
+ <div class='code'><pre class="idle"><span class="Comment"><span class="Comment">#</span> The first ten global properties.</span>
+
+globals <span class="Keyword">=</span> (name <span class="Keyword">for</span> name <span class="Keyword">of</span> window)[<span class="Number">0</span>...<span class="Number">10</span>]
+</pre><pre class="idle"><span class="Storage">var</span> _result, globals, name;
+<span class="Storage">var</span> __hasProp <span class="Keyword">=</span> <span class="LibraryClassType">Object</span>.<span class="LibraryConstant">prototype</span>.hasOwnProperty;
+globals <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ _result <span class="Keyword">=</span> [];
+ <span class="Keyword">for</span> (name <span class="Keyword">in</span> <span class="LibraryClassType">window</span>) {
+ <span class="Keyword">if</span> (<span class="Keyword">!</span>__hasProp.<span class="LibraryFunction">call</span>(<span class="LibraryClassType">window</span>, name)) <span class="Keyword">continue</span>;
+ _result.<span class="LibraryFunction">push</span>(name);
+ }
+ <span class="Keyword">return</span> _result;
+})().<span class="LibraryFunction">slice</span>(<span class="Number">0</span>, <span class="Number">10</span>);
+</pre><button onclick='javascript: var _result, globals, name;
+var __hasProp = Object.prototype.hasOwnProperty;
+globals = (function() {
+ _result = [];
+ for (name in window) {
+ if (!__hasProp.call(window, name)) continue;
+ _result.push(name);
+ }
+ return _result;
+})().slice(0, 10);;alert(globals);'>run: globals</button><br class='clear' /></div>
+ <p>
+ As well as silly things, like passing a <b>try/catch</b> statement directly
+ into a function call:
+ </p>
+ <div class='code'><pre class="idle">alert(
+ <span class="Keyword">try</span>
+ nonexistent <span class="Keyword">/</span> <span class="BuiltInConstant">undefined</span>
+ <span class="Keyword">catch</span> error
+ <span class="String"><span class="String">"</span>And the error is ... <span class="String">"</span></span> <span class="Keyword">+</span> error
+)
+</pre><pre class="idle"><span class="LibraryFunction">alert</span>((<span class="Storage">function</span>() {
+ <span class="Keyword">try</span> {
+ <span class="Keyword">return</span> nonexistent / undefined;
+ } <span class="Keyword">catch</span> (error) {
+ <span class="Keyword">return</span> <span class="String"><span class="String">"</span>And the error is ... <span class="String">"</span></span> <span class="Keyword">+</span> error;
+ }
+})());
+</pre><button onclick='javascript: alert((function() {
+ try {
+ return nonexistent / undefined;
+ } catch (error) {
+ return "And the error is ... " + error;
+ }
+})());;'>run</button><br class='clear' /></div>
+ <p>
+ There are a handful of statements in JavaScript that can't be meaningfully
+ converted into expressions, namely <tt>break</tt>, <tt>continue</tt>,
+ and <tt>return</tt>. If you make use of them within a block of code,
+ CoffeeScript won't try to perform the conversion.
+ </p>
+
+ <p>
+ <span id="existence" class="bookmark"></span>
+ <b class="header">The Existential Operator</b>
+ It's a little difficult to check for the existence of a variable in
+ JavaScript. <tt>if (variable) ...</tt> comes close, but fails for zero,
+ the empty string, and false. CoffeeScript's existential operator <tt>?</tt> returns true unless
+ a variable is <b>null</b> or <b>undefined</b>, which makes it analogous
+ to Ruby's <tt>nil?</tt>
+ </p>
+ <p>
+ It can also be used for safer conditional assignment than <tt>||=</tt>
+ provides, for cases where you may be handling numbers or strings.
+ </p>
+ <div class='code'><pre class="idle">solipsism <span class="Keyword">=</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> mind<span class="Keyword">?</span> <span class="Keyword">and</span> <span class="Keyword">not</span> world<span class="Keyword">?</span>
+
+speed <span class="Keyword">?</span><span class="Keyword">=</span> <span class="Number">140</span>
+
+
+
+
+
+</pre><pre class="idle"><span class="Storage">var</span> solipsism, speed;
+<span class="Keyword">if</span> ((<span class="Keyword">typeof</span> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> mind <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) <span class="Keyword">&</span><span class="Keyword">&</span> <span class="Keyword">!</span>(<span class="Keyword">typeof</span> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> world <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>)) {
+ solipsism <span class="Keyword">=</span> <span class="BuiltInConstant">true</span>;
+}
+(<span class="Keyword">typeof</span> speed <span class="Keyword">!</span><span class="Keyword">==</span> <span class="String"><span class="String">"</span>undefined<span class="String">"</span></span> <span class="Keyword">&</span><span class="Keyword">&</span> speed <span class="Keyword">!</span><span class="Keyword">==</span> <span class="BuiltInConstant">null</span>) ? speed : (speed <span class="Keyword">=</span> <span class="Number">140</span>);
+</pre><button onclick='javascript: var solipsism, speed;
+if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
+ solipsism = true;
+}
+(typeof speed !== "undefined" && speed !== null) ? speed : (speed = 140);;alert(speed);'>run: speed</button><br class='clear' /></div>
+ <p>
+ The accessor variant of the existential operator <tt>?.</tt> can be used to soak
+ up null references in a chain of properties. Use it instead
+ of the dot accessor <tt>.</tt> in cases where the base value may be <b>null</b>
+ or <b>undefined</b>. If all of the properties exist then you'll get the expected
+ result, if the chain is broken, <b>undefined</b> is returned instead of
+ the <b>TypeError</b> that would be raised otherwise.
+ </p>
+ <div class='code'><pre class="idle">lottery.drawWinner()<span class="Keyword">?</span>.address<span class="Keyword">?</span>.zipcode
+</pre><pre class="idle"><span class="Storage">var</span> _ref, _ref2;
+(((_ref <span class="Keyword">=</span> lottery.drawWinner()) <span class="Keyword">!</span><span class="Keyword">=</span> <span class="BuiltInConstant">null</span>) ? (((_ref2 <span class="Keyword">=</span> _ref.address) <span class="Keyword">!</span><span class="Keyword">=</span> <span class="BuiltInConstant">null</span>) ? _ref2.zipcode : undefined) : undefined);
+</pre><br class='clear' /></div>
+ <p>
+ Soaking up nulls is similar to Ruby's
+ <a href="http://andand.rubyforge.org/">andand gem</a>, and to the
+ <a href="http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator%28%3F.%29">safe navigation operator</a>
+ in Groovy.
+ </p>
+
+ <p>
+ <span id="classes" class="bookmark"></span>
+ <b class="header">Classes, Inheritance, and Super</b>
+ JavaScript's prototypal inheritance has always been a bit of a
+ brain-bender, with a whole family tree of libraries that provide a cleaner
+ syntax for classical inheritance on top of JavaScript's prototypes:
+ <a href="http://code.google.com/p/base2/">Base2</a>,
+ <a href="http://prototypejs.org/">Prototype.js</a>,
+ <a href="http://jsclass.jcoglan.com/">JS.Class</a>, etc.
+ The libraries provide syntactic sugar, but the built-in inheritance would
+ be completely usable if it weren't for a couple of small exceptions:
+ it's awkward to call <b>super</b> (the prototype object's
+ implementation of the current function), and it's awkward to correctly
+ set the prototype chain.
+ </p>
+ <p>
+ Instead of repetitively attaching functions to a prototype, CoffeeScript
+ provides a basic <tt>class</tt> structure that allows you to name your class,
+ set the superclass, assign prototypal properties, and define the constructor,
+ in a single assignable expression.
+ </p>
+ <div class='code'><pre class="idle"><span class="Storage">class</span> <span class="TypeName">Animal</span>
+ <span class="FunctionName">constructor</span><span class="Keyword">:</span> (<span class="Variable">@name</span>) <span class="Storage">-></span>
+
+ <span class="FunctionName">move</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">meters</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
+ alert <span class="Variable">@name</span> <span class="Keyword">+</span> <span class="String"><span class="String">"</span> moved <span class="String">"</span></span> <span class="Keyword">+</span> meters <span class="Keyword">+</span> <span class="String"><span class="String">"</span>m.<span class="String">"</span></span>
+
+<span class="Storage">class</span> <span class="TypeName">Snake</span><span class="InheritedClass"> <span class="Keyword">extends</span> Animal</span>
+ <span class="FunctionName">move</span><span class="Keyword">:</span> <span class="Storage">-></span>
+ alert <span class="String"><span class="String">"</span>Slithering...<span class="String">"</span></span>
+ <span class="Variable">super</span> <span class="Number">5</span>
+
+<span class="Storage">class</span> <span class="TypeName">Horse</span><span class="InheritedClass"> <span class="Keyword">extends</span> Animal</span>
+ <span class="FunctionName">move</span><span class="Keyword">:</span> <span class="Storage">-></span>
+ alert <span class="String"><span class="String">"</span>Galloping...<span class="String">"</span></span>
+ <span class="Variable">super</span> <span class="Number">45</span>
+
+sam <span class="Keyword">=</span> <span class="Keyword">new</span> <span class="TypeName">Snake</span> <span class="String"><span class="String">"</span>Sammy the Python<span class="String">"</span></span>
+tom <span class="Keyword">=</span> <span class="Keyword">new</span> <span class="TypeName">Horse</span> <span class="String"><span class="String">"</span>Tommy the Palomino<span class="String">"</span></span>
+
+sam.move()
+tom.move()
+
+
+
+
+</pre><pre class="idle"><span class="Storage">var</span> Animal, Horse, Snake, sam, tom;
+<span class="Storage">var</span> <span class="FunctionName">__extends</span> = <span class="Storage">function</span>(<span class="FunctionArgument">child, parent</span>) {
+ <span class="Storage">var</span> <span class="FunctionName">ctor</span> = <span class="Storage">function</span>() {};
+ <span class="LibraryClassType">ctor</span>.<span class="LibraryConstant">prototype</span> = parent.<span class="LibraryConstant">prototype</span>;
+ <span class="LibraryClassType">child</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">ctor</span>();
+ <span class="LibraryClassType">child</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">constructor</span> = child;
+ <span class="Keyword">if</span> (<span class="Keyword">typeof</span> parent.extended <span class="Keyword">===</span> <span class="String"><span class="String">"</span>function<span class="String">"</span></span>) parent.extended(child);
+ child.__super__ <span class="Keyword">=</span> parent.<span class="LibraryConstant">prototype</span>;
+};
+Animal <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ <span class="Keyword">return</span> <span class="Storage">function</span> <span class="FunctionName">Animal</span>(<span class="FunctionArgument">_arg</span>) {
+ <span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> _arg;
+ <span class="Keyword">return</span> <span class="Variable">this</span>;
+ };
+})();
+<span class="LibraryClassType">Animal</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>(<span class="FunctionArgument">meters</span>) {
+ <span class="Keyword">return</span> <span class="LibraryFunction">alert</span>(<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">+</span> <span class="String"><span class="String">"</span> moved <span class="String">"</span></span> <span class="Keyword">+</span> meters <span class="Keyword">+</span> <span class="String"><span class="String">"</span>m.<span class="String">"</span></span>);
+};
+Snake <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ <span class="Keyword">return</span> <span class="Storage">function</span> <span class="FunctionName">Snake</span>() {
+ <span class="Keyword">return</span> Animal.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
+ };
+})();
+__extends(Snake, Animal);
+<span class="LibraryClassType">Snake</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>() {
+ <span class="LibraryFunction">alert</span>(<span class="String"><span class="String">"</span>Slithering...<span class="String">"</span></span>);
+ <span class="Keyword">return</span> Snake.__super__.move.<span class="LibraryFunction">call</span>(<span class="Variable">this</span>, <span class="Number">5</span>);
+};
+Horse <span class="Keyword">=</span> (<span class="Storage">function</span>() {
+ <span class="Keyword">return</span> <span class="Storage">function</span> <span class="FunctionName">Horse</span>() {
+ <span class="Keyword">return</span> Animal.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
+ };
+})();
+__extends(Horse, Animal);
+<span class="LibraryClassType">Horse</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">move</span> = <span class="Storage">function</span>() {
+ <span class="LibraryFunction">alert</span>(<span class="String"><span class="String">"</span>Galloping...<span class="String">"</span></span>);
+ <span class="Keyword">return</span> Horse.__super__.move.<span class="LibraryFunction">call</span>(<span class="Variable">this</span>, <span class="Number">45</span>);
+};
+sam <span class="Keyword">=</span> <span class="Keyword">new</span> <span class="TypeName">Snake</span>(<span class="String"><span class="String">"</span>Sammy the Python<span class="String">"</span></span>);
+tom <span class="Keyword">=</span> <span class="Keyword">new</span> <span class="TypeName">Horse</span>(<span class="String"><span class="String">"</span>Tommy the Palomino<span class="String">"</span></span>);
+sam.move();
+tom.move();
+</pre><button onclick='javascript: var Animal, Horse, Snake, sam, tom;
+var __extends = function(child, parent) {
+ var ctor = function() {};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+};
+Animal = (function() {
+ return function Animal(_arg) {
+ this.name = _arg;
+ return this;
+ };
+})();
+Animal.prototype.move = function(meters) {
+ return alert(this.name + " moved " + meters + "m.");
+};
+Snake = (function() {
+ return function Snake() {
+ return Animal.apply(this, arguments);
+ };
+})();
+__extends(Snake, Animal);
+Snake.prototype.move = function() {
+ alert("Slithering...");
+ return Snake.__super__.move.call(this, 5);
+};
+Horse = (function() {
+ return function Horse() {
+ return Animal.apply(this, arguments);
+ };
+})();
+__extends(Horse, Animal);
+Horse.prototype.move = function() {
+ alert("Galloping...");
+ return Horse.__super__.move.call(this, 45);
+};
+sam = new Snake("Sammy the Python");
+tom = new Horse("Tommy the Palomino");
+sam.move();
+tom.move();;'>run</button><br class='clear' /></div>
+ <p>
+ If structuring your prototypes classically isn't your cup of tea, CoffeeScript
+ provides a couple of lower-level conveniences. The <tt>extends</tt> operator
+ helps with proper prototype setup, <tt>::</tt> gives you
+ quick access to an object's prototype, and <tt>super()</tt>
+ is converted into a call against the immediate ancestor's method of the same name.
+ </p>
+ <div class='code'><pre class="idle"><span class="FunctionName">String::dasherize </span><span class="Keyword">=</span> <span class="Storage">-></span>
+ <span class="Variable">this</span>.replace <span class="String">/_/g</span>, <span class="String"><span class="String">"</span>-<span class="String">"</span></span>
+</pre><pre class="idle"><span class="LibraryClassType">String</span>.<span class="LibraryConstant">prototype</span>.<span class="FunctionName">dasherize</span> = <span class="Storage">function</span>() {
+ <span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryFunction">replace</span>(<span class="String"><span class="String">/</span>_<span class="String">/</span>g</span>, <span class="String"><span class="String">"</span>-<span class="String">"</span></span>);
+};
+</pre><button onclick='javascript: String.prototype.dasherize = function() {
+ return this.replace(/_/g, "-");
+};;alert("one_two".dasherize());'>run: "one_two".dasherize()</button><br class='clear' /></div>
+ <p>
+ Finally, you may assign Class-level (static) properties within a class
+ definition by using<br /><tt>@property: value</tt>
+ </p>
+
+ <p>
+ <span id="pattern_matching" class="bookmark"></span>
+ <b class="header">Pattern Matching (Destructuring Assignment)</b>
+ To make extracting values from complex arrays and objects more convenient,
+ CoffeeScript implements ECMAScript Harmony's proposed
+ <a href="http://wiki.ecmascript.org/doku.php?id=harmony:destructuring">destructuring assignment</a>
+ syntax. When you assign an array or object literal to a value, CoffeeScript
+ breaks up and matches both sides against each other, assigning the values
+ on the right to the variables on the left. In the simplest case, it can be
+ used for parallel assignment:
+ </p>
+ <div class='code'><pre class="idle">theBait <span class="Keyword">=</span> <span class="Number">1000</span>
+theSwitch <span class="Keyword">=</span> <span class="Number">0</span>
+
+<span class="Keyword">[</span>theBait, theSwitch<span class="Keyword">] =</span> [theSwitch, theBait]
+</pre><pre class="idle"><span class="Storage">var</span> _ref, theBait, theSwitch;
+theBait <span class="Keyword">=</span> <span class="Number">1000</span>;
+theSwitch <span class="Keyword">=</span> <span class="Number">0</span>;
+_ref <span class="Keyword">=</span> [theSwitch, theBait], theBait <span class="Keyword">=</span> _ref[<span class="Number">0</span>], theSwitch <span class="Keyword">=</span> _ref[<span class="Number">1</span>];
+</pre><button onclick='javascript: var _ref, theBait, theSwitch;
+theBait = 1000;
+theSwitch = 0;
+_ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];;alert(theBait);'>run: theBait</button><br class='clear' /></div>
+ <p>
+ But it's also helpful for dealing with functions that return multiple
+ values.
+ </p>
+ <div class='code'><pre class="idle"><span class="FunctionName">weatherReport </span><span class="Keyword">=</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">location</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
+ <span class="Comment"><span class="Comment">#</span> Make an Ajax request to fetch the weather...</span>
+ [location, <span class="Number">72</span>, <span class="String"><span class="String">"</span>Mostly Sunny<span class="String">"</span></span>]
+
+<span class="Keyword">[</span>city, temp, forecast<span class="Keyword">] =</span> weatherReport <span class="String"><span class="String">"</span>Berkeley, CA<span class="String">"</span></span>
+</pre><pre class="idle"><span class="Storage">var</span> _ref, city, forecast, temp, weatherReport;
+<span class="FunctionName">weatherReport</span> = <span class="Storage">function</span>(<span class="FunctionArgument">location</span>) {
+ <span class="Keyword">return</span> [location, <span class="Number">72</span>, <span class="String"><span class="String">"</span>Mostly Sunny<span class="String">"</span></span>];
+};
+_ref <span class="Keyword">=</span> weatherReport(<span class="String"><span class="String">"</span>Berkeley, CA<span class="String">"</span></span>), city <span class="Keyword">=</span> _ref[<span class="Number">0</span>], temp <span class="Keyword">=</span> _ref[<span class="Number">1</span>], forecast <span class="Keyword">=</span> _ref[<span class="Number">2</span>];
+</pre><button onclick='javascript: var _ref, city, forecast, temp, weatherReport;
+weatherReport = function(location) {
+ return [location, 72, "Mostly Sunny"];
+};
+_ref = weatherReport("Berkeley, CA"), city = _ref[0], temp = _ref[1], forecast = _ref[2];;alert(forecast);'>run: forecast</button><br class='clear' /></div>
+ <p>
+ Pattern matching can be used with any depth of array and object nesting,
+ to help pull out deeply nested properties.
+ </p>
+ <div class='code'><pre class="idle">futurists <span class="Keyword">=</span>
+ sculptor: <span class="String"><span class="String">"</span>Umberto Boccioni<span class="String">"</span></span>
+ painter: <span class="String"><span class="String">"</span>Vladimir Burliuk<span class="String">"</span></span>
+ poet:
+ name: <span class="String"><span class="String">"</span>F.T. Marinetti<span class="String">"</span></span>
+ address: [
+ <span class="String"><span class="String">"</span>Via Roma 42R<span class="String">"</span></span>
+ <span class="String"><span class="String">"</span>Bellagio, Italy 22021<span class="String">"</span></span>
+ ]
+
+<span class="Keyword">{</span>poet: {name, address: [street, city]}<span class="Keyword">} =</span> futurists
+</pre><pre class="idle"><span class="Storage">var</span> _ref, _ref2, city, futurists, name, street;
+futurists <span class="Keyword">=</span> {
+ sculptor: <span class="String"><span class="String">"</span>Umberto Boccioni<span class="String">"</span></span>,
+ painter: <span class="String"><span class="String">"</span>Vladimir Burliuk<span class="String">"</span></span>,
+ poet: {
+ name: <span class="String"><span class="String">"</span>F.T. Marinetti<span class="String">"</span></span>,
+ address: [<span class="String"><span class="String">"</span>Via Roma 42R<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Bellagio, Italy 22021<span class="String">"</span></span>]
+ }
+};
+_ref <span class="Keyword">=</span> futurists.poet, name <span class="Keyword">=</span> _ref.<span class="LibraryConstant">name</span>, _ref2 <span class="Keyword">=</span> _ref.address, street <span class="Keyword">=</span> _ref2[<span class="Number">0</span>], city <span class="Keyword">=</span> _ref2[<span class="Number">1</span>];
+</pre><button onclick='javascript: var _ref, _ref2, city, futurists, name, street;
+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];;alert(name + " — " + street);'>run: name + " — " + street</button><br class='clear' /></div>
+ <p>
+ Pattern matching can even be combined with splats.
+ </p>
+ <div class='code'><pre class="idle">tag <span class="Keyword">=</span> <span class="String"><span class="String">"</span><impossible><span class="String">"</span></span>
+
+<span class="Keyword">[</span>open, contents..., close<span class="Keyword">] =</span> tag.split(<span class="String"><span class="String">"</span><span class="String">"</span></span>)
+
+
+
+
+</pre><pre class="idle"><span class="Storage">var</span> _ref, close, contents, open, tag;
+<span class="Storage">var</span> __slice <span class="Keyword">=</span> <span class="LibraryClassType">Array</span>.<span class="LibraryConstant">prototype</span>.slice;
+tag <span class="Keyword">=</span> <span class="String"><span class="String">"</span><impossible><span class="String">"</span></span>;
+_ref <span class="Keyword">=</span> tag.<span class="LibraryFunction">split</span>(<span class="String"><span class="String">"</span><span class="String">"</span></span>), open <span class="Keyword">=</span> _ref[<span class="Number">0</span>], contents <span class="Keyword">=</span> __slice.<span class="LibraryFunction">call</span>(_ref, <span class="Number">1</span>, _ref.<span class="LibraryConstant">length</span> <span class="Keyword">-</span> <span class="Number">1</span>), close <span class="Keyword">=</span> _ref[_ref.<span class="LibraryConstant">length</span> <span class="Keyword">-</span> <span class="Number">1</span>];
+</pre><button onclick='javascript: var _ref, close, contents, open, tag;
+var __slice = Array.prototype.slice;
+tag = "<impossible>";
+_ref = tag.split(""), open = _ref[0], contents = __slice.call(_ref, 1, _ref.length - 1), close = _ref[_ref.length - 1];;alert(contents.join(""));'>run: contents.join("")</button><br class='clear' /></div>
+
+ <p>
+ <span id="fat_arrow" class="bookmark"></span>
+ <b class="header">Function binding</b>
+ In JavaScript, the <tt>this</tt> keyword is dynamically scoped to mean the
+ object that the current function is attached to. If you pass a function as
+ as callback, or attach it to a different object, the original value of <tt>this</tt>
+ will be lost. If you're not familiar with this behavior,
+ <a href="http://www.digital-web.com/articles/scope_in_javascript/">this Digital Web article</a>
+ gives a good overview of the quirks.
+ </p>
+ <p>
+ The fat arrow <tt>=></tt> can be used to both define a function, and to bind
+ it to the current value of <tt>this</tt>, right on the spot. This is helpful
+ when using callback-based libraries like Prototype or jQuery, for creating
+ iterator functions to pass to <tt>each</tt>, or event-handler functions
+ to use with <tt>bind</tt>. Functions created with the fat arrow are able to access
+ properties of the <tt>this</tt> where they're defined.
+ </p>
+ <div class='code'><pre class="idle"><span class="FunctionName">Account </span><span class="Keyword">=</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">customer, cart</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
+ <span class="Variable">@customer</span> <span class="Keyword">=</span> customer
+ <span class="Variable">@cart</span> <span class="Keyword">=</span> cart
+
+ $(<span class="String"><span class="String">'</span>.shopping_cart<span class="String">'</span></span>).bind <span class="String"><span class="String">'</span>click<span class="String">'</span></span>, <span class="FunctionArgument">(</span><span class="FunctionArgument">event</span><span class="FunctionArgument">)</span> <span class="Storage">=></span>
+ <span class="Variable">@customer</span>.purchase <span class="Variable">@cart</span>
+</pre><pre class="idle"><span class="Storage">var</span> Account;
+<span class="Storage">var</span> <span class="FunctionName">__bind</span> = <span class="Storage">function</span>(<span class="FunctionArgument">func, context</span>) {
+ <span class="Keyword">return</span> <span class="Storage">function</span>() { <span class="Keyword">return</span> func.<span class="LibraryFunction">apply</span>(context, arguments); };
+};
+<span class="FunctionName">Account</span> = <span class="Storage">function</span>(<span class="FunctionArgument">customer, cart</span>) {
+ <span class="Variable">this</span>.customer <span class="Keyword">=</span> customer;
+ <span class="Variable">this</span>.cart <span class="Keyword">=</span> cart;
+ <span class="Keyword">return</span> <span class="Keyword">$</span>(<span class="String"><span class="String">'</span>.shopping_cart<span class="String">'</span></span>).bind(<span class="String"><span class="String">'</span>click<span class="String">'</span></span>, __bind(<span class="Storage">function</span>(<span class="LibraryClassType">event</span>) {
+ <span class="Keyword">return</span> <span class="Variable">this</span>.customer.purchase(<span class="Variable">this</span>.cart);
+ }, <span class="Variable">this</span>));
+};
+</pre><br class='clear' /></div>
+ <p>
+ If we had used <tt>-></tt> in the callback above, <tt>@customer</tt> would
+ have referred to the undefined "customer" property of the DOM element,
+ and trying to call <tt>purchase()</tt> on it would have raised an exception.
+ </p>
+
+ <p>
+ <span id="embedded" class="bookmark"></span>
+ <b class="header">Embedded JavaScript</b>
+ Hopefully, you'll never need to use it, but if you ever need to intersperse
+ snippets of JavaScript within your CoffeeScript, you can
+ use backticks to pass it straight through.
+ </p>
+ <div class='code'><pre class="idle">hi <span class="Keyword">=</span> <span class="String"><span class="String">`</span>function() {</span>
+<span class="String"> return [document.title, "Hello JavaScript"].join(": ");</span>
+<span class="String">}<span class="String">`</span></span>
+
+
+</pre><pre class="idle"><span class="Storage">var</span> hi;
+<span class="FunctionName">hi</span> = <span class="Storage">function</span>() {
+ <span class="Keyword">return</span> [<span class="LibraryClassType">document</span>.<span class="LibraryConstant">title</span>, <span class="String"><span class="String">"</span>Hello JavaScript<span class="String">"</span></span>].<span class="LibraryFunction">join</span>(<span class="String"><span class="String">"</span>: <span class="String">"</span></span>);
+};
+</pre><button onclick='javascript: var hi;
+hi = function() {
+ return [document.title, "Hello JavaScript"].join(": ");
+};;alert(hi());'>run: hi()</button><br class='clear' /></div>
+
+ <p>
+ <span id="switch" class="bookmark"></span>
+ <b class="header">Switch/When/Else</b>
+ <b>Switch</b> statements in JavaScript are a bit awkward. You need to
+ remember to <b>break</b> at the end of every <b>case</b> statement to
+ avoid accidentally falling through to the default case.
+ CoffeeScript prevents accidental fall-through, and can convert the <tt>switch</tt>
+ into a returnable, assignable expression. The format is: <tt>switch</tt> condition,
+ <tt>when</tt> clauses, <tt>else</tt> the default case.
+ </p>
+ <p>
+ As in Ruby, <b>switch</b> statements in CoffeeScript can take multiple
+ values for each <b>when</b> clause. If any of the values match, the clause
+ runs.
+ </p>
+ <div class='code'><pre class="idle"><span class="Keyword">switch</span> day
+ <span class="Keyword">when</span> <span class="String"><span class="String">"</span>Mon<span class="String">"</span></span> <span class="Keyword">then</span> go work
+ <span class="Keyword">when</span> <span class="String"><span class="String">"</span>Tue<span class="String">"</span></span> <span class="Keyword">then</span> go relax
+ <span class="Keyword">when</span> <span class="String"><span class="String">"</span>Thu<span class="String">"</span></span> <span class="Keyword">then</span> go iceFishing
+ <span class="Keyword">when</span> <span class="String"><span class="String">"</span>Fri<span class="String">"</span></span>, <span class="String"><span class="String">"</span>Sat<span class="String">"</span></span>
+ <span class="Keyword">if</span> day <span class="Keyword">is</span> bingoDay
+ go bingo
+ go dancing
+ <span class="Keyword">when</span> <span class="String"><span class="String">"</span>Sun<span class="String">"</span></span> <span class="Keyword">then</span> go church
+ <span class="Keyword">else</span> go work
+</pre><pre class="idle"><span class="Keyword">switch</span> (day) {
+ <span class="Keyword">case</span> <span class="String"><span class="String">"</span>Mon<span class="String">"</span></span>:
+ <span class="LibraryFunction">go</span>(work);
+ <span class="Keyword">break</span>;
+ <span class="Keyword">case</span> <span class="String"><span class="String">"</span>Tue<span class="String">"</span></span>:
+ <span class="LibraryFunction">go</span>(relax);
+ <span class="Keyword">break</span>;
+ <span class="Keyword">case</span> <span class="String"><span class="String">"</span>Thu<span class="String">"</span></span>:
+ <span class="LibraryFunction">go</span>(iceFishing);
+ <span class="Keyword">break</span>;
+ <span class="Keyword">case</span> <span class="String"><span class="String">"</span>Fri<span class="String">"</span></span>:
+ <span class="Keyword">case</span> <span class="String"><span class="String">"</span>Sat<span class="String">"</span></span>:
+ <span class="Keyword">if</span> (day <span class="Keyword">===</span> bingoDay) {
+ <span class="LibraryFunction">go</span>(bingo);
+ <span class="LibraryFunction">go</span>(dancing);
+ }
+ <span class="Keyword">break</span>;
+ <span class="Keyword">case</span> <span class="String"><span class="String">"</span>Sun<span class="String">"</span></span>:
+ <span class="LibraryFunction">go</span>(church);
+ <span class="Keyword">break</span>;
+ <span class="Keyword">default</span>:
+ <span class="LibraryFunction">go</span>(work);
+}
+</pre><br class='clear' /></div>
+
+ <p>
+ <span id="try" class="bookmark"></span>
+ <b class="header">Try/Catch/Finally</b>
+ Try/catch statements are just about the same as JavaScript (although
+ they work as expressions).
+ </p>
+ <div class='code'><pre class="idle"><span class="Keyword">try</span>
+ allHellBreaksLoose()
+ catsAndDogsLivingTogether()
+<span class="Keyword">catch</span> error
+ print error
+<span class="Keyword">finally</span>
+ cleanUp()
+</pre><pre class="idle"><span class="Keyword">try</span> {
+ allHellBreaksLoose();
+ catsAndDogsLivingTogether();
+} <span class="Keyword">catch</span> (error) {
+ <span class="LibraryFunction">print</span>(error);
+} <span class="Keyword">finally</span> {
+ cleanUp();
+}
+</pre><br class='clear' /></div>
+
+ <p>
+ <span id="comparisons" class="bookmark"></span>
+ <b class="header">Chained Comparisons</b>
+ CoffeeScript borrows
+ <a href="http://docs.python.org/reference/expressions.html#notin">chained comparisons</a>
+ from Python — making it easy to test if a value falls within a
+ certain range.
+ </p>
+ <div class='code'><pre class="idle">cholesterol <span class="Keyword">=</span> <span class="Number">127</span>
+
+healthy <span class="Keyword">=</span> <span class="Number">200</span> <span class="Keyword">></span> cholesterol <span class="Keyword">></span> <span class="Number">60</span>
+
+
+</pre><pre class="idle"><span class="Storage">var</span> cholesterol, healthy;
+cholesterol <span class="Keyword">=</span> <span class="Number">127</span>;
+healthy <span class="Keyword">=</span> (<span class="Number">200</span> <span class="Keyword">></span> cholesterol) <span class="Keyword">&</span><span class="Keyword">&</span> (cholesterol <span class="Keyword">></span> <span class="Number">60</span>);
+</pre><button onclick='javascript: var cholesterol, healthy;
+cholesterol = 127;
+healthy = (200 > cholesterol) && (cholesterol > 60);;alert(healthy);'>run: healthy</button><br class='clear' /></div>
+
+ <p>
+ <span id="interpolation" class="bookmark"></span>
+ <b class="header">String and RegExp Interpolation</b>
+ Ruby-style string interpolation is included in CoffeeScript. Double-quoted
+ strings allow for interpolated values, while single-quoted strings are literal.
+ </p>
+ <div class='code'><pre class="idle">author <span class="Keyword">=</span> <span class="String"><span class="String">"</span>Wittgenstein<span class="String">"</span></span>
+quote <span class="Keyword">=</span> <span class="String"><span class="String">"</span>A picture is a fact. -- <span class="String"><span class="String">#{</span>author<span class="String">}</span></span><span class="String">"</span></span>
+</pre><pre class="idle"><span class="Storage">var</span> author, quote;
+author <span class="Keyword">=</span> <span class="String"><span class="String">"</span>Wittgenstein<span class="String">"</span></span>;
+quote <span class="Keyword">=</span> (<span class="String"><span class="String">"</span>A picture is a fact. -- <span class="String">"</span></span> <span class="Keyword">+</span> author);
+</pre><button onclick='javascript: var author, quote;
+author = "Wittgenstein";
+quote = ("A picture is a fact. -- " + author);;alert(quote);'>run: quote</button><br class='clear' /></div>
+ <p>
+ And arbitrary expressions can be interpolated by using brackets <tt>#{ ... }</tt><br />
+ Interpolation works the same way within regular expressions.
+ </p>
+ <div class='code'><pre class="idle">sentence <span class="Keyword">=</span> <span class="String"><span class="String">"</span><span class="String"><span class="String">#{</span> <span class="Number">22</span> <span class="Keyword">/</span> <span class="Number">7</span> <span class="String">}</span></span> is a decent approximation of π<span class="String">"</span></span>
+
+sep <span class="Keyword">=</span> <span class="String"><span class="String">"</span>[.<span class="UserDefinedConstant">\\</span>/<span class="UserDefinedConstant">\\</span>- ]<span class="String">"</span></span>
+dates <span class="Keyword">=</span> <span class="String">/\d+#{sep}\d+#{sep}\d+/g</span>
+
+
+</pre><pre class="idle"><span class="Storage">var</span> dates, sentence, sep;
+sentence <span class="Keyword">=</span> (<span class="String"><span class="String">"</span><span class="String">"</span></span> <span class="Keyword">+</span> (<span class="Number">22</span> / <span class="Number">7</span>) <span class="Keyword">+</span> <span class="String"><span class="String">"</span> is a decent approximation of π<span class="String">"</span></span>);
+sep <span class="Keyword">=</span> <span class="String"><span class="String">"</span>[.<span class="UserDefinedConstant">\\</span>/<span class="UserDefinedConstant">\\</span>- ]<span class="String">"</span></span>;
+dates <span class="Keyword">=</span><span class="String"> <span class="String">/</span><span class="UserDefinedConstant">\d</span>+#{sep}<span class="UserDefinedConstant">\d</span>+#{sep}<span class="UserDefinedConstant">\d</span>+<span class="String">/</span>g</span>;
+</pre><button onclick='javascript: var dates, sentence, sep;
+sentence = ("" + (22 / 7) + " is a decent approximation of π");
+sep = "[.\\/\\- ]";
+dates = /\d+#{sep}\d+#{sep}\d+/g;;alert(sentence);'>run: sentence</button><br class='clear' /></div>
+
+ <p>
+ <span id="heredocs" class="bookmark"></span>
+ <b class="header">Multiline Strings, Heredocs, and Block Comments</b>
+ Multiline strings are allowed in CoffeeScript.
+ </p>
+ <div class='code'><pre class="idle">mobyDick <span class="Keyword">=</span> <span class="String"><span class="String">"</span>Call me Ishmael. Some years ago --</span>
+<span class="String"> never mind how long precisely -- having little</span>
+<span class="String"> or no money in my purse, and nothing particular</span>
+<span class="String"> to interest me on shore, I thought I would sail</span>
+<span class="String"> about a little and see the watery part of the</span>
+<span class="String"> world...<span class="String">"</span></span>
+
+
+</pre><pre class="idle"><span class="Storage">var</span> mobyDick;
+mobyDick <span class="Keyword">=</span> <span class="String"><span class="String">"</span>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...<span class="String">"</span></span>;
+</pre><button onclick='javascript: var mobyDick;
+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...";;alert(mobyDick);'>run: mobyDick</button><br class='clear' /></div>
+ <p>
+ Heredocs can be used to hold formatted or indentation-sensitive text
+ (or, if you just don't feel like escaping quotes and apostrophes). The
+ indentation level that begins the heredoc is maintained throughout, so
+ you can keep it all aligned with the body of your code.
+ </p>
+ <div class='code'><pre class="idle">html <span class="Keyword">=</span> <span class="String"><span class="String">'''</span></span>
+<span class="String"> <strong></span>
+<span class="String"> cup of coffeescript</span>
+<span class="String"> </strong></span>
+<span class="String"> <span class="String">'''</span></span>
+</pre><pre class="idle"><span class="Storage">var</span> html;
+html <span class="Keyword">=</span> <span class="String"><span class="String">'</span><strong><span class="UserDefinedConstant">\n</span> cup of coffeescript<span class="UserDefinedConstant">\n</span></strong><span class="String">'</span></span>;
+</pre><br class='clear' /></div>
+ <p>
+ Double-quoted heredocs, like double-quoted strings, allow interpolation.
+ </p>
+ <p>
+ Sometimes you'd like to pass a block comment through to the generated
+ JavaScript. For example, when you need to embed a licensing header at
+ the top of a file. Block comments, which mirror the syntax for heredocs,
+ are preserved in the generated code.
+ </p>
+ <div class='code'><pre class="idle"><span class="Comment"><span class="Comment">###</span></span>
+<span class="Comment">CoffeeScript Compiler v0.9.4</span>
+<span class="Comment">Released under the MIT License</span>
+<span class="Comment">###</span>
+</pre><pre class="idle"><span class="Comment"><span class="Comment">/*</span></span>
+<span class="Comment">CoffeeScript Compiler v0.9.4</span>
+<span class="Comment">Released under the MIT License</span>
+<span class="Comment"><span class="Comment">*/</span></span>
+</pre><br class='clear' /></div>
+
+ <h2>
+ <span id="cake" class="bookmark"></span>
+ Cake, and Cakefiles
+ </h2>
+
+ <p>
+ CoffeeScript includes a simple build system similar to
+ <a href="http://www.gnu.org/software/make/">Make</a> and
+ <a href="http://rake.rubyforge.org/">Rake</a>. Naturally,
+ it's called Cake, and is used for the build and test tasks for the CoffeeScript
+ language itself. Tasks are defined in a file named <tt>Cakefile</tt>, and
+ can be invoked by running <tt>cake taskname</tt> from within the directory.
+ To print a list of all the tasks and options, just run <tt>cake</tt>.
+ </p>
+
+ <p>
+ Task definitions are written in CoffeeScript, so you can put arbitrary code
+ in your Cakefile. Define a task with a name, a long description, and the
+ function to invoke when the task is run. If your task takes a command-line
+ option, you can define the option with short and long flags, and it will
+ be made available in the <tt>options</tt> object. Here's a task that uses
+ the Node.js API to rebuild CoffeeScript's parser:
+ </p>
+ <div class='code'><pre class="idle">fs <span class="Keyword">=</span> require <span class="String"><span class="String">'</span>fs<span class="String">'</span></span>
+
+option <span class="String"><span class="String">'</span>-o<span class="String">'</span></span>, <span class="String"><span class="String">'</span>--output [DIR]<span class="String">'</span></span>, <span class="String"><span class="String">'</span>directory for compiled code<span class="String">'</span></span>
+
+task <span class="String"><span class="String">'</span>build:parser<span class="String">'</span></span>, <span class="String"><span class="String">'</span>rebuild the Jison parser<span class="String">'</span></span>, <span class="FunctionArgument">(</span><span class="FunctionArgument">options</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
+ require <span class="String"><span class="String">'</span>jison<span class="String">'</span></span>
+ code <span class="Keyword">=</span> require(<span class="String"><span class="String">'</span>./lib/grammar<span class="String">'</span></span>).parser.generate()
+ dir <span class="Keyword">=</span> options.output <span class="Keyword">or</span> <span class="String"><span class="String">'</span>lib<span class="String">'</span></span>
+ fs.writeFile <span class="String"><span class="String">"</span><span class="String"><span class="String">#{</span>dir<span class="String">}</span></span>/parser.js<span class="String">"</span></span>, code
+</pre><pre class="idle"><span class="Storage">var</span> fs;
+fs <span class="Keyword">=</span> require(<span class="String"><span class="String">'</span>fs<span class="String">'</span></span>);
+option(<span class="String"><span class="String">'</span>-o<span class="String">'</span></span>, <span class="String"><span class="String">'</span>--output [DIR]<span class="String">'</span></span>, <span class="String"><span class="String">'</span>directory for compiled code<span class="String">'</span></span>);
+task(<span class="String"><span class="String">'</span>build:parser<span class="String">'</span></span>, <span class="String"><span class="String">'</span>rebuild the Jison parser<span class="String">'</span></span>, <span class="Storage">function</span>(options) {
+ <span class="Storage">var</span> code, dir;
+ require(<span class="String"><span class="String">'</span>jison<span class="String">'</span></span>);
+ code <span class="Keyword">=</span> require(<span class="String"><span class="String">'</span>./lib/grammar<span class="String">'</span></span>).parser.generate();
+ dir <span class="Keyword">=</span> options.output <span class="Keyword">||</span> <span class="String"><span class="String">'</span>lib<span class="String">'</span></span>;
+ <span class="Keyword">return</span> fs.writeFile(<span class="String"><span class="String">"</span><span class="String">"</span></span> <span class="Keyword">+</span> dir <span class="Keyword">+</span> <span class="String"><span class="String">"</span>/parser.js<span class="String">"</span></span>, code);
+});
+</pre><br class='clear' /></div>
+ <p>
+ If you need to invoke one task before another — for example, running
+ <tt>build</tt> before <tt>test</tt>, you can use the <tt>invoke</tt> function:
+ <tt>invoke 'build'</tt>
+ </p>
+
+ <h2>
+ <span id="scripts" class="bookmark"></span>
+ "text/coffeescript" Script Tags
+ </h2>
+
+ <p>
+ While it's not recommended for serious use, CoffeeScripts may be included
+ directly within the browser using <tt><script type="text/coffeescript"></tt>
+ tags. The source includes a compressed and minified version of the compiler
+ (<a href="extras/coffee-script.js">Download current version here, 43k when gzipped</a>)
+ as <tt>extras/coffee-script.js</tt>. Include this file on a page with
+ inline CoffeeScript tags, and it will compile and evaluate them in order.
+ </p>
+
+ <p>
+ In fact, the little bit of glue script that runs "Try CoffeeScript" above,
+ as well as jQuery for the menu, is implemented in just this way.
+ View source and look at the bottom of the page to see the example.
+ Including the script also gives you access to <tt>CoffeeScript.compile()</tt>
+ so you can pop open Firebug and try compiling some strings.
+ </p>
+
+ <p>
+ The usual caveats about CoffeeScript apply — your inline scripts will
+ run within a closure wrapper, so if you want to expose global variables or
+ functions, attach them to the <tt>window</tt> object.
+ </p>
+
+ <h2>
+ <span id="resources" class="bookmark"></span>
+ Resources
+ </h2>
+
+ <ul>
+ <li>
+ <a href="http://github.com/jashkenas/coffee-script/">Source Code</a><br />
+ Use <tt>bin/coffee</tt> to test your changes,<br />
+ <tt>bin/cake test</tt> to run the test suite,<br />
+ <tt>bin/cake build</tt> to rebuild the CoffeeScript compiler, and <br />
+ <tt>bin/cake build:parser</tt> to regenerate the Jison parser if you're
+ working on the grammar. <br /><br />
+ <tt>git checkout lib && bin/cake build:full</tt> is a good command to run when you're working
+ on the core language. It'll refresh the lib directory
+ (in case you broke something), build your altered compiler, use that to
+ rebuild itself (a good sanity test) and then run all of the tests. If
+ they pass, there's a good chance you've made a successful change.
+ </li>
+ <li>
+ <a href="http://github.com/jashkenas/coffee-script/issues">CoffeeScript Issues</a><br />
+ Bugs reports, feature requests, and general discussion all belong here.
+ </li>
+ <li>
+ If you'd like to chat, stop by <tt>#coffeescript</tt> on Freenode in the
+ IRC client of your choice, or on
+ <a href="http://webchat.freenode.net/">webchat.freenode.net</a>.
+ </li>
+ <li>
+ <b>yeungda</b>'s <a href="http://github.com/yeungda/jcoffeescript">JCoffeeScript</a>
+ — A Java Library that uses Rhino to compile CoffeeScript, allowing
+ compilation within Java projects or on systems that Node.js doesn't support.
+ </li>
+ <li>
+ <b>defunkt</b>'s <a href="http://github.com/defunkt/coffee-mode">CoffeeScript Major Mode</a>
+ — a Emacs major mode that provides syntax highlighting, indentation
+ support, and some bonus commands.
+ </li>
+ <li>
+ <b>jashkenas</b>'s <a href="http://github.com/jashkenas/coffee-script-tmbundle">CoffeeScript TextMate Bundle</a>
+ — which provides syntax highlighting, snippet expansion, and the
+ ability to run bits of CoffeeScript from within TextMate itself.
+ </li>
+ <li>
+ <b>kchmck</b>'s <a href="http://github.com/kchmck/vim-coffee-script">Vim CoffeeScript</a>
+ — which adds Vim syntax highlighting and indentation support.
+ </li>
+ <li>
+ <b>wavded</b>'s <a href="http://github.com/wavded/gedit-coffeescript">gedit-coffeescript</a>
+ — a CoffeeScript syntax highlighter for the gedit text editor.
+ </li>
+ <li>
+ <b>yeungda</b>'s <a href="http://yeungda.github.com/coffeescript-idea/">coffeescript-idea</a>
+ — a plugin for IntelliJ IDEA and RubyMine providing syntax highlighting.
+ </li>
+ <li>
+ <b>mattly</b>'s <a href="http://github.com/mattly/rack-coffee">rack-coffee</a>
+ — a small Rack middleware for serving CoffeeScript files as
+ compiled JavaScript on the fly.
+ </li>
+ <li>
+ <b>jnicklas</b>'s <a href="http://github.com/jnicklas/bistro_car">BistroCar</a>
+ — a plugin that serves and bundles CoffeeScript from within your
+ Rails application.
+ </li>
+ <li>
+ <b>dsc</b>'s <a href="http://github.com/dsc/coffeecup">CoffeeCup</a>
+ — a Python WSGI middleware that compiles CoffeeScript to JavaScript
+ on-demand during development.
+ </li>
+ <li>
+ <b>sutto</b>'s <a href="http://github.com/Sutto/barista">Barista</a>
+ — a BistroCar alternative that integrates well with
+ <a href="http://documentcloud.github.com/jammit">Jammit</a> and Rails 3.
+ </li>
+ <li>
+ <b>inem</b> and <b>gerad</b>'s <a href="http://github.com/gerad/coffee-haml-filter">coffee-haml-filter</a>
+ — a custom filter for rendering CoffeeScript inline within
+ <a href="http://haml-lang.com/">HAML</a> templates.
+ </li>
+ <li>
+ <b>chrislloyd</b>'s <a href="http://github.com/chrislloyd/roast">Roast</a>
+ — a CoffeeScript compiler plug-in that allows you to include external
+ source files.
+ </li>
+ <li>
+ <b>mauricemach</b>'s <a href="http://github.com/mauricemach/coffeekup">CoffeeKup</a>
+ — Markup as CoffeeScript. After _why's
+ <a href="http://markaby.github.com/">Markaby</a>.
+ </li>
+ <li>
+ <b>jashkenas</b>'s <a href="http://jashkenas.github.com/docco/">Docco</a>
+ — a quick-and-dirty literate-programming-style documentation generator
+ for CoffeeScript. Used to produce the annotated source.
+ </li>
+ </ul>
+
+ <h2>
+ <span id="webchat" class="bookmark"></span>
+ Web Chat (IRC)
+ </h2>
+
+ <p>
+ Quick help and advice can usually be found in the CoffeeScript IRC room.
+ Join <tt>#coffeescript</tt> on <tt>irc.freenode.net</tt>, or click the
+ button below to open a webchat session on this page.
+ </p>
+
+ <p>
+ <button id="open_webchat">click to open #coffeescript</button>
+ </p>
+
+ <h2>
+ <span id="change_log" class="bookmark"></span>
+ Change Log
+ </h2>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.4</b>
+ CoffeeScript now uses appropriately-named temporary variables, and recycles
+ their references after use. Added <tt>require.extensions</tt> support for
+ <b>Node.js 0.3</b>. Loading CoffeeScript in the browser now adds just a
+ single <tt>CoffeeScript</tt> object to global scope.
+ Fixes for implicit object and block comment edge cases.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.3</b>
+ CoffeeScript <tt>switch</tt> statements now compile into JS <tt>switch</tt>
+ statements — they previously compiled into <tt>if/else</tt> chains
+ for JavaScript 1.3 compatibility.
+ Soaking a function invocation is now supported. Users of the RubyMine
+ editor should now be able to use <tt>--watch</tt> mode.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.2</b>
+ Specifying the start and end of a range literal is now optional, eg. <tt>array[3..]</tt>.
+ You can now say <tt>a not instanceof b</tt>.
+ Fixed important bugs with nested significant and non-significant indentation (Issue #637).
+ Added a <tt>--require</tt> flag that allows you to hook into the <tt>coffee</tt> command.
+ Added a custom <tt>jsl.conf</tt> file for our preferred JavaScriptLint setup.
+ Sped up Jison grammar compilation time by flattening rules for operations.
+ Block comments can now be used with JavaScript-minifier-friendly syntax.
+ Added JavaScript's compound assignment bitwise operators. Bugfixes to
+ implicit object literals with leading number and string keys, as the subject
+ of implicit calls, and as part of compound assignment.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.1</b>
+ Bugfix release for <b>0.9.1</b>. Greatly improves the handling of mixed
+ implicit objects, implicit function calls, and implicit indentation.
+ String and regex interpolation is now strictly <tt>#{ ... }</tt> (Ruby style).
+ The compiler now takes a <tt>--require</tt> flag, which specifies scripts
+ to run before compilation.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.9.0</b>
+ The CoffeeScript <b>0.9</b> series is considered to be a release candidate
+ for <b>1.0</b>; let's give her a shakedown cruise. <b>0.9.0</b> introduces a massive
+ backwards-incompatible change: Assignment now uses <tt>=</tt>, and object
+ literals use <tt>:</tt>, as in JavaScript. This allows us to have implicit
+ object literals, and YAML-style object definitions. Half assignments are
+ removed, in favor of <tt>+=</tt>, <tt>or=</tt>, and friends.
+ Interpolation now uses a hash mark <tt>#</tt> instead of the dollar sign
+ <tt>$</tt> — because dollar signs may be part of a valid JS identifier.
+ Downwards range comprehensions are now safe again, and are optimized to
+ straight for loops when created with integer endpoints.
+ A fast, unguarded form of object comprehension was added:
+ <tt>for all key, value of object</tt>. Mentioning the <tt>super</tt> keyword
+ with no arguments now forwards all arguments passed to the function,
+ as in Ruby. If you extend class <tt>B</tt> from parent class <tt>A</tt>, if
+ <tt>A</tt> has an <tt>extended</tt> method defined, it will be called, passing in <tt>B</tt> —
+ this enables static inheritance, among other things. Cleaner output for
+ functions bound with the fat arrow. <tt>@variables</tt> can now be used
+ in parameter lists, with the parameter being automatically set as a property
+ on the object — useful in constructors and setter functions.
+ Constructor functions can now take splats.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.7.2</b>
+ Quick bugfix (right after 0.7.1) for a problem that prevented <tt>coffee</tt>
+ command-line options from being parsed in some circumstances.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.7.1</b>
+ Block-style comments are now passed through and printed as JavaScript block
+ comments -- making them useful for licenses and copyright headers. Better
+ support for running coffee scripts standalone via hashbangs.
+ Improved syntax errors for tokens that are not in the grammar.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.7.0</b>
+ Official CoffeeScript variable style is now camelCase, as in JavaScript.
+ Reserved words are now allowed as object keys, and will be quoted for you.
+ Range comprehensions now generate cleaner code, but you have to specify <tt>by -1</tt>
+ if you'd like to iterate downward. Reporting of syntax errors is greatly
+ improved from the previous release. Running <tt>coffee</tt> with no arguments
+ now launches the REPL, with Readline support. The <tt><-</tt> bind operator
+ has been removed from CoffeeScript. The <tt>loop</tt> keyword was added,
+ which is equivalent to a <tt>while true</tt> loop. Comprehensions that contain
+ closures will now close over their variables, like the semantics of a <tt>forEach</tt>.
+ You can now use bound function in class definitions (bound to the instance).
+ For consistency, <tt>a in b</tt> is now an array presence check, and <tt>a of b</tt>
+ is an object-key check. Comments are no longer passed through to the generated
+ JavaScript.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.6.2</b>
+ The <tt>coffee</tt> command will now preserve directory structure when
+ compiling a directory full of scripts. Fixed two omissions that were preventing
+ the CoffeeScript compiler from running live within Internet Explorer.
+ There's now a syntax for block comments, similar in spirit to CoffeeScript's heredocs.
+ ECMA Harmony DRY-style pattern matching is now supported, where the name
+ of the property is the same as the name of the value: <tt>{name, length}: func</tt>.
+ Pattern matching is now allowed within comprehension variables. <tt>unless</tt>
+ is now allowed in block form. <tt>until</tt> loops were added, as the inverse
+ of <tt>while</tt> loops. <tt>switch</tt> statements are now allowed without
+ switch object clauses. Compatible
+ with Node.js <b>v0.1.95</b>.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.6.1</b>
+ Upgraded CoffeeScript for compatibility with the new Node.js <b>v0.1.90</b>
+ series.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.6.0</b>
+ Trailing commas are now allowed, a-la Python. Static
+ properties may be assigned directly within class definitions,
+ using <tt>@property</tt> notation.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.6</b>
+ Interpolation can now be used within regular expressions and heredocs, as well as
+ strings. Added the <tt><-</tt> bind operator.
+ Allowing assignment to half-expressions instead of special <tt>||=</tt>-style
+ operators. The arguments object is no longer automatically converted into
+ an array. After requiring <tt>coffee-script</tt>, Node.js can now directly
+ load <tt>.coffee</tt> files, thanks to <b>registerExtension</b>. Multiple
+ splats can now be used in function calls, arrays, and pattern matching.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.5</b>
+ String interpolation, contributed by
+ <a href="http://github.com/StanAngeloff">Stan Angeloff</a>.
+ Since <tt>--run</tt> has been the default since <b>0.5.3</b>, updating
+ <tt>--stdio</tt> and <tt>--eval</tt> to run by default, pass <tt>--compile</tt>
+ as well if you'd like to print the result.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.4</b>
+ Bugfix that corrects the Node.js global constants <tt>__filename</tt> and
+ <tt>__dirname</tt>. Tweaks for more flexible parsing of nested function
+ literals and improperly-indented comments. Updates for the latest Node.js API.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.3</b>
+ CoffeeScript now has a syntax for defining classes. Many of the core
+ components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them.
+ Cakefiles can use <tt>optparse.coffee</tt> to define options for tasks.
+ <tt>--run</tt> is now the default flag for the <tt>coffee</tt> command,
+ use <tt>--compile</tt> to save JavaScripts. Bugfix for an ambiguity between
+ RegExp literals and chained divisions.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.2</b>
+ Added a compressed version of the compiler for inclusion in web pages as
+ <br /><tt>extras/coffee-script.js</tt>. It'll automatically run any script tags
+ with type <tt>text/coffeescript</tt> for you. Added a <tt>--stdio</tt> option
+ to the <tt>coffee</tt> command, for piped-in compiles.
+ </p>
+
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.1</b>
+ Improvements to null soaking with the existential operator, including
+ soaks on indexed properties. Added conditions to <tt>while</tt> loops,
+ so you can use them as filters with <tt>when</tt>, in the same manner as
+ comprehensions.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.5.0</b>
+ CoffeeScript 0.5.0 is a major release, While there are no language changes,
+ the Ruby compiler has been removed in favor of a self-hosting
+ compiler written in pure CoffeeScript.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.3.2</b>
+ <tt>@property</tt> is now a shorthand for <tt>this.property</tt>.<br />
+ Switched the default JavaScript engine from Narwhal to Node.js. Pass
+ the <tt>--narwhal</tt> flag if you'd like to continue using it.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.3.0</b>
+ CoffeeScript 0.3 includes major syntax changes:
+ <br />
+ The function symbol was changed to
+ <tt>-></tt>, and the bound function symbol is now <tt>=></tt>.
+ <br />
+ Parameter lists in function definitions must now be wrapped in parentheses.
+ <br />
+ Added property soaking, with the <tt>?.</tt> operator.
+ <br />
+ Made parentheses optional, when invoking functions with arguments.
+ <br />
+ Removed the obsolete block literal syntax.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.6</b>
+ Added Python-style chained comparisons, the conditional existence
+ operator <tt>?=</tt>, and some examples from <i>Beautiful Code</i>.
+ Bugfixes relating to statement-to-expression conversion, arguments-to-array
+ conversion, and the TextMate syntax highlighter.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.5</b>
+ The conditions in switch statements can now take multiple values at once —
+ If any of them are true, the case will run. Added the long arrow <tt>==></tt>,
+ which defines and immediately binds a function to <tt>this</tt>. While loops can
+ now be used as expressions, in the same way that comprehensions can. Splats
+ can be used within pattern matches to soak up the rest of an array.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.4</b>
+ Added ECMAScript Harmony style destructuring assignment, for dealing with
+ extracting values from nested arrays and objects. Added indentation-sensitive
+ heredocs for nicely formatted strings or chunks of code.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.3</b>
+ Axed the unsatisfactory <tt>ino</tt> keyword, replacing it with <tt>of</tt> for
+ object comprehensions. They now look like: <tt>for prop, value of object</tt>.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.2</b>
+ When performing a comprehension over an object, use <tt>ino</tt>, instead
+ of <tt>in</tt>, which helps us generate smaller, more efficient code at
+ compile time.
+ <br />
+ Added <tt>::</tt> as a shorthand for saying <tt>.prototype.</tt>
+ <br />
+ The "splat" symbol has been changed from a prefix asterisk <tt>*</tt>, to
+ a postfix ellipsis <tt>...</tt>
+ <br />
+ Added JavaScript's <tt>in</tt> operator,
+ empty <tt>return</tt> statements, and empty <tt>while</tt> loops.
+ <br />
+ Constructor functions that start with capital letters now include a
+ safety check to make sure that the new instance of the object is returned.
+ <br />
+ The <tt>extends</tt> keyword now functions identically to <tt>goog.inherits</tt>
+ in Google's Closure Library.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.1</b>
+ Arguments objects are now converted into real arrays when referenced.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.2.0</b>
+ Major release. Significant whitespace. Better statement-to-expression
+ conversion. Splats. Splice literals. Object comprehensions. Blocks.
+ The existential operator. Many thanks to all the folks who posted issues,
+ with special thanks to
+ <a href="http://github.com/liamoc">Liam O'Connor-Davis</a> for whitespace
+ and expression help.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.6</b>
+ Bugfix for running <tt>coffee --interactive</tt> and <tt>--run</tt>
+ from outside of the CoffeeScript directory. Bugfix for nested
+ function/if-statements.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.5</b>
+ Array slice literals and array comprehensions can now both take Ruby-style
+ ranges to specify the start and end. JavaScript variable declaration is
+ now pushed up to the top of the scope, making all assignment statements into
+ expressions. You can use <tt>\</tt> to escape newlines.
+ The <tt>coffee-script</tt> command is now called <tt>coffee</tt>.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.4</b>
+ The official CoffeeScript extension is now <tt>.coffee</tt> instead of
+ <tt>.cs</tt>, which properly belongs to
+ <a href="http://en.wikipedia.org/wiki/C_Sharp_(programming_language)">C#</a>.
+ Due to popular demand, you can now also use <tt>=</tt> to assign. Unlike
+ JavaScript, <tt>=</tt> can also be used within object literals, interchangeably
+ with <tt>:</tt>. Made a grammatical fix for chained function calls
+ like <tt>func(1)(2)(3)(4)</tt>. Inheritance and super no longer use
+ <tt>__proto__</tt>, so they should be IE-compatible now.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.3</b>
+ The <tt>coffee</tt> command now includes <tt>--interactive</tt>,
+ which launches an interactive CoffeeScript session, and <tt>--run</tt>,
+ which directly compiles and executes a script. Both options depend on a
+ working installation of Narwhal.
+ The <tt>aint</tt> keyword has been replaced by <tt>isnt</tt>, which goes
+ together a little smoother with <tt>is</tt>.
+ Quoted strings are now allowed as identifiers within object literals: eg.
+ <tt>{"5+5": 10}</tt>.
+ All assignment operators now use a colon: <tt>+:</tt>, <tt>-:</tt>,
+ <tt>*:</tt>, etc.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.2</b>
+ Fixed a bug with calling <tt>super()</tt> through more than one level of
+ inheritance, with the re-addition of the <tt>extends</tt> keyword.
+ Added experimental <a href="http://narwhaljs.org/">Narwhal</a>
+ support (as a Tusk package), contributed by
+ <a href="http://tlrobinson.net/">Tom Robinson</a>, including
+ <b>bin/cs</b> as a CoffeeScript REPL and interpreter.
+ New <tt>--no-wrap</tt> option to suppress the safety function
+ wrapper.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.1</b>
+ Added <tt>instanceof</tt> and <tt>typeof</tt> as operators.
+ </p>
+
+ <p>
+ <b class="header" style="margin-top: 20px;">0.1.0</b>
+ Initial CoffeeScript release.
+ </p>
+
+ </div>
+
+ <script type="text/coffeescript">
+
+ # Set up the compilation function, to run when you stop typing.
+ compile_source = ->
+ source = $('#repl_source').val()
+ window.compiled_js = ''
+ try
+ window.compiled_js = CoffeeScript.compile source, wrap: false
+ $('#repl_results').text window.compiled_js
+ $('#error').hide()
+ catch error
+ $('#error').text(error.message).show()
+
+ # Listen for keypresses and recompile.
+ $('#repl_source').keyup -> compile_source()
+
+ # Eval the compiled js.
+ $('button.run').click ->
+ try
+ eval window.compiled_js
+ catch error then alert error
+
+ current_nav = null
+
+ # Helper to hide the menus.
+ close_menus = ->
+ if current_nav
+ current_nav.removeClass 'active'
+ document.body.className = 'minimized'
+ current_nav = null
+
+ # Bind navigation buttons to open the menus.
+ $('.navigation').click (e) ->
+ return if e.target.tagName.toLowerCase() is 'a'
+ if this isnt (current_nav and current_nav[0])
+ close_menus()
+ current_nav = $(this)
+ current_nav.addClass 'active'
+ false
+
+ $(document.body).click -> close_menus()
+
+ $('.navigation .full_screen').click ->
+ document.body.className = 'full_screen'
+
+ $('.navigation .minimize').click ->
+ document.body.className = 'minimized'
+
+ $('#open_webchat').click ->
+ $(this).replaceWith $('<iframe src="http://webchat.freenode.net/?channels=coffeescript" width="625" height="400"></iframe>')
+
+ compile_source()
+
+ </script>
+
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+ <script src="extras/coffee-script.js"></script>
+
+</body>
+</html>
--- /dev/null
+(function() {
+ var CoffeeScript, runScripts;
+ CoffeeScript = require('./coffee-script');
+ CoffeeScript.require = require;
+ CoffeeScript.eval = function(code, options) {
+ return eval(CoffeeScript.compile(code, options));
+ };
+ CoffeeScript.run = function(code, options) {
+ ((options != null) ? (options.bare = true) : undefined);
+ return Function(CoffeeScript.compile(code, options))();
+ };
+ if (!(typeof window !== "undefined" && window !== null)) {
+ return;
+ }
+ CoffeeScript.load = function(url, options) {
+ var xhr;
+ xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP');
+ xhr.open('GET', url, true);
+ if ('overrideMimeType' in xhr) {
+ xhr.overrideMimeType('text/plain');
+ }
+ xhr.onreadystatechange = function() {
+ return xhr.readyState === 4 ? CoffeeScript.run(xhr.responseText, options) : undefined;
+ };
+ return xhr.send(null);
+ };
+ runScripts = function() {
+ var _i, _j, _len, _ref, script;
+ for (_i = 0, _len = (_ref = document.getElementsByTagName('script')).length; _i < _len; _i++) {
+ (function() {
+ var script = _ref[_i];
+ _j = script;
+ return script.type === 'text/coffeescript' ? (script.src ? CoffeeScript.load(script.src) : setTimeout(function() {
+ return CoffeeScript.run(script.innerHTML);
+ })) : undefined;
+ })();
+ script = _j;
+ }
+ return null;
+ };
+ if (window.addEventListener) {
+ addEventListener('DOMContentLoaded', runScripts, false);
+ } else {
+ attachEvent('onload', runScripts);
+ }
+}).call(this);
--- /dev/null
+(function() {
+ var CoffeeScript, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
+ fs = require('fs');
+ path = require('path');
+ helpers = require('./helpers');
+ optparse = require('./optparse');
+ CoffeeScript = require('./coffee-script');
+ tasks = {};
+ options = {};
+ switches = [];
+ oparse = null;
+ helpers.extend(global, {
+ task: function(name, description, action) {
+ var _ref;
+ if (!action) {
+ _ref = [description, action], action = _ref[0], description = _ref[1];
+ }
+ return (tasks[name] = {
+ name: name,
+ description: description,
+ action: action
+ });
+ },
+ option: function(letter, flag, description) {
+ return switches.push([letter, flag, description]);
+ },
+ invoke: function(name) {
+ if (!tasks[name]) {
+ missingTask(name);
+ }
+ return tasks[name].action(options);
+ }
+ });
+ exports.run = function() {
+ return path.exists('Cakefile', function(exists) {
+ var _i, _len, _ref, _result, arg, args;
+ if (!exists) {
+ throw new Error("Cakefile not found in " + (process.cwd()));
+ }
+ args = process.argv.slice(2);
+ CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
+ fileName: 'Cakefile'
+ });
+ oparse = new optparse.OptionParser(switches);
+ if (!args.length) {
+ return printTasks();
+ }
+ options = oparse.parse(args);
+ _result = [];
+ for (_i = 0, _len = (_ref = options.arguments).length; _i < _len; _i++) {
+ arg = _ref[_i];
+ _result.push(invoke(arg));
+ }
+ return _result;
+ });
+ };
+ printTasks = function() {
+ var _ref, desc, name, spaces, task;
+ puts('');
+ for (name in _ref = tasks) {
+ task = _ref[name];
+ spaces = 20 - name.length;
+ spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
+ desc = task.description ? ("# " + (task.description)) : '';
+ puts("cake " + name + spaces + " " + desc);
+ }
+ return switches.length ? puts(oparse.help()) : undefined;
+ };
+ missingTask = function(task) {
+ puts("No such task: \"" + task + "\"");
+ return process.exit(1);
+ };
+}).call(this);
--- /dev/null
+(function() {
+ var Lexer, compile, fs, lexer, parser, path;
+ path = require('path');
+ Lexer = require('./lexer').Lexer;
+ parser = require('./parser').parser;
+ if (require.extensions) {
+ fs = require('fs');
+ require.extensions['.coffee'] = function(module, filename) {
+ var content;
+ content = compile(fs.readFileSync(filename, 'utf8'));
+ return module._compile(content, filename);
+ };
+ } else if (require.registerExtension) {
+ require.registerExtension('.coffee', function(content) {
+ return compile(content);
+ });
+ }
+ exports.VERSION = '0.9.4';
+ exports.helpers = require('./helpers');
+ exports.compile = (compile = function(code, options) {
+ options || (options = {});
+ try {
+ return (parser.parse(lexer.tokenize(code))).compile(options);
+ } catch (err) {
+ if (options.fileName) {
+ err.message = ("In " + (options.fileName) + ", " + (err.message));
+ }
+ throw err;
+ }
+ });
+ exports.tokens = function(code, options) {
+ return lexer.tokenize(code, options);
+ };
+ exports.nodes = function(code, options) {
+ return parser.parse(lexer.tokenize(code, options));
+ };
+ exports.run = function(code, options) {
+ var root;
+ root = module;
+ while (root.parent) {
+ root = root.parent;
+ }
+ root.filename = options.fileName;
+ if (root.moduleCache) {
+ root.moduleCache = {};
+ }
+ return path.extname(root.filename) !== '.coffee' || require.extensions ? root._compile(exports.compile(code, options), root.filename) : root._compile(code, root.filename);
+ };
+ exports.eval = function(code, options) {
+ var __dirname, __filename;
+ __filename = options.fileName;
+ __dirname = path.dirname(__filename);
+ return eval(exports.compile(code, options));
+ };
+ lexer = new Lexer;
+ parser.lexer = {
+ lex: function() {
+ var token;
+ token = this.tokens[this.pos] || [""];
+ this.pos += 1;
+ this.yylineno = token[2];
+ this.yytext = token[1];
+ return token[0];
+ },
+ setInput: function(tokens) {
+ this.tokens = tokens;
+ return (this.pos = 0);
+ },
+ upcomingInput: function() {
+ return "";
+ }
+ };
+ parser.yy = require('./nodes');
+}).call(this);
--- /dev/null
+(function() {
+ var BANNER, CoffeeScript, EventEmitter, SWITCHES, _ref, compileOptions, compileScript, compileScripts, compileStdio, exec, fs, helpers, lint, optionParser, optparse, opts, parseOptions, path, printTokens, sources, spawn, usage, version, watch, writeJs;
+ fs = require('fs');
+ path = require('path');
+ optparse = require('./optparse');
+ CoffeeScript = require('./coffee-script');
+ helpers = require('./helpers');
+ _ref = require('child_process'), spawn = _ref.spawn, exec = _ref.exec;
+ EventEmitter = require('events').EventEmitter;
+ helpers.extend(CoffeeScript, new EventEmitter);
+ global.CoffeeScript = CoffeeScript;
+ BANNER = 'coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee';
+ SWITCHES = [['-c', '--compile', 'compile to JavaScript and save as .js files'], ['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-r', '--require [FILE*]', 'require a library before executing your script'], ['-b', '--bare', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-n', '--nodes', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
+ opts = {};
+ sources = [];
+ optionParser = null;
+ exports.run = function() {
+ var flags, separator;
+ parseOptions();
+ if (opts.help) {
+ return usage();
+ }
+ if (opts.version) {
+ return version();
+ }
+ if (opts.interactive) {
+ return require('./repl');
+ }
+ if (opts.stdio) {
+ return compileStdio();
+ }
+ if (opts.eval) {
+ return compileScript('console', sources[0]);
+ }
+ if (!sources.length) {
+ return require('./repl');
+ }
+ separator = sources.indexOf('--');
+ flags = [];
+ if (separator >= 0) {
+ flags = sources.splice(separator + 1);
+ sources.pop();
+ }
+ if (opts.run) {
+ flags = sources.splice(1).concat(flags);
+ }
+ process.ARGV = (process.argv = flags);
+ return compileScripts();
+ };
+ compileScripts = function() {
+ var _i, _j, _len, _ref2, _result, base, compile, source;
+ _result = [];
+ for (_i = 0, _len = (_ref2 = sources).length; _i < _len; _i++) {
+ (function() {
+ var source = _ref2[_i];
+ _j = source;
+ return _result.push((function() {
+ base = source;
+ compile = function(source, topLevel) {
+ return path.exists(source, function(exists) {
+ if (!exists) {
+ throw new Error("File not found: " + source);
+ }
+ return fs.stat(source, function(err, stats) {
+ if (stats.isDirectory()) {
+ return fs.readdir(source, function(err, files) {
+ var _k, _len2, _result2, file;
+ _result2 = [];
+ for (_k = 0, _len2 = files.length; _k < _len2; _k++) {
+ file = files[_k];
+ _result2.push(compile(path.join(source, file)));
+ }
+ return _result2;
+ });
+ } else if (topLevel || path.extname(source) === '.coffee') {
+ fs.readFile(source, function(err, code) {
+ return compileScript(source, code.toString(), base);
+ });
+ return opts.watch ? watch(source, base) : undefined;
+ }
+ });
+ });
+ };
+ return compile(source, true);
+ })());
+ })();
+ source = _j;
+ }
+ return _result;
+ };
+ compileScript = function(file, input, base) {
+ var _i, _len, _ref2, o, options, req, t, task;
+ o = opts;
+ options = compileOptions(file);
+ if (o.require) {
+ for (_i = 0, _len = (_ref2 = o.require).length; _i < _len; _i++) {
+ req = _ref2[_i];
+ require(helpers.starts(req, '.') ? fs.realpathSync(req) : req);
+ }
+ }
+ try {
+ t = (task = {
+ file: file,
+ input: input,
+ options: options
+ });
+ CoffeeScript.emit('compile', task);
+ if (o.tokens) {
+ return printTokens(CoffeeScript.tokens(t.input));
+ } else if (o.nodes) {
+ return puts(CoffeeScript.nodes(t.input).toString().trim());
+ } else if (o.run) {
+ return CoffeeScript.run(t.input, t.options);
+ } else {
+ t.output = CoffeeScript.compile(t.input, t.options);
+ CoffeeScript.emit('success', task);
+ return o.print ? print(t.output) : (o.compile ? writeJs(t.file, t.output, base) : (o.lint ? lint(t.output) : undefined));
+ }
+ } catch (err) {
+ CoffeeScript.emit('failure', err, task);
+ if (CoffeeScript.listeners('failure').length) {
+ return;
+ }
+ if (o.watch) {
+ return puts(err.message);
+ }
+ error(err.stack);
+ return process.exit(1);
+ }
+ };
+ compileStdio = function() {
+ var code, stdin;
+ code = '';
+ stdin = process.openStdin();
+ stdin.on('data', function(buffer) {
+ return buffer ? code += buffer.toString() : undefined;
+ });
+ return stdin.on('end', function() {
+ return compileScript('stdio', code);
+ });
+ };
+ watch = function(source, base) {
+ return fs.watchFile(source, {
+ persistent: true,
+ interval: 500
+ }, function(curr, prev) {
+ if (curr.size === prev.size && curr.mtime.getTime() === prev.mtime.getTime()) {
+ return;
+ }
+ return fs.readFile(source, function(err, code) {
+ if (err) {
+ throw err;
+ }
+ return compileScript(source, code.toString(), base);
+ });
+ });
+ };
+ writeJs = function(source, js, base) {
+ var baseDir, compile, dir, filename, jsPath, srcDir;
+ filename = path.basename(source, path.extname(source)) + '.js';
+ srcDir = path.dirname(source);
+ baseDir = srcDir.substring(base.length);
+ dir = opts.output ? path.join(opts.output, baseDir) : srcDir;
+ jsPath = path.join(dir, filename);
+ compile = function() {
+ if (js.length <= 0) {
+ js = ' ';
+ }
+ return fs.writeFile(jsPath, js, function(err) {
+ return opts.compile && opts.watch ? puts("Compiled " + source) : undefined;
+ });
+ };
+ return path.exists(dir, function(exists) {
+ return exists ? compile() : exec("mkdir -p " + dir, compile);
+ });
+ };
+ lint = function(js) {
+ var conf, jsl, printIt;
+ printIt = function(buffer) {
+ return puts(buffer.toString().trim());
+ };
+ conf = __dirname + '/../extras/jsl.conf';
+ jsl = spawn('jsl', ['-nologo', '-stdin', '-conf', conf]);
+ jsl.stdout.on('data', printIt);
+ jsl.stderr.on('data', printIt);
+ jsl.stdin.write(js);
+ return jsl.stdin.end();
+ };
+ printTokens = function(tokens) {
+ var _i, _len, _ref2, _result, strings, tag, token, value;
+ strings = (function() {
+ _result = [];
+ for (_i = 0, _len = tokens.length; _i < _len; _i++) {
+ token = tokens[_i];
+ _result.push((function() {
+ _ref2 = [token[0], token[1].toString().replace(/\n/, '\\n')], tag = _ref2[0], value = _ref2[1];
+ return "[" + tag + " " + value + "]";
+ })());
+ }
+ return _result;
+ })();
+ return puts(strings.join(' '));
+ };
+ parseOptions = function() {
+ var o;
+ optionParser = new optparse.OptionParser(SWITCHES, BANNER);
+ o = (opts = optionParser.parse(process.argv.slice(2)));
+ o.compile || (o.compile = !!o.output);
+ o.run = !(o.compile || o.print || o.lint);
+ o.print = !!(o.print || (o.eval || o.stdio && o.compile));
+ return (sources = o.arguments);
+ };
+ compileOptions = function(fileName) {
+ return {
+ fileName: fileName,
+ bare: opts.bare
+ };
+ };
+ usage = function() {
+ puts(optionParser.help());
+ return process.exit(0);
+ };
+ version = function() {
+ puts("CoffeeScript version " + (CoffeeScript.VERSION));
+ return process.exit(0);
+ };
+}).call(this);
--- /dev/null
+(function() {
+ var Parser, _i, _j, _len, _len2, _ref, _result, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap;
+ var __hasProp = Object.prototype.hasOwnProperty;
+ Parser = require('jison').Parser;
+ unwrap = /function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/;
+ o = function(patternString, action, options) {
+ var match;
+ if (!action) {
+ return [patternString, '$$ = $1;', options];
+ }
+ action = (match = (action + '').match(unwrap)) ? match[1] : ("(" + action + "())");
+ action = action.replace(/\bnew (\w+)\b/g, 'new yy.$1').replace(/Expressions\.wrap/g, 'yy.Expressions.wrap');
+ return [patternString, ("$$ = " + action + ";"), options];
+ };
+ grammar = {
+ Root: [
+ o("", function() {
+ return new Expressions;
+ }), o("TERMINATOR", function() {
+ return new Expressions;
+ }), o("Body"), o("Block TERMINATOR")
+ ],
+ Body: [
+ o("Line", function() {
+ return Expressions.wrap([$1]);
+ }), o("Body TERMINATOR Line", function() {
+ return $1.push($3);
+ }), o("Body TERMINATOR")
+ ],
+ Line: [o("Expression"), o("Statement")],
+ Statement: [
+ o("Return"), o("Throw"), o("BREAK", function() {
+ return new Literal($1);
+ }), o("CONTINUE", function() {
+ return new Literal($1);
+ }), o("DEBUGGER", function() {
+ return new Literal($1);
+ })
+ ],
+ Expression: [o("Value"), o("Invocation"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment")],
+ Block: [
+ o("INDENT Body OUTDENT", function() {
+ return $2;
+ }), o("INDENT OUTDENT", function() {
+ return new Expressions;
+ }), o("TERMINATOR Comment", function() {
+ return Expressions.wrap([$2]);
+ })
+ ],
+ Identifier: [
+ o("IDENTIFIER", function() {
+ return new Literal($1);
+ })
+ ],
+ AlphaNumeric: [
+ o("NUMBER", function() {
+ return new Literal($1);
+ }), o("STRING", function() {
+ return new Literal($1);
+ })
+ ],
+ Literal: [
+ o("AlphaNumeric"), o("JS", function() {
+ return new Literal($1);
+ }), o("REGEX", function() {
+ return new Literal($1);
+ }), o("BOOL", function() {
+ return new Literal($1);
+ })
+ ],
+ Assign: [
+ o("Assignable = Expression", function() {
+ return new Assign($1, $3);
+ }), o("Assignable = INDENT Expression OUTDENT", function() {
+ return new Assign($1, $4);
+ })
+ ],
+ AssignObj: [
+ o("Identifier", function() {
+ return new Value($1);
+ }), o("AlphaNumeric"), o("ThisProperty"), o("Identifier : Expression", function() {
+ return new Assign(new Value($1), $3, 'object');
+ }), o("AlphaNumeric : Expression", function() {
+ return new Assign(new Value($1), $3, 'object');
+ }), o("Identifier : INDENT Expression OUTDENT", function() {
+ return new Assign(new Value($1), $4, 'object');
+ }), o("AlphaNumeric : INDENT Expression OUTDENT", function() {
+ return new Assign(new Value($1), $4, 'object');
+ }), o("Comment")
+ ],
+ Return: [
+ o("RETURN Expression", function() {
+ return new Return($2);
+ }), o("RETURN", function() {
+ return new Return;
+ })
+ ],
+ Comment: [
+ o("HERECOMMENT", function() {
+ return new Comment($1);
+ })
+ ],
+ Existence: [
+ o("Expression ?", function() {
+ return new Existence($1);
+ })
+ ],
+ Code: [
+ o("PARAM_START ParamList PARAM_END FuncGlyph Block", function() {
+ return new Code($2, $5, $4);
+ }), o("FuncGlyph Block", function() {
+ return new Code([], $2, $1);
+ })
+ ],
+ FuncGlyph: [
+ o("->", function() {
+ return 'func';
+ }), o("=>", function() {
+ return 'boundfunc';
+ })
+ ],
+ OptComma: [o(''), o(',')],
+ ParamList: [
+ o("", function() {
+ return [];
+ }), o("Param", function() {
+ return [$1];
+ }), o("ParamList , Param", function() {
+ return $1.concat($3);
+ })
+ ],
+ Param: [
+ o("PARAM", function() {
+ return new Literal($1);
+ }), o("@ PARAM", function() {
+ return new Param($2, true);
+ }), o("PARAM ...", function() {
+ return new Param($1, false, true);
+ }), o("@ PARAM ...", function() {
+ return new Param($2, true, true);
+ })
+ ],
+ Splat: [
+ o("Expression ...", function() {
+ return new Splat($1);
+ })
+ ],
+ SimpleAssignable: [
+ o("Identifier", function() {
+ return new Value($1);
+ }), o("Value Accessor", function() {
+ return $1.push($2);
+ }), o("Invocation Accessor", function() {
+ return new Value($1, [$2]);
+ }), o("ThisProperty")
+ ],
+ Assignable: [
+ o("SimpleAssignable"), o("Array", function() {
+ return new Value($1);
+ }), o("Object", function() {
+ return new Value($1);
+ })
+ ],
+ Value: [
+ o("Assignable"), o("Literal", function() {
+ return new Value($1);
+ }), o("Parenthetical", function() {
+ return new Value($1);
+ }), o("Range", function() {
+ return new Value($1);
+ }), o("This")
+ ],
+ Accessor: [
+ o("PROPERTY_ACCESS Identifier", function() {
+ return new Accessor($2);
+ }), o("PROTOTYPE_ACCESS Identifier", function() {
+ return new Accessor($2, 'prototype');
+ }), o("::", function() {
+ return new Accessor(new Literal('prototype'));
+ }), o("SOAK_ACCESS Identifier", function() {
+ return new Accessor($2, 'soak');
+ }), o("Index"), o("Slice", function() {
+ return new Slice($1);
+ })
+ ],
+ Index: [
+ o("INDEX_START Expression INDEX_END", function() {
+ return new Index($2);
+ }), o("INDEX_SOAK Index", function() {
+ $2.soakNode = true;
+ return $2;
+ }), o("INDEX_PROTO Index", function() {
+ $2.proto = true;
+ return $2;
+ })
+ ],
+ Object: [
+ o("{ AssignList OptComma }", function() {
+ return new ObjectLiteral($2);
+ })
+ ],
+ AssignList: [
+ o("", function() {
+ return [];
+ }), o("AssignObj", function() {
+ return [$1];
+ }), o("AssignList , AssignObj", function() {
+ return $1.concat($3);
+ }), o("AssignList OptComma TERMINATOR AssignObj", function() {
+ return $1.concat($4);
+ }), o("AssignList OptComma INDENT AssignList OptComma OUTDENT", function() {
+ return $1.concat($4);
+ })
+ ],
+ Class: [
+ o("CLASS SimpleAssignable", function() {
+ return new Class($2);
+ }), o("CLASS SimpleAssignable EXTENDS Value", function() {
+ return new Class($2, $4);
+ }), o("CLASS SimpleAssignable INDENT ClassBody OUTDENT", function() {
+ return new Class($2, null, $4);
+ }), o("CLASS SimpleAssignable EXTENDS Value INDENT ClassBody OUTDENT", function() {
+ return new Class($2, $4, $6);
+ }), o("CLASS INDENT ClassBody OUTDENT", function() {
+ return new Class('__temp__', null, $3);
+ }), o("CLASS", function() {
+ return new Class('__temp__', null, new Expressions);
+ }), o("CLASS EXTENDS Value", function() {
+ return new Class('__temp__', $3, new Expressions);
+ }), o("CLASS EXTENDS Value INDENT ClassBody OUTDENT", function() {
+ return new Class('__temp__', $3, $5);
+ })
+ ],
+ ClassAssign: [
+ o("AssignObj", function() {
+ return $1;
+ }), o("ThisProperty : Expression", function() {
+ return new Assign(new Value($1), $3, 'this');
+ }), o("ThisProperty : INDENT Expression OUTDENT", function() {
+ return new Assign(new Value($1), $4, 'this');
+ })
+ ],
+ ClassBody: [
+ o("", function() {
+ return [];
+ }), o("ClassAssign", function() {
+ return [$1];
+ }), o("ClassBody TERMINATOR ClassAssign", function() {
+ return $1.concat($3);
+ }), o("{ ClassBody }", function() {
+ return $2;
+ })
+ ],
+ Extends: [
+ o("SimpleAssignable EXTENDS Value", function() {
+ return new Extends($1, $3);
+ })
+ ],
+ Invocation: [
+ o("Value OptFuncExist Arguments", function() {
+ return new Call($1, $3, $2);
+ }), o("Invocation OptFuncExist Arguments", function() {
+ return new Call($1, $3, $2);
+ }), o("SUPER", function() {
+ return new Call('super', [new Splat(new Literal('arguments'))]);
+ }), o("SUPER Arguments", function() {
+ return new Call('super', $2);
+ })
+ ],
+ OptFuncExist: [
+ o("", function() {
+ return false;
+ }), o("FUNC_EXIST", function() {
+ return true;
+ })
+ ],
+ Arguments: [
+ o("CALL_START CALL_END", function() {
+ return [];
+ }), o("CALL_START ArgList OptComma CALL_END", function() {
+ return $2;
+ })
+ ],
+ This: [
+ o("THIS", function() {
+ return new Value(new Literal('this'));
+ }), o("@", function() {
+ return new Value(new Literal('this'));
+ })
+ ],
+ RangeDots: [
+ o("..", function() {
+ return 'inclusive';
+ }), o("...", function() {
+ return 'exclusive';
+ })
+ ],
+ ThisProperty: [
+ o("@ Identifier", function() {
+ return new Value(new Literal('this'), [new Accessor($2)], 'this');
+ })
+ ],
+ Range: [
+ o("[ Expression RangeDots Expression ]", function() {
+ return new Range($2, $4, $3);
+ })
+ ],
+ Slice: [
+ o("INDEX_START Expression RangeDots Expression INDEX_END", function() {
+ return new Range($2, $4, $3);
+ }), o("INDEX_START Expression RangeDots INDEX_END", function() {
+ return new Range($2, null, $3);
+ }), o("INDEX_START RangeDots Expression INDEX_END", function() {
+ return new Range(null, $3, $2);
+ })
+ ],
+ Array: [
+ o("[ ]", function() {
+ return new ArrayLiteral([]);
+ }), o("[ ArgList OptComma ]", function() {
+ return new ArrayLiteral($2);
+ })
+ ],
+ ArgList: [
+ o("Arg", function() {
+ return [$1];
+ }), o("ArgList , Arg", function() {
+ return $1.concat($3);
+ }), o("ArgList OptComma TERMINATOR Arg", function() {
+ return $1.concat($4);
+ }), o("INDENT ArgList OptComma OUTDENT", function() {
+ return $2;
+ }), o("ArgList OptComma INDENT ArgList OptComma OUTDENT", function() {
+ return $1.concat($4);
+ })
+ ],
+ Arg: [o("Expression"), o("Splat")],
+ SimpleArgs: [
+ o("Expression"), o("SimpleArgs , Expression", function() {
+ return [].concat($1, $3);
+ })
+ ],
+ Try: [
+ o("TRY Block", function() {
+ return new Try($2);
+ }), o("TRY Block Catch", function() {
+ return new Try($2, $3[0], $3[1]);
+ }), o("TRY Block FINALLY Block", function() {
+ return new Try($2, null, null, $4);
+ }), o("TRY Block Catch FINALLY Block", function() {
+ return new Try($2, $3[0], $3[1], $5);
+ })
+ ],
+ Catch: [
+ o("CATCH Identifier Block", function() {
+ return [$2, $3];
+ })
+ ],
+ Throw: [
+ o("THROW Expression", function() {
+ return new Throw($2);
+ })
+ ],
+ Parenthetical: [
+ o("( Expression )", function() {
+ return new Parens($2);
+ }), o("( )", function() {
+ return new Parens(new Literal(''));
+ })
+ ],
+ WhileSource: [
+ o("WHILE Expression", function() {
+ return new While($2);
+ }), o("WHILE Expression WHEN Expression", function() {
+ return new While($2, {
+ guard: $4
+ });
+ }), o("UNTIL Expression", function() {
+ return new While($2, {
+ invert: true
+ });
+ }), o("UNTIL Expression WHEN Expression", function() {
+ return new While($2, {
+ invert: true,
+ guard: $4
+ });
+ })
+ ],
+ While: [
+ o("WhileSource Block", function() {
+ return $1.addBody($2);
+ }), o("Statement WhileSource", function() {
+ return $2.addBody(Expressions.wrap([$1]));
+ }), o("Expression WhileSource", function() {
+ return $2.addBody(Expressions.wrap([$1]));
+ }), o("Loop", function() {
+ return $1;
+ })
+ ],
+ Loop: [
+ o("LOOP Block", function() {
+ return new While(new Literal('true')).addBody($2);
+ }), o("LOOP Expression", function() {
+ return new While(new Literal('true')).addBody(Expressions.wrap([$2]));
+ })
+ ],
+ For: [
+ o("Statement ForBody", function() {
+ return new For($1, $2, $2.vars[0], $2.vars[1]);
+ }), o("Expression ForBody", function() {
+ return new For($1, $2, $2.vars[0], $2.vars[1]);
+ }), o("ForBody Block", function() {
+ return new For($2, $1, $1.vars[0], $1.vars[1]);
+ })
+ ],
+ ForBody: [
+ o("FOR Range", function() {
+ return {
+ source: new Value($2),
+ vars: []
+ };
+ }), o("ForStart ForSource", function() {
+ $2.raw = $1.raw;
+ $2.vars = $1;
+ return $2;
+ })
+ ],
+ ForStart: [
+ o("FOR ForVariables", function() {
+ return $2;
+ }), o("FOR ALL ForVariables", function() {
+ $3.raw = true;
+ return $3;
+ })
+ ],
+ ForValue: [
+ o("Identifier"), o("Array", function() {
+ return new Value($1);
+ }), o("Object", function() {
+ return new Value($1);
+ })
+ ],
+ ForVariables: [
+ o("ForValue", function() {
+ return [$1];
+ }), o("ForValue , ForValue", function() {
+ return [$1, $3];
+ })
+ ],
+ ForSource: [
+ o("FORIN Expression", function() {
+ return {
+ source: $2
+ };
+ }), o("FOROF Expression", function() {
+ return {
+ source: $2,
+ object: true
+ };
+ }), o("FORIN Expression WHEN Expression", function() {
+ return {
+ source: $2,
+ guard: $4
+ };
+ }), o("FOROF Expression WHEN Expression", function() {
+ return {
+ source: $2,
+ guard: $4,
+ object: true
+ };
+ }), o("FORIN Expression BY Expression", function() {
+ return {
+ source: $2,
+ step: $4
+ };
+ }), o("FORIN Expression WHEN Expression BY Expression", function() {
+ return {
+ source: $2,
+ guard: $4,
+ step: $6
+ };
+ }), o("FORIN Expression BY Expression WHEN Expression", function() {
+ return {
+ source: $2,
+ step: $4,
+ guard: $6
+ };
+ })
+ ],
+ Switch: [
+ o("SWITCH Expression INDENT Whens OUTDENT", function() {
+ return new Switch($2, $4);
+ }), o("SWITCH Expression INDENT Whens ELSE Block OUTDENT", function() {
+ return new Switch($2, $4, $6);
+ }), o("SWITCH INDENT Whens OUTDENT", function() {
+ return new Switch(null, $3);
+ }), o("SWITCH INDENT Whens ELSE Block OUTDENT", function() {
+ return new Switch(null, $3, $5);
+ })
+ ],
+ Whens: [
+ o("When"), o("Whens When", function() {
+ return $1.concat($2);
+ })
+ ],
+ When: [
+ o("LEADING_WHEN SimpleArgs Block", function() {
+ return [[$2, $3]];
+ }), o("LEADING_WHEN SimpleArgs Block TERMINATOR", function() {
+ return [[$2, $3]];
+ })
+ ],
+ IfBlock: [
+ o("IF Expression Block", function() {
+ return new If($2, $3);
+ }), o("UNLESS Expression Block", function() {
+ return new If($2, $3, {
+ invert: true
+ });
+ }), o("IfBlock ELSE IF Expression Block", function() {
+ return $1.addElse(new If($4, $5));
+ }), o("IfBlock ELSE Block", function() {
+ return $1.addElse($3);
+ })
+ ],
+ If: [
+ o("IfBlock"), o("Statement POST_IF Expression", function() {
+ return new If($3, Expressions.wrap([$1]), {
+ statement: true
+ });
+ }), o("Expression POST_IF Expression", function() {
+ return new If($3, Expressions.wrap([$1]), {
+ statement: true
+ });
+ }), o("Statement POST_UNLESS Expression", function() {
+ return new If($3, Expressions.wrap([$1]), {
+ statement: true,
+ invert: true
+ });
+ }), o("Expression POST_UNLESS Expression", function() {
+ return new If($3, Expressions.wrap([$1]), {
+ statement: true,
+ invert: true
+ });
+ })
+ ],
+ Operation: [
+ o("UNARY Expression", function() {
+ return new Op($1, $2);
+ }), o("- Expression", function() {
+ return new Op('-', $2);
+ }, {
+ prec: 'UNARY'
+ }), o("+ Expression", function() {
+ return new Op('+', $2);
+ }, {
+ prec: 'UNARY'
+ }), o("-- SimpleAssignable", function() {
+ return new Op('--', $2);
+ }), o("++ SimpleAssignable", function() {
+ return new Op('++', $2);
+ }), o("SimpleAssignable --", function() {
+ return new Op('--', $1, null, true);
+ }), o("SimpleAssignable ++", function() {
+ return new Op('++', $1, null, true);
+ }), o("Expression + Expression", function() {
+ return new Op('+', $1, $3);
+ }), o("Expression - Expression", function() {
+ return new Op('-', $1, $3);
+ }), o("Expression == Expression", function() {
+ return new Op('==', $1, $3);
+ }), o("Expression != Expression", function() {
+ return new Op('!=', $1, $3);
+ }), o("Expression MATH Expression", function() {
+ return new Op($2, $1, $3);
+ }), o("Expression SHIFT Expression", function() {
+ return new Op($2, $1, $3);
+ }), o("Expression COMPARE Expression", function() {
+ return new Op($2, $1, $3);
+ }), o("Expression LOGIC Expression", function() {
+ return new Op($2, $1, $3);
+ }), o("SimpleAssignable COMPOUND_ASSIGN Expression", function() {
+ return new Op($2, $1, $3);
+ }), o("SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT", function() {
+ return new Op($2, $1, $4);
+ }), o("Expression RELATION Expression", function() {
+ return $2.charAt(0) === '!' ? ($2 === '!in' ? new Op('!', new In($1, $3)) : new Op('!', new Parens(new Op($2.slice(1), $1, $3)))) : ($2 === 'in' ? new In($1, $3) : new Op($2, $1, $3));
+ })
+ ]
+ };
+ operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'RELATION'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
+ tokens = [];
+ for (name in grammar) {
+ if (!__hasProp.call(grammar, name)) continue;
+ alternatives = grammar[name];
+ grammar[name] = (function() {
+ _result = [];
+ for (_i = 0, _len = alternatives.length; _i < _len; _i++) {
+ alt = alternatives[_i];
+ _result.push((function() {
+ for (_j = 0, _len2 = (_ref = alt[0].split(' ')).length; _j < _len2; _j++) {
+ token = _ref[_j];
+ if (!grammar[token]) {
+ tokens.push(token);
+ }
+ }
+ if (name === 'Root') {
+ alt[1] = ("return " + (alt[1]));
+ }
+ return alt;
+ })());
+ }
+ return _result;
+ })();
+ }
+ exports.parser = new Parser({
+ tokens: tokens.join(' '),
+ bnf: grammar,
+ operators: operators.reverse(),
+ startSymbol: 'Root'
+ });
+}).call(this);
--- /dev/null
+(function() {
+ var extend, flatten, indexOf;
+ indexOf = (exports.indexOf = Array.indexOf || (Array.prototype.indexOf ? function(array, item, from) {
+ return array.indexOf(item, from);
+ } : function(array, item, from) {
+ var _len, index, other;
+ for (index = 0, _len = array.length; index < _len; index++) {
+ other = array[index];
+ if (other === item && (!from || (from <= index))) {
+ return index;
+ }
+ }
+ return -1;
+ }));
+ exports.include = function(list, value) {
+ return indexOf(list, value) >= 0;
+ };
+ exports.starts = function(string, literal, start) {
+ return literal === string.substr(start, literal.length);
+ };
+ exports.ends = function(string, literal, back) {
+ var len;
+ len = literal.length;
+ return literal === string.substr(string.length - len - (back || 0), len);
+ };
+ exports.compact = function(array) {
+ var _i, _len, _result, item;
+ _result = [];
+ for (_i = 0, _len = array.length; _i < _len; _i++) {
+ item = array[_i];
+ if (item) {
+ _result.push(item);
+ }
+ }
+ return _result;
+ };
+ exports.count = function(string, letter) {
+ var num, pos;
+ num = (pos = 0);
+ while (pos = 1 + string.indexOf(letter, pos)) {
+ num++;
+ }
+ return num;
+ };
+ exports.merge = function(options, overrides) {
+ return extend(extend({}, options), overrides);
+ };
+ extend = (exports.extend = function(object, properties) {
+ var key, val;
+ for (key in properties) {
+ val = properties[key];
+ object[key] = val;
+ }
+ return object;
+ });
+ exports.flatten = (flatten = function(array) {
+ var _i, _len, element, flattened;
+ flattened = [];
+ for (_i = 0, _len = array.length; _i < _len; _i++) {
+ element = array[_i];
+ if (element instanceof Array) {
+ flattened = flattened.concat(flatten(element));
+ } else {
+ flattened.push(element);
+ }
+ }
+ return flattened;
+ });
+ exports.del = function(obj, key) {
+ var val;
+ val = obj[key];
+ delete obj[key];
+ return val;
+ };
+ exports.last = function(array, back) {
+ return array[array.length - (back || 0) - 1];
+ };
+}).call(this);
--- /dev/null
+(function() {
+ var _ref, key, val;
+ var __hasProp = Object.prototype.hasOwnProperty;
+ for (key in _ref = require('./coffee-script')) {
+ if (!__hasProp.call(_ref, key)) continue;
+ val = _ref[key];
+ (exports[key] = val);
+ }
+}).call(this);
--- /dev/null
+(function() {
+ var ASSIGNED, BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LEADING_SPACES, LINE_BREAK, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NEXT_CHARACTER, NEXT_ELLIPSIS, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, TRAILING_SPACES, UNARY, WHITESPACE, _ref, compact, count, include, last, op, starts;
+ Rewriter = require('./rewriter').Rewriter;
+ _ref = require('./helpers'), include = _ref.include, count = _ref.count, starts = _ref.starts, compact = _ref.compact, last = _ref.last;
+ exports.Lexer = (function() {
+ Lexer = (function() {
+ function Lexer() {
+ return this;
+ };
+ return Lexer;
+ })();
+ Lexer.prototype.tokenize = function(code, options) {
+ var o;
+ code = code.replace(/\r/g, '').replace(TRAILING_SPACES, '');
+ o = options || {};
+ this.code = code;
+ this.i = 0;
+ this.line = o.line || 0;
+ this.indent = 0;
+ this.indebt = 0;
+ this.outdebt = 0;
+ this.seenFor = false;
+ this.indents = [];
+ this.tokens = [];
+ while (this.chunk = code.slice(this.i)) {
+ this.identifierToken() || this.commentToken() || this.whitespaceToken() || this.lineToken() || this.heredocToken() || this.stringToken() || this.numberToken() || this.regexToken() || this.jsToken() || this.literalToken();
+ }
+ this.closeIndentation();
+ if (o.rewrite === false) {
+ return this.tokens;
+ }
+ return (new Rewriter).rewrite(this.tokens);
+ };
+ Lexer.prototype.identifierToken = function() {
+ var colon, forcedIdentifier, id, input, match, tag;
+ if (!(match = IDENTIFIER.exec(this.chunk))) {
+ return false;
+ }
+ input = match[0], id = match[1], colon = match[2];
+ this.i += input.length;
+ if (id === 'all' && this.tag() === 'FOR') {
+ this.token('ALL', id);
+ return true;
+ }
+ forcedIdentifier = colon || this.tagAccessor();
+ tag = 'IDENTIFIER';
+ if (include(JS_KEYWORDS, id) || !forcedIdentifier && include(COFFEE_KEYWORDS, id)) {
+ tag = id.toUpperCase();
+ if (tag === 'WHEN' && include(LINE_BREAK, this.tag())) {
+ tag = 'LEADING_WHEN';
+ } else if (tag === 'FOR') {
+ this.seenFor = true;
+ } else if (include(UNARY, tag)) {
+ tag = 'UNARY';
+ } else if (include(RELATION, tag)) {
+ if (tag !== 'INSTANCEOF' && this.seenFor) {
+ this.seenFor = false;
+ tag = 'FOR' + tag;
+ } else {
+ tag = 'RELATION';
+ if (this.value() === '!') {
+ this.tokens.pop();
+ id = '!' + id;
+ }
+ }
+ }
+ }
+ if (include(JS_FORBIDDEN, id)) {
+ if (forcedIdentifier) {
+ tag = 'IDENTIFIER';
+ id = new String(id);
+ id.reserved = true;
+ } else if (include(RESERVED, id)) {
+ this.identifierError(id);
+ }
+ }
+ if (!forcedIdentifier) {
+ if (COFFEE_ALIASES.hasOwnProperty(id)) {
+ tag = (id = COFFEE_ALIASES[id]);
+ }
+ if (id === '!') {
+ tag = 'UNARY';
+ } else if (include(LOGIC, id)) {
+ tag = 'LOGIC';
+ } else if (include(BOOL, tag)) {
+ id = tag.toLowerCase();
+ tag = 'BOOL';
+ }
+ }
+ this.token(tag, id);
+ if (colon) {
+ this.token(':', ':');
+ }
+ return true;
+ };
+ Lexer.prototype.numberToken = function() {
+ var match, number;
+ if (!(match = NUMBER.exec(this.chunk))) {
+ return false;
+ }
+ number = match[0];
+ if (this.tag() === '.' && number.charAt(0) === '.') {
+ return false;
+ }
+ this.i += number.length;
+ this.token('NUMBER', number);
+ return true;
+ };
+ Lexer.prototype.stringToken = function() {
+ var match, string;
+ switch (this.chunk.charAt(0)) {
+ case "'":
+ if (!(match = SIMPLESTR.exec(this.chunk))) {
+ return false;
+ }
+ this.token('STRING', (string = match[0]).replace(MULTILINER, '\\\n'));
+ break;
+ case '"':
+ if (!(string = this.balancedString(this.chunk, [['"', '"'], ['#{', '}']]))) {
+ return false;
+ }
+ if (0 < string.indexOf('#{', 1)) {
+ this.interpolateString(string.slice(1, -1));
+ } else {
+ this.token('STRING', this.escapeLines(string));
+ }
+ break;
+ default:
+ return false;
+ }
+ this.line += count(string, '\n');
+ this.i += string.length;
+ return true;
+ };
+ Lexer.prototype.heredocToken = function() {
+ var doc, heredoc, match, quote;
+ if (!(match = HEREDOC.exec(this.chunk))) {
+ return false;
+ }
+ heredoc = match[0];
+ quote = heredoc.charAt(0);
+ doc = this.sanitizeHeredoc(match[2], {
+ quote: quote,
+ indent: null
+ });
+ if (quote === '"' && (0 <= doc.indexOf('#{'))) {
+ this.interpolateString(doc, {
+ heredoc: true
+ });
+ } else {
+ this.token('STRING', this.makeString(doc, quote, true));
+ }
+ this.line += count(heredoc, '\n');
+ this.i += heredoc.length;
+ return true;
+ };
+ Lexer.prototype.commentToken = function() {
+ var comment, here, match;
+ if (!(match = this.chunk.match(COMMENT))) {
+ return false;
+ }
+ comment = match[0], here = match[1];
+ this.line += count(comment, '\n');
+ this.i += comment.length;
+ if (here) {
+ this.token('HERECOMMENT', this.sanitizeHeredoc(here, {
+ herecomment: true,
+ indent: Array(this.indent + 1).join(' ')
+ }));
+ this.token('TERMINATOR', '\n');
+ }
+ return true;
+ };
+ Lexer.prototype.jsToken = function() {
+ var match, script;
+ if (!(this.chunk.charAt(0) === '`' && (match = JSTOKEN.exec(this.chunk)))) {
+ return false;
+ }
+ this.token('JS', (script = match[0]).slice(1, -1));
+ this.i += script.length;
+ return true;
+ };
+ Lexer.prototype.regexToken = function() {
+ var match, regex;
+ if (this.chunk.charAt(0) !== '/') {
+ return false;
+ }
+ if (match = HEREGEX.exec(this.chunk)) {
+ return this.heregexToken(match);
+ }
+ if (include(NOT_REGEX, this.tag())) {
+ return false;
+ }
+ if (!(match = REGEX.exec(this.chunk))) {
+ return false;
+ }
+ regex = match[0];
+ this.token('REGEX', regex === '//' ? '/(?:)/' : regex);
+ this.i += regex.length;
+ return true;
+ };
+ Lexer.prototype.heregexToken = function(match) {
+ var _i, _len, _ref2, _ref3, _ref4, _this, body, flags, heregex, re, tag, tokens, value;
+ heregex = match[0], body = match[1], flags = match[2];
+ this.i += heregex.length;
+ if (0 > body.indexOf('#{')) {
+ re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/');
+ this.token('REGEX', "/" + (re || '(?:)') + "/" + flags);
+ return true;
+ }
+ this.token('IDENTIFIER', 'RegExp');
+ this.tokens.push(['CALL_START', '(']);
+ tokens = [];
+ for (_i = 0, _len = (_ref2 = this.interpolateString(body, {
+ regex: true
+ })).length; _i < _len; _i++) {
+ _ref3 = _ref2[_i], tag = _ref3[0], value = _ref3[1];
+ if (tag === 'TOKENS') {
+ tokens.push.apply(tokens, value);
+ } else {
+ if (!(value = value.replace(HEREGEX_OMIT, ''))) {
+ continue;
+ }
+ value = value.replace(/\\/g, '\\\\');
+ tokens.push(['STRING', this.makeString(value, '"', true)]);
+ }
+ tokens.push(['+', '+']);
+ }
+ tokens.pop();
+ if ((((_ref4 = tokens[0]) != null) ? _ref4[0] : undefined) !== 'STRING') {
+ this.tokens.push(['STRING', '""'], ['+', '+']);
+ }
+ (_this = this.tokens).push.apply(_this, tokens);
+ if (flags) {
+ this.tokens.push([',', ','], ['STRING', '"' + flags + '"']);
+ }
+ this.token(')', ')');
+ return true;
+ };
+ Lexer.prototype.lineToken = function() {
+ var diff, indent, match, nextCharacter, noNewlines, prev, size;
+ if (!(match = MULTI_DENT.exec(this.chunk))) {
+ return false;
+ }
+ indent = match[0];
+ this.line += count(indent, '\n');
+ this.i += indent.length;
+ prev = last(this.tokens, 1);
+ size = indent.length - 1 - indent.lastIndexOf('\n');
+ nextCharacter = NEXT_CHARACTER.exec(this.chunk)[1];
+ noNewlines = ((nextCharacter === '.' || nextCharacter === ',') && !NEXT_ELLIPSIS.test(this.chunk)) || this.unfinished();
+ if (size - this.indebt === this.indent) {
+ if (noNewlines) {
+ return this.suppressNewlines();
+ }
+ return this.newlineToken(indent);
+ } else if (size > this.indent) {
+ if (noNewlines) {
+ this.indebt = size - this.indent;
+ return this.suppressNewlines();
+ }
+ diff = size - this.indent + this.outdebt;
+ this.token('INDENT', diff);
+ this.indents.push(diff);
+ this.outdebt = (this.indebt = 0);
+ } else {
+ this.indebt = 0;
+ this.outdentToken(this.indent - size, noNewlines);
+ }
+ this.indent = size;
+ return true;
+ };
+ Lexer.prototype.outdentToken = function(moveOut, noNewlines, close) {
+ var dent, len;
+ while (moveOut > 0) {
+ len = this.indents.length - 1;
+ if (this.indents[len] === undefined) {
+ moveOut = 0;
+ } else if (this.indents[len] === this.outdebt) {
+ moveOut -= this.outdebt;
+ this.outdebt = 0;
+ } else if (this.indents[len] < this.outdebt) {
+ this.outdebt -= this.indents[len];
+ moveOut -= this.indents[len];
+ } else {
+ dent = this.indents.pop() - this.outdebt;
+ moveOut -= dent;
+ this.outdebt = 0;
+ this.token('OUTDENT', dent);
+ }
+ }
+ if (dent) {
+ this.outdebt -= moveOut;
+ }
+ if (!(this.tag() === 'TERMINATOR' || noNewlines)) {
+ this.token('TERMINATOR', '\n');
+ }
+ return true;
+ };
+ Lexer.prototype.whitespaceToken = function() {
+ var match, prev;
+ if (!(match = WHITESPACE.exec(this.chunk))) {
+ return false;
+ }
+ prev = last(this.tokens);
+ if (prev) {
+ prev.spaced = true;
+ }
+ this.i += match[0].length;
+ return true;
+ };
+ Lexer.prototype.newlineToken = function(newlines) {
+ if (this.tag() !== 'TERMINATOR') {
+ this.token('TERMINATOR', '\n');
+ }
+ return true;
+ };
+ Lexer.prototype.suppressNewlines = function() {
+ if (this.value() === '\\') {
+ this.tokens.pop();
+ }
+ return true;
+ };
+ Lexer.prototype.literalToken = function() {
+ var _ref2, match, prev, tag, value;
+ if (match = OPERATOR.exec(this.chunk)) {
+ value = match[0];
+ if (CODE.test(value)) {
+ this.tagParameters();
+ }
+ } else {
+ value = this.chunk.charAt(0);
+ }
+ this.i += value.length;
+ tag = value;
+ prev = last(this.tokens);
+ if (value === '=' && prev) {
+ if (!prev[1].reserved && include(JS_FORBIDDEN, prev[1])) {
+ this.assignmentError();
+ }
+ if (((_ref2 = prev[1]) === '||' || _ref2 === '&&')) {
+ prev[0] = 'COMPOUND_ASSIGN';
+ prev[1] += '=';
+ return true;
+ }
+ }
+ if (';' === value) {
+ tag = 'TERMINATOR';
+ } else if (include(LOGIC, value)) {
+ tag = 'LOGIC';
+ } else if (include(MATH, value)) {
+ tag = 'MATH';
+ } else if (include(COMPARE, value)) {
+ tag = 'COMPARE';
+ } else if (include(COMPOUND_ASSIGN, value)) {
+ tag = 'COMPOUND_ASSIGN';
+ } else if (include(UNARY, value)) {
+ tag = 'UNARY';
+ } else if (include(SHIFT, value)) {
+ tag = 'SHIFT';
+ } else if (value === '?' && ((prev != null) ? prev.spaced : undefined)) {
+ tag = 'LOGIC';
+ } else if (prev && !prev.spaced) {
+ if (value === '(' && include(CALLABLE, prev[0])) {
+ if (prev[0] === '?') {
+ prev[0] = 'FUNC_EXIST';
+ }
+ tag = 'CALL_START';
+ } else if (value === '[' && include(INDEXABLE, prev[0])) {
+ tag = 'INDEX_START';
+ switch (prev[0]) {
+ case '?':
+ prev[0] = 'INDEX_SOAK';
+ break;
+ case '::':
+ prev[0] = 'INDEX_PROTO';
+ break;
+ }
+ }
+ }
+ this.token(tag, value);
+ return true;
+ };
+ Lexer.prototype.tagAccessor = function() {
+ var prev;
+ if (!(prev = last(this.tokens)) || prev.spaced) {
+ return false;
+ }
+ if (prev[1] === '::') {
+ this.tag(0, 'PROTOTYPE_ACCESS');
+ } else if (prev[1] === '.' && this.value(1) !== '.') {
+ if (this.tag(1) === '?') {
+ this.tag(0, 'SOAK_ACCESS');
+ this.tokens.splice(-2, 1);
+ } else {
+ this.tag(0, 'PROPERTY_ACCESS');
+ }
+ } else {
+ return prev[0] === '@';
+ }
+ return true;
+ };
+ Lexer.prototype.sanitizeHeredoc = function(doc, options) {
+ var _ref2, attempt, herecomment, indent, match;
+ indent = options.indent, herecomment = options.herecomment;
+ if (herecomment && 0 > doc.indexOf('\n')) {
+ return doc;
+ }
+ if (!herecomment) {
+ while (match = HEREDOC_INDENT.exec(doc)) {
+ attempt = match[1];
+ if (indent === null || (0 < (_ref2 = attempt.length)) && (_ref2 < indent.length)) {
+ indent = attempt;
+ }
+ }
+ }
+ if (indent) {
+ doc = doc.replace(RegExp("\\n" + indent, "g"), '\n');
+ }
+ if (!herecomment) {
+ doc = doc.replace(/^\n/, '');
+ }
+ return doc;
+ };
+ Lexer.prototype.tagParameters = function() {
+ var i, tok;
+ if (this.tag() !== ')') {
+ return;
+ }
+ i = this.tokens.length;
+ while (tok = this.tokens[--i]) {
+ switch (tok[0]) {
+ case 'IDENTIFIER':
+ tok[0] = 'PARAM';
+ break;
+ case ')':
+ tok[0] = 'PARAM_END';
+ break;
+ case '(':
+ case 'CALL_START':
+ tok[0] = 'PARAM_START';
+ return true;
+ }
+ }
+ return true;
+ };
+ Lexer.prototype.closeIndentation = function() {
+ return this.outdentToken(this.indent);
+ };
+ Lexer.prototype.identifierError = function(word) {
+ throw SyntaxError("Reserved word \"" + word + "\" on line " + (this.line + 1));
+ };
+ Lexer.prototype.assignmentError = function() {
+ throw SyntaxError("Reserved word \"" + (this.value()) + "\" on line " + (this.line + 1) + " can't be assigned");
+ };
+ Lexer.prototype.balancedString = function(str, delimited, options) {
+ var _i, _len, close, i, levels, open, pair, slen;
+ options || (options = {});
+ levels = [];
+ i = 0;
+ slen = str.length;
+ while (i < slen) {
+ if (levels.length && str.charAt(i) === '\\') {
+ i += 1;
+ } else {
+ for (_i = 0, _len = delimited.length; _i < _len; _i++) {
+ pair = delimited[_i];
+ open = pair[0], close = pair[1];
+ if (levels.length && starts(str, close, i) && last(levels) === pair) {
+ levels.pop();
+ i += close.length - 1;
+ if (!levels.length) {
+ i += 1;
+ }
+ break;
+ }
+ if (starts(str, open, i)) {
+ levels.push(pair);
+ i += open.length - 1;
+ break;
+ }
+ }
+ }
+ if (!levels.length) {
+ break;
+ }
+ i += 1;
+ }
+ if (levels.length) {
+ throw SyntaxError("Unterminated " + (levels.pop()[0]) + " starting on line " + (this.line + 1));
+ }
+ return !i ? false : str.slice(0, i);
+ };
+ Lexer.prototype.interpolateString = function(str, options) {
+ var _len, _ref2, _ref3, _this, expr, heredoc, i, inner, interpolated, letter, nested, pi, regex, tag, tokens, value;
+ _ref2 = options || (options = {}), heredoc = _ref2.heredoc, regex = _ref2.regex;
+ tokens = [];
+ pi = 0;
+ i = -1;
+ while (letter = str.charAt(i += 1)) {
+ if (letter === '\\') {
+ i += 1;
+ continue;
+ }
+ if (!(letter === '#' && str.charAt(i + 1) === '{' && (expr = this.balancedString(str.slice(i + 1), [['{', '}']])))) {
+ continue;
+ }
+ if (pi < i) {
+ tokens.push(['TO_BE_STRING', str.slice(pi, i)]);
+ }
+ inner = expr.slice(1, -1).replace(LEADING_SPACES, '').replace(TRAILING_SPACES, '');
+ if (inner.length) {
+ nested = new Lexer().tokenize(inner, {
+ line: this.line,
+ rewrite: false
+ });
+ nested.pop();
+ if (nested.length > 1) {
+ nested.unshift(['(', '(']);
+ nested.push([')', ')']);
+ }
+ tokens.push(['TOKENS', nested]);
+ }
+ i += expr.length;
+ pi = i + 1;
+ }
+ if ((i > pi) && (pi < str.length)) {
+ tokens.push(['TO_BE_STRING', str.slice(pi)]);
+ }
+ if (regex) {
+ return tokens;
+ }
+ if (!tokens.length) {
+ return this.token('STRING', '""');
+ }
+ if (tokens[0][0] !== 'TO_BE_STRING') {
+ tokens.unshift(['', '']);
+ }
+ if (interpolated = tokens.length > 1) {
+ this.token('(', '(');
+ }
+ for (i = 0, _len = tokens.length; i < _len; i++) {
+ _ref3 = tokens[i], tag = _ref3[0], value = _ref3[1];
+ if (i) {
+ this.token('+', '+');
+ }
+ if (tag === 'TOKENS') {
+ (_this = this.tokens).push.apply(_this, value);
+ } else {
+ this.token('STRING', this.makeString(value, '"', heredoc));
+ }
+ }
+ if (interpolated) {
+ this.token(')', ')');
+ }
+ return tokens;
+ };
+ Lexer.prototype.token = function(tag, value) {
+ return this.tokens.push([tag, value, this.line]);
+ };
+ Lexer.prototype.tag = function(index, tag) {
+ var tok;
+ return (tok = last(this.tokens, index)) && ((tag != null) ? (tok[0] = tag) : tok[0]);
+ };
+ Lexer.prototype.value = function(index, val) {
+ var tok;
+ return (tok = last(this.tokens, index)) && ((val != null) ? (tok[1] = val) : tok[1]);
+ };
+ Lexer.prototype.unfinished = function() {
+ var prev, value;
+ return (prev = last(this.tokens, 1)) && prev[0] !== '.' && (value = this.value()) && !value.reserved && NO_NEWLINE.test(value) && !CODE.test(value) && !ASSIGNED.test(this.chunk);
+ };
+ Lexer.prototype.escapeLines = function(str, heredoc) {
+ return str.replace(MULTILINER, heredoc ? '\\n' : '');
+ };
+ Lexer.prototype.makeString = function(body, quote, heredoc) {
+ if (!body) {
+ return quote + quote;
+ }
+ body = body.replace(/\\([\s\S])/g, function(match, contents) {
+ return (contents === '\n' || contents === quote) ? contents : match;
+ });
+ body = body.replace(RegExp("" + quote, "g"), '\\$&');
+ return quote + this.escapeLines(body, heredoc) + quote;
+ };
+ return Lexer;
+ })();
+ JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
+ COFFEE_KEYWORDS = ['then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
+ for (op in (COFFEE_ALIASES = {
+ and: '&&',
+ or: '||',
+ is: '==',
+ isnt: '!=',
+ not: '!',
+ yes: 'TRUE',
+ no: 'FALSE',
+ on: 'TRUE',
+ off: 'FALSE'
+ })) {
+ COFFEE_KEYWORDS.push(op);
+ }
+ RESERVED = ['case', 'default', 'do', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice'];
+ JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
+ IDENTIFIER = /^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/;
+ NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i;
+ HEREDOC = /^("""|''')([\s\S]*?)(?:\n[ \t]*)?\1/;
+ OPERATOR = /^(?:-[-=>]?|\+[+=]?|\.\.\.?|[*&|\/%=<>^:!?]+)/;
+ WHITESPACE = /^[ \t]+/;
+ COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/;
+ CODE = /^[-=]>/;
+ MULTI_DENT = /^(?:\n[ \t]*)+/;
+ SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/;
+ JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/;
+ REGEX = /^\/(?!\s)[^[\/\n\\]*(?:(?:\\[\s\S]|\[[^\]\n\\]*(?:\\[\s\S][^\]\n\\]*)*])[^[\/\n\\]*)*\/[imgy]{0,4}(?![A-Za-z])/;
+ HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?![A-Za-z])/;
+ HEREGEX_OMIT = /\s+(?:#.*)?/g;
+ MULTILINER = /\n/g;
+ HEREDOC_INDENT = /\n+([ \t]*)/g;
+ ASSIGNED = /^\s*@?[$A-Za-z_][$\w]*[ \t]*?[:=][^:=>]/;
+ NEXT_CHARACTER = /^\s*(\S?)/;
+ NEXT_ELLIPSIS = /^\s*\.\.\.?/;
+ LEADING_SPACES = /^\s+/;
+ TRAILING_SPACES = /\s+$/;
+ NO_NEWLINE = /^(?:[-+*&|\/%=<>!.\\][<>=&|]*|and|or|is(?:nt)?|n(?:ot|ew)|delete|typeof|instanceof)$/;
+ COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|='];
+ UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE'];
+ LOGIC = ['&', '|', '^', '&&', '||'];
+ SHIFT = ['<<', '>>', '>>>'];
+ COMPARE = ['<=', '<', '>', '>='];
+ MATH = ['*', '/', '%'];
+ RELATION = ['IN', 'OF', 'INSTANCEOF'];
+ BOOL = ['TRUE', 'FALSE', 'NULL'];
+ NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']'];
+ CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER'];
+ INDEXABLE = CALLABLE.concat('NUMBER', 'BOOL');
+ LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR'];
+}).call(this);
--- /dev/null
+(function() {
+ var Accessor, ArrayLiteral, Assign, Base, Call, Class, Closure, Code, Comment, Existence, Expressions, Extends, For, IDENTIFIER, IS_STRING, If, In, Index, Literal, NO, NUMBER, ObjectLiteral, Op, Param, Parens, Push, Range, Return, SIMPLENUM, Scope, Slice, Splat, Switch, TAB, THIS, TRAILING_WHITESPACE, Throw, Try, UTILITIES, Value, While, YES, _ref, compact, del, ends, flatten, include, last, merge, starts, utility;
+ var __extends = function(child, parent) {
+ function ctor() { this.constructor = child; }
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ Scope = require('./scope').Scope;
+ _ref = require('./helpers'), compact = _ref.compact, flatten = _ref.flatten, merge = _ref.merge, del = _ref.del, include = _ref.include, starts = _ref.starts, ends = _ref.ends, last = _ref.last;
+ YES = function() {
+ return true;
+ };
+ NO = function() {
+ return false;
+ };
+ THIS = function() {
+ return this;
+ };
+ exports.Base = (function() {
+ Base = (function() {
+ function Base() {
+ this.tags = {};
+ return this;
+ };
+ return Base;
+ })();
+ Base.prototype.compile = function(o) {
+ var closure, code, top;
+ this.options = o ? merge(o) : {};
+ this.tab = o.indent;
+ top = this.topSensitive() ? this.options.top : del(this.options, 'top');
+ closure = this.isStatement(o) && !this.isPureStatement() && !top && !this.options.asStatement && !(this instanceof Comment);
+ code = closure ? this.compileClosure(this.options) : this.compileNode(this.options);
+ return code;
+ };
+ Base.prototype.compileClosure = function(o) {
+ o.sharedScope = o.scope;
+ if (this.containsPureStatement()) {
+ throw new Error('cannot include a pure statement in an expression.');
+ }
+ return Closure.wrap(this).compile(o);
+ };
+ Base.prototype.compileReference = function(o, options) {
+ var _len, compiled, i, node, pair, reference;
+ pair = (function() {
+ if (!this.isComplex()) {
+ return [this, this];
+ } else {
+ reference = new Literal(o.scope.freeVariable('ref'));
+ compiled = new Assign(reference, this);
+ return [compiled, reference];
+ }
+ }).call(this);
+ if (((options != null) ? options.precompile : undefined)) {
+ for (i = 0, _len = pair.length; i < _len; i++) {
+ node = pair[i];
+ (pair[i] = node.compile(o));
+ }
+ }
+ return pair;
+ };
+ Base.prototype.idt = function(tabs) {
+ var idt, num;
+ idt = this.tab || '';
+ num = (tabs || 0) + 1;
+ while (num -= 1) {
+ idt += TAB;
+ }
+ return idt;
+ };
+ Base.prototype.makeReturn = function() {
+ return new Return(this);
+ };
+ Base.prototype.contains = function(block) {
+ var contains;
+ contains = false;
+ this.traverseChildren(false, function(node) {
+ if (block(node)) {
+ contains = true;
+ return false;
+ }
+ });
+ return contains;
+ };
+ Base.prototype.containsType = function(type) {
+ return this instanceof type || this.contains(function(node) {
+ return node instanceof type;
+ });
+ };
+ Base.prototype.containsPureStatement = function() {
+ return this.isPureStatement() || this.contains(function(node) {
+ return node.isPureStatement();
+ });
+ };
+ Base.prototype.traverse = function(block) {
+ return this.traverseChildren(true, block);
+ };
+ Base.prototype.toString = function(idt, override) {
+ var _i, _len, _ref2, _result, child, children, klass;
+ idt || (idt = '');
+ children = (function() {
+ _result = [];
+ for (_i = 0, _len = (_ref2 = this.collectChildren()).length; _i < _len; _i++) {
+ child = _ref2[_i];
+ _result.push(child.toString(idt + TAB));
+ }
+ return _result;
+ }).call(this).join('');
+ klass = override || this.constructor.name + (this.soakNode ? '?' : '');
+ return '\n' + idt + klass + children;
+ };
+ Base.prototype.eachChild = function(func) {
+ var _i, _j, _len, _len2, _ref2, _ref3, _result, attr, child;
+ if (!this.children) {
+ return;
+ }
+ _result = [];
+ for (_i = 0, _len = (_ref2 = this.children).length; _i < _len; _i++) {
+ attr = _ref2[_i];
+ if (this[attr]) {
+ for (_j = 0, _len2 = (_ref3 = flatten([this[attr]])).length; _j < _len2; _j++) {
+ child = _ref3[_j];
+ if (func(child) === false) {
+ return;
+ }
+ }
+ }
+ }
+ return _result;
+ };
+ Base.prototype.collectChildren = function() {
+ var nodes;
+ nodes = [];
+ this.eachChild(function(node) {
+ return nodes.push(node);
+ });
+ return nodes;
+ };
+ Base.prototype.traverseChildren = function(crossScope, func) {
+ return this.eachChild(function(child) {
+ if (func(child) === false) {
+ return false;
+ }
+ return crossScope || !(child instanceof Code) ? child.traverseChildren(crossScope, func) : undefined;
+ });
+ };
+ Base.prototype.invert = function() {
+ return new Op('!', this);
+ };
+ Base.prototype.children = [];
+ Base.prototype.unwrap = THIS;
+ Base.prototype.isStatement = NO;
+ Base.prototype.isPureStatement = NO;
+ Base.prototype.isComplex = YES;
+ Base.prototype.topSensitive = NO;
+ Base.prototype.unfoldSoak = NO;
+ Base.prototype.assigns = NO;
+ return Base;
+ })();
+ exports.Expressions = (function() {
+ Expressions = (function() {
+ function Expressions(nodes) {
+ Expressions.__super__.constructor.call(this);
+ this.expressions = compact(flatten(nodes || []));
+ return this;
+ };
+ return Expressions;
+ })();
+ __extends(Expressions, Base);
+ Expressions.prototype.children = ['expressions'];
+ Expressions.prototype.isStatement = YES;
+ Expressions.prototype.push = function(node) {
+ this.expressions.push(node);
+ return this;
+ };
+ Expressions.prototype.unshift = function(node) {
+ this.expressions.unshift(node);
+ return this;
+ };
+ Expressions.prototype.unwrap = function() {
+ return this.expressions.length === 1 ? this.expressions[0] : this;
+ };
+ Expressions.prototype.empty = function() {
+ return this.expressions.length === 0;
+ };
+ Expressions.prototype.makeReturn = function() {
+ var end, idx;
+ end = this.expressions[(idx = this.expressions.length - 1)];
+ if (end instanceof Comment) {
+ end = this.expressions[idx -= 1];
+ }
+ if (end && !(end instanceof Return)) {
+ this.expressions[idx] = end.makeReturn();
+ }
+ return this;
+ };
+ Expressions.prototype.compile = function(o) {
+ o || (o = {});
+ return o.scope ? Expressions.__super__.compile.call(this, o) : this.compileRoot(o);
+ };
+ Expressions.prototype.compileNode = function(o) {
+ var _i, _len, _ref2, _result, node;
+ return (function() {
+ _result = [];
+ for (_i = 0, _len = (_ref2 = this.expressions).length; _i < _len; _i++) {
+ node = _ref2[_i];
+ _result.push(this.compileExpression(node, merge(o)));
+ }
+ return _result;
+ }).call(this).join('\n');
+ };
+ Expressions.prototype.compileRoot = function(o) {
+ var code;
+ o.indent = (this.tab = o.bare ? '' : TAB);
+ o.scope = new Scope(null, this, null);
+ code = this.compileWithDeclarations(o);
+ code = code.replace(TRAILING_WHITESPACE, '');
+ return o.bare ? code : ("(function() {\n" + code + "\n}).call(this);\n");
+ };
+ Expressions.prototype.compileWithDeclarations = function(o) {
+ var code;
+ code = this.compileNode(o);
+ if (o.scope.hasAssignments(this)) {
+ code = ("" + (this.tab) + "var " + (o.scope.compiledAssignments().replace(/\n/g, '$&' + this.tab)) + ";\n" + code);
+ }
+ if (!o.globals && o.scope.hasDeclarations(this)) {
+ code = ("" + (this.tab) + "var " + (o.scope.compiledDeclarations()) + ";\n" + code);
+ }
+ return code;
+ };
+ Expressions.prototype.compileExpression = function(node, o) {
+ var compiledNode;
+ this.tab = o.indent;
+ node.tags.front = true;
+ compiledNode = node.compile(merge(o, {
+ top: true
+ }));
+ return node.isStatement(o) ? compiledNode : ("" + (this.idt()) + compiledNode + ";");
+ };
+ return Expressions;
+ })();
+ Expressions.wrap = function(nodes) {
+ if (nodes.length === 1 && nodes[0] instanceof Expressions) {
+ return nodes[0];
+ }
+ return new Expressions(nodes);
+ };
+ exports.Literal = (function() {
+ Literal = (function() {
+ function Literal(_arg) {
+ this.value = _arg;
+ Literal.__super__.constructor.call(this);
+ return this;
+ };
+ return Literal;
+ })();
+ __extends(Literal, Base);
+ Literal.prototype.makeReturn = function() {
+ return this.isStatement() ? this : Literal.__super__.makeReturn.call(this);
+ };
+ Literal.prototype.isStatement = function() {
+ var _ref2;
+ return ((_ref2 = this.value) === 'break' || _ref2 === 'continue' || _ref2 === 'debugger');
+ };
+ Literal.prototype.isPureStatement = Literal.prototype.isStatement;
+ Literal.prototype.isComplex = NO;
+ Literal.prototype.isReserved = function() {
+ return !!this.value.reserved;
+ };
+ Literal.prototype.assigns = function(name) {
+ return name === this.value;
+ };
+ Literal.prototype.compileNode = function(o) {
+ var end, idt, val;
+ idt = this.isStatement(o) ? this.idt() : '';
+ end = this.isStatement(o) ? ';' : '';
+ val = this.isReserved() ? ("\"" + (this.value) + "\"") : this.value;
+ return idt + val + end;
+ };
+ Literal.prototype.toString = function() {
+ return ' "' + this.value + '"';
+ };
+ return Literal;
+ })();
+ exports.Return = (function() {
+ Return = (function() {
+ function Return(_arg) {
+ this.expression = _arg;
+ Return.__super__.constructor.call(this);
+ return this;
+ };
+ return Return;
+ })();
+ __extends(Return, Base);
+ Return.prototype.isStatement = YES;
+ Return.prototype.isPureStatement = YES;
+ Return.prototype.children = ['expression'];
+ Return.prototype.makeReturn = THIS;
+ Return.prototype.compile = function(o) {
+ var _ref2, expr;
+ expr = (((_ref2 = this.expression) != null) ? _ref2.makeReturn() : undefined);
+ if (expr && (!(expr instanceof Return))) {
+ return expr.compile(o);
+ }
+ return Return.__super__.compile.call(this, o);
+ };
+ Return.prototype.compileNode = function(o) {
+ var expr;
+ expr = '';
+ if (this.expression) {
+ if (this.expression.isStatement(o)) {
+ o.asStatement = true;
+ }
+ expr = ' ' + this.expression.compile(o);
+ }
+ return "" + (this.tab) + "return" + expr + ";";
+ };
+ return Return;
+ })();
+ exports.Value = (function() {
+ Value = (function() {
+ function Value(_arg, _arg2, tag) {
+ this.properties = _arg2;
+ this.base = _arg;
+ Value.__super__.constructor.call(this);
+ this.properties || (this.properties = []);
+ if (tag) {
+ this.tags[tag] = true;
+ }
+ return this;
+ };
+ return Value;
+ })();
+ __extends(Value, Base);
+ Value.prototype.children = ['base', 'properties'];
+ Value.prototype.push = function(prop) {
+ this.properties.push(prop);
+ return this;
+ };
+ Value.prototype.hasProperties = function() {
+ return !!this.properties.length;
+ };
+ Value.prototype.isArray = function() {
+ return this.base instanceof ArrayLiteral && !this.properties.length;
+ };
+ Value.prototype.isObject = function() {
+ return this.base instanceof ObjectLiteral && !this.properties.length;
+ };
+ Value.prototype.isSplice = function() {
+ return last(this.properties) instanceof Slice;
+ };
+ Value.prototype.isComplex = function() {
+ return this.base.isComplex() || this.hasProperties();
+ };
+ Value.prototype.assigns = function(name) {
+ return !this.properties.length && this.base.assigns(name);
+ };
+ Value.prototype.makeReturn = function() {
+ return this.properties.length ? Value.__super__.makeReturn.call(this) : this.base.makeReturn();
+ };
+ Value.prototype.unwrap = function() {
+ return this.properties.length ? this : this.base;
+ };
+ Value.prototype.isStatement = function(o) {
+ return this.base.isStatement(o) && !this.properties.length;
+ };
+ Value.prototype.isSimpleNumber = function() {
+ return this.base instanceof Literal && SIMPLENUM.test(this.base.value);
+ };
+ Value.prototype.cacheReference = function(o) {
+ var base, bref, name, nref;
+ name = last(this.properties);
+ if (!this.base.isComplex() && this.properties.length < 2 && !((name != null) ? name.isComplex() : undefined)) {
+ return [this, this];
+ }
+ base = new Value(this.base, this.properties.slice(0, -1));
+ if (base.isComplex()) {
+ bref = new Literal(o.scope.freeVariable('base'));
+ base = new Value(new Parens(new Assign(bref, base)));
+ }
+ if (!name) {
+ return [base, bref];
+ }
+ if (name.isComplex()) {
+ nref = new Literal(o.scope.freeVariable('name'));
+ name = new Index(new Assign(nref, name.index));
+ nref = new Index(nref);
+ }
+ return [base.push(name), new Value(bref || base.base, [nref || name])];
+ };
+ Value.prototype.compile = function(o) {
+ this.base.tags.front = this.tags.front;
+ return !o.top || this.properties.length ? Value.__super__.compile.call(this, o) : this.base.compile(o);
+ };
+ Value.prototype.compileNode = function(o) {
+ var _i, _len, code, ifn, prop, props;
+ if (ifn = this.unfoldSoak(o)) {
+ return ifn.compile(o);
+ }
+ props = this.properties;
+ if (this.parenthetical && !props.length) {
+ this.base.parenthetical = true;
+ }
+ code = this.base.compile(o);
+ if (props[0] instanceof Accessor && this.isSimpleNumber()) {
+ code = ("(" + code + ")");
+ }
+ for (_i = 0, _len = props.length; _i < _len; _i++) {
+ prop = props[_i];
+ (code += prop.compile(o));
+ }
+ return code;
+ };
+ Value.prototype.unfoldSoak = function(o) {
+ var _len, _ref2, fst, i, ifn, prop, ref, snd;
+ if (ifn = this.base.unfoldSoak(o)) {
+ Array.prototype.push.apply(ifn.body.properties, this.properties);
+ return ifn;
+ }
+ for (i = 0, _len = (_ref2 = this.properties).length; i < _len; i++) {
+ prop = _ref2[i];
+ if (prop.soakNode) {
+ prop.soakNode = false;
+ fst = new Value(this.base, this.properties.slice(0, i));
+ snd = new Value(this.base, this.properties.slice(i));
+ if (fst.isComplex()) {
+ ref = new Literal(o.scope.freeVariable('ref'));
+ fst = new Parens(new Assign(ref, fst));
+ snd.base = ref;
+ }
+ ifn = new If(new Existence(fst), snd, {
+ soak: true
+ });
+ return ifn;
+ }
+ }
+ return null;
+ };
+ return Value;
+ })();
+ exports.Comment = (function() {
+ Comment = (function() {
+ function Comment(_arg) {
+ this.comment = _arg;
+ Comment.__super__.constructor.call(this);
+ return this;
+ };
+ return Comment;
+ })();
+ __extends(Comment, Base);
+ Comment.prototype.isStatement = YES;
+ Comment.prototype.makeReturn = THIS;
+ Comment.prototype.compileNode = function(o) {
+ return this.tab + '/*' + this.comment.replace(/\n/g, '\n' + this.tab) + '*/';
+ };
+ return Comment;
+ })();
+ exports.Call = (function() {
+ Call = (function() {
+ function Call(variable, _arg, _arg2) {
+ this.soakNode = _arg2;
+ this.args = _arg;
+ Call.__super__.constructor.call(this);
+ this.isNew = false;
+ this.isSuper = variable === 'super';
+ this.variable = this.isSuper ? null : variable;
+ this.args || (this.args = []);
+ return this;
+ };
+ return Call;
+ })();
+ __extends(Call, Base);
+ Call.prototype.children = ['variable', 'args'];
+ Call.prototype.compileSplatArguments = function(o) {
+ return Splat.compileSplattedArray(this.args, o);
+ };
+ Call.prototype.newInstance = function() {
+ this.isNew = true;
+ return this;
+ };
+ Call.prototype.prefix = function() {
+ return this.isNew ? 'new ' : '';
+ };
+ Call.prototype.superReference = function(o) {
+ var method, name;
+ method = o.scope.method;
+ if (!method) {
+ throw Error("cannot call super outside of a function.");
+ }
+ name = method.name;
+ if (!name) {
+ throw Error("cannot call super on an anonymous function.");
+ }
+ return method.klass ? ("" + (method.klass) + ".__super__." + name) : ("" + name + ".__super__.constructor");
+ };
+ Call.prototype.unfoldSoak = function(o) {
+ var _i, _len, _ref2, _ref3, call, ifn, left, list, rite, val;
+ if (this.soakNode) {
+ if (val = this.variable) {
+ if (!(val instanceof Value)) {
+ val = new Value(val);
+ }
+ _ref2 = val.cacheReference(o), left = _ref2[0], rite = _ref2[1];
+ } else {
+ left = new Literal(this.superReference(o));
+ rite = new Value(left);
+ }
+ rite = new Call(rite, this.args);
+ rite.isNew = this.isNew;
+ left = new Literal("typeof " + (left.compile(o)) + " === \"function\"");
+ ifn = new If(left, new Value(rite), {
+ soak: true
+ });
+ return ifn;
+ }
+ call = this;
+ list = [];
+ while (true) {
+ if (call.variable instanceof Call) {
+ list.push(call);
+ call = call.variable;
+ continue;
+ }
+ if (!(call.variable instanceof Value)) {
+ break;
+ }
+ list.push(call);
+ if (!((call = call.variable.base) instanceof Call)) {
+ break;
+ }
+ }
+ for (_i = 0, _len = (_ref3 = list.reverse()).length; _i < _len; _i++) {
+ call = _ref3[_i];
+ if (ifn) {
+ if (call.variable instanceof Call) {
+ call.variable = ifn;
+ } else {
+ call.variable.base = ifn;
+ }
+ }
+ ifn = If.unfoldSoak(o, call, 'variable');
+ }
+ return ifn;
+ };
+ Call.prototype.compileNode = function(o) {
+ var _i, _j, _len, _len2, _ref2, _ref3, _ref4, _result, arg, args, ifn;
+ if (ifn = this.unfoldSoak(o)) {
+ return ifn.compile(o);
+ }
+ (((_ref2 = this.variable) != null) ? (_ref2.tags.front = this.tags.front) : undefined);
+ for (_i = 0, _len = (_ref3 = this.args).length; _i < _len; _i++) {
+ arg = _ref3[_i];
+ if (arg instanceof Splat) {
+ return this.compileSplat(o);
+ }
+ }
+ args = (function() {
+ _result = [];
+ for (_j = 0, _len2 = (_ref4 = this.args).length; _j < _len2; _j++) {
+ arg = _ref4[_j];
+ _result.push((arg.parenthetical = true) && arg.compile(o));
+ }
+ return _result;
+ }).call(this).join(', ');
+ return this.isSuper ? this.compileSuper(args, o) : ("" + (this.prefix()) + (this.variable.compile(o)) + "(" + args + ")");
+ };
+ Call.prototype.compileSuper = function(args, o) {
+ return "" + (this.superReference(o)) + ".call(this" + (args.length ? ', ' : '') + args + ")";
+ };
+ Call.prototype.compileSplat = function(o) {
+ var base, fun, idt, name, ref, splatargs;
+ splatargs = this.compileSplatArguments(o);
+ if (this.isSuper) {
+ return ("" + (this.superReference(o)) + ".apply(this, " + splatargs + ")");
+ }
+ if (!this.isNew) {
+ if (!((base = this.variable) instanceof Value)) {
+ base = new Value(base);
+ }
+ if ((name = base.properties.pop()) && base.isComplex()) {
+ ref = o.scope.freeVariable('this');
+ fun = ("(" + ref + " = " + (base.compile(o)) + ")" + (name.compile(o)));
+ } else {
+ fun = (ref = base.compile(o));
+ if (name) {
+ fun += name.compile(o);
+ }
+ }
+ return ("" + fun + ".apply(" + ref + ", " + splatargs + ")");
+ }
+ idt = this.idt(1);
+ return "(function(func, args, ctor) {\n" + idt + "ctor.prototype = func.prototype;\n" + idt + "var child = new ctor, result = func.apply(child, args);\n" + idt + "return typeof result === \"object\" ? result : child;\n" + (this.tab) + "})(" + (this.variable.compile(o)) + ", " + splatargs + ", function() {})";
+ };
+ return Call;
+ })();
+ exports.Extends = (function() {
+ Extends = (function() {
+ function Extends(_arg, _arg2) {
+ this.parent = _arg2;
+ this.child = _arg;
+ Extends.__super__.constructor.call(this);
+ return this;
+ };
+ return Extends;
+ })();
+ __extends(Extends, Base);
+ Extends.prototype.children = ['child', 'parent'];
+ Extends.prototype.compileNode = function(o) {
+ var ref;
+ ref = new Value(new Literal(utility('extends')));
+ return (new Call(ref, [this.child, this.parent])).compile(o);
+ };
+ return Extends;
+ })();
+ exports.Accessor = (function() {
+ Accessor = (function() {
+ function Accessor(_arg, tag) {
+ this.name = _arg;
+ Accessor.__super__.constructor.call(this);
+ this.prototype = tag === 'prototype' ? '.prototype' : '';
+ this.soakNode = tag === 'soak';
+ return this;
+ };
+ return Accessor;
+ })();
+ __extends(Accessor, Base);
+ Accessor.prototype.children = ['name'];
+ Accessor.prototype.compileNode = function(o) {
+ var name, namePart;
+ name = this.name.compile(o);
+ namePart = name.match(IS_STRING) ? ("[" + name + "]") : ("." + name);
+ return this.prototype + namePart;
+ };
+ Accessor.prototype.isComplex = NO;
+ return Accessor;
+ })();
+ exports.Index = (function() {
+ Index = (function() {
+ function Index(_arg) {
+ this.index = _arg;
+ Index.__super__.constructor.call(this);
+ return this;
+ };
+ return Index;
+ })();
+ __extends(Index, Base);
+ Index.prototype.children = ['index'];
+ Index.prototype.compileNode = function(o) {
+ var idx, prefix;
+ idx = this.index.compile(o);
+ prefix = this.proto ? '.prototype' : '';
+ return "" + prefix + "[" + idx + "]";
+ };
+ Index.prototype.isComplex = function() {
+ return this.index.isComplex();
+ };
+ return Index;
+ })();
+ exports.Range = (function() {
+ Range = (function() {
+ function Range(_arg, _arg2, tag) {
+ this.to = _arg2;
+ this.from = _arg;
+ Range.__super__.constructor.call(this);
+ this.exclusive = tag === 'exclusive';
+ this.equals = this.exclusive ? '' : '=';
+ return this;
+ };
+ return Range;
+ })();
+ __extends(Range, Base);
+ Range.prototype.children = ['from', 'to'];
+ Range.prototype.compileVariables = function(o) {
+ var _ref2, _ref3, _ref4, parts;
+ o = merge(o, {
+ top: true
+ });
+ _ref2 = this.from.compileReference(o, {
+ precompile: true
+ }), this.from = _ref2[0], this.fromVar = _ref2[1];
+ _ref3 = this.to.compileReference(o, {
+ precompile: true
+ }), this.to = _ref3[0], this.toVar = _ref3[1];
+ _ref4 = [this.fromVar.match(SIMPLENUM), this.toVar.match(SIMPLENUM)], this.fromNum = _ref4[0], this.toNum = _ref4[1];
+ parts = [];
+ if (this.from !== this.fromVar) {
+ parts.push(this.from);
+ }
+ return this.to !== this.toVar ? parts.push(this.to) : undefined;
+ };
+ Range.prototype.compileNode = function(o) {
+ var compare, idx, incr, intro, step, stepPart, vars;
+ this.compileVariables(o);
+ if (!o.index) {
+ return this.compileArray(o);
+ }
+ if (this.fromNum && this.toNum) {
+ return this.compileSimple(o);
+ }
+ idx = del(o, 'index');
+ step = del(o, 'step');
+ vars = ("" + idx + " = " + (this.from)) + (this.to !== this.toVar ? (", " + (this.to)) : '');
+ intro = ("(" + (this.fromVar) + " <= " + (this.toVar) + " ? " + idx);
+ compare = ("" + intro + " <" + (this.equals) + " " + (this.toVar) + " : " + idx + " >" + (this.equals) + " " + (this.toVar) + ")");
+ stepPart = step ? step.compile(o) : '1';
+ incr = step ? ("" + idx + " += " + stepPart) : ("" + intro + " += " + stepPart + " : " + idx + " -= " + stepPart + ")");
+ return "" + vars + "; " + compare + "; " + incr;
+ };
+ Range.prototype.compileSimple = function(o) {
+ var _ref2, from, idx, step, to;
+ _ref2 = [+this.fromNum, +this.toNum], from = _ref2[0], to = _ref2[1];
+ idx = del(o, 'index');
+ step = del(o, 'step');
+ step && (step = ("" + idx + " += " + (step.compile(o))));
+ return from <= to ? ("" + idx + " = " + from + "; " + idx + " <" + (this.equals) + " " + to + "; " + (step || ("" + idx + "++"))) : ("" + idx + " = " + from + "; " + idx + " >" + (this.equals) + " " + to + "; " + (step || ("" + idx + "--")));
+ };
+ Range.prototype.compileArray = function(o) {
+ var _i, _ref2, _ref3, _result, body, clause, i, idt, post, pre, range, result, vars;
+ if (this.fromNum && this.toNum && (Math.abs(this.fromNum - this.toNum) <= 20)) {
+ range = (function() {
+ _result = [];
+ for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i += 1 : _i -= 1){ _result.push(_i); }
+ return _result;
+ }).call(this);
+ if (this.exclusive) {
+ range.pop();
+ }
+ return ("[" + (range.join(', ')) + "]");
+ }
+ idt = this.idt(1);
+ i = o.scope.freeVariable('i');
+ result = o.scope.freeVariable('result');
+ pre = ("\n" + idt + result + " = [];");
+ if (this.fromNum && this.toNum) {
+ o.index = i;
+ body = this.compileSimple(o);
+ } else {
+ vars = ("" + i + " = " + (this.from)) + (this.to !== this.toVar ? (", " + (this.to)) : '');
+ clause = ("" + (this.fromVar) + " <= " + (this.toVar) + " ?");
+ body = ("var " + vars + "; " + clause + " " + i + " <" + (this.equals) + " " + (this.toVar) + " : " + i + " >" + (this.equals) + " " + (this.toVar) + "; " + clause + " " + i + " += 1 : " + i + " -= 1");
+ }
+ post = ("{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + (o.indent));
+ return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).call(this)";
+ };
+ return Range;
+ })();
+ exports.Slice = (function() {
+ Slice = (function() {
+ function Slice(_arg) {
+ this.range = _arg;
+ Slice.__super__.constructor.call(this);
+ return this;
+ };
+ return Slice;
+ })();
+ __extends(Slice, Base);
+ Slice.prototype.children = ['range'];
+ Slice.prototype.compileNode = function(o) {
+ var from, to;
+ from = this.range.from ? this.range.from.compile(o) : '0';
+ to = this.range.to ? this.range.to.compile(o) : '';
+ to += (!to || this.range.exclusive ? '' : ' + 1');
+ if (to) {
+ to = ', ' + to;
+ }
+ return ".slice(" + from + to + ")";
+ };
+ return Slice;
+ })();
+ exports.ObjectLiteral = (function() {
+ ObjectLiteral = (function() {
+ function ObjectLiteral(props) {
+ ObjectLiteral.__super__.constructor.call(this);
+ this.objects = (this.properties = props || []);
+ return this;
+ };
+ return ObjectLiteral;
+ })();
+ __extends(ObjectLiteral, Base);
+ ObjectLiteral.prototype.children = ['properties'];
+ ObjectLiteral.prototype.compileNode = function(o) {
+ var _i, _len, _ref2, _result, i, indent, join, lastNoncom, nonComments, obj, prop, props, top;
+ top = del(o, 'top');
+ o.indent = this.idt(1);
+ nonComments = (function() {
+ _result = [];
+ for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
+ prop = _ref2[_i];
+ if (!(prop instanceof Comment)) {
+ _result.push(prop);
+ }
+ }
+ return _result;
+ }).call(this);
+ lastNoncom = last(nonComments);
+ props = (function() {
+ _result = [];
+ for (i = 0, _len = (_ref2 = this.properties).length; i < _len; i++) {
+ prop = _ref2[i];
+ _result.push((function() {
+ join = i === this.properties.length - 1 ? '' : (prop === lastNoncom || prop instanceof Comment ? '\n' : ',\n');
+ indent = prop instanceof Comment ? '' : this.idt(1);
+ if (prop instanceof Value && prop.tags["this"]) {
+ prop = new Assign(prop.properties[0].name, prop, 'object');
+ } else if (!(prop instanceof Assign) && !(prop instanceof Comment)) {
+ prop = new Assign(prop, prop, 'object');
+ }
+ return indent + prop.compile(o) + join;
+ }).call(this));
+ }
+ return _result;
+ }).call(this);
+ props = props.join('');
+ obj = ("{" + (props ? '\n' + props + '\n' + this.idt() : '') + "}");
+ return this.tags.front ? ("(" + obj + ")") : obj;
+ };
+ ObjectLiteral.prototype.assigns = function(name) {
+ var _i, _len, _ref2, prop;
+ for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
+ prop = _ref2[_i];
+ if (prop.assigns(name)) {
+ return true;
+ }
+ }
+ return false;
+ };
+ return ObjectLiteral;
+ })();
+ exports.ArrayLiteral = (function() {
+ ArrayLiteral = (function() {
+ function ArrayLiteral(_arg) {
+ this.objects = _arg;
+ ArrayLiteral.__super__.constructor.call(this);
+ this.objects || (this.objects = []);
+ return this;
+ };
+ return ArrayLiteral;
+ })();
+ __extends(ArrayLiteral, Base);
+ ArrayLiteral.prototype.children = ['objects'];
+ ArrayLiteral.prototype.compileSplatLiteral = function(o) {
+ return Splat.compileSplattedArray(this.objects, o);
+ };
+ ArrayLiteral.prototype.compileNode = function(o) {
+ var _i, _len, _len2, _ref2, _ref3, code, i, obj, objects;
+ o.indent = this.idt(1);
+ for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
+ obj = _ref2[_i];
+ if (obj instanceof Splat) {
+ return this.compileSplatLiteral(o);
+ }
+ }
+ objects = [];
+ for (i = 0, _len2 = (_ref3 = this.objects).length; i < _len2; i++) {
+ obj = _ref3[i];
+ code = obj.compile(o);
+ objects.push(obj instanceof Comment ? ("\n" + code + "\n" + (o.indent)) : (i === this.objects.length - 1 ? code : code + ', '));
+ }
+ objects = objects.join('');
+ return 0 < objects.indexOf('\n') ? ("[\n" + (o.indent) + objects + "\n" + (this.tab) + "]") : ("[" + objects + "]");
+ };
+ ArrayLiteral.prototype.assigns = function(name) {
+ var _i, _len, _ref2, obj;
+ for (_i = 0, _len = (_ref2 = this.objects).length; _i < _len; _i++) {
+ obj = _ref2[_i];
+ if (obj.assigns(name)) {
+ return true;
+ }
+ }
+ return false;
+ };
+ return ArrayLiteral;
+ })();
+ exports.Class = (function() {
+ Class = (function() {
+ function Class(variable, _arg, _arg2) {
+ this.properties = _arg2;
+ this.parent = _arg;
+ Class.__super__.constructor.call(this);
+ this.variable = variable === '__temp__' ? new Literal(variable) : variable;
+ this.properties || (this.properties = []);
+ this.returns = false;
+ return this;
+ };
+ return Class;
+ })();
+ __extends(Class, Base);
+ Class.prototype.children = ['variable', 'parent', 'properties'];
+ Class.prototype.isStatement = YES;
+ Class.prototype.makeReturn = function() {
+ this.returns = true;
+ return this;
+ };
+ Class.prototype.compileNode = function(o) {
+ var _i, _len, _ref2, _ref3, _ref4, access, applied, apply, className, constScope, construct, constructor, extension, func, me, pname, prop, props, pvar, ref, returns, val, variable;
+ variable = this.variable;
+ if (variable.value === '__temp__') {
+ variable = new Literal(o.scope.freeVariable('ctor'));
+ }
+ extension = this.parent && new Extends(variable, this.parent);
+ props = new Expressions;
+ o.top = true;
+ me = null;
+ className = variable.compile(o);
+ constScope = null;
+ if (this.parent) {
+ applied = new Value(this.parent, [new Accessor(new Literal('apply'))]);
+ constructor = new Code([], new Expressions([new Call(applied, [new Literal('this'), new Literal('arguments')])]));
+ } else {
+ constructor = new Code([], new Expressions([new Return(new Literal('this'))]));
+ }
+ for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
+ prop = _ref2[_i];
+ _ref3 = [prop.variable, prop.value], pvar = _ref3[0], func = _ref3[1];
+ if (pvar && pvar.base.value === 'constructor') {
+ if (!(func instanceof Code)) {
+ _ref4 = func.compileReference(o), func = _ref4[0], ref = _ref4[1];
+ if (func !== ref) {
+ props.push(func);
+ }
+ apply = new Call(new Value(ref, [new Accessor(new Literal('apply'))]), [new Literal('this'), new Literal('arguments')]);
+ func = new Code([], new Expressions([apply]));
+ }
+ if (func.bound) {
+ throw new Error("cannot define a constructor as a bound function.");
+ }
+ func.name = className;
+ func.body.push(new Return(new Literal('this')));
+ variable = new Value(variable);
+ variable.namespaced = 0 < className.indexOf('.');
+ constructor = func;
+ if (props.expressions[props.expressions.length - 1] instanceof Comment) {
+ constructor.comment = props.expressions.pop();
+ }
+ continue;
+ }
+ if (func instanceof Code && func.bound) {
+ if (prop.context === 'this') {
+ func.context = className;
+ } else {
+ func.bound = false;
+ constScope || (constScope = new Scope(o.scope, constructor.body, constructor));
+ me || (me = constScope.freeVariable('this'));
+ pname = pvar.compile(o);
+ if (constructor.body.empty()) {
+ constructor.body.push(new Return(new Literal('this')));
+ }
+ constructor.body.unshift(new Literal("this." + pname + " = function(){ return " + className + ".prototype." + pname + ".apply(" + me + ", arguments); }"));
+ }
+ }
+ if (pvar) {
+ access = prop.context === 'this' ? pvar.base.properties[0] : new Accessor(pvar, 'prototype');
+ val = new Value(variable, [access]);
+ prop = new Assign(val, func);
+ }
+ props.push(prop);
+ }
+ constructor.className = className.match(/[\w\d\$_]+$/);
+ if (me) {
+ constructor.body.unshift(new Literal("" + me + " = this"));
+ }
+ construct = this.idt() + new Assign(variable, constructor).compile(merge(o, {
+ sharedScope: constScope
+ })) + ';';
+ props = !props.empty() ? '\n' + props.compile(o) : '';
+ extension = extension ? '\n' + this.idt() + extension.compile(o) + ';' : '';
+ returns = this.returns ? '\n' + new Return(variable).compile(o) : '';
+ return construct + extension + props + returns;
+ };
+ return Class;
+ })();
+ exports.Assign = (function() {
+ Assign = (function() {
+ function Assign(_arg, _arg2, _arg3) {
+ this.context = _arg3;
+ this.value = _arg2;
+ this.variable = _arg;
+ Assign.__super__.constructor.call(this);
+ return this;
+ };
+ return Assign;
+ })();
+ __extends(Assign, Base);
+ Assign.prototype.METHOD_DEF = /^(?:(\S+)\.prototype\.)?([$A-Za-z_][$\w]*)$/;
+ Assign.prototype.children = ['variable', 'value'];
+ Assign.prototype.topSensitive = YES;
+ Assign.prototype.isValue = function() {
+ return this.variable instanceof Value;
+ };
+ Assign.prototype.compileNode = function(o) {
+ var ifn, isValue, match, name, stmt, top, val;
+ if (isValue = this.isValue()) {
+ if (this.variable.isArray() || this.variable.isObject()) {
+ return this.compilePatternMatch(o);
+ }
+ if (this.variable.isSplice()) {
+ return this.compileSplice(o);
+ }
+ if (ifn = If.unfoldSoak(o, this, 'variable')) {
+ delete o.top;
+ return ifn.compile(o);
+ }
+ }
+ top = del(o, 'top');
+ stmt = del(o, 'asStatement');
+ name = this.variable.compile(o);
+ if (this.value instanceof Code && (match = this.METHOD_DEF.exec(name))) {
+ this.value.name = match[2];
+ this.value.klass = match[1];
+ }
+ val = this.value.compile(o);
+ if (this.context === 'object') {
+ return ("" + name + ": " + val);
+ }
+ if (!(isValue && (this.variable.hasProperties() || this.variable.namespaced))) {
+ o.scope.find(name);
+ }
+ val = ("" + name + " = " + val);
+ if (stmt) {
+ return ("" + (this.tab) + val + ";");
+ }
+ return top || this.parenthetical ? val : ("(" + val + ")");
+ };
+ Assign.prototype.compilePatternMatch = function(o) {
+ var _len, _ref2, _ref3, accessClass, assigns, code, i, idx, isObject, obj, objects, olength, otop, ref, splat, top, val, valVar, value;
+ if ((value = this.value).isStatement(o)) {
+ value = Closure.wrap(value);
+ }
+ objects = this.variable.base.objects;
+ if (!(olength = objects.length)) {
+ return value.compile(o);
+ }
+ isObject = this.variable.isObject();
+ if (o.top && olength === 1 && !((obj = objects[0]) instanceof Splat)) {
+ if (obj instanceof Assign) {
+ _ref2 = obj, idx = _ref2.variable.base, obj = _ref2.value;
+ } else {
+ idx = isObject ? (obj.tags["this"] ? obj.properties[0].name : obj) : new Literal(0);
+ }
+ if (!(value instanceof Value)) {
+ value = new Value(value);
+ }
+ accessClass = IDENTIFIER.test(idx.value) ? Accessor : Index;
+ value.properties.push(new accessClass(idx));
+ return new Assign(obj, value).compile(o);
+ }
+ top = del(o, 'top');
+ otop = merge(o, {
+ top: true
+ });
+ valVar = value.compile(o);
+ assigns = [];
+ splat = false;
+ if (!IDENTIFIER.test(valVar) || this.variable.assigns(valVar)) {
+ assigns.push("" + (ref = o.scope.freeVariable('ref')) + " = " + valVar);
+ valVar = ref;
+ }
+ for (i = 0, _len = objects.length; i < _len; i++) {
+ obj = objects[i];
+ idx = i;
+ if (isObject) {
+ if (obj instanceof Assign) {
+ _ref3 = obj, idx = _ref3.variable.base, obj = _ref3.value;
+ } else {
+ idx = obj.tags["this"] ? obj.properties[0].name : obj;
+ }
+ }
+ if (!(obj instanceof Value || obj instanceof Splat)) {
+ throw new Error('pattern matching must use only identifiers on the left-hand side.');
+ }
+ accessClass = isObject && IDENTIFIER.test(idx.value) ? Accessor : Index;
+ if (!splat && obj instanceof Splat) {
+ val = new Literal(obj.compileValue(o, valVar, i, olength - i - 1));
+ splat = true;
+ } else {
+ if (typeof idx !== 'object') {
+ idx = new Literal(splat ? ("" + valVar + ".length - " + (olength - idx)) : idx);
+ }
+ val = new Value(new Literal(valVar), [new accessClass(idx)]);
+ }
+ assigns.push(new Assign(obj, val).compile(otop));
+ }
+ if (!top) {
+ assigns.push(valVar);
+ }
+ code = assigns.join(', ');
+ return top || this.parenthetical ? code : ("(" + code + ")");
+ };
+ Assign.prototype.compileSplice = function(o) {
+ var from, name, plus, range, ref, to, val;
+ range = this.variable.properties.pop().range;
+ name = this.variable.compile(o);
+ plus = range.exclusive ? '' : ' + 1';
+ from = range.from ? range.from.compile(o) : '0';
+ to = range.to ? range.to.compile(o) + ' - ' + from + plus : ("" + name + ".length");
+ ref = o.scope.freeVariable('ref');
+ val = this.value.compile(o);
+ return "([].splice.apply(" + name + ", [" + from + ", " + to + "].concat(" + ref + " = " + val + ")), " + ref + ")";
+ };
+ Assign.prototype.assigns = function(name) {
+ return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
+ };
+ return Assign;
+ })();
+ exports.Code = (function() {
+ Code = (function() {
+ function Code(_arg, _arg2, tag) {
+ this.body = _arg2;
+ this.params = _arg;
+ Code.__super__.constructor.call(this);
+ this.params || (this.params = []);
+ this.body || (this.body = new Expressions);
+ this.bound = tag === 'boundfunc';
+ if (this.bound) {
+ this.context = 'this';
+ }
+ return this;
+ };
+ return Code;
+ })();
+ __extends(Code, Base);
+ Code.prototype.children = ['params', 'body'];
+ Code.prototype.compileNode = function(o) {
+ var _i, _len, _len2, _ref2, _ref3, _result, close, code, comm, empty, func, i, open, param, params, sharedScope, splat, top, value;
+ sharedScope = del(o, 'sharedScope');
+ top = del(o, 'top');
+ o.scope = sharedScope || new Scope(o.scope, this.body, this);
+ o.top = true;
+ o.indent = this.idt(1);
+ empty = this.body.expressions.length === 0;
+ delete o.bare;
+ delete o.globals;
+ splat = undefined;
+ params = [];
+ for (i = 0, _len = (_ref2 = this.params).length; i < _len; i++) {
+ param = _ref2[i];
+ if (splat) {
+ if (param.attach) {
+ param.assign = new Assign(new Value(new Literal('this'), [new Accessor(param.value)]));
+ this.body.expressions.splice(splat.index + 1, 0, param.assign);
+ }
+ splat.trailings.push(param);
+ } else {
+ if (param.attach) {
+ value = param.value;
+ _ref3 = [new Literal(o.scope.freeVariable('arg')), param.splat], param = _ref3[0], param.splat = _ref3[1];
+ this.body.unshift(new Assign(new Value(new Literal('this'), [new Accessor(value)]), param));
+ }
+ if (param.splat) {
+ splat = new Splat(param.value);
+ splat.index = i;
+ splat.trailings = [];
+ splat.arglength = this.params.length;
+ this.body.unshift(splat);
+ } else {
+ params.push(param);
+ }
+ }
+ }
+ o.scope.startLevel();
+ params = (function() {
+ _result = [];
+ for (_i = 0, _len2 = params.length; _i < _len2; _i++) {
+ param = params[_i];
+ _result.push(param.compile(o));
+ }
+ return _result;
+ })();
+ if (!(empty || this.noReturn)) {
+ this.body.makeReturn();
+ }
+ for (_i = 0, _len2 = params.length; _i < _len2; _i++) {
+ param = params[_i];
+ (o.scope.parameter(param));
+ }
+ comm = this.comment ? this.comment.compile(o) + '\n' : '';
+ if (this.className) {
+ o.indent = this.idt(2);
+ }
+ code = this.body.expressions.length ? ("\n" + (this.body.compileWithDeclarations(o)) + "\n") : '';
+ open = this.className ? ("(function() {\n" + comm + (this.idt(1)) + "function " + (this.className) + "(") : "function(";
+ close = this.className ? ("" + (code && this.idt(1)) + "};\n" + (this.idt(1)) + "return " + (this.className) + ";\n" + (this.tab) + "})()") : ("" + (code && this.tab) + "}");
+ func = ("" + open + (params.join(', ')) + ") {" + code + close);
+ o.scope.endLevel();
+ if (this.bound) {
+ return ("" + (utility('bind')) + "(" + func + ", " + (this.context) + ")");
+ }
+ return this.tags.front ? ("(" + func + ")") : func;
+ };
+ Code.prototype.traverseChildren = function(crossScope, func) {
+ return crossScope ? Code.__super__.traverseChildren.call(this, crossScope, func) : undefined;
+ };
+ return Code;
+ })();
+ exports.Param = (function() {
+ Param = (function() {
+ function Param(_arg, _arg2, _arg3) {
+ this.splat = _arg3;
+ this.attach = _arg2;
+ this.name = _arg;
+ Param.__super__.constructor.call(this);
+ this.value = new Literal(this.name);
+ return this;
+ };
+ return Param;
+ })();
+ __extends(Param, Base);
+ Param.prototype.children = ['name'];
+ Param.prototype.compileNode = function(o) {
+ return this.value.compile(o);
+ };
+ Param.prototype.toString = function() {
+ var name;
+ name = this.name;
+ if (this.attach) {
+ name = '@' + name;
+ }
+ if (this.splat) {
+ name += '...';
+ }
+ return new Literal(name).toString();
+ };
+ return Param;
+ })();
+ exports.Splat = (function() {
+ Splat = (function() {
+ function Splat(name) {
+ Splat.__super__.constructor.call(this);
+ this.name = name.compile ? name : new Literal(name);
+ return this;
+ };
+ return Splat;
+ })();
+ __extends(Splat, Base);
+ Splat.prototype.children = ['name'];
+ Splat.prototype.assigns = function(name) {
+ return this.name.assigns(name);
+ };
+ Splat.prototype.compileNode = function(o) {
+ return (this.index != null) ? this.compileParam(o) : this.name.compile(o);
+ };
+ Splat.prototype.compileParam = function(o) {
+ var _len, _ref2, assign, end, idx, len, name, pos, trailing, variadic;
+ name = this.name.compile(o);
+ o.scope.find(name);
+ end = '';
+ if (this.trailings.length) {
+ len = o.scope.freeVariable('len');
+ o.scope.assign(len, "arguments.length");
+ variadic = o.scope.freeVariable('result');
+ o.scope.assign(variadic, len + ' >= ' + this.arglength);
+ end = this.trailings.length ? (", " + len + " - " + (this.trailings.length)) : undefined;
+ for (idx = 0, _len = (_ref2 = this.trailings).length; idx < _len; idx++) {
+ trailing = _ref2[idx];
+ if (trailing.attach) {
+ assign = trailing.assign;
+ trailing = new Literal(o.scope.freeVariable('arg'));
+ assign.value = trailing;
+ }
+ pos = this.trailings.length - idx;
+ o.scope.assign(trailing.compile(o), "arguments[" + variadic + " ? " + len + " - " + pos + " : " + (this.index + idx) + "]");
+ }
+ }
+ return "" + name + " = " + (utility('slice')) + ".call(arguments, " + (this.index) + end + ")";
+ };
+ Splat.prototype.compileValue = function(o, name, index, trailings) {
+ var trail;
+ trail = trailings ? (", " + name + ".length - " + trailings) : '';
+ return "" + (utility('slice')) + ".call(" + name + ", " + index + trail + ")";
+ };
+ Splat.compileSplattedArray = function(list, o) {
+ var _len, arg, args, code, end, i, prev;
+ args = [];
+ end = -1;
+ for (i = 0, _len = list.length; i < _len; i++) {
+ arg = list[i];
+ code = arg.compile(o);
+ prev = args[end];
+ if (!(arg instanceof Splat)) {
+ if (prev && starts(prev, '[') && ends(prev, ']')) {
+ args[end] = ("" + (prev.slice(0, -1)) + ", " + code + "]");
+ continue;
+ }
+ if (prev && starts(prev, '.concat([') && ends(prev, '])')) {
+ args[end] = ("" + (prev.slice(0, -2)) + ", " + code + "])");
+ continue;
+ }
+ code = ("[" + code + "]");
+ }
+ args[++end] = i === 0 ? code : (".concat(" + code + ")");
+ }
+ return args.join('');
+ };
+ return Splat;
+ }).call(this);
+ exports.While = (function() {
+ While = (function() {
+ function While(condition, opts) {
+ While.__super__.constructor.call(this);
+ this.condition = ((opts != null) ? opts.invert : undefined) ? condition.invert() : condition;
+ this.guard = ((opts != null) ? opts.guard : undefined);
+ return this;
+ };
+ return While;
+ })();
+ __extends(While, Base);
+ While.prototype.children = ['condition', 'guard', 'body'];
+ While.prototype.isStatement = YES;
+ While.prototype.addBody = function(body) {
+ this.body = body;
+ return this;
+ };
+ While.prototype.makeReturn = function() {
+ this.returns = true;
+ return this;
+ };
+ While.prototype.topSensitive = YES;
+ While.prototype.compileNode = function(o) {
+ var cond, post, pre, rvar, set, top;
+ top = del(o, 'top') && !this.returns;
+ o.indent = this.idt(1);
+ this.condition.parenthetical = true;
+ cond = this.condition.compile(o);
+ o.top = true;
+ set = '';
+ if (!top) {
+ rvar = o.scope.freeVariable('result');
+ set = ("" + (this.tab) + rvar + " = [];\n");
+ if (this.body) {
+ this.body = Push.wrap(rvar, this.body);
+ }
+ }
+ pre = ("" + set + (this.tab) + "while (" + cond + ")");
+ if (this.guard) {
+ this.body = Expressions.wrap([new If(this.guard, this.body)]);
+ }
+ if (this.returns) {
+ post = '\n' + new Return(new Literal(rvar)).compile(merge(o, {
+ indent: this.idt()
+ }));
+ } else {
+ post = '';
+ }
+ return "" + pre + " {\n" + (this.body.compile(o)) + "\n" + (this.tab) + "}" + post;
+ };
+ return While;
+ })();
+ exports.Op = (function() {
+ Op = (function() {
+ function Op(op, first, second, flip) {
+ if (op === 'new') {
+ if (first instanceof Call) {
+ return first.newInstance();
+ }
+ if (first instanceof Code && first.bound) {
+ first = new Parens(first);
+ }
+ }
+ Op.__super__.constructor.call(this);
+ this.operator = this.CONVERSIONS[op] || op;
+ (this.first = first).tags.operation = true;
+ if (second) {
+ (this.second = second).tags.operation = true;
+ }
+ this.flip = !!flip;
+ return this;
+ };
+ return Op;
+ })();
+ __extends(Op, Base);
+ Op.prototype.CONVERSIONS = {
+ '==': '===',
+ '!=': '!==',
+ of: 'in'
+ };
+ Op.prototype.INVERSIONS = {
+ '!==': '===',
+ '===': '!=='
+ };
+ Op.prototype.CHAINABLE = ['<', '>', '>=', '<=', '===', '!=='];
+ Op.prototype.ASSIGNMENT = ['||=', '&&=', '?='];
+ Op.prototype.PREFIX_OPERATORS = ['new', 'typeof', 'delete'];
+ Op.prototype.children = ['first', 'second'];
+ Op.prototype.isUnary = function() {
+ return !this.second;
+ };
+ Op.prototype.isComplex = function() {
+ return this.operator !== '!' || this.first.isComplex();
+ };
+ Op.prototype.isMutator = function() {
+ var _ref2;
+ return ends(this.operator, '=') && !((_ref2 = this.operator) === '===' || _ref2 === '!==');
+ };
+ Op.prototype.isChainable = function() {
+ return include(this.CHAINABLE, this.operator);
+ };
+ Op.prototype.invert = function() {
+ var _ref2;
+ if (((_ref2 = this.operator) === '===' || _ref2 === '!==')) {
+ this.operator = this.INVERSIONS[this.operator];
+ return this;
+ } else return this.second ? new Parens(this).invert() : Op.__super__.invert.call(this);
+ };
+ Op.prototype.toString = function(idt) {
+ return Op.__super__.toString.call(this, idt, this.constructor.name + ' ' + this.operator);
+ };
+ Op.prototype.compileNode = function(o) {
+ if (this.second) {
+ this.first.tags.front = this.tags.front;
+ }
+ if (this.isChainable() && this.first.unwrap() instanceof Op && this.first.unwrap().isChainable()) {
+ return this.compileChain(o);
+ }
+ if (include(this.ASSIGNMENT, this.operator)) {
+ return this.compileAssignment(o);
+ }
+ if (this.isUnary()) {
+ return this.compileUnary(o);
+ }
+ if (this.operator === '?') {
+ return this.compileExistence(o);
+ }
+ if (this.first instanceof Op && this.first.isMutator()) {
+ this.first = new Parens(this.first);
+ }
+ if (this.second instanceof Op && this.second.isMutator()) {
+ this.second = new Parens(this.second);
+ }
+ return [this.first.compile(o), this.operator, this.second.compile(o)].join(' ');
+ };
+ Op.prototype.compileChain = function(o) {
+ var _ref2, _ref3, first, second, shared;
+ shared = this.first.unwrap().second;
+ _ref2 = shared.compileReference(o), this.first.second = _ref2[0], shared = _ref2[1];
+ _ref3 = [this.first.compile(o), this.second.compile(o), shared.compile(o)], first = _ref3[0], second = _ref3[1], shared = _ref3[2];
+ return "(" + first + ") && (" + shared + " " + (this.operator) + " " + second + ")";
+ };
+ Op.prototype.compileAssignment = function(o) {
+ var _ref2, left, rite;
+ _ref2 = this.first.cacheReference(o), left = _ref2[0], rite = _ref2[1];
+ rite = new Assign(rite, this.second);
+ return new Op(this.operator.slice(0, -1), left, rite).compile(o);
+ };
+ Op.prototype.compileExistence = function(o) {
+ var fst, ref;
+ if (this.first.isComplex()) {
+ ref = o.scope.freeVariable('ref');
+ fst = new Parens(new Assign(new Literal(ref), this.first));
+ } else {
+ fst = this.first;
+ ref = fst.compile(o);
+ }
+ return new Existence(fst).compile(o) + (" ? " + ref + " : " + (this.second.compile(o)));
+ };
+ Op.prototype.compileUnary = function(o) {
+ var parts, space;
+ space = include(this.PREFIX_OPERATORS, this.operator) ? ' ' : '';
+ parts = [this.operator, space, this.first.compile(o)];
+ return (this.flip ? parts.reverse() : parts).join('');
+ };
+ return Op;
+ })();
+ exports.In = (function() {
+ In = (function() {
+ function In(_arg, _arg2) {
+ this.array = _arg2;
+ this.object = _arg;
+ In.__super__.constructor.call(this);
+ return this;
+ };
+ return In;
+ })();
+ __extends(In, Base);
+ In.prototype.children = ['object', 'array'];
+ In.prototype.isArray = function() {
+ return this.array instanceof Value && this.array.isArray();
+ };
+ In.prototype.compileNode = function(o) {
+ return this.isArray() ? this.compileOrTest(o) : this.compileLoopTest(o);
+ };
+ In.prototype.compileOrTest = function(o) {
+ var _len, _ref2, _ref3, _result, i, item, obj1, obj2, tests;
+ _ref2 = this.object.compileReference(o, {
+ precompile: true
+ }), obj1 = _ref2[0], obj2 = _ref2[1];
+ tests = (function() {
+ _result = [];
+ for (i = 0, _len = (_ref3 = this.array.base.objects).length; i < _len; i++) {
+ item = _ref3[i];
+ _result.push("" + (i ? obj2 : obj1) + " === " + (item.compile(o)));
+ }
+ return _result;
+ }).call(this);
+ return "(" + (tests.join(' || ')) + ")";
+ };
+ In.prototype.compileLoopTest = function(o) {
+ return "" + (utility('inArray')) + "(" + (this.object.compile(o)) + ", " + (this.array.compile(o)) + ")";
+ };
+ return In;
+ })();
+ exports.Try = (function() {
+ Try = (function() {
+ function Try(_arg, _arg2, _arg3, _arg4) {
+ this.ensure = _arg4;
+ this.recovery = _arg3;
+ this.error = _arg2;
+ this.attempt = _arg;
+ Try.__super__.constructor.call(this);
+ return this;
+ };
+ return Try;
+ })();
+ __extends(Try, Base);
+ Try.prototype.children = ['attempt', 'recovery', 'ensure'];
+ Try.prototype.isStatement = YES;
+ Try.prototype.makeReturn = function() {
+ if (this.attempt) {
+ this.attempt = this.attempt.makeReturn();
+ }
+ if (this.recovery) {
+ this.recovery = this.recovery.makeReturn();
+ }
+ return this;
+ };
+ Try.prototype.compileNode = function(o) {
+ var attemptPart, catchPart, errorPart, finallyPart;
+ o.indent = this.idt(1);
+ o.top = true;
+ attemptPart = this.attempt.compile(o);
+ errorPart = this.error ? (" (" + (this.error.compile(o)) + ") ") : ' ';
+ catchPart = this.recovery ? (" catch" + errorPart + "{\n" + (this.recovery.compile(o)) + "\n" + (this.tab) + "}") : (!(this.ensure || this.recovery) ? ' catch (_e) {}' : '');
+ finallyPart = (this.ensure || '') && ' finally {\n' + this.ensure.compile(merge(o)) + ("\n" + (this.tab) + "}");
+ return "" + (this.tab) + "try {\n" + attemptPart + "\n" + (this.tab) + "}" + catchPart + finallyPart;
+ };
+ return Try;
+ })();
+ exports.Throw = (function() {
+ Throw = (function() {
+ function Throw(_arg) {
+ this.expression = _arg;
+ Throw.__super__.constructor.call(this);
+ return this;
+ };
+ return Throw;
+ })();
+ __extends(Throw, Base);
+ Throw.prototype.children = ['expression'];
+ Throw.prototype.isStatement = YES;
+ Throw.prototype.makeReturn = THIS;
+ Throw.prototype.compileNode = function(o) {
+ return "" + (this.tab) + "throw " + (this.expression.compile(o)) + ";";
+ };
+ return Throw;
+ })();
+ exports.Existence = (function() {
+ Existence = (function() {
+ function Existence(_arg) {
+ this.expression = _arg;
+ Existence.__super__.constructor.call(this);
+ return this;
+ };
+ return Existence;
+ })();
+ __extends(Existence, Base);
+ Existence.prototype.children = ['expression'];
+ Existence.prototype.compileNode = function(o) {
+ var code;
+ code = this.expression.compile(o);
+ code = IDENTIFIER.test(code) && !o.scope.check(code) ? ("typeof " + code + " !== \"undefined\" && " + code + " !== null") : ("" + code + " != null");
+ return this.parenthetical ? code : ("(" + code + ")");
+ };
+ return Existence;
+ })();
+ exports.Parens = (function() {
+ Parens = (function() {
+ function Parens(_arg) {
+ this.expression = _arg;
+ Parens.__super__.constructor.call(this);
+ return this;
+ };
+ return Parens;
+ })();
+ __extends(Parens, Base);
+ Parens.prototype.children = ['expression'];
+ Parens.prototype.isStatement = function(o) {
+ return this.expression.isStatement(o);
+ };
+ Parens.prototype.isComplex = function() {
+ return this.expression.isComplex();
+ };
+ Parens.prototype.topSensitive = YES;
+ Parens.prototype.makeReturn = function() {
+ return this.expression.makeReturn();
+ };
+ Parens.prototype.compileNode = function(o) {
+ var code, top;
+ top = del(o, 'top');
+ this.expression.parenthetical = true;
+ code = this.expression.compile(o);
+ if (top && this.expression.isPureStatement(o)) {
+ return code;
+ }
+ if (this.parenthetical || this.isStatement(o)) {
+ return top ? this.tab + code + ';' : code;
+ }
+ return "(" + code + ")";
+ };
+ return Parens;
+ })();
+ exports.For = (function() {
+ For = (function() {
+ function For(_arg, source, _arg2, _arg3) {
+ var _ref2;
+ this.index = _arg3;
+ this.name = _arg2;
+ this.body = _arg;
+ For.__super__.constructor.call(this);
+ this.source = source.source, this.guard = source.guard, this.step = source.step;
+ this.raw = !!source.raw;
+ this.object = !!source.object;
+ if (this.object) {
+ _ref2 = [this.index, this.name], this.name = _ref2[0], this.index = _ref2[1];
+ }
+ this.pattern = this.name instanceof Value;
+ if (this.index instanceof Value) {
+ throw new Error('index cannot be a pattern matching expression');
+ }
+ this.returns = false;
+ return this;
+ };
+ return For;
+ })();
+ __extends(For, Base);
+ For.prototype.children = ['body', 'source', 'guard'];
+ For.prototype.isStatement = YES;
+ For.prototype.topSensitive = YES;
+ For.prototype.makeReturn = function() {
+ this.returns = true;
+ return this;
+ };
+ For.prototype.compileReturnValue = function(val, o) {
+ if (this.returns) {
+ return '\n' + new Return(new Literal(val)).compile(o);
+ }
+ if (val) {
+ return '\n' + val;
+ }
+ return '';
+ };
+ For.prototype.compileNode = function(o) {
+ var body, codeInBody, forPart, guardPart, idt1, index, ivar, lastLine, lvar, name, namePart, nvar, range, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, unstepPart, varPart, vars;
+ topLevel = del(o, 'top') && !this.returns;
+ range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
+ source = range ? this.source.base : this.source;
+ codeInBody = !this.body.containsPureStatement() && this.body.contains(function(node) {
+ return node instanceof Code;
+ });
+ scope = o.scope;
+ name = this.name && this.name.compile(o);
+ index = this.index && this.index.compile(o);
+ if (name && !this.pattern && (range || !codeInBody)) {
+ scope.find(name, {
+ immediate: true
+ });
+ }
+ if (index) {
+ scope.find(index, {
+ immediate: true
+ });
+ }
+ if (!topLevel) {
+ rvar = scope.freeVariable('result');
+ }
+ ivar = range ? name : index;
+ if (!ivar || codeInBody) {
+ ivar = scope.freeVariable('i');
+ }
+ if (name && !range && codeInBody) {
+ nvar = scope.freeVariable('i');
+ }
+ varPart = '';
+ guardPart = '';
+ unstepPart = '';
+ body = Expressions.wrap([this.body]);
+ idt1 = this.idt(1);
+ if (range) {
+ forPart = source.compile(merge(o, {
+ index: ivar,
+ step: this.step
+ }));
+ } else {
+ svar = (sourcePart = this.source.compile(o));
+ if ((name || !this.raw) && !(IDENTIFIER.test(svar) && scope.check(svar, {
+ immediate: true
+ }))) {
+ sourcePart = ("" + (ref = scope.freeVariable('ref')) + " = " + svar);
+ if (!this.object) {
+ sourcePart = ("(" + sourcePart + ")");
+ }
+ svar = ref;
+ }
+ namePart = this.pattern ? new Assign(this.name, new Literal("" + svar + "[" + ivar + "]")).compile(merge(o, {
+ top: true
+ })) : (name ? ("" + name + " = " + svar + "[" + ivar + "]") : undefined);
+ if (!this.object) {
+ lvar = scope.freeVariable('len');
+ stepPart = this.step ? ("" + ivar + " += " + (this.step.compile(o))) : ("" + ivar + "++");
+ forPart = ("" + ivar + " = 0, " + lvar + " = " + sourcePart + ".length; " + ivar + " < " + lvar + "; " + stepPart);
+ }
+ }
+ resultPart = rvar ? ("" + (this.tab) + rvar + " = [];\n") : '';
+ returnResult = this.compileReturnValue(rvar, o);
+ if (!topLevel) {
+ body = Push.wrap(rvar, body);
+ }
+ if (this.guard) {
+ body = Expressions.wrap([new If(this.guard, body)]);
+ }
+ if (codeInBody) {
+ if (range) {
+ body.unshift(new Literal("var " + name + " = " + ivar));
+ }
+ if (namePart) {
+ body.unshift(new Literal("var " + namePart));
+ }
+ if (index) {
+ body.unshift(new Literal("var " + index + " = " + ivar));
+ }
+ lastLine = body.expressions.pop();
+ if (index) {
+ body.push(new Assign(new Literal(ivar), new Literal(index)));
+ }
+ if (nvar) {
+ body.push(new Assign(new Literal(nvar), new Literal(name)));
+ }
+ body.push(lastLine);
+ o.indent = this.idt(1);
+ body = Expressions.wrap([new Literal(body.compile(o))]);
+ if (index) {
+ body.push(new Assign(new Literal(index), new Literal(ivar)));
+ }
+ if (name) {
+ body.push(new Assign(new Literal(name), new Literal(nvar || ivar)));
+ }
+ } else {
+ if (namePart) {
+ varPart = ("" + idt1 + namePart + ";\n");
+ }
+ if (forPart && name === ivar) {
+ unstepPart = this.step ? ("" + name + " -= " + (this.step.compile(o)) + ";") : ("" + name + "--;");
+ unstepPart = ("\n" + (this.tab)) + unstepPart;
+ }
+ }
+ if (this.object) {
+ forPart = ("" + ivar + " in " + sourcePart);
+ if (!this.raw) {
+ guardPart = ("\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;");
+ }
+ }
+ body = body.compile(merge(o, {
+ indent: idt1,
+ top: true
+ }));
+ vars = range ? name : ("" + name + ", " + ivar);
+ return "" + resultPart + (this.tab) + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + (this.tab) + "}" + unstepPart + returnResult;
+ };
+ return For;
+ })();
+ exports.Switch = (function() {
+ Switch = (function() {
+ function Switch(_arg, _arg2, _arg3) {
+ this.otherwise = _arg3;
+ this.cases = _arg2;
+ this.subject = _arg;
+ Switch.__super__.constructor.call(this);
+ this.tags.subjectless = !this.subject;
+ this.subject || (this.subject = new Literal('true'));
+ return this;
+ };
+ return Switch;
+ })();
+ __extends(Switch, Base);
+ Switch.prototype.children = ['subject', 'cases', 'otherwise'];
+ Switch.prototype.isStatement = YES;
+ Switch.prototype.makeReturn = function() {
+ var _i, _len, _ref2, pair;
+ for (_i = 0, _len = (_ref2 = this.cases).length; _i < _len; _i++) {
+ pair = _ref2[_i];
+ pair[1].makeReturn();
+ }
+ if (this.otherwise) {
+ this.otherwise.makeReturn();
+ }
+ return this;
+ };
+ Switch.prototype.compileNode = function(o) {
+ var _i, _j, _len, _len2, _ref2, _ref3, block, code, condition, conditions, exprs, idt, pair;
+ idt = (o.indent = this.idt(2));
+ o.top = true;
+ code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
+ for (_i = 0, _len = (_ref2 = this.cases).length; _i < _len; _i++) {
+ pair = _ref2[_i];
+ conditions = pair[0], block = pair[1];
+ exprs = block.expressions;
+ for (_j = 0, _len2 = (_ref3 = flatten([conditions])).length; _j < _len2; _j++) {
+ condition = _ref3[_j];
+ if (this.tags.subjectless) {
+ condition = new Op('!!', new Parens(condition));
+ }
+ code += ("\n" + (this.idt(1)) + "case " + (condition.compile(o)) + ":");
+ }
+ code += ("\n" + (block.compile(o)));
+ if (!(last(exprs) instanceof Return)) {
+ code += ("\n" + idt + "break;");
+ }
+ }
+ if (this.otherwise) {
+ code += ("\n" + (this.idt(1)) + "default:\n" + (this.otherwise.compile(o)));
+ }
+ code += ("\n" + (this.tab) + "}");
+ return code;
+ };
+ return Switch;
+ })();
+ exports.If = (function() {
+ If = (function() {
+ function If(condition, _arg, tags) {
+ this.body = _arg;
+ this.tags = tags || (tags = {});
+ this.condition = tags.invert ? condition.invert() : condition;
+ this.soakNode = tags.soak;
+ this.elseBody = null;
+ this.isChain = false;
+ return this;
+ };
+ return If;
+ })();
+ __extends(If, Base);
+ If.prototype.children = ['condition', 'body', 'elseBody', 'assigner'];
+ If.prototype.topSensitive = YES;
+ If.prototype.bodyNode = function() {
+ var _ref2;
+ return (((_ref2 = this.body) != null) ? _ref2.unwrap() : undefined);
+ };
+ If.prototype.elseBodyNode = function() {
+ var _ref2;
+ return (((_ref2 = this.elseBody) != null) ? _ref2.unwrap() : undefined);
+ };
+ If.prototype.addElse = function(elseBody) {
+ if (this.isChain) {
+ this.elseBodyNode().addElse(elseBody);
+ } else {
+ this.isChain = elseBody instanceof If;
+ this.elseBody = this.ensureExpressions(elseBody);
+ }
+ return this;
+ };
+ If.prototype.isStatement = function(o) {
+ var _ref2;
+ return this.statement || (this.statement = ((o != null) ? o.top : undefined) || this.bodyNode().isStatement(o) || (((_ref2 = this.elseBodyNode()) != null) ? _ref2.isStatement(o) : undefined));
+ };
+ If.prototype.compileCondition = function(o) {
+ this.condition.parenthetical = true;
+ return this.condition.compile(o);
+ };
+ If.prototype.compileNode = function(o) {
+ return this.isStatement(o) ? this.compileStatement(o) : this.compileExpression(o);
+ };
+ If.prototype.makeReturn = function() {
+ if (this.isStatement()) {
+ this.body && (this.body = this.ensureExpressions(this.body.makeReturn()));
+ this.elseBody && (this.elseBody = this.ensureExpressions(this.elseBody.makeReturn()));
+ return this;
+ } else {
+ return new Return(this);
+ }
+ };
+ If.prototype.ensureExpressions = function(node) {
+ return node instanceof Expressions ? node : new Expressions([node]);
+ };
+ If.prototype.compileStatement = function(o) {
+ var child, condO, ifPart, top;
+ top = del(o, 'top');
+ child = del(o, 'chainChild');
+ condO = merge(o);
+ o.indent = this.idt(1);
+ o.top = true;
+ ifPart = ("if (" + (this.compileCondition(condO)) + ") {\n" + (this.body.compile(o)) + "\n" + (this.tab) + "}");
+ if (!child) {
+ ifPart = this.tab + ifPart;
+ }
+ if (!this.elseBody) {
+ return ifPart;
+ }
+ return ifPart + (this.isChain ? ' else ' + this.elseBodyNode().compile(merge(o, {
+ indent: this.tab,
+ chainChild: true
+ })) : (" else {\n" + (this.elseBody.compile(o)) + "\n" + (this.tab) + "}"));
+ };
+ If.prototype.compileExpression = function(o) {
+ var code, elsePart, ifPart;
+ this.bodyNode().tags.operation = (this.condition.tags.operation = true);
+ if (this.elseBody) {
+ this.elseBodyNode().tags.operation = true;
+ }
+ ifPart = this.condition.compile(o) + ' ? ' + this.bodyNode().compile(o);
+ elsePart = this.elseBody ? this.elseBodyNode().compile(o) : 'undefined';
+ code = ("" + ifPart + " : " + elsePart);
+ return this.tags.operation || this.soakNode ? ("(" + code + ")") : code;
+ };
+ If.prototype.unfoldSoak = function() {
+ return this.soakNode && this;
+ };
+ If.unfoldSoak = function(o, parent, name) {
+ var ifn;
+ if (!(ifn = parent[name].unfoldSoak(o))) {
+ return;
+ }
+ parent[name] = ifn.body;
+ ifn.body = new Value(parent);
+ return ifn;
+ };
+ return If;
+ }).call(this);
+ Push = {
+ wrap: function(name, expressions) {
+ if (expressions.empty() || expressions.containsPureStatement()) {
+ return expressions;
+ }
+ return Expressions.wrap([new Call(new Value(new Literal(name), [new Accessor(new Literal('push'))]), [expressions.unwrap()])]);
+ }
+ };
+ Closure = {
+ wrap: function(expressions, statement, noReturn) {
+ var args, call, func, mentionsArgs, meth;
+ if (expressions.containsPureStatement()) {
+ return expressions;
+ }
+ func = new Parens(new Code([], Expressions.wrap([expressions])));
+ args = [];
+ if ((mentionsArgs = expressions.contains(this.literalArgs)) || (expressions.contains(this.literalThis))) {
+ meth = new Literal(mentionsArgs ? 'apply' : 'call');
+ args = [new Literal('this')];
+ if (mentionsArgs) {
+ args.push(new Literal('arguments'));
+ }
+ func = new Value(func, [new Accessor(meth)]);
+ func.noReturn = noReturn;
+ }
+ call = new Call(func, args);
+ return statement ? Expressions.wrap([call]) : call;
+ },
+ literalArgs: function(node) {
+ return node instanceof Literal && node.value === 'arguments';
+ },
+ literalThis: function(node) {
+ return node instanceof Literal && node.value === 'this' || node instanceof Code && node.bound;
+ }
+ };
+ UTILITIES = {
+ "extends": 'function(child, parent) {\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n if (typeof parent.extended === "function") parent.extended(child);\n child.__super__ = parent.prototype;\n}',
+ bind: 'function(func, context) {\n return function() { return func.apply(context, arguments); };\n}',
+ inArray: '(function() {\n var indexOf = Array.prototype.indexOf || function(item) {\n var i = this.length; while (i--) if (this[i] === item) return i;\n return -1;\n };\n return function(item, array) { return indexOf.call(array, item) > -1; };\n})();',
+ hasProp: 'Object.prototype.hasOwnProperty',
+ slice: 'Array.prototype.slice'
+ };
+ TAB = ' ';
+ TRAILING_WHITESPACE = /[ \t]+$/gm;
+ IDENTIFIER = /^[$A-Za-z_][$\w]*$/;
+ NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?$/i;
+ SIMPLENUM = /^[+-]?\d+$/;
+ IS_STRING = /^['"]/;
+ utility = function(name) {
+ var ref;
+ ref = ("__" + name);
+ Scope.root.assign(ref, UTILITIES[name]);
+ return ref;
+ };
+}).call(this);
--- /dev/null
+(function() {
+ var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments;
+ exports.OptionParser = (function() {
+ OptionParser = (function() {
+ function OptionParser(rules, banner) {
+ this.banner = banner;
+ this.rules = buildRules(rules);
+ return this;
+ };
+ return OptionParser;
+ })();
+ OptionParser.prototype.parse = function(args) {
+ var _i, _len, _len2, _ref, arg, i, isOption, matchedRule, options, rule, value;
+ options = {
+ arguments: []
+ };
+ args = normalizeArguments(args);
+ for (i = 0, _len = args.length; i < _len; i++) {
+ arg = args[i];
+ isOption = !!(arg.match(LONG_FLAG) || arg.match(SHORT_FLAG));
+ matchedRule = false;
+ for (_i = 0, _len2 = (_ref = this.rules).length; _i < _len2; _i++) {
+ rule = _ref[_i];
+ if (rule.shortFlag === arg || rule.longFlag === arg) {
+ value = rule.hasArgument ? args[i += 1] : true;
+ options[rule.name] = rule.isList ? (options[rule.name] || []).concat(value) : value;
+ matchedRule = true;
+ break;
+ }
+ }
+ if (isOption && !matchedRule) {
+ throw new Error("unrecognized option: " + arg);
+ }
+ if (!isOption) {
+ options.arguments = args.slice(i);
+ break;
+ }
+ }
+ return options;
+ };
+ OptionParser.prototype.help = function() {
+ var _i, _len, _ref, letPart, lines, rule, spaces;
+ lines = ['Available options:'];
+ if (this.banner) {
+ lines.unshift("" + (this.banner) + "\n");
+ }
+ for (_i = 0, _len = (_ref = this.rules).length; _i < _len; _i++) {
+ rule = _ref[_i];
+ spaces = 15 - rule.longFlag.length;
+ spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
+ letPart = rule.shortFlag ? rule.shortFlag + ', ' : ' ';
+ lines.push(' ' + letPart + rule.longFlag + spaces + rule.description);
+ }
+ return "\n" + (lines.join('\n')) + "\n";
+ };
+ return OptionParser;
+ })();
+ LONG_FLAG = /^(--\w[\w\-]+)/;
+ SHORT_FLAG = /^(-\w)/;
+ MULTI_FLAG = /^-(\w{2,})/;
+ OPTIONAL = /\[(\w+(\*?))\]/;
+ buildRules = function(rules) {
+ var _i, _len, _result, tuple;
+ _result = [];
+ for (_i = 0, _len = rules.length; _i < _len; _i++) {
+ tuple = rules[_i];
+ _result.push((function() {
+ if (tuple.length < 3) {
+ tuple.unshift(null);
+ }
+ return buildRule.apply(buildRule, tuple);
+ })());
+ }
+ return _result;
+ };
+ buildRule = function(shortFlag, longFlag, description, options) {
+ var match;
+ match = longFlag.match(OPTIONAL);
+ longFlag = longFlag.match(LONG_FLAG)[1];
+ options || (options = {});
+ return {
+ name: longFlag.substr(2),
+ shortFlag: shortFlag,
+ longFlag: longFlag,
+ description: description,
+ hasArgument: !!(match && match[1]),
+ isList: !!(match && match[2])
+ };
+ };
+ normalizeArguments = function(args) {
+ var _i, _j, _len, _len2, _ref, arg, l, match, result;
+ args = args.slice(0);
+ result = [];
+ for (_i = 0, _len = args.length; _i < _len; _i++) {
+ arg = args[_i];
+ if (match = arg.match(MULTI_FLAG)) {
+ for (_j = 0, _len2 = (_ref = match[1].split('')).length; _j < _len2; _j++) {
+ l = _ref[_j];
+ result.push('-' + l);
+ }
+ } else {
+ result.push(arg);
+ }
+ }
+ return result;
+ };
+}).call(this);
--- /dev/null
+/* Jison generated parser */
+var parser = (function(){
+var parser = {trace: function trace() { },
+yy: {},
+symbols_: {"error":2,"Root":3,"TERMINATOR":4,"Body":5,"Block":6,"Line":7,"Expression":8,"Statement":9,"Return":10,"Throw":11,"BREAK":12,"CONTINUE":13,"DEBUGGER":14,"Value":15,"Invocation":16,"Code":17,"Operation":18,"Assign":19,"If":20,"Try":21,"While":22,"For":23,"Switch":24,"Extends":25,"Class":26,"Existence":27,"Comment":28,"INDENT":29,"OUTDENT":30,"Identifier":31,"IDENTIFIER":32,"AlphaNumeric":33,"NUMBER":34,"STRING":35,"Literal":36,"JS":37,"REGEX":38,"BOOL":39,"Assignable":40,"=":41,"AssignObj":42,"ThisProperty":43,":":44,"RETURN":45,"HERECOMMENT":46,"?":47,"PARAM_START":48,"ParamList":49,"PARAM_END":50,"FuncGlyph":51,"->":52,"=>":53,"OptComma":54,",":55,"Param":56,"PARAM":57,"@":58,"...":59,"Splat":60,"SimpleAssignable":61,"Accessor":62,"Array":63,"Object":64,"Parenthetical":65,"Range":66,"This":67,"PROPERTY_ACCESS":68,"PROTOTYPE_ACCESS":69,"::":70,"SOAK_ACCESS":71,"Index":72,"Slice":73,"INDEX_START":74,"INDEX_END":75,"INDEX_SOAK":76,"INDEX_PROTO":77,"{":78,"AssignList":79,"}":80,"CLASS":81,"EXTENDS":82,"ClassBody":83,"ClassAssign":84,"OptFuncExist":85,"Arguments":86,"SUPER":87,"FUNC_EXIST":88,"CALL_START":89,"CALL_END":90,"ArgList":91,"THIS":92,"RangeDots":93,"..":94,"[":95,"]":96,"Arg":97,"SimpleArgs":98,"TRY":99,"Catch":100,"FINALLY":101,"CATCH":102,"THROW":103,"(":104,")":105,"WhileSource":106,"WHILE":107,"WHEN":108,"UNTIL":109,"Loop":110,"LOOP":111,"ForBody":112,"FOR":113,"ForStart":114,"ForSource":115,"ForVariables":116,"ALL":117,"ForValue":118,"FORIN":119,"FOROF":120,"BY":121,"SWITCH":122,"Whens":123,"ELSE":124,"When":125,"LEADING_WHEN":126,"IfBlock":127,"IF":128,"UNLESS":129,"POST_IF":130,"POST_UNLESS":131,"UNARY":132,"-":133,"+":134,"--":135,"++":136,"==":137,"!=":138,"MATH":139,"SHIFT":140,"COMPARE":141,"LOGIC":142,"COMPOUND_ASSIGN":143,"RELATION":144,"$accept":0,"$end":1},
+terminals_: {"2":"error","4":"TERMINATOR","12":"BREAK","13":"CONTINUE","14":"DEBUGGER","29":"INDENT","30":"OUTDENT","32":"IDENTIFIER","34":"NUMBER","35":"STRING","37":"JS","38":"REGEX","39":"BOOL","41":"=","44":":","45":"RETURN","46":"HERECOMMENT","47":"?","48":"PARAM_START","50":"PARAM_END","52":"->","53":"=>","55":",","57":"PARAM","58":"@","59":"...","68":"PROPERTY_ACCESS","69":"PROTOTYPE_ACCESS","70":"::","71":"SOAK_ACCESS","74":"INDEX_START","75":"INDEX_END","76":"INDEX_SOAK","77":"INDEX_PROTO","78":"{","80":"}","81":"CLASS","82":"EXTENDS","87":"SUPER","88":"FUNC_EXIST","89":"CALL_START","90":"CALL_END","92":"THIS","94":"..","95":"[","96":"]","99":"TRY","101":"FINALLY","102":"CATCH","103":"THROW","104":"(","105":")","107":"WHILE","108":"WHEN","109":"UNTIL","111":"LOOP","113":"FOR","117":"ALL","119":"FORIN","120":"FOROF","121":"BY","122":"SWITCH","124":"ELSE","126":"LEADING_WHEN","128":"IF","129":"UNLESS","130":"POST_IF","131":"POST_UNLESS","132":"UNARY","133":"-","134":"+","135":"--","136":"++","137":"==","138":"!=","139":"MATH","140":"SHIFT","141":"COMPARE","142":"LOGIC","143":"COMPOUND_ASSIGN","144":"RELATION"},
+productions_: [0,[3,0],[3,1],[3,1],[3,2],[5,1],[5,3],[5,2],[7,1],[7,1],[9,1],[9,1],[9,1],[9,1],[9,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[8,1],[6,3],[6,2],[6,2],[31,1],[33,1],[33,1],[36,1],[36,1],[36,1],[36,1],[19,3],[19,5],[42,1],[42,1],[42,1],[42,3],[42,3],[42,5],[42,5],[42,1],[10,2],[10,1],[28,1],[27,2],[17,5],[17,2],[51,1],[51,1],[54,0],[54,1],[49,0],[49,1],[49,3],[56,1],[56,2],[56,2],[56,3],[60,2],[61,1],[61,2],[61,2],[61,1],[40,1],[40,1],[40,1],[15,1],[15,1],[15,1],[15,1],[15,1],[62,2],[62,2],[62,1],[62,2],[62,1],[62,1],[72,3],[72,2],[72,2],[64,4],[79,0],[79,1],[79,3],[79,4],[79,6],[26,2],[26,4],[26,5],[26,7],[26,4],[26,1],[26,3],[26,6],[84,1],[84,3],[84,5],[83,0],[83,1],[83,3],[83,3],[25,3],[16,3],[16,3],[16,1],[16,2],[85,0],[85,1],[86,2],[86,4],[67,1],[67,1],[93,1],[93,1],[43,2],[66,5],[73,5],[73,4],[73,4],[63,2],[63,4],[91,1],[91,3],[91,4],[91,4],[91,6],[97,1],[97,1],[98,1],[98,3],[21,2],[21,3],[21,4],[21,5],[100,3],[11,2],[65,3],[65,2],[106,2],[106,4],[106,2],[106,4],[22,2],[22,2],[22,2],[22,1],[110,2],[110,2],[23,2],[23,2],[23,2],[112,2],[112,2],[114,2],[114,3],[118,1],[118,1],[118,1],[116,1],[116,3],[115,2],[115,2],[115,4],[115,4],[115,4],[115,6],[115,6],[24,5],[24,7],[24,4],[24,6],[123,1],[123,2],[125,3],[125,4],[127,3],[127,3],[127,5],[127,3],[20,1],[20,3],[20,3],[20,3],[20,3],[18,2],[18,2],[18,2],[18,2],[18,2],[18,2],[18,2],[18,3],[18,3],[18,3],[18,3],[18,3],[18,3],[18,3],[18,3],[18,3],[18,5],[18,3]],
+performAction: function anonymous(yytext,yyleng,yylineno,yy) {
+
+var $$ = arguments[5],$0=arguments[5].length;
+switch(arguments[4]) {
+case 1:return this.$ = new yy.Expressions;
+break;
+case 2:return this.$ = new yy.Expressions;
+break;
+case 3:return this.$ = $$[$0-1+1-1];
+break;
+case 4:return this.$ = $$[$0-2+1-1];
+break;
+case 5:this.$ = yy.Expressions.wrap([$$[$0-1+1-1]]);
+break;
+case 6:this.$ = $$[$0-3+1-1].push($$[$0-3+3-1]);
+break;
+case 7:this.$ = $$[$0-2+1-1];
+break;
+case 8:this.$ = $$[$0-1+1-1];
+break;
+case 9:this.$ = $$[$0-1+1-1];
+break;
+case 10:this.$ = $$[$0-1+1-1];
+break;
+case 11:this.$ = $$[$0-1+1-1];
+break;
+case 12:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 13:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 14:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 15:this.$ = $$[$0-1+1-1];
+break;
+case 16:this.$ = $$[$0-1+1-1];
+break;
+case 17:this.$ = $$[$0-1+1-1];
+break;
+case 18:this.$ = $$[$0-1+1-1];
+break;
+case 19:this.$ = $$[$0-1+1-1];
+break;
+case 20:this.$ = $$[$0-1+1-1];
+break;
+case 21:this.$ = $$[$0-1+1-1];
+break;
+case 22:this.$ = $$[$0-1+1-1];
+break;
+case 23:this.$ = $$[$0-1+1-1];
+break;
+case 24:this.$ = $$[$0-1+1-1];
+break;
+case 25:this.$ = $$[$0-1+1-1];
+break;
+case 26:this.$ = $$[$0-1+1-1];
+break;
+case 27:this.$ = $$[$0-1+1-1];
+break;
+case 28:this.$ = $$[$0-1+1-1];
+break;
+case 29:this.$ = $$[$0-3+2-1];
+break;
+case 30:this.$ = new yy.Expressions;
+break;
+case 31:this.$ = yy.Expressions.wrap([$$[$0-2+2-1]]);
+break;
+case 32:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 33:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 34:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 35:this.$ = $$[$0-1+1-1];
+break;
+case 36:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 37:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 38:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 39:this.$ = new yy.Assign($$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 40:this.$ = new yy.Assign($$[$0-5+1-1], $$[$0-5+4-1]);
+break;
+case 41:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 42:this.$ = $$[$0-1+1-1];
+break;
+case 43:this.$ = $$[$0-1+1-1];
+break;
+case 44:this.$ = new yy.Assign(new yy.Value($$[$0-3+1-1]), $$[$0-3+3-1], 'object');
+break;
+case 45:this.$ = new yy.Assign(new yy.Value($$[$0-3+1-1]), $$[$0-3+3-1], 'object');
+break;
+case 46:this.$ = new yy.Assign(new yy.Value($$[$0-5+1-1]), $$[$0-5+4-1], 'object');
+break;
+case 47:this.$ = new yy.Assign(new yy.Value($$[$0-5+1-1]), $$[$0-5+4-1], 'object');
+break;
+case 48:this.$ = $$[$0-1+1-1];
+break;
+case 49:this.$ = new yy.Return($$[$0-2+2-1]);
+break;
+case 50:this.$ = new yy.Return;
+break;
+case 51:this.$ = new yy.Comment($$[$0-1+1-1]);
+break;
+case 52:this.$ = new yy.Existence($$[$0-2+1-1]);
+break;
+case 53:this.$ = new yy.Code($$[$0-5+2-1], $$[$0-5+5-1], $$[$0-5+4-1]);
+break;
+case 54:this.$ = new yy.Code([], $$[$0-2+2-1], $$[$0-2+1-1]);
+break;
+case 55:this.$ = 'func';
+break;
+case 56:this.$ = 'boundfunc';
+break;
+case 57:this.$ = $$[$0-1+1-1];
+break;
+case 58:this.$ = $$[$0-1+1-1];
+break;
+case 59:this.$ = [];
+break;
+case 60:this.$ = [$$[$0-1+1-1]];
+break;
+case 61:this.$ = $$[$0-3+1-1].concat($$[$0-3+3-1]);
+break;
+case 62:this.$ = new yy.Literal($$[$0-1+1-1]);
+break;
+case 63:this.$ = new yy.Param($$[$0-2+2-1], true);
+break;
+case 64:this.$ = new yy.Param($$[$0-2+1-1], false, true);
+break;
+case 65:this.$ = new yy.Param($$[$0-3+2-1], true, true);
+break;
+case 66:this.$ = new yy.Splat($$[$0-2+1-1]);
+break;
+case 67:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 68:this.$ = $$[$0-2+1-1].push($$[$0-2+2-1]);
+break;
+case 69:this.$ = new yy.Value($$[$0-2+1-1], [$$[$0-2+2-1]]);
+break;
+case 70:this.$ = $$[$0-1+1-1];
+break;
+case 71:this.$ = $$[$0-1+1-1];
+break;
+case 72:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 73:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 74:this.$ = $$[$0-1+1-1];
+break;
+case 75:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 76:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 77:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 78:this.$ = $$[$0-1+1-1];
+break;
+case 79:this.$ = new yy.Accessor($$[$0-2+2-1]);
+break;
+case 80:this.$ = new yy.Accessor($$[$0-2+2-1], 'prototype');
+break;
+case 81:this.$ = new yy.Accessor(new yy.Literal('prototype'));
+break;
+case 82:this.$ = new yy.Accessor($$[$0-2+2-1], 'soak');
+break;
+case 83:this.$ = $$[$0-1+1-1];
+break;
+case 84:this.$ = new yy.Slice($$[$0-1+1-1]);
+break;
+case 85:this.$ = new yy.Index($$[$0-3+2-1]);
+break;
+case 86:this.$ = (function () {
+ $$[$0-2+2-1].soakNode = true;
+ return $$[$0-2+2-1];
+ }());
+break;
+case 87:this.$ = (function () {
+ $$[$0-2+2-1].proto = true;
+ return $$[$0-2+2-1];
+ }());
+break;
+case 88:this.$ = new yy.ObjectLiteral($$[$0-4+2-1]);
+break;
+case 89:this.$ = [];
+break;
+case 90:this.$ = [$$[$0-1+1-1]];
+break;
+case 91:this.$ = $$[$0-3+1-1].concat($$[$0-3+3-1]);
+break;
+case 92:this.$ = $$[$0-4+1-1].concat($$[$0-4+4-1]);
+break;
+case 93:this.$ = $$[$0-6+1-1].concat($$[$0-6+4-1]);
+break;
+case 94:this.$ = new yy.Class($$[$0-2+2-1]);
+break;
+case 95:this.$ = new yy.Class($$[$0-4+2-1], $$[$0-4+4-1]);
+break;
+case 96:this.$ = new yy.Class($$[$0-5+2-1], null, $$[$0-5+4-1]);
+break;
+case 97:this.$ = new yy.Class($$[$0-7+2-1], $$[$0-7+4-1], $$[$0-7+6-1]);
+break;
+case 98:this.$ = new yy.Class('__temp__', null, $$[$0-4+3-1]);
+break;
+case 99:this.$ = new yy.Class('__temp__', null, new yy.Expressions);
+break;
+case 100:this.$ = new yy.Class('__temp__', $$[$0-3+3-1], new yy.Expressions);
+break;
+case 101:this.$ = new yy.Class('__temp__', $$[$0-6+3-1], $$[$0-6+5-1]);
+break;
+case 102:this.$ = $$[$0-1+1-1];
+break;
+case 103:this.$ = new yy.Assign(new yy.Value($$[$0-3+1-1]), $$[$0-3+3-1], 'this');
+break;
+case 104:this.$ = new yy.Assign(new yy.Value($$[$0-5+1-1]), $$[$0-5+4-1], 'this');
+break;
+case 105:this.$ = [];
+break;
+case 106:this.$ = [$$[$0-1+1-1]];
+break;
+case 107:this.$ = $$[$0-3+1-1].concat($$[$0-3+3-1]);
+break;
+case 108:this.$ = $$[$0-3+2-1];
+break;
+case 109:this.$ = new yy.Extends($$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 110:this.$ = new yy.Call($$[$0-3+1-1], $$[$0-3+3-1], $$[$0-3+2-1]);
+break;
+case 111:this.$ = new yy.Call($$[$0-3+1-1], $$[$0-3+3-1], $$[$0-3+2-1]);
+break;
+case 112:this.$ = new yy.Call('super', [new yy.Splat(new yy.Literal('arguments'))]);
+break;
+case 113:this.$ = new yy.Call('super', $$[$0-2+2-1]);
+break;
+case 114:this.$ = false;
+break;
+case 115:this.$ = true;
+break;
+case 116:this.$ = [];
+break;
+case 117:this.$ = $$[$0-4+2-1];
+break;
+case 118:this.$ = new yy.Value(new yy.Literal('this'));
+break;
+case 119:this.$ = new yy.Value(new yy.Literal('this'));
+break;
+case 120:this.$ = 'inclusive';
+break;
+case 121:this.$ = 'exclusive';
+break;
+case 122:this.$ = new yy.Value(new yy.Literal('this'), [new yy.Accessor($$[$0-2+2-1])], 'this');
+break;
+case 123:this.$ = new yy.Range($$[$0-5+2-1], $$[$0-5+4-1], $$[$0-5+3-1]);
+break;
+case 124:this.$ = new yy.Range($$[$0-5+2-1], $$[$0-5+4-1], $$[$0-5+3-1]);
+break;
+case 125:this.$ = new yy.Range($$[$0-4+2-1], null, $$[$0-4+3-1]);
+break;
+case 126:this.$ = new yy.Range(null, $$[$0-4+3-1], $$[$0-4+2-1]);
+break;
+case 127:this.$ = new yy.ArrayLiteral([]);
+break;
+case 128:this.$ = new yy.ArrayLiteral($$[$0-4+2-1]);
+break;
+case 129:this.$ = [$$[$0-1+1-1]];
+break;
+case 130:this.$ = $$[$0-3+1-1].concat($$[$0-3+3-1]);
+break;
+case 131:this.$ = $$[$0-4+1-1].concat($$[$0-4+4-1]);
+break;
+case 132:this.$ = $$[$0-4+2-1];
+break;
+case 133:this.$ = $$[$0-6+1-1].concat($$[$0-6+4-1]);
+break;
+case 134:this.$ = $$[$0-1+1-1];
+break;
+case 135:this.$ = $$[$0-1+1-1];
+break;
+case 136:this.$ = $$[$0-1+1-1];
+break;
+case 137:this.$ = [].concat($$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 138:this.$ = new yy.Try($$[$0-2+2-1]);
+break;
+case 139:this.$ = new yy.Try($$[$0-3+2-1], $$[$0-3+3-1][0], $$[$0-3+3-1][1]);
+break;
+case 140:this.$ = new yy.Try($$[$0-4+2-1], null, null, $$[$0-4+4-1]);
+break;
+case 141:this.$ = new yy.Try($$[$0-5+2-1], $$[$0-5+3-1][0], $$[$0-5+3-1][1], $$[$0-5+5-1]);
+break;
+case 142:this.$ = [$$[$0-3+2-1], $$[$0-3+3-1]];
+break;
+case 143:this.$ = new yy.Throw($$[$0-2+2-1]);
+break;
+case 144:this.$ = new yy.Parens($$[$0-3+2-1]);
+break;
+case 145:this.$ = new yy.Parens(new yy.Literal(''));
+break;
+case 146:this.$ = new yy.While($$[$0-2+2-1]);
+break;
+case 147:this.$ = new yy.While($$[$0-4+2-1], {
+ guard: $$[$0-4+4-1]
+ });
+break;
+case 148:this.$ = new yy.While($$[$0-2+2-1], {
+ invert: true
+ });
+break;
+case 149:this.$ = new yy.While($$[$0-4+2-1], {
+ invert: true,
+ guard: $$[$0-4+4-1]
+ });
+break;
+case 150:this.$ = $$[$0-2+1-1].addBody($$[$0-2+2-1]);
+break;
+case 151:this.$ = $$[$0-2+2-1].addBody(yy.Expressions.wrap([$$[$0-2+1-1]]));
+break;
+case 152:this.$ = $$[$0-2+2-1].addBody(yy.Expressions.wrap([$$[$0-2+1-1]]));
+break;
+case 153:this.$ = $$[$0-1+1-1];
+break;
+case 154:this.$ = new yy.While(new yy.Literal('true')).addBody($$[$0-2+2-1]);
+break;
+case 155:this.$ = new yy.While(new yy.Literal('true')).addBody(yy.Expressions.wrap([$$[$0-2+2-1]]));
+break;
+case 156:this.$ = new yy.For($$[$0-2+1-1], $$[$0-2+2-1], $$[$0-2+2-1].vars[0], $$[$0-2+2-1].vars[1]);
+break;
+case 157:this.$ = new yy.For($$[$0-2+1-1], $$[$0-2+2-1], $$[$0-2+2-1].vars[0], $$[$0-2+2-1].vars[1]);
+break;
+case 158:this.$ = new yy.For($$[$0-2+2-1], $$[$0-2+1-1], $$[$0-2+1-1].vars[0], $$[$0-2+1-1].vars[1]);
+break;
+case 159:this.$ = {
+ source: new yy.Value($$[$0-2+2-1]),
+ vars: []
+ };
+break;
+case 160:this.$ = (function () {
+ $$[$0-2+2-1].raw = $$[$0-2+1-1].raw;
+ $$[$0-2+2-1].vars = $$[$0-2+1-1];
+ return $$[$0-2+2-1];
+ }());
+break;
+case 161:this.$ = $$[$0-2+2-1];
+break;
+case 162:this.$ = (function () {
+ $$[$0-3+3-1].raw = true;
+ return $$[$0-3+3-1];
+ }());
+break;
+case 163:this.$ = $$[$0-1+1-1];
+break;
+case 164:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 165:this.$ = new yy.Value($$[$0-1+1-1]);
+break;
+case 166:this.$ = [$$[$0-1+1-1]];
+break;
+case 167:this.$ = [$$[$0-3+1-1], $$[$0-3+3-1]];
+break;
+case 168:this.$ = {
+ source: $$[$0-2+2-1]
+ };
+break;
+case 169:this.$ = {
+ source: $$[$0-2+2-1],
+ object: true
+ };
+break;
+case 170:this.$ = {
+ source: $$[$0-4+2-1],
+ guard: $$[$0-4+4-1]
+ };
+break;
+case 171:this.$ = {
+ source: $$[$0-4+2-1],
+ guard: $$[$0-4+4-1],
+ object: true
+ };
+break;
+case 172:this.$ = {
+ source: $$[$0-4+2-1],
+ step: $$[$0-4+4-1]
+ };
+break;
+case 173:this.$ = {
+ source: $$[$0-6+2-1],
+ guard: $$[$0-6+4-1],
+ step: $$[$0-6+6-1]
+ };
+break;
+case 174:this.$ = {
+ source: $$[$0-6+2-1],
+ step: $$[$0-6+4-1],
+ guard: $$[$0-6+6-1]
+ };
+break;
+case 175:this.$ = new yy.Switch($$[$0-5+2-1], $$[$0-5+4-1]);
+break;
+case 176:this.$ = new yy.Switch($$[$0-7+2-1], $$[$0-7+4-1], $$[$0-7+6-1]);
+break;
+case 177:this.$ = new yy.Switch(null, $$[$0-4+3-1]);
+break;
+case 178:this.$ = new yy.Switch(null, $$[$0-6+3-1], $$[$0-6+5-1]);
+break;
+case 179:this.$ = $$[$0-1+1-1];
+break;
+case 180:this.$ = $$[$0-2+1-1].concat($$[$0-2+2-1]);
+break;
+case 181:this.$ = [[$$[$0-3+2-1], $$[$0-3+3-1]]];
+break;
+case 182:this.$ = [[$$[$0-4+2-1], $$[$0-4+3-1]]];
+break;
+case 183:this.$ = new yy.If($$[$0-3+2-1], $$[$0-3+3-1]);
+break;
+case 184:this.$ = new yy.If($$[$0-3+2-1], $$[$0-3+3-1], {
+ invert: true
+ });
+break;
+case 185:this.$ = $$[$0-5+1-1].addElse(new yy.If($$[$0-5+4-1], $$[$0-5+5-1]));
+break;
+case 186:this.$ = $$[$0-3+1-1].addElse($$[$0-3+3-1]);
+break;
+case 187:this.$ = $$[$0-1+1-1];
+break;
+case 188:this.$ = new yy.If($$[$0-3+3-1], yy.Expressions.wrap([$$[$0-3+1-1]]), {
+ statement: true
+ });
+break;
+case 189:this.$ = new yy.If($$[$0-3+3-1], yy.Expressions.wrap([$$[$0-3+1-1]]), {
+ statement: true
+ });
+break;
+case 190:this.$ = new yy.If($$[$0-3+3-1], yy.Expressions.wrap([$$[$0-3+1-1]]), {
+ statement: true,
+ invert: true
+ });
+break;
+case 191:this.$ = new yy.If($$[$0-3+3-1], yy.Expressions.wrap([$$[$0-3+1-1]]), {
+ statement: true,
+ invert: true
+ });
+break;
+case 192:this.$ = new yy.Op($$[$0-2+1-1], $$[$0-2+2-1]);
+break;
+case 193:this.$ = new yy.Op('-', $$[$0-2+2-1]);
+break;
+case 194:this.$ = new yy.Op('+', $$[$0-2+2-1]);
+break;
+case 195:this.$ = new yy.Op('--', $$[$0-2+2-1]);
+break;
+case 196:this.$ = new yy.Op('++', $$[$0-2+2-1]);
+break;
+case 197:this.$ = new yy.Op('--', $$[$0-2+1-1], null, true);
+break;
+case 198:this.$ = new yy.Op('++', $$[$0-2+1-1], null, true);
+break;
+case 199:this.$ = new yy.Op('+', $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 200:this.$ = new yy.Op('-', $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 201:this.$ = new yy.Op('==', $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 202:this.$ = new yy.Op('!=', $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 203:this.$ = new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 204:this.$ = new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 205:this.$ = new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 206:this.$ = new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 207:this.$ = new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]);
+break;
+case 208:this.$ = new yy.Op($$[$0-5+2-1], $$[$0-5+1-1], $$[$0-5+4-1]);
+break;
+case 209:this.$ = $$[$0-3+2-1].charAt(0) === '!' ? ($$[$0-3+2-1] === '!in' ? new yy.Op('!', new yy.In($$[$0-3+1-1], $$[$0-3+3-1])) : new yy.Op('!', new yy.Parens(new yy.Op($$[$0-3+2-1].slice(1), $$[$0-3+1-1], $$[$0-3+3-1])))) : ($$[$0-3+2-1] === 'in' ? new yy.In($$[$0-3+1-1], $$[$0-3+3-1]) : new yy.Op($$[$0-3+2-1], $$[$0-3+1-1], $$[$0-3+3-1]));
+break;
+}
+},
+table: [{"1":[2,1],"3":1,"4":[1,2],"5":3,"6":4,"7":5,"8":7,"9":8,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,6],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[3]},{"1":[2,2],"28":77,"46":[1,49]},{"1":[2,3],"4":[1,78]},{"4":[1,79]},{"1":[2,5],"4":[2,5],"30":[2,5]},{"5":80,"7":5,"8":7,"9":8,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"30":[1,81],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,8],"4":[2,8],"30":[2,8],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,9],"4":[2,9],"30":[2,9],"106":98,"107":[1,68],"109":[1,69],"112":99,"113":[1,71],"114":72,"130":[1,96],"131":[1,97]},{"1":[2,15],"4":[2,15],"29":[2,15],"30":[2,15],"47":[2,15],"55":[2,15],"59":[2,15],"62":101,"68":[1,103],"69":[1,104],"70":[1,105],"71":[1,106],"72":107,"73":108,"74":[1,109],"75":[2,15],"76":[1,110],"77":[1,111],"80":[2,15],"85":100,"88":[1,102],"89":[2,114],"90":[2,15],"94":[2,15],"96":[2,15],"105":[2,15],"107":[2,15],"108":[2,15],"109":[2,15],"113":[2,15],"121":[2,15],"130":[2,15],"131":[2,15],"133":[2,15],"134":[2,15],"137":[2,15],"138":[2,15],"139":[2,15],"140":[2,15],"141":[2,15],"142":[2,15],"144":[2,15]},{"1":[2,16],"4":[2,16],"29":[2,16],"30":[2,16],"47":[2,16],"55":[2,16],"59":[2,16],"62":113,"68":[1,103],"69":[1,104],"70":[1,105],"71":[1,106],"72":107,"73":108,"74":[1,109],"75":[2,16],"76":[1,110],"77":[1,111],"80":[2,16],"85":112,"88":[1,102],"89":[2,114],"90":[2,16],"94":[2,16],"96":[2,16],"105":[2,16],"107":[2,16],"108":[2,16],"109":[2,16],"113":[2,16],"121":[2,16],"130":[2,16],"131":[2,16],"133":[2,16],"134":[2,16],"137":[2,16],"138":[2,16],"139":[2,16],"140":[2,16],"141":[2,16],"142":[2,16],"144":[2,16]},{"1":[2,17],"4":[2,17],"29":[2,17],"30":[2,17],"47":[2,17],"55":[2,17],"59":[2,17],"75":[2,17],"80":[2,17],"90":[2,17],"94":[2,17],"96":[2,17],"105":[2,17],"107":[2,17],"108":[2,17],"109":[2,17],"113":[2,17],"121":[2,17],"130":[2,17],"131":[2,17],"133":[2,17],"134":[2,17],"137":[2,17],"138":[2,17],"139":[2,17],"140":[2,17],"141":[2,17],"142":[2,17],"144":[2,17]},{"1":[2,18],"4":[2,18],"29":[2,18],"30":[2,18],"47":[2,18],"55":[2,18],"59":[2,18],"75":[2,18],"80":[2,18],"90":[2,18],"94":[2,18],"96":[2,18],"105":[2,18],"107":[2,18],"108":[2,18],"109":[2,18],"113":[2,18],"121":[2,18],"130":[2,18],"131":[2,18],"133":[2,18],"134":[2,18],"137":[2,18],"138":[2,18],"139":[2,18],"140":[2,18],"141":[2,18],"142":[2,18],"144":[2,18]},{"1":[2,19],"4":[2,19],"29":[2,19],"30":[2,19],"47":[2,19],"55":[2,19],"59":[2,19],"75":[2,19],"80":[2,19],"90":[2,19],"94":[2,19],"96":[2,19],"105":[2,19],"107":[2,19],"108":[2,19],"109":[2,19],"113":[2,19],"121":[2,19],"130":[2,19],"131":[2,19],"133":[2,19],"134":[2,19],"137":[2,19],"138":[2,19],"139":[2,19],"140":[2,19],"141":[2,19],"142":[2,19],"144":[2,19]},{"1":[2,20],"4":[2,20],"29":[2,20],"30":[2,20],"47":[2,20],"55":[2,20],"59":[2,20],"75":[2,20],"80":[2,20],"90":[2,20],"94":[2,20],"96":[2,20],"105":[2,20],"107":[2,20],"108":[2,20],"109":[2,20],"113":[2,20],"121":[2,20],"130":[2,20],"131":[2,20],"133":[2,20],"134":[2,20],"137":[2,20],"138":[2,20],"139":[2,20],"140":[2,20],"141":[2,20],"142":[2,20],"144":[2,20]},{"1":[2,21],"4":[2,21],"29":[2,21],"30":[2,21],"47":[2,21],"55":[2,21],"59":[2,21],"75":[2,21],"80":[2,21],"90":[2,21],"94":[2,21],"96":[2,21],"105":[2,21],"107":[2,21],"108":[2,21],"109":[2,21],"113":[2,21],"121":[2,21],"130":[2,21],"131":[2,21],"133":[2,21],"134":[2,21],"137":[2,21],"138":[2,21],"139":[2,21],"140":[2,21],"141":[2,21],"142":[2,21],"144":[2,21]},{"1":[2,22],"4":[2,22],"29":[2,22],"30":[2,22],"47":[2,22],"55":[2,22],"59":[2,22],"75":[2,22],"80":[2,22],"90":[2,22],"94":[2,22],"96":[2,22],"105":[2,22],"107":[2,22],"108":[2,22],"109":[2,22],"113":[2,22],"121":[2,22],"130":[2,22],"131":[2,22],"133":[2,22],"134":[2,22],"137":[2,22],"138":[2,22],"139":[2,22],"140":[2,22],"141":[2,22],"142":[2,22],"144":[2,22]},{"1":[2,23],"4":[2,23],"29":[2,23],"30":[2,23],"47":[2,23],"55":[2,23],"59":[2,23],"75":[2,23],"80":[2,23],"90":[2,23],"94":[2,23],"96":[2,23],"105":[2,23],"107":[2,23],"108":[2,23],"109":[2,23],"113":[2,23],"121":[2,23],"130":[2,23],"131":[2,23],"133":[2,23],"134":[2,23],"137":[2,23],"138":[2,23],"139":[2,23],"140":[2,23],"141":[2,23],"142":[2,23],"144":[2,23]},{"1":[2,24],"4":[2,24],"29":[2,24],"30":[2,24],"47":[2,24],"55":[2,24],"59":[2,24],"75":[2,24],"80":[2,24],"90":[2,24],"94":[2,24],"96":[2,24],"105":[2,24],"107":[2,24],"108":[2,24],"109":[2,24],"113":[2,24],"121":[2,24],"130":[2,24],"131":[2,24],"133":[2,24],"134":[2,24],"137":[2,24],"138":[2,24],"139":[2,24],"140":[2,24],"141":[2,24],"142":[2,24],"144":[2,24]},{"1":[2,25],"4":[2,25],"29":[2,25],"30":[2,25],"47":[2,25],"55":[2,25],"59":[2,25],"75":[2,25],"80":[2,25],"90":[2,25],"94":[2,25],"96":[2,25],"105":[2,25],"107":[2,25],"108":[2,25],"109":[2,25],"113":[2,25],"121":[2,25],"130":[2,25],"131":[2,25],"133":[2,25],"134":[2,25],"137":[2,25],"138":[2,25],"139":[2,25],"140":[2,25],"141":[2,25],"142":[2,25],"144":[2,25]},{"1":[2,26],"4":[2,26],"29":[2,26],"30":[2,26],"47":[2,26],"55":[2,26],"59":[2,26],"75":[2,26],"80":[2,26],"90":[2,26],"94":[2,26],"96":[2,26],"105":[2,26],"107":[2,26],"108":[2,26],"109":[2,26],"113":[2,26],"121":[2,26],"130":[2,26],"131":[2,26],"133":[2,26],"134":[2,26],"137":[2,26],"138":[2,26],"139":[2,26],"140":[2,26],"141":[2,26],"142":[2,26],"144":[2,26]},{"1":[2,27],"4":[2,27],"29":[2,27],"30":[2,27],"47":[2,27],"55":[2,27],"59":[2,27],"75":[2,27],"80":[2,27],"90":[2,27],"94":[2,27],"96":[2,27],"105":[2,27],"107":[2,27],"108":[2,27],"109":[2,27],"113":[2,27],"121":[2,27],"130":[2,27],"131":[2,27],"133":[2,27],"134":[2,27],"137":[2,27],"138":[2,27],"139":[2,27],"140":[2,27],"141":[2,27],"142":[2,27],"144":[2,27]},{"1":[2,28],"4":[2,28],"29":[2,28],"30":[2,28],"47":[2,28],"55":[2,28],"59":[2,28],"75":[2,28],"80":[2,28],"90":[2,28],"94":[2,28],"96":[2,28],"105":[2,28],"107":[2,28],"108":[2,28],"109":[2,28],"113":[2,28],"121":[2,28],"130":[2,28],"131":[2,28],"133":[2,28],"134":[2,28],"137":[2,28],"138":[2,28],"139":[2,28],"140":[2,28],"141":[2,28],"142":[2,28],"144":[2,28]},{"1":[2,10],"4":[2,10],"30":[2,10],"107":[2,10],"109":[2,10],"113":[2,10],"130":[2,10],"131":[2,10]},{"1":[2,11],"4":[2,11],"30":[2,11],"107":[2,11],"109":[2,11],"113":[2,11],"130":[2,11],"131":[2,11]},{"1":[2,12],"4":[2,12],"30":[2,12],"107":[2,12],"109":[2,12],"113":[2,12],"130":[2,12],"131":[2,12]},{"1":[2,13],"4":[2,13],"30":[2,13],"107":[2,13],"109":[2,13],"113":[2,13],"130":[2,13],"131":[2,13]},{"1":[2,14],"4":[2,14],"30":[2,14],"107":[2,14],"109":[2,14],"113":[2,14],"130":[2,14],"131":[2,14]},{"1":[2,74],"4":[2,74],"29":[2,74],"30":[2,74],"41":[1,114],"47":[2,74],"55":[2,74],"59":[2,74],"68":[2,74],"69":[2,74],"70":[2,74],"71":[2,74],"74":[2,74],"75":[2,74],"76":[2,74],"77":[2,74],"80":[2,74],"88":[2,74],"89":[2,74],"90":[2,74],"94":[2,74],"96":[2,74],"105":[2,74],"107":[2,74],"108":[2,74],"109":[2,74],"113":[2,74],"121":[2,74],"130":[2,74],"131":[2,74],"133":[2,74],"134":[2,74],"137":[2,74],"138":[2,74],"139":[2,74],"140":[2,74],"141":[2,74],"142":[2,74],"144":[2,74]},{"1":[2,75],"4":[2,75],"29":[2,75],"30":[2,75],"47":[2,75],"55":[2,75],"59":[2,75],"68":[2,75],"69":[2,75],"70":[2,75],"71":[2,75],"74":[2,75],"75":[2,75],"76":[2,75],"77":[2,75],"80":[2,75],"88":[2,75],"89":[2,75],"90":[2,75],"94":[2,75],"96":[2,75],"105":[2,75],"107":[2,75],"108":[2,75],"109":[2,75],"113":[2,75],"121":[2,75],"130":[2,75],"131":[2,75],"133":[2,75],"134":[2,75],"137":[2,75],"138":[2,75],"139":[2,75],"140":[2,75],"141":[2,75],"142":[2,75],"144":[2,75]},{"1":[2,76],"4":[2,76],"29":[2,76],"30":[2,76],"47":[2,76],"55":[2,76],"59":[2,76],"68":[2,76],"69":[2,76],"70":[2,76],"71":[2,76],"74":[2,76],"75":[2,76],"76":[2,76],"77":[2,76],"80":[2,76],"88":[2,76],"89":[2,76],"90":[2,76],"94":[2,76],"96":[2,76],"105":[2,76],"107":[2,76],"108":[2,76],"109":[2,76],"113":[2,76],"121":[2,76],"130":[2,76],"131":[2,76],"133":[2,76],"134":[2,76],"137":[2,76],"138":[2,76],"139":[2,76],"140":[2,76],"141":[2,76],"142":[2,76],"144":[2,76]},{"1":[2,77],"4":[2,77],"29":[2,77],"30":[2,77],"47":[2,77],"55":[2,77],"59":[2,77],"68":[2,77],"69":[2,77],"70":[2,77],"71":[2,77],"74":[2,77],"75":[2,77],"76":[2,77],"77":[2,77],"80":[2,77],"88":[2,77],"89":[2,77],"90":[2,77],"94":[2,77],"96":[2,77],"105":[2,77],"107":[2,77],"108":[2,77],"109":[2,77],"113":[2,77],"121":[2,77],"130":[2,77],"131":[2,77],"133":[2,77],"134":[2,77],"137":[2,77],"138":[2,77],"139":[2,77],"140":[2,77],"141":[2,77],"142":[2,77],"144":[2,77]},{"1":[2,78],"4":[2,78],"29":[2,78],"30":[2,78],"47":[2,78],"55":[2,78],"59":[2,78],"68":[2,78],"69":[2,78],"70":[2,78],"71":[2,78],"74":[2,78],"75":[2,78],"76":[2,78],"77":[2,78],"80":[2,78],"88":[2,78],"89":[2,78],"90":[2,78],"94":[2,78],"96":[2,78],"105":[2,78],"107":[2,78],"108":[2,78],"109":[2,78],"113":[2,78],"121":[2,78],"130":[2,78],"131":[2,78],"133":[2,78],"134":[2,78],"137":[2,78],"138":[2,78],"139":[2,78],"140":[2,78],"141":[2,78],"142":[2,78],"144":[2,78]},{"1":[2,112],"4":[2,112],"29":[2,112],"30":[2,112],"47":[2,112],"55":[2,112],"59":[2,112],"68":[2,112],"69":[2,112],"70":[2,112],"71":[2,112],"74":[2,112],"75":[2,112],"76":[2,112],"77":[2,112],"80":[2,112],"86":115,"88":[2,112],"89":[1,116],"90":[2,112],"94":[2,112],"96":[2,112],"105":[2,112],"107":[2,112],"108":[2,112],"109":[2,112],"113":[2,112],"121":[2,112],"130":[2,112],"131":[2,112],"133":[2,112],"134":[2,112],"137":[2,112],"138":[2,112],"139":[2,112],"140":[2,112],"141":[2,112],"142":[2,112],"144":[2,112]},{"49":117,"50":[2,59],"55":[2,59],"56":118,"57":[1,119],"58":[1,120]},{"4":[1,122],"6":121,"29":[1,6]},{"8":123,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":125,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":126,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"15":128,"16":129,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":130,"43":65,"58":[1,61],"61":127,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"87":[1,33],"92":[1,60],"95":[1,59],"104":[1,58]},{"15":128,"16":129,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":130,"43":65,"58":[1,61],"61":131,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"87":[1,33],"92":[1,60],"95":[1,59],"104":[1,58]},{"1":[2,71],"4":[2,71],"29":[2,71],"30":[2,71],"41":[2,71],"47":[2,71],"55":[2,71],"59":[2,71],"68":[2,71],"69":[2,71],"70":[2,71],"71":[2,71],"74":[2,71],"75":[2,71],"76":[2,71],"77":[2,71],"80":[2,71],"82":[1,135],"88":[2,71],"89":[2,71],"90":[2,71],"94":[2,71],"96":[2,71],"105":[2,71],"107":[2,71],"108":[2,71],"109":[2,71],"113":[2,71],"121":[2,71],"130":[2,71],"131":[2,71],"133":[2,71],"134":[2,71],"135":[1,132],"136":[1,133],"137":[2,71],"138":[2,71],"139":[2,71],"140":[2,71],"141":[2,71],"142":[2,71],"143":[1,134],"144":[2,71]},{"1":[2,187],"4":[2,187],"29":[2,187],"30":[2,187],"47":[2,187],"55":[2,187],"59":[2,187],"75":[2,187],"80":[2,187],"90":[2,187],"94":[2,187],"96":[2,187],"105":[2,187],"107":[2,187],"108":[2,187],"109":[2,187],"113":[2,187],"121":[2,187],"124":[1,136],"130":[2,187],"131":[2,187],"133":[2,187],"134":[2,187],"137":[2,187],"138":[2,187],"139":[2,187],"140":[2,187],"141":[2,187],"142":[2,187],"144":[2,187]},{"4":[1,122],"6":137,"29":[1,6]},{"4":[1,122],"6":138,"29":[1,6]},{"1":[2,153],"4":[2,153],"29":[2,153],"30":[2,153],"47":[2,153],"55":[2,153],"59":[2,153],"75":[2,153],"80":[2,153],"90":[2,153],"94":[2,153],"96":[2,153],"105":[2,153],"107":[2,153],"108":[2,153],"109":[2,153],"113":[2,153],"121":[2,153],"130":[2,153],"131":[2,153],"133":[2,153],"134":[2,153],"137":[2,153],"138":[2,153],"139":[2,153],"140":[2,153],"141":[2,153],"142":[2,153],"144":[2,153]},{"4":[1,122],"6":139,"29":[1,6]},{"8":140,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,141],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,99],"4":[2,99],"15":128,"16":129,"29":[1,143],"30":[2,99],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":130,"43":65,"47":[2,99],"55":[2,99],"58":[1,61],"59":[2,99],"61":142,"63":52,"64":53,"65":30,"66":31,"67":32,"75":[2,99],"78":[1,73],"80":[2,99],"82":[1,144],"87":[1,33],"90":[2,99],"92":[1,60],"94":[2,99],"95":[1,59],"96":[2,99],"104":[1,58],"105":[2,99],"107":[2,99],"108":[2,99],"109":[2,99],"113":[2,99],"121":[2,99],"130":[2,99],"131":[2,99],"133":[2,99],"134":[2,99],"137":[2,99],"138":[2,99],"139":[2,99],"140":[2,99],"141":[2,99],"142":[2,99],"144":[2,99]},{"1":[2,51],"4":[2,51],"29":[2,51],"30":[2,51],"47":[2,51],"55":[2,51],"59":[2,51],"75":[2,51],"80":[2,51],"90":[2,51],"94":[2,51],"96":[2,51],"101":[2,51],"102":[2,51],"105":[2,51],"107":[2,51],"108":[2,51],"109":[2,51],"113":[2,51],"121":[2,51],"124":[2,51],"126":[2,51],"130":[2,51],"131":[2,51],"133":[2,51],"134":[2,51],"137":[2,51],"138":[2,51],"139":[2,51],"140":[2,51],"141":[2,51],"142":[2,51],"144":[2,51]},{"1":[2,50],"4":[2,50],"8":145,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"30":[2,50],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"130":[2,50],"131":[2,50],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":146,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,72],"4":[2,72],"29":[2,72],"30":[2,72],"41":[2,72],"47":[2,72],"55":[2,72],"59":[2,72],"68":[2,72],"69":[2,72],"70":[2,72],"71":[2,72],"74":[2,72],"75":[2,72],"76":[2,72],"77":[2,72],"80":[2,72],"88":[2,72],"89":[2,72],"90":[2,72],"94":[2,72],"96":[2,72],"105":[2,72],"107":[2,72],"108":[2,72],"109":[2,72],"113":[2,72],"121":[2,72],"130":[2,72],"131":[2,72],"133":[2,72],"134":[2,72],"137":[2,72],"138":[2,72],"139":[2,72],"140":[2,72],"141":[2,72],"142":[2,72],"144":[2,72]},{"1":[2,73],"4":[2,73],"29":[2,73],"30":[2,73],"41":[2,73],"47":[2,73],"55":[2,73],"59":[2,73],"68":[2,73],"69":[2,73],"70":[2,73],"71":[2,73],"74":[2,73],"75":[2,73],"76":[2,73],"77":[2,73],"80":[2,73],"88":[2,73],"89":[2,73],"90":[2,73],"94":[2,73],"96":[2,73],"105":[2,73],"107":[2,73],"108":[2,73],"109":[2,73],"113":[2,73],"121":[2,73],"130":[2,73],"131":[2,73],"133":[2,73],"134":[2,73],"137":[2,73],"138":[2,73],"139":[2,73],"140":[2,73],"141":[2,73],"142":[2,73],"144":[2,73]},{"1":[2,35],"4":[2,35],"29":[2,35],"30":[2,35],"47":[2,35],"55":[2,35],"59":[2,35],"68":[2,35],"69":[2,35],"70":[2,35],"71":[2,35],"74":[2,35],"75":[2,35],"76":[2,35],"77":[2,35],"80":[2,35],"88":[2,35],"89":[2,35],"90":[2,35],"94":[2,35],"96":[2,35],"105":[2,35],"107":[2,35],"108":[2,35],"109":[2,35],"113":[2,35],"121":[2,35],"130":[2,35],"131":[2,35],"133":[2,35],"134":[2,35],"137":[2,35],"138":[2,35],"139":[2,35],"140":[2,35],"141":[2,35],"142":[2,35],"144":[2,35]},{"1":[2,36],"4":[2,36],"29":[2,36],"30":[2,36],"47":[2,36],"55":[2,36],"59":[2,36],"68":[2,36],"69":[2,36],"70":[2,36],"71":[2,36],"74":[2,36],"75":[2,36],"76":[2,36],"77":[2,36],"80":[2,36],"88":[2,36],"89":[2,36],"90":[2,36],"94":[2,36],"96":[2,36],"105":[2,36],"107":[2,36],"108":[2,36],"109":[2,36],"113":[2,36],"121":[2,36],"130":[2,36],"131":[2,36],"133":[2,36],"134":[2,36],"137":[2,36],"138":[2,36],"139":[2,36],"140":[2,36],"141":[2,36],"142":[2,36],"144":[2,36]},{"1":[2,37],"4":[2,37],"29":[2,37],"30":[2,37],"47":[2,37],"55":[2,37],"59":[2,37],"68":[2,37],"69":[2,37],"70":[2,37],"71":[2,37],"74":[2,37],"75":[2,37],"76":[2,37],"77":[2,37],"80":[2,37],"88":[2,37],"89":[2,37],"90":[2,37],"94":[2,37],"96":[2,37],"105":[2,37],"107":[2,37],"108":[2,37],"109":[2,37],"113":[2,37],"121":[2,37],"130":[2,37],"131":[2,37],"133":[2,37],"134":[2,37],"137":[2,37],"138":[2,37],"139":[2,37],"140":[2,37],"141":[2,37],"142":[2,37],"144":[2,37]},{"1":[2,38],"4":[2,38],"29":[2,38],"30":[2,38],"47":[2,38],"55":[2,38],"59":[2,38],"68":[2,38],"69":[2,38],"70":[2,38],"71":[2,38],"74":[2,38],"75":[2,38],"76":[2,38],"77":[2,38],"80":[2,38],"88":[2,38],"89":[2,38],"90":[2,38],"94":[2,38],"96":[2,38],"105":[2,38],"107":[2,38],"108":[2,38],"109":[2,38],"113":[2,38],"121":[2,38],"130":[2,38],"131":[2,38],"133":[2,38],"134":[2,38],"137":[2,38],"138":[2,38],"139":[2,38],"140":[2,38],"141":[2,38],"142":[2,38],"144":[2,38]},{"8":147,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"105":[1,148],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":149,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"91":151,"92":[1,60],"95":[1,59],"96":[1,150],"97":152,"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,118],"4":[2,118],"29":[2,118],"30":[2,118],"47":[2,118],"55":[2,118],"59":[2,118],"68":[2,118],"69":[2,118],"70":[2,118],"71":[2,118],"74":[2,118],"75":[2,118],"76":[2,118],"77":[2,118],"80":[2,118],"88":[2,118],"89":[2,118],"90":[2,118],"94":[2,118],"96":[2,118],"105":[2,118],"107":[2,118],"108":[2,118],"109":[2,118],"113":[2,118],"121":[2,118],"130":[2,118],"131":[2,118],"133":[2,118],"134":[2,118],"137":[2,118],"138":[2,118],"139":[2,118],"140":[2,118],"141":[2,118],"142":[2,118],"144":[2,118]},{"1":[2,119],"4":[2,119],"29":[2,119],"30":[2,119],"31":155,"32":[1,76],"47":[2,119],"55":[2,119],"59":[2,119],"68":[2,119],"69":[2,119],"70":[2,119],"71":[2,119],"74":[2,119],"75":[2,119],"76":[2,119],"77":[2,119],"80":[2,119],"88":[2,119],"89":[2,119],"90":[2,119],"94":[2,119],"96":[2,119],"105":[2,119],"107":[2,119],"108":[2,119],"109":[2,119],"113":[2,119],"121":[2,119],"130":[2,119],"131":[2,119],"133":[2,119],"134":[2,119],"137":[2,119],"138":[2,119],"139":[2,119],"140":[2,119],"141":[2,119],"142":[2,119],"144":[2,119]},{"4":[2,55],"29":[2,55]},{"4":[2,56],"29":[2,56]},{"1":[2,67],"4":[2,67],"29":[2,67],"30":[2,67],"41":[2,67],"47":[2,67],"55":[2,67],"59":[2,67],"68":[2,67],"69":[2,67],"70":[2,67],"71":[2,67],"74":[2,67],"75":[2,67],"76":[2,67],"77":[2,67],"80":[2,67],"82":[2,67],"88":[2,67],"89":[2,67],"90":[2,67],"94":[2,67],"96":[2,67],"105":[2,67],"107":[2,67],"108":[2,67],"109":[2,67],"113":[2,67],"121":[2,67],"130":[2,67],"131":[2,67],"133":[2,67],"134":[2,67],"135":[2,67],"136":[2,67],"137":[2,67],"138":[2,67],"139":[2,67],"140":[2,67],"141":[2,67],"142":[2,67],"143":[2,67],"144":[2,67]},{"1":[2,70],"4":[2,70],"29":[2,70],"30":[2,70],"41":[2,70],"47":[2,70],"55":[2,70],"59":[2,70],"68":[2,70],"69":[2,70],"70":[2,70],"71":[2,70],"74":[2,70],"75":[2,70],"76":[2,70],"77":[2,70],"80":[2,70],"82":[2,70],"88":[2,70],"89":[2,70],"90":[2,70],"94":[2,70],"96":[2,70],"105":[2,70],"107":[2,70],"108":[2,70],"109":[2,70],"113":[2,70],"121":[2,70],"130":[2,70],"131":[2,70],"133":[2,70],"134":[2,70],"135":[2,70],"136":[2,70],"137":[2,70],"138":[2,70],"139":[2,70],"140":[2,70],"141":[2,70],"142":[2,70],"143":[2,70],"144":[2,70]},{"8":156,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":157,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":158,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":159,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[1,122],"6":160,"8":161,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,6],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"31":166,"32":[1,76],"63":167,"64":168,"66":162,"78":[1,73],"95":[1,59],"116":163,"117":[1,164],"118":165},{"115":169,"119":[1,170],"120":[1,171]},{"4":[2,89],"28":177,"29":[2,89],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":173,"43":176,"46":[1,49],"55":[2,89],"58":[1,178],"79":172,"80":[2,89]},{"1":[2,33],"4":[2,33],"29":[2,33],"30":[2,33],"44":[2,33],"47":[2,33],"55":[2,33],"59":[2,33],"68":[2,33],"69":[2,33],"70":[2,33],"71":[2,33],"74":[2,33],"75":[2,33],"76":[2,33],"77":[2,33],"80":[2,33],"88":[2,33],"89":[2,33],"90":[2,33],"94":[2,33],"96":[2,33],"105":[2,33],"107":[2,33],"108":[2,33],"109":[2,33],"113":[2,33],"121":[2,33],"130":[2,33],"131":[2,33],"133":[2,33],"134":[2,33],"137":[2,33],"138":[2,33],"139":[2,33],"140":[2,33],"141":[2,33],"142":[2,33],"144":[2,33]},{"1":[2,34],"4":[2,34],"29":[2,34],"30":[2,34],"44":[2,34],"47":[2,34],"55":[2,34],"59":[2,34],"68":[2,34],"69":[2,34],"70":[2,34],"71":[2,34],"74":[2,34],"75":[2,34],"76":[2,34],"77":[2,34],"80":[2,34],"88":[2,34],"89":[2,34],"90":[2,34],"94":[2,34],"96":[2,34],"105":[2,34],"107":[2,34],"108":[2,34],"109":[2,34],"113":[2,34],"121":[2,34],"130":[2,34],"131":[2,34],"133":[2,34],"134":[2,34],"137":[2,34],"138":[2,34],"139":[2,34],"140":[2,34],"141":[2,34],"142":[2,34],"144":[2,34]},{"1":[2,32],"4":[2,32],"29":[2,32],"30":[2,32],"41":[2,32],"44":[2,32],"47":[2,32],"55":[2,32],"59":[2,32],"68":[2,32],"69":[2,32],"70":[2,32],"71":[2,32],"74":[2,32],"75":[2,32],"76":[2,32],"77":[2,32],"80":[2,32],"82":[2,32],"88":[2,32],"89":[2,32],"90":[2,32],"94":[2,32],"96":[2,32],"105":[2,32],"107":[2,32],"108":[2,32],"109":[2,32],"113":[2,32],"119":[2,32],"120":[2,32],"121":[2,32],"130":[2,32],"131":[2,32],"133":[2,32],"134":[2,32],"135":[2,32],"136":[2,32],"137":[2,32],"138":[2,32],"139":[2,32],"140":[2,32],"141":[2,32],"142":[2,32],"143":[2,32],"144":[2,32]},{"1":[2,31],"4":[2,31],"29":[2,31],"30":[2,31],"47":[2,31],"55":[2,31],"59":[2,31],"75":[2,31],"80":[2,31],"90":[2,31],"94":[2,31],"96":[2,31],"101":[2,31],"102":[2,31],"105":[2,31],"107":[2,31],"108":[2,31],"109":[2,31],"113":[2,31],"121":[2,31],"124":[2,31],"126":[2,31],"130":[2,31],"131":[2,31],"133":[2,31],"134":[2,31],"137":[2,31],"138":[2,31],"139":[2,31],"140":[2,31],"141":[2,31],"142":[2,31],"144":[2,31]},{"1":[2,7],"4":[2,7],"7":179,"8":7,"9":8,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"30":[2,7],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,4]},{"4":[1,78],"30":[1,180]},{"1":[2,30],"4":[2,30],"29":[2,30],"30":[2,30],"47":[2,30],"55":[2,30],"59":[2,30],"75":[2,30],"80":[2,30],"90":[2,30],"94":[2,30],"96":[2,30],"101":[2,30],"102":[2,30],"105":[2,30],"107":[2,30],"108":[2,30],"109":[2,30],"113":[2,30],"121":[2,30],"124":[2,30],"126":[2,30],"130":[2,30],"131":[2,30],"133":[2,30],"134":[2,30],"137":[2,30],"138":[2,30],"139":[2,30],"140":[2,30],"141":[2,30],"142":[2,30],"144":[2,30]},{"8":181,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":182,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":183,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":184,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":185,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":186,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":187,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":188,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":189,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":190,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":191,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,152],"4":[2,152],"29":[2,152],"30":[2,152],"47":[2,152],"55":[2,152],"59":[2,152],"75":[2,152],"80":[2,152],"90":[2,152],"94":[2,152],"96":[2,152],"105":[2,152],"107":[2,152],"108":[2,152],"109":[2,152],"113":[2,152],"121":[2,152],"130":[2,152],"131":[2,152],"133":[2,152],"134":[2,152],"137":[2,152],"138":[2,152],"139":[2,152],"140":[2,152],"141":[2,152],"142":[2,152],"144":[2,152]},{"1":[2,157],"4":[2,157],"29":[2,157],"30":[2,157],"47":[2,157],"55":[2,157],"59":[2,157],"75":[2,157],"80":[2,157],"90":[2,157],"94":[2,157],"96":[2,157],"105":[2,157],"107":[2,157],"108":[2,157],"109":[2,157],"113":[2,157],"121":[2,157],"130":[2,157],"131":[2,157],"133":[2,157],"134":[2,157],"137":[2,157],"138":[2,157],"139":[2,157],"140":[2,157],"141":[2,157],"142":[2,157],"144":[2,157]},{"1":[2,52],"4":[2,52],"29":[2,52],"30":[2,52],"47":[2,52],"55":[2,52],"59":[2,52],"75":[2,52],"80":[2,52],"90":[2,52],"94":[2,52],"96":[2,52],"105":[2,52],"107":[2,52],"108":[2,52],"109":[2,52],"113":[2,52],"121":[2,52],"130":[2,52],"131":[2,52],"133":[2,52],"134":[2,52],"137":[2,52],"138":[2,52],"139":[2,52],"140":[2,52],"141":[2,52],"142":[2,52],"144":[2,52]},{"8":192,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":193,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,151],"4":[2,151],"29":[2,151],"30":[2,151],"47":[2,151],"55":[2,151],"59":[2,151],"75":[2,151],"80":[2,151],"90":[2,151],"94":[2,151],"96":[2,151],"105":[2,151],"107":[2,151],"108":[2,151],"109":[2,151],"113":[2,151],"121":[2,151],"130":[2,151],"131":[2,151],"133":[2,151],"134":[2,151],"137":[2,151],"138":[2,151],"139":[2,151],"140":[2,151],"141":[2,151],"142":[2,151],"144":[2,151]},{"1":[2,156],"4":[2,156],"29":[2,156],"30":[2,156],"47":[2,156],"55":[2,156],"59":[2,156],"75":[2,156],"80":[2,156],"90":[2,156],"94":[2,156],"96":[2,156],"105":[2,156],"107":[2,156],"108":[2,156],"109":[2,156],"113":[2,156],"121":[2,156],"130":[2,156],"131":[2,156],"133":[2,156],"134":[2,156],"137":[2,156],"138":[2,156],"139":[2,156],"140":[2,156],"141":[2,156],"142":[2,156],"144":[2,156]},{"86":194,"89":[1,116]},{"1":[2,68],"4":[2,68],"29":[2,68],"30":[2,68],"41":[2,68],"47":[2,68],"55":[2,68],"59":[2,68],"68":[2,68],"69":[2,68],"70":[2,68],"71":[2,68],"74":[2,68],"75":[2,68],"76":[2,68],"77":[2,68],"80":[2,68],"82":[2,68],"88":[2,68],"89":[2,68],"90":[2,68],"94":[2,68],"96":[2,68],"105":[2,68],"107":[2,68],"108":[2,68],"109":[2,68],"113":[2,68],"121":[2,68],"130":[2,68],"131":[2,68],"133":[2,68],"134":[2,68],"135":[2,68],"136":[2,68],"137":[2,68],"138":[2,68],"139":[2,68],"140":[2,68],"141":[2,68],"142":[2,68],"143":[2,68],"144":[2,68]},{"89":[2,115]},{"31":195,"32":[1,76]},{"31":196,"32":[1,76]},{"1":[2,81],"4":[2,81],"29":[2,81],"30":[2,81],"41":[2,81],"47":[2,81],"55":[2,81],"59":[2,81],"68":[2,81],"69":[2,81],"70":[2,81],"71":[2,81],"74":[2,81],"75":[2,81],"76":[2,81],"77":[2,81],"80":[2,81],"82":[2,81],"88":[2,81],"89":[2,81],"90":[2,81],"94":[2,81],"96":[2,81],"105":[2,81],"107":[2,81],"108":[2,81],"109":[2,81],"113":[2,81],"121":[2,81],"130":[2,81],"131":[2,81],"133":[2,81],"134":[2,81],"135":[2,81],"136":[2,81],"137":[2,81],"138":[2,81],"139":[2,81],"140":[2,81],"141":[2,81],"142":[2,81],"143":[2,81],"144":[2,81]},{"31":197,"32":[1,76]},{"1":[2,83],"4":[2,83],"29":[2,83],"30":[2,83],"41":[2,83],"47":[2,83],"55":[2,83],"59":[2,83],"68":[2,83],"69":[2,83],"70":[2,83],"71":[2,83],"74":[2,83],"75":[2,83],"76":[2,83],"77":[2,83],"80":[2,83],"82":[2,83],"88":[2,83],"89":[2,83],"90":[2,83],"94":[2,83],"96":[2,83],"105":[2,83],"107":[2,83],"108":[2,83],"109":[2,83],"113":[2,83],"121":[2,83],"130":[2,83],"131":[2,83],"133":[2,83],"134":[2,83],"135":[2,83],"136":[2,83],"137":[2,83],"138":[2,83],"139":[2,83],"140":[2,83],"141":[2,83],"142":[2,83],"143":[2,83],"144":[2,83]},{"1":[2,84],"4":[2,84],"29":[2,84],"30":[2,84],"41":[2,84],"47":[2,84],"55":[2,84],"59":[2,84],"68":[2,84],"69":[2,84],"70":[2,84],"71":[2,84],"74":[2,84],"75":[2,84],"76":[2,84],"77":[2,84],"80":[2,84],"82":[2,84],"88":[2,84],"89":[2,84],"90":[2,84],"94":[2,84],"96":[2,84],"105":[2,84],"107":[2,84],"108":[2,84],"109":[2,84],"113":[2,84],"121":[2,84],"130":[2,84],"131":[2,84],"133":[2,84],"134":[2,84],"135":[2,84],"136":[2,84],"137":[2,84],"138":[2,84],"139":[2,84],"140":[2,84],"141":[2,84],"142":[2,84],"143":[2,84],"144":[2,84]},{"8":198,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"59":[1,201],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"93":199,"94":[1,200],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"72":202,"74":[1,203],"76":[1,110],"77":[1,111]},{"72":204,"74":[1,203],"76":[1,110],"77":[1,111]},{"86":205,"89":[1,116]},{"1":[2,69],"4":[2,69],"29":[2,69],"30":[2,69],"41":[2,69],"47":[2,69],"55":[2,69],"59":[2,69],"68":[2,69],"69":[2,69],"70":[2,69],"71":[2,69],"74":[2,69],"75":[2,69],"76":[2,69],"77":[2,69],"80":[2,69],"82":[2,69],"88":[2,69],"89":[2,69],"90":[2,69],"94":[2,69],"96":[2,69],"105":[2,69],"107":[2,69],"108":[2,69],"109":[2,69],"113":[2,69],"121":[2,69],"130":[2,69],"131":[2,69],"133":[2,69],"134":[2,69],"135":[2,69],"136":[2,69],"137":[2,69],"138":[2,69],"139":[2,69],"140":[2,69],"141":[2,69],"142":[2,69],"143":[2,69],"144":[2,69]},{"8":206,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,207],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,113],"4":[2,113],"29":[2,113],"30":[2,113],"47":[2,113],"55":[2,113],"59":[2,113],"68":[2,113],"69":[2,113],"70":[2,113],"71":[2,113],"74":[2,113],"75":[2,113],"76":[2,113],"77":[2,113],"80":[2,113],"88":[2,113],"89":[2,113],"90":[2,113],"94":[2,113],"96":[2,113],"105":[2,113],"107":[2,113],"108":[2,113],"109":[2,113],"113":[2,113],"121":[2,113],"130":[2,113],"131":[2,113],"133":[2,113],"134":[2,113],"137":[2,113],"138":[2,113],"139":[2,113],"140":[2,113],"141":[2,113],"142":[2,113],"144":[2,113]},{"8":210,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"90":[1,208],"91":209,"92":[1,60],"95":[1,59],"97":152,"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"50":[1,211],"55":[1,212]},{"50":[2,60],"55":[2,60]},{"50":[2,62],"55":[2,62],"59":[1,213]},{"57":[1,214]},{"1":[2,54],"4":[2,54],"29":[2,54],"30":[2,54],"47":[2,54],"55":[2,54],"59":[2,54],"75":[2,54],"80":[2,54],"90":[2,54],"94":[2,54],"96":[2,54],"105":[2,54],"107":[2,54],"108":[2,54],"109":[2,54],"113":[2,54],"121":[2,54],"130":[2,54],"131":[2,54],"133":[2,54],"134":[2,54],"137":[2,54],"138":[2,54],"139":[2,54],"140":[2,54],"141":[2,54],"142":[2,54],"144":[2,54]},{"28":77,"46":[1,49]},{"1":[2,192],"4":[2,192],"29":[2,192],"30":[2,192],"47":[1,95],"55":[2,192],"59":[2,192],"75":[2,192],"80":[2,192],"90":[2,192],"94":[2,192],"96":[2,192],"105":[2,192],"106":93,"107":[2,192],"108":[2,192],"109":[2,192],"112":94,"113":[2,192],"114":72,"121":[2,192],"130":[2,192],"131":[2,192],"133":[2,192],"134":[2,192],"137":[2,192],"138":[2,192],"139":[2,192],"140":[2,192],"141":[2,192],"142":[2,192],"144":[2,192]},{"106":98,"107":[1,68],"109":[1,69],"112":99,"113":[1,71],"114":72,"130":[1,96],"131":[1,97]},{"1":[2,193],"4":[2,193],"29":[2,193],"30":[2,193],"47":[1,95],"55":[2,193],"59":[2,193],"75":[2,193],"80":[2,193],"90":[2,193],"94":[2,193],"96":[2,193],"105":[2,193],"106":93,"107":[2,193],"108":[2,193],"109":[2,193],"112":94,"113":[2,193],"114":72,"121":[2,193],"130":[2,193],"131":[2,193],"133":[2,193],"134":[2,193],"137":[2,193],"138":[2,193],"139":[2,193],"140":[2,193],"141":[2,193],"142":[2,193],"144":[2,193]},{"1":[2,194],"4":[2,194],"29":[2,194],"30":[2,194],"47":[1,95],"55":[2,194],"59":[2,194],"75":[2,194],"80":[2,194],"90":[2,194],"94":[2,194],"96":[2,194],"105":[2,194],"106":93,"107":[2,194],"108":[2,194],"109":[2,194],"112":94,"113":[2,194],"114":72,"121":[2,194],"130":[2,194],"131":[2,194],"133":[2,194],"134":[2,194],"137":[2,194],"138":[2,194],"139":[2,194],"140":[2,194],"141":[2,194],"142":[2,194],"144":[2,194]},{"1":[2,195],"4":[2,195],"29":[2,195],"30":[2,195],"47":[2,195],"55":[2,195],"59":[2,195],"68":[2,71],"69":[2,71],"70":[2,71],"71":[2,71],"74":[2,71],"75":[2,195],"76":[2,71],"77":[2,71],"80":[2,195],"88":[2,71],"89":[2,71],"90":[2,195],"94":[2,195],"96":[2,195],"105":[2,195],"107":[2,195],"108":[2,195],"109":[2,195],"113":[2,195],"121":[2,195],"130":[2,195],"131":[2,195],"133":[2,195],"134":[2,195],"137":[2,195],"138":[2,195],"139":[2,195],"140":[2,195],"141":[2,195],"142":[2,195],"144":[2,195]},{"62":101,"68":[1,103],"69":[1,104],"70":[1,105],"71":[1,106],"72":107,"73":108,"74":[1,109],"76":[1,110],"77":[1,111],"85":100,"88":[1,102],"89":[2,114]},{"62":113,"68":[1,103],"69":[1,104],"70":[1,105],"71":[1,106],"72":107,"73":108,"74":[1,109],"76":[1,110],"77":[1,111],"85":112,"88":[1,102],"89":[2,114]},{"1":[2,74],"4":[2,74],"29":[2,74],"30":[2,74],"47":[2,74],"55":[2,74],"59":[2,74],"68":[2,74],"69":[2,74],"70":[2,74],"71":[2,74],"74":[2,74],"75":[2,74],"76":[2,74],"77":[2,74],"80":[2,74],"88":[2,74],"89":[2,74],"90":[2,74],"94":[2,74],"96":[2,74],"105":[2,74],"107":[2,74],"108":[2,74],"109":[2,74],"113":[2,74],"121":[2,74],"130":[2,74],"131":[2,74],"133":[2,74],"134":[2,74],"137":[2,74],"138":[2,74],"139":[2,74],"140":[2,74],"141":[2,74],"142":[2,74],"144":[2,74]},{"1":[2,196],"4":[2,196],"29":[2,196],"30":[2,196],"47":[2,196],"55":[2,196],"59":[2,196],"68":[2,71],"69":[2,71],"70":[2,71],"71":[2,71],"74":[2,71],"75":[2,196],"76":[2,71],"77":[2,71],"80":[2,196],"88":[2,71],"89":[2,71],"90":[2,196],"94":[2,196],"96":[2,196],"105":[2,196],"107":[2,196],"108":[2,196],"109":[2,196],"113":[2,196],"121":[2,196],"130":[2,196],"131":[2,196],"133":[2,196],"134":[2,196],"137":[2,196],"138":[2,196],"139":[2,196],"140":[2,196],"141":[2,196],"142":[2,196],"144":[2,196]},{"1":[2,197],"4":[2,197],"29":[2,197],"30":[2,197],"47":[2,197],"55":[2,197],"59":[2,197],"75":[2,197],"80":[2,197],"90":[2,197],"94":[2,197],"96":[2,197],"105":[2,197],"107":[2,197],"108":[2,197],"109":[2,197],"113":[2,197],"121":[2,197],"130":[2,197],"131":[2,197],"133":[2,197],"134":[2,197],"137":[2,197],"138":[2,197],"139":[2,197],"140":[2,197],"141":[2,197],"142":[2,197],"144":[2,197]},{"1":[2,198],"4":[2,198],"29":[2,198],"30":[2,198],"47":[2,198],"55":[2,198],"59":[2,198],"75":[2,198],"80":[2,198],"90":[2,198],"94":[2,198],"96":[2,198],"105":[2,198],"107":[2,198],"108":[2,198],"109":[2,198],"113":[2,198],"121":[2,198],"130":[2,198],"131":[2,198],"133":[2,198],"134":[2,198],"137":[2,198],"138":[2,198],"139":[2,198],"140":[2,198],"141":[2,198],"142":[2,198],"144":[2,198]},{"8":215,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,216],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"15":217,"16":129,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":130,"43":65,"58":[1,61],"61":218,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"87":[1,33],"92":[1,60],"95":[1,59],"104":[1,58]},{"4":[1,122],"6":220,"29":[1,6],"128":[1,219]},{"1":[2,138],"4":[2,138],"29":[2,138],"30":[2,138],"47":[2,138],"55":[2,138],"59":[2,138],"75":[2,138],"80":[2,138],"90":[2,138],"94":[2,138],"96":[2,138],"100":221,"101":[1,222],"102":[1,223],"105":[2,138],"107":[2,138],"108":[2,138],"109":[2,138],"113":[2,138],"121":[2,138],"130":[2,138],"131":[2,138],"133":[2,138],"134":[2,138],"137":[2,138],"138":[2,138],"139":[2,138],"140":[2,138],"141":[2,138],"142":[2,138],"144":[2,138]},{"1":[2,150],"4":[2,150],"29":[2,150],"30":[2,150],"47":[2,150],"55":[2,150],"59":[2,150],"75":[2,150],"80":[2,150],"90":[2,150],"94":[2,150],"96":[2,150],"105":[2,150],"107":[2,150],"108":[2,150],"109":[2,150],"113":[2,150],"121":[2,150],"130":[2,150],"131":[2,150],"133":[2,150],"134":[2,150],"137":[2,150],"138":[2,150],"139":[2,150],"140":[2,150],"141":[2,150],"142":[2,150],"144":[2,150]},{"1":[2,158],"4":[2,158],"29":[2,158],"30":[2,158],"47":[2,158],"55":[2,158],"59":[2,158],"75":[2,158],"80":[2,158],"90":[2,158],"94":[2,158],"96":[2,158],"105":[2,158],"107":[2,158],"108":[2,158],"109":[2,158],"113":[2,158],"121":[2,158],"130":[2,158],"131":[2,158],"133":[2,158],"134":[2,158],"137":[2,158],"138":[2,158],"139":[2,158],"140":[2,158],"141":[2,158],"142":[2,158],"144":[2,158]},{"29":[1,224],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"123":225,"125":226,"126":[1,227]},{"1":[2,94],"4":[2,94],"29":[1,229],"30":[2,94],"47":[2,94],"55":[2,94],"59":[2,94],"68":[2,71],"69":[2,71],"70":[2,71],"71":[2,71],"74":[2,71],"75":[2,94],"76":[2,71],"77":[2,71],"80":[2,94],"82":[1,228],"88":[2,71],"89":[2,71],"90":[2,94],"94":[2,94],"96":[2,94],"105":[2,94],"107":[2,94],"108":[2,94],"109":[2,94],"113":[2,94],"121":[2,94],"130":[2,94],"131":[2,94],"133":[2,94],"134":[2,94],"137":[2,94],"138":[2,94],"139":[2,94],"140":[2,94],"141":[2,94],"142":[2,94],"144":[2,94]},{"4":[2,105],"28":177,"30":[2,105],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"83":230,"84":231},{"15":235,"16":129,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":130,"43":65,"58":[1,61],"61":218,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"87":[1,33],"92":[1,60],"95":[1,59],"104":[1,58]},{"1":[2,49],"4":[2,49],"30":[2,49],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[2,49],"131":[2,49],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,143],"4":[2,143],"30":[2,143],"47":[1,95],"106":93,"107":[2,143],"109":[2,143],"112":94,"113":[2,143],"114":72,"130":[2,143],"131":[2,143],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"47":[1,95],"105":[1,236],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,145],"4":[2,145],"29":[2,145],"30":[2,145],"47":[2,145],"55":[2,145],"59":[2,145],"68":[2,145],"69":[2,145],"70":[2,145],"71":[2,145],"74":[2,145],"75":[2,145],"76":[2,145],"77":[2,145],"80":[2,145],"88":[2,145],"89":[2,145],"90":[2,145],"94":[2,145],"96":[2,145],"105":[2,145],"107":[2,145],"108":[2,145],"109":[2,145],"113":[2,145],"121":[2,145],"130":[2,145],"131":[2,145],"133":[2,145],"134":[2,145],"137":[2,145],"138":[2,145],"139":[2,145],"140":[2,145],"141":[2,145],"142":[2,145],"144":[2,145]},{"4":[2,134],"29":[2,134],"47":[1,95],"55":[2,134],"59":[1,238],"93":237,"94":[1,200],"96":[2,134],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,127],"4":[2,127],"29":[2,127],"30":[2,127],"41":[2,127],"47":[2,127],"55":[2,127],"59":[2,127],"68":[2,127],"69":[2,127],"70":[2,127],"71":[2,127],"74":[2,127],"75":[2,127],"76":[2,127],"77":[2,127],"80":[2,127],"88":[2,127],"89":[2,127],"90":[2,127],"94":[2,127],"96":[2,127],"105":[2,127],"107":[2,127],"108":[2,127],"109":[2,127],"113":[2,127],"119":[2,127],"120":[2,127],"121":[2,127],"130":[2,127],"131":[2,127],"133":[2,127],"134":[2,127],"137":[2,127],"138":[2,127],"139":[2,127],"140":[2,127],"141":[2,127],"142":[2,127],"144":[2,127]},{"4":[2,57],"29":[2,57],"54":239,"55":[1,240],"96":[2,57]},{"4":[2,129],"29":[2,129],"30":[2,129],"55":[2,129],"90":[2,129],"96":[2,129]},{"8":210,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"91":241,"92":[1,60],"95":[1,59],"97":152,"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,135],"29":[2,135],"30":[2,135],"55":[2,135],"90":[2,135],"96":[2,135]},{"1":[2,122],"4":[2,122],"29":[2,122],"30":[2,122],"41":[2,122],"44":[2,122],"47":[2,122],"55":[2,122],"59":[2,122],"68":[2,122],"69":[2,122],"70":[2,122],"71":[2,122],"74":[2,122],"75":[2,122],"76":[2,122],"77":[2,122],"80":[2,122],"82":[2,122],"88":[2,122],"89":[2,122],"90":[2,122],"94":[2,122],"96":[2,122],"105":[2,122],"107":[2,122],"108":[2,122],"109":[2,122],"113":[2,122],"121":[2,122],"130":[2,122],"131":[2,122],"133":[2,122],"134":[2,122],"135":[2,122],"136":[2,122],"137":[2,122],"138":[2,122],"139":[2,122],"140":[2,122],"141":[2,122],"142":[2,122],"143":[2,122],"144":[2,122]},{"4":[1,122],"6":242,"29":[1,6],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"4":[1,122],"6":243,"29":[1,6],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,146],"4":[2,146],"29":[2,146],"30":[2,146],"47":[1,95],"55":[2,146],"59":[2,146],"75":[2,146],"80":[2,146],"90":[2,146],"94":[2,146],"96":[2,146],"105":[2,146],"106":93,"107":[1,68],"108":[1,244],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,146],"130":[2,146],"131":[2,146],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,148],"4":[2,148],"29":[2,148],"30":[2,148],"47":[1,95],"55":[2,148],"59":[2,148],"75":[2,148],"80":[2,148],"90":[2,148],"94":[2,148],"96":[2,148],"105":[2,148],"106":93,"107":[1,68],"108":[1,245],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,148],"130":[2,148],"131":[2,148],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,154],"4":[2,154],"29":[2,154],"30":[2,154],"47":[2,154],"55":[2,154],"59":[2,154],"75":[2,154],"80":[2,154],"90":[2,154],"94":[2,154],"96":[2,154],"105":[2,154],"107":[2,154],"108":[2,154],"109":[2,154],"113":[2,154],"121":[2,154],"130":[2,154],"131":[2,154],"133":[2,154],"134":[2,154],"137":[2,154],"138":[2,154],"139":[2,154],"140":[2,154],"141":[2,154],"142":[2,154],"144":[2,154]},{"1":[2,155],"4":[2,155],"29":[2,155],"30":[2,155],"47":[1,95],"55":[2,155],"59":[2,155],"75":[2,155],"80":[2,155],"90":[2,155],"94":[2,155],"96":[2,155],"105":[2,155],"106":93,"107":[1,68],"108":[2,155],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,155],"130":[2,155],"131":[2,155],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,159],"4":[2,159],"29":[2,159],"30":[2,159],"47":[2,159],"55":[2,159],"59":[2,159],"75":[2,159],"80":[2,159],"90":[2,159],"94":[2,159],"96":[2,159],"105":[2,159],"107":[2,159],"108":[2,159],"109":[2,159],"113":[2,159],"121":[2,159],"130":[2,159],"131":[2,159],"133":[2,159],"134":[2,159],"137":[2,159],"138":[2,159],"139":[2,159],"140":[2,159],"141":[2,159],"142":[2,159],"144":[2,159]},{"119":[2,161],"120":[2,161]},{"31":166,"32":[1,76],"63":167,"64":168,"78":[1,73],"95":[1,247],"116":246,"118":165},{"55":[1,248],"119":[2,166],"120":[2,166]},{"55":[2,163],"119":[2,163],"120":[2,163]},{"55":[2,164],"119":[2,164],"120":[2,164]},{"55":[2,165],"119":[2,165],"120":[2,165]},{"1":[2,160],"4":[2,160],"29":[2,160],"30":[2,160],"47":[2,160],"55":[2,160],"59":[2,160],"75":[2,160],"80":[2,160],"90":[2,160],"94":[2,160],"96":[2,160],"105":[2,160],"107":[2,160],"108":[2,160],"109":[2,160],"113":[2,160],"121":[2,160],"130":[2,160],"131":[2,160],"133":[2,160],"134":[2,160],"137":[2,160],"138":[2,160],"139":[2,160],"140":[2,160],"141":[2,160],"142":[2,160],"144":[2,160]},{"8":249,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":250,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,57],"29":[2,57],"54":251,"55":[1,252],"80":[2,57]},{"4":[2,90],"29":[2,90],"30":[2,90],"55":[2,90],"80":[2,90]},{"4":[2,41],"29":[2,41],"30":[2,41],"44":[1,253],"55":[2,41],"80":[2,41]},{"4":[2,42],"29":[2,42],"30":[2,42],"44":[1,254],"55":[2,42],"80":[2,42]},{"4":[2,43],"29":[2,43],"30":[2,43],"55":[2,43],"80":[2,43]},{"4":[2,48],"29":[2,48],"30":[2,48],"55":[2,48],"80":[2,48]},{"31":155,"32":[1,76]},{"1":[2,6],"4":[2,6],"30":[2,6]},{"1":[2,29],"4":[2,29],"29":[2,29],"30":[2,29],"47":[2,29],"55":[2,29],"59":[2,29],"75":[2,29],"80":[2,29],"90":[2,29],"94":[2,29],"96":[2,29],"101":[2,29],"102":[2,29],"105":[2,29],"107":[2,29],"108":[2,29],"109":[2,29],"113":[2,29],"121":[2,29],"124":[2,29],"126":[2,29],"130":[2,29],"131":[2,29],"133":[2,29],"134":[2,29],"137":[2,29],"138":[2,29],"139":[2,29],"140":[2,29],"141":[2,29],"142":[2,29],"144":[2,29]},{"1":[2,199],"4":[2,199],"29":[2,199],"30":[2,199],"47":[1,95],"55":[2,199],"59":[2,199],"75":[2,199],"80":[2,199],"90":[2,199],"94":[2,199],"96":[2,199],"105":[2,199],"106":93,"107":[2,199],"108":[2,199],"109":[2,199],"112":94,"113":[2,199],"114":72,"121":[2,199],"130":[2,199],"131":[2,199],"133":[2,199],"134":[2,199],"137":[2,199],"138":[2,199],"139":[1,86],"140":[2,199],"141":[2,199],"142":[2,199],"144":[2,199]},{"1":[2,200],"4":[2,200],"29":[2,200],"30":[2,200],"47":[1,95],"55":[2,200],"59":[2,200],"75":[2,200],"80":[2,200],"90":[2,200],"94":[2,200],"96":[2,200],"105":[2,200],"106":93,"107":[2,200],"108":[2,200],"109":[2,200],"112":94,"113":[2,200],"114":72,"121":[2,200],"130":[2,200],"131":[2,200],"133":[2,200],"134":[2,200],"137":[2,200],"138":[2,200],"139":[1,86],"140":[2,200],"141":[2,200],"142":[2,200],"144":[2,200]},{"1":[2,201],"4":[2,201],"29":[2,201],"30":[2,201],"47":[1,95],"55":[2,201],"59":[2,201],"75":[2,201],"80":[2,201],"90":[2,201],"94":[2,201],"96":[2,201],"105":[2,201],"106":93,"107":[2,201],"108":[2,201],"109":[2,201],"112":94,"113":[2,201],"114":72,"121":[2,201],"130":[2,201],"131":[2,201],"133":[1,83],"134":[1,82],"137":[2,201],"138":[2,201],"139":[1,86],"140":[1,87],"141":[1,88],"142":[2,201],"144":[1,90]},{"1":[2,202],"4":[2,202],"29":[2,202],"30":[2,202],"47":[1,95],"55":[2,202],"59":[2,202],"75":[2,202],"80":[2,202],"90":[2,202],"94":[2,202],"96":[2,202],"105":[2,202],"106":93,"107":[2,202],"108":[2,202],"109":[2,202],"112":94,"113":[2,202],"114":72,"121":[2,202],"130":[2,202],"131":[2,202],"133":[1,83],"134":[1,82],"137":[2,202],"138":[2,202],"139":[1,86],"140":[1,87],"141":[1,88],"142":[2,202],"144":[1,90]},{"1":[2,203],"4":[2,203],"29":[2,203],"30":[2,203],"47":[1,95],"55":[2,203],"59":[2,203],"75":[2,203],"80":[2,203],"90":[2,203],"94":[2,203],"96":[2,203],"105":[2,203],"106":93,"107":[2,203],"108":[2,203],"109":[2,203],"112":94,"113":[2,203],"114":72,"121":[2,203],"130":[2,203],"131":[2,203],"133":[2,203],"134":[2,203],"137":[2,203],"138":[2,203],"139":[2,203],"140":[2,203],"141":[2,203],"142":[2,203],"144":[2,203]},{"1":[2,204],"4":[2,204],"29":[2,204],"30":[2,204],"47":[1,95],"55":[2,204],"59":[2,204],"75":[2,204],"80":[2,204],"90":[2,204],"94":[2,204],"96":[2,204],"105":[2,204],"106":93,"107":[2,204],"108":[2,204],"109":[2,204],"112":94,"113":[2,204],"114":72,"121":[2,204],"130":[2,204],"131":[2,204],"133":[1,83],"134":[1,82],"137":[2,204],"138":[2,204],"139":[1,86],"140":[2,204],"141":[2,204],"142":[2,204],"144":[2,204]},{"1":[2,205],"4":[2,205],"29":[2,205],"30":[2,205],"47":[1,95],"55":[2,205],"59":[2,205],"75":[2,205],"80":[2,205],"90":[2,205],"94":[2,205],"96":[2,205],"105":[2,205],"106":93,"107":[2,205],"108":[2,205],"109":[2,205],"112":94,"113":[2,205],"114":72,"121":[2,205],"130":[2,205],"131":[2,205],"133":[1,83],"134":[1,82],"137":[2,205],"138":[2,205],"139":[1,86],"140":[1,87],"141":[2,205],"142":[2,205],"144":[2,205]},{"1":[2,206],"4":[2,206],"29":[2,206],"30":[2,206],"47":[1,95],"55":[2,206],"59":[2,206],"75":[2,206],"80":[2,206],"90":[2,206],"94":[2,206],"96":[2,206],"105":[2,206],"106":93,"107":[2,206],"108":[2,206],"109":[2,206],"112":94,"113":[2,206],"114":72,"121":[2,206],"130":[2,206],"131":[2,206],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[2,206],"144":[1,90]},{"1":[2,209],"4":[2,209],"29":[2,209],"30":[2,209],"47":[1,95],"55":[2,209],"59":[2,209],"75":[2,209],"80":[2,209],"90":[2,209],"94":[2,209],"96":[2,209],"105":[2,209],"106":93,"107":[2,209],"108":[2,209],"109":[2,209],"112":94,"113":[2,209],"114":72,"121":[2,209],"130":[2,209],"131":[2,209],"133":[1,83],"134":[1,82],"137":[2,209],"138":[2,209],"139":[1,86],"140":[1,87],"141":[1,88],"142":[2,209],"144":[2,209]},{"1":[2,189],"4":[2,189],"29":[2,189],"30":[2,189],"47":[1,95],"55":[2,189],"59":[2,189],"75":[2,189],"80":[2,189],"90":[2,189],"94":[2,189],"96":[2,189],"105":[2,189],"106":93,"107":[1,68],"108":[2,189],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,189],"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,191],"4":[2,191],"29":[2,191],"30":[2,191],"47":[1,95],"55":[2,191],"59":[2,191],"75":[2,191],"80":[2,191],"90":[2,191],"94":[2,191],"96":[2,191],"105":[2,191],"106":93,"107":[1,68],"108":[2,191],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,191],"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,188],"4":[2,188],"29":[2,188],"30":[2,188],"47":[1,95],"55":[2,188],"59":[2,188],"75":[2,188],"80":[2,188],"90":[2,188],"94":[2,188],"96":[2,188],"105":[2,188],"106":93,"107":[1,68],"108":[2,188],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,188],"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,190],"4":[2,190],"29":[2,190],"30":[2,190],"47":[1,95],"55":[2,190],"59":[2,190],"75":[2,190],"80":[2,190],"90":[2,190],"94":[2,190],"96":[2,190],"105":[2,190],"106":93,"107":[1,68],"108":[2,190],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,190],"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,110],"4":[2,110],"29":[2,110],"30":[2,110],"47":[2,110],"55":[2,110],"59":[2,110],"68":[2,110],"69":[2,110],"70":[2,110],"71":[2,110],"74":[2,110],"75":[2,110],"76":[2,110],"77":[2,110],"80":[2,110],"88":[2,110],"89":[2,110],"90":[2,110],"94":[2,110],"96":[2,110],"105":[2,110],"107":[2,110],"108":[2,110],"109":[2,110],"113":[2,110],"121":[2,110],"130":[2,110],"131":[2,110],"133":[2,110],"134":[2,110],"137":[2,110],"138":[2,110],"139":[2,110],"140":[2,110],"141":[2,110],"142":[2,110],"144":[2,110]},{"1":[2,79],"4":[2,79],"29":[2,79],"30":[2,79],"41":[2,79],"47":[2,79],"55":[2,79],"59":[2,79],"68":[2,79],"69":[2,79],"70":[2,79],"71":[2,79],"74":[2,79],"75":[2,79],"76":[2,79],"77":[2,79],"80":[2,79],"82":[2,79],"88":[2,79],"89":[2,79],"90":[2,79],"94":[2,79],"96":[2,79],"105":[2,79],"107":[2,79],"108":[2,79],"109":[2,79],"113":[2,79],"121":[2,79],"130":[2,79],"131":[2,79],"133":[2,79],"134":[2,79],"135":[2,79],"136":[2,79],"137":[2,79],"138":[2,79],"139":[2,79],"140":[2,79],"141":[2,79],"142":[2,79],"143":[2,79],"144":[2,79]},{"1":[2,80],"4":[2,80],"29":[2,80],"30":[2,80],"41":[2,80],"47":[2,80],"55":[2,80],"59":[2,80],"68":[2,80],"69":[2,80],"70":[2,80],"71":[2,80],"74":[2,80],"75":[2,80],"76":[2,80],"77":[2,80],"80":[2,80],"82":[2,80],"88":[2,80],"89":[2,80],"90":[2,80],"94":[2,80],"96":[2,80],"105":[2,80],"107":[2,80],"108":[2,80],"109":[2,80],"113":[2,80],"121":[2,80],"130":[2,80],"131":[2,80],"133":[2,80],"134":[2,80],"135":[2,80],"136":[2,80],"137":[2,80],"138":[2,80],"139":[2,80],"140":[2,80],"141":[2,80],"142":[2,80],"143":[2,80],"144":[2,80]},{"1":[2,82],"4":[2,82],"29":[2,82],"30":[2,82],"41":[2,82],"47":[2,82],"55":[2,82],"59":[2,82],"68":[2,82],"69":[2,82],"70":[2,82],"71":[2,82],"74":[2,82],"75":[2,82],"76":[2,82],"77":[2,82],"80":[2,82],"82":[2,82],"88":[2,82],"89":[2,82],"90":[2,82],"94":[2,82],"96":[2,82],"105":[2,82],"107":[2,82],"108":[2,82],"109":[2,82],"113":[2,82],"121":[2,82],"130":[2,82],"131":[2,82],"133":[2,82],"134":[2,82],"135":[2,82],"136":[2,82],"137":[2,82],"138":[2,82],"139":[2,82],"140":[2,82],"141":[2,82],"142":[2,82],"143":[2,82],"144":[2,82]},{"47":[1,95],"59":[1,201],"75":[1,255],"93":256,"94":[1,200],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"8":257,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"12":[2,120],"13":[2,120],"14":[2,120],"32":[2,120],"34":[2,120],"35":[2,120],"37":[2,120],"38":[2,120],"39":[2,120],"45":[2,120],"46":[2,120],"48":[2,120],"52":[2,120],"53":[2,120],"58":[2,120],"75":[2,120],"78":[2,120],"81":[2,120],"87":[2,120],"92":[2,120],"95":[2,120],"99":[2,120],"103":[2,120],"104":[2,120],"107":[2,120],"109":[2,120],"111":[2,120],"113":[2,120],"122":[2,120],"128":[2,120],"129":[2,120],"132":[2,120],"133":[2,120],"134":[2,120],"135":[2,120],"136":[2,120]},{"12":[2,121],"13":[2,121],"14":[2,121],"32":[2,121],"34":[2,121],"35":[2,121],"37":[2,121],"38":[2,121],"39":[2,121],"45":[2,121],"46":[2,121],"48":[2,121],"52":[2,121],"53":[2,121],"58":[2,121],"75":[2,121],"78":[2,121],"81":[2,121],"87":[2,121],"92":[2,121],"95":[2,121],"99":[2,121],"103":[2,121],"104":[2,121],"107":[2,121],"109":[2,121],"111":[2,121],"113":[2,121],"122":[2,121],"128":[2,121],"129":[2,121],"132":[2,121],"133":[2,121],"134":[2,121],"135":[2,121],"136":[2,121]},{"1":[2,86],"4":[2,86],"29":[2,86],"30":[2,86],"41":[2,86],"47":[2,86],"55":[2,86],"59":[2,86],"68":[2,86],"69":[2,86],"70":[2,86],"71":[2,86],"74":[2,86],"75":[2,86],"76":[2,86],"77":[2,86],"80":[2,86],"82":[2,86],"88":[2,86],"89":[2,86],"90":[2,86],"94":[2,86],"96":[2,86],"105":[2,86],"107":[2,86],"108":[2,86],"109":[2,86],"113":[2,86],"121":[2,86],"130":[2,86],"131":[2,86],"133":[2,86],"134":[2,86],"135":[2,86],"136":[2,86],"137":[2,86],"138":[2,86],"139":[2,86],"140":[2,86],"141":[2,86],"142":[2,86],"143":[2,86],"144":[2,86]},{"8":258,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,87],"4":[2,87],"29":[2,87],"30":[2,87],"41":[2,87],"47":[2,87],"55":[2,87],"59":[2,87],"68":[2,87],"69":[2,87],"70":[2,87],"71":[2,87],"74":[2,87],"75":[2,87],"76":[2,87],"77":[2,87],"80":[2,87],"82":[2,87],"88":[2,87],"89":[2,87],"90":[2,87],"94":[2,87],"96":[2,87],"105":[2,87],"107":[2,87],"108":[2,87],"109":[2,87],"113":[2,87],"121":[2,87],"130":[2,87],"131":[2,87],"133":[2,87],"134":[2,87],"135":[2,87],"136":[2,87],"137":[2,87],"138":[2,87],"139":[2,87],"140":[2,87],"141":[2,87],"142":[2,87],"143":[2,87],"144":[2,87]},{"1":[2,111],"4":[2,111],"29":[2,111],"30":[2,111],"47":[2,111],"55":[2,111],"59":[2,111],"68":[2,111],"69":[2,111],"70":[2,111],"71":[2,111],"74":[2,111],"75":[2,111],"76":[2,111],"77":[2,111],"80":[2,111],"88":[2,111],"89":[2,111],"90":[2,111],"94":[2,111],"96":[2,111],"105":[2,111],"107":[2,111],"108":[2,111],"109":[2,111],"113":[2,111],"121":[2,111],"130":[2,111],"131":[2,111],"133":[2,111],"134":[2,111],"137":[2,111],"138":[2,111],"139":[2,111],"140":[2,111],"141":[2,111],"142":[2,111],"144":[2,111]},{"1":[2,39],"4":[2,39],"29":[2,39],"30":[2,39],"47":[1,95],"55":[2,39],"59":[2,39],"75":[2,39],"80":[2,39],"90":[2,39],"94":[2,39],"96":[2,39],"105":[2,39],"106":93,"107":[1,68],"108":[2,39],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,39],"130":[2,39],"131":[2,39],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"8":259,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,116],"4":[2,116],"29":[2,116],"30":[2,116],"47":[2,116],"55":[2,116],"59":[2,116],"68":[2,116],"69":[2,116],"70":[2,116],"71":[2,116],"74":[2,116],"75":[2,116],"76":[2,116],"77":[2,116],"80":[2,116],"88":[2,116],"89":[2,116],"90":[2,116],"94":[2,116],"96":[2,116],"105":[2,116],"107":[2,116],"108":[2,116],"109":[2,116],"113":[2,116],"121":[2,116],"130":[2,116],"131":[2,116],"133":[2,116],"134":[2,116],"137":[2,116],"138":[2,116],"139":[2,116],"140":[2,116],"141":[2,116],"142":[2,116],"144":[2,116]},{"4":[2,57],"29":[2,57],"54":260,"55":[1,240],"90":[2,57]},{"4":[2,134],"29":[2,134],"30":[2,134],"47":[1,95],"55":[2,134],"59":[1,261],"90":[2,134],"96":[2,134],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"51":262,"52":[1,62],"53":[1,63]},{"56":263,"57":[1,119],"58":[1,120]},{"50":[2,64],"55":[2,64]},{"50":[2,63],"55":[2,63],"59":[1,264]},{"1":[2,207],"4":[2,207],"29":[2,207],"30":[2,207],"47":[1,95],"55":[2,207],"59":[2,207],"75":[2,207],"80":[2,207],"90":[2,207],"94":[2,207],"96":[2,207],"105":[2,207],"106":93,"107":[2,207],"108":[2,207],"109":[2,207],"112":94,"113":[2,207],"114":72,"121":[2,207],"130":[2,207],"131":[2,207],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"8":265,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,109],"4":[2,109],"29":[2,109],"30":[2,109],"47":[2,109],"55":[2,109],"59":[2,109],"62":101,"68":[1,103],"69":[1,104],"70":[1,105],"71":[1,106],"72":107,"73":108,"74":[1,109],"75":[2,109],"76":[1,110],"77":[1,111],"80":[2,109],"85":100,"88":[1,102],"89":[2,114],"90":[2,109],"94":[2,109],"96":[2,109],"105":[2,109],"107":[2,109],"108":[2,109],"109":[2,109],"113":[2,109],"121":[2,109],"130":[2,109],"131":[2,109],"133":[2,109],"134":[2,109],"137":[2,109],"138":[2,109],"139":[2,109],"140":[2,109],"141":[2,109],"142":[2,109],"144":[2,109]},{"1":[2,71],"4":[2,71],"29":[2,71],"30":[2,71],"47":[2,71],"55":[2,71],"59":[2,71],"68":[2,71],"69":[2,71],"70":[2,71],"71":[2,71],"74":[2,71],"75":[2,71],"76":[2,71],"77":[2,71],"80":[2,71],"88":[2,71],"89":[2,71],"90":[2,71],"94":[2,71],"96":[2,71],"105":[2,71],"107":[2,71],"108":[2,71],"109":[2,71],"113":[2,71],"121":[2,71],"130":[2,71],"131":[2,71],"133":[2,71],"134":[2,71],"137":[2,71],"138":[2,71],"139":[2,71],"140":[2,71],"141":[2,71],"142":[2,71],"144":[2,71]},{"8":266,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,186],"4":[2,186],"29":[2,186],"30":[2,186],"47":[2,186],"55":[2,186],"59":[2,186],"75":[2,186],"80":[2,186],"90":[2,186],"94":[2,186],"96":[2,186],"105":[2,186],"107":[2,186],"108":[2,186],"109":[2,186],"113":[2,186],"121":[2,186],"124":[2,186],"130":[2,186],"131":[2,186],"133":[2,186],"134":[2,186],"137":[2,186],"138":[2,186],"139":[2,186],"140":[2,186],"141":[2,186],"142":[2,186],"144":[2,186]},{"1":[2,139],"4":[2,139],"29":[2,139],"30":[2,139],"47":[2,139],"55":[2,139],"59":[2,139],"75":[2,139],"80":[2,139],"90":[2,139],"94":[2,139],"96":[2,139],"101":[1,267],"105":[2,139],"107":[2,139],"108":[2,139],"109":[2,139],"113":[2,139],"121":[2,139],"130":[2,139],"131":[2,139],"133":[2,139],"134":[2,139],"137":[2,139],"138":[2,139],"139":[2,139],"140":[2,139],"141":[2,139],"142":[2,139],"144":[2,139]},{"4":[1,122],"6":268,"29":[1,6]},{"31":269,"32":[1,76]},{"123":270,"125":226,"126":[1,227]},{"30":[1,271],"124":[1,272],"125":273,"126":[1,227]},{"30":[2,179],"124":[2,179],"126":[2,179]},{"8":275,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"98":274,"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"15":276,"16":129,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":130,"43":65,"58":[1,61],"61":218,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"87":[1,33],"92":[1,60],"95":[1,59],"104":[1,58]},{"4":[2,105],"28":177,"30":[2,105],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"83":277,"84":231},{"4":[1,279],"30":[1,278]},{"4":[2,106],"30":[2,106],"80":[2,106]},{"4":[2,105],"28":177,"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"80":[2,105],"83":280,"84":231},{"4":[2,102],"30":[2,102],"80":[2,102]},{"4":[2,43],"30":[2,43],"44":[1,281],"80":[2,43]},{"1":[2,100],"4":[2,100],"29":[1,282],"30":[2,100],"47":[2,100],"55":[2,100],"59":[2,100],"62":101,"68":[1,103],"69":[1,104],"70":[1,105],"71":[1,106],"72":107,"73":108,"74":[1,109],"75":[2,100],"76":[1,110],"77":[1,111],"80":[2,100],"85":100,"88":[1,102],"89":[2,114],"90":[2,100],"94":[2,100],"96":[2,100],"105":[2,100],"107":[2,100],"108":[2,100],"109":[2,100],"113":[2,100],"121":[2,100],"130":[2,100],"131":[2,100],"133":[2,100],"134":[2,100],"137":[2,100],"138":[2,100],"139":[2,100],"140":[2,100],"141":[2,100],"142":[2,100],"144":[2,100]},{"1":[2,144],"4":[2,144],"29":[2,144],"30":[2,144],"47":[2,144],"55":[2,144],"59":[2,144],"68":[2,144],"69":[2,144],"70":[2,144],"71":[2,144],"74":[2,144],"75":[2,144],"76":[2,144],"77":[2,144],"80":[2,144],"88":[2,144],"89":[2,144],"90":[2,144],"94":[2,144],"96":[2,144],"105":[2,144],"107":[2,144],"108":[2,144],"109":[2,144],"113":[2,144],"121":[2,144],"130":[2,144],"131":[2,144],"133":[2,144],"134":[2,144],"137":[2,144],"138":[2,144],"139":[2,144],"140":[2,144],"141":[2,144],"142":[2,144],"144":[2,144]},{"8":283,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,66],"12":[2,121],"13":[2,121],"14":[2,121],"29":[2,66],"32":[2,121],"34":[2,121],"35":[2,121],"37":[2,121],"38":[2,121],"39":[2,121],"45":[2,121],"46":[2,121],"48":[2,121],"52":[2,121],"53":[2,121],"55":[2,66],"58":[2,121],"78":[2,121],"81":[2,121],"87":[2,121],"92":[2,121],"95":[2,121],"96":[2,66],"99":[2,121],"103":[2,121],"104":[2,121],"107":[2,121],"109":[2,121],"111":[2,121],"113":[2,121],"122":[2,121],"128":[2,121],"129":[2,121],"132":[2,121],"133":[2,121],"134":[2,121],"135":[2,121],"136":[2,121]},{"4":[1,285],"29":[1,286],"96":[1,284]},{"4":[2,58],"8":210,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[2,58],"30":[2,58],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"90":[2,58],"92":[1,60],"95":[1,59],"96":[2,58],"97":287,"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,57],"29":[2,57],"30":[2,57],"54":288,"55":[1,240]},{"1":[2,183],"4":[2,183],"29":[2,183],"30":[2,183],"47":[2,183],"55":[2,183],"59":[2,183],"75":[2,183],"80":[2,183],"90":[2,183],"94":[2,183],"96":[2,183],"105":[2,183],"107":[2,183],"108":[2,183],"109":[2,183],"113":[2,183],"121":[2,183],"124":[2,183],"130":[2,183],"131":[2,183],"133":[2,183],"134":[2,183],"137":[2,183],"138":[2,183],"139":[2,183],"140":[2,183],"141":[2,183],"142":[2,183],"144":[2,183]},{"1":[2,184],"4":[2,184],"29":[2,184],"30":[2,184],"47":[2,184],"55":[2,184],"59":[2,184],"75":[2,184],"80":[2,184],"90":[2,184],"94":[2,184],"96":[2,184],"105":[2,184],"107":[2,184],"108":[2,184],"109":[2,184],"113":[2,184],"121":[2,184],"124":[2,184],"130":[2,184],"131":[2,184],"133":[2,184],"134":[2,184],"137":[2,184],"138":[2,184],"139":[2,184],"140":[2,184],"141":[2,184],"142":[2,184],"144":[2,184]},{"8":289,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":290,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"119":[2,162],"120":[2,162]},{"8":210,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"91":151,"92":[1,60],"95":[1,59],"96":[1,150],"97":152,"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"31":166,"32":[1,76],"63":167,"64":168,"78":[1,73],"95":[1,247],"118":291},{"1":[2,168],"4":[2,168],"29":[2,168],"30":[2,168],"47":[1,95],"55":[2,168],"59":[2,168],"75":[2,168],"80":[2,168],"90":[2,168],"94":[2,168],"96":[2,168],"105":[2,168],"106":93,"107":[2,168],"108":[1,292],"109":[2,168],"112":94,"113":[2,168],"114":72,"121":[1,293],"130":[2,168],"131":[2,168],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,169],"4":[2,169],"29":[2,169],"30":[2,169],"47":[1,95],"55":[2,169],"59":[2,169],"75":[2,169],"80":[2,169],"90":[2,169],"94":[2,169],"96":[2,169],"105":[2,169],"106":93,"107":[2,169],"108":[1,294],"109":[2,169],"112":94,"113":[2,169],"114":72,"121":[2,169],"130":[2,169],"131":[2,169],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"4":[1,296],"29":[1,297],"80":[1,295]},{"4":[2,58],"28":177,"29":[2,58],"30":[2,58],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":298,"43":176,"46":[1,49],"58":[1,178],"80":[2,58]},{"8":299,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,300],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":301,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,302],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,85],"4":[2,85],"29":[2,85],"30":[2,85],"41":[2,85],"47":[2,85],"55":[2,85],"59":[2,85],"68":[2,85],"69":[2,85],"70":[2,85],"71":[2,85],"74":[2,85],"75":[2,85],"76":[2,85],"77":[2,85],"80":[2,85],"82":[2,85],"88":[2,85],"89":[2,85],"90":[2,85],"94":[2,85],"96":[2,85],"105":[2,85],"107":[2,85],"108":[2,85],"109":[2,85],"113":[2,85],"121":[2,85],"130":[2,85],"131":[2,85],"133":[2,85],"134":[2,85],"135":[2,85],"136":[2,85],"137":[2,85],"138":[2,85],"139":[2,85],"140":[2,85],"141":[2,85],"142":[2,85],"143":[2,85],"144":[2,85]},{"8":303,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"75":[1,304],"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"47":[1,95],"75":[1,305],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"47":[1,95],"75":[1,255],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"30":[1,306],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"4":[1,285],"29":[1,286],"90":[1,307]},{"4":[2,66],"29":[2,66],"30":[2,66],"55":[2,66],"90":[2,66],"96":[2,66]},{"4":[1,122],"6":308,"29":[1,6]},{"50":[2,61],"55":[2,61]},{"50":[2,65],"55":[2,65]},{"30":[1,309],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"4":[1,122],"6":310,"29":[1,6],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"4":[1,122],"6":311,"29":[1,6]},{"1":[2,140],"4":[2,140],"29":[2,140],"30":[2,140],"47":[2,140],"55":[2,140],"59":[2,140],"75":[2,140],"80":[2,140],"90":[2,140],"94":[2,140],"96":[2,140],"105":[2,140],"107":[2,140],"108":[2,140],"109":[2,140],"113":[2,140],"121":[2,140],"130":[2,140],"131":[2,140],"133":[2,140],"134":[2,140],"137":[2,140],"138":[2,140],"139":[2,140],"140":[2,140],"141":[2,140],"142":[2,140],"144":[2,140]},{"4":[1,122],"6":312,"29":[1,6]},{"30":[1,313],"124":[1,314],"125":273,"126":[1,227]},{"1":[2,177],"4":[2,177],"29":[2,177],"30":[2,177],"47":[2,177],"55":[2,177],"59":[2,177],"75":[2,177],"80":[2,177],"90":[2,177],"94":[2,177],"96":[2,177],"105":[2,177],"107":[2,177],"108":[2,177],"109":[2,177],"113":[2,177],"121":[2,177],"130":[2,177],"131":[2,177],"133":[2,177],"134":[2,177],"137":[2,177],"138":[2,177],"139":[2,177],"140":[2,177],"141":[2,177],"142":[2,177],"144":[2,177]},{"4":[1,122],"6":315,"29":[1,6]},{"30":[2,180],"124":[2,180],"126":[2,180]},{"4":[1,122],"6":316,"29":[1,6],"55":[1,317]},{"4":[2,136],"29":[2,136],"47":[1,95],"55":[2,136],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,95],"4":[2,95],"29":[1,318],"30":[2,95],"47":[2,95],"55":[2,95],"59":[2,95],"62":101,"68":[1,103],"69":[1,104],"70":[1,105],"71":[1,106],"72":107,"73":108,"74":[1,109],"75":[2,95],"76":[1,110],"77":[1,111],"80":[2,95],"85":100,"88":[1,102],"89":[2,114],"90":[2,95],"94":[2,95],"96":[2,95],"105":[2,95],"107":[2,95],"108":[2,95],"109":[2,95],"113":[2,95],"121":[2,95],"130":[2,95],"131":[2,95],"133":[2,95],"134":[2,95],"137":[2,95],"138":[2,95],"139":[2,95],"140":[2,95],"141":[2,95],"142":[2,95],"144":[2,95]},{"4":[1,279],"30":[1,319]},{"1":[2,98],"4":[2,98],"29":[2,98],"30":[2,98],"47":[2,98],"55":[2,98],"59":[2,98],"75":[2,98],"80":[2,98],"90":[2,98],"94":[2,98],"96":[2,98],"105":[2,98],"107":[2,98],"108":[2,98],"109":[2,98],"113":[2,98],"121":[2,98],"130":[2,98],"131":[2,98],"133":[2,98],"134":[2,98],"137":[2,98],"138":[2,98],"139":[2,98],"140":[2,98],"141":[2,98],"142":[2,98],"144":[2,98]},{"28":177,"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"84":320},{"4":[1,279],"80":[1,321]},{"8":322,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,323],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,105],"28":177,"30":[2,105],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"83":324,"84":231},{"47":[1,95],"96":[1,325],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,128],"4":[2,128],"29":[2,128],"30":[2,128],"41":[2,128],"47":[2,128],"55":[2,128],"59":[2,128],"68":[2,128],"69":[2,128],"70":[2,128],"71":[2,128],"74":[2,128],"75":[2,128],"76":[2,128],"77":[2,128],"80":[2,128],"88":[2,128],"89":[2,128],"90":[2,128],"94":[2,128],"96":[2,128],"105":[2,128],"107":[2,128],"108":[2,128],"109":[2,128],"113":[2,128],"119":[2,128],"120":[2,128],"121":[2,128],"130":[2,128],"131":[2,128],"133":[2,128],"134":[2,128],"137":[2,128],"138":[2,128],"139":[2,128],"140":[2,128],"141":[2,128],"142":[2,128],"144":[2,128]},{"8":210,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"97":326,"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":210,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"29":[1,153],"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"60":154,"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"91":327,"92":[1,60],"95":[1,59],"97":152,"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,130],"29":[2,130],"30":[2,130],"55":[2,130],"90":[2,130],"96":[2,130]},{"4":[1,285],"29":[1,286],"30":[1,328]},{"1":[2,147],"4":[2,147],"29":[2,147],"30":[2,147],"47":[1,95],"55":[2,147],"59":[2,147],"75":[2,147],"80":[2,147],"90":[2,147],"94":[2,147],"96":[2,147],"105":[2,147],"106":93,"107":[1,68],"108":[2,147],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,147],"130":[2,147],"131":[2,147],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,149],"4":[2,149],"29":[2,149],"30":[2,149],"47":[1,95],"55":[2,149],"59":[2,149],"75":[2,149],"80":[2,149],"90":[2,149],"94":[2,149],"96":[2,149],"105":[2,149],"106":93,"107":[1,68],"108":[2,149],"109":[1,69],"112":94,"113":[1,71],"114":72,"121":[2,149],"130":[2,149],"131":[2,149],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"119":[2,167],"120":[2,167]},{"8":329,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":330,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":331,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"1":[2,88],"4":[2,88],"29":[2,88],"30":[2,88],"41":[2,88],"47":[2,88],"55":[2,88],"59":[2,88],"68":[2,88],"69":[2,88],"70":[2,88],"71":[2,88],"74":[2,88],"75":[2,88],"76":[2,88],"77":[2,88],"80":[2,88],"88":[2,88],"89":[2,88],"90":[2,88],"94":[2,88],"96":[2,88],"105":[2,88],"107":[2,88],"108":[2,88],"109":[2,88],"113":[2,88],"119":[2,88],"120":[2,88],"121":[2,88],"130":[2,88],"131":[2,88],"133":[2,88],"134":[2,88],"137":[2,88],"138":[2,88],"139":[2,88],"140":[2,88],"141":[2,88],"142":[2,88],"144":[2,88]},{"28":177,"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":332,"43":176,"46":[1,49],"58":[1,178]},{"4":[2,89],"28":177,"29":[2,89],"30":[2,89],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":173,"43":176,"46":[1,49],"55":[2,89],"58":[1,178],"79":333},{"4":[2,91],"29":[2,91],"30":[2,91],"55":[2,91],"80":[2,91]},{"4":[2,44],"29":[2,44],"30":[2,44],"47":[1,95],"55":[2,44],"80":[2,44],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"8":334,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,45],"29":[2,45],"30":[2,45],"47":[1,95],"55":[2,45],"80":[2,45],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"8":335,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"47":[1,95],"75":[1,336],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,125],"4":[2,125],"29":[2,125],"30":[2,125],"41":[2,125],"47":[2,125],"55":[2,125],"59":[2,125],"68":[2,125],"69":[2,125],"70":[2,125],"71":[2,125],"74":[2,125],"75":[2,125],"76":[2,125],"77":[2,125],"80":[2,125],"82":[2,125],"88":[2,125],"89":[2,125],"90":[2,125],"94":[2,125],"96":[2,125],"105":[2,125],"107":[2,125],"108":[2,125],"109":[2,125],"113":[2,125],"121":[2,125],"130":[2,125],"131":[2,125],"133":[2,125],"134":[2,125],"135":[2,125],"136":[2,125],"137":[2,125],"138":[2,125],"139":[2,125],"140":[2,125],"141":[2,125],"142":[2,125],"143":[2,125],"144":[2,125]},{"1":[2,126],"4":[2,126],"29":[2,126],"30":[2,126],"41":[2,126],"47":[2,126],"55":[2,126],"59":[2,126],"68":[2,126],"69":[2,126],"70":[2,126],"71":[2,126],"74":[2,126],"75":[2,126],"76":[2,126],"77":[2,126],"80":[2,126],"82":[2,126],"88":[2,126],"89":[2,126],"90":[2,126],"94":[2,126],"96":[2,126],"105":[2,126],"107":[2,126],"108":[2,126],"109":[2,126],"113":[2,126],"121":[2,126],"130":[2,126],"131":[2,126],"133":[2,126],"134":[2,126],"135":[2,126],"136":[2,126],"137":[2,126],"138":[2,126],"139":[2,126],"140":[2,126],"141":[2,126],"142":[2,126],"143":[2,126],"144":[2,126]},{"1":[2,40],"4":[2,40],"29":[2,40],"30":[2,40],"47":[2,40],"55":[2,40],"59":[2,40],"75":[2,40],"80":[2,40],"90":[2,40],"94":[2,40],"96":[2,40],"105":[2,40],"107":[2,40],"108":[2,40],"109":[2,40],"113":[2,40],"121":[2,40],"130":[2,40],"131":[2,40],"133":[2,40],"134":[2,40],"137":[2,40],"138":[2,40],"139":[2,40],"140":[2,40],"141":[2,40],"142":[2,40],"144":[2,40]},{"1":[2,117],"4":[2,117],"29":[2,117],"30":[2,117],"47":[2,117],"55":[2,117],"59":[2,117],"68":[2,117],"69":[2,117],"70":[2,117],"71":[2,117],"74":[2,117],"75":[2,117],"76":[2,117],"77":[2,117],"80":[2,117],"88":[2,117],"89":[2,117],"90":[2,117],"94":[2,117],"96":[2,117],"105":[2,117],"107":[2,117],"108":[2,117],"109":[2,117],"113":[2,117],"121":[2,117],"130":[2,117],"131":[2,117],"133":[2,117],"134":[2,117],"137":[2,117],"138":[2,117],"139":[2,117],"140":[2,117],"141":[2,117],"142":[2,117],"144":[2,117]},{"1":[2,53],"4":[2,53],"29":[2,53],"30":[2,53],"47":[2,53],"55":[2,53],"59":[2,53],"75":[2,53],"80":[2,53],"90":[2,53],"94":[2,53],"96":[2,53],"105":[2,53],"107":[2,53],"108":[2,53],"109":[2,53],"113":[2,53],"121":[2,53],"130":[2,53],"131":[2,53],"133":[2,53],"134":[2,53],"137":[2,53],"138":[2,53],"139":[2,53],"140":[2,53],"141":[2,53],"142":[2,53],"144":[2,53]},{"1":[2,208],"4":[2,208],"29":[2,208],"30":[2,208],"47":[2,208],"55":[2,208],"59":[2,208],"75":[2,208],"80":[2,208],"90":[2,208],"94":[2,208],"96":[2,208],"105":[2,208],"107":[2,208],"108":[2,208],"109":[2,208],"113":[2,208],"121":[2,208],"130":[2,208],"131":[2,208],"133":[2,208],"134":[2,208],"137":[2,208],"138":[2,208],"139":[2,208],"140":[2,208],"141":[2,208],"142":[2,208],"144":[2,208]},{"1":[2,185],"4":[2,185],"29":[2,185],"30":[2,185],"47":[2,185],"55":[2,185],"59":[2,185],"75":[2,185],"80":[2,185],"90":[2,185],"94":[2,185],"96":[2,185],"105":[2,185],"107":[2,185],"108":[2,185],"109":[2,185],"113":[2,185],"121":[2,185],"124":[2,185],"130":[2,185],"131":[2,185],"133":[2,185],"134":[2,185],"137":[2,185],"138":[2,185],"139":[2,185],"140":[2,185],"141":[2,185],"142":[2,185],"144":[2,185]},{"1":[2,141],"4":[2,141],"29":[2,141],"30":[2,141],"47":[2,141],"55":[2,141],"59":[2,141],"75":[2,141],"80":[2,141],"90":[2,141],"94":[2,141],"96":[2,141],"105":[2,141],"107":[2,141],"108":[2,141],"109":[2,141],"113":[2,141],"121":[2,141],"130":[2,141],"131":[2,141],"133":[2,141],"134":[2,141],"137":[2,141],"138":[2,141],"139":[2,141],"140":[2,141],"141":[2,141],"142":[2,141],"144":[2,141]},{"1":[2,142],"4":[2,142],"29":[2,142],"30":[2,142],"47":[2,142],"55":[2,142],"59":[2,142],"75":[2,142],"80":[2,142],"90":[2,142],"94":[2,142],"96":[2,142],"101":[2,142],"105":[2,142],"107":[2,142],"108":[2,142],"109":[2,142],"113":[2,142],"121":[2,142],"130":[2,142],"131":[2,142],"133":[2,142],"134":[2,142],"137":[2,142],"138":[2,142],"139":[2,142],"140":[2,142],"141":[2,142],"142":[2,142],"144":[2,142]},{"1":[2,175],"4":[2,175],"29":[2,175],"30":[2,175],"47":[2,175],"55":[2,175],"59":[2,175],"75":[2,175],"80":[2,175],"90":[2,175],"94":[2,175],"96":[2,175],"105":[2,175],"107":[2,175],"108":[2,175],"109":[2,175],"113":[2,175],"121":[2,175],"130":[2,175],"131":[2,175],"133":[2,175],"134":[2,175],"137":[2,175],"138":[2,175],"139":[2,175],"140":[2,175],"141":[2,175],"142":[2,175],"144":[2,175]},{"4":[1,122],"6":337,"29":[1,6]},{"30":[1,338]},{"4":[1,339],"30":[2,181],"124":[2,181],"126":[2,181]},{"8":340,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[2,105],"28":177,"30":[2,105],"31":174,"32":[1,76],"33":175,"34":[1,74],"35":[1,75],"42":233,"43":234,"46":[1,49],"58":[1,178],"78":[1,232],"83":341,"84":231},{"1":[2,96],"4":[2,96],"29":[2,96],"30":[2,96],"47":[2,96],"55":[2,96],"59":[2,96],"75":[2,96],"80":[2,96],"90":[2,96],"94":[2,96],"96":[2,96],"105":[2,96],"107":[2,96],"108":[2,96],"109":[2,96],"113":[2,96],"121":[2,96],"130":[2,96],"131":[2,96],"133":[2,96],"134":[2,96],"137":[2,96],"138":[2,96],"139":[2,96],"140":[2,96],"141":[2,96],"142":[2,96],"144":[2,96]},{"4":[2,107],"30":[2,107],"80":[2,107]},{"4":[2,108],"30":[2,108],"80":[2,108]},{"4":[2,103],"30":[2,103],"47":[1,95],"80":[2,103],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"8":342,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[1,279],"30":[1,343]},{"1":[2,123],"4":[2,123],"29":[2,123],"30":[2,123],"47":[2,123],"55":[2,123],"59":[2,123],"68":[2,123],"69":[2,123],"70":[2,123],"71":[2,123],"74":[2,123],"75":[2,123],"76":[2,123],"77":[2,123],"80":[2,123],"88":[2,123],"89":[2,123],"90":[2,123],"94":[2,123],"96":[2,123],"105":[2,123],"107":[2,123],"108":[2,123],"109":[2,123],"113":[2,123],"121":[2,123],"130":[2,123],"131":[2,123],"133":[2,123],"134":[2,123],"137":[2,123],"138":[2,123],"139":[2,123],"140":[2,123],"141":[2,123],"142":[2,123],"144":[2,123]},{"4":[2,131],"29":[2,131],"30":[2,131],"55":[2,131],"90":[2,131],"96":[2,131]},{"4":[2,57],"29":[2,57],"30":[2,57],"54":344,"55":[1,240]},{"4":[2,132],"29":[2,132],"30":[2,132],"55":[2,132],"90":[2,132],"96":[2,132]},{"1":[2,170],"4":[2,170],"29":[2,170],"30":[2,170],"47":[1,95],"55":[2,170],"59":[2,170],"75":[2,170],"80":[2,170],"90":[2,170],"94":[2,170],"96":[2,170],"105":[2,170],"106":93,"107":[2,170],"108":[2,170],"109":[2,170],"112":94,"113":[2,170],"114":72,"121":[1,345],"130":[2,170],"131":[2,170],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,172],"4":[2,172],"29":[2,172],"30":[2,172],"47":[1,95],"55":[2,172],"59":[2,172],"75":[2,172],"80":[2,172],"90":[2,172],"94":[2,172],"96":[2,172],"105":[2,172],"106":93,"107":[2,172],"108":[1,346],"109":[2,172],"112":94,"113":[2,172],"114":72,"121":[2,172],"130":[2,172],"131":[2,172],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,171],"4":[2,171],"29":[2,171],"30":[2,171],"47":[1,95],"55":[2,171],"59":[2,171],"75":[2,171],"80":[2,171],"90":[2,171],"94":[2,171],"96":[2,171],"105":[2,171],"106":93,"107":[2,171],"108":[2,171],"109":[2,171],"112":94,"113":[2,171],"114":72,"121":[2,171],"130":[2,171],"131":[2,171],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"4":[2,92],"29":[2,92],"30":[2,92],"55":[2,92],"80":[2,92]},{"4":[2,57],"29":[2,57],"30":[2,57],"54":347,"55":[1,252]},{"30":[1,348],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"30":[1,349],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,124],"4":[2,124],"29":[2,124],"30":[2,124],"41":[2,124],"47":[2,124],"55":[2,124],"59":[2,124],"68":[2,124],"69":[2,124],"70":[2,124],"71":[2,124],"74":[2,124],"75":[2,124],"76":[2,124],"77":[2,124],"80":[2,124],"82":[2,124],"88":[2,124],"89":[2,124],"90":[2,124],"94":[2,124],"96":[2,124],"105":[2,124],"107":[2,124],"108":[2,124],"109":[2,124],"113":[2,124],"121":[2,124],"130":[2,124],"131":[2,124],"133":[2,124],"134":[2,124],"135":[2,124],"136":[2,124],"137":[2,124],"138":[2,124],"139":[2,124],"140":[2,124],"141":[2,124],"142":[2,124],"143":[2,124],"144":[2,124]},{"30":[1,350]},{"1":[2,178],"4":[2,178],"29":[2,178],"30":[2,178],"47":[2,178],"55":[2,178],"59":[2,178],"75":[2,178],"80":[2,178],"90":[2,178],"94":[2,178],"96":[2,178],"105":[2,178],"107":[2,178],"108":[2,178],"109":[2,178],"113":[2,178],"121":[2,178],"130":[2,178],"131":[2,178],"133":[2,178],"134":[2,178],"137":[2,178],"138":[2,178],"139":[2,178],"140":[2,178],"141":[2,178],"142":[2,178],"144":[2,178]},{"30":[2,182],"124":[2,182],"126":[2,182]},{"4":[2,137],"29":[2,137],"47":[1,95],"55":[2,137],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"4":[1,279],"30":[1,351]},{"30":[1,352],"47":[1,95],"106":93,"107":[1,68],"109":[1,69],"112":94,"113":[1,71],"114":72,"130":[1,91],"131":[1,92],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,101],"4":[2,101],"29":[2,101],"30":[2,101],"47":[2,101],"55":[2,101],"59":[2,101],"75":[2,101],"80":[2,101],"90":[2,101],"94":[2,101],"96":[2,101],"105":[2,101],"107":[2,101],"108":[2,101],"109":[2,101],"113":[2,101],"121":[2,101],"130":[2,101],"131":[2,101],"133":[2,101],"134":[2,101],"137":[2,101],"138":[2,101],"139":[2,101],"140":[2,101],"141":[2,101],"142":[2,101],"144":[2,101]},{"4":[1,285],"29":[1,286],"30":[1,353]},{"8":354,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"8":355,"9":124,"10":23,"11":24,"12":[1,25],"13":[1,26],"14":[1,27],"15":9,"16":10,"17":11,"18":12,"19":13,"20":14,"21":15,"22":16,"23":17,"24":18,"25":19,"26":20,"27":21,"28":22,"31":64,"32":[1,76],"33":54,"34":[1,74],"35":[1,75],"36":29,"37":[1,55],"38":[1,56],"39":[1,57],"40":28,"43":65,"45":[1,50],"46":[1,49],"48":[1,34],"51":35,"52":[1,62],"53":[1,63],"58":[1,61],"61":41,"63":52,"64":53,"65":30,"66":31,"67":32,"78":[1,73],"81":[1,48],"87":[1,33],"92":[1,60],"95":[1,59],"99":[1,43],"103":[1,51],"104":[1,58],"106":44,"107":[1,68],"109":[1,69],"110":45,"111":[1,70],"112":46,"113":[1,71],"114":72,"122":[1,47],"127":42,"128":[1,66],"129":[1,67],"132":[1,36],"133":[1,37],"134":[1,38],"135":[1,39],"136":[1,40]},{"4":[1,296],"29":[1,297],"30":[1,356]},{"4":[2,46],"29":[2,46],"30":[2,46],"55":[2,46],"80":[2,46]},{"4":[2,47],"29":[2,47],"30":[2,47],"55":[2,47],"80":[2,47]},{"1":[2,176],"4":[2,176],"29":[2,176],"30":[2,176],"47":[2,176],"55":[2,176],"59":[2,176],"75":[2,176],"80":[2,176],"90":[2,176],"94":[2,176],"96":[2,176],"105":[2,176],"107":[2,176],"108":[2,176],"109":[2,176],"113":[2,176],"121":[2,176],"130":[2,176],"131":[2,176],"133":[2,176],"134":[2,176],"137":[2,176],"138":[2,176],"139":[2,176],"140":[2,176],"141":[2,176],"142":[2,176],"144":[2,176]},{"1":[2,97],"4":[2,97],"29":[2,97],"30":[2,97],"47":[2,97],"55":[2,97],"59":[2,97],"75":[2,97],"80":[2,97],"90":[2,97],"94":[2,97],"96":[2,97],"105":[2,97],"107":[2,97],"108":[2,97],"109":[2,97],"113":[2,97],"121":[2,97],"130":[2,97],"131":[2,97],"133":[2,97],"134":[2,97],"137":[2,97],"138":[2,97],"139":[2,97],"140":[2,97],"141":[2,97],"142":[2,97],"144":[2,97]},{"4":[2,104],"30":[2,104],"80":[2,104]},{"4":[2,133],"29":[2,133],"30":[2,133],"55":[2,133],"90":[2,133],"96":[2,133]},{"1":[2,173],"4":[2,173],"29":[2,173],"30":[2,173],"47":[1,95],"55":[2,173],"59":[2,173],"75":[2,173],"80":[2,173],"90":[2,173],"94":[2,173],"96":[2,173],"105":[2,173],"106":93,"107":[2,173],"108":[2,173],"109":[2,173],"112":94,"113":[2,173],"114":72,"121":[2,173],"130":[2,173],"131":[2,173],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"1":[2,174],"4":[2,174],"29":[2,174],"30":[2,174],"47":[1,95],"55":[2,174],"59":[2,174],"75":[2,174],"80":[2,174],"90":[2,174],"94":[2,174],"96":[2,174],"105":[2,174],"106":93,"107":[2,174],"108":[2,174],"109":[2,174],"112":94,"113":[2,174],"114":72,"121":[2,174],"130":[2,174],"131":[2,174],"133":[1,83],"134":[1,82],"137":[1,84],"138":[1,85],"139":[1,86],"140":[1,87],"141":[1,88],"142":[1,89],"144":[1,90]},{"4":[2,93],"29":[2,93],"30":[2,93],"55":[2,93],"80":[2,93]}],
+defaultActions: {"79":[2,4],"102":[2,115]},
+parseError: function parseError(str, hash) {
+ throw new Error(str);
+},
+parse: function parse(input) {
+ var self = this,
+ stack = [0],
+ vstack = [null], // semantic value stack
+ table = this.table,
+ yytext = '',
+ yylineno = 0,
+ yyleng = 0,
+ shifts = 0,
+ reductions = 0,
+ recovering = 0,
+ TERROR = 2,
+ EOF = 1;
+
+ this.lexer.setInput(input);
+ this.lexer.yy = this.yy;
+ this.yy.lexer = this.lexer;
+
+ var parseError = this.yy.parseError = typeof this.yy.parseError == 'function' ? this.yy.parseError : this.parseError;
+
+ function popStack (n) {
+ stack.length = stack.length - 2*n;
+ vstack.length = vstack.length - n;
+ }
+
+ function checkRecover (st) {
+ for (var p in table[st]) if (p == TERROR) {
+ return true;
+ }
+ return false;
+ }
+
+ function lex() {
+ var token;
+ token = self.lexer.lex() || 1; // $end = 1
+ // if token isn't its numeric value, convert
+ if (typeof token !== 'number') {
+ token = self.symbols_[token] || token;
+ }
+ return token;
+ };
+
+ var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected, recovered = false;
+ while (true) {
+ // retreive state number from top of stack
+ state = stack[stack.length-1];
+
+ // use default actions if available
+ if (this.defaultActions[state]) {
+ action = this.defaultActions[state];
+ } else {
+ if (symbol == null)
+ symbol = lex();
+ // read action for current state and first input
+ action = table[state] && table[state][symbol];
+ }
+
+ // handle parse error
+ if (typeof action === 'undefined' || !action.length || !action[0]) {
+
+ if (!recovering) {
+ // Report error
+ expected = [];
+ for (p in table[state]) if (this.terminals_[p] && p > 2) {
+ expected.push("'"+this.terminals_[p]+"'");
+ }
+ if (this.lexer.showPosition) {
+ parseError.call(this, 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+'\nExpecting '+expected.join(', '),
+ {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, expected: expected});
+ } else {
+ parseError.call(this, 'Parse error on line '+(yylineno+1)+": Unexpected '"+(this.terminals_[symbol] || symbol)+"'",
+ {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, expected: expected});
+ }
+ }
+
+ // just recovered from another error
+ if (recovering == 3) {
+ if (symbol == EOF) {
+ throw 'Parsing halted.'
+ }
+
+ // discard current lookahead and grab another
+ yyleng = this.lexer.yyleng;
+ yytext = this.lexer.yytext;
+ yylineno = this.lexer.yylineno;
+ symbol = lex();
+ }
+
+ // try to recover from error
+ while (1) {
+ // check for error recovery rule in this state
+ if (checkRecover(state)) {
+ break;
+ }
+ if (state == 0) {
+ throw 'Parsing halted.'
+ }
+ popStack(1);
+ state = stack[stack.length-1];
+ }
+
+ preErrorSymbol = symbol; // save the lookahead token
+ symbol = TERROR; // insert generic error symbol as new lookahead
+ state = stack[stack.length-1];
+ action = table[state] && table[state][TERROR];
+ recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
+ }
+
+ // this shouldn't happen, unless resolve defaults are off
+ if (action[0] instanceof Array && action.length > 1) {
+ throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
+ }
+
+ a = action;
+
+ switch (a[0]) {
+
+ case 1: // shift
+ shifts++;
+
+ stack.push(symbol);
+ vstack.push(this.lexer.yytext); // semantic values or junk only, no terminals
+ stack.push(a[1]); // push state
+ symbol = null;
+ if (!preErrorSymbol) { // normal execution/no error
+ yyleng = this.lexer.yyleng;
+ yytext = this.lexer.yytext;
+ yylineno = this.lexer.yylineno;
+ if (recovering > 0)
+ recovering--;
+ } else { // error just occurred, resume old lookahead f/ before error
+ symbol = preErrorSymbol;
+ preErrorSymbol = null;
+ }
+ break;
+
+ case 2: // reduce
+ reductions++;
+
+ len = this.productions_[a[1]][1];
+
+ // perform semantic action
+ yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
+ r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, a[1], vstack);
+
+ if (typeof r !== 'undefined') {
+ return r;
+ }
+
+ // pop off stack
+ if (len) {
+ stack = stack.slice(0,-1*len*2);
+ vstack = vstack.slice(0, -1*len);
+ }
+
+ stack.push(this.productions_[a[1]][0]); // push nonterminal (reduce)
+ vstack.push(yyval.$);
+ // goto new state = table[STATE][NONTERMINAL]
+ newState = table[stack[stack.length-2]][stack[stack.length-1]];
+ stack.push(newState);
+ break;
+
+ case 3: // accept
+
+ this.reductionCount = reductions;
+ this.shiftCount = shifts;
+ return true;
+ }
+
+ }
+
+ return true;
+}};
+return parser;
+})();
+if (typeof require !== 'undefined') {
+exports.parser = parser;
+exports.parse = function () { return parser.parse.apply(parser, arguments); }
+exports.main = function commonjsMain(args) {
+ if (!args[1])
+ throw new Error('Usage: '+args[0]+' FILE');
+ if (typeof process !== 'undefined') {
+ var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8");
+ } else {
+ var cwd = require("file").path(require("file").cwd());
+ var source = cwd.join(args[1]).read({charset: "utf-8"});
+ }
+ return exports.parser.parse(source);
+}
+if (typeof module !== 'undefined' && require.main === module) {
+ exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args);
+}
+}
\ No newline at end of file
--- /dev/null
+(function() {
+ var CoffeeScript, helpers, readline, repl, run, stdio;
+ CoffeeScript = require('./coffee-script');
+ helpers = require('./helpers');
+ readline = require('readline');
+ stdio = process.openStdin();
+ helpers.extend(global, {
+ quit: function() {
+ return process.exit(0);
+ }
+ });
+ run = function(buffer) {
+ var val;
+ try {
+ val = CoffeeScript.eval(buffer.toString(), {
+ bare: true,
+ globals: true,
+ fileName: 'repl'
+ });
+ if (val !== undefined) {
+ puts(inspect(val));
+ }
+ } catch (err) {
+ puts(err.stack || err.toString());
+ }
+ return repl.prompt();
+ };
+ repl = readline.createInterface(stdio);
+ repl.setPrompt('coffee> ');
+ stdio.on('data', function(buffer) {
+ return repl.write(buffer);
+ });
+ repl.on('close', function() {
+ return stdio.destroy();
+ });
+ repl.on('line', run);
+ repl.prompt();
+}).call(this);
--- /dev/null
+(function() {
+ var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, _i, _len, _ref, include, left, rite;
+ include = require('./helpers').include;
+ exports.Rewriter = (function() {
+ function Rewriter() {
+ return this;
+ };
+ return Rewriter;
+ })();
+ exports.Rewriter.prototype.rewrite = function(_arg) {
+ this.tokens = _arg;
+ this.adjustComments();
+ this.removeLeadingNewlines();
+ this.removeMidExpressionNewlines();
+ this.closeOpenCalls();
+ this.closeOpenIndexes();
+ this.addImplicitIndentation();
+ this.tagPostfixConditionals();
+ this.addImplicitBraces();
+ this.addImplicitParentheses();
+ this.ensureBalance(BALANCED_PAIRS);
+ this.rewriteClosingParens();
+ return this.tokens;
+ };
+ exports.Rewriter.prototype.scanTokens = function(block) {
+ var i, token, tokens;
+ tokens = this.tokens;
+ i = 0;
+ while (token = tokens[i]) {
+ i += block.call(this, token, i, tokens);
+ }
+ return true;
+ };
+ exports.Rewriter.prototype.detectEnd = function(i, condition, action) {
+ var levels, token, tokens;
+ tokens = this.tokens;
+ levels = 0;
+ while (token = tokens[i]) {
+ if (levels === 0 && condition.call(this, token, i)) {
+ return action.call(this, token, i);
+ }
+ if (!token || levels < 0) {
+ return action.call(this, token, i - 1);
+ }
+ if (include(EXPRESSION_START, token[0])) {
+ levels += 1;
+ } else if (include(EXPRESSION_END, token[0])) {
+ levels -= 1;
+ }
+ i += 1;
+ }
+ return i - 1;
+ };
+ exports.Rewriter.prototype.adjustComments = function() {
+ return this.scanTokens(function(token, i, tokens) {
+ var _ref, after, before, post, prev;
+ if (token[0] !== 'HERECOMMENT') {
+ return 1;
+ }
+ before = tokens[i - 2];
+ prev = tokens[i - 1];
+ post = tokens[i + 1];
+ after = tokens[i + 2];
+ if (((after != null) ? after[0] : undefined) === 'INDENT') {
+ tokens.splice(i + 2, 1);
+ if (((before != null) ? before[0] : undefined) === 'OUTDENT' && ((post != null) ? post[0] : undefined) === 'TERMINATOR') {
+ tokens.splice(i - 2, 1);
+ } else {
+ tokens.splice(i, 0, after);
+ }
+ } else if (prev && !((_ref = prev[0]) === 'TERMINATOR' || _ref === 'INDENT' || _ref === 'OUTDENT')) {
+ if (((post != null) ? post[0] : undefined) === 'TERMINATOR' && ((after != null) ? after[0] : undefined) === 'OUTDENT') {
+ tokens.splice.apply(tokens, [i + 2, 0].concat(tokens.splice(i, 2)));
+ if (tokens[i + 2][0] !== 'TERMINATOR') {
+ tokens.splice(i + 2, 0, ['TERMINATOR', '\n', prev[2]]);
+ }
+ } else {
+ tokens.splice(i, 0, ['TERMINATOR', '\n', prev[2]]);
+ }
+ return 2;
+ }
+ return 1;
+ });
+ };
+ exports.Rewriter.prototype.removeLeadingNewlines = function() {
+ var _len, _ref, i, tag;
+ for (i = 0, _len = (_ref = this.tokens).length; i < _len; i++) {
+ tag = _ref[i][0];
+ if (tag !== 'TERMINATOR') {
+ break;
+ }
+ }
+ return i ? this.tokens.splice(0, i) : undefined;
+ };
+ exports.Rewriter.prototype.removeMidExpressionNewlines = function() {
+ return this.scanTokens(function(token, i, tokens) {
+ if (!(token[0] === 'TERMINATOR' && include(EXPRESSION_CLOSE, this.tag(i + 1)))) {
+ return 1;
+ }
+ tokens.splice(i, 1);
+ return 0;
+ });
+ };
+ exports.Rewriter.prototype.closeOpenCalls = function() {
+ var action, condition;
+ condition = function(token, i) {
+ var _ref;
+ return ((_ref = token[0]) === ')' || _ref === 'CALL_END') || token[0] === 'OUTDENT' && this.tag(i - 1) === ')';
+ };
+ action = function(token, i) {
+ return (this.tokens[token[0] === 'OUTDENT' ? i - 1 : i][0] = 'CALL_END');
+ };
+ return this.scanTokens(function(token, i) {
+ if (token[0] === 'CALL_START') {
+ this.detectEnd(i + 1, condition, action);
+ }
+ return 1;
+ });
+ };
+ exports.Rewriter.prototype.closeOpenIndexes = function() {
+ var action, condition;
+ condition = function(token, i) {
+ var _ref;
+ return ((_ref = token[0]) === ']' || _ref === 'INDEX_END');
+ };
+ action = function(token, i) {
+ return (token[0] = 'INDEX_END');
+ };
+ return this.scanTokens(function(token, i) {
+ if (token[0] === 'INDEX_START') {
+ this.detectEnd(i + 1, condition, action);
+ }
+ return 1;
+ });
+ };
+ exports.Rewriter.prototype.addImplicitBraces = function() {
+ var action, condition, stack;
+ stack = [];
+ condition = function(token, i) {
+ var _ref, _ref2, one, tag, three, two;
+ if (('HERECOMMENT' === this.tag(i + 1) || 'HERECOMMENT' === this.tag(i - 1))) {
+ return false;
+ }
+ _ref = this.tokens.slice(i + 1, i + 4), one = _ref[0], two = _ref[1], three = _ref[2];
+ tag = token[0];
+ return (tag === 'TERMINATOR' || tag === 'OUTDENT') && !(((two != null) ? two[0] : undefined) === ':' || ((one != null) ? one[0] : undefined) === '@' && ((three != null) ? three[0] : undefined) === ':') || tag === ',' && !((_ref2 = ((one != null) ? one[0] : undefined)) === 'IDENTIFIER' || _ref2 === 'NUMBER' || _ref2 === 'STRING' || _ref2 === '@' || _ref2 === 'TERMINATOR' || _ref2 === 'OUTDENT');
+ };
+ action = function(token, i) {
+ return this.tokens.splice(i, 0, ['}', '}', token[2]]);
+ };
+ return this.scanTokens(function(token, i, tokens) {
+ var idx, tag, tok;
+ if (include(EXPRESSION_START, tag = token[0])) {
+ stack.push(tag === 'INDENT' && this.tag(i - 1) === '{' ? '{' : tag);
+ return 1;
+ }
+ if (include(EXPRESSION_END, tag)) {
+ stack.pop();
+ return 1;
+ }
+ if (!(tag === ':' && stack[stack.length - 1] !== '{')) {
+ return 1;
+ }
+ stack.push('{');
+ idx = this.tag(i - 2) === '@' ? i - 2 : i - 1;
+ if (this.tag(idx - 2) === 'HERECOMMENT') {
+ idx -= 2;
+ }
+ tok = ['{', '{', token[2]];
+ tok.generated = true;
+ tokens.splice(idx, 0, tok);
+ this.detectEnd(i + 2, condition, action);
+ return 2;
+ });
+ };
+ exports.Rewriter.prototype.addImplicitParentheses = function() {
+ var action, classLine;
+ classLine = false;
+ action = function(token, i) {
+ var idx;
+ idx = token[0] === 'OUTDENT' ? i + 1 : i;
+ return this.tokens.splice(idx, 0, ['CALL_END', ')', token[2]]);
+ };
+ return this.scanTokens(function(token, i, tokens) {
+ var callObject, next, prev, seenSingle, tag;
+ tag = token[0];
+ if (tag === 'CLASS') {
+ classLine = true;
+ }
+ prev = tokens[i - 1];
+ next = tokens[i + 1];
+ callObject = !classLine && tag === 'INDENT' && next && next.generated && next[0] === '{' && prev && include(IMPLICIT_FUNC, prev[0]);
+ seenSingle = false;
+ if (include(LINEBREAKS, tag)) {
+ classLine = false;
+ }
+ if (prev && !prev.spaced && tag === '?') {
+ token.call = true;
+ }
+ if (!(callObject || ((prev != null) ? prev.spaced : undefined) && (prev.call || include(IMPLICIT_FUNC, prev[0])) && (include(IMPLICIT_CALL, tag) || include(IMPLICIT_UNSPACED_CALL, tag) && !token.spaced))) {
+ return 1;
+ }
+ tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
+ this.detectEnd(i + (callObject ? 2 : 1), function(token, i) {
+ var post;
+ if (!seenSingle && token.fromThen) {
+ return true;
+ }
+ tag = token[0];
+ if ((tag === 'IF' || tag === 'ELSE' || tag === 'UNLESS' || tag === '->' || tag === '=>')) {
+ seenSingle = true;
+ }
+ if (tag === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT') {
+ return true;
+ }
+ return !token.generated && this.tag(i - 1) !== ',' && include(IMPLICIT_END, tag) && (tag !== 'INDENT' || (this.tag(i - 2) !== 'CLASS' && !include(IMPLICIT_BLOCK, this.tag(i - 1)) && !((post = this.tokens[i + 1]) && post.generated && post[0] === '{')));
+ }, action);
+ if (prev[0] === '?') {
+ prev[0] = 'FUNC_EXIST';
+ }
+ return 2;
+ });
+ };
+ exports.Rewriter.prototype.addImplicitIndentation = function() {
+ return this.scanTokens(function(token, i, tokens) {
+ var _ref, _ref2, action, condition, indent, outdent, starter, tag;
+ tag = token[0];
+ if (tag === 'ELSE' && this.tag(i - 1) !== 'OUTDENT') {
+ tokens.splice.apply(tokens, [i, 0].concat(this.indentation(token)));
+ return 2;
+ }
+ if (tag === 'CATCH' && ((_ref = this.tag(i + 2)) === 'TERMINATOR' || _ref === 'FINALLY')) {
+ tokens.splice.apply(tokens, [i + 2, 0].concat(this.indentation(token)));
+ return 4;
+ }
+ if (include(SINGLE_LINERS, tag) && this.tag(i + 1) !== 'INDENT' && !(tag === 'ELSE' && this.tag(i + 1) === 'IF')) {
+ starter = tag;
+ _ref2 = this.indentation(token), indent = _ref2[0], outdent = _ref2[1];
+ if (starter === 'THEN') {
+ indent.fromThen = true;
+ }
+ indent.generated = (outdent.generated = true);
+ tokens.splice(i + 1, 0, indent);
+ condition = function(token, i) {
+ return token[1] !== ';' && include(SINGLE_CLOSERS, token[0]) && !(token[0] === 'ELSE' && !(starter === 'IF' || starter === 'THEN'));
+ };
+ action = function(token, i) {
+ return this.tokens.splice(this.tag(i - 1) === ',' ? i - 1 : i, 0, outdent);
+ };
+ this.detectEnd(i + 2, condition, action);
+ if (tag === 'THEN') {
+ tokens.splice(i, 1);
+ }
+ return 1;
+ }
+ return 1;
+ });
+ };
+ exports.Rewriter.prototype.tagPostfixConditionals = function() {
+ var condition;
+ condition = function(token, i) {
+ var _ref;
+ return ((_ref = token[0]) === 'TERMINATOR' || _ref === 'INDENT');
+ };
+ return this.scanTokens(function(token, i) {
+ var _ref, original;
+ if (!((_ref = token[0]) === 'IF' || _ref === 'UNLESS')) {
+ return 1;
+ }
+ original = token;
+ this.detectEnd(i + 1, condition, function(token, i) {
+ return token[0] !== 'INDENT' ? (original[0] = 'POST_' + original[0]) : undefined;
+ });
+ return 1;
+ });
+ };
+ exports.Rewriter.prototype.ensureBalance = function(pairs) {
+ var _result, key, levels, open, openLine, unclosed, value;
+ levels = {};
+ openLine = {};
+ this.scanTokens(function(token, i) {
+ var _i, _len, _ref, _ref2, close, open, tag;
+ tag = token[0];
+ for (_i = 0, _len = (_ref = pairs).length; _i < _len; _i++) {
+ _ref2 = _ref[_i], open = _ref2[0], close = _ref2[1];
+ levels[open] |= 0;
+ if (tag === open) {
+ if (levels[open] === 0) {
+ openLine[open] = token[2];
+ }
+ levels[open] += 1;
+ } else if (tag === close) {
+ levels[open] -= 1;
+ }
+ if (levels[open] < 0) {
+ throw Error("too many " + (token[1]) + " on line " + (token[2] + 1));
+ }
+ }
+ return 1;
+ });
+ unclosed = (function() {
+ _result = [];
+ for (key in levels) {
+ value = levels[key];
+ if (value > 0) {
+ _result.push(key);
+ }
+ }
+ return _result;
+ })();
+ if (unclosed.length) {
+ throw Error("unclosed " + (open = unclosed[0]) + " on line " + (openLine[open] + 1));
+ }
+ };
+ exports.Rewriter.prototype.rewriteClosingParens = function() {
+ var debt, key, stack;
+ stack = [];
+ debt = {};
+ for (key in INVERSES) {
+ (debt[key] = 0);
+ }
+ return this.scanTokens(function(token, i, tokens) {
+ var inv, match, mtag, oppos, tag, val;
+ if (include(EXPRESSION_START, tag = token[0])) {
+ stack.push(token);
+ return 1;
+ }
+ if (!include(EXPRESSION_END, tag)) {
+ return 1;
+ }
+ if (debt[(inv = INVERSES[tag])] > 0) {
+ debt[inv] -= 1;
+ tokens.splice(i, 1);
+ return 0;
+ }
+ match = stack.pop();
+ mtag = match[0];
+ oppos = INVERSES[mtag];
+ if (tag === oppos) {
+ return 1;
+ }
+ debt[mtag] += 1;
+ val = [oppos, mtag === 'INDENT' ? match[1] : oppos];
+ if (this.tag(i + 2) === mtag) {
+ tokens.splice(i + 3, 0, val);
+ stack.push(match);
+ } else {
+ tokens.splice(i, 0, val);
+ }
+ return 1;
+ });
+ };
+ exports.Rewriter.prototype.indentation = function(token) {
+ return [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]];
+ };
+ exports.Rewriter.prototype.tag = function(i) {
+ var _ref;
+ return (((_ref = this.tokens[i]) != null) ? _ref[0] : undefined);
+ };
+ BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['CALL_START', 'CALL_END'], ['PARAM_START', 'PARAM_END'], ['INDEX_START', 'INDEX_END']];
+ INVERSES = {};
+ EXPRESSION_START = [];
+ EXPRESSION_END = [];
+ for (_i = 0, _len = BALANCED_PAIRS.length; _i < _len; _i++) {
+ _ref = BALANCED_PAIRS[_i], left = _ref[0], rite = _ref[1];
+ EXPRESSION_START.push(INVERSES[rite] = left);
+ EXPRESSION_END.push(INVERSES[left] = rite);
+ }
+ EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat(EXPRESSION_END);
+ IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS'];
+ IMPLICIT_CALL = ['IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS', 'IF', 'UNLESS', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY', '@', '->', '=>', '[', '(', '{', '--', '++'];
+ IMPLICIT_UNSPACED_CALL = ['+', '-'];
+ IMPLICIT_BLOCK = ['->', '=>', '{', '[', ','];
+ IMPLICIT_END = ['POST_IF', 'POST_UNLESS', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'TERMINATOR', 'INDENT'];
+ SINGLE_LINERS = ['ELSE', '->', '=>', 'TRY', 'FINALLY', 'THEN'];
+ SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN'];
+ LINEBREAKS = ['TERMINATOR', 'INDENT', 'OUTDENT'];
+}).call(this);
--- /dev/null
+(function() {
+ var Scope, _ref, extend, last;
+ var __hasProp = Object.prototype.hasOwnProperty;
+ _ref = require('./helpers'), extend = _ref.extend, last = _ref.last;
+ exports.Scope = (function() {
+ Scope = (function() {
+ function Scope(_arg, _arg2, _arg3) {
+ this.method = _arg3;
+ this.expressions = _arg2;
+ this.parent = _arg;
+ this.variables = {
+ 'arguments': 'arguments'
+ };
+ if (this.parent) {
+ this.garbage = this.parent.garbage;
+ } else {
+ this.garbage = [];
+ Scope.root = this;
+ }
+ return this;
+ };
+ return Scope;
+ })();
+ Scope.root = null;
+ Scope.prototype.startLevel = function() {
+ return this.garbage.push([]);
+ };
+ Scope.prototype.endLevel = function() {
+ var _i, _len, _ref2, _result, name, vars;
+ vars = this.variables;
+ _result = [];
+ for (_i = 0, _len = (_ref2 = this.garbage.pop()).length; _i < _len; _i++) {
+ name = _ref2[_i];
+ if (vars[name] === 'var') {
+ _result.push(vars[name] = 'reuse');
+ }
+ }
+ return _result;
+ };
+ Scope.prototype.find = function(name, options) {
+ if (this.check(name, options)) {
+ return true;
+ }
+ this.variables[name] = 'var';
+ return false;
+ };
+ Scope.prototype.any = function(fn) {
+ var _ref2, k, v;
+ for (v in _ref2 = this.variables) {
+ if (!__hasProp.call(_ref2, v)) continue;
+ k = _ref2[v];
+ if (fn(v, k)) {
+ return true;
+ }
+ }
+ return false;
+ };
+ Scope.prototype.parameter = function(name) {
+ return (this.variables[name] = 'param');
+ };
+ Scope.prototype.check = function(name, options) {
+ var _ref2, immediate;
+ immediate = Object.prototype.hasOwnProperty.call(this.variables, name);
+ if (immediate || ((options != null) ? options.immediate : undefined)) {
+ return immediate;
+ }
+ return !!(((_ref2 = this.parent) != null) ? _ref2.check(name) : undefined);
+ };
+ Scope.prototype.temporary = function(type, index) {
+ return type.length > 1 ? '_' + type + (index > 1 ? index : '') : '_' + (index + parseInt(type, 36)).toString(36).replace(/\d/g, 'a');
+ };
+ Scope.prototype.freeVariable = function(type) {
+ var index, temp;
+ index = 0;
+ while (this.check(temp = this.temporary(type, index)) && this.variables[temp] !== 'reuse') {
+ index++;
+ }
+ this.variables[temp] = 'var';
+ if (this.garbage.length) {
+ last(this.garbage).push(temp);
+ }
+ return temp;
+ };
+ Scope.prototype.assign = function(name, value) {
+ return (this.variables[name] = {
+ value: value,
+ assigned: true
+ });
+ };
+ Scope.prototype.hasDeclarations = function(body) {
+ return body === this.expressions && this.any(function(k, val) {
+ return (val === 'var' || val === 'reuse');
+ });
+ };
+ Scope.prototype.hasAssignments = function(body) {
+ return body === this.expressions && this.any(function(k, val) {
+ return val.assigned;
+ });
+ };
+ Scope.prototype.declaredVariables = function() {
+ var _ref2, _result, key, val;
+ return (function() {
+ _result = [];
+ for (key in _ref2 = this.variables) {
+ if (!__hasProp.call(_ref2, key)) continue;
+ val = _ref2[key];
+ if ((val === 'var' || val === 'reuse')) {
+ _result.push(key);
+ }
+ }
+ return _result;
+ }).call(this).sort();
+ };
+ Scope.prototype.assignedVariables = function() {
+ var _ref2, _result, key, val;
+ _result = [];
+ for (key in _ref2 = this.variables) {
+ if (!__hasProp.call(_ref2, key)) continue;
+ val = _ref2[key];
+ if (val.assigned) {
+ _result.push("" + key + " = " + (val.value));
+ }
+ }
+ return _result;
+ };
+ Scope.prototype.compiledDeclarations = function() {
+ return this.declaredVariables().join(', ');
+ };
+ Scope.prototype.compiledAssignments = function() {
+ return this.assignedVariables().join(', ');
+ };
+ return Scope;
+ }).call(this);
+}).call(this);
--- /dev/null
+(function(){
+ if (!((typeof process !== "undefined" && process !== null))) {
+ this.exports = this;
+ }
+ exports.utilities = {
+ extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n }",
+ bind: "function(func, obj, args) {\n return function() {\n return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);\n };\n }",
+ range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n }",
+ hasProp: 'Object.prototype.hasOwnProperty',
+ slice: 'Array.prototype.slice'
+ };
+})();
--- /dev/null
+{
+ "name": "coffee-script",
+ "description": "Unfancy JavaScript",
+ "keywords": ["javascript", "language", "coffeescript", "compiler"],
+ "author": "Jeremy Ashkenas",
+ "version": "0.9.4",
+ "licenses": [{
+ "type": "MIT",
+ "url": "http://github.com/jashkenas/coffee-script/raw/master/LICENSE"
+ }],
+ "engines": {
+ "node": ">=0.1.99"
+ },
+ "directories" : {
+ "lib" : "./lib"
+ },
+ "main" : "./lib/coffee-script",
+ "bin": {
+ "coffee": "./bin/coffee",
+ "cake": "./bin/cake"
+ }
+}
--- /dev/null
+# Override exported methods for non-Node.js engines.
+
+CoffeeScript = require './coffee-script'
+CoffeeScript.require = require
+
+# Use standard JavaScript `eval` to eval code.
+CoffeeScript.eval = (code, options) ->
+ eval CoffeeScript.compile code, options
+
+# Running code does not provide access to this scope.
+CoffeeScript.run = (code, options) ->
+ options?.bare = on
+ Function(CoffeeScript.compile code, options)()
+
+# If we're not in a browser environment, we're finished with the public API.
+return unless window?
+
+# Load a remote script from the current domain via XHR.
+CoffeeScript.load = (url, options) ->
+ xhr = new (window.ActiveXObject or XMLHttpRequest)('Microsoft.XMLHTTP')
+ xhr.open 'GET', url, true
+ xhr.overrideMimeType 'text/plain' if 'overrideMimeType' of xhr
+ xhr.onreadystatechange = ->
+ CoffeeScript.run xhr.responseText, options if xhr.readyState is 4
+ xhr.send null
+
+# Activate CoffeeScript in the browser by having it compile and evaluate
+# all script tags with a content-type of `text/coffeescript`.
+# This happens on page load.
+runScripts = ->
+ for script in document.getElementsByTagName 'script'
+ if script.type is 'text/coffeescript'
+ if script.src
+ CoffeeScript.load script.src
+ else
+ setTimeout -> CoffeeScript.run script.innerHTML
+ null
+if window.addEventListener
+ addEventListener 'DOMContentLoaded', runScripts, no
+else
+ attachEvent 'onload', runScripts
--- /dev/null
+# `cake` is a simplified version of [Make](http://www.gnu.org/software/make/)
+# ([Rake](http://rake.rubyforge.org/), [Jake](http://github.com/280north/jake))
+# 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.
+#
+# Running `cake` with no arguments will print out a list of all the tasks in the
+# current directory's Cakefile.
+
+# External dependencies.
+fs = require 'fs'
+path = require 'path'
+helpers = require './helpers'
+optparse = require './optparse'
+CoffeeScript = require './coffee-script'
+
+# Keep track of the list of defined tasks, the accepted options, and so on.
+tasks = {}
+options = {}
+switches = []
+oparse = null
+
+# Mixin the top-level Cake functions for Cakefiles to use directly.
+helpers.extend global,
+
+ # Define a Cake task with a short name, an optional sentence description,
+ # and the function to run as the action itself.
+ task: (name, description, action) ->
+ [action, description] = [description, action] unless action
+ tasks[name] = {name, description, action}
+
+ # 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.
+ option: (letter, flag, description) ->
+ switches.push [letter, flag, description]
+
+ # Invoke another task in the current Cakefile.
+ invoke: (name) ->
+ missingTask name unless tasks[name]
+ tasks[name].action options
+
+
+# Run `cake`. 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.
+exports.run = ->
+ path.exists 'Cakefile', (exists) ->
+ throw new Error("Cakefile not found in #{process.cwd()}") unless exists
+ args = process.argv.slice 2
+ CoffeeScript.run fs.readFileSync('Cakefile').toString(), fileName: 'Cakefile'
+ oparse = new optparse.OptionParser switches
+ return printTasks() unless args.length
+ options = oparse.parse(args)
+ invoke arg for arg in options.arguments
+
+# Display the list of Cake tasks in a format similar to `rake -T`
+printTasks = ->
+ puts ''
+ for all name, task of tasks
+ spaces = 20 - name.length
+ spaces = if spaces > 0 then Array(spaces + 1).join(' ') else ''
+ desc = if task.description then "# #{task.description}" else ''
+ puts "cake #{name}#{spaces} #{desc}"
+ puts oparse.help() if switches.length
+
+# Print an error and exit when attempting to all an undefined task.
+missingTask = (task) ->
+ puts "No such task: \"#{task}\""
+ process.exit 1
--- /dev/null
+# 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 tokenzing, parsing, and compiling source
+# CoffeeScript into JavaScript.
+#
+# If included on a webpage, it will automatically sniff out, compile, and
+# execute all scripts present in `text/coffeescript` tags.
+
+path = require 'path'
+{Lexer} = require './lexer'
+{parser} = require './parser'
+
+# TODO: Remove registerExtension when fully deprecated
+if require.extensions
+ fs = require 'fs'
+ require.extensions['.coffee'] = (module, filename) ->
+ content = compile fs.readFileSync filename, 'utf8'
+ module._compile content, filename
+else if require.registerExtension
+ require.registerExtension '.coffee', (content) -> compile content
+
+# The current CoffeeScript version number.
+exports.VERSION = '0.9.4'
+
+# Expose helpers for testing.
+exports.helpers = require './helpers'
+
+# Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison
+# compiler.
+exports.compile = compile = (code, options) ->
+ options or= {}
+ try
+ (parser.parse lexer.tokenize code).compile options
+ catch err
+ err.message = "In #{options.fileName}, #{err.message}" if options.fileName
+ throw err
+
+# Tokenize a string of CoffeeScript code, and return the array of tokens.
+exports.tokens = (code, options) ->
+ lexer.tokenize code, options
+
+# Tokenize and parse a string of CoffeeScript code, and return the AST. You can
+# then compile it by calling `.compile()` on the root, or traverse it by using
+# `.traverse()` with a callback.
+exports.nodes = (code, options) ->
+ parser.parse lexer.tokenize code, options
+
+# Compile and execute a string of CoffeeScript (on the server), correctly
+# setting `__filename`, `__dirname`, and relative `require()`.
+exports.run = (code, options) ->
+ # We want the root module.
+ root = module
+ while root.parent
+ root = root.parent
+ # Set the filename
+ root.filename = options.fileName
+ # Clear the module cache
+ root.moduleCache = {} if root.moduleCache
+ # Compile
+ if path.extname(root.filename) isnt '.coffee' or require.extensions
+ root._compile exports.compile(code, options), root.filename
+ else
+ root._compile code, root.filename
+
+# Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
+# The CoffeeScript REPL uses this to run the input.
+exports.eval = (code, options) ->
+ __filename = options.fileName
+ __dirname = path.dirname __filename
+ eval exports.compile(code, options)
+
+# Instantiate a Lexer for our use here.
+lexer = new Lexer
+
+# 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".
+parser.lexer =
+ lex: ->
+ token = @tokens[@pos] or [""]
+ @pos += 1
+ this.yylineno = token[2]
+ this.yytext = token[1]
+ token[0]
+ setInput: (tokens) ->
+ @tokens = tokens
+ @pos = 0
+ upcomingInput: -> ""
+
+parser.yy = require './nodes'
--- /dev/null
+# The `coffee` utility. Handles command-line compilation of CoffeeScript
+# into various forms: saved into `.js` files or printed to stdout, piped to
+# [JSLint](http://javascriptlint.com/) or recompiled every time the source is
+# saved, printed as a token stream or as the syntax tree, or launch an
+# interactive REPL.
+
+# External dependencies.
+fs = require 'fs'
+path = require 'path'
+optparse = require './optparse'
+CoffeeScript = require './coffee-script'
+helpers = require './helpers'
+{spawn, exec} = require 'child_process'
+{EventEmitter} = require 'events'
+
+# Allow CoffeeScript to emit Node.js events, and add it to global scope.
+helpers.extend CoffeeScript, new EventEmitter
+global.CoffeeScript = CoffeeScript
+
+# The help banner that is printed when `coffee` is called without arguments.
+BANNER = '''
+ coffee compiles CoffeeScript source files into JavaScript.
+
+ Usage:
+ coffee path/to/script.coffee
+ '''
+
+# The list of all the valid option flags that `coffee` knows how to handle.
+SWITCHES = [
+ ['-c', '--compile', 'compile to JavaScript and save as .js files']
+ ['-i', '--interactive', 'run an interactive CoffeeScript REPL']
+ ['-o', '--output [DIR]', 'set the directory for compiled JavaScript']
+ ['-w', '--watch', 'watch scripts for changes, and recompile']
+ ['-p', '--print', 'print the compiled JavaScript to stdout']
+ ['-l', '--lint', 'pipe the compiled JavaScript through JSLint']
+ ['-s', '--stdio', 'listen for and compile scripts over stdio']
+ ['-e', '--eval', 'compile a string from the command line']
+ ['-r', '--require [FILE*]', 'require a library before executing your script']
+ ['-b', '--bare', 'compile without the top-level function wrapper']
+ ['-t', '--tokens', 'print the tokens that the lexer produces']
+ ['-n', '--nodes', 'print the parse tree that Jison produces']
+ ['-v', '--version', 'display CoffeeScript version']
+ ['-h', '--help', 'display this help message']
+]
+
+# Top-level objects shared by all the functions.
+opts = {}
+sources = []
+optionParser = null
+
+# Run `coffee` by parsing passed options and determining what action to take.
+# Many flags cause us to divert before compiling anything. Flags passed after
+# `--` will be passed verbatim to your script as arguments in `process.argv`
+exports.run = ->
+ parseOptions()
+ return usage() if opts.help
+ return version() if opts.version
+ return require './repl' if opts.interactive
+ return compileStdio() if opts.stdio
+ return compileScript 'console', sources[0] if opts.eval
+ return require './repl' unless sources.length
+ separator = sources.indexOf '--'
+ flags = []
+ if separator >= 0
+ flags = sources.splice separator + 1
+ sources.pop()
+ if opts.run
+ flags = sources.splice(1).concat flags
+ process.ARGV = process.argv = flags
+ compileScripts()
+
+# 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.
+compileScripts = ->
+ for source in sources
+ base = source
+ compile = (source, topLevel) ->
+ path.exists source, (exists) ->
+ throw new Error "File not found: #{source}" unless exists
+ fs.stat source, (err, stats) ->
+ if stats.isDirectory()
+ fs.readdir source, (err, files) ->
+ for file in files
+ compile path.join(source, file)
+ else if topLevel or path.extname(source) is '.coffee'
+ fs.readFile source, (err, code) -> compileScript(source, code.toString(), base)
+ watch source, base if opts.watch
+ compile source, true
+
+# Compile a single source script, containing the given code, according to the
+# requested options. If evaluating the script directly sets `__filename`,
+# `__dirname` and `module.filename` to be correct relative to the script's path.
+compileScript = (file, input, base) ->
+ o = opts
+ options = compileOptions file
+ if o.require
+ require(if helpers.starts(req, '.') then fs.realpathSync(req) else req) for req in o.require
+ try
+ t = task = {file, input, options}
+ CoffeeScript.emit 'compile', task
+ if o.tokens then printTokens CoffeeScript.tokens t.input
+ else if o.nodes then puts CoffeeScript.nodes(t.input).toString().trim()
+ else if o.run then CoffeeScript.run t.input, t.options
+ else
+ t.output = CoffeeScript.compile t.input, t.options
+ CoffeeScript.emit 'success', task
+ if o.print then print t.output
+ else if o.compile then writeJs t.file, t.output, base
+ else if o.lint then lint t.output
+ catch err
+ # Avoid using 'error' as it is a special event -- if there is no handler,
+ # node will print a stack trace and exit the program.
+ CoffeeScript.emit 'failure', err, task
+ return if CoffeeScript.listeners('failure').length
+ return puts err.message if o.watch
+ error err.stack
+ process.exit 1
+
+# Attach the appropriate listeners to compile scripts incoming over **stdin**,
+# and write them back to **stdout**.
+compileStdio = ->
+ code = ''
+ stdin = process.openStdin()
+ stdin.on 'data', (buffer) ->
+ code += buffer.toString() if buffer
+ stdin.on 'end', ->
+ compileScript 'stdio', code
+
+# Watch a source CoffeeScript file using `fs.watchFile`, recompiling it every
+# time the file is updated. May be used in combination with other options,
+# such as `--lint` or `--print`.
+watch = (source, base) ->
+ fs.watchFile source, {persistent: true, interval: 500}, (curr, prev) ->
+ return if curr.size is prev.size and curr.mtime.getTime() is prev.mtime.getTime()
+ fs.readFile source, (err, code) ->
+ throw err if err
+ compileScript(source, code.toString(), base)
+
+# Write out a JavaScript source file with the compiled code. By default, files
+# are written out in `cwd` as `.js` files with the same name, but the output
+# directory can be customized with `--output`.
+writeJs = (source, js, base) ->
+ filename = path.basename(source, path.extname(source)) + '.js'
+ srcDir = path.dirname source
+ baseDir = srcDir.substring base.length
+ dir = if opts.output then path.join opts.output, baseDir else srcDir
+ jsPath = path.join dir, filename
+ compile = ->
+ js = ' ' if js.length <= 0
+ fs.writeFile jsPath, js, (err) ->
+ puts "Compiled #{source}" if opts.compile and opts.watch
+ path.exists dir, (exists) ->
+ if exists then compile() else exec "mkdir -p #{dir}", compile
+
+# Pipe compiled JS through JSLint (requires a working `jsl` command), printing
+# any errors or warnings that arise.
+lint = (js) ->
+ printIt = (buffer) -> puts buffer.toString().trim()
+ conf = __dirname + '/../extras/jsl.conf'
+ jsl = spawn 'jsl', ['-nologo', '-stdin', '-conf', conf]
+ jsl.stdout.on 'data', printIt
+ jsl.stderr.on 'data', printIt
+ jsl.stdin.write js
+ jsl.stdin.end()
+
+# Pretty-print a stream of tokens.
+printTokens = (tokens) ->
+ strings = for token in tokens
+ [tag, value] = [token[0], token[1].toString().replace(/\n/, '\\n')]
+ "[#{tag} #{value}]"
+ puts strings.join(' ')
+
+# Use the [OptionParser module](optparse.html) to extract all options from
+# `process.argv` that are specified in `SWITCHES`.
+parseOptions = ->
+ optionParser = new optparse.OptionParser SWITCHES, BANNER
+ o = opts = optionParser.parse process.argv.slice 2
+ o.compile or= !!o.output
+ o.run = not (o.compile or o.print or o.lint)
+ o.print = !! (o.print or (o.eval or o.stdio and o.compile))
+ sources = o.arguments
+
+# The compile-time options to pass to the CoffeeScript compiler.
+compileOptions = (fileName) -> {fileName, bare: opts.bare}
+
+# Print the `--help` usage message and exit.
+usage = ->
+ puts optionParser.help()
+ process.exit 0
+
+# Print the `--version` message and exit.
+version = ->
+ puts "CoffeeScript version #{CoffeeScript.VERSION}"
+ process.exit 0
--- /dev/null
+# The CoffeeScript parser is generated by [Jison](http://github.com/zaach/jison)
+# from this grammar file. Jison is a bottom-up parser generator, similar in
+# style to [Bison](http://www.gnu.org/software/bison), implemented in JavaScript.
+# It can recognize [LALR(1), LR(0), SLR(1), and LR(1)](http://en.wikipedia.org/wiki/LR_grammar)
+# 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
+# [attempts to match](http://en.wikipedia.org/wiki/Bottom-up_parsing)
+# the token sequence against the rules below. When a match can be made, it
+# reduces into the [nonterminal](http://en.wikipedia.org/wiki/Terminal_and_nonterminal_symbols)
+# (the enclosing name at the top), and we proceed from there.
+#
+# If you run the `cake build:parser` command, Jison constructs a parse table
+# from our rules and saves it into `lib/parser.js`.
+
+# The only dependency is on the **Jison.Parser**.
+Parser = require('jison').Parser
+
+# Jison DSL
+# ---------
+
+# 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.
+unwrap = /function\s*\(\)\s*\{\s*return\s*([\s\S]*);\s*\}/
+
+# Our handy DSL for Jison grammar generation, thanks to
+# [Tim Caswell](http://github.com/creationix). 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.
+o = (patternString, action, options) ->
+ return [patternString, '$$ = $1;', options] unless action
+ action = if match = (action + '').match(unwrap) then match[1] else "(#{action}())"
+ action = action.replace(/\bnew (\w+)\b/g, 'new yy.$1').replace(/Expressions\.wrap/g, 'yy.Expressions.wrap');
+ [patternString, "$$ = #{action};", options]
+
+# Grammatical Rules
+# -----------------
+
+# 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:
+#
+# "Expression UNLESS Expression"
+#
+# `$1` would be the value of the first `Expression`, `$2` would be the token
+# for the `UNLESS` terminal, and `$3` would be the value of the second
+# `Expression`.
+grammar =
+
+ # The **Root** is the top-level node in the syntax tree. Since we parse bottom-up,
+ # all parsing must end here.
+ Root: [
+ o "", -> new Expressions
+ o "TERMINATOR", -> new Expressions
+ o "Body"
+ o "Block TERMINATOR"
+ ]
+
+ # Any list of statements and expressions, seperated by line breaks or semicolons.
+ Body: [
+ o "Line", -> Expressions.wrap [$1]
+ o "Body TERMINATOR Line", -> $1.push $3
+ o "Body TERMINATOR"
+ ]
+
+ # Expressions and statements, which make up a line in a body.
+ Line: [
+ o "Expression"
+ o "Statement"
+ ]
+
+ # Pure statements which cannot be expressions.
+ Statement: [
+ o "Return"
+ o "Throw"
+ o "BREAK", -> new Literal $1
+ o "CONTINUE", -> new Literal $1
+ o "DEBUGGER", -> new Literal $1
+ ]
+
+ # All the different types of expressions in our language. The basic unit of
+ # CoffeeScript is the **Expression** -- everything that can be an expression
+ # is one. Expressions serve as the building blocks of many other rules, making
+ # them somewhat circular.
+ Expression: [
+ o "Value"
+ o "Invocation"
+ o "Code"
+ o "Operation"
+ o "Assign"
+ o "If"
+ o "Try"
+ o "While"
+ o "For"
+ o "Switch"
+ o "Extends"
+ o "Class"
+ o "Existence"
+ o "Comment"
+ ]
+
+ # An indented block of expressions. Note that the [Rewriter](rewriter.html)
+ # will convert some postfix forms into blocks for us, by adjusting the
+ # token stream.
+ Block: [
+ o "INDENT Body OUTDENT", -> $2
+ o "INDENT OUTDENT", -> new Expressions
+ o "TERMINATOR Comment", -> Expressions.wrap [$2]
+ ]
+
+ # A literal identifier, a variable name or property.
+ Identifier: [
+ o "IDENTIFIER", -> new Literal $1
+ ]
+
+ # Alphanumerics are separated from the other **Literal** matchers because
+ # they can also serve as keys in object literals.
+ AlphaNumeric: [
+ o "NUMBER", -> new Literal $1
+ o "STRING", -> new Literal $1
+ ]
+
+ # All of our immediate values. These can (in general), be passed straight
+ # through and printed to JavaScript.
+ Literal: [
+ o "AlphaNumeric"
+ o "JS", -> new Literal $1
+ o "REGEX", -> new Literal $1
+ o "BOOL", -> new Literal $1
+ ]
+
+ # Assignment of a variable, property, or index to a value.
+ Assign: [
+ o "Assignable = Expression", -> new Assign $1, $3
+ o "Assignable = INDENT Expression OUTDENT", -> new Assign $1, $4
+ ]
+
+ # Assignment when it happens within an object literal. The difference from
+ # the ordinary **Assign** is that these allow numbers and strings as keys.
+ AssignObj: [
+ o "Identifier", -> new Value $1
+ o "AlphaNumeric"
+ o "ThisProperty"
+ o "Identifier : Expression", -> new Assign new Value($1), $3, 'object'
+ o "AlphaNumeric : Expression", -> new Assign new Value($1), $3, 'object'
+ o "Identifier : INDENT Expression OUTDENT", -> new Assign new Value($1), $4, 'object'
+ o "AlphaNumeric : INDENT Expression OUTDENT", -> new Assign new Value($1), $4, 'object'
+ o "Comment"
+ ]
+
+ # A return statement from a function body.
+ Return: [
+ o "RETURN Expression", -> new Return $2
+ o "RETURN", -> new Return
+ ]
+
+ # A block comment.
+ Comment: [
+ o "HERECOMMENT", -> new Comment $1
+ ]
+
+ # [The existential operator](http://jashkenas.github.com/coffee-script/#existence).
+ Existence: [
+ o "Expression ?", -> new Existence $1
+ ]
+
+ # The **Code** node is the function literal. It's defined by an indented block
+ # of **Expressions** preceded by a function arrow, with an optional parameter
+ # list.
+ Code: [
+ o "PARAM_START ParamList PARAM_END FuncGlyph Block", -> new Code $2, $5, $4
+ o "FuncGlyph Block", -> new Code [], $2, $1
+ ]
+
+ # CoffeeScript has two different symbols for functions. `->` is for ordinary
+ # functions, and `=>` is for functions bound to the current value of *this*.
+ FuncGlyph: [
+ o "->", -> 'func'
+ o "=>", -> 'boundfunc'
+ ]
+
+ # An optional, trailing comma.
+ OptComma: [
+ o ''
+ o ','
+ ]
+
+ # The list of parameters that a function accepts can be of any length.
+ ParamList: [
+ o "", -> []
+ o "Param", -> [$1]
+ o "ParamList , Param", -> $1.concat $3
+ ]
+
+ # A single parameter in a function definition can be ordinary, or a splat
+ # that hoovers up the remaining arguments.
+ Param: [
+ o "PARAM", -> new Literal $1
+ o "@ PARAM", -> new Param $2, true
+ o "PARAM ...", -> new Param $1, false, true
+ o "@ PARAM ...", -> new Param $2, true, true
+ ]
+
+ # A splat that occurs outside of a parameter list.
+ Splat: [
+ o "Expression ...", -> new Splat $1
+ ]
+
+ # Variables and properties that can be assigned to.
+ SimpleAssignable: [
+ o "Identifier", -> new Value $1
+ o "Value Accessor", -> $1.push $2
+ o "Invocation Accessor", -> new Value $1, [$2]
+ o "ThisProperty"
+ ]
+
+ # Everything that can be assigned to.
+ Assignable: [
+ o "SimpleAssignable"
+ o "Array", -> new Value $1
+ o "Object", -> new Value $1
+ ]
+
+ # The types of things that can be treated as values -- assigned to, invoked
+ # as functions, indexed into, named as a class, etc.
+ Value: [
+ o "Assignable"
+ o "Literal", -> new Value $1
+ o "Parenthetical", -> new Value $1
+ o "Range", -> new Value $1
+ o "This"
+ ]
+
+ # The general group of accessors into an object, by property, by prototype
+ # or by array index or slice.
+ Accessor: [
+ o "PROPERTY_ACCESS Identifier", -> new Accessor $2
+ o "PROTOTYPE_ACCESS Identifier", -> new Accessor $2, 'prototype'
+ o "::", -> new Accessor(new Literal('prototype'))
+ o "SOAK_ACCESS Identifier", -> new Accessor $2, 'soak'
+ o "Index"
+ o "Slice", -> new Slice $1
+ ]
+
+ # Indexing into an object or array using bracket notation.
+ Index: [
+ o "INDEX_START Expression INDEX_END", -> new Index $2
+ o "INDEX_SOAK Index", -> $2.soakNode = yes; $2
+ o "INDEX_PROTO Index", -> $2.proto = yes; $2
+ ]
+
+ # In CoffeeScript, an object literal is simply a list of assignments.
+ Object: [
+ o "{ AssignList OptComma }", -> new ObjectLiteral $2
+ ]
+
+ # Assignment of properties within an object literal can be separated by
+ # comma, as in JavaScript, or simply by newline.
+ AssignList: [
+ o "", -> []
+ o "AssignObj", -> [$1]
+ o "AssignList , AssignObj", -> $1.concat $3
+ o "AssignList OptComma TERMINATOR AssignObj", -> $1.concat $4
+ o "AssignList OptComma INDENT AssignList OptComma OUTDENT", -> $1.concat $4
+ ]
+
+ # Class definitions have optional bodies of prototype property assignments,
+ # and optional references to the superclass.
+ Class: [
+ o "CLASS SimpleAssignable", -> new Class $2
+ o "CLASS SimpleAssignable EXTENDS Value", -> new Class $2, $4
+ o "CLASS SimpleAssignable INDENT ClassBody OUTDENT", -> new Class $2, null, $4
+ o "CLASS SimpleAssignable EXTENDS Value INDENT ClassBody OUTDENT", -> new Class $2, $4, $6
+ o "CLASS INDENT ClassBody OUTDENT", -> new Class '__temp__', null, $3
+ o "CLASS", -> new Class '__temp__', null, new Expressions
+ o "CLASS EXTENDS Value", -> new Class '__temp__', $3, new Expressions
+ o "CLASS EXTENDS Value INDENT ClassBody OUTDENT", -> new Class '__temp__', $3, $5
+ ]
+
+ # Assignments that can happen directly inside a class declaration.
+ ClassAssign: [
+ o "AssignObj", -> $1
+ o "ThisProperty : Expression", -> new Assign new Value($1), $3, 'this'
+ o "ThisProperty : INDENT Expression OUTDENT", -> new Assign new Value($1), $4, 'this'
+ ]
+
+ # A list of assignments to a class.
+ ClassBody: [
+ o "", -> []
+ o "ClassAssign", -> [$1]
+ o "ClassBody TERMINATOR ClassAssign", -> $1.concat $3
+ o "{ ClassBody }", -> $2
+ ]
+
+ # Extending an object by setting its prototype chain to reference a parent
+ # object.
+ Extends: [
+ o "SimpleAssignable EXTENDS Value", -> new Extends $1, $3
+ ]
+
+ # Ordinary function invocation, or a chained series of calls.
+ Invocation: [
+ o "Value OptFuncExist Arguments", -> new Call $1, $3, $2
+ o "Invocation OptFuncExist Arguments", -> new Call $1, $3, $2
+ o "SUPER", -> new Call 'super', [new Splat(new Literal('arguments'))]
+ o "SUPER Arguments", -> new Call 'super', $2
+ ]
+
+ # An optional existence check on a function.
+ OptFuncExist: [
+ o "", -> no
+ o "FUNC_EXIST", -> yes
+ ]
+
+ # The list of arguments to a function call.
+ Arguments: [
+ o "CALL_START CALL_END", -> []
+ o "CALL_START ArgList OptComma CALL_END", -> $2
+ ]
+
+ # A reference to the *this* current object.
+ This: [
+ o "THIS", -> new Value new Literal 'this'
+ o "@", -> new Value new Literal 'this'
+ ]
+
+ RangeDots: [
+ o "..", -> 'inclusive'
+ o "...", -> 'exclusive'
+ ]
+
+ # A reference to a property on *this*.
+ ThisProperty: [
+ o "@ Identifier", -> new Value new Literal('this'), [new Accessor($2)], 'this'
+ ]
+
+ # The CoffeeScript range literal.
+ Range: [
+ o "[ Expression RangeDots Expression ]", -> new Range $2, $4, $3
+ ]
+
+ # The slice literal.
+ Slice: [
+ o "INDEX_START Expression RangeDots Expression INDEX_END", -> new Range $2, $4, $3
+ o "INDEX_START Expression RangeDots INDEX_END", -> new Range $2, null, $3
+ o "INDEX_START RangeDots Expression INDEX_END", -> new Range null, $3, $2
+ ]
+
+ # The array literal.
+ Array: [
+ o "[ ]", -> new ArrayLiteral []
+ o "[ ArgList OptComma ]", -> new ArrayLiteral $2
+ ]
+
+ # The **ArgList** 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.
+ ArgList: [
+ o "Arg", -> [$1]
+ o "ArgList , Arg", -> $1.concat $3
+ o "ArgList OptComma TERMINATOR Arg", -> $1.concat $4
+ o "INDENT ArgList OptComma OUTDENT", -> $2
+ o "ArgList OptComma INDENT ArgList OptComma OUTDENT", -> $1.concat $4
+ ]
+
+ # Valid arguments are Expressions or Splats.
+ Arg: [
+ o "Expression"
+ o "Splat"
+ ]
+
+ # Just simple, comma-separated, required arguments (no fancy syntax). We need
+ # this to be separate from the **ArgList** for use in **Switch** blocks, where
+ # having the newlines wouldn't make sense.
+ SimpleArgs: [
+ o "Expression"
+ o "SimpleArgs , Expression", -> [].concat $1, $3
+ ]
+
+ # The variants of *try/catch/finally* exception handling blocks.
+ Try: [
+ o "TRY Block", -> new Try $2
+ o "TRY Block Catch", -> new Try $2, $3[0], $3[1]
+ o "TRY Block FINALLY Block", -> new Try $2, null, null, $4
+ o "TRY Block Catch FINALLY Block", -> new Try $2, $3[0], $3[1], $5
+ ]
+
+ # A catch clause names its error and runs a block of code.
+ Catch: [
+ o "CATCH Identifier Block", -> [$2, $3]
+ ]
+
+ # Throw an exception object.
+ Throw: [
+ o "THROW Expression", -> new Throw $2
+ ]
+
+ # Parenthetical expressions. Note that the **Parenthetical** is a **Value**,
+ # not an **Expression**, 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.
+ Parenthetical: [
+ o "( Expression )", -> new Parens $2
+ o "( )", -> new Parens new Literal ''
+ ]
+
+ # The condition portion of a while loop.
+ WhileSource: [
+ o "WHILE Expression", -> new While $2
+ o "WHILE Expression WHEN Expression", -> new While $2, guard: $4
+ o "UNTIL Expression", -> new While $2, invert: true
+ o "UNTIL Expression WHEN Expression", -> new While $2, invert: true, guard: $4
+ ]
+
+ # 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.
+ While: [
+ o "WhileSource Block", -> $1.addBody $2
+ o "Statement WhileSource", -> $2.addBody Expressions.wrap [$1]
+ o "Expression WhileSource", -> $2.addBody Expressions.wrap [$1]
+ o "Loop", -> $1
+ ]
+
+ Loop: [
+ o "LOOP Block", -> new While(new Literal 'true').addBody $2
+ o "LOOP Expression", -> new While(new Literal 'true').addBody Expressions.wrap [$2]
+ ]
+
+ # 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.
+ For: [
+ o "Statement ForBody", -> new For $1, $2, $2.vars[0], $2.vars[1]
+ o "Expression ForBody", -> new For $1, $2, $2.vars[0], $2.vars[1]
+ o "ForBody Block", -> new For $2, $1, $1.vars[0], $1.vars[1]
+ ]
+
+ ForBody: [
+ o "FOR Range", -> source: new Value($2), vars: []
+ o "ForStart ForSource", -> $2.raw = $1.raw; $2.vars = $1; $2
+ ]
+
+ ForStart: [
+ o "FOR ForVariables", -> $2
+ o "FOR ALL ForVariables", -> $3.raw = true; $3
+ ]
+
+ # An array of all accepted values for a variable inside the loop. This
+ # enables support for pattern matching.
+ ForValue: [
+ o "Identifier"
+ o "Array", -> new Value $1
+ o "Object", -> new Value $1
+ ]
+
+ # An array or range comprehension has variables for the current element and
+ # (optional) reference to the current index. Or, *key, value*, in the case
+ # of object comprehensions.
+ ForVariables: [
+ o "ForValue", -> [$1]
+ o "ForValue , ForValue", -> [$1, $3]
+ ]
+
+ # 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.
+ ForSource: [
+ o "FORIN Expression", -> source: $2
+ o "FOROF Expression", -> source: $2, object: true
+ o "FORIN Expression WHEN Expression", -> source: $2, guard: $4
+ o "FOROF Expression WHEN Expression", -> source: $2, guard: $4, object: true
+ o "FORIN Expression BY Expression", -> source: $2, step: $4
+ o "FORIN Expression WHEN Expression BY Expression", -> source: $2, guard: $4, step: $6
+ o "FORIN Expression BY Expression WHEN Expression", -> source: $2, step: $4, guard: $6
+ ]
+
+ Switch: [
+ o "SWITCH Expression INDENT Whens OUTDENT", -> new Switch $2, $4
+ o "SWITCH Expression INDENT Whens ELSE Block OUTDENT", -> new Switch $2, $4, $6
+ o "SWITCH INDENT Whens OUTDENT", -> new Switch null, $3
+ o "SWITCH INDENT Whens ELSE Block OUTDENT", -> new Switch null, $3, $5
+ ]
+
+ Whens: [
+ o "When"
+ o "Whens When", -> $1.concat $2
+ ]
+
+ # An individual **When** clause, with action.
+ When: [
+ o "LEADING_WHEN SimpleArgs Block", -> [[$2, $3]]
+ o "LEADING_WHEN SimpleArgs Block TERMINATOR", -> [[$2, $3]]
+ ]
+
+ # The most basic form of *if* is a condition and an action. The following
+ # if-related rules are broken up along these lines in order to avoid
+ # ambiguity.
+ IfBlock: [
+ o "IF Expression Block", -> new If $2, $3
+ o "UNLESS Expression Block", -> new If $2, $3, invert: true
+ o "IfBlock ELSE IF Expression Block", -> $1.addElse new If $4, $5
+ o "IfBlock ELSE Block", -> $1.addElse $3
+ ]
+
+ # The full complement of *if* expressions, including postfix one-liner
+ # *if* and *unless*.
+ If: [
+ o "IfBlock"
+ o "Statement POST_IF Expression", -> new If $3, Expressions.wrap([$1]), statement: true
+ o "Expression POST_IF Expression", -> new If $3, Expressions.wrap([$1]), statement: true
+ o "Statement POST_UNLESS Expression", -> new If $3, Expressions.wrap([$1]), statement: true, invert: true
+ o "Expression POST_UNLESS Expression", -> new If $3, Expressions.wrap([$1]), statement: true, invert: true
+ ]
+
+ # 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 *Operand OpSymbol Operand*
+ # -type rule, but in order to make the precedence binding possible, separate
+ # rules are necessary.
+ Operation: [
+ o "UNARY Expression", -> new Op $1, $2
+ o "- Expression", (-> new Op '-', $2), prec: 'UNARY'
+ o "+ Expression", (-> new Op '+', $2), prec: 'UNARY'
+
+ o "-- SimpleAssignable", -> new Op '--', $2
+ o "++ SimpleAssignable", -> new Op '++', $2
+ o "SimpleAssignable --", -> new Op '--', $1, null, true
+ o "SimpleAssignable ++", -> new Op '++', $1, null, true
+
+ o "Expression + Expression", -> new Op '+', $1, $3
+ o "Expression - Expression", -> new Op '-', $1, $3
+ o "Expression == Expression", -> new Op '==', $1, $3
+ o "Expression != Expression", -> new Op '!=', $1, $3
+
+ o "Expression MATH Expression", -> new Op $2, $1, $3
+ o "Expression SHIFT Expression", -> new Op $2, $1, $3
+ o "Expression COMPARE Expression", -> new Op $2, $1, $3
+ o "Expression LOGIC Expression", -> new Op $2, $1, $3
+ o "SimpleAssignable COMPOUND_ASSIGN Expression", -> new Op $2, $1, $3
+ o "SimpleAssignable COMPOUND_ASSIGN INDENT Expression OUTDENT", -> new Op $2, $1, $4
+
+ o "Expression RELATION Expression", ->
+ if $2.charAt(0) is '!'
+ if $2 is '!in'
+ new Op '!', new In $1, $3
+ else
+ new Op '!', new Parens new Op $2.slice(1), $1, $3
+ else
+ if $2 is 'in' then new In $1, $3 else new Op $2, $1, $3
+ ]
+
+
+# Precedence
+# ----------
+
+# Operators at the top of this list have higher precedence than the ones lower
+# down. Following these rules is what makes `2 + 3 * 4` parse as:
+#
+# 2 + (3 * 4)
+#
+# And not:
+#
+# (2 + 3) * 4
+operators = [
+ ["left", 'CALL_START', 'CALL_END']
+ ["nonassoc", '++', '--']
+ ["left", '?']
+ ["right", 'UNARY']
+ ["left", 'MATH']
+ ["left", '+', '-']
+ ["left", 'SHIFT']
+ ["left", 'COMPARE']
+ ["left", 'RELATION']
+ ["left", '==', '!=']
+ ["left", 'LOGIC']
+ ["right", 'COMPOUND_ASSIGN']
+ ["left", '.']
+ ["nonassoc", 'INDENT', 'OUTDENT']
+ ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'BY', 'THROW']
+ ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']
+ ["right", '=', ':', 'RETURN']
+ ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']
+]
+
+# Wrapping Up
+# -----------
+
+# Finally, now what we have our **grammar** and our **operators**, we can create
+# our **Jison.Parser**. 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".
+tokens = []
+for name, alternatives of grammar
+ grammar[name] = for alt in alternatives
+ for token in alt[0].split ' '
+ tokens.push token unless grammar[token]
+ alt[1] = "return #{alt[1]}" if name is 'Root'
+ alt
+
+# Initialize the **Parser** with our list of terminal **tokens**, our **grammar**
+# 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 [Yacc](http://dinosaur.compilertools.net/yacc/index.html)).
+exports.parser = new Parser
+ tokens: tokens.join ' '
+ bnf: grammar
+ operators: operators.reverse()
+ startSymbol: 'Root'
--- /dev/null
+# This file contains the common helper functions that we'd like to share among
+# the **Lexer**, **Rewriter**, and the **Nodes**. Merge objects, flatten
+# arrays, count characters, that sort of thing.
+
+# Cross-engine `indexOf`, so that JScript can join the party. Use SpiderMonkey's
+# functional-style `indexOf`, if it's available.
+indexOf = exports.indexOf = Array.indexOf or
+ if Array::indexOf
+ (array, item, from) -> array.indexOf item, from
+ else
+ (array, item, from) ->
+ for other, index in array
+ if other is item and (not from or from <= index)
+ return index
+ -1
+
+# Does a list include a value?
+exports.include = (list, value) ->
+ indexOf(list, value) >= 0
+
+# Peek at the beginning of a given string to see if it matches a sequence.
+exports.starts = (string, literal, start) ->
+ literal is string.substr start, literal.length
+
+# Peek at the end of a given string to see if it matches a sequence.
+exports.ends = (string, literal, back) ->
+ len = literal.length
+ literal is string.substr string.length - len - (back or 0), len
+
+# Trim out all falsy values from an array.
+exports.compact = (array) ->
+ item for item in array when item
+
+# Count the number of occurences of a character in a string.
+exports.count = (string, letter) ->
+ num = pos = 0
+ num++ while pos = 1 + string.indexOf letter, pos
+ num
+
+# Merge objects, returning a fresh copy with attributes from both sides.
+# Used every time `Base#compile` is called, to allow properties in the
+# options hash to propagate down the tree without polluting other branches.
+exports.merge = (options, overrides) ->
+ extend (extend {}, options), overrides
+
+# Extend a source object with the properties of another object (shallow copy).
+# We use this to simulate Node's deprecated `process.mixin`.
+extend = exports.extend = (object, properties) ->
+ for all key, val of properties
+ object[key] = val
+ object
+
+# Return a flattened version of an array.
+# Handy for getting a list of `children` from the nodes.
+exports.flatten = flatten = (array) ->
+ flattened = []
+ for element in array
+ if element instanceof Array
+ flattened = flattened.concat flatten element
+ else
+ flattened.push element
+ flattened
+
+# Delete a key from an object, returning the value. Useful when a node is
+# looking for a particular method in an options hash.
+exports.del = (obj, key) ->
+ val = obj[key]
+ delete obj[key]
+ val
+
+# Gets the last item of an array(-like) object.
+exports.last = (array, back) -> array[array.length - (back or 0) - 1]
--- /dev/null
+# Loader for CoffeeScript as a Node.js library.
+(exports[key] = val) for key, val of require './coffee-script'
\ No newline at end of file
--- /dev/null
+# The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
+# matches against the beginning of the source code. When a match is found,
+# a token is produced, we consume the match, and start again. Tokens are in the
+# form:
+#
+# [tag, value, lineNumber]
+#
+# Which is a format that can be fed directly into [Jison](http://github.com/zaach/jison).
+
+{Rewriter} = require './rewriter'
+
+# Import the helpers we need.
+{include, count, starts, compact, last} = require './helpers'
+
+# The Lexer Class
+# ---------------
+
+# The Lexer class reads a stream of CoffeeScript and divvys it up into tagged
+# tokens. Some potential ambiguity in the grammar has been avoided by
+# pushing some extra smarts into the Lexer.
+exports.Lexer = class Lexer
+
+ # **tokenize** is the Lexer's main method. Scan by attempting to match tokens
+ # one at a time, using a regular expression anchored at the start of the
+ # remaining code, or a custom recursive token-matching method
+ # (for interpolations). When the next token has been recorded, we move forward
+ # within the code past the token, and begin again.
+ #
+ # Each tokenizing method is responsible for incrementing `@i` by the number of
+ # characters it has consumed. `@i` can be thought of as our finger on the page
+ # of source.
+ #
+ # Before returning the token stream, run it through the [Rewriter](rewriter.html)
+ # unless explicitly asked not to.
+ tokenize: (code, options) ->
+ code = code.replace(/\r/g, '').replace TRAILING_SPACES, ''
+ o = options or {}
+ @code = code # The remainder of the source code.
+ @i = 0 # Current character position we're parsing.
+ @line = o.line or 0 # The current line.
+ @indent = 0 # The current indentation level.
+ @indebt = 0 # The over-indentation at the current level.
+ @outdebt = 0 # The under-outdentation at the current level.
+ @seenFor = no # The flag for distinguishing FORIN/FOROF from IN/OF.
+ @indents = [] # The stack of all current indentation levels.
+ @tokens = [] # Stream of parsed tokens in the form ['TYPE', value, line]
+ # At every position, run through this list of attempted matches,
+ # short-circuiting if any of them succeed. Their order determines precedence:
+ # `@literalToken` is the fallback catch-all.
+ while @chunk = code.slice @i
+ @identifierToken() or
+ @commentToken() or
+ @whitespaceToken() or
+ @lineToken() or
+ @heredocToken() or
+ @stringToken() or
+ @numberToken() or
+ @regexToken() or
+ @jsToken() or
+ @literalToken()
+ @closeIndentation()
+ return @tokens if o.rewrite is off
+ (new Rewriter).rewrite @tokens
+
+ # Tokenizers
+ # ----------
+
+ # Matches identifying literals: variables, keywords, method names, etc.
+ # Check to ensure that JavaScript reserved words aren't being used as
+ # identifiers. Because CoffeeScript reserves a handful of keywords that are
+ # allowed in JavaScript, we're careful not to tag them as keywords when
+ # referenced as property names here, so you can still do `jQuery.is()` even
+ # though `is` means `===` otherwise.
+ identifierToken: ->
+ return false unless match = IDENTIFIER.exec @chunk
+ [input, id, colon] = match
+ @i += input.length
+ if id is 'all' and @tag() is 'FOR'
+ @token 'ALL', id
+ return true
+ forcedIdentifier = colon or @tagAccessor()
+ tag = 'IDENTIFIER'
+ if include(JS_KEYWORDS, id) or
+ not forcedIdentifier and include(COFFEE_KEYWORDS, id)
+ tag = id.toUpperCase()
+ if tag is 'WHEN' and include LINE_BREAK, @tag()
+ tag = 'LEADING_WHEN'
+ else if tag is 'FOR'
+ @seenFor = yes
+ else if include UNARY, tag
+ tag = 'UNARY'
+ else if include RELATION, tag
+ if tag isnt 'INSTANCEOF' and @seenFor
+ @seenFor = no
+ tag = 'FOR' + tag
+ else
+ tag = 'RELATION'
+ if @value() is '!'
+ @tokens.pop()
+ id = '!' + id
+ if include JS_FORBIDDEN, id
+ if forcedIdentifier
+ tag = 'IDENTIFIER'
+ id = new String id
+ id.reserved = yes
+ else if include RESERVED, id
+ @identifierError id
+ unless forcedIdentifier
+ tag = id = COFFEE_ALIASES[id] if COFFEE_ALIASES.hasOwnProperty id
+ if id is '!'
+ tag = 'UNARY'
+ else if include LOGIC, id
+ tag = 'LOGIC'
+ else if include BOOL, tag
+ id = tag.toLowerCase()
+ tag = 'BOOL'
+ @token tag, id
+ @token ':', ':' if colon
+ true
+
+ # Matches numbers, including decimals, hex, and exponential notation.
+ # Be careful not to interfere with ranges-in-progress.
+ numberToken: ->
+ return false unless match = NUMBER.exec @chunk
+ number = match[0]
+ return false if @tag() is '.' and number.charAt(0) is '.'
+ @i += number.length
+ @token 'NUMBER', number
+ true
+
+ # Matches strings, including multi-line strings. Ensures that quotation marks
+ # are balanced within the string's contents, and within nested interpolations.
+ stringToken: ->
+ switch @chunk.charAt 0
+ when "'"
+ return false unless match = SIMPLESTR.exec @chunk
+ @token 'STRING', (string = match[0]).replace MULTILINER, '\\\n'
+ when '"'
+ return false unless string = @balancedString @chunk, [['"', '"'], ['#{', '}']]
+ if 0 < string.indexOf '#{', 1
+ @interpolateString string.slice 1, -1
+ else
+ @token 'STRING', @escapeLines string
+ else
+ return false
+ @line += count string, '\n'
+ @i += string.length
+ true
+
+ # Matches heredocs, adjusting indentation to the correct level, as heredocs
+ # preserve whitespace, but ignore indentation to the left.
+ heredocToken: ->
+ return false unless match = HEREDOC.exec @chunk
+ heredoc = match[0]
+ quote = heredoc.charAt 0
+ doc = @sanitizeHeredoc match[2], {quote, indent: null}
+ if quote is '"' and 0 <= doc.indexOf '#{'
+ @interpolateString doc, heredoc: yes
+ else
+ @token 'STRING', @makeString doc, quote, yes
+ @line += count heredoc, '\n'
+ @i += heredoc.length
+ true
+
+ # Matches and consumes comments.
+ commentToken: ->
+ return false unless match = @chunk.match COMMENT
+ [comment, here] = match
+ @line += count comment, '\n'
+ @i += comment.length
+ if here
+ @token 'HERECOMMENT', @sanitizeHeredoc here,
+ herecomment: true, indent: Array(@indent + 1).join(' ')
+ @token 'TERMINATOR', '\n'
+ true
+
+ # Matches JavaScript interpolated directly into the source via backticks.
+ jsToken: ->
+ return false unless @chunk.charAt(0) is '`' and match = JSTOKEN.exec @chunk
+ @token 'JS', (script = match[0]).slice 1, -1
+ @i += script.length
+ true
+
+ # Matches regular expression literals. Lexing regular expressions is difficult
+ # to distinguish from division, so we borrow some basic heuristics from
+ # JavaScript and Ruby.
+ regexToken: ->
+ return false if @chunk.charAt(0) isnt '/'
+ return @heregexToken match if match = HEREGEX.exec @chunk
+ return false if include NOT_REGEX, @tag()
+ return false unless match = REGEX.exec @chunk
+ [regex] = match
+ @token 'REGEX', if regex is '//' then '/(?:)/' else regex
+ @i += regex.length
+ true
+
+ # Matches experimental, multiline and extended regular expression literals.
+ heregexToken: (match) ->
+ [heregex, body, flags] = match
+ @i += heregex.length
+ if 0 > body.indexOf '#{'
+ re = body.replace(HEREGEX_OMIT, '').replace(/\//g, '\\/')
+ @token 'REGEX', "/#{ re or '(?:)' }/#{flags}"
+ return true
+ @token 'IDENTIFIER', 'RegExp'
+ @tokens.push ['CALL_START', '(']
+ tokens = []
+ for [tag, value] in @interpolateString(body, regex: yes)
+ if tag is 'TOKENS'
+ tokens.push value...
+ else
+ continue unless value = value.replace HEREGEX_OMIT, ''
+ value = value.replace /\\/g, '\\\\'
+ tokens.push ['STRING', @makeString(value, '"', yes)]
+ tokens.push ['+', '+']
+ tokens.pop()
+ @tokens.push ['STRING', '""'], ['+', '+'] unless tokens[0]?[0] is 'STRING'
+ @tokens.push tokens...
+ @tokens.push [',', ','], ['STRING', '"' + flags + '"'] if flags
+ @token ')', ')'
+ true
+
+ # Matches newlines, indents, and outdents, and determines which is which.
+ # If we can detect that the current line is continued onto the the next line,
+ # then the newline is suppressed:
+ #
+ # elements
+ # .each( ... )
+ # .map( ... )
+ #
+ # Keeps track of the level of indentation, because a single outdent token
+ # can close multiple indents, so we need to know how far in we happen to be.
+ lineToken: ->
+ return false unless match = MULTI_DENT.exec @chunk
+ indent = match[0]
+ @line += count indent, '\n'
+ @i += indent.length
+ prev = last @tokens, 1
+ size = indent.length - 1 - indent.lastIndexOf '\n'
+ nextCharacter = NEXT_CHARACTER.exec(@chunk)[1]
+ noNewlines = (nextCharacter in ['.', ','] and not NEXT_ELLIPSIS.test(@chunk)) or @unfinished()
+ if size - @indebt is @indent
+ return @suppressNewlines() if noNewlines
+ return @newlineToken indent
+ else if size > @indent
+ if noNewlines
+ @indebt = size - @indent
+ return @suppressNewlines()
+ diff = size - @indent + @outdebt
+ @token 'INDENT', diff
+ @indents.push diff
+ @outdebt = @indebt = 0
+ else
+ @indebt = 0
+ @outdentToken @indent - size, noNewlines
+ @indent = size
+ true
+
+ # Record an outdent token or multiple tokens, if we happen to be moving back
+ # inwards past several recorded indents.
+ outdentToken: (moveOut, noNewlines, close) ->
+ while moveOut > 0
+ len = @indents.length - 1
+ if @indents[len] is undefined
+ moveOut = 0
+ else if @indents[len] is @outdebt
+ moveOut -= @outdebt
+ @outdebt = 0
+ else if @indents[len] < @outdebt
+ @outdebt -= @indents[len]
+ moveOut -= @indents[len]
+ else
+ dent = @indents.pop() - @outdebt
+ moveOut -= dent
+ @outdebt = 0
+ @token 'OUTDENT', dent
+ @outdebt -= moveOut if dent
+ @token 'TERMINATOR', '\n' unless @tag() is 'TERMINATOR' or noNewlines
+ true
+
+ # Matches and consumes non-meaningful whitespace. Tag the previous token
+ # as being "spaced", because there are some cases where it makes a difference.
+ whitespaceToken: ->
+ return false unless match = WHITESPACE.exec @chunk
+ prev = last @tokens
+ prev.spaced = true if prev
+ @i += match[0].length
+ true
+
+ # Generate a newline token. Consecutive newlines get merged together.
+ newlineToken: (newlines) ->
+ @token 'TERMINATOR', '\n' unless @tag() is 'TERMINATOR'
+ true
+
+ # Use a `\` at a line-ending to suppress the newline.
+ # The slash is removed here once its job is done.
+ suppressNewlines: ->
+ @tokens.pop() if @value() is '\\'
+ true
+
+ # We treat all other single characters as a token. Eg.: `( ) , . !`
+ # Multi-character operators are also literal tokens, so that Jison can assign
+ # the proper order of operations. There are some symbols that we tag specially
+ # here. `;` and newlines are both treated as a `TERMINATOR`, we distinguish
+ # parentheses that indicate a method call from regular parentheses, and so on.
+ literalToken: ->
+ if match = OPERATOR.exec @chunk
+ [value] = match
+ @tagParameters() if CODE.test value
+ else
+ value = @chunk.charAt 0
+ @i += value.length
+ tag = value
+ prev = last @tokens
+ if value is '=' and prev
+ @assignmentError() if not prev[1].reserved and include JS_FORBIDDEN, prev[1]
+ if prev[1] in ['||', '&&']
+ prev[0] = 'COMPOUND_ASSIGN'
+ prev[1] += '='
+ return true
+ if ';' is value then tag = 'TERMINATOR'
+ else if include LOGIC , value then tag = 'LOGIC'
+ else if include MATH , value then tag = 'MATH'
+ else if include COMPARE , value then tag = 'COMPARE'
+ else if include COMPOUND_ASSIGN, value then tag = 'COMPOUND_ASSIGN'
+ else if include UNARY , value then tag = 'UNARY'
+ else if include SHIFT , value then tag = 'SHIFT'
+ else if value is '?' and prev?.spaced then tag = 'LOGIC'
+ else if prev and not prev.spaced
+ if value is '(' and include CALLABLE, prev[0]
+ prev[0] = 'FUNC_EXIST' if prev[0] is '?'
+ tag = 'CALL_START'
+ else if value is '[' and include INDEXABLE, prev[0]
+ tag = 'INDEX_START'
+ switch prev[0]
+ when '?' then prev[0] = 'INDEX_SOAK'
+ when '::' then prev[0] = 'INDEX_PROTO'
+ @token tag, value
+ true
+
+ # Token Manipulators
+ # ------------------
+
+ # As we consume a new `IDENTIFIER`, look at the previous token to determine
+ # if it's a special kind of accessor. Return `true` if any type of accessor
+ # is the previous token.
+ tagAccessor: ->
+ return false if not (prev = last @tokens) or prev.spaced
+ if prev[1] is '::'
+ @tag 0, 'PROTOTYPE_ACCESS'
+ else if prev[1] is '.' and @value(1) isnt '.'
+ if @tag(1) is '?'
+ @tag 0, 'SOAK_ACCESS'
+ @tokens.splice(-2, 1)
+ else
+ @tag 0, 'PROPERTY_ACCESS'
+ else
+ return prev[0] is '@'
+ true
+
+ # Sanitize a heredoc or herecomment by
+ # erasing all external indentation on the left-hand side.
+ sanitizeHeredoc: (doc, options) ->
+ {indent, herecomment} = options
+ return doc if herecomment and 0 > doc.indexOf '\n'
+ unless herecomment
+ while match = HEREDOC_INDENT.exec doc
+ attempt = match[1]
+ indent = attempt if indent is null or 0 < attempt.length < indent.length
+ doc = doc.replace /// \n #{indent} ///g, '\n' if indent
+ doc = doc.replace /^\n/, '' unless herecomment
+ doc
+
+ # A source of ambiguity in our grammar used to be parameter lists in function
+ # definitions versus argument lists in function calls. Walk backwards, tagging
+ # parameters specially in order to make things easier for the parser.
+ tagParameters: ->
+ return if @tag() isnt ')'
+ i = @tokens.length
+ while tok = @tokens[--i]
+ switch tok[0]
+ when 'IDENTIFIER' then tok[0] = 'PARAM'
+ when ')' then tok[0] = 'PARAM_END'
+ when '(', 'CALL_START' then tok[0] = 'PARAM_START'; return true
+ true
+
+ # Close up all remaining open blocks at the end of the file.
+ closeIndentation: ->
+ @outdentToken @indent
+
+ # The error for when you try to use a forbidden word in JavaScript as
+ # an identifier.
+ identifierError: (word) ->
+ throw SyntaxError "Reserved word \"#{word}\" on line #{@line + 1}"
+
+ # The error for when you try to assign to a reserved word in JavaScript,
+ # like "function" or "default".
+ assignmentError: ->
+ throw SyntaxError "Reserved word \"#{@value()}\" on line #{@line + 1} can't be assigned"
+
+ # Matches a balanced group such as a single or double-quoted string. Pass in
+ # a series of delimiters, all of which must be nested correctly within the
+ # contents of the string. This method allows us to have strings within
+ # interpolations within strings, ad infinitum.
+ balancedString: (str, delimited, options) ->
+ options or= {}
+ levels = []
+ i = 0
+ slen = str.length
+ while i < slen
+ if levels.length and str.charAt(i) is '\\'
+ i += 1
+ else
+ for pair in delimited
+ [open, close] = pair
+ if levels.length and starts(str, close, i) and last(levels) is pair
+ levels.pop()
+ i += close.length - 1
+ i += 1 unless levels.length
+ break
+ if starts str, open, i
+ levels.push(pair)
+ i += open.length - 1
+ break
+ break if not levels.length
+ i += 1
+ if levels.length
+ throw SyntaxError "Unterminated #{levels.pop()[0]} starting on line #{@line + 1}"
+ if not i then false else str[0...i]
+
+ # Expand variables and expressions inside double-quoted strings using
+ # Ruby-like notation for substitution of arbitrary expressions.
+ #
+ # "Hello #{name.capitalize()}."
+ #
+ # If it encounters an interpolation, this method will recursively create a
+ # new Lexer, tokenize the interpolated contents, and merge them into the
+ # token stream.
+ interpolateString: (str, options) ->
+ {heredoc, regex} = options or= {}
+ tokens = []
+ pi = 0
+ i = -1
+ while letter = str.charAt i += 1
+ if letter is '\\'
+ i += 1
+ continue
+ unless letter is '#' and str.charAt(i+1) is '{' and
+ (expr = @balancedString str.slice(i+1), [['{', '}']])
+ continue
+ tokens.push ['TO_BE_STRING', str.slice(pi, i)] if pi < i
+ inner = expr.slice(1, -1).replace(LEADING_SPACES, '').replace(TRAILING_SPACES, '')
+ if inner.length
+ nested = new Lexer().tokenize inner, line: @line, rewrite: off
+ nested.pop()
+ if nested.length > 1
+ nested.unshift ['(', '(']
+ nested.push [')', ')']
+ tokens.push ['TOKENS', nested]
+ i += expr.length
+ pi = i + 1
+ tokens.push ['TO_BE_STRING', str.slice pi] if i > pi < str.length
+ return tokens if regex
+ return @token 'STRING', '""' unless tokens.length
+ tokens.unshift ['', ''] unless tokens[0][0] is 'TO_BE_STRING'
+ @token '(', '(' if interpolated = tokens.length > 1
+ for [tag, value], i in tokens
+ @token '+', '+' if i
+ if tag is 'TOKENS'
+ @tokens.push value...
+ else
+ @token 'STRING', @makeString value, '"', heredoc
+ @token ')', ')' if interpolated
+ tokens
+
+ # Helpers
+ # -------
+
+ # Add a token to the results, taking note of the line number.
+ token: (tag, value) ->
+ @tokens.push [tag, value, @line]
+
+ # Peek at a tag/value in the current token stream.
+ tag : (index, tag) ->
+ (tok = last @tokens, index) and if tag? then tok[0] = tag else tok[0]
+ value: (index, val) ->
+ (tok = last @tokens, index) and if val? then tok[1] = val else tok[1]
+
+ # Are we in the midst of an unfinished expression?
+ unfinished: ->
+ (prev = last @tokens, 1) and prev[0] isnt '.' and
+ (value = @value()) and not value.reserved and
+ NO_NEWLINE.test(value) and not CODE.test(value) and not ASSIGNED.test(@chunk)
+
+ # Converts newlines for string literals.
+ escapeLines: (str, heredoc) ->
+ str.replace MULTILINER, if heredoc then '\\n' else ''
+
+ # Constructs a string token by escaping quotes and newlines.
+ makeString: (body, quote, heredoc) ->
+ return quote + quote unless body
+ body = body.replace /\\([\s\S])/g, (match, contents) ->
+ if contents in ['\n', quote] then contents else match
+ body = body.replace /// #{quote} ///g, '\\$&'
+ quote + @escapeLines(body, heredoc) + quote
+
+# Constants
+# ---------
+
+# Keywords that CoffeeScript shares in common with JavaScript.
+JS_KEYWORDS = [
+ 'true', 'false', 'null', 'this'
+ 'new', 'delete', 'typeof', 'in', 'instanceof'
+ 'return', 'throw', 'break', 'continue', 'debugger'
+ 'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally'
+ 'class', 'extends', 'super'
+]
+
+# CoffeeScript-only keywords.
+COFFEE_KEYWORDS = ['then', 'unless', 'until', 'loop', 'of', 'by', 'when']
+COFFEE_KEYWORDS.push op for all op of COFFEE_ALIASES =
+ and : '&&'
+ or : '||'
+ is : '=='
+ isnt : '!='
+ not : '!'
+ yes : 'TRUE'
+ no : 'FALSE'
+ on : 'TRUE'
+ off : 'FALSE'
+
+# The list of keywords that are reserved by JavaScript, but not used, or are
+# used by CoffeeScript internally. We throw an error when these are encountered,
+# to avoid having a JavaScript error at runtime.
+RESERVED = [
+ 'case', 'default', 'do', 'function', 'var', 'void', 'with'
+ 'const', 'let', 'enum', 'export', 'import', 'native'
+ '__hasProp', '__extends', '__slice'
+]
+
+# The superset of both JavaScript keywords and reserved words, none of which may
+# be used as identifiers or properties.
+JS_FORBIDDEN = JS_KEYWORDS.concat RESERVED
+
+# Token matching regexes.
+IDENTIFIER = /// ^
+ ( [$A-Za-z_][$\w]* )
+ ( [^\n\S]* : (?!:) )? # Is this a property name?
+///
+NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i
+HEREDOC = /^("""|''')([\s\S]*?)(?:\n[ \t]*)?\1/
+OPERATOR = /// ^ (?: -[-=>]? | \+[+=]? | \.\.\.? | [*&|/%=<>^:!?]+ ) ///
+WHITESPACE = /^[ \t]+/
+COMMENT = /^###([^#][\s\S]*?)(?:###[ \t]*\n|(?:###)?$)|^(?:\s*#(?!##[^#]).*)+/
+CODE = /^[-=]>/
+MULTI_DENT = /^(?:\n[ \t]*)+/
+SIMPLESTR = /^'[^\\']*(?:\\.[^\\']*)*'/
+JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/
+
+# Regex-matching-regexes.
+REGEX = /// ^
+ / (?! \s ) # disallow leading whitespace
+ [^ [ / \n \\ ]* # every other thing
+ (?:
+ (?: \\[\s\S] # anything escaped
+ | \[ # character class
+ [^ \] \n \\ ]*
+ (?: \\[\s\S] [^ \] \n \\ ]* )*
+ ]
+ ) [^ [ / \n \\ ]*
+ )*
+ / [imgy]{0,4} (?![A-Za-z])
+///
+HEREGEX = /^\/{3}([\s\S]+?)\/{3}([imgy]{0,4})(?![A-Za-z])/
+HEREGEX_OMIT = /\s+(?:#.*)?/g
+
+# Token cleaning regexes.
+MULTILINER = /\n/g
+HEREDOC_INDENT = /\n+([ \t]*)/g
+ASSIGNED = /^\s*@?[$A-Za-z_][$\w]*[ \t]*?[:=][^:=>]/
+NEXT_CHARACTER = /^\s*(\S?)/
+NEXT_ELLIPSIS = /^\s*\.\.\.?/
+LEADING_SPACES = /^\s+/
+TRAILING_SPACES = /\s+$/
+NO_NEWLINE = /// ^
+ (?: # non-capturing...
+ [-+*&|/%=<>!.\\][<>=&|]* | # symbol operators
+ and | or | is(?:nt)? | n(?:ot|ew) | # word operators
+ delete | typeof | instanceof
+ )$
+///
+
+
+# Compound assignment tokens.
+COMPOUND_ASSIGN = ['-=', '+=', '/=', '*=', '%=', '||=', '&&=', '?=', '<<=', '>>=', '>>>=', '&=', '^=', '|=']
+
+# Unary tokens.
+UNARY = ['UMINUS', 'UPLUS', '!', '!!', '~', 'NEW', 'TYPEOF', 'DELETE']
+
+# Logical tokens.
+LOGIC = ['&', '|', '^', '&&', '||']
+
+# Bit-shifting tokens.
+SHIFT = ['<<', '>>', '>>>']
+
+# Comparison tokens.
+COMPARE = ['<=', '<', '>', '>=']
+
+# Mathmatical tokens.
+MATH = ['*', '/', '%']
+
+# Relational tokens that are negatable with `not` prefix.
+RELATION = ['IN', 'OF', 'INSTANCEOF']
+
+# Boolean tokens.
+BOOL = ['TRUE', 'FALSE', 'NULL']
+
+# Tokens which a regular expression will never immediately follow, but which
+# a division operator might.
+#
+# See: http://www.mozilla.org/js/language/js20-2002-04/rationale/syntax.html#regular-expressions
+#
+# Our list is shorter, due to sans-parentheses method calls.
+NOT_REGEX = ['NUMBER', 'REGEX', 'BOOL', '++', '--', ']']
+
+# Tokens which could legitimately be invoked or indexed. A opening
+# parentheses or bracket following these tokens will be recorded as the start
+# of a function invocation or indexing operation.
+CALLABLE = ['IDENTIFIER', 'STRING', 'REGEX', ')', ']', '}', '?', '::', '@', 'THIS', 'SUPER']
+INDEXABLE = CALLABLE.concat 'NUMBER', 'BOOL'
+
+# Tokens that, when immediately preceding a `WHEN`, indicate that the `WHEN`
+# occurs at the start of a line. We disambiguate these from trailing whens to
+# avoid an ambiguity in the grammar.
+LINE_BREAK = ['INDENT', 'OUTDENT', 'TERMINATOR']
--- /dev/null
+# `nodes.coffee` contains all of the node classes for the syntax tree. Most
+# nodes are created as the result of actions in the [grammar](grammar.html),
+# but some are created by other nodes as a method of code generation. To convert
+# the syntax tree into a string of JavaScript code, call `compile()` on the root.
+
+{Scope} = require './scope'
+
+# Import the helpers we plan to use.
+{compact, flatten, merge, del, include, starts, ends, last} = require './helpers'
+
+# Constant functions for nodes that don't need customization.
+YES = -> yes
+NO = -> no
+THIS = -> this
+
+#### Base
+
+# The **Base** is the abstract base class for all nodes in the syntax tree.
+# Each subclass implements the `compileNode` method, which performs the
+# code generation for that node. To compile a node to JavaScript,
+# call `compile` on it, which wraps `compileNode` in some generic extra smarts,
+# to know when the generated code needs to be wrapped up in a closure.
+# An options hash is passed and cloned throughout, containing information about
+# the environment from higher in the tree (such as if a returned value is
+# being requested by the surrounding function), information about the current
+# scope, and indentation level.
+exports.Base = class Base
+
+ constructor: ->
+ @tags = {}
+
+ # Common logic for determining whether to wrap this node in a closure before
+ # compiling it, or to compile directly. We need to wrap if this node is a
+ # *statement*, and it's not a *pureStatement*, and we're not at
+ # the top level of a block (which would be unnecessary), and we haven't
+ # already been asked to return the result (because statements know how to
+ # return results).
+ #
+ # If a Node is *topSensitive*, that means that it needs to compile differently
+ # depending on whether it's being used as part of a larger expression, or is a
+ # top-level statement within the function body.
+ compile: (o) ->
+ @options = if o then merge o else {}
+ @tab = o.indent
+ top = if @topSensitive() then @options.top else del @options, 'top'
+ closure = @isStatement(o) and not @isPureStatement() and not top and
+ not @options.asStatement and this not instanceof Comment
+ code = if closure then @compileClosure(@options) else @compileNode(@options)
+ code
+
+ # Statements converted into expressions via closure-wrapping share a scope
+ # object with their parent closure, to preserve the expected lexical scope.
+ compileClosure: (o) ->
+ o.sharedScope = o.scope
+ throw new Error 'cannot include a pure statement in an expression.' if @containsPureStatement()
+ Closure.wrap(this).compile o
+
+ # If the code generation wishes to use the result of a complex expression
+ # in multiple places, ensure that the expression is only ever evaluated once,
+ # by assigning it to a temporary variable.
+ compileReference: (o, options) ->
+ pair = unless @isComplex()
+ [this, this]
+ else
+ reference = new Literal o.scope.freeVariable 'ref'
+ compiled = new Assign reference, this
+ [compiled, reference]
+ (pair[i] = node.compile o) for node, i in pair if options?.precompile
+ pair
+
+ # Convenience method to grab the current indentation level, plus tabbing in.
+ idt: (tabs) ->
+ idt = @tab or ''
+ num = (tabs or 0) + 1
+ idt += TAB while num -= 1
+ idt
+
+ # Construct a node that returns the current node's result.
+ # Note that this is overridden for smarter behavior for
+ # many statement nodes (eg If, For)...
+ makeReturn: ->
+ new Return this
+
+ # Does this node, or any of its children, contain a node of a certain kind?
+ # Recursively traverses down the *children* of the nodes, yielding to a block
+ # and returning true when the block finds a match. `contains` does not cross
+ # scope boundaries.
+ contains: (block) ->
+ contains = false
+ @traverseChildren false, (node) ->
+ if block(node)
+ contains = true
+ return false
+ contains
+
+ # Is this node of a certain type, or does it contain the type?
+ containsType: (type) ->
+ this instanceof type or @contains (node) -> node instanceof type
+
+ # Convenience for the most common use of contains. Does the node contain
+ # a pure statement?
+ containsPureStatement: ->
+ @isPureStatement() or @contains (node) -> node.isPureStatement()
+
+ # Perform an in-order traversal of the AST. Crosses scope boundaries.
+ traverse: (block) -> @traverseChildren true, block
+
+ # `toString` representation of the node, for inspecting the parse tree.
+ # This is what `coffee --nodes` prints out.
+ toString: (idt, override) ->
+ idt or= ''
+ children = (child.toString idt + TAB for child in @collectChildren()).join('')
+ klass = override or @constructor.name + if @soakNode then '?' else ''
+ '\n' + idt + klass + children
+
+ eachChild: (func) ->
+ return unless @children
+ for attr in @children when this[attr]
+ for child in flatten [this[attr]]
+ return if func(child) is false
+
+ collectChildren: ->
+ nodes = []
+ @eachChild (node) -> nodes.push node
+ nodes
+
+ traverseChildren: (crossScope, func) ->
+ @eachChild (child) ->
+ return false if func(child) is false
+ if crossScope or child not instanceof Code
+ child.traverseChildren crossScope, func
+
+ invert: -> new Op '!', this
+
+ # Default implementations of the common node properties and methods. Nodes
+ # will override these with custom logic, if needed.
+ children: []
+
+ unwrap : THIS
+ isStatement : NO
+ isPureStatement : NO
+ isComplex : YES
+ topSensitive : NO
+ unfoldSoak : NO
+
+ # Is this node used to assign a certain variable?
+ assigns: NO
+
+#### Expressions
+
+# The expressions body is the list of expressions that forms the body of an
+# indented block of code -- the implementation of a function, a clause in an
+# `if`, `switch`, or `try`, and so on...
+exports.Expressions = class Expressions extends Base
+
+ children: ['expressions']
+ isStatement: YES
+
+ constructor: (nodes) ->
+ super()
+ @expressions = compact flatten nodes or []
+
+ # Tack an expression on to the end of this expression list.
+ push: (node) ->
+ @expressions.push(node)
+ this
+
+ # Add an expression at the beginning of this expression list.
+ unshift: (node) ->
+ @expressions.unshift(node)
+ this
+
+ # If this Expressions consists of just a single node, unwrap it by pulling
+ # it back out.
+ unwrap: ->
+ if @expressions.length is 1 then @expressions[0] else this
+
+ # Is this an empty block of code?
+ empty: ->
+ @expressions.length is 0
+
+ # An Expressions node does not return its entire body, rather it
+ # ensures that the final expression is returned.
+ makeReturn: ->
+ end = @expressions[idx = @expressions.length - 1]
+ end = @expressions[idx -= 1] if end instanceof Comment
+ if end and end not instanceof Return
+ @expressions[idx] = end.makeReturn()
+ this
+
+ # An **Expressions** is the only node that can serve as the root.
+ compile: (o) ->
+ o or= {}
+ if o.scope then super(o) else @compileRoot(o)
+
+ compileNode: (o) ->
+ (@compileExpression node, merge o for node in @expressions).join '\n'
+
+ # If we happen to be the top-level **Expressions**, wrap everything in
+ # a safety closure, unless requested not to.
+ # It would be better not to generate them in the first place, but for now,
+ # clean up obvious double-parentheses.
+ compileRoot: (o) ->
+ o.indent = @tab = if o.bare then '' else TAB
+ o.scope = new Scope null, this, null
+ code = @compileWithDeclarations o
+ code = code.replace TRAILING_WHITESPACE, ''
+ if o.bare then code else "(function() {\n#{code}\n}).call(this);\n"
+
+ # Compile the expressions body for the contents of a function, with
+ # declarations of all inner variables pushed up to the top.
+ compileWithDeclarations: (o) ->
+ code = @compileNode(o)
+ if o.scope.hasAssignments this
+ code = "#{@tab}var #{ o.scope.compiledAssignments().replace /\n/g, '$&' + @tab };\n#{code}"
+ if not o.globals and o.scope.hasDeclarations this
+ code = "#{@tab}var #{o.scope.compiledDeclarations()};\n#{code}"
+ code
+
+ # Compiles a single expression within the expressions body. If we need to
+ # return the result, and it's an expression, simply return it. If it's a
+ # statement, ask the statement to do so.
+ compileExpression: (node, o) ->
+ @tab = o.indent
+ node.tags.front = true
+ compiledNode = node.compile merge o, top: true
+ if node.isStatement(o) then compiledNode else "#{@idt()}#{compiledNode};"
+
+# Wrap up the given nodes as an **Expressions**, unless it already happens
+# to be one.
+Expressions.wrap = (nodes) ->
+ return nodes[0] if nodes.length is 1 and nodes[0] instanceof Expressions
+ new Expressions(nodes)
+
+#### Literal
+
+# Literals are static values that can be passed through directly into
+# JavaScript without translation, such as: strings, numbers,
+# `true`, `false`, `null`...
+exports.Literal = class Literal extends Base
+
+ constructor: (@value) ->
+ super()
+
+ makeReturn: ->
+ if @isStatement() then this else super()
+
+ # Break and continue must be treated as pure statements -- they lose their
+ # meaning when wrapped in a closure.
+ isStatement: ->
+ @value in ['break', 'continue', 'debugger']
+ isPureStatement: Literal::isStatement
+
+ isComplex: NO
+
+ isReserved: ->
+ !!@value.reserved
+
+ assigns: (name) -> name is @value
+
+ compileNode: (o) ->
+ idt = if @isStatement(o) then @idt() else ''
+ end = if @isStatement(o) then ';' else ''
+ val = if @isReserved() then "\"#{@value}\"" else @value
+ idt + val + end
+
+ toString: -> ' "' + @value + '"'
+
+#### Return
+
+# A `return` is a *pureStatement* -- wrapping it in a closure wouldn't
+# make sense.
+exports.Return = class Return extends Base
+
+ isStatement: YES
+ isPureStatement: YES
+ children: ['expression']
+
+ constructor: (@expression) ->
+ super()
+
+ makeReturn: THIS
+
+ compile: (o) ->
+ expr = @expression?.makeReturn()
+ return expr.compile o if expr and (expr not instanceof Return)
+ super o
+
+ compileNode: (o) ->
+ expr = ''
+ if @expression
+ o.asStatement = true if @expression.isStatement(o)
+ expr = ' ' + @expression.compile(o)
+ "#{@tab}return#{expr};"
+
+#### Value
+
+# A value, variable or literal or parenthesized, indexed or dotted into,
+# or vanilla.
+exports.Value = class Value extends Base
+
+ children: ['base', 'properties']
+
+ # A **Value** has a base and a list of property accesses.
+ constructor: (@base, @properties, tag) ->
+ super()
+ @properties or= []
+ @tags[tag] = yes if tag
+
+ # Add a property access to the list.
+ push: (prop) ->
+ @properties.push(prop)
+ this
+
+ hasProperties: ->
+ !!@properties.length
+
+ # Some boolean checks for the benefit of other nodes.
+
+ isArray: ->
+ @base instanceof ArrayLiteral and not @properties.length
+
+ isObject: ->
+ @base instanceof ObjectLiteral and not @properties.length
+
+ isSplice: ->
+ last(@properties) instanceof Slice
+
+ isComplex: ->
+ @base.isComplex() or @hasProperties()
+
+ assigns: (name) ->
+ not @properties.length and @base.assigns name
+
+ makeReturn: ->
+ if @properties.length then super() else @base.makeReturn()
+
+
+ # The value can be unwrapped as its inner node, if there are no attached
+ # properties.
+ unwrap: ->
+ if @properties.length then this else @base
+
+ # Values are considered to be statements if their base is a statement.
+ isStatement: (o) ->
+ @base.isStatement(o) and not @properties.length
+
+ isSimpleNumber: ->
+ @base instanceof Literal and SIMPLENUM.test @base.value
+
+ # A reference has base part (`this` value) and name part.
+ # We cache them separately for compiling complex expressions.
+ # `a()[b()] ?= c` -> `(_base = a())[_name = b()] ? _base[_name] = c`
+ cacheReference: (o) ->
+ name = last @properties
+ if not @base.isComplex() and @properties.length < 2 and
+ not name?.isComplex()
+ return [this, this] # `a` `a.b`
+ base = new Value @base, @properties.slice 0, -1
+ if base.isComplex() # `a().b`
+ bref = new Literal o.scope.freeVariable 'base'
+ base = new Value new Parens new Assign bref, base
+ return [base, bref] unless name # `a()`
+ if name.isComplex() # `a[b()]`
+ nref = new Literal o.scope.freeVariable 'name'
+ name = new Index new Assign nref, name.index
+ nref = new Index nref
+ [base.push(name), new Value(bref or base.base, [nref or name])]
+
+ # Override compile to unwrap the value when possible.
+ compile: (o) ->
+ @base.tags.front = @tags.front
+ if not o.top or @properties.length then super(o) else @base.compile(o)
+
+ # We compile a value to JavaScript by compiling and joining each property.
+ # Things get much more insteresting if the chain of properties has *soak*
+ # operators `?.` interspersed. Then we have to take care not to accidentally
+ # evaluate a anything twice when building the soak chain.
+ compileNode: (o) ->
+ return ifn.compile o if ifn = @unfoldSoak o
+ props = @properties
+ @base.parenthetical = yes if @parenthetical and not props.length
+ code = @base.compile o
+ code = "(#{code})" if props[0] instanceof Accessor and @isSimpleNumber()
+ (code += prop.compile o) for prop in props
+ return code
+
+ # Unfold a soak into an `If`: `a?.b` -> `a.b if a?`
+ unfoldSoak: (o) ->
+ if ifn = @base.unfoldSoak o
+ Array::push.apply ifn.body.properties, @properties
+ return ifn
+ for prop, i in @properties when prop.soakNode
+ prop.soakNode = off
+ fst = new Value @base, @properties.slice 0, i
+ snd = new Value @base, @properties.slice i
+ if fst.isComplex()
+ ref = new Literal o.scope.freeVariable 'ref'
+ fst = new Parens new Assign ref, fst
+ snd.base = ref
+ ifn = new If new Existence(fst), snd, soak: yes
+ return ifn
+ null
+
+#### Comment
+
+# CoffeeScript passes through block comments as JavaScript block comments
+# at the same position.
+exports.Comment = class Comment extends Base
+
+ isStatement: YES
+
+ constructor: (@comment) ->
+ super()
+
+ makeReturn: THIS
+
+ compileNode: (o) ->
+ @tab + '/*' + @comment.replace(/\n/g, '\n' + @tab) + '*/'
+
+#### Call
+
+# Node for a function invocation. Takes care of converting `super()` calls into
+# calls against the prototype's function of the same name.
+exports.Call = class Call extends Base
+
+ children: ['variable', 'args']
+
+ constructor: (variable, @args, @soakNode) ->
+ super()
+ @isNew = false
+ @isSuper = variable is 'super'
+ @variable = if @isSuper then null else variable
+ @args or= []
+
+ compileSplatArguments: (o) ->
+ Splat.compileSplattedArray @args, o
+
+ # Tag this invocation as creating a new instance.
+ newInstance: ->
+ @isNew = true
+ this
+
+ prefix: ->
+ if @isNew then 'new ' else ''
+
+ # Grab the reference to the superclass' implementation of the current method.
+ superReference: (o) ->
+ {method} = o.scope
+ throw Error "cannot call super outside of a function." unless method
+ {name} = method
+ throw Error "cannot call super on an anonymous function." unless name
+ if method.klass
+ "#{method.klass}.__super__.#{name}"
+ else
+ "#{name}.__super__.constructor"
+
+ # Soaked chained invocations unfold into if/else ternary structures.
+ unfoldSoak: (o) ->
+ if @soakNode
+ if val = @variable
+ val = new Value val unless val instanceof Value
+ [left, rite] = val.cacheReference o
+ else
+ left = new Literal @superReference o
+ rite = new Value left
+ rite = new Call rite, @args
+ rite.isNew = @isNew
+ left = new Literal "typeof #{ left.compile o } === \"function\""
+ ifn = new If left, new Value(rite), soak: yes
+ return ifn
+ call = this
+ list = []
+ loop
+ if call.variable instanceof Call
+ list.push call
+ call = call.variable
+ continue
+ break unless call.variable instanceof Value
+ list.push call
+ break unless (call = call.variable.base) instanceof Call
+ for call in list.reverse()
+ if ifn
+ if call.variable instanceof Call
+ call.variable = ifn
+ else
+ call.variable.base = ifn
+ ifn = If.unfoldSoak o, call, 'variable'
+ ifn
+
+ # Compile a vanilla function call.
+ compileNode: (o) ->
+ return ifn.compile o if ifn = @unfoldSoak o
+ @variable?.tags.front = @tags.front
+ for arg in @args when arg instanceof Splat
+ return @compileSplat o
+ args = ((arg.parenthetical = on) and arg.compile o for arg in @args).join ', '
+ if @isSuper
+ @compileSuper args, o
+ else
+ "#{@prefix()}#{@variable.compile o}(#{args})"
+
+ # `super()` is converted into a call against the superclass's implementation
+ # of the current function.
+ compileSuper: (args, o) ->
+ "#{@superReference(o)}.call(this#{ if args.length then ', ' else '' }#{args})"
+
+ # If you call a function with a splat, it's converted into a JavaScript
+ # `.apply()` call to allow an array of arguments to be passed.
+ # If it's a constructor, then things get real tricky. We have to inject an
+ # inner constructor in order to be able to pass the varargs.
+ compileSplat: (o) ->
+ splatargs = @compileSplatArguments o
+ return "#{ @superReference o }.apply(this, #{splatargs})" if @isSuper
+ unless @isNew
+ base = new Value base unless (base = @variable) instanceof Value
+ if (name = base.properties.pop()) and base.isComplex()
+ ref = o.scope.freeVariable 'this'
+ fun = "(#{ref} = #{ base.compile o })#{ name.compile o }"
+ else
+ fun = ref = base.compile o
+ fun += name.compile o if name
+ return "#{fun}.apply(#{ref}, #{splatargs})"
+ idt = @idt 1
+ """
+ (function(func, args, ctor) {
+ #{idt}ctor.prototype = func.prototype;
+ #{idt}var child = new ctor, result = func.apply(child, args);
+ #{idt}return typeof result === "object" ? result : child;
+ #{@tab}})(#{ @variable.compile o }, #{splatargs}, function() {})
+ """
+
+#### Extends
+
+# Node to extend an object's prototype with an ancestor object.
+# After `goog.inherits` from the
+# [Closure Library](http://closure-library.googlecode.com/svn/docs/closureGoogBase.js.html).
+exports.Extends = class Extends extends Base
+
+ children: ['child', 'parent']
+
+ constructor: (@child, @parent) ->
+ super()
+
+ # Hooks one constructor into another's prototype chain.
+ compileNode: (o) ->
+ ref = new Value new Literal utility 'extends'
+ (new Call ref, [@child, @parent]).compile o
+
+#### Accessor
+
+# A `.` accessor into a property of a value, or the `::` shorthand for
+# an accessor into the object's prototype.
+exports.Accessor = class Accessor extends Base
+
+ children: ['name']
+
+ constructor: (@name, tag) ->
+ super()
+ @prototype = if tag is 'prototype' then '.prototype' else ''
+ @soakNode = tag is 'soak'
+
+ compileNode: (o) ->
+ name = @name.compile o
+ namePart = if name.match(IS_STRING) then "[#{name}]" else ".#{name}"
+ @prototype + namePart
+
+ isComplex: NO
+
+#### Index
+
+# A `[ ... ]` indexed accessor into an array or object.
+exports.Index = class Index extends Base
+
+ children: ['index']
+
+ constructor: (@index) ->
+ super()
+
+ compileNode: (o) ->
+ idx = @index.compile o
+ prefix = if @proto then '.prototype' else ''
+ "#{prefix}[#{idx}]"
+
+ isComplex: -> @index.isComplex()
+
+#### Range
+
+# A range literal. Ranges can be used to extract portions (slices) of arrays,
+# to specify a range for comprehensions, or as a value, to be expanded into the
+# corresponding array of integers at runtime.
+exports.Range = class Range extends Base
+
+ children: ['from', 'to']
+
+ constructor: (@from, @to, tag) ->
+ super()
+ @exclusive = tag is 'exclusive'
+ @equals = if @exclusive then '' else '='
+
+ # Compiles the range's source variables -- where it starts and where it ends.
+ # But only if they need to be cached to avoid double evaluation.
+ compileVariables: (o) ->
+ o = merge(o, top: true)
+ [@from, @fromVar] = @from.compileReference o, precompile: yes
+ [@to, @toVar] = @to.compileReference o, precompile: yes
+ [@fromNum, @toNum] = [@fromVar.match(SIMPLENUM), @toVar.match(SIMPLENUM)]
+ parts = []
+ parts.push @from if @from isnt @fromVar
+ parts.push @to if @to isnt @toVar
+
+ # When compiled normally, the range returns the contents of the *for loop*
+ # needed to iterate over the values in the range. Used by comprehensions.
+ compileNode: (o) ->
+ @compileVariables o
+ return @compileArray(o) unless o.index
+ return @compileSimple(o) if @fromNum and @toNum
+ idx = del o, 'index'
+ step = del o, 'step'
+ vars = "#{idx} = #{@from}" + if @to isnt @toVar then ", #{@to}" else ''
+ intro = "(#{@fromVar} <= #{@toVar} ? #{idx}"
+ compare = "#{intro} <#{@equals} #{@toVar} : #{idx} >#{@equals} #{@toVar})"
+ stepPart = if step then step.compile(o) else '1'
+ incr = if step then "#{idx} += #{stepPart}" else "#{intro} += #{stepPart} : #{idx} -= #{stepPart})"
+ "#{vars}; #{compare}; #{incr}"
+
+ # Compile a simple range comprehension, with integers.
+ compileSimple: (o) ->
+ [from, to] = [+@fromNum, +@toNum]
+ idx = del o, 'index'
+ step = del o, 'step'
+ step and= "#{idx} += #{step.compile(o)}"
+ if from <= to
+ "#{idx} = #{from}; #{idx} <#{@equals} #{to}; #{step or "#{idx}++"}"
+ else
+ "#{idx} = #{from}; #{idx} >#{@equals} #{to}; #{step or "#{idx}--"}"
+
+ # When used as a value, expand the range into the equivalent array.
+ compileArray: (o) ->
+ if @fromNum and @toNum and Math.abs(@fromNum - @toNum) <= 20
+ range = [+@fromNum..+@toNum]
+ range.pop() if @exclusive
+ return "[#{ range.join(', ') }]"
+ idt = @idt 1
+ i = o.scope.freeVariable 'i'
+ result = o.scope.freeVariable 'result'
+ pre = "\n#{idt}#{result} = [];"
+ if @fromNum and @toNum
+ o.index = i
+ body = @compileSimple o
+ else
+ vars = "#{i} = #{@from}" + if @to isnt @toVar then ", #{@to}" else ''
+ clause = "#{@fromVar} <= #{@toVar} ?"
+ body = "var #{vars}; #{clause} #{i} <#{@equals} #{@toVar} : #{i} >#{@equals} #{@toVar}; #{clause} #{i} += 1 : #{i} -= 1"
+ post = "{ #{result}.push(#{i}); }\n#{idt}return #{result};\n#{o.indent}"
+ "(function() {#{pre}\n#{idt}for (#{body})#{post}}).call(this)"
+
+#### Slice
+
+# An array slice literal. Unlike JavaScript's `Array#slice`, the second parameter
+# specifies the index of the end of the slice, just as the first parameter
+# is the index of the beginning.
+exports.Slice = class Slice extends Base
+
+ children: ['range']
+
+ constructor: (@range) ->
+ super()
+
+ compileNode: (o) ->
+ from = if @range.from then @range.from.compile(o) else '0'
+ to = if @range.to then @range.to.compile(o) else ''
+ to += if not to or @range.exclusive then '' else ' + 1'
+ to = ', ' + to if to
+ ".slice(#{from}#{to})"
+
+#### ObjectLiteral
+
+# An object literal, nothing fancy.
+exports.ObjectLiteral = class ObjectLiteral extends Base
+
+ children: ['properties']
+
+ constructor: (props) ->
+ super()
+ @objects = @properties = props or []
+
+ compileNode: (o) ->
+ top = del o, 'top'
+ o.indent = @idt 1
+ nonComments = prop for prop in @properties when prop not instanceof Comment
+ lastNoncom = last nonComments
+ props = for prop, i in @properties
+ join = if i is @properties.length - 1
+ ''
+ else if prop is lastNoncom or prop instanceof Comment
+ '\n'
+ else
+ ',\n'
+ indent = if prop instanceof Comment then '' else @idt 1
+ if prop instanceof Value and prop.tags.this
+ prop = new Assign prop.properties[0].name, prop, 'object'
+ else if prop not instanceof Assign and prop not instanceof Comment
+ prop = new Assign prop, prop, 'object'
+ indent + prop.compile(o) + join
+ props = props.join('')
+ obj = "{#{ if props then '\n' + props + '\n' + @idt() else '' }}"
+ if @tags.front then "(#{obj})" else obj
+
+ assigns: (name) ->
+ for prop in @properties when prop.assigns name then return yes
+ no
+
+#### ArrayLiteral
+
+# An array literal.
+exports.ArrayLiteral = class ArrayLiteral extends Base
+
+ children: ['objects']
+
+ constructor: (@objects) ->
+ super()
+ @objects or= []
+
+ compileSplatLiteral: (o) ->
+ Splat.compileSplattedArray @objects, o
+
+ compileNode: (o) ->
+ o.indent = @idt 1
+ for obj in @objects when obj instanceof Splat
+ return @compileSplatLiteral o
+ objects = []
+ for obj, i in @objects
+ code = obj.compile o
+ objects.push (if obj instanceof Comment
+ "\n#{code}\n#{o.indent}"
+ else if i is @objects.length - 1
+ code
+ else
+ code + ', '
+ )
+ objects = objects.join ''
+ if 0 < objects.indexOf '\n'
+ "[\n#{o.indent}#{objects}\n#{@tab}]"
+ else
+ "[#{objects}]"
+
+ assigns: (name) ->
+ for obj in @objects when obj.assigns name then return yes
+ no
+
+#### Class
+
+# The CoffeeScript class definition.
+exports.Class = class Class extends Base
+
+ children: ['variable', 'parent', 'properties']
+ isStatement: YES
+
+ # Initialize a **Class** with its name, an optional superclass, and a
+ # list of prototype property assignments.
+ constructor: (variable, @parent, @properties) ->
+ super()
+ @variable = if variable is '__temp__' then new Literal variable else variable
+ @properties or= []
+ @returns = false
+
+ makeReturn: ->
+ @returns = true
+ this
+
+ # Instead of generating the JavaScript string directly, we build up the
+ # equivalent syntax tree and compile that, in pieces. You can see the
+ # constructor, property assignments, and inheritance getting built out below.
+ compileNode: (o) ->
+ {variable} = this
+ variable = new Literal o.scope.freeVariable 'ctor' if variable.value is '__temp__'
+ extension = @parent and new Extends variable, @parent
+ props = new Expressions
+ o.top = true
+ me = null
+ className = variable.compile o
+ constScope = null
+
+ if @parent
+ applied = new Value @parent, [new Accessor new Literal 'apply']
+ constructor = new Code([], new Expressions([
+ new Call applied, [new Literal('this'), new Literal('arguments')]
+ ]))
+ else
+ constructor = new Code [], new Expressions [new Return new Literal 'this']
+
+ for prop in @properties
+ [pvar, func] = [prop.variable, prop.value]
+ if pvar and pvar.base.value is 'constructor'
+ if func not instanceof Code
+ [func, ref] = func.compileReference o
+ props.push func if func isnt ref
+ apply = new Call(new Value(ref, [new Accessor new Literal 'apply']), [new Literal('this'), new Literal('arguments')])
+ func = new Code [], new Expressions([apply])
+ throw new Error "cannot define a constructor as a bound function." if func.bound
+ func.name = className
+ func.body.push new Return new Literal 'this'
+ variable = new Value variable
+ variable.namespaced = 0 < className.indexOf '.'
+ constructor = func
+ constructor.comment = props.expressions.pop() if props.expressions[props.expressions.length - 1] instanceof Comment
+ continue
+ if func instanceof Code and func.bound
+ if prop.context is 'this'
+ func.context = className
+ else
+ func.bound = false
+ constScope or= new Scope(o.scope, constructor.body, constructor)
+ me or= constScope.freeVariable 'this'
+ pname = pvar.compile(o)
+ constructor.body.push new Return new Literal 'this' if constructor.body.empty()
+ constructor.body.unshift new Literal "this.#{pname} = function(){ return #{className}.prototype.#{pname}.apply(#{me}, arguments); }"
+ if pvar
+ access = if prop.context is 'this' then pvar.base.properties[0] else new Accessor(pvar, 'prototype')
+ val = new Value variable, [access]
+ prop = new Assign(val, func)
+ props.push prop
+
+ constructor.className = className.match /[\w\d\$_]+$/
+ constructor.body.unshift new Literal "#{me} = this" if me
+ construct = @idt() + new Assign(variable, constructor).compile(merge o, sharedScope: constScope) + ';'
+ props = if !props.empty() then '\n' + props.compile(o) else ''
+ extension = if extension then '\n' + @idt() + extension.compile(o) + ';' else ''
+ returns = if @returns then '\n' + new Return(variable).compile(o) else ''
+ construct + extension + props + returns
+
+#### Assign
+
+# The **Assign** is used to assign a local variable to value, or to set the
+# property of an object -- including within object literals.
+exports.Assign = class Assign extends Base
+
+ # Matchers for detecting class/method names
+ METHOD_DEF: /^(?:(\S+)\.prototype\.)?([$A-Za-z_][$\w]*)$/
+
+ children: ['variable', 'value']
+
+ constructor: (@variable, @value, @context) ->
+ super()
+
+ topSensitive: YES
+
+ isValue: ->
+ @variable instanceof Value
+
+ # Compile an assignment, delegating to `compilePatternMatch` or
+ # `compileSplice` if appropriate. Keep track of the name of the base object
+ # we've been assigned to, for correct internal references. If the variable
+ # has not been seen yet within the current scope, declare it.
+ compileNode: (o) ->
+ if isValue = @isValue()
+ return @compilePatternMatch(o) if @variable.isArray() or @variable.isObject()
+ return @compileSplice(o) if @variable.isSplice()
+ if ifn = If.unfoldSoak o, this, 'variable'
+ delete o.top
+ return ifn.compile o
+ top = del o, 'top'
+ stmt = del o, 'asStatement'
+ name = @variable.compile(o)
+ if @value instanceof Code and match = @METHOD_DEF.exec name
+ @value.name = match[2]
+ @value.klass = match[1]
+ val = @value.compile o
+ return "#{name}: #{val}" if @context is 'object'
+ o.scope.find name unless isValue and (@variable.hasProperties() or @variable.namespaced)
+ val = "#{name} = #{val}"
+ return "#{@tab}#{val};" if stmt
+ if top or @parenthetical then val else "(#{val})"
+
+ # Brief implementation of recursive pattern matching, when assigning array or
+ # object literals to a value. Peeks at their properties to assign inner names.
+ # See the [ECMAScript Harmony Wiki](http://wiki.ecmascript.org/doku.php?id=harmony:destructuring)
+ # for details.
+ compilePatternMatch: (o) ->
+ if (value = @value).isStatement o then value = Closure.wrap value
+ {objects} = @variable.base
+ return value.compile o unless olength = objects.length
+ isObject = @variable.isObject()
+ if o.top and olength is 1 and (obj = objects[0]) not instanceof Splat
+ # Unroll simplest cases: `{v} = x` -> `v = x.v`
+ if obj instanceof Assign
+ {variable: {base: idx}, value: obj} = obj
+ else
+ idx = if isObject
+ if obj.tags.this then obj.properties[0].name else obj
+ else new Literal 0
+ value = new Value value unless value instanceof Value
+ accessClass = if IDENTIFIER.test idx.value then Accessor else Index
+ value.properties.push new accessClass idx
+ return new Assign(obj, value).compile o
+ top = del o, 'top'
+ otop = merge o, top: yes
+ valVar = value.compile o
+ assigns = []
+ splat = false
+ if not IDENTIFIER.test(valVar) or @variable.assigns(valVar)
+ assigns.push "#{ ref = o.scope.freeVariable 'ref' } = #{valVar}"
+ valVar = ref
+ for obj, i in objects
+ # A regular array pattern-match.
+ idx = i
+ if isObject
+ if obj instanceof Assign
+ # A regular object pattern-match.
+ {variable: {base: idx}, value: obj} = obj
+ else
+ # A shorthand `{a, b, @c} = val` pattern-match.
+ idx = if obj.tags.this then obj.properties[0].name else obj
+ unless obj instanceof Value or obj instanceof Splat
+ throw new Error 'pattern matching must use only identifiers on the left-hand side.'
+ accessClass = if isObject and IDENTIFIER.test(idx.value) then Accessor else Index
+ if not splat and obj instanceof Splat
+ val = new Literal obj.compileValue o, valVar, i, olength - i - 1
+ splat = true
+ else
+ idx = new Literal(if splat then "#{valVar}.length - #{olength - idx}" else idx) if typeof idx isnt 'object'
+ val = new Value new Literal(valVar), [new accessClass idx]
+ assigns.push new Assign(obj, val).compile otop
+ assigns.push valVar unless top
+ code = assigns.join ', '
+ if top or @parenthetical then code else "(#{code})"
+
+ # Compile the assignment from an array splice literal, using JavaScript's
+ # `Array#splice` method.
+ compileSplice: (o) ->
+ {range} = @variable.properties.pop()
+ name = @variable.compile o
+ plus = if range.exclusive then '' else ' + 1'
+ from = if range.from then range.from.compile(o) else '0'
+ to = if range.to then range.to.compile(o) + ' - ' + from + plus else "#{name}.length"
+ ref = o.scope.freeVariable 'ref'
+ val = @value.compile(o)
+ "([].splice.apply(#{name}, [#{from}, #{to}].concat(#{ref} = #{val})), #{ref})"
+
+ assigns: (name) ->
+ @[if @context is 'object' then 'value' else 'variable'].assigns name
+
+#### Code
+
+# A function definition. This is the only node that creates a new Scope.
+# When for the purposes of walking the contents of a function body, the Code
+# has no *children* -- they're within the inner scope.
+exports.Code = class Code extends Base
+
+ children: ['params', 'body']
+
+ constructor: (@params, @body, tag) ->
+ super()
+ @params or= []
+ @body or= new Expressions
+ @bound = tag is 'boundfunc'
+ @context = 'this' if @bound
+
+ # Compilation creates a new scope unless explicitly asked to share with the
+ # outer scope. Handles splat parameters in the parameter list by peeking at
+ # the JavaScript `arguments` objects. If the function is bound with the `=>`
+ # arrow, generates a wrapper that saves the current value of `this` through
+ # a closure.
+ compileNode: (o) ->
+ sharedScope = del o, 'sharedScope'
+ top = del o, 'top'
+ o.scope = sharedScope or new Scope(o.scope, @body, this)
+ o.top = true
+ o.indent = @idt(1)
+ empty = @body.expressions.length is 0
+ delete o.bare
+ delete o.globals
+ splat = undefined
+ params = []
+ for param, i in @params
+ if splat
+ if param.attach
+ param.assign = new Assign new Value new Literal('this'), [new Accessor param.value]
+ @body.expressions.splice splat.index + 1, 0, param.assign
+ splat.trailings.push param
+ else
+ if param.attach
+ {value} = param
+ [param, param.splat] = [new Literal(o.scope.freeVariable 'arg'), param.splat]
+ @body.unshift new Assign new Value(new Literal('this'), [new Accessor value]), param
+ if param.splat
+ splat = new Splat param.value
+ splat.index = i
+ splat.trailings = []
+ splat.arglength = @params.length
+ @body.unshift(splat)
+ else
+ params.push param
+ o.scope.startLevel()
+ params = (param.compile(o) for param in params)
+ @body.makeReturn() unless empty or @noReturn
+ (o.scope.parameter(param)) for param in params
+ comm = if @comment then @comment.compile(o) + '\n' else ''
+ o.indent = @idt 2 if @className
+ code = if @body.expressions.length then "\n#{ @body.compileWithDeclarations(o) }\n" else ''
+ open = if @className then "(function() {\n#{comm}#{@idt(1)}function #{@className}(" else "function("
+ close = if @className then "#{code and @idt(1)}};\n#{@idt(1)}return #{@className};\n#{@tab}})()" else "#{code and @tab}}"
+ func = "#{open}#{ params.join(', ') }) {#{code}#{close}"
+ o.scope.endLevel()
+ return "#{utility 'bind'}(#{func}, #{@context})" if @bound
+ if @tags.front then "(#{func})" else func
+
+ # Short-circuit traverseChildren method to prevent it from crossing scope boundaries
+ # unless crossScope is true
+ traverseChildren: (crossScope, func) -> super(crossScope, func) if crossScope
+
+#### Param
+
+# A parameter in a function definition. Beyond a typical Javascript parameter,
+# these parameters can also attach themselves to the context of the function,
+# as well as be a splat, gathering up a group of parameters into an array.
+exports.Param = class Param extends Base
+
+ children: ['name']
+
+ constructor: (@name, @attach, @splat) ->
+ super()
+ @value = new Literal @name
+
+ compileNode: (o) ->
+ @value.compile o
+
+ toString: ->
+ {name} = @
+ name = '@' + name if @attach
+ name += '...' if @splat
+ new Literal(name).toString()
+
+#### Splat
+
+# A splat, either as a parameter to a function, an argument to a call,
+# or as part of a destructuring assignment.
+exports.Splat = class Splat extends Base
+
+ children: ['name']
+
+ constructor: (name) ->
+ super()
+ @name = if name.compile then name else new Literal name
+
+ assigns: (name) -> @name.assigns name
+
+ compileNode: (o) ->
+ if @index? then @compileParam(o) else @name.compile(o)
+
+ # Compiling a parameter splat means recovering the parameters that succeed
+ # the splat in the parameter list, by slicing the arguments object.
+ compileParam: (o) ->
+ name = @name.compile(o)
+ o.scope.find name
+ end = ''
+ if @trailings.length
+ len = o.scope.freeVariable 'len'
+ o.scope.assign len, "arguments.length"
+ variadic = o.scope.freeVariable 'result'
+ o.scope.assign variadic, len + ' >= ' + @arglength
+ end = if @trailings.length then ", #{len} - #{@trailings.length}"
+ for trailing, idx in @trailings
+ if trailing.attach
+ assign = trailing.assign
+ trailing = new Literal o.scope.freeVariable 'arg'
+ assign.value = trailing
+ pos = @trailings.length - idx
+ o.scope.assign(trailing.compile(o), "arguments[#{variadic} ? #{len} - #{pos} : #{@index + idx}]")
+ "#{name} = #{utility('slice')}.call(arguments, #{@index}#{end})"
+
+ # A compiling a splat as a destructuring assignment means slicing arguments
+ # from the right-hand-side's corresponding array.
+ compileValue: (o, name, index, trailings) ->
+ trail = if trailings then ", #{name}.length - #{trailings}" else ''
+ "#{utility 'slice'}.call(#{name}, #{index}#{trail})"
+
+ # Utility function that converts arbitrary number of elements, mixed with
+ # splats, to a proper array
+ @compileSplattedArray: (list, o) ->
+ args = []
+ end = -1
+ for arg, i in list
+ code = arg.compile o
+ prev = args[end]
+ if arg not instanceof Splat
+ if prev and starts(prev, '[') and ends(prev, ']')
+ args[end] = "#{prev.slice 0, -1}, #{code}]"
+ continue
+ if prev and starts(prev, '.concat([') and ends(prev, '])')
+ args[end] = "#{prev.slice 0, -2}, #{code}])"
+ continue
+ code = "[#{code}]"
+ args[++end] = if i is 0 then code else ".concat(#{code})"
+ args.join ''
+
+#### While
+
+# A while loop, the only sort of low-level loop exposed by CoffeeScript. From
+# it, all other loops can be manufactured. Useful in cases where you need more
+# flexibility or more speed than a comprehension can provide.
+exports.While = class While extends Base
+
+ children: ['condition', 'guard', 'body']
+ isStatement: YES
+
+ constructor: (condition, opts) ->
+ super()
+ @condition = if opts?.invert then condition.invert() else condition
+ @guard = opts?.guard
+
+ addBody: (body) ->
+ @body = body
+ this
+
+ makeReturn: ->
+ @returns = true
+ this
+
+ topSensitive: YES
+
+ # The main difference from a JavaScript *while* is that the CoffeeScript
+ # *while* can be used as a part of a larger expression -- while loops may
+ # return an array containing the computed result of each iteration.
+ compileNode: (o) ->
+ top = del(o, 'top') and not @returns
+ o.indent = @idt 1
+ @condition.parenthetical = yes
+ cond = @condition.compile(o)
+ o.top = true
+ set = ''
+ unless top
+ rvar = o.scope.freeVariable 'result'
+ set = "#{@tab}#{rvar} = [];\n"
+ @body = Push.wrap(rvar, @body) if @body
+ pre = "#{set}#{@tab}while (#{cond})"
+ @body = Expressions.wrap([new If(@guard, @body)]) if @guard
+ if @returns
+ post = '\n' + new Return(new Literal rvar).compile(merge(o, indent: @idt()))
+ else
+ post = ''
+ "#{pre} {\n#{ @body.compile(o) }\n#{@tab}}#{post}"
+
+#### Op
+
+# Simple Arithmetic and logical operations. Performs some conversion from
+# CoffeeScript operations into their JavaScript equivalents.
+exports.Op = class Op extends Base
+
+ # The map of conversions from CoffeeScript to JavaScript symbols.
+ CONVERSIONS:
+ '==': '==='
+ '!=': '!=='
+ of: 'in'
+
+ # The map of invertible operators.
+ INVERSIONS:
+ '!==': '==='
+ '===': '!=='
+
+ # The list of operators for which we perform
+ # [Python-style comparison chaining](http://docs.python.org/reference/expressions.html#notin).
+ CHAINABLE: ['<', '>', '>=', '<=', '===', '!==']
+
+ # Our assignment operators that have no JavaScript equivalent.
+ ASSIGNMENT: ['||=', '&&=', '?=']
+
+ # Operators must come before their operands with a space.
+ PREFIX_OPERATORS: ['new', 'typeof', 'delete']
+
+ children: ['first', 'second']
+
+ constructor: (op, first, second, flip) ->
+ if op is 'new'
+ return first.newInstance() if first instanceof Call
+ first = new Parens first if first instanceof Code and first.bound
+ super()
+ @operator = @CONVERSIONS[op] or op
+ (@first = first ).tags.operation = yes
+ (@second = second).tags.operation = yes if second
+ @flip = !!flip
+
+ isUnary: ->
+ not @second
+
+ isComplex: -> @operator isnt '!' or @first.isComplex()
+
+ isMutator: ->
+ ends(@operator, '=') and @operator not in ['===', '!==']
+
+ isChainable: ->
+ include(@CHAINABLE, @operator)
+
+ invert: ->
+ if @operator in ['===', '!==']
+ @operator = @INVERSIONS[@operator]
+ this
+ else if @second
+ new Parens(this).invert()
+ else
+ super()
+
+ toString: (idt) ->
+ super(idt, @constructor.name + ' ' + @operator)
+
+ compileNode: (o) ->
+ @first.tags.front = @tags.front if @second
+ return @compileChain(o) if @isChainable() and @first.unwrap() instanceof Op and @first.unwrap().isChainable()
+ return @compileAssignment(o) if include @ASSIGNMENT, @operator
+ return @compileUnary(o) if @isUnary()
+ return @compileExistence(o) if @operator is '?'
+ @first = new Parens @first if @first instanceof Op and @first.isMutator()
+ @second = new Parens @second if @second instanceof Op and @second.isMutator()
+ [@first.compile(o), @operator, @second.compile(o)].join ' '
+
+ # Mimic Python's chained comparisons when multiple comparison operators are
+ # used sequentially. For example:
+ #
+ # bin/coffee -e "puts 50 < 65 > 10"
+ # true
+ compileChain: (o) ->
+ shared = @first.unwrap().second
+ [@first.second, shared] = shared.compileReference o
+ [first, second, shared] = [@first.compile(o), @second.compile(o), shared.compile(o)]
+ "(#{first}) && (#{shared} #{@operator} #{second})"
+
+ # When compiling a conditional assignment, take care to ensure that the
+ # operands are only evaluated once, even though we have to reference them
+ # more than once.
+ compileAssignment: (o) ->
+ [left, rite] = @first.cacheReference o
+ rite = new Assign rite, @second
+ return new Op(@operator.slice(0, -1), left, rite).compile o
+
+ compileExistence: (o) ->
+ if @first.isComplex()
+ ref = o.scope.freeVariable 'ref'
+ fst = new Parens new Assign new Literal(ref), @first
+ else
+ fst = @first
+ ref = fst.compile o
+ new Existence(fst).compile(o) + " ? #{ref} : #{ @second.compile o }"
+
+ # Compile a unary **Op**.
+ compileUnary: (o) ->
+ space = if include @PREFIX_OPERATORS, @operator then ' ' else ''
+ parts = [@operator, space, @first.compile(o)]
+ (if @flip then parts.reverse() else parts).join ''
+
+#### In
+exports.In = class In extends Base
+
+ children: ['object', 'array']
+
+ constructor: (@object, @array) ->
+ super()
+
+ isArray: ->
+ @array instanceof Value and @array.isArray()
+
+ compileNode: (o) ->
+ if @isArray() then @compileOrTest(o) else @compileLoopTest(o)
+
+ compileOrTest: (o) ->
+ [obj1, obj2] = @object.compileReference o, precompile: yes
+ tests = for item, i in @array.base.objects
+ "#{if i then obj2 else obj1} === #{item.compile(o)}"
+ "(#{tests.join(' || ')})"
+
+ compileLoopTest: (o) ->
+ "#{utility 'inArray'}(#{@object.compile o}, #{@array.compile o})"
+
+#### Try
+
+# A classic *try/catch/finally* block.
+exports.Try = class Try extends Base
+
+ children: ['attempt', 'recovery', 'ensure']
+ isStatement: YES
+
+ constructor: (@attempt, @error, @recovery, @ensure) ->
+ super()
+
+ makeReturn: ->
+ @attempt = @attempt.makeReturn() if @attempt
+ @recovery = @recovery.makeReturn() if @recovery
+ this
+
+ # Compilation is more or less as you would expect -- the *finally* clause
+ # is optional, the *catch* is not.
+ compileNode: (o) ->
+ o.indent = @idt 1
+ o.top = true
+ attemptPart = @attempt.compile(o)
+ errorPart = if @error then " (#{ @error.compile(o) }) " else ' '
+ catchPart = if @recovery
+ " catch#{errorPart}{\n#{ @recovery.compile(o) }\n#{@tab}}"
+ else unless @ensure or @recovery then ' catch (_e) {}' else ''
+ finallyPart = (@ensure or '') and ' finally {\n' + @ensure.compile(merge(o)) + "\n#{@tab}}"
+ "#{@tab}try {\n#{attemptPart}\n#{@tab}}#{catchPart}#{finallyPart}"
+
+#### Throw
+
+# Simple node to throw an exception.
+exports.Throw = class Throw extends Base
+
+ children: ['expression']
+ isStatement: YES
+
+ constructor: (@expression) ->
+ super()
+
+ # A **Throw** is already a return, of sorts...
+ makeReturn: THIS
+
+ compileNode: (o) ->
+ "#{@tab}throw #{@expression.compile(o)};"
+
+#### Existence
+
+# Checks a variable for existence -- not *null* and not *undefined*. This is
+# similar to `.nil?` in Ruby, and avoids having to consult a JavaScript truth
+# table.
+exports.Existence = class Existence extends Base
+
+ children: ['expression']
+
+ constructor: (@expression) ->
+ super()
+
+ compileNode: (o) ->
+ code = @expression.compile o
+ code = if IDENTIFIER.test(code) and not o.scope.check code
+ "typeof #{code} !== \"undefined\" && #{code} !== null"
+ else
+ "#{code} != null"
+ if @parenthetical then code else "(#{code})"
+
+#### Parens
+
+# An extra set of parentheses, specified explicitly in the source. At one time
+# we tried to clean up the results by detecting and removing redundant
+# parentheses, but no longer -- you can put in as many as you please.
+#
+# Parentheses are a good way to force any statement to become an expression.
+exports.Parens = class Parens extends Base
+
+ children: ['expression']
+
+ constructor: (@expression) ->
+ super()
+
+ isStatement: (o) ->
+ @expression.isStatement(o)
+ isComplex: ->
+ @expression.isComplex()
+
+ topSensitive: YES
+
+ makeReturn: ->
+ @expression.makeReturn()
+
+ compileNode: (o) ->
+ top = del o, 'top'
+ @expression.parenthetical = true
+ code = @expression.compile(o)
+ return code if top and @expression.isPureStatement o
+ if @parenthetical or @isStatement o
+ return if top then @tab + code + ';' else code
+ "(#{code})"
+
+#### For
+
+# CoffeeScript's replacement for the *for* loop is our array and object
+# comprehensions, that compile into *for* loops here. They also act as an
+# expression, able to return the result of each filtered iteration.
+#
+# Unlike Python array comprehensions, they can be multi-line, and you can pass
+# the current index of the loop as a second parameter. Unlike Ruby blocks,
+# you can map and filter in a single pass.
+exports.For = class For extends Base
+
+ children: ['body', 'source', 'guard']
+ isStatement: YES
+
+ constructor: (@body, source, @name, @index) ->
+ super()
+ {@source, @guard, @step} = source
+ @raw = !!source.raw
+ @object = !!source.object
+ [@name, @index] = [@index, @name] if @object
+ @pattern = @name instanceof Value
+ throw new Error('index cannot be a pattern matching expression') if @index instanceof Value
+ @returns = false
+
+ topSensitive: YES
+
+ makeReturn: ->
+ @returns = true
+ this
+
+ compileReturnValue: (val, o) ->
+ return '\n' + new Return(new Literal val).compile(o) if @returns
+ return '\n' + val if val
+ ''
+
+ # Welcome to the hairiest method in all of CoffeeScript. Handles the inner
+ # loop, filtering, stepping, and result saving for array, object, and range
+ # comprehensions. Some of the generated code can be shared in common, and
+ # some cannot.
+ compileNode: (o) ->
+ topLevel = del(o, 'top') and not @returns
+ range = @source instanceof Value and @source.base instanceof Range and not @source.properties.length
+ source = if range then @source.base else @source
+ codeInBody = not @body.containsPureStatement() and @body.contains (node) -> node instanceof Code
+ scope = o.scope
+ name = @name and @name.compile o
+ index = @index and @index.compile o
+ scope.find(name, immediate: yes) if name and not @pattern and (range or not codeInBody)
+ scope.find(index, immediate: yes) if index
+ rvar = scope.freeVariable 'result' unless topLevel
+ ivar = if range then name else index
+ ivar = scope.freeVariable 'i' if not ivar or codeInBody
+ nvar = scope.freeVariable 'i' if name and not range and codeInBody
+ varPart = ''
+ guardPart = ''
+ unstepPart = ''
+ body = Expressions.wrap([@body])
+ idt1 = @idt 1
+ if range
+ forPart = source.compile merge o, {index: ivar, @step}
+ else
+ svar = sourcePart = @source.compile o
+ if (name or not @raw) and
+ not (IDENTIFIER.test(svar) and scope.check svar, immediate: on)
+ sourcePart = "#{ref = scope.freeVariable 'ref'} = #{svar}"
+ sourcePart = "(#{sourcePart})" unless @object
+ svar = ref
+ namePart = if @pattern
+ new Assign(@name, new Literal "#{svar}[#{ivar}]").compile merge o, top: on
+ else if name
+ "#{name} = #{svar}[#{ivar}]"
+ unless @object
+ lvar = scope.freeVariable 'len'
+ stepPart = if @step then "#{ivar} += #{ @step.compile(o) }" else "#{ivar}++"
+ forPart = "#{ivar} = 0, #{lvar} = #{sourcePart}.length; #{ivar} < #{lvar}; #{stepPart}"
+ resultPart = if rvar then "#{@tab}#{rvar} = [];\n" else ''
+ returnResult = @compileReturnValue(rvar, o)
+ body = Push.wrap(rvar, body) unless topLevel
+ if @guard
+ body = Expressions.wrap([new If(@guard, body)])
+ if codeInBody
+ body.unshift new Literal "var #{name} = #{ivar}" if range
+ body.unshift new Literal "var #{namePart}" if namePart
+ body.unshift new Literal "var #{index} = #{ivar}" if index
+ lastLine = body.expressions.pop()
+ body.push new Assign new Literal(ivar), new Literal index if index
+ body.push new Assign new Literal(nvar), new Literal name if nvar
+ body.push lastLine
+ o.indent = @idt 1
+ body = Expressions.wrap [new Literal body.compile o]
+ body.push new Assign new Literal(index), new Literal ivar if index
+ body.push new Assign new Literal(name), new Literal nvar or ivar if name
+ else
+ varPart = "#{idt1}#{namePart};\n" if namePart
+ if forPart and name is ivar
+ unstepPart = if @step then "#{name} -= #{ @step.compile(o) };" else "#{name}--;"
+ unstepPart = "\n#{@tab}" + unstepPart
+ if @object
+ forPart = "#{ivar} in #{sourcePart}"
+ guardPart = "\n#{idt1}if (!#{utility('hasProp')}.call(#{svar}, #{ivar})) continue;" unless @raw
+ body = body.compile merge o, indent: idt1, top: true
+ vars = if range then name else "#{name}, #{ivar}"
+ """
+ #{resultPart}#{@tab}for (#{forPart}) {#{guardPart}
+ #{varPart}#{body}
+ #{@tab}}#{unstepPart}#{returnResult}
+ """
+
+#### Switch
+
+# A JavaScript *switch* statement. Converts into a returnable expression on-demand.
+exports.Switch = class Switch extends Base
+
+ children: ['subject', 'cases', 'otherwise']
+
+ isStatement: YES
+
+ constructor: (@subject, @cases, @otherwise) ->
+ super()
+ @tags.subjectless = !@subject
+ @subject or= new Literal 'true'
+
+ makeReturn: ->
+ pair[1].makeReturn() for pair in @cases
+ @otherwise.makeReturn() if @otherwise
+ this
+
+ compileNode: (o) ->
+ idt = o.indent = @idt 2
+ o.top = yes
+ code = "#{ @tab }switch (#{ @subject.compile o }) {"
+ for pair in @cases
+ [conditions, block] = pair
+ exprs = block.expressions
+ for condition in flatten [conditions]
+ condition = new Op '!!', new Parens condition if @tags.subjectless
+ code += "\n#{ @idt(1) }case #{ condition.compile o }:"
+ code += "\n#{ block.compile o }"
+ code += "\n#{ idt }break;" unless last(exprs) instanceof Return
+ if @otherwise
+ code += "\n#{ @idt(1) }default:\n#{ @otherwise.compile o }"
+ code += "\n#{ @tab }}"
+ code
+
+#### If
+
+# *If/else* statements. Acts as an expression by pushing down requested returns
+# to the last line of each clause.
+#
+# Single-expression **Ifs** are compiled into conditional operators if possible,
+# because ternaries are already proper expressions, and don't need conversion.
+exports.If = class If extends Base
+
+ children: ['condition', 'body', 'elseBody', 'assigner']
+
+ topSensitive: YES
+
+ constructor: (condition, @body, tags) ->
+ @tags = tags or= {}
+ @condition = if tags.invert then condition.invert() else condition
+ @soakNode = tags.soak
+ @elseBody = null
+ @isChain = false
+
+ bodyNode: -> @body?.unwrap()
+ elseBodyNode: -> @elseBody?.unwrap()
+
+ # Rewrite a chain of **Ifs** to add a default case as the final *else*.
+ addElse: (elseBody) ->
+ if @isChain
+ @elseBodyNode().addElse elseBody
+ else
+ @isChain = elseBody instanceof If
+ @elseBody = @ensureExpressions elseBody
+ this
+
+ # The **If** only compiles into a statement if either of its bodies needs
+ # to be a statement. Otherwise a conditional operator is safe.
+ isStatement: (o) ->
+ @statement or= o?.top or @bodyNode().isStatement(o) or @elseBodyNode()?.isStatement(o)
+
+ compileCondition: (o) ->
+ @condition.parenthetical = yes
+ @condition.compile o
+
+ compileNode: (o) ->
+ if @isStatement o then @compileStatement o else @compileExpression o
+
+ makeReturn: ->
+ if @isStatement()
+ @body and= @ensureExpressions(@body.makeReturn())
+ @elseBody and= @ensureExpressions(@elseBody.makeReturn())
+ this
+ else
+ new Return this
+
+ ensureExpressions: (node) ->
+ if node instanceof Expressions then node else new Expressions [node]
+
+ # Compile the **If** as a regular *if-else* statement. Flattened chains
+ # force inner *else* bodies into statement form.
+ compileStatement: (o) ->
+ top = del o, 'top'
+ child = del o, 'chainChild'
+ condO = merge o
+ o.indent = @idt 1
+ o.top = true
+ ifPart = "if (#{ @compileCondition condO }) {\n#{ @body.compile o }\n#{@tab}}"
+ ifPart = @tab + ifPart unless child
+ return ifPart unless @elseBody
+ ifPart + if @isChain
+ ' else ' + @elseBodyNode().compile merge o, indent: @tab, chainChild: true
+ else
+ " else {\n#{ @elseBody.compile(o) }\n#{@tab}}"
+
+ # Compile the If as a conditional operator.
+ compileExpression: (o) ->
+ @bodyNode().tags.operation = @condition.tags.operation = yes
+ @elseBodyNode().tags.operation = yes if @elseBody
+ ifPart = @condition.compile(o) + ' ? ' + @bodyNode().compile(o)
+ elsePart = if @elseBody then @elseBodyNode().compile(o) else 'undefined'
+ code = "#{ifPart} : #{elsePart}"
+ if @tags.operation or @soakNode then "(#{code})" else code
+
+ unfoldSoak: -> @soakNode and this
+
+ # Unfold a node's child if soak, then tuck the node under created `If`
+ @unfoldSoak: (o, parent, name) ->
+ return unless ifn = parent[name].unfoldSoak o
+ parent[name] = ifn.body
+ ifn.body = new Value parent
+ ifn
+
+# Faux-Nodes
+# ----------
+# Faux-nodes are never created by the grammar, but are used during code
+# generation to generate other combinations of nodes.
+
+#### Push
+
+# The **Push** creates the tree for `array.push(value)`,
+# which is helpful for recording the result arrays from comprehensions.
+Push =
+ wrap: (name, expressions) ->
+ return expressions if expressions.empty() or expressions.containsPureStatement()
+ Expressions.wrap [new Call(
+ new Value new Literal(name), [new Accessor new Literal 'push']
+ [expressions.unwrap()]
+ )]
+
+#### Closure
+
+# A faux-node used to wrap an expressions body in a closure.
+Closure =
+
+ # Wrap the expressions body, unless it contains a pure statement,
+ # in which case, no dice. If the body mentions `this` or `arguments`,
+ # then make sure that the closure wrapper preserves the original values.
+ wrap: (expressions, statement, noReturn) ->
+ return expressions if expressions.containsPureStatement()
+ func = new Parens new Code [], Expressions.wrap [expressions]
+ args = []
+ if (mentionsArgs = expressions.contains @literalArgs) or
+ ( expressions.contains @literalThis)
+ meth = new Literal if mentionsArgs then 'apply' else 'call'
+ args = [new Literal 'this']
+ args.push new Literal 'arguments' if mentionsArgs
+ func = new Value func, [new Accessor meth]
+ func.noReturn = noReturn
+ call = new Call func, args
+ if statement then Expressions.wrap [call] else call
+
+ literalArgs: (node) -> node instanceof Literal and node.value is 'arguments'
+ literalThis: (node) -> node instanceof Literal and node.value is 'this' or
+ node instanceof Code and node.bound
+
+# Constants
+# ---------
+
+UTILITIES =
+
+ # Correctly set up a prototype chain for inheritance, including a reference
+ # to the superclass for `super()` calls. See:
+ # [goog.inherits](http://closure-library.googlecode.com/svn/docs/closureGoogBase.js.source.html#line1206).
+ extends: '''
+ function(child, parent) {
+ function ctor() { this.constructor = child; }
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ }
+ '''
+
+ # Create a function bound to the current value of "this".
+ bind: '''
+ function(func, context) {
+ return function() { return func.apply(context, arguments); };
+ }
+ '''
+
+ # Discover if an item is in an array.
+ inArray: '''
+ (function() {
+ var indexOf = Array.prototype.indexOf || function(item) {
+ var i = this.length; while (i--) if (this[i] === item) return i;
+ return -1;
+ };
+ return function(item, array) { return indexOf.call(array, item) > -1; };
+ })();
+ '''
+
+ # Shortcuts to speed up the lookup time for native functions.
+ hasProp: 'Object.prototype.hasOwnProperty'
+ slice: 'Array.prototype.slice'
+
+# Tabs are two spaces for pretty printing.
+TAB = ' '
+
+# Trim out all trailing whitespace, so that the generated code plays nice
+# with Git.
+TRAILING_WHITESPACE = /[ \t]+$/gm
+
+IDENTIFIER = /^[$A-Za-z_][$\w]*$/
+NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?$/i
+SIMPLENUM = /^[+-]?\d+$/
+
+# Is a literal value a string?
+IS_STRING = /^['"]/
+
+# Utility Functions
+# -----------------
+
+# Helper for ensuring that utility functions are assigned at the top level.
+utility = (name) ->
+ ref = "__#{name}"
+ Scope.root.assign ref, UTILITIES[name]
+ ref
--- /dev/null
+# A simple **OptionParser** class to parse option flags from the command-line.
+# Use it like so:
+#
+# parser = new OptionParser switches, helpBanner
+# options = parser.parse process.argv
+#
+# The first non-option is considered to be the start of the file (and file
+# option) list, and all subsequent arguments are left unparsed.
+exports.OptionParser = class OptionParser
+
+ # Initialize with a list of valid options, in the form:
+ #
+ # [short-flag, long-flag, description]
+ #
+ # Along with an an optional banner for the usage help.
+ constructor: (rules, banner) ->
+ @banner = banner
+ @rules = buildRules rules
+
+ # Parse the list of arguments, populating an `options` object with all of the
+ # specified options, and returning it. `options.arguments` will be an array
+ # containing the remaning 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.
+ parse: (args) ->
+ options = arguments: []
+ args = normalizeArguments args
+ for arg, i in args
+ isOption = !!(arg.match(LONG_FLAG) or arg.match(SHORT_FLAG))
+ matchedRule = no
+ for rule in @rules
+ if rule.shortFlag is arg or rule.longFlag is arg
+ value = if rule.hasArgument then args[i += 1] else true
+ options[rule.name] = if rule.isList then (options[rule.name] or []).concat value else value
+ matchedRule = yes
+ break
+ throw new Error "unrecognized option: #{arg}" if isOption and not matchedRule
+ if not isOption
+ options.arguments = args.slice i
+ break
+ options
+
+ # Return the help text for this **OptionParser**, listing and describing all
+ # of the valid options, for `--help` and such.
+ help: ->
+ lines = ['Available options:']
+ lines.unshift "#{@banner}\n" if @banner
+ for rule in @rules
+ spaces = 15 - rule.longFlag.length
+ spaces = if spaces > 0 then Array(spaces + 1).join(' ') else ''
+ letPart = if rule.shortFlag then rule.shortFlag + ', ' else ' '
+ lines.push ' ' + letPart + rule.longFlag + spaces + rule.description
+ "\n#{ lines.join('\n') }\n"
+
+# Helpers
+# -------
+
+# Regex matchers for option flags.
+LONG_FLAG = /^(--\w[\w\-]+)/
+SHORT_FLAG = /^(-\w)/
+MULTI_FLAG = /^-(\w{2,})/
+OPTIONAL = /\[(\w+(\*?))\]/
+
+# Build and return the list of option rules. If the optional *short-flag* is
+# unspecified, leave it out by padding with `null`.
+buildRules = (rules) ->
+ for tuple in rules
+ tuple.unshift null if tuple.length < 3
+ buildRule tuple...
+
+# Build a rule from a `-o` short flag, a `--output [DIR]` long flag, and the
+# description of what the option does.
+buildRule = (shortFlag, longFlag, description, options) ->
+ match = longFlag.match(OPTIONAL)
+ longFlag = longFlag.match(LONG_FLAG)[1]
+ options or= {}
+ {
+ name: longFlag.substr 2
+ shortFlag: shortFlag
+ longFlag: longFlag
+ description: description
+ hasArgument: !!(match and match[1])
+ isList: !!(match and match[2])
+ }
+
+# Normalize arguments by expanding merged flags into multiple flags. This allows
+# you to have `-wl` be the same as `--watch --lint`.
+normalizeArguments = (args) ->
+ args = args.slice 0
+ result = []
+ for arg in args
+ if match = arg.match MULTI_FLAG
+ result.push '-' + l for l in match[1].split ''
+ else
+ result.push arg
+ result
--- /dev/null
+# 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 **Node.js** API.
+# Using it looks like this:
+#
+# coffee> puts "#{num} bottles of beer" for num in [99..1]
+
+# Require the **coffee-script** module to get access to the compiler.
+CoffeeScript = require './coffee-script'
+helpers = require './helpers'
+readline = require 'readline'
+
+# Start by opening up **stdio**.
+stdio = process.openStdin()
+
+# Quick alias for quitting the REPL.
+helpers.extend global, quit: -> process.exit(0)
+
+# The main REPL function. **run** 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.
+run = (buffer) ->
+ try
+ val = CoffeeScript.eval buffer.toString(), bare: on, globals: on, fileName: 'repl'
+ puts inspect val if val isnt undefined
+ catch err
+ puts err.stack or err.toString()
+ repl.prompt()
+
+# Create the REPL by listening to **stdin**.
+repl = readline.createInterface stdio
+repl.setPrompt 'coffee> '
+stdio.on 'data', (buffer) -> repl.write buffer
+repl.on 'close', -> stdio.destroy()
+repl.on 'line', run
+repl.prompt()
--- /dev/null
+# 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 **Rewriter** to convert
+# shorthand into the unambiguous long form, add implicit indentation and
+# parentheses, balance incorrect nestings, and generally clean things up.
+
+# Import the helpers we need.
+{include} = require './helpers'
+
+# The **Rewriter** class is used by the [Lexer](lexer.html), directly against
+# its internal array of tokens.
+class exports.Rewriter
+
+ # Helpful snippet for debugging:
+ # puts (t[0] + '/' + t[1] for t in @tokens).join ' '
+
+ # 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.
+ rewrite: (@tokens) ->
+ @adjustComments()
+ @removeLeadingNewlines()
+ @removeMidExpressionNewlines()
+ @closeOpenCalls()
+ @closeOpenIndexes()
+ @addImplicitIndentation()
+ @tagPostfixConditionals()
+ @addImplicitBraces()
+ @addImplicitParentheses()
+ @ensureBalance BALANCED_PAIRS
+ @rewriteClosingParens()
+ @tokens
+
+ # 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.
+ scanTokens: (block) ->
+ {tokens} = this
+ i = 0
+ i += block.call this, token, i, tokens while token = tokens[i]
+ true
+
+ detectEnd: (i, condition, action) ->
+ {tokens} = this
+ levels = 0
+ while token = tokens[i]
+ return action.call this, token, i if levels is 0 and condition.call this, token, i
+ return action.call this, token, i - 1 if not token or levels < 0
+ if include EXPRESSION_START, token[0]
+ levels += 1
+ else if include EXPRESSION_END, token[0]
+ levels -= 1
+ i += 1
+ i - 1
+
+ # Massage newlines and indentations so that comments don't have to be
+ # correctly indented, or appear on a line of their own.
+ adjustComments: ->
+ @scanTokens (token, i, tokens) ->
+ return 1 unless token[0] is 'HERECOMMENT'
+ before = tokens[i - 2]
+ prev = tokens[i - 1]
+ post = tokens[i + 1]
+ after = tokens[i + 2]
+ if after?[0] is 'INDENT'
+ tokens.splice i + 2, 1
+ if before?[0] is 'OUTDENT' and post?[0] is 'TERMINATOR'
+ tokens.splice i - 2, 1
+ else
+ tokens.splice i, 0, after
+ else if prev and prev[0] not in ['TERMINATOR', 'INDENT', 'OUTDENT']
+ if post?[0] is 'TERMINATOR' and after?[0] is 'OUTDENT'
+ tokens.splice i + 2, 0, tokens.splice(i, 2)...
+ if tokens[i + 2][0] isnt 'TERMINATOR'
+ tokens.splice i + 2, 0, ['TERMINATOR', '\n', prev[2]]
+ else
+ tokens.splice i, 0, ['TERMINATOR', '\n', prev[2]]
+ return 2
+ 1
+
+ # Leading newlines would introduce an ambiguity in the grammar, so we
+ # dispatch them here.
+ removeLeadingNewlines: ->
+ break for [tag], i in @tokens when tag isnt 'TERMINATOR'
+ @tokens.splice 0, i if i
+
+ # Some blocks occur in the middle of expressions -- when we're expecting
+ # this, remove their trailing newlines.
+ removeMidExpressionNewlines: ->
+ @scanTokens (token, i, tokens) ->
+ return 1 unless token[0] is 'TERMINATOR' and include EXPRESSION_CLOSE, @tag(i + 1)
+ tokens.splice i, 1
+ 0
+
+ # 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.
+ closeOpenCalls: ->
+ condition = (token, i) ->
+ token[0] in [')', 'CALL_END'] or
+ token[0] is 'OUTDENT' and @tag(i - 1) is ')'
+ action = (token, i) ->
+ @tokens[if token[0] is 'OUTDENT' then i - 1 else i][0] = 'CALL_END'
+ @scanTokens (token, i) ->
+ @detectEnd i + 1, condition, action if token[0] is 'CALL_START'
+ 1
+
+ # The lexer has tagged the opening parenthesis of an indexing operation call.
+ # Match it with its paired close.
+ closeOpenIndexes: ->
+ condition = (token, i) -> token[0] in [']', 'INDEX_END']
+ action = (token, i) -> token[0] = 'INDEX_END'
+ @scanTokens (token, i) ->
+ @detectEnd i + 1, condition, action if token[0] is 'INDEX_START'
+ 1
+
+ # Object literals may be written with implicit braces, for simple cases.
+ # Insert the missing braces here, so that the parser doesn't have to.
+ addImplicitBraces: ->
+ stack = []
+ condition = (token, i) ->
+ return false if 'HERECOMMENT' in [@tag(i + 1), @tag(i - 1)]
+ [one, two, three] = @tokens.slice i + 1, i + 4
+ [tag] = token
+ tag in ['TERMINATOR', 'OUTDENT'] and not (two?[0] is ':' or one?[0] is '@' and three?[0] is ':') or
+ tag is ',' and one?[0] not in ['IDENTIFIER', 'NUMBER', 'STRING', '@', 'TERMINATOR', 'OUTDENT']
+ action = (token, i) -> @tokens.splice i, 0, ['}', '}', token[2]]
+ @scanTokens (token, i, tokens) ->
+ if include EXPRESSION_START, tag = token[0]
+ stack.push if tag is 'INDENT' and @tag(i - 1) is '{' then '{' else tag
+ return 1
+ if include EXPRESSION_END, tag
+ stack.pop()
+ return 1
+ return 1 unless tag is ':' and stack[stack.length - 1] isnt '{'
+ stack.push '{'
+ idx = if @tag(i - 2) is '@' then i - 2 else i - 1
+ idx -= 2 if @tag(idx - 2) is 'HERECOMMENT'
+ tok = ['{', '{', token[2]]
+ tok.generated = yes
+ tokens.splice idx, 0, tok
+ @detectEnd i + 2, condition, action
+ 2
+
+ # 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.
+ addImplicitParentheses: ->
+ classLine = no
+ action = (token, i) ->
+ idx = if token[0] is 'OUTDENT' then i + 1 else i
+ @tokens.splice idx, 0, ['CALL_END', ')', token[2]]
+ @scanTokens (token, i, tokens) ->
+ tag = token[0]
+ classLine = yes if tag is 'CLASS'
+ prev = tokens[i - 1]
+ next = tokens[i + 1]
+ callObject = not classLine and tag is 'INDENT' and
+ next and next.generated and next[0] is '{' and
+ prev and include(IMPLICIT_FUNC, prev[0])
+ seenSingle = no
+ classLine = no if include LINEBREAKS, tag
+ token.call = yes if prev and not prev.spaced and tag is '?'
+ return 1 unless callObject or
+ prev?.spaced and (prev.call or include(IMPLICIT_FUNC, prev[0])) and
+ (include(IMPLICIT_CALL, tag) or include(IMPLICIT_UNSPACED_CALL, tag) and not token.spaced)
+ tokens.splice i, 0, ['CALL_START', '(', token[2]]
+ @detectEnd i + (if callObject then 2 else 1), (token, i) ->
+ return yes if not seenSingle and token.fromThen
+ [tag] = token
+ seenSingle = yes if tag in ['IF', 'ELSE', 'UNLESS', '->', '=>']
+ return yes if tag is 'PROPERTY_ACCESS' and @tag(i - 1) is 'OUTDENT'
+ not token.generated and @tag(i - 1) isnt ',' and include(IMPLICIT_END, tag) and
+ (tag isnt 'INDENT' or
+ (@tag(i - 2) isnt 'CLASS' and not include(IMPLICIT_BLOCK, @tag(i - 1)) and
+ not ((post = @tokens[i + 1]) and post.generated and post[0] is '{')))
+ , action
+ prev[0] = 'FUNC_EXIST' if prev[0] is '?'
+ 2
+
+ # Because our grammar is LALR(1), it can't handle some single-line
+ # expressions that lack ending delimiters. The **Rewriter** 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.
+ addImplicitIndentation: ->
+ @scanTokens (token, i, tokens) ->
+ [tag] = token
+ if tag is 'ELSE' and @tag(i - 1) isnt 'OUTDENT'
+ tokens.splice i, 0, @indentation(token)...
+ return 2
+ if tag is 'CATCH' and @tag(i + 2) in ['TERMINATOR', 'FINALLY']
+ tokens.splice i + 2, 0, @indentation(token)...
+ return 4
+ if include(SINGLE_LINERS, tag) and @tag(i + 1) isnt 'INDENT' and
+ not (tag is 'ELSE' and @tag(i + 1) is 'IF')
+ starter = tag
+ [indent, outdent] = @indentation token
+ indent.fromThen = true if starter is 'THEN'
+ indent.generated = outdent.generated = true
+ tokens.splice i + 1, 0, indent
+ condition = (token, i) ->
+ token[1] isnt ';' and include(SINGLE_CLOSERS, token[0]) and
+ not (token[0] is 'ELSE' and starter not in ['IF', 'THEN'])
+ action = (token, i) ->
+ @tokens.splice (if @tag(i - 1) is ',' then i - 1 else i), 0, outdent
+ @detectEnd i + 2, condition, action
+ tokens.splice i, 1 if tag is 'THEN'
+ return 1
+ return 1
+
+ # Tag postfix conditionals as such, so that we can parse them with a
+ # different precedence.
+ tagPostfixConditionals: ->
+ condition = (token, i) -> token[0] in ['TERMINATOR', 'INDENT']
+ @scanTokens (token, i) ->
+ return 1 unless token[0] in ['IF', 'UNLESS']
+ original = token
+ @detectEnd i + 1, condition, (token, i) ->
+ original[0] = 'POST_' + original[0] if token[0] isnt 'INDENT'
+ 1
+
+ # Ensure that all listed pairs of tokens are correctly balanced throughout
+ # the course of the token stream.
+ ensureBalance: (pairs) ->
+ levels = {}
+ openLine = {}
+ @scanTokens (token, i) ->
+ [tag] = token
+ for [open, close] in pairs
+ levels[open] |= 0
+ if tag is open
+ openLine[open] = token[2] if levels[open] is 0
+ levels[open] += 1
+ else if tag is close
+ levels[open] -= 1
+ throw Error "too many #{token[1]} on line #{token[2] + 1}" if levels[open] < 0
+ 1
+ unclosed = key for all key, value of levels when value > 0
+ if unclosed.length
+ throw Error "unclosed #{ open = unclosed[0] } on line #{openLine[open] + 1}"
+
+ # We'd like to support syntax like this:
+ #
+ # el.click((event) ->
+ # el.hide())
+ #
+ # In order to accomplish this, move outdents that follow closing parens
+ # inwards, safely. The steps to accomplish this are:
+ #
+ # 1. Check that all paired tokens are balanced and in order.
+ # 2. Rewrite the stream with a stack: if you see an `EXPRESSION_START`, add it
+ # to the stack. If you see an `EXPRESSION_END`, pop the stack and replace
+ # it with the inverse of what we've just popped.
+ # 3. Keep track of "debt" for tokens that we manufacture, to make sure we end
+ # up balanced in the end.
+ # 4. Be careful not to alter array or parentheses delimiters with overzealous
+ # rewriting.
+ rewriteClosingParens: ->
+ stack = []
+ debt = {}
+ (debt[key] = 0) for all key of INVERSES
+ @scanTokens (token, i, tokens) ->
+ if include EXPRESSION_START, tag = token[0]
+ stack.push token
+ return 1
+ return 1 unless include EXPRESSION_END, tag
+ if debt[inv = INVERSES[tag]] > 0
+ debt[inv] -= 1
+ tokens.splice i, 1
+ return 0
+ match = stack.pop()
+ mtag = match[0]
+ oppos = INVERSES[mtag]
+ return 1 if tag is oppos
+ debt[mtag] += 1
+ val = [oppos, if mtag is 'INDENT' then match[1] else oppos]
+ if @tag(i + 2) is mtag
+ tokens.splice i + 3, 0, val
+ stack.push match
+ else
+ tokens.splice i, 0, val
+ 1
+
+ # Generate the indentation tokens, based on another token on the same line.
+ indentation: (token) ->
+ [['INDENT', 2, token[2]], ['OUTDENT', 2, token[2]]]
+
+ # Look up a tag by token index.
+ tag: (i) -> @tokens[i]?[0]
+
+# Constants
+# ---------
+
+# List of the token pairs that must be balanced.
+BALANCED_PAIRS = [
+ ['(', ')']
+ ['[', ']']
+ ['{', '}']
+ ['INDENT', 'OUTDENT'],
+ ['CALL_START', 'CALL_END']
+ ['PARAM_START', 'PARAM_END']
+ ['INDEX_START', 'INDEX_END']
+]
+
+# The inverse mappings of `BALANCED_PAIRS` we're trying to fix up, so we can
+# look things up from either end.
+INVERSES = {}
+
+# The tokens that signal the start/end of a balanced pair.
+EXPRESSION_START = []
+EXPRESSION_END = []
+
+for [left, rite] in BALANCED_PAIRS
+ EXPRESSION_START.push INVERSES[rite] = left
+ EXPRESSION_END .push INVERSES[left] = rite
+
+# Tokens that indicate the close of a clause of an expression.
+EXPRESSION_CLOSE = ['CATCH', 'WHEN', 'ELSE', 'FINALLY'].concat EXPRESSION_END
+
+# Tokens that, if followed by an `IMPLICIT_CALL`, indicate a function invocation.
+IMPLICIT_FUNC = ['IDENTIFIER', 'SUPER', ')', 'CALL_END', ']', 'INDEX_END', '@', 'THIS']
+
+# If preceded by an `IMPLICIT_FUNC`, indicates a function invocation.
+IMPLICIT_CALL = [
+ 'IDENTIFIER', 'NUMBER', 'STRING', 'JS', 'REGEX', 'NEW', 'PARAM_START', 'CLASS'
+ 'IF', 'UNLESS', 'TRY', 'SWITCH', 'THIS', 'BOOL', 'UNARY',
+ '@', '->', '=>', '[', '(', '{', '--', '++'
+]
+
+IMPLICIT_UNSPACED_CALL = ['+', '-']
+
+# Tokens indicating that the implicit call must enclose a block of expressions.
+IMPLICIT_BLOCK = ['->', '=>', '{', '[', ',']
+
+# Tokens that always mark the end of an implicit call for single-liners.
+IMPLICIT_END = ['POST_IF', 'POST_UNLESS', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'TERMINATOR', 'INDENT']
+
+# Single-line flavors of block expressions that have unclosed endings.
+# The grammar can't disambiguate them, so we insert the implicit indentation.
+SINGLE_LINERS = ['ELSE', '->', '=>', 'TRY', 'FINALLY', 'THEN']
+SINGLE_CLOSERS = ['TERMINATOR', 'CATCH', 'FINALLY', 'ELSE', 'OUTDENT', 'LEADING_WHEN']
+
+# Tokens that end a line.
+LINEBREAKS = ['TERMINATOR', 'INDENT', 'OUTDENT']
--- /dev/null
+# The **Scope** 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 `var`, and which are shared
+# with the outside.
+
+# Import the helpers we plan to use.
+{extend, last} = require './helpers'
+
+exports.Scope = class Scope
+
+ # The top-level **Scope** object.
+ @root: null
+
+ # Initialize a scope with its parent, for lookups up the chain,
+ # as well as a reference to the **Expressions** node is belongs to, which is
+ # where it should declare its variables, and a reference to the function that
+ # it wraps.
+ constructor: (@parent, @expressions, @method) ->
+ @variables = {'arguments'}
+ if @parent
+ @garbage = @parent.garbage
+ else
+ @garbage = []
+ Scope.root = this
+
+ # Create a new garbage level
+ startLevel: ->
+ @garbage.push []
+
+ # Return to the previous garbage level and erase referenced temporary
+ # variables in current level from scope.
+ endLevel: ->
+ vars = @variables
+ (vars[name] = 'reuse') for name in @garbage.pop() when vars[name] is 'var'
+
+ # Look up a variable name in lexical scope, and declare it if it does not
+ # already exist.
+ find: (name, options) ->
+ return true if @check name, options
+ @variables[name] = 'var'
+ false
+
+ # Test variables and return true the first time fn(v, k) returns true
+ any: (fn) ->
+ for v, k of @variables when fn(v, k)
+ return true
+ return false
+
+ # Reserve a variable name as originating from a function parameter for this
+ # scope. No `var` required for internal references.
+ parameter: (name) ->
+ @variables[name] = 'param'
+
+ # Just check to see if a variable has already been declared, without reserving,
+ # walks up to the root scope.
+ check: (name, options) ->
+ immediate = Object::hasOwnProperty.call @variables, name
+ return immediate if immediate or options?.immediate
+ !!@parent?.check name
+
+ # Generate a temporary variable name at the given index.
+ temporary: (type, index) ->
+ if type.length > 1
+ '_' + type + if index > 1 then index else ''
+ else
+ '_' + (index + parseInt type, 36).toString(36).replace /\d/g, 'a'
+
+ # If we need to store an intermediate result, find an available name for a
+ # compiler-generated variable. `_var`, `_var2`, and so on...
+ freeVariable: (type) ->
+ index = 0
+ index++ while @check(temp = @temporary type, index) and @variables[temp] isnt 'reuse'
+ @variables[temp] = 'var'
+ last(@garbage).push temp if @garbage.length
+ temp
+
+ # Ensure that an assignment is made at the top of this scope
+ # (or at the top-level scope, if requested).
+ assign: (name, value) ->
+ @variables[name] = value: value, assigned: true
+
+ # Does this scope reference any variables that need to be declared in the
+ # given function body?
+ hasDeclarations: (body) ->
+ body is @expressions and @any (k, val) -> val in ['var', 'reuse']
+
+ # Does this scope reference any assignments that need to be declared at the
+ # top of the given function body?
+ hasAssignments: (body) ->
+ body is @expressions and @any (k, val) -> val.assigned
+
+ # Return the list of variables first declared in this scope.
+ declaredVariables: ->
+ (key for key, val of @variables when val in ['var', 'reuse']).sort()
+
+ # Return the list of assignments that are supposed to be made at the top
+ # of this scope.
+ assignedVariables: ->
+ "#{key} = #{val.value}" for key, val of @variables when val.assigned
+
+ # Compile the JavaScript for all of the variable declarations in this scope.
+ compiledDeclarations: ->
+ @declaredVariables().join ', '
+
+ # Compile the JavaScript forall of the variable assignments in this scope.
+ compiledAssignments: ->
+ @assignedVariables().join ', '
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+ <title>CoffeeScript Test Suite</title>
+ <script src="../extras/coffee-script.js"></script>
+ <style>
+ body {
+ margin: 30px;
+ font-family: Menlo, Monaco, monospace;
+ }
+ h1 {
+ font-size: 20px;
+ }
+ #stdout {
+ }
+ </style>
+</head>
+<body>
+
+ <h1>CoffeeScript Test Suite</h1>
+ <pre id="stdout"></pre>
+
+ <script type="text/coffeescript">
+
+ stdout = document.getElementById 'stdout'
+ start = new Date
+ success = total = done = failed = 0
+
+ say = (msg, yay) ->
+ div = document.createElement 'div'
+ div.appendChild document.createTextNode msg
+ div.style.color = if yay then 'green' else 'red'
+ stdout.appendChild div
+ msg
+
+ this.ok = (good, msg) ->
+ ++total
+ if good then ++success else throw Error say msg
+
+ this.eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y
+
+ this.throws = (fun, err, msg) ->
+ try fun(); throw new String 'No Error'
+ catch e then eq e, err
+
+ CoffeeScript.run = (code, cb) ->
+ try Function(CoffeeScript.compile code, wrap: no)()
+ catch e then cb(); throw e
+ cb yes
+
+ run = (name) ->
+ CoffeeScript.load "test_#{name}.coffee", (yay) ->
+ say "#{ if yay then '\u2714' else '\u3000' } #{name}", yay
+ ++failed unless yay
+ fin() if ++done is names.length
+
+ fin = ->
+ yay = success is total and not failed
+ sec = (new Date - start) / 1000
+ msg = "passed #{success} tests in #{ sec.toFixed 2 } seconds"
+ msg = "failed #{ total - success } tests and #{msg}" unless yay
+ say msg, yay
+
+ run name for name in names = [
+ 'arguments'
+ 'assignment'
+ 'break'
+ 'chaining'
+ 'classes'
+ 'comments'
+ 'compilation'
+ 'compound_assignment'
+ 'comprehensions'
+ 'existence'
+ 'expressions'
+ 'functions'
+ 'helpers'
+ 'heredocs'
+ 'if'
+ 'literals'
+ 'operations'
+ 'pattern_matching'
+ 'regexps'
+ 'returns'
+ 'splats'
+ 'strings'
+ 'switch'
+ 'try_catch'
+ 'while'
+ ]
+ </script>
+
+</body>
+</html>
\ No newline at end of file
--- /dev/null
+area = (x, y, x1, y1) ->
+ (x - x1) * (x - y1)
+
+x = y = 10
+x1 = y1 = 20
+
+ok area(x, y, x1, y1) is 100
+
+# ok(area(x, y,
+# x1, y1) is 100)
+
+ok(area(
+ x
+ y
+ x1
+ y1
+) is 100)
+
+
+sumOfArgs = ->
+ sum = 0
+ sum += val for val in arguments
+ sum
+
+ok sumOfArgs(1, 2, 3, 4, 5) is 15
+
+
+((@arg) ->).call context = {}, 1
+ok context.arg is 1
+
+((splat..., @arg) ->).call context, 1, 2, 3
+ok context.arg is 3
+
+((@arg...) ->).call context, 1, 2, 3
+ok context.arg.join ' ' is '1 2 3'
+
+class Klass
+ constructor: (@one, @two) ->
+
+obj = new Klass 1, 2
+
+ok obj.one is 1
+ok obj.two is 2
\ No newline at end of file
--- /dev/null
+# Can assign the result of a try/catch block.
+result = try
+ nonexistent * missing
+catch error
+ true
+
+result2 = try nonexistent * missing catch error then true
+
+ok result is true and result2 is true
+
+
+# Can assign a conditional statement.
+getX = -> 10
+
+if x = getX() then 100
+
+ok x is 10
+
+x = if getX() then 100
+
+ok x is 100
+
+
+# This-assignment.
+tester = ->
+ @example = -> 'example function'
+ this
+
+ok tester().example() is 'example function'
+
+
+try throw CoffeeScript.tokens 'in = 1'
+catch e then eq e.message, 'Reserved word "in" on line 1 can\'t be assigned'
--- /dev/null
+# Test with break at the top level.
+array = [1,2,3]
+callWithLambda = (l) -> null
+for i in array
+ result = callWithLambda(->)
+ if i == 2
+ puts "i = 2"
+ else
+ break
+
+ok result is null
+
+
+# Test with break *not* at the top level.
+someFunc = (input) ->
+ takesLambda = (l) -> null
+ for i in [1,2]
+ result = takesLambda(->)
+ if input == 1
+ return 1
+ else
+ break
+
+ return 2
+
+ok someFunc(1) is 1
+ok someFunc(2) is 2
+
--- /dev/null
+# Basic chained function calls.
+identityWrap = (x) ->
+ -> x
+
+result = identityWrap(identityWrap(true))()()
+
+ok result
+
+
+# Chained accesses split on period/newline, backwards and forwards.
+str = 'god'
+
+result = str.
+ split('').
+ reverse().
+ reverse().
+ reverse()
+
+ok result.join('') is 'dog'
+
+result = str
+ .split('')
+ .reverse()
+ .reverse()
+ .reverse()
+
+ok result.join('') is 'dog'
+
+
+# Newline suppression for operators.
+six =
+ 1 +
+ 2 +
+ 3
+
+ok six is 6
+
+
+# Ensure that indented array literals don't trigger whitespace rewriting.
+func = () ->
+ ok arguments.length is 1
+
+func(
+ [[[[[],
+ []],
+ [[]]]],
+ []])
+
+id = (x) -> x
+
+greeting = id(
+ """
+ Hello
+ """)
+
+ok greeting is "Hello"
--- /dev/null
+# Test classes with a four-level inheritance chain.
+class Base
+ func: (string) ->
+ "zero/#{string}"
+
+ @static: (string) ->
+ "static/#{string}"
+
+class FirstChild extends Base
+ func: (string) ->
+ super('one/') + string
+
+SecondChild = class extends FirstChild
+ func: (string) ->
+ super('two/') + string
+
+thirdCtor = ->
+ @array = [1, 2, 3]
+
+class ThirdChild extends SecondChild
+ constructor: thirdCtor
+
+ # Gratuitous comment for testing.
+ func: (string) ->
+ super('three/') + string
+
+result = (new ThirdChild).func 'four'
+
+ok result is 'zero/one/two/three/four'
+ok Base.static('word') is 'static/word'
+
+FirstChild::func = (string) ->
+ super('one/').length + string
+
+result = (new ThirdChild).func 'four'
+
+ok result is '9two/three/four'
+
+ok (new ThirdChild).array.join(' ') is '1 2 3'
+
+
+class TopClass
+ constructor: (arg) ->
+ @prop = 'top-' + arg
+
+class SuperClass extends TopClass
+ constructor: (arg) ->
+ super 'super-' + arg
+
+class SubClass extends SuperClass
+ constructor: ->
+ super 'sub'
+
+ok (new SubClass).prop is 'top-super-sub'
+
+
+class OneClass
+ @new: 'new'
+ function: 'function'
+ constructor: (name) -> @name = name
+
+class TwoClass extends OneClass
+
+Function.prototype.new = -> new this arguments...
+
+ok (TwoClass.new('three')).name is 'three'
+ok (new OneClass).function is 'function'
+ok OneClass.new is 'new'
+
+delete Function.prototype.new
+
+
+# And now the same tests, but written in the manual style:
+Base = ->
+Base::func = (string) ->
+ 'zero/' + string
+Base::['func-func'] = (string) ->
+ "dynamic-#{string}"
+
+FirstChild = ->
+FirstChild extends Base
+FirstChild::func = (string) ->
+ super('one/') + string
+
+SecondChild = ->
+SecondChild extends FirstChild
+SecondChild::func = (string) ->
+ super('two/') + string
+
+ThirdChild = ->
+ @array = [1, 2, 3]
+ this
+ThirdChild extends SecondChild
+ThirdChild::func = (string) ->
+ super('three/') + string
+
+result = (new ThirdChild).func 'four'
+
+ok result is 'zero/one/two/three/four'
+
+ok (new ThirdChild)['func-func']('thing') is 'dynamic-thing'
+
+
+TopClass = (arg) ->
+ @prop = 'top-' + arg
+ this
+
+SuperClass = (arg) ->
+ super 'super-' + arg
+ this
+
+SubClass = ->
+ super 'sub'
+ this
+
+SuperClass extends TopClass
+SubClass extends SuperClass
+
+ok (new SubClass).prop is 'top-super-sub'
+
+
+# '@' referring to the current instance, and not being coerced into a call.
+class ClassName
+ amI: ->
+ @ instanceof ClassName
+
+obj = new ClassName
+ok obj.amI()
+
+
+# super() calls in constructors of classes that are defined as object properties.
+class Hive
+ constructor: (name) -> @name = name
+
+class Hive.Bee extends Hive
+ constructor: (name) -> super
+
+maya = new Hive.Bee 'Maya'
+ok maya.name is 'Maya'
+
+
+# Class with JS-keyword properties.
+class Class
+ class: 'class'
+ name: -> @class
+
+instance = new Class
+ok instance.class is 'class'
+ok instance.name() is 'class'
+
+
+# Classes with methods that are pre-bound to the instance.
+# ... or statically, to the class.
+class Dog
+
+ constructor: (name) ->
+ @name = name
+
+ bark: =>
+ "#{@name} woofs!"
+
+ @static: =>
+ new this('Dog')
+
+spark = new Dog('Spark')
+fido = new Dog('Fido')
+fido.bark = spark.bark
+
+ok fido.bark() is 'Spark woofs!'
+
+obj = func: Dog.static
+
+ok obj.func().name is 'Dog'
+
+
+# Testing a bound function in a bound function.
+class Mini
+ num: 10
+ generate: =>
+ for i in [1..3]
+ =>
+ @num
+
+m = new Mini
+ok (func() for func in m.generate()).join(' ') is '10 10 10'
+
+
+# Testing a contructor called with varargs.
+class Connection
+ constructor: (one, two, three) ->
+ [@one, @two, @three] = [one, two, three]
+
+ out: ->
+ "#{@one}-#{@two}-#{@three}"
+
+list = [3, 2, 1]
+conn = new Connection list...
+ok conn instanceof Connection
+ok conn.out() is '3-2-1'
+
+
+# Test calling super and passing along all arguments.
+class Parent
+ method: (args...) -> @args = args
+
+class Child extends Parent
+ method: -> super
+
+c = new Child
+c.method 1, 2, 3, 4
+ok c.args.join(' ') is '1 2 3 4'
+
+
+# Test `extended` callback.
+class Base
+ @extended: (subclass) ->
+ for key, value of @
+ subclass[key] = value
+
+class Element extends Base
+ @fromHTML: (html) ->
+ node = "..."
+ new @(node)
+
+ constructor: (node) ->
+ @node = node
+
+ok Element.extended is Base.extended
+ok Element.__super__ is Base.prototype
+
+class MyElement extends Element
+
+ok MyElement.extended is Base.extended
+ok MyElement.fromHTML is Element.fromHTML
+ok MyElement.__super__ is Element.prototype
+
+
+# Test classes wrapped in decorators.
+func = (klass) ->
+ klass::prop = 'value'
+ klass
+
+func class Test
+ prop2: 'value2'
+
+ok (new Test).prop is 'value'
+ok (new Test).prop2 is 'value2'
+
+
+# Test anonymous classes.
+obj =
+ klass: class
+ method: -> 'value'
+
+instance = new obj.klass
+ok instance.method() is 'value'
+
+
+# Implicit objects as static properties.
+class Static
+ @static:
+ one: 1
+ two: 2
+
+ok Static.static.one is 1
+ok Static.static.two is 2
+
+
+# Nothing classes.
+c = class
+ok c instanceof Function
+
+
+# Classes with value'd constructors.
+counter = 0
+classMaker = ->
+ counter += 1
+ inner = counter
+ ->
+ @value = inner
+
+class One
+ constructor: classMaker()
+
+class Two
+ constructor: classMaker()
+
+ok (new One).value is 1
+ok (new Two).value is 2
+ok (new One).value is 1
+ok (new Two).value is 2
--- /dev/null
+# comment before a ...
+
+###
+... block comment.
+###
+
+
+ # comment
+func = ->
+# comment
+ false
+ false # comment
+ false
+
+# comment
+ true
+
+switch 'string'
+ # comment
+ when false then something()
+ # comment
+ when null
+ somethingElse()
+
+->
+ code()
+ # comment
+
+ok func()
+
+func
+func
+# Line3
+
+obj = {
+# comment
+ # comment
+ # comment
+ one: 1
+# comment
+ two: 2
+ # comment
+}
+
+result = if true # comment
+ false
+
+ok not result
+
+result = if false
+ false
+else # comment
+ 45
+
+ok result is 45
+
+
+test =
+ 'test ' +
+ 'test ' + # comment
+ 'test'
+
+ok test is 'test test test'
+
+###
+ This is a here-comment.
+ Kind of like a heredoc.
+###
+
+func = ->
+ ###
+ Another block comment.
+ ###
+ code
+
+func = ->
+ one = ->
+ two = ->
+ three = ->
+ ###
+ block.
+ ###
+ four = ->
+
+fn1 = ->
+ oneLevel = null
+###
+This isn't fine.
+###
+
+ok ok
+
+obj = {
+ a: 'b'
+ ###
+ comment
+ ###
+ c: 'd'
+}
+
+arr = [
+ 1, 2, 3,
+ ###
+ four
+ ###
+ 5, 6, 7
+]
+
+# Spaced comments in if / elses.
+result = if false
+ 1
+
+# comment
+else if false
+ 2
+
+# comment
+else
+ 3
+
+ok result is 3
+
+
+result = switch 'z'
+ when 'z' then 7
+# comment
+ok result is 7
+
+
+# Trailing-line comment before an outdent.
+func = ->
+ if true
+ true # comment
+ 7
+
+ok func() is 7
+
+
+# Trailing herecomment in a function.
+fn = ->
+ code
+ ###
+ debug code commented
+ ###
+
+fn2 = ->
+
+
+class A
+ b: ->
+
+ ###
+ Comment
+ ###
+ c: ->
+
+ok A.prototype.c instanceof Function
+
+class A
+ ###
+ Comment
+ ###
+ b: ->
+ c: ->
+
+ok A.prototype.b instanceof Function
--- /dev/null
+# Ensure that carriage returns don't break compilation on Windows.
+eq CoffeeScript.compile('one\r\ntwo', bare: on), 'one;\ntwo;'
+
+# `globals: on` removes `var`s
+eq CoffeeScript.compile('x = y', bare: on, globals: on), 'x = y;'
+
+ok 'passed' is CoffeeScript.eval '"passed"', bare: on, fileName: 'test'
+
+#750
+try ok not CoffeeScript.nodes 'f(->'
+catch e then eq e.message, 'unclosed CALL_START on line 1'
--- /dev/null
+num = 10
+num -= 5
+eq num, 5
+
+num *= 10
+eq num, 50
+
+num /= 10
+eq num, 5
+
+num %= 3
+eq num, 2
+
+val = false
+val ||= 'value'
+val ||= 'eulav'
+eq val, 'value'
+
+val &&= 'rehto'
+val &&= 'other'
+eq val, 'other'
+
+val = null
+val ?= 'value'
+val ?= 'eulav'
+eq val, 'value'
--- /dev/null
+# Basic array comprehensions.
+nums = n * n for n in [1, 2, 3] when n % 2 isnt 0
+results = n * 2 for n in nums
+
+ok results.join(',') is '2,18'
+
+
+# Basic object comprehensions.
+obj = {one: 1, two: 2, three: 3}
+names = prop + '!' for prop of obj
+odds = prop + '!' for prop, value of obj when value % 2 isnt 0
+
+ok names.join(' ') is "one! two! three!"
+ok odds.join(' ') is "one! three!"
+
+
+# Basic range comprehensions.
+nums = i * 3 for i in [1..3]
+
+negs = x for x in [-20..-5*2]
+negs = negs[0..2]
+
+result = nums.concat(negs).join(', ')
+
+ok result is '3, 6, 9, -20, -19, -18'
+ok i is 3
+ok x is -10
+
+
+# With range comprehensions, you can loop in steps.
+results = x for x in [0...15] by 5
+ok results.join(' ') is '0 5 10'
+
+results = x for x in [0..100] by 10
+ok results.join(' ') is '0 10 20 30 40 50 60 70 80 90 100'
+
+
+# And can loop downwards, with a negative step.
+results = x for x in [5..1]
+
+ok results.join(' ') is '5 4 3 2 1'
+ok results.join(' ') is [(10-5)..(-2+3)].join(' ')
+
+results = x for x in [10..1]
+ok results.join(' ') is [10..1].join(' ')
+
+results = x for x in [10...0] by -2
+ok results.join(' ') is [10, 8, 6, 4, 2].join(' ')
+
+
+# Multiline array comprehension with filter.
+evens = for num in [1, 2, 3, 4, 5, 6] when num % 2 is 0
+ num *= -1
+ num -= 2
+ num * -1
+
+ok evens.join(', ') is '4, 6, 8'
+
+
+# The in operator still works, standalone.
+ok 2 of evens
+
+
+# Ensure that the closure wrapper preserves local variables.
+obj = {}
+
+for method in ['one', 'two', 'three']
+ obj[method] = ->
+ "I'm " + method
+
+ok obj.one() is "I'm one"
+ok obj.two() is "I'm two"
+ok obj.three() is "I'm three"
+
+i = 0
+for i in [1..3]
+ -> 'func'
+ break if false
+ok i is 3
+
+
+# Ensure that local variables are closed over for range comprehensions.
+funcs = for i in [1..3]
+ -> -i
+
+ok (func() for func in funcs).join(' ') is '-1 -2 -3'
+ok i is 3
+
+
+# Ensure that closing over local variables doesn't break scoping laws.
+for i in [0]
+ count = 0
+ i = 50
+ ->
+ok count is 0
+ok i is 50
+
+
+# Even when referenced in the filter.
+list = ['one', 'two', 'three']
+
+methods = for num, i in list when num isnt 'two' and i isnt 1
+ -> num + ' ' + i
+
+ok methods.length is 2
+ok methods[0]() is 'one 0'
+ok methods[1]() is 'three 2'
+
+
+# Naked ranges are expanded into arrays.
+array = [0..10]
+ok(num % 2 is 0 for num in array by 2)
+
+
+# Nested comprehensions.
+multiLiner =
+ for x in [3..5]
+ for y in [3..5]
+ [x, y]
+
+singleLiner =
+ [x, y] for y in [3..5] for x in [3..5]
+
+ok multiLiner.length is singleLiner.length
+ok 5 is multiLiner[2][2][1]
+ok 5 is singleLiner[2][2][1]
+
+
+# Comprehensions within parentheses.
+result = null
+store = (obj) -> result = obj
+store (x * 2 for x in [3, 2, 1])
+
+ok result.join(' ') is '6 4 2'
+
+
+# Closure-wrapped comprehensions that refer to the "arguments" object.
+expr = ->
+ result = item * item for item in arguments
+
+ok expr(2, 4, 8).join(' ') is '4 16 64'
+
+
+# Fast object comprehensions over all properties, including prototypal ones.
+class Cat
+ constructor: -> @name = 'Whiskers'
+ breed: 'tabby'
+ hair: 'cream'
+
+whiskers = new Cat
+own = value for key, value of whiskers
+all = value for all key, value of whiskers
+
+ok own.join(' ') is 'Whiskers'
+ok all.sort().join(' ') is 'Whiskers cream tabby'
+
+
+# Optimized range comprehensions.
+exxes = 'x' for [0...10]
+ok exxes.join(' ') is 'x x x x x x x x x x'
+
+
+# Comprehensions safely redeclare parameters if they're not present in closest
+# scope.
+rule = (x) -> x
+
+learn = ->
+ rule for rule in [1, 2, 3]
+
+ok learn().join(' ') is '1 2 3'
+
+ok rule(101) is 101
\ No newline at end of file
--- /dev/null
+ok(if mySpecialVariable? then false else true)
+
+mySpecialVariable = false
+
+ok(if mySpecialVariable? then true else false)
+
+
+# Existential assignment.
+a = 5
+a = null
+a ?= 10
+b ?= 10
+
+ok a is 10 and b is 10
+
+
+# The existential operator.
+z = null
+x = z ? "EX"
+ok z is null and x is "EX"
+
+i = 9
+func = -> i += 1
+result = func() ? 101
+ok result is 10
+
+# Only evaluate once.
+counter = 0
+getNextNode = ->
+ throw "up" if counter
+ counter++
+
+ok(if getNextNode()? then true else false)
+
+
+# Existence chains, soaking up undefined properties:
+obj =
+ prop: "hello"
+
+eq obj?.prop, "hello"
+eq obj?['prop'], "hello"
+eq obj.prop?.length, 5
+eq obj?.prop?['length'], 5
+eq obj?.prop?.non?.existent?.property, undefined
+
+
+# Soaks and caches method calls as well.
+arr = ["--", "----"]
+
+eq arr.pop()?.length, 4
+eq arr.pop()?.length, 2
+eq arr.pop()?.length, undefined
+eq arr.pop()?.length?.non?.existent()?.property, undefined
+
+
+# Soaks method calls safely.
+value = null
+eq value?.toString().toLowerCase(), undefined
+
+value = 10
+eq value?.toString().toLowerCase(), '10'
+
+eq 0.nothing?.property() or 101, 101
+
+counter = 0
+func = ->
+ counter += 1
+ 'prop'
+obj =
+ prop: -> this
+ value: 25
+
+ok obj[func()]()[func()]()[func()]()?.value is 25
+ok counter is 3
+
+
+ident = (obj) -> obj
+eq ident(non?.existent().method()), undefined, 'soaks inner values'
+
+
+# Soaks constructor invocations.
+a = 0
+class Foo
+ constructor: -> a += 1
+ bar: "bat"
+
+ok (new Foo())?.bar is 'bat'
+ok a is 1
+
+
+ok not value?.property?, 'safely checks existence on soaks'
+
+
+eq nothing?.value, undefined, 'safely calls values off of non-existent variables'
+eq !nothing?.value and 1, 1, 'corresponding operators work as expected'
+
+
+# Assign to the result of an exsitential operation with a minus.
+x = null ? - 1
+ok x is - 1
+
+
+# Things that compile to ternaries should force parentheses, like operators do.
+duration = if options?.animated then 150 else 0
+ok duration is 0
+
+
+# Function soaks.
+plus1 = (x) -> x + 1
+count = 0
+obj = {
+ counter: -> count += 1; this
+ returnThis: -> this
+}
+
+eq plus1?(41), 42
+eq (plus1? 41), 42
+eq plus2?(41), undefined
+eq (plus2? 41), undefined
+eq obj.returnThis?(), obj
+eq obj.returnSelf?(), undefined
+eq obj.returnThis?().flag = on, on
+eq obj.returnSelf?().flag = on, undefined
+eq obj.counter().counter().returnThis?(), obj
+eq count, 2
+
+maybe_close = (f, arg) -> if typeof f is 'function' then () -> f(arg) else -1
+
+eq maybe_close(plus1, 41)?(), 42
+eq (maybe_close plus1, 41)?(), 42
+eq (maybe_close 'string', 41)?(), undefined
+
+eq 2?(3), undefined
+eq new Number?(42) | 0, 42
+eq new Bumper?(42) | 0, 0
+
+#726
+eq calendar?[Date()], undefined
+
+#733
+a = b: {c: null}
+eq a.b?.c?(), undefined
+a.b?.c or= (it) -> it
+eq a.b?.c?(1), 1
+eq a.b?.c?([2, 3]...), 2
--- /dev/null
+# Ensure that we don't wrap Nodes that are "pureStatement" in a closure.
+items = [1, 2, 3, "bacon", 4, 5]
+
+for item in items
+ break if item is "bacon"
+
+findit = (items) ->
+ for item in items
+ return item if item is "bacon"
+
+ok findit(items) is "bacon"
+
+
+# When when a closure wrapper is generated for expression conversion, make sure
+# that references to "this" within the wrapper are safely converted as well.
+obj = {
+ num: 5
+ func: ->
+ this.result = if false
+ 10
+ else
+ "a"
+ "b"
+ this.num
+}
+
+ok obj.num is obj.func()
+ok obj.num is obj.result
+
+
+# Should be able to look at prototypes on keywords.
+obj =
+ withAt: -> @::prop
+ withThis: -> this::prop
+ proto:
+ prop: 100
+
+obj.prototype = obj.proto
+ok obj.withAt() is 100
+ok obj.withThis() is 100
\ No newline at end of file
--- /dev/null
+x = 1
+y = {}
+y.x = -> 3
+
+ok x is 1
+ok typeof(y.x) is 'function'
+ok y.x instanceof Function
+ok y.x() is 3
+
+
+# The empty function should not cause a syntax error.
+->
+() ->
+
+
+# Multiple nested function declarations mixed with implicit calls should not
+# cause a syntax error.
+(one) -> (two) -> three four, (five) -> six seven, eight, (nine) ->
+
+
+obj = {
+ name: 'Fred'
+
+ bound: ->
+ (=> eq this, obj)()
+
+ unbound: ->
+ (-> ok this isnt obj)()
+
+ nested: ->
+ (=>
+ (=>
+ (=>
+ eq this, obj
+ )()
+ )()
+ )()
+}
+
+obj.unbound()
+obj.bound()
+obj.nested()
+
+
+# Python decorator style wrapper that memoizes any function
+memoize = (fn) ->
+ cache = {}
+ self = this
+ (args...) ->
+ key = args.toString()
+ return cache[key] if cache[key]
+ cache[key] = fn.apply(self, args)
+
+Math = {
+ Add: (a, b) -> a + b
+ AnonymousAdd: ((a, b) -> a + b)
+ FastAdd: memoize (a, b) -> a + b
+}
+
+ok Math.Add(5, 5) is 10
+ok Math.AnonymousAdd(10, 10) is 20
+ok Math.FastAdd(20, 20) is 40
+
+
+# Parens are optional on simple function calls.
+ok 100 > 1 if 1 > 0
+ok true unless false
+ok true for i in [1..3]
+
+okFunc = (f) -> ok(f())
+okFunc -> true
+
+# Optional parens can be used in a nested fashion.
+call = (func) -> func()
+
+result = call ->
+ inner = call ->
+ Math.Add(5, 5)
+
+ok result is 10
+
+
+# More fun with optional parens.
+fn = (arg) -> arg
+
+ok fn(fn {prop: 101}).prop is 101
+
+
+# Multi-blocks with optional parens.
+result = fn( ->
+ fn ->
+ "Wrapped"
+)
+
+ok result()() is 'Wrapped'
+
+
+# And even with strange things like this:
+funcs = [((x) -> x), ((x) -> x * x)]
+result = funcs[1] 5
+
+ok result is 25
+
+result = ("hello".slice) 3
+
+ok result is 'lo'
+
+
+# And with multiple single-line functions on the same line.
+func = (x) -> (x) -> (x) -> x
+ok func(1)(2)(3) is 3
+
+
+# Ensure that functions with the same name don't clash with helper functions.
+del = -> 5
+ok del() is 5
+
+# Ensure that functions can have a trailing comma in their argument list
+mult = (x, mids..., y) ->
+ x *= n for n in mids
+ x *= y
+
+ok mult(1, 2,) is 2
+ok mult(1, 2, 3,) is 6
+ok mult(10,[1..6]...,) is 7200
+
+
+# Test for inline functions with parentheses and implicit calls.
+combine = (func, num) -> func() * num
+result = combine (-> 1 + 2), 3
+
+ok result is 9
+
+
+# Test for calls/parens/multiline-chains.
+f = (x) -> x
+result = (f 1).toString()
+ .length
+
+ok result is 1
+
+
+# Test implicit calls in functions in parens:
+result = ((val) ->
+ [].push val
+ val
+)(10)
+
+ok result is 10
+
+
+# More paren compilation tests:
+reverse = (obj) -> obj.reverse()
+ok reverse([1, 2].concat 3).join(' ') is '3 2 1'
+
+# Passing multiple functions without paren-wrapping is legal, and should compile.
+sum = (one, two) -> one() + two()
+result = sum ->
+ 7 + 9
+, ->
+ 1 + 3
+
+ok result is 20
+
+
+# Implicit call with a trailing if statement as a param.
+func = -> arguments[1]
+result = func 'one', if false then 100 else 13
+ok result is 13
+
+
+# Test more function passing:
+result = sum( ->
+ 1 + 2
+, ->
+ 2 + 1
+)
+ok result is 6
+
+sum = (a, b) -> a + b
+result = sum(1
+, 2)
+
+ok result is 3
+
+
+# This is a crazy one.
+x = (obj, func) -> func obj
+ident = (x) -> x
+
+result = x {one: ident 1}, (obj) ->
+ inner = ident(obj)
+ ident inner
+
+ok result.one is 1
+
+
+# Assignment to a Object.prototype-named variable should not leak to outer scope.
+# FIXME: fails on IE
+(->
+ constructor = 'word'
+)()
+
+ok constructor isnt 'word'
+
+
+# Trying an implicit object call with a trailing function.
+a = null
+meth = (arg, obj, func) -> a = [obj.a, arg, func()].join ' '
+
+meth 'apple', b: 1, a: 13, ->
+ 'orange'
+
+ok a is '13 apple orange'
+
+
+# Ensure that empty functions don't return mistaken values.
+obj =
+ func: (@param, @rest...) ->
+
+ok obj.func(101, 102, 103, 104) is undefined
+ok obj.param is 101
+ok obj.rest.join(' ') is '102 103 104'
+
+
+# `@` and `this` should both be able to invoke a method.
+func = (arg) -> ok arg is true
+func.withAt = -> @ true
+func.withThis = -> this true
+
+func.withAt()
+func.withThis()
+
+
+# Ensure that constructors invoked with splats return a new object.
+args = [1, 2, 3]
+Type = (@args) ->
+type = new Type args
+
+ok type and type instanceof Type
+ok type.args and type.args instanceof Array
+ok v is args[i] for v, i in type.args
+
+Type1 = (@a, @b, @c) ->
+type1 = new Type1 args...
+
+ok type1 instanceof Type1
+eq type1.constructor, Type1
+ok type1.a is args[0] and type1.b is args[1] and type1.c is args[2]
+
+
+# Ensure that constructors invoked with splats cache the function.
+called = 0
+get = -> if called++ then false else class Type
+new get() args...
+
+
+# Chained blocks, with proper indentation levels:
+counter =
+ results: []
+ tick: (func) ->
+ @results.push func()
+ this
+
+counter
+ .tick ->
+ 3
+ .tick ->
+ 2
+ .tick ->
+ 1
+
+eq counter.results.join(' '), '3 2 1'
+
+
+# Make incorrect indentation safe.
+func = ->
+ obj = {
+ key: 10
+ }
+ obj.key - 5
+
+eq func(), 5
+
+
+# Ensure that chained calls with indented implicit object literals below are
+# alright.
+result = null
+obj =
+ method: (val) -> this
+ second: (hash) -> result = hash.three
+
+
+obj
+ .method(
+ 101
+ ).second(
+ one:
+ two: 2
+ three: 3
+ )
+
+eq result, 3
+
+
+# Test newline-supressed call chains with nested functions.
+obj =
+ call: -> this
+func = ->
+ obj
+ .call ->
+ one two
+ .call ->
+ three four
+ 101
+
+eq func(), 101
+
+
+# `new` shouldn't add extra parens
+ok new Date().constructor is Date
+
+
+# `new` works against bare function
+eq Date, new ->
+ eq this, new => this
+ Date
+
+
+# Implicit objects with number arguments.
+func = (x, y) -> y
+obj =
+ prop: func "a", 1
+
+ok obj.prop is 1
+
+
+# Non-spaced unary and binary operators should cause a function call.
+func = (val) -> val + 1
+ok (func +5) is 6
+ok (func -5) is -4
+
+
+# Prefix unary assignment operators are allowed in parenless calls.
+val = 5
+ok (func --val) is 5
--- /dev/null
+{indexOf, include, starts, ends, compact, count, merge, extend, flatten, del, last} = CoffeeScript.helpers
+
+array = [0..4]
+string = array.join ''
+object = {}
+
+# Test `indexOf`
+eq 0, indexOf array, 0
+eq 2, indexOf array, 2
+eq 4, indexOf array, 4
+eq(-1, indexOf array, 6)
+
+# Test `include`
+ok include array, 0
+ok include array, 2
+ok include array, 4
+ok not include array, 6
+
+# Test `starts`
+ok starts string, '012'
+ok starts string, '34', 3
+ok not starts string, '42'
+ok not starts string, '42', 6
+
+# Test `ends`
+ok ends string, '234'
+ok ends string, '01', 3
+ok not ends string, '42'
+ok not ends string, '42', 6
+
+# Test `merge`
+merged = merge object, array
+ok merged isnt object
+eq merged[3], 3
+
+# Test `extend`
+ok object is extend object, array
+eq object[3], 3
+
+# Test `flatten`
+eq "#{ flatten [0, [1, 2], 3, [4]] }", "#{ array }"
+
+# Test `del`
+eq 1, del object, 1
+ok 1 not of object
+
+# Test `last`
+eq 4, last array
+eq 2, last array, 2
--- /dev/null
+a = """
+ basic heredoc
+ on two lines
+ """
+
+ok a is "basic heredoc\non two lines"
+
+
+a = '''
+ a
+ "b
+ c
+ '''
+
+ok a is "a\n \"b\nc"
+
+
+a = """
+a
+ b
+ c
+"""
+
+ok a is "a\n b\n c"
+
+
+a = '''one-liner'''
+
+ok a is 'one-liner'
+
+
+a = """
+ out
+ here
+"""
+
+ok a is "out\nhere"
+
+
+a = '''
+ a
+ b
+ c
+ '''
+
+ok a is " a\n b\nc"
+
+
+a = '''
+a
+
+
+b c
+'''
+
+ok a is "a\n\n\nb c"
+
+
+a = '''more"than"one"quote'''
+
+ok a is 'more"than"one"quote'
+
+
+val = 10
+
+a = """
+ basic heredoc #{val}
+ on two lines
+ """
+
+b = '''
+ basic heredoc #{val}
+ on two lines
+ '''
+
+ok a is "basic heredoc 10\non two lines"
+ok b is "basic heredoc \#{val}\non two lines"
+
+
+a = '''here's an apostrophe'''
+ok a is "here's an apostrophe"
+
+
+# The indentation detector ignores blank lines without trailing whitespace
+a = """
+ one
+ two
+
+ """
+ok a is "one\ntwo\n"
+
+eq ''' line 0
+ should not be relevant
+ to the indent level
+''', '
+ line 0\n
+should not be relevant\n
+ to the indent level
+'
+
+eq ''' '\\\' ''', " '\\' "
+eq """ "\\\" """, ' "\\" '
+
+eq ''' <- keep these spaces -> ''', ' <- keep these spaces -> '
+
+eq 'multiline nested "interpolations" work', """multiline #{
+ "nested #{(->
+ ok yes
+ "\"interpolations\""
+ )()}"
+} work"""
--- /dev/null
+a = b = d = true
+c = false
+
+result = if a
+ if b
+ if c then false else
+ if d
+ true
+
+ok result
+
+
+first = if false then false else second = if false then false else true
+
+ok first
+ok second
+
+
+result = if false
+ false
+else if NaN
+ false
+else
+ true
+
+ok result
+
+
+# Testing unless.
+result = unless true
+ 10
+else
+ 11
+
+ok result is 11
+
+
+# Nested inline if statements.
+echo = (x) -> x
+result = if true then echo((if false then 'xxx' else 'y') + 'a')
+ok result is 'ya'
+
+
+# Testing inline funcs with inline if-elses.
+func = -> if 1 < 0.5 then 1 else -1
+ok func() is -1
+
+
+# Testing empty or commented if statements ... should compile:
+result = if false
+else if false
+else
+
+ok result is undefined
+
+result = if false
+ # comment
+else if true
+ # comment
+else
+
+ok result is undefined
+
+
+# Return an if with no else.
+func = ->
+ return if false then callback()
+
+ok func() is undefined
+
+func = ->
+ return unless false then 100 else -100
+
+ok func() is 100
+
+ident = (x) -> x
+result = ident if false then 300 else 100
+
+ok result is 100
+
+
+# If-to-ternary with instanceof requires parentheses (no comment).
+if {} instanceof Object
+ ok yes
+else
+ ok no
+
+try
+ {} + {}
+ ok yes
+catch e
+ ok no
+
+
+# If-to-ternary as part of a larger operation requires parens.
+x = 1
+result = x + if false then 10 else 1
+ok result is 2
+
+
+# If/else indented within an assignment.
+func = ->
+ a =
+ if false
+ 3
+ else
+ 5
+ 101
+ a
+
+ok func() is 5
+
+
+# Unmatched 'then' should catch implicit calls.
+i = 1
+isTrue = (x) -> x is true
+
+if isTrue yes then i += 1
+
+ok i is 2
+
+# If/else with a suppressed indentation via assignment.
+result =
+ if false then 10
+ else if no then 20
+ else if 0 then 30
+ else if NaN then 40
+ else 50 +
+ if false then 10
+ else 20
+
+ok result is 70
+
+
+# Issue #738
+func = if true then -> 1
+eq func(), 1
+
+
+# Issue #748. Trailing reserved identifiers.
+obj = delete: true
+
+result = if obj.delete
+ 101
+
+ok result is 101
--- /dev/null
+# Check if we can import and execute a CoffeeScript-only module successfully.
+if require?.extensions? or require?.registerExtension?
+ ok require('./test_module').func() is "from over there"
--- /dev/null
+a = [((x) -> x), ((x) -> x * x)]
+
+ok a.length is 2
+
+
+neg = (3 -4)
+
+ok neg is -1
+
+
+# Decimal number literals.
+value = .25 + .75
+ok value is 1
+value = 0.0 + -.25 - -.75 + 0.0
+ok value is 0.5
+
+# Decimals don't interfere with ranges.
+ok [0..10].join(' ') is '0 1 2 3 4 5 6 7 8 9 10'
+ok [0...10].join(' ') is '0 1 2 3 4 5 6 7 8 9'
+
+
+# Can call methods directly on numbers.
+4.valueOf() is 4
+
+
+func = ->
+ return if true
+
+ok func() is undefined
+
+
+trailingComma = [1, 2, 3,]
+ok (trailingComma[0] is 1) and (trailingComma[2] is 3) and (trailingComma.length is 3)
+
+trailingComma = [
+ 1, 2, 3,
+ 4, 5, 6
+ 7, 8, 9,
+]
+(sum = (sum or 0) + n) for n in trailingComma
+
+trailingComma = {k1: "v1", k2: 4, k3: (-> true),}
+ok trailingComma.k3() and (trailingComma.k2 is 4) and (trailingComma.k1 is "v1")
+
+
+ok {a: (num) -> num is 10 }.a 10
+
+
+moe = {
+ name: 'Moe'
+ greet: (salutation) ->
+ salutation + " " + @name
+ hello: ->
+ @['greet'] "Hello"
+ 10: 'number'
+}
+
+ok moe.hello() is "Hello Moe"
+ok moe[10] is 'number'
+
+moe.hello = ->
+ this['greet'] "Hello"
+
+ok moe.hello() is 'Hello Moe'
+
+
+obj = {
+ is: -> yes,
+ 'not': -> no,
+}
+
+ok obj.is()
+ok not obj.not()
+
+
+# Top-level object literal doesn't break things.
+obj: 1
+
+
+# Funky indentation within non-comma-seperated arrays.
+result = [['a']
+ {b: 'c'}]
+
+ok result[0][0] is 'a'
+ok result[1]['b'] is 'c'
+
+
+# Object literals should be able to include keywords.
+obj = {class: 'höt'}
+obj.function = 'dog'
+
+ok obj.class + obj.function is 'hötdog'
+
+
+# But keyword assignment should be smart enough not to stringify variables.
+func = ->
+ this == 'this'
+
+ok func() is false
+
+
+# New fancy implicit objects:
+config =
+ development:
+ server: 'localhost'
+ timeout: 10
+
+ production:
+ server: 'dreamboat'
+ timeout: 1000
+
+ok config.development.server is 'localhost'
+ok config.production.server is 'dreamboat'
+ok config.development.timeout is 10
+ok config.production.timeout is 1000
+
+obj =
+ a: 1
+ b: 2
+
+ok obj.a is 1
+ok obj.b is 2
+
+obj =
+ a: 1,
+ b: 2,
+
+ok obj.a is 1
+ok obj.b is 2
+
+
+# Implicit objects nesting.
+obj =
+ options:
+ value: yes
+
+ fn: ->
+ {}
+ null
+
+ok obj.options.value is yes
+ok obj.fn() is null
+
+
+# Implicit arguments to function calls:
+func = (obj) -> obj.a
+
+result = func
+ a: 10
+
+ok result is 10
+
+result = func
+ "a": 20
+
+ok result is 20
+
+third = (a, b, c) -> c
+obj =
+ one: 'one'
+ two: third 'one', 'two', 'three'
+
+ok obj.one is 'one'
+ok obj.two is 'three'
+
+
+# Implicit objects with wacky indentation:
+obj =
+ 'reverse': (obj) ->
+ Array.prototype.reverse.call obj
+ abc: ->
+ @reverse(
+ @reverse @reverse ['a', 'b', 'c'].reverse()
+ )
+ one: [1, 2,
+ a: 'b'
+ 3, 4]
+ red:
+ orange:
+ yellow:
+ green: 'blue'
+ indigo: 'violet'
+ misdent: [[],
+ [],
+ [],
+ []]
+
+ok obj.abc().join(' ') is 'a b c'
+ok obj.one.length is 5
+ok obj.one[4] is 4
+ok obj.one[2].a is 'b'
+ok (key for key of obj.red).length is 2
+ok obj.red.orange.yellow.green is 'blue'
+ok obj.red.indigo is 'violet'
+ok obj.misdent.toString() is ',,,'
+
+second = (x, y) -> y
+obj = then second 'the',
+ 1: 1
+ two:
+ three: ->
+ four five,
+ six: seven
+ three: 3
+
+ok obj[1] is 1
+ok obj.three is 3
+
+
+# Implicit objects as part of chained calls.
+identity = (x) -> x.a
+
+b = identity identity identity
+ a:
+ a:
+ a: 100
+
+ok b is 100
+
+
+# Inline JS
+eq '\\`', `
+ "\\\`"
+`
+
+
+# Shorthand objects with property references.
+obj =
+ one: 1
+ two: 2
+ object: -> {@one, @two}
+ list: -> [@one, @two]
+
+
+result = obj.object()
+eq result.one, 1
+eq result.two, 2
+eq result.two, obj.list()[1]
+
+
+#542: Objects leading expression statement should be parenthesized.
+{f: -> ok yes }.f() + 1
+
+
+#764: Boolean/Number should be indexable.
+ok 42['toString']
+ok on['toString']
--- /dev/null
+# This file is imported by `testImporting.coffee`
+if exports?
+ local = "from over there"
+ exports.func = -> local
--- /dev/null
+# CoffeeScript's operations should be chainable, like Python's.
+ok 500 > 50 > 5 > -5
+
+ok true is not false is true is not false
+
+ok 0 is 0 isnt 50 is 50
+
+ok 10 < 20 > 10
+
+ok 50 > 10 > 5 is parseInt('5', 10)
+
+i = 0
+ok 1 > i++ < 1, 'chained operations should evaluate each value only once'
+
+
+# `==` and `is` should be interchangeable.
+a = b = 1
+
+ok a is 1 and b is 1
+ok a == b
+ok a is b
+
+
+# Allow "if x not in y"
+obj = {a: true}
+ok 'a' of obj
+ok 'b' not of obj
+
+# And for "a in b" with array presence.
+ok 200 in [100, 200, 300]
+array = [100, 200, 300]
+ok 200 in array
+ok 1 not in array
+ok array[0]++ in [99, 100], 'should cache testee'
+
+# And with array presence on an instance variable.
+obj = {
+ list: [1, 2, 3, 4, 5]
+ in_list: (value) -> value in @list
+}
+ok obj.in_list 4
+ok not obj.in_list 0
+
+# Non-spaced values still work.
+x = 10
+y = -5
+
+ok x*-y is 50
+ok x*+y is -50
+
+
+# Compound operators.
+one = 1
+two = 0
+one or= 2
+two or= 2
+
+eq one, 1
+eq two, 2
+
+zero = 0
+
+zero and= 'one'
+one and= 'one'
+
+eq zero, 0
+eq one , 'one'
+
+
+# Compound assignment should be careful about caching variables.
+count = 0
+list = []
+
+list[++count] or= 1
+eq list[1], 1
+eq count, 1
+
+list[++count] ?= 2
+eq list[2], 2
+eq count, 2
+
+list[count++] and= 'two'
+eq list[2], 'two'
+eq count, 3
+
+base = -> ++count; base
+
+base().four or= 4
+eq base.four, 4
+eq count, 4
+
+base().five ?= 5
+eq base.five, 5
+eq count, 5
+
+
+# Ensure that RHS is treated as a group.
+a = b = false
+a and= b or true
+ok a is false
+
+
+# Bitwise operators:
+ok (10 & 3) is 2
+ok (10 | 3) is 11
+ok (10 ^ 3) is 9
+ok (10 << 3) is 80
+ok (10 >> 3) is 1
+ok (10 >>> 3) is 1
+
+num = 10; ok (num <<= 3) is 80
+num = 10; ok (num >>= 3) is 1
+num = 10; ok (num >>>= 3) is 1
+num = 10; ok (num &= 3) is 2
+num = 10; ok (num ^= 3) is 9
+num = 10; ok (num |= 3) is 11
+
+
+# Compound assignment with implicit objects.
+obj = undefined
+obj ?=
+ one: 1
+
+ok obj.one is 1
+
+obj and=
+ two: 2
+
+ok not obj.one
+ok obj.two is 2
+
+
+# Compound assignment as a sub expression.
+[a, b, c] = [1, 2, 3]
+ok (a + b += c) is 6
+ok a is 1
+ok b is 5
+ok c is 3
+
+
+# Instanceof.
+ok new String instanceof String
+ok new Number not instanceof String
+
+
+#737: `in` should have higher precedence than logical operators
+eq 1, 1 in [1] and 1
+
+#768: `in` should preserve evaluation order
+share = 0
+a = -> share++ if share is 0
+b = -> share++ if share is 1
+c = -> share++ if share is 2
+ok a() not in [b(),c()] and share is 3
--- /dev/null
+# Ensure that the OptionParser handles arguments correctly.
+return unless require?
+{OptionParser} = require './../lib/optparse'
+
+opt = new OptionParser [
+ ['-r', '--required [DIR]', 'desc required']
+ ['-o', '--optional', 'desc optional']
+ ['-l', '--list [FILES*]', 'desc list']
+]
+
+result = opt.parse ['one', 'two', 'three', '-r', 'dir']
+
+ok result.arguments.length is 5
+ok result.arguments[3] is '-r'
+
+result = opt.parse ['--optional', '-r', 'folder', 'one', 'two']
+
+ok result.optional is true
+ok result.required is 'folder'
+ok result.arguments.join(' ') is 'one two'
+
+result = opt.parse ['-l', 'one.txt', '-l', 'two.txt', 'three']
+
+ok result.list instanceof Array
+ok result.list.join(' ') is 'one.txt two.txt'
+ok result.arguments.join(' ') is 'three'
+
--- /dev/null
+# Simple variable swapping.
+a = -1
+b = -2
+
+[a, b] = [b, a]
+
+eq a, -2
+eq b, -1
+
+func = ->
+ [a, b] = [b, a]
+
+eq func().join(' '), '-1 -2'
+eq a, -1
+eq b, -2
+
+#713
+eq (onetwo = [1, 2]), [a, b] = [c, d] = onetwo
+ok a is c is 1 and b is d is 2
+
+
+# Array destructuring, including splats.
+[x,y...,z] = [1,2,3,4,5]
+
+ok x is 1
+ok y.length is 3
+ok z is 5
+
+[x, [y, mids..., last], z..., end] = [1, [10, 20, 30, 40], 2,3,4, 5]
+
+ok x is 1
+ok y is 10
+ok mids.length is 2 and mids[1] is 30
+ok last is 40
+ok z.length is 3 and z[2] is 4
+ok end is 5
+
+
+# Object destructuring.
+obj = {x: 10, y: 20, z: 30}
+
+{x: a, y: b, z: c} = obj
+
+ok a is 10
+ok b is 20
+ok c is 30
+
+person = {
+ name: "Moe"
+ family: {
+ 'elder-brother': {
+ addresses: [
+ "first"
+ {
+ street: "101 Deercreek Ln."
+ city: "Moquasset NY, 10021"
+ }
+ ]
+ }
+ }
+}
+
+{name: a, family: {'elder-brother': {addresses: [one, {city: b}]}}} = person
+
+ok a is "Moe"
+ok b is "Moquasset NY, 10021"
+
+test = {
+ person: {
+ address: [
+ "------"
+ "Street 101"
+ "Apt 101"
+ "City 101"
+ ]
+ }
+}
+
+{person: {address: [ignore, addr...]}} = test
+
+ok addr.join(', ') is "Street 101, Apt 101, City 101"
+
+
+# Pattern matching against an expression.
+[a, b] = if true then [2, 1] else [1, 2]
+
+ok a is 2
+ok b is 1
+
+
+# Pattern matching with object shorthand.
+
+person = {
+ name: "Bob"
+ age: 26
+ dogs: ["Prince", "Bowie"]
+}
+
+{name, age, dogs: [first, second]} = person
+
+ok name is "Bob"
+ok age is 26
+ok first is "Prince"
+ok second is "Bowie"
+
+# Pattern matching within for..loops
+
+persons = {
+ George: { name: "Bob" },
+ Bob: { name: "Alice" }
+ Christopher: { name: "Stan" }
+}
+
+join1 = "#{key}: #{name}" for key, { name } of persons
+
+eq join1.join(' / '), "George: Bob / Bob: Alice / Christopher: Stan"
+
+persons = [
+ { name: "Bob", parent: { name: "George" } },
+ { name: "Alice", parent: { name: "Bob" } },
+ { name: "Stan", parent: { name: "Christopher" } }
+]
+
+join2 = "#{parent}: #{name}" for { name, parent: { name: parent } } in persons
+
+eq join1.join(' '), join2.join(' ')
+
+persons = [['Bob', ['George']], ['Alice', ['Bob']], ['Stan', ['Christopher']]]
+join3 = "#{parent}: #{name}" for [name, [parent]] in persons
+
+eq join2.join(' '), join3.join(' ')
+
+
+# Pattern matching doesn't clash with implicit block objects.
+obj = a: 101
+func = -> true
+
+if func func
+ {a} = obj
+
+ok a is 101
+
+[x] = {0: y} = {'0': z} = [Math.random()]
+ok x is y is z, 'destructuring in multiple'
+
+
+# Destructuring into an object.
+obj =
+ func: (list, object) ->
+ [@one, @two] = list
+ {@a, @b} = object
+ {@a} = object # must not unroll this
+ null
+
+obj.func [1, 2], a: 'a', b: 'b'
+
+eq obj.one, 1
+eq obj.two, 2
+eq obj.a, 'a'
+eq obj.b, 'b'
--- /dev/null
+# Slice.
+array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+
+a = array[7..9]
+b = array[2...4]
+
+result = a.concat(b).join(' ')
+
+ok result is "7 8 9 2 3"
+
+a = [0, 1, 2, 3, 4, 5, 6, 7]
+eq a[2...6].join(' '), '2 3 4 5'
+
+
+# Ranges.
+countdown = [10..1].join(' ')
+ok countdown is "10 9 8 7 6 5 4 3 2 1"
+
+a = 1
+b = 5
+nums = [a...b]
+ok nums.join(' ') is '1 2 3 4'
+
+b = -5
+nums = [a..b]
+ok nums.join(' ') is '1 0 -1 -2 -3 -4 -5'
+
+
+# Expression-based range.
+array = [(1+5)..1+9]
+ok array.join(' ') is "6 7 8 9 10"
+
+array = [5..1]
+ok array.join(' ') is '5 4 3 2 1'
+
+array = [30...0]
+ok (len = array.length) is 30
+ok array[len - 1] is 1
+
+
+
+# String slicing (at least on Node).
+hello = "Hello World"
+
+ok hello[1...1] is ""
+ok hello[1..1] is "e"
+ok hello[1...5] is "ello"
+ok hello[0..4] is "Hello"
+
+
+# Splice literals.
+array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+
+array[5..10] = [0, 0, 0]
+
+ok array.join(' ') is '0 1 2 3 4 0 0 0'
+
+
+# Slices and splices that omit their beginning or end.
+array = [0..10]
+
+ok array[7..].join(' ') is '7 8 9 10'
+ok array[-2..].join(' ') is '9 10'
+
+ok array[...3].join(' ') is '0 1 2'
+ok array[..-5].join(' ') is '0 1 2 3 4 5 6'
+
+array[3..] = [9, 8, 7]
+
+ok array.join(' ') is '0 1 2 9 8 7'
+
+array[...3] = [7, 8, 9]
+
+ok array.join(' ') is '7 8 9 9 8 7'
+
--- /dev/null
+# Regular expression literals.
+ok 'x'.match(/x/g)
+ok 'x'.match /x/g
+ok 'x'.match(/x/)
+ok 'x'.match /x/
+
+ok 4 / 2 / 1 is 2
+
+y = 4
+x = 2
+g = 1
+
+ok y / x/g is 2
+
+obj = {
+ width: -> 10
+ height: -> 20
+}
+id = 2
+
+ok (obj.width()/id - obj.height()/id) is -5
+
+eq /\\/.source, "\\\\"
+
+
+eq /^I'm\s+Heregex?\/\/\//gim + '', ///
+ ^ I'm \s+ Heregex? / // # or not
+///gim + ''
+eq '\\\\#{}\\\\\\\"', ///
+ #{
+ "#{ '\\' }" # normal comment
+ }
+ # regex comment
+ \#{}
+ \\ \"
+///.source
+eq /// /// + '', '/(?:)/'
+
+
+#584: Unescaped slashes in character classes.
+ok /:\/[/]goog/.test 'http://google.com'
+
+
+#764: Should be indexable.
+eq /0/['source'], ///#{0}///['source']
--- /dev/null
+# Expression conversion under explicit returns.
+first = ->
+ return 'do' for x in [1,2,3]
+
+second = ->
+ return ['re' for x in [1,2,3]]
+
+third = ->
+ return ('mi' for x in [1,2,3])
+
+ok first().join(' ') is 'do do do'
+ok second()[0].join(' ') is 're re re'
+ok third().join(' ') is 'mi mi mi'
+
+
+# Testing returns with multiple branches.
+func = ->
+ if false
+ for a in b
+ return c if d
+ else
+ "word"
+
+ok func() is 'word'
+
+
+# And with switches.
+func = ->
+ switch 'a'
+ when 'a' then 42
+ else return 23
+
+ok func() is 42
\ No newline at end of file
--- /dev/null
+func = (first, second, rest...) ->
+ rest.join ' '
+
+result = func 1, 2, 3, 4, 5
+
+ok result is "3 4 5"
+
+
+gold = silver = bronze = theField = last = null
+
+medalists = (first, second, third, rest..., unlucky) ->
+ gold = first
+ silver = second
+ bronze = third
+ theField = rest.concat([last])
+ last = unlucky
+
+contenders = [
+ "Michael Phelps"
+ "Liu Xiang"
+ "Yao Ming"
+ "Allyson Felix"
+ "Shawn Johnson"
+ "Roman Sebrle"
+ "Guo Jingjing"
+ "Tyson Gay"
+ "Asafa Powell"
+ "Usain Bolt"
+]
+
+medalists "Mighty Mouse", contenders...
+
+ok gold is "Mighty Mouse"
+ok silver is "Michael Phelps"
+ok bronze is "Liu Xiang"
+ok last is "Usain Bolt"
+ok theField.length is 8
+
+contenders.reverse()
+medalists contenders[0...2]..., "Mighty Mouse", contenders[2...contenders.length]...
+
+ok gold is "Usain Bolt"
+ok silver is "Asafa Powell"
+ok bronze is "Mighty Mouse"
+ok last is "Michael Phelps"
+ok theField.length is 8
+
+medalists contenders..., 'Tim', 'Moe', 'Jim'
+ok last is 'Jim'
+
+
+obj =
+ name: 'moe'
+ accessor: (args...) ->
+ [@name].concat(args).join(' ')
+ getNames: ->
+ args = ['jane', 'ted']
+ @accessor(args...)
+ index: 0
+ 0: {method: -> this is obj[0]}
+
+ok obj.getNames() is 'moe jane ted'
+ok obj[obj.index++].method([]...), 'should cache base value'
+
+crowd = [
+ contenders...
+ "Mighty Mouse"
+]
+
+bests = [
+ "Mighty Mouse"
+ contenders[0..3]...
+]
+
+ok crowd[0] is contenders[0]
+ok crowd[10] is "Mighty Mouse"
+
+ok bests[1] is contenders[0]
+ok bests[4] is contenders[3]
+
+
+# Finally, splats with super() within classes.
+
+class Parent
+ meth: (args...) ->
+ args
+
+class Child extends Parent
+ meth: ->
+ nums = [3, 2, 1]
+ super nums...
+
+ok (new Child).meth().join(' ') is '3 2 1'
+
+
+# Functions with splats being called with too few arguments.
+pen = null
+method = (first, variable..., penultimate, ultimate) ->
+ pen = penultimate
+
+method 1, 2, 3, 4, 5, 6, 7, 8, 9
+ok pen is 8
+
+method 1, 2, 3
+ok pen is 2
+
+method 1, 2
+ok pen is 2
+
+
+# Array splat expansions with assigns.
+nums = [1, 2, 3]
+list = [a = 0, nums..., b = 4]
+ok a is 0
+ok b is 4
+ok list.join(' ') is '0 1 2 3 4'
+
+
+# Splat on a line by itself is invalid.
+failed = true
+try
+ CoffeeScript.compile "x 'a'\n...\n"
+ failed = false
+catch err
+ok failed
--- /dev/null
+eq '(((dollars)))', '\(\(\(dollars\)\)\)'
+eq 'one two three', "one
+ two
+ three"
+eq "four five", 'four
+
+ five'
+
+#647
+eq "''Hello, World\\''", '''
+'\'Hello, World\\\''
+'''
+eq '""Hello, World\\""', """
+"\"Hello, World\\\""
+"""
+eq 'Hello, World\n', '''
+Hello, World\
+
+'''
+
+
+hello = 'Hello'
+world = 'World'
+ok '#{hello} #{world}!' is '#{hello} #{world}!'
+ok "#{hello} #{world}!" is 'Hello World!'
+ok "[#{hello}#{world}]" is '[HelloWorld]'
+ok "#{hello}##{world}" is 'Hello#World'
+ok "Hello #{ 1 + 2 } World" is 'Hello 3 World'
+ok "#{hello} #{ 1 + 2 } #{world}" is "Hello 3 World"
+
+
+[s, t, r, i, n, g] = ['s', 't', 'r', 'i', 'n', 'g']
+ok "#{s}#{t}#{r}#{i}#{n}#{g}" is 'string'
+ok "\#{s}\#{t}\#{r}\#{i}\#{n}\#{g}" is '#{s}#{t}#{r}#{i}#{n}#{g}'
+ok "\#{string}" is '#{string}'
+
+
+ok "\#{Escaping} first" is '#{Escaping} first'
+ok "Escaping \#{in} middle" is 'Escaping #{in} middle'
+ok "Escaping \#{last}" is 'Escaping #{last}'
+
+
+ok "##" is '##'
+ok "#{}" is ''
+ok "#{}A#{} #{} #{}B#{}" is 'A B'
+ok "\\\#{}" is '\\#{}'
+
+
+ok "I won ##{20} last night." is 'I won #20 last night.'
+ok "I won ##{'#20'} last night." is 'I won ##20 last night.'
+
+
+ok "#{hello + world}" is 'HelloWorld'
+ok "#{hello + ' ' + world + '!'}" is 'Hello World!'
+
+
+list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+ok "values: #{list.join(', ')}, length: #{list.length}." is 'values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, length: 10.'
+ok "values: #{list.join ' '}" is 'values: 0 1 2 3 4 5 6 7 8 9'
+
+
+obj = {
+ name: 'Joe'
+ hi: -> "Hello #{@name}."
+ cya: -> "Hello #{@name}.".replace('Hello','Goodbye')
+}
+ok obj.hi() is "Hello Joe."
+ok obj.cya() is "Goodbye Joe."
+
+
+ok "With #{"quotes"}" is 'With quotes'
+ok 'With #{"quotes"}' is 'With #{"quotes"}'
+
+ok "Where is #{obj["name"] + '?'}" is 'Where is Joe?'
+
+ok "Where is #{"the nested #{obj["name"]}"}?" is 'Where is the nested Joe?'
+ok "Hello #{world ? "#{hello}"}" is 'Hello World'
+
+ok "Hello #{"#{"#{obj["name"]}" + '!'}"}" is 'Hello Joe!'
+
+
+a = """
+ Hello #{ "Joe" }
+ """
+ok a is "Hello Joe"
+
+
+a = 1
+b = 2
+c = 3
+ok "#{a}#{b}#{c}" is '123'
+
+
+result = null
+stash = (str) -> result = str
+stash "a #{ ('aa').replace /a/g, 'b' } c"
+ok result is 'a bb c'
+
+
+foo = "hello"
+ok "#{foo.replace("\"", "")}" is 'hello'
--- /dev/null
+num = 10
+
+result = switch num
+ when 5 then false
+ when 'a'
+ true
+ true
+ false
+ when 10 then true
+
+
+ # Mid-switch comment with whitespace
+ # and multi line
+ when 11 then false
+ else false
+
+ok result
+
+
+func = (num) ->
+ switch num
+ when 2, 4, 6
+ true
+ when 1, 3, 5
+ false
+ else false
+
+ok func(2)
+ok func(6)
+ok !func(3)
+ok !func(8)
+
+
+# Should cache the switch value, if anything fancier than a literal.
+num = 5
+result = switch num += 5
+ when 5 then false
+ when 15 then false
+ when 10 then true
+ else false
+
+ok result
+
+
+# Ensure that trailing switch elses don't get rewritten.
+result = false
+switch "word"
+ when "one thing"
+ doSomething()
+ else
+ result = true unless false
+
+ok result
+
+result = false
+switch "word"
+ when "one thing"
+ doSomething()
+ when "other thing"
+ doSomething()
+ else
+ result = true unless false
+
+ok result
+
+
+# Should be able to handle switches sans-condition.
+result = switch
+ when null then 1
+ when 'truthful string' then 2
+ else 3
+
+ok result is 2
+
+
+# Should be able to use "@properties" within the switch clause.
+obj = {
+ num: 101
+ func: ->
+ switch @num
+ when 101 then '101!'
+ else 'other'
+}
+
+ok obj.func() is '101!'
+
+
+# Should be able to use "@properties" within the switch cases.
+obj = {
+ num: 101
+ func: (yesOrNo) ->
+ result = switch yesOrNo
+ when yes then @num
+ else 'other'
+ result
+}
+
+ok obj.func(yes) is 101
--- /dev/null
+# Basic exception throwing.
+block = -> throw 'up'
+throws block, 'up'
+
+
+# Basic try/catch.
+result = try
+ 10
+finally
+ 15
+
+ok result is 10
+
+result = try
+ throw 'up'
+catch err
+ err.length
+
+ok result is 2
+
+
+result = try throw 'error' catch err then err.length
+
+ok result is 5
+
+try throw 'catch is optional'
+
+# try/catch with empty clauses still compiles.
+try
+
+try
+ # nothing
+catch err
+ # nothing
+
+try
+ # nothing
+finally
+ # nothing
+
+try
+catch err
+finally
+
+ok yes
--- /dev/null
+i = 5
+list = while i -= 1
+ i * 2
+
+ok list.join(' ') is "8 6 4 2"
+
+
+i = 5
+list = (i * 3 while i -= 1)
+
+ok list.join(' ') is "12 9 6 3"
+
+
+i = 5
+func = (num) -> i -= num
+assert = -> ok i < 5 > 0
+
+results = while func 1
+ assert()
+ i
+
+ok results.join(' ') is '4 3 2 1'
+
+
+i = 10
+results = while i -= 1 when i % 2 is 0
+ i * 2
+
+ok results.join(' ') is '16 12 8 4'
+
+
+value = false
+i = 0
+results = until value
+ value = true if i is 5
+ i += 1
+
+ok i is 6
+
+
+# And, the loop form of while.
+i = 5
+list = []
+loop
+ i -= 1
+ break if i is 0
+ list.push i * 2
+
+ok list.join(' ') is '8 6 4 2'
+
+
+#759: `if` within `while` condition
+2 while if 1 then 0
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs');
+
+/**
+ * Arguments.
+ */
+
+var args = process.argv.slice(2)
+ , pending = args.length
+ , files = {};
+
+console.log('');
+
+// parse arguments
+
+args.forEach(function(file){
+ var mod = file.replace('lib/', '');
+ fs.readFile(file, 'utf8', function(err, js){
+ if (err) throw err;
+ console.log(' \033[90mcompile : \033[0m\033[36m%s\033[0m', file);
+ files[file] = parse(js);
+ --pending || compile();
+ });
+});
+
+/**
+ * Parse the given `js`.
+ */
+
+function parse(js) {
+ return parseInheritance(parseConditionals(js));
+}
+
+/**
+ * Parse __proto__.
+ */
+
+function parseInheritance(js) {
+ return js
+ .replace(/^ *(\w+)\.prototype\.__proto__ * = *(\w+)\.prototype *;?/gm, function(_, child, parent){
+ return child + '.prototype = new ' + parent + ';\n'
+ + child + '.prototype.constructor = '+ child + ';\n';
+ });
+}
+
+/**
+ * Parse the given `js`, currently supporting:
+ *
+ * 'if' ['node' | 'browser']
+ * 'end'
+ *
+ */
+
+function parseConditionals(js) {
+ var lines = js.split('\n')
+ , len = lines.length
+ , buffer = true
+ , browser = false
+ , buf = []
+ , line
+ , cond;
+
+ for (var i = 0; i < len; ++i) {
+ line = lines[i];
+ if (/^ *\/\/ *if *(node|browser)/gm.exec(line)) {
+ cond = RegExp.$1;
+ buffer = browser = 'browser' == cond;
+ } else if (/^ *\/\/ *end/.test(line)) {
+ buffer = true;
+ browser = false;
+ } else if (browser) {
+ buf.push(line.replace(/^( *)\/\//, '$1'));
+ } else if (buffer) {
+ buf.push(line);
+ }
+ }
+
+ return buf.join('\n');
+}
+
+/**
+ * Compile the files.
+ */
+
+function compile() {
+ var buf = '';
+ buf += '\n// CommonJS require()\n\n';
+ buf += browser.require + '\n\n';
+ buf += 'require.modules = {};\n\n';
+ buf += 'require.resolve = ' + browser.resolve + ';\n\n';
+ buf += 'require.register = ' + browser.register + ';\n\n';
+ buf += 'require.relative = ' + browser.relative + ';\n\n';
+ args.forEach(function(file){
+ var js = files[file];
+ file = file.replace('lib/', '');
+ buf += '\nrequire.register("' + file + '", function(module, exports, require){\n';
+ buf += js;
+ buf += '\n}); // module: ' + file + '\n';
+ });
+ fs.writeFile('jade.js', buf, function(err){
+ if (err) throw err;
+ console.log(' \033[90m create : \033[0m\033[36m%s\033[0m', 'jade.js');
+ console.log();
+ });
+}
+
+// refactored version of weepy's
+// https://github.com/weepy/brequire/blob/master/browser/brequire.js
+
+var browser = {
+
+ /**
+ * Require a module.
+ */
+
+ require: function require(p){
+ var path = require.resolve(p)
+ , mod = require.modules[path];
+ if (!mod) throw new Error('failed to require "' + p + '"');
+ if (!mod.exports) {
+ mod.exports = {};
+ mod.call(mod.exports, mod, mod.exports, require.relative(path));
+ }
+ return mod.exports;
+ },
+
+ /**
+ * Resolve module path.
+ */
+
+ resolve: function(path){
+ var orig = path
+ , reg = path + '.js'
+ , index = path + '/index.js';
+ return require.modules[reg] && reg
+ || require.modules[index] && index
+ || orig;
+ },
+
+ /**
+ * Return relative require().
+ */
+
+ relative: function(parent) {
+ return function(p){
+ if ('.' != p[0]) return require(p);
+
+ var path = parent.split('/')
+ , segs = p.split('/');
+ path.pop();
+
+ for (var i = 0; i < segs.length; i++) {
+ var seg = segs[i];
+ if ('..' == seg) path.pop();
+ else if ('.' != seg) path.push(seg);
+ }
+
+ return require(path.join('/'));
+ };
+ },
+
+ /**
+ * Register a module.
+ */
+
+ register: function(path, fn){
+ require.modules[path] = fn;
+ }
+};
\ No newline at end of file
--- /dev/null
+.DS_Store
+lib-cov
+*.seed
\ No newline at end of file
--- /dev/null
+[submodule "deps/jscoverage"]
+ path = deps/jscoverage
+ url = git://github.com/visionmedia/node-jscoverage.git
--- /dev/null
+
+0.6.2 / 2010-09-17
+==================
+
+ * Added _node-jsocoverage_ to package.json (aka will respect npm's binroot)
+ * Added _-t, --timeout_ MS option, defaulting to 2000 ms
+ * Added _-s, --serial_
+ * __PREFIX__ clobberable
+ * Fixed `assert.response()` for latest node
+ * Fixed cov reporting from exploding on empty files
+
+0.6.2 / 2010-08-03
+==================
+
+ * Added `assert.type()`
+ * Renamed `assert.isNotUndefined()` to `assert.isDefined()`
+ * Fixed `assert.includes()` param ordering
+
+0.6.0 / 2010-07-31
+==================
+
+ * Added _docs/api.html_
+ * Added -w, --watch
+ * Added `Array` support to `assert.includes()`
+ * Added; outputting exceptions immediately. Closes #19
+ * Fixed `assert.includes()` param ordering
+ * Fixed `assert.length()` param ordering
+ * Fixed jscoverage links
+
+0.5.0 / 2010-07-16
+==================
+
+ * Added support for async exports
+ * Added timeout support to `assert.response()`. Closes #3
+ * Added 4th arg callback support to `assert.response()`
+ * Added `assert.length()`
+ * Added `assert.match()`
+ * Added `assert.isUndefined()`
+ * Added `assert.isNull()`
+ * Added `assert.includes()`
+ * Added growlnotify support via -g, --growl
+ * Added -o, --only TESTS. Ex: --only "test foo()" --only "test foo(), test bar()"
+ * Removed profanity
+
+0.4.0 / 2010-07-09
+==================
+
+ * Added reporting source coverage (respects --boring for color haters)
+ * Added callback to assert.response(). Closes #12
+ * Fixed; putting exceptions to stderr. Closes #13
+
+0.3.1 / 2010-06-28
+==================
+
+ * Faster assert.response()
+
+0.3.0 / 2010-06-28
+==================
+
+ * Added -p, --port NUM flags
+ * Added assert.response(). Closes #11
+
+0.2.1 / 2010-06-25
+==================
+
+ * Fixed issue with reporting object assertions
+
+0.2.0 / 2010-06-21
+==================
+
+ * Added `make uninstall`
+ * Added better readdir() failure message
+ * Fixed `make install` for kiwi
+
+0.1.0 / 2010-06-15
+==================
+
+ * Added better usage docs via --help
+ * Added better conditional color support
+ * Added pre exit assertion support
+
+0.0.3 / 2010-06-02
+==================
+
+ * Added more room for filenames in test coverage
+ * Added boring output support via --boring (suppress colored output)
+ * Fixed async failure exit status
+
+0.0.2 / 2010-05-30
+==================
+
+ * Fixed exit status for CI support
+
+0.0.1 / 2010-05-30
+==================
+
+ * Initial release
\ No newline at end of file
--- /dev/null
+
+PREFIX ?= /usr/local
+BIN = bin/expresso
+JSCOV = deps/jscoverage/node-jscoverage
+DOCS = docs/index.md
+HTMLDOCS = $(DOCS:.md=.html)
+
+test: $(BIN)
+ @./$(BIN) -I lib --growl $(TEST_FLAGS) test/*.test.js
+
+test-cov:
+ @./$(BIN) -I lib --cov $(TEST_FLAGS) test/*.test.js
+
+test-serial:
+ @./$(BIN) --serial -I lib $(TEST_FLAGS) test/serial/*.test.js
+
+install: install-jscov install-expresso
+
+uninstall:
+ rm -f $(PREFIX)/bin/expresso
+ rm -f $(PREFIX)/bin/node-jscoverage
+
+install-jscov: $(JSCOV)
+ install $(JSCOV) $(PREFIX)/bin
+
+install-expresso:
+ install $(BIN) $(PREFIX)/bin
+
+$(JSCOV):
+ cd deps/jscoverage && ./configure && make && mv jscoverage node-jscoverage
+
+clean:
+ @cd deps/jscoverage && git clean -fd
+
+docs: docs/api.html $(HTMLDOCS)
+
+%.html: %.md
+ @echo "... $< > $@"
+ @ronn -5 --pipe --fragment $< \
+ | cat docs/layout/head.html - docs/layout/foot.html \
+ > $@
+
+docs/api.html: bin/expresso
+ dox \
+ --title "Expresso" \
+ --ribbon "http://github.com/visionmedia/expresso" \
+ --desc "Insanely fast TDD framework for [node](http://nodejs.org) featuring code coverage reporting." \
+ $< > $@
+
+docclean:
+ rm -f docs/*.html
+
+.PHONY: test test-cov install uninstall install-expresso install-jscov clean docs docclean
\ No newline at end of file
--- /dev/null
+
+# Expresso
+
+ TDD framework for [nodejs](http://nodejs.org).
+
+## Features
+
+ - light-weight
+ - intuitive async support
+ - intuitive test runner executable
+ - test coverage support and reporting
+ - uses the _assert_ module
+ - `assert.eql()` alias of `assert.deepEqual()`
+ - `assert.response()` http response utility
+ - `assert.includes()`
+ - `assert.type()`
+ - `assert.isNull()`
+ - `assert.isUndefined()`
+ - `assert.isNotNull()`
+ - `assert.isDefined()`
+ - `assert.match()`
+ - `assert.length()`
+
+## Installation
+
+To install both expresso _and_ node-jscoverage run:
+
+ $ make install
+
+To install expresso alone (no build required) run:
+
+ $ make install-expresso
+
+Install via npm:
+
+ $ npm install expresso
+
+
+
--- /dev/null
+#!/usr/bin/env node
+
+/*!
+ * Expresso
+ * Copyright(c) TJ Holowaychuk <tj@vision-media.ca>
+ * (MIT Licensed)
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var assert = require('assert'),
+ childProcess = require('child_process'),
+ http = require('http'),
+ path = require('path'),
+ sys = require('sys'),
+ cwd = process.cwd(),
+ fs = require('fs'),
+ defer;
+
+/**
+ * Expresso version.
+ */
+
+var version = '0.6.2';
+
+/**
+ * Failure count.
+ */
+
+var failures = 0;
+
+
+/**
+ * Number of tests executed.
+ */
+
+var testcount = 0;
+
+/**
+ * Whitelist of tests to run.
+ */
+
+var only = [];
+
+/**
+ * Boring output.
+ */
+
+var boring = false;
+
+/**
+ * Growl notifications.
+ */
+
+var growl = false;
+
+/**
+ * Server port.
+ */
+
+var port = 5555;
+
+/**
+ * Watch mode.
+ */
+
+var watch = false;
+
+/**
+ * Execute serially.
+ */
+
+var serial = false;
+
+/**
+ * Default timeout.
+ */
+
+var timeout = 2000;
+
+/**
+ * Usage documentation.
+ */
+
+var usage = ''
+ + '[bold]{Usage}: expresso [options] <file ...>'
+ + '\n'
+ + '\n[bold]{Options}:'
+ + '\n -w, --watch Watch for modifications and re-execute tests'
+ + '\n -g, --growl Enable growl notifications'
+ + '\n -c, --coverage Generate and report test coverage'
+ + '\n -t, --timeout MS Timeout in milliseconds, defaults to 2000'
+ + '\n -r, --require PATH Require the given module path'
+ + '\n -o, --only TESTS Execute only the comma sperated TESTS (can be set several times)'
+ + '\n -I, --include PATH Unshift the given path to require.paths'
+ + '\n -p, --port NUM Port number for test servers, starts at 5555'
+ + '\n -s, --serial Execute tests serially'
+ + '\n -b, --boring Suppress ansi-escape colors'
+ + '\n -v, --version Output version number'
+ + '\n -h, --help Display help information'
+ + '\n';
+
+// Parse arguments
+
+var files = [],
+ args = process.argv.slice(2);
+
+while (args.length) {
+ var arg = args.shift();
+ switch (arg) {
+ case '-h':
+ case '--help':
+ print(usage + '\n');
+ process.exit(1);
+ break;
+ case '-v':
+ case '--version':
+ sys.puts(version);
+ process.exit(1);
+ break;
+ case '-i':
+ case '-I':
+ case '--include':
+ if (arg = args.shift()) {
+ require.paths.unshift(arg);
+ } else {
+ throw new Error('--include requires a path');
+ }
+ break;
+ case '-o':
+ case '--only':
+ if (arg = args.shift()) {
+ only = only.concat(arg.split(/ *, */));
+ } else {
+ throw new Error('--only requires comma-separated test names');
+ }
+ break;
+ case '-p':
+ case '--port':
+ if (arg = args.shift()) {
+ port = parseInt(arg, 10);
+ } else {
+ throw new Error('--port requires a number');
+ }
+ break;
+ case '-r':
+ case '--require':
+ if (arg = args.shift()) {
+ require(arg);
+ } else {
+ throw new Error('--require requires a path');
+ }
+ break;
+ case '-t':
+ case '--timeout':
+ if (arg = args.shift()) {
+ timeout = parseInt(arg, 10);
+ } else {
+ throw new Error('--timeout requires an argument');
+ }
+ break;
+ case '-c':
+ case '--cov':
+ case '--coverage':
+ defer = true;
+ childProcess.exec('rm -fr lib-cov && node-jscoverage lib lib-cov', function(err){
+ if (err) throw err;
+ require.paths.unshift('lib-cov');
+ run(files);
+ })
+ break;
+ case '-b':
+ case '--boring':
+ boring = true;
+ break;
+ case '-w':
+ case '--watch':
+ watch = true;
+ break;
+ case '-g':
+ case '--growl':
+ growl = true;
+ break;
+ case '-s':
+ case '--serial':
+ serial = true;
+ break;
+ default:
+ if (/\.js$/.test(arg)) {
+ files.push(arg);
+ }
+ break;
+ }
+}
+
+/**
+ * Colorized sys.error().
+ *
+ * @param {String} str
+ */
+
+function print(str){
+ sys.error(colorize(str));
+}
+
+/**
+ * Colorize the given string using ansi-escape sequences.
+ * Disabled when --boring is set.
+ *
+ * @param {String} str
+ * @return {String}
+ */
+
+function colorize(str){
+ var colors = { bold: 1, red: 31, green: 32, yellow: 33 };
+ return str.replace(/\[(\w+)\]\{([^]*?)\}/g, function(_, color, str){
+ return boring
+ ? str
+ : '\x1B[' + colors[color] + 'm' + str + '\x1B[0m';
+ });
+}
+
+// Alias deepEqual as eql for complex equality
+
+assert.eql = assert.deepEqual;
+
+/**
+ * Assert that `val` is null.
+ *
+ * @param {Mixed} val
+ * @param {String} msg
+ */
+
+assert.isNull = function(val, msg) {
+ assert.strictEqual(null, val, msg);
+};
+
+/**
+ * Assert that `val` is not null.
+ *
+ * @param {Mixed} val
+ * @param {String} msg
+ */
+
+assert.isNotNull = function(val, msg) {
+ assert.notStrictEqual(null, val, msg);
+};
+
+/**
+ * Assert that `val` is undefined.
+ *
+ * @param {Mixed} val
+ * @param {String} msg
+ */
+
+assert.isUndefined = function(val, msg) {
+ assert.strictEqual(undefined, val, msg);
+};
+
+/**
+ * Assert that `val` is not undefined.
+ *
+ * @param {Mixed} val
+ * @param {String} msg
+ */
+
+assert.isDefined = function(val, msg) {
+ assert.notStrictEqual(undefined, val, msg);
+};
+
+/**
+ * Assert that `obj` is `type`.
+ *
+ * @param {Mixed} obj
+ * @param {String} type
+ * @api public
+ */
+
+assert.type = function(obj, type, msg){
+ var real = typeof obj;
+ msg = msg || 'typeof ' + sys.inspect(obj) + ' is ' + real + ', expected ' + type;
+ assert.ok(type === real, msg);
+};
+
+/**
+ * Assert that `str` matches `regexp`.
+ *
+ * @param {String} str
+ * @param {RegExp} regexp
+ * @param {String} msg
+ */
+
+assert.match = function(str, regexp, msg) {
+ msg = msg || sys.inspect(str) + ' does not match ' + sys.inspect(regexp);
+ assert.ok(regexp.test(str), msg);
+};
+
+/**
+ * Assert that `val` is within `obj`.
+ *
+ * Examples:
+ *
+ * assert.includes('foobar', 'bar');
+ * assert.includes(['foo', 'bar'], 'foo');
+ *
+ * @param {String|Array} obj
+ * @param {Mixed} val
+ * @param {String} msg
+ */
+
+assert.includes = function(obj, val, msg) {
+ msg = msg || sys.inspect(obj) + ' does not include ' + sys.inspect(val);
+ assert.ok(obj.indexOf(val) >= 0, msg);
+};
+
+/**
+ * Assert length of `val` is `n`.
+ *
+ * @param {Mixed} val
+ * @param {Number} n
+ * @param {String} msg
+ */
+
+assert.length = function(val, n, msg) {
+ msg = msg || sys.inspect(val) + ' has length of ' + val.length + ', expected ' + n;
+ assert.equal(n, val.length, msg);
+};
+
+/**
+ * Assert response from `server` with
+ * the given `req` object and `res` assertions object.
+ *
+ * @param {Server} server
+ * @param {Object} req
+ * @param {Object|Function} res
+ * @param {String} msg
+ */
+
+assert.response = function(server, req, res, msg){
+ // Callback as third or fourth arg
+ var callback = typeof res === 'function'
+ ? res
+ : typeof msg === 'function'
+ ? msg
+ : function(){};
+
+ // Default messate to test title
+ if (typeof msg === 'function') msg = null;
+ msg = msg || assert.testTitle;
+ msg += '. ';
+
+ // Pending responses
+ server.__pending = server.__pending || 0;
+ server.__pending++;
+
+ // Create client
+ if (!server.fd) {
+ server.listen(server.__port = port++, '127.0.0.1');
+ server.client = http.createClient(server.__port);
+ }
+
+ // Issue request
+ var timer,
+ client = server.client,
+ method = req.method || 'GET',
+ status = res.status || res.statusCode,
+ data = req.data || req.body,
+ timeout = req.timeout || 0;
+
+ var request = client.request(method, req.url, req.headers);
+
+ // Timeout
+ if (timeout) {
+ timer = setTimeout(function(){
+ --server.__pending || server.close();
+ delete req.timeout;
+ assert.fail(msg + 'Request timed out after ' + timeout + 'ms.');
+ }, timeout);
+ }
+
+ if (data) request.write(data);
+ request.addListener('response', function(response){
+ response.body = '';
+ response.setEncoding('utf8');
+ response.addListener('data', function(chunk){ response.body += chunk; });
+ response.addListener('end', function(){
+ --server.__pending || server.close();
+ if (timer) clearTimeout(timer);
+
+ // Assert response body
+ if (res.body !== undefined) {
+ var eql = res.body instanceof RegExp
+ ? res.body.test(response.body)
+ : res.body === response.body;
+ assert.ok(
+ eql,
+ msg + 'Invalid response body.\n'
+ + ' Expected: ' + sys.inspect(res.body) + '\n'
+ + ' Got: ' + sys.inspect(response.body)
+ );
+ }
+
+ // Assert response status
+ if (typeof status === 'number') {
+ assert.equal(
+ response.statusCode,
+ status,
+ msg + colorize('Invalid response status code.\n'
+ + ' Expected: [green]{' + status + '}\n'
+ + ' Got: [red]{' + response.statusCode + '}')
+ );
+ }
+
+ // Assert response headers
+ if (res.headers) {
+ var keys = Object.keys(res.headers);
+ for (var i = 0, len = keys.length; i < len; ++i) {
+ var name = keys[i],
+ actual = response.headers[name.toLowerCase()],
+ expected = res.headers[name];
+ assert.equal(
+ actual,
+ expected,
+ msg + colorize('Invalid response header [bold]{' + name + '}.\n'
+ + ' Expected: [green]{' + expected + '}\n'
+ + ' Got: [red]{' + actual + '}')
+ );
+ }
+ }
+
+ // Callback
+ callback(response);
+ });
+ });
+ request.end();
+};
+
+/**
+ * Pad the given string to the maximum width provided.
+ *
+ * @param {String} str
+ * @param {Number} width
+ * @return {String}
+ */
+
+function lpad(str, width) {
+ str = String(str);
+ var n = width - str.length;
+ if (n < 1) return str;
+ while (n--) str = ' ' + str;
+ return str;
+}
+
+/**
+ * Pad the given string to the maximum width provided.
+ *
+ * @param {String} str
+ * @param {Number} width
+ * @return {String}
+ */
+
+function rpad(str, width) {
+ str = String(str);
+ var n = width - str.length;
+ if (n < 1) return str;
+ while (n--) str = str + ' ';
+ return str;
+}
+
+/**
+ * Report test coverage.
+ *
+ * @param {Object} cov
+ */
+
+function reportCoverage(cov) {
+ populateCoverage(cov);
+ // Stats
+ print('\n [bold]{Test Coverage}\n');
+ var sep = ' +------------------------------------------+----------+------+------+--------+',
+ lastSep = ' +----------+------+------+--------+';
+ sys.puts(sep);
+ sys.puts(' | filename | coverage | LOC | SLOC | missed |');
+ sys.puts(sep);
+ for (var name in cov) {
+ var file = cov[name];
+ if (Array.isArray(file)) {
+ sys.print(' | ' + rpad(name, 40));
+ sys.print(' | ' + lpad(file.coverage.toFixed(2), 8));
+ sys.print(' | ' + lpad(file.LOC, 4));
+ sys.print(' | ' + lpad(file.SLOC, 4));
+ sys.print(' | ' + lpad(file.totalMisses, 6));
+ sys.print(' |\n');
+ }
+ }
+ sys.puts(sep);
+ sys.print(' ' + rpad('', 40));
+ sys.print(' | ' + lpad(cov.coverage.toFixed(2), 8));
+ sys.print(' | ' + lpad(cov.LOC, 4));
+ sys.print(' | ' + lpad(cov.SLOC, 4));
+ sys.print(' | ' + lpad(cov.totalMisses, 6));
+ sys.print(' |\n');
+ sys.puts(lastSep);
+ // Source
+ for (var name in cov) {
+ if (name.match(/\.js$/)) {
+ var file = cov[name];
+ print('\n [bold]{' + name + '}:');
+ print(file.source);
+ sys.print('\n');
+ }
+ }
+}
+
+/**
+ * Populate code coverage data.
+ *
+ * @param {Object} cov
+ */
+
+function populateCoverage(cov) {
+ cov.LOC =
+ cov.SLOC =
+ cov.totalFiles =
+ cov.totalHits =
+ cov.totalMisses =
+ cov.coverage = 0;
+ for (var name in cov) {
+ var file = cov[name];
+ if (Array.isArray(file)) {
+ // Stats
+ ++cov.totalFiles;
+ cov.totalHits += file.totalHits = coverage(file, true);
+ cov.totalMisses += file.totalMisses = coverage(file, false);
+ file.totalLines = file.totalHits + file.totalMisses;
+ cov.SLOC += file.SLOC = file.totalLines;
+ if (!file.source) file.source = [];
+ cov.LOC += file.LOC = file.source.length;
+ file.coverage = (file.totalHits / file.totalLines) * 100;
+ // Source
+ var width = file.source.length.toString().length;
+ file.source = file.source.map(function(line, i){
+ ++i;
+ var hits = file[i] === 0 ? 0 : (file[i] || ' ');
+ if (!boring) {
+ if (hits === 0) {
+ hits = '\x1b[31m' + hits + '\x1b[0m';
+ line = '\x1b[41m' + line + '\x1b[0m';
+ } else {
+ hits = '\x1b[32m' + hits + '\x1b[0m';
+ }
+ }
+ return '\n ' + lpad(i, width) + ' | ' + hits + ' | ' + line;
+ }).join('');
+ }
+ }
+ cov.coverage = (cov.totalHits / cov.SLOC) * 100;
+}
+
+/**
+ * Total coverage for the given file data.
+ *
+ * @param {Array} data
+ * @return {Type}
+ */
+
+function coverage(data, val) {
+ var n = 0;
+ for (var i = 0, len = data.length; i < len; ++i) {
+ if (data[i] !== undefined && data[i] == val) ++n;
+ }
+ return n;
+}
+
+/**
+ * Run the given test `files`, or try _test/*_.
+ *
+ * @param {Array} files
+ */
+
+function run(files) {
+ if (!files.length) {
+ try {
+ files = fs.readdirSync('test').map(function(file){
+ return 'test/' + file;
+ });
+ } catch (err) {
+ print('\n failed to load tests in [bold]{./test}\n');
+ ++failures;
+ process.exit(1);
+ }
+ }
+ if (watch) watchFiles(files);
+ runFiles(files);
+}
+
+/**
+ * Show the cursor when `show` is true, otherwise hide it.
+ *
+ * @param {Boolean} show
+ */
+
+function cursor(show) {
+ if (show) {
+ sys.print('\x1b[?25h');
+ } else {
+ sys.print('\x1b[?25l');
+ }
+}
+
+/**
+ * Run the given test `files`.
+ *
+ * @param {Array} files
+ */
+
+function runFiles(files) {
+ files.forEach(runFile);
+}
+
+/**
+ * Run tests for the given `file`.
+ *
+ * @param {String} file
+ */
+
+function runFile(file) {
+ if (file.match(/\.js$/)) {
+ var title = path.basename(file),
+ file = path.join(cwd, file),
+ mod = require(file.replace(/\.js$/, ''));
+ (function check(){
+ var len = Object.keys(mod).length;
+ if (len) {
+ runSuite(title, mod);
+ } else {
+ setTimeout(check, 20);
+ }
+ })();
+ }
+}
+
+/**
+ * Clear the module cache for the given `file`.
+ *
+ * @param {String} file
+ */
+
+function clearCache(file) {
+ var keys = Object.keys(module.moduleCache);
+ for (var i = 0, len = keys.length; i < len; ++i) {
+ var key = keys[i];
+ if (key.indexOf(file) === key.length - file.length) {
+ delete module.moduleCache[key];
+ }
+ }
+}
+
+/**
+ * Watch the given `files` for changes.
+ *
+ * @param {Array} files
+ */
+
+function watchFiles(files) {
+ var p = 0,
+ c = ['â–« ', 'â–«â–« ', 'â–«â–«â–« ', ' â–«â–«â–«',
+ ' â–«â–«', ' â–«', ' â–«', ' â–«â–«',
+ 'â–«â–«â–« ', 'â–«â–« ', 'â–« '],
+ l = c.length;
+ cursor(false);
+ setInterval(function(){
+ sys.print(colorize(' [green]{' + c[p++ % l] + '} watching\r'));
+ }, 100);
+ files.forEach(function(file){
+ fs.watchFile(file, { interval: 100 }, function(curr, prev){
+ if (curr.mtime > prev.mtime) {
+ print(' [yellow]{â—¦} ' + file);
+ clearCache(file);
+ runFile(file);
+ }
+ });
+ });
+}
+
+/**
+ * Report `err` for the given `test` and `suite`.
+ *
+ * @param {String} suite
+ * @param {String} test
+ * @param {Error} err
+ */
+
+function error(suite, test, err) {
+ ++failures;
+ var name = err.name,
+ stack = err.stack.replace(err.name, ''),
+ label = test === 'uncaught'
+ ? test
+ : suite + ' ' + test;
+ print('\n [bold]{' + label + '}: [red]{' + name + '}' + stack + '\n');
+ if (watch) notify(label + ' failed');
+}
+
+/**
+ * Run the given tests.
+ *
+ * @param {String} title
+ * @param {Object} tests
+ */
+
+var dots = 0;
+function runSuite(title, tests) {
+ // Keys
+ var keys = only.length
+ ? only.slice(0)
+ : Object.keys(tests);
+
+ // Setup
+ var setup = tests.setup || function(fn){ fn(); };
+
+ // Iterate tests
+ (function next(){
+ if (keys.length) {
+ var key,
+ test = tests[key = keys.shift()];
+ // Non-tests
+ if (key === 'setup') return next();
+
+ // Run test
+ if (test) {
+ try {
+ ++testcount;
+ assert.testTitle = key;
+ if (serial) {
+ if (!watch) {
+ sys.print('.');
+ if (++dots % 25 === 0) sys.print('\n');
+ }
+ setup(function(){
+ if (test.length < 2) {
+ test(assert);
+ next();
+ } else {
+ var id = setTimeout(function(){
+ throw new Error("'" + key + "' timed out");
+ }, timeout);
+ test(assert, function(){
+ clearTimeout(id);
+ next();
+ });
+ }
+ });
+ } else {
+ test(assert, function(fn){
+ process.addListener('beforeExit', function(){
+ try {
+ fn();
+ } catch (err) {
+ error(title, key, err);
+ }
+ });
+ });
+ }
+ } catch (err) {
+ error(title, key, err);
+ }
+ }
+ if (!serial) next();
+ }
+ })();
+}
+
+/**
+ * Report exceptions.
+ */
+
+function report() {
+ process.emit('beforeExit');
+ if (failures) {
+ print('\n [bold]{Failures}: [red]{' + failures + '}\n\n');
+ notify('Failures: ' + failures);
+ } else {
+ if (serial) print('');
+ print('\n [green]{100%} ' + testcount + ' tests\n');
+ notify('100% ok');
+ }
+ if (typeof _$jscoverage === 'object') {
+ reportCoverage(_$jscoverage);
+ }
+}
+
+/**
+ * Growl notify the given `msg`.
+ *
+ * @param {String} msg
+ */
+
+function notify(msg) {
+ if (growl) {
+ childProcess.exec('growlnotify -name Expresso -m "' + msg + '"');
+ }
+}
+
+// Report uncaught exceptions
+
+process.addListener('uncaughtException', function(err){
+ error('uncaught', 'uncaught', err);
+});
+
+// Show cursor
+
+['INT', 'TERM', 'QUIT'].forEach(function(sig){
+ process.addListener('SIG' + sig, function(){
+ cursor(true);
+ process.exit(1);
+ });
+});
+
+// Report test coverage when available
+// and emit "beforeExit" event to perform
+// final assertions
+
+var orig = process.emit;
+process.emit = function(event){
+ if (event === 'exit') {
+ report();
+ process.reallyExit(failures);
+ }
+ orig.apply(this, arguments);
+};
+
+// Run test files
+
+if (!defer) run(files);
--- /dev/null
+<a href="http://github.com/visionmedia/expresso"><img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a><html>
+ <head>
+ <title>Expresso</title>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
+ <style>body {
+ margin: 0;
+ padding: 0;
+ font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ color: #252519;
+}
+a {
+ color: #252519;
+}
+a:hover {
+ text-decoration: underline;
+ color: #19469D;
+}
+p {
+ margin: 12px 0;
+}
+h1, h2, h3 {
+ margin: 0;
+ padding: 0;
+}
+table#source {
+ width: 100%;
+ border-collapse: collapse;
+}
+table#source td:first-child {
+ padding: 30px 40px 30px 40px;
+ vertical-align: top;
+}
+table#source td:first-child,
+table#source td:first-child pre {
+ width: 450px;
+}
+table#source td:last-child {
+ padding: 30px 0 30px 40px;
+ border-left: 1px solid #E5E5EE;
+ background: #F5F5FF;
+}
+table#source tr {
+ border-bottom: 1px solid #E5E5EE;
+}
+table#source tr.filename {
+ padding-top: 40px;
+ border-top: 1px solid #E5E5EE;
+}
+table#source tr.filename td:first-child {
+ text-transform: capitalize;
+}
+table#source tr.filename td:last-child {
+ font-size: 12px;
+}
+table#source tr.filename h2 {
+ margin: 0;
+ padding: 0;
+ cursor: pointer;
+}
+table#source tr.code h1,
+table#source tr.code h2,
+table#source tr.code h3 {
+ margin-top: 30px;
+ font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;
+ font-size: 18px;
+}
+table#source tr.code h2 {
+ font-size: 16px;
+}
+table#source tr.code h3 {
+ font-size: 14px;
+}
+table#source tr.code ul {
+ margin: 15px 0 15px 35px;
+ padding: 0;
+}
+table#source tr.code ul li {
+ margin: 0;
+ padding: 1px 0;
+}
+table#source tr.code ul li p {
+ margin: 0;
+ padding: 0;
+}
+table#source tr.code td:first-child pre {
+ padding: 20px;
+}
+#ribbon {
+ position: fixed;
+ top: 0;
+ right: 0;
+}
+code .string { color: #219161; }
+code .regexp { color: #219161; }
+code .keyword { color: #954121; }
+code .number { color: #19469D; }
+code .comment { color: #bbb; }
+code .this { color: #19469D; }</style>
+ <script>
+ $(function(){
+ $('tr.code').hide();
+ $('tr.filename').toggle(function(){
+ $(this).nextUntil('.filename').fadeIn();
+ }, function(){
+ $(this).nextUntil('.filename').fadeOut();
+ });
+ });
+ </script>
+ </head>
+ <body>
+<table id="source"><tbody><tr><td><h1>Expresso</h1><p>Insanely fast TDD framework for <a href="http://nodejs.org">node</a> featuring code coverage reporting.</p></td><td></td></tr><tr class="filename"><td><h2 id="bin/expresso"><a href="#">expresso</a></h2></td><td>bin/expresso</td></tr><tr class="code">
+<td class="docs">
+<h1>!/usr/bin/env node</h1>
+</td>
+<td class="code">
+<pre><code>!
+ * <span class="class">Expresso</span>
+ * <span class="class">Copyright</span>(<span class="variable">c</span>) <span class="class">TJ</span> <span class="class">Holowaychuk</span> &<span class="variable">lt</span>;<span class="variable">tj</span>@<span class="variable">vision</span>-<span class="variable">media</span>.<span class="variable">ca</span>&<span class="variable">gt</span>;
+ * (<span class="class">MIT</span> <span class="class">Licensed</span>)
+ </code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Module dependencies.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">assert</span> = <span class="variable">require</span>(<span class="string">'assert'</span>),
+ <span class="variable">childProcess</span> = <span class="variable">require</span>(<span class="string">'child_process'</span>),
+ <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),
+ <span class="variable">path</span> = <span class="variable">require</span>(<span class="string">'path'</span>),
+ <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),
+ <span class="variable">cwd</span> = <span class="variable">process</span>.<span class="variable">cwd</span>(),
+ <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>),
+ <span class="variable">defer</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Expresso version.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">version</span> = <span class="string">'0.6.1'</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Failure count.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">failures</span> = <span class="number integer">0</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Number of tests executed.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">testcount</span> = <span class="number integer">0</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Whitelist of tests to run.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">only</span> = [];</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Boring output.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">boring</span> = <span class="variable">false</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Growl notifications.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">growl</span> = <span class="variable">false</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Server port.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">port</span> = <span class="number integer">5555</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Watch mode.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">watch</span> = <span class="variable">false</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Execute serially.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">serial</span> = <span class="variable">false</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Usage documentation.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">usage</span> = <span class="string">''</span>
+ + <span class="string">'[bold]{Usage}: expresso [options] <file ...>'</span>
+ + <span class="string">'\n'</span>
+ + <span class="string">'\n[bold]{Options}:'</span>
+ + <span class="string">'\n -w, --watch Watch for modifications and re-execute tests'</span>
+ + <span class="string">'\n -g, --growl Enable growl notifications'</span>
+ + <span class="string">'\n -c, --coverage Generate and report test coverage'</span>
+ + <span class="string">'\n -r, --require PATH Require the given module path'</span>
+ + <span class="string">'\n -o, --only TESTS Execute only the comma sperated TESTS (can be set several times)'</span>
+ + <span class="string">'\n -I, --include PATH Unshift the given path to require.paths'</span>
+ + <span class="string">'\n -p, --port NUM Port number for test servers, starts at 5555'</span>
+ + <span class="string">'\n -s, --serial Execute tests serially'</span>
+ + <span class="string">'\n -b, --boring Suppress ansi-escape colors'</span>
+ + <span class="string">'\n -v, --version Output version number'</span>
+ + <span class="string">'\n -h, --help Display help information'</span>
+ + <span class="string">'\n'</span>;
+
+<span class="comment">// Parse arguments</span>
+
+<span class="keyword">var</span> <span class="variable">files</span> = [],
+ <span class="variable">args</span> = <span class="variable">process</span>.<span class="variable">argv</span>.<span class="variable">slice</span>(<span class="number integer">2</span>);
+
+<span class="keyword">while</span> (<span class="variable">args</span>.<span class="variable">length</span>) {
+ <span class="keyword">var</span> <span class="variable">arg</span> = <span class="variable">args</span>.<span class="variable">shift</span>();
+ <span class="keyword">switch</span> (<span class="variable">arg</span>) {
+ <span class="keyword">case</span> <span class="string">'-h'</span>:
+ <span class="keyword">case</span> <span class="string">'--help'</span>:
+ <span class="variable">print</span>(<span class="variable">usage</span> + <span class="string">'\n'</span>);
+ <span class="variable">process</span>.<span class="variable">exit</span>(<span class="number integer">1</span>);
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-v'</span>:
+ <span class="keyword">case</span> <span class="string">'--version'</span>:
+ <span class="variable">sys</span>.<span class="variable">puts</span>(<span class="variable">version</span>);
+ <span class="variable">process</span>.<span class="variable">exit</span>(<span class="number integer">1</span>);
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-i'</span>:
+ <span class="keyword">case</span> <span class="string">'-I'</span>:
+ <span class="keyword">case</span> <span class="string">'--include'</span>:
+ <span class="keyword">if</span> (<span class="variable">arg</span> = <span class="variable">args</span>.<span class="variable">shift</span>()) {
+ <span class="variable">require</span>.<span class="variable">paths</span>.<span class="variable">unshift</span>(<span class="variable">arg</span>);
+ } <span class="keyword">else</span> {
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'--include requires a path'</span>);
+ }
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-o'</span>:
+ <span class="keyword">case</span> <span class="string">'--only'</span>:
+ <span class="keyword">if</span> (<span class="variable">arg</span> = <span class="variable">args</span>.<span class="variable">shift</span>()) {
+ <span class="variable">only</span> = <span class="variable">only</span>.<span class="variable">concat</span>(<span class="variable">arg</span>.<span class="variable">split</span>(<span class="regexp">/ *, */</span>));
+ } <span class="keyword">else</span> {
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'--only requires comma-separated test names'</span>);
+ }
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-p'</span>:
+ <span class="keyword">case</span> <span class="string">'--port'</span>:
+ <span class="keyword">if</span> (<span class="variable">arg</span> = <span class="variable">args</span>.<span class="variable">shift</span>()) {
+ <span class="variable">port</span> = <span class="variable">parseInt</span>(<span class="variable">arg</span>, <span class="number integer">10</span>);
+ } <span class="keyword">else</span> {
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'--port requires a number'</span>);
+ }
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-r'</span>:
+ <span class="keyword">case</span> <span class="string">'--require'</span>:
+ <span class="keyword">if</span> (<span class="variable">arg</span> = <span class="variable">args</span>.<span class="variable">shift</span>()) {
+ <span class="variable">require</span>(<span class="variable">arg</span>);
+ } <span class="keyword">else</span> {
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'--require requires a path'</span>);
+ }
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-c'</span>:
+ <span class="keyword">case</span> <span class="string">'--cov'</span>:
+ <span class="keyword">case</span> <span class="string">'--coverage'</span>:
+ <span class="variable">defer</span> = <span class="variable">true</span>;
+ <span class="variable">childProcess</span>.<span class="variable">exec</span>(<span class="string">'rm -fr lib-cov && node-jscoverage lib lib-cov'</span>, <span class="keyword">function</span>(<span class="variable">err</span>){
+ <span class="keyword">if</span> (<span class="variable">err</span>) <span class="keyword">throw</span> <span class="variable">err</span>;
+ <span class="variable">require</span>.<span class="variable">paths</span>.<span class="variable">unshift</span>(<span class="string">'lib-cov'</span>);
+ <span class="variable">run</span>(<span class="variable">files</span>);
+ })
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-b'</span>:
+ <span class="keyword">case</span> <span class="string">'--boring'</span>:
+ <span class="variable">boring</span> = <span class="variable">true</span>;
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-w'</span>:
+ <span class="keyword">case</span> <span class="string">'--watch'</span>:
+ <span class="variable">watch</span> = <span class="variable">true</span>;
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-g'</span>:
+ <span class="keyword">case</span> <span class="string">'--growl'</span>:
+ <span class="variable">growl</span> = <span class="variable">true</span>;
+ <span class="keyword">break</span>;
+ <span class="keyword">case</span> <span class="string">'-s'</span>:
+ <span class="keyword">case</span> <span class="string">'--serial'</span>:
+ <span class="variable">serial</span> = <span class="variable">true</span>;
+ <span class="keyword">break</span>;
+ <span class="keyword">default</span>:
+ <span class="keyword">if</span> (<span class="regexp">/\.js$/</span>.<span class="variable">test</span>(<span class="variable">arg</span>)) {
+ <span class="variable">files</span>.<span class="variable">push</span>(<span class="variable">arg</span>);
+ }
+ <span class="keyword">break</span>;
+ }
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Colorized sys.error().</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> str</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">print</span>(<span class="variable">str</span>){
+ <span class="variable">sys</span>.<span class="variable">error</span>(<span class="variable">colorize</span>(<span class="variable">str</span>));
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Colorize the given string using ansi-escape sequences.
+Disabled when --boring is set.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>return</strong>: <em>String</em> </p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">colorize</span>(<span class="variable">str</span>){
+ <span class="keyword">var</span> <span class="variable">colors</span> = { <span class="variable">bold</span>: <span class="number integer">1</span>, <span class="variable">red</span>: <span class="number integer">31</span>, <span class="variable">green</span>: <span class="number integer">32</span>, <span class="variable">yellow</span>: <span class="number integer">33</span> };
+ <span class="keyword">return</span> <span class="variable">str</span>.<span class="variable">replace</span>(<span class="regexp">/\[(\w+)\]\{([^]*?)\}/g</span>, <span class="keyword">function</span>(<span class="variable">_</span>, <span class="variable">color</span>, <span class="variable">str</span>){
+ <span class="keyword">return</span> <span class="variable">boring</span>
+ ? <span class="variable">str</span>
+ : <span class="string">'\x1B['</span> + <span class="variable">colors</span>[<span class="variable">color</span>] + <span class="string">'m'</span> + <span class="variable">str</span> + <span class="string">'\x1B[0m'</span>;
+ });
+}
+
+<span class="comment">// Alias deepEqual as eql for complex equality</span>
+
+<span class="variable">assert</span>.<span class="variable">eql</span> = <span class="variable">assert</span>.<span class="variable">deepEqual</span>;</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert that <code>val</code> is null.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Mixed</em> val</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">isNull</span> = <span class="keyword">function</span>(<span class="variable">val</span>, <span class="variable">msg</span>) {
+ <span class="variable">assert</span>.<span class="variable">strictEqual</span>(<span class="keyword">null</span>, <span class="variable">val</span>, <span class="variable">msg</span>);
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert that <code>val</code> is not null.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Mixed</em> val</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">isNotNull</span> = <span class="keyword">function</span>(<span class="variable">val</span>, <span class="variable">msg</span>) {
+ <span class="variable">assert</span>.<span class="variable">notStrictEqual</span>(<span class="keyword">null</span>, <span class="variable">val</span>, <span class="variable">msg</span>);
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert that <code>val</code> is undefined.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Mixed</em> val</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">isUndefined</span> = <span class="keyword">function</span>(<span class="variable">val</span>, <span class="variable">msg</span>) {
+ <span class="variable">assert</span>.<span class="variable">strictEqual</span>(<span class="variable">undefined</span>, <span class="variable">val</span>, <span class="variable">msg</span>);
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert that <code>val</code> is not undefined.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Mixed</em> val</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">isDefined</span> = <span class="keyword">function</span>(<span class="variable">val</span>, <span class="variable">msg</span>) {
+ <span class="variable">assert</span>.<span class="variable">notStrictEqual</span>(<span class="variable">undefined</span>, <span class="variable">val</span>, <span class="variable">msg</span>);
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert that <code>obj</code> is <code>type</code>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Mixed</em> obj</p></li><li><p><strong>param</strong>: <em>String</em> type</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">type</span> = <span class="keyword">function</span>(<span class="variable">obj</span>, <span class="variable">type</span>, <span class="variable">msg</span>){
+ <span class="keyword">var</span> <span class="variable">real</span> = <span class="keyword">typeof</span> <span class="variable">obj</span>;
+ <span class="variable">msg</span> = <span class="variable">msg</span> || <span class="string">'typeof '</span> + <span class="variable">sys</span>.<span class="variable">inspect</span>(<span class="variable">obj</span>) + <span class="string">' is '</span> + <span class="variable">real</span> + <span class="string">', expected '</span> + <span class="variable">type</span>;
+ <span class="variable">assert</span>.<span class="variable">ok</span>(<span class="variable">type</span> === <span class="variable">real</span>, <span class="variable">msg</span>);
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert that <code>str</code> matches <code>regexp</code>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>param</strong>: <em>RegExp</em> regexp</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">match</span> = <span class="keyword">function</span>(<span class="variable">str</span>, <span class="variable">regexp</span>, <span class="variable">msg</span>) {
+ <span class="variable">msg</span> = <span class="variable">msg</span> || <span class="variable">sys</span>.<span class="variable">inspect</span>(<span class="variable">str</span>) + <span class="string">' does not match '</span> + <span class="variable">sys</span>.<span class="variable">inspect</span>(<span class="variable">regexp</span>);
+ <span class="variable">assert</span>.<span class="variable">ok</span>(<span class="variable">regexp</span>.<span class="variable">test</span>(<span class="variable">str</span>), <span class="variable">msg</span>);
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert that <code>val</code> is within <code>obj</code>.</p>
+
+<h2>Examples</h2>
+
+<p> assert.includes('foobar', 'bar');
+ assert.includes(['foo', 'bar'], 'foo');</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String | Array</em> obj</p></li><li><p><strong>param</strong>: <em>Mixed</em> val</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">includes</span> = <span class="keyword">function</span>(<span class="variable">obj</span>, <span class="variable">val</span>, <span class="variable">msg</span>) {
+ <span class="variable">msg</span> = <span class="variable">msg</span> || <span class="variable">sys</span>.<span class="variable">inspect</span>(<span class="variable">obj</span>) + <span class="string">' does not include '</span> + <span class="variable">sys</span>.<span class="variable">inspect</span>(<span class="variable">val</span>);
+ <span class="variable">assert</span>.<span class="variable">ok</span>(<span class="variable">obj</span>.<span class="variable">indexOf</span>(<span class="variable">val</span>) &<span class="variable">gt</span>;= <span class="number integer">0</span>, <span class="variable">msg</span>);
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert length of <code>val</code> is <code>n</code>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Mixed</em> val</p></li><li><p><strong>param</strong>: <em>Number</em> n</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">length</span> = <span class="keyword">function</span>(<span class="variable">val</span>, <span class="variable">n</span>, <span class="variable">msg</span>) {
+ <span class="variable">msg</span> = <span class="variable">msg</span> || <span class="variable">sys</span>.<span class="variable">inspect</span>(<span class="variable">val</span>) + <span class="string">' has length of '</span> + <span class="variable">val</span>.<span class="variable">length</span> + <span class="string">', expected '</span> + <span class="variable">n</span>;
+ <span class="variable">assert</span>.<span class="variable">equal</span>(<span class="variable">n</span>, <span class="variable">val</span>.<span class="variable">length</span>, <span class="variable">msg</span>);
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Assert response from <code>server</code> with
+the given <code>req</code> object and <code>res</code> assertions object.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Server</em> server</p></li><li><p><strong>param</strong>: <em>Object</em> req</p></li><li><p><strong>param</strong>: <em>Object | Function</em> res</p></li><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="variable">assert</span>.<span class="variable">response</span> = <span class="keyword">function</span>(<span class="variable">server</span>, <span class="variable">req</span>, <span class="variable">res</span>, <span class="variable">msg</span>){
+ <span class="comment">// Callback as third or fourth arg</span>
+ <span class="keyword">var</span> <span class="variable">callback</span> = <span class="keyword">typeof</span> <span class="variable">res</span> === <span class="string">'function'</span>
+ ? <span class="variable">res</span>
+ : <span class="keyword">typeof</span> <span class="variable">msg</span> === <span class="string">'function'</span>
+ ? <span class="variable">msg</span>
+ : <span class="keyword">function</span>(){};
+
+ <span class="comment">// Default messate to test title</span>
+ <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">msg</span> === <span class="string">'function'</span>) <span class="variable">msg</span> = <span class="keyword">null</span>;
+ <span class="variable">msg</span> = <span class="variable">msg</span> || <span class="variable">assert</span>.<span class="variable">testTitle</span>;
+ <span class="variable">msg</span> += <span class="string">'. '</span>;
+
+ <span class="comment">// Pending responses</span>
+ <span class="variable">server</span>.<span class="variable">__pending</span> = <span class="variable">server</span>.<span class="variable">__pending</span> || <span class="number integer">0</span>;
+ <span class="variable">server</span>.<span class="variable">__pending</span>++;
+
+ <span class="comment">// Create client</span>
+ <span class="keyword">if</span> (!<span class="variable">server</span>.<span class="variable">fd</span>) {
+ <span class="variable">server</span>.<span class="variable">listen</span>(<span class="variable">server</span>.<span class="variable">__port</span> = <span class="variable">port</span>++, <span class="string">'127.0.0.1'</span>);
+ <span class="variable">server</span>.<span class="variable">client</span> = <span class="variable">http</span>.<span class="variable">createClient</span>(<span class="variable">server</span>.<span class="variable">__port</span>);
+ }
+
+ <span class="comment">// Issue request</span>
+ <span class="keyword">var</span> <span class="variable">timer</span>,
+ <span class="variable">client</span> = <span class="variable">server</span>.<span class="variable">client</span>,
+ <span class="variable">method</span> = <span class="variable">req</span>.<span class="variable">method</span> || <span class="string">'GET'</span>,
+ <span class="variable">status</span> = <span class="variable">res</span>.<span class="variable">status</span> || <span class="variable">res</span>.<span class="variable">statusCode</span>,
+ <span class="variable">data</span> = <span class="variable">req</span>.<span class="variable">data</span> || <span class="variable">req</span>.<span class="variable">body</span>,
+ <span class="variable">timeout</span> = <span class="variable">req</span>.<span class="variable">timeout</span> || <span class="number integer">0</span>;
+
+ <span class="keyword">var</span> <span class="variable">request</span> = <span class="variable">client</span>.<span class="variable">request</span>(<span class="variable">method</span>, <span class="variable">req</span>.<span class="variable">url</span>, <span class="variable">req</span>.<span class="variable">headers</span>);
+
+ <span class="comment">// Timeout</span>
+ <span class="keyword">if</span> (<span class="variable">timeout</span>) {
+ <span class="variable">timer</span> = <span class="variable">setTimeout</span>(<span class="keyword">function</span>(){
+ --<span class="variable">server</span>.<span class="variable">__pending</span> || <span class="variable">server</span>.<span class="variable">close</span>();
+ <span class="keyword">delete</span> <span class="variable">req</span>.<span class="variable">timeout</span>;
+ <span class="variable">assert</span>.<span class="variable">fail</span>(<span class="variable">msg</span> + <span class="string">'Request timed out after '</span> + <span class="variable">timeout</span> + <span class="string">'ms.'</span>);
+ }, <span class="variable">timeout</span>);
+ }
+
+ <span class="keyword">if</span> (<span class="variable">data</span>) <span class="variable">request</span>.<span class="variable">write</span>(<span class="variable">data</span>);
+ <span class="variable">request</span>.<span class="variable">addListener</span>(<span class="string">'response'</span>, <span class="keyword">function</span>(<span class="variable">response</span>){
+ <span class="variable">response</span>.<span class="variable">body</span> = <span class="string">''</span>;
+ <span class="variable">response</span>.<span class="variable">setEncoding</span>(<span class="string">'utf8'</span>);
+ <span class="variable">response</span>.<span class="variable">addListener</span>(<span class="string">'data'</span>, <span class="keyword">function</span>(<span class="variable">chunk</span>){ <span class="variable">response</span>.<span class="variable">body</span> += <span class="variable">chunk</span>; });
+ <span class="variable">response</span>.<span class="variable">addListener</span>(<span class="string">'end'</span>, <span class="keyword">function</span>(){
+ --<span class="variable">server</span>.<span class="variable">__pending</span> || <span class="variable">server</span>.<span class="variable">close</span>();
+ <span class="keyword">if</span> (<span class="variable">timer</span>) <span class="variable">clearTimeout</span>(<span class="variable">timer</span>);
+
+ <span class="comment">// Assert response body</span>
+ <span class="keyword">if</span> (<span class="variable">res</span>.<span class="variable">body</span> !== <span class="variable">undefined</span>) {
+ <span class="variable">assert</span>.<span class="variable">equal</span>(
+ <span class="variable">response</span>.<span class="variable">body</span>,
+ <span class="variable">res</span>.<span class="variable">body</span>,
+ <span class="variable">msg</span> + <span class="string">'Invalid response body.\n'</span>
+ + <span class="string">' Expected: '</span> + <span class="variable">sys</span>.<span class="variable">inspect</span>(<span class="variable">res</span>.<span class="variable">body</span>) + <span class="string">'\n'</span>
+ + <span class="string">' Got: '</span> + <span class="variable">sys</span>.<span class="variable">inspect</span>(<span class="variable">response</span>.<span class="variable">body</span>)
+ );
+ }
+
+ <span class="comment">// Assert response status</span>
+ <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">status</span> === <span class="string">'number'</span>) {
+ <span class="variable">assert</span>.<span class="variable">equal</span>(
+ <span class="variable">response</span>.<span class="variable">statusCode</span>,
+ <span class="variable">status</span>,
+ <span class="variable">msg</span> + <span class="variable">colorize</span>(<span class="string">'Invalid response status code.\n'</span>
+ + <span class="string">' Expected: [green]{'</span> + <span class="variable">status</span> + <span class="string">'}\n'</span>
+ + <span class="string">' Got: [red]{'</span> + <span class="variable">response</span>.<span class="variable">statusCode</span> + <span class="string">'}'</span>)
+ );
+ }
+
+ <span class="comment">// Assert response headers</span>
+ <span class="keyword">if</span> (<span class="variable">res</span>.<span class="variable">headers</span>) {
+ <span class="keyword">var</span> <span class="variable">keys</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">res</span>.<span class="variable">headers</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">keys</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {
+ <span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">keys</span>[<span class="variable">i</span>],
+ <span class="variable">actual</span> = <span class="variable">response</span>.<span class="variable">headers</span>[<span class="variable">name</span>.<span class="variable">toLowerCase</span>()],
+ <span class="variable">expected</span> = <span class="variable">res</span>.<span class="variable">headers</span>[<span class="variable">name</span>];
+ <span class="variable">assert</span>.<span class="variable">equal</span>(
+ <span class="variable">actual</span>,
+ <span class="variable">expected</span>,
+ <span class="variable">msg</span> + <span class="variable">colorize</span>(<span class="string">'Invalid response header [bold]{'</span> + <span class="variable">name</span> + <span class="string">'}.\n'</span>
+ + <span class="string">' Expected: [green]{'</span> + <span class="variable">expected</span> + <span class="string">'}\n'</span>
+ + <span class="string">' Got: [red]{'</span> + <span class="variable">actual</span> + <span class="string">'}'</span>)
+ );
+ }
+ }
+
+ <span class="comment">// Callback</span>
+ <span class="variable">callback</span>(<span class="variable">response</span>);
+ });
+ });
+ <span class="variable">request</span>.<span class="variable">end</span>();
+};</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Pad the given string to the maximum width provided.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>param</strong>: <em>Number</em> width</p></li><li><p><strong>return</strong>: <em>String</em> </p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">lpad</span>(<span class="variable">str</span>, <span class="variable">width</span>) {
+ <span class="variable">str</span> = <span class="class">String</span>(<span class="variable">str</span>);
+ <span class="keyword">var</span> <span class="variable">n</span> = <span class="variable">width</span> - <span class="variable">str</span>.<span class="variable">length</span>;
+ <span class="keyword">if</span> (<span class="variable">n</span> &<span class="variable">lt</span>; <span class="number integer">1</span>) <span class="keyword">return</span> <span class="variable">str</span>;
+ <span class="keyword">while</span> (<span class="variable">n</span>--) <span class="variable">str</span> = <span class="string">' '</span> + <span class="variable">str</span>;
+ <span class="keyword">return</span> <span class="variable">str</span>;
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Pad the given string to the maximum width provided.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>param</strong>: <em>Number</em> width</p></li><li><p><strong>return</strong>: <em>String</em> </p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">rpad</span>(<span class="variable">str</span>, <span class="variable">width</span>) {
+ <span class="variable">str</span> = <span class="class">String</span>(<span class="variable">str</span>);
+ <span class="keyword">var</span> <span class="variable">n</span> = <span class="variable">width</span> - <span class="variable">str</span>.<span class="variable">length</span>;
+ <span class="keyword">if</span> (<span class="variable">n</span> &<span class="variable">lt</span>; <span class="number integer">1</span>) <span class="keyword">return</span> <span class="variable">str</span>;
+ <span class="keyword">while</span> (<span class="variable">n</span>--) <span class="variable">str</span> = <span class="variable">str</span> + <span class="string">' '</span>;
+ <span class="keyword">return</span> <span class="variable">str</span>;
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Report test coverage.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Object</em> cov</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">reportCoverage</span>(<span class="variable">cov</span>) {
+ <span class="variable">populateCoverage</span>(<span class="variable">cov</span>);
+ <span class="comment">// Stats</span>
+ <span class="variable">print</span>(<span class="string">'\n [bold]{Test Coverage}\n'</span>);
+ <span class="keyword">var</span> <span class="variable">sep</span> = <span class="string">' +------------------------------------------+----------+------+------+--------+'</span>,
+ <span class="variable">lastSep</span> = <span class="string">' +----------+------+------+--------+'</span>;
+ <span class="variable">sys</span>.<span class="variable">puts</span>(<span class="variable">sep</span>);
+ <span class="variable">sys</span>.<span class="variable">puts</span>(<span class="string">' | filename | coverage | LOC | SLOC | missed |'</span>);
+ <span class="variable">sys</span>.<span class="variable">puts</span>(<span class="variable">sep</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">name</span> <span class="keyword">in</span> <span class="variable">cov</span>) {
+ <span class="keyword">var</span> <span class="variable">file</span> = <span class="variable">cov</span>[<span class="variable">name</span>];
+ <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">file</span>)) {
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">rpad</span>(<span class="variable">name</span>, <span class="number integer">40</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">lpad</span>(<span class="variable">file</span>.<span class="variable">coverage</span>.<span class="variable">toFixed</span>(<span class="number integer">2</span>), <span class="number integer">8</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">lpad</span>(<span class="variable">file</span>.<span class="class">LOC</span>, <span class="number integer">4</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">lpad</span>(<span class="variable">file</span>.<span class="class">SLOC</span>, <span class="number integer">4</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">lpad</span>(<span class="variable">file</span>.<span class="variable">totalMisses</span>, <span class="number integer">6</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' |\n'</span>);
+ }
+ }
+ <span class="variable">sys</span>.<span class="variable">puts</span>(<span class="variable">sep</span>);
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' '</span> + <span class="variable">rpad</span>(<span class="string">''</span>, <span class="number integer">40</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">lpad</span>(<span class="variable">cov</span>.<span class="variable">coverage</span>.<span class="variable">toFixed</span>(<span class="number integer">2</span>), <span class="number integer">8</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">lpad</span>(<span class="variable">cov</span>.<span class="class">LOC</span>, <span class="number integer">4</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">lpad</span>(<span class="variable">cov</span>.<span class="class">SLOC</span>, <span class="number integer">4</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' | '</span> + <span class="variable">lpad</span>(<span class="variable">cov</span>.<span class="variable">totalMisses</span>, <span class="number integer">6</span>));
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">' |\n'</span>);
+ <span class="variable">sys</span>.<span class="variable">puts</span>(<span class="variable">lastSep</span>);
+ <span class="comment">// Source</span>
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">name</span> <span class="keyword">in</span> <span class="variable">cov</span>) {
+ <span class="keyword">if</span> (<span class="variable">name</span>.<span class="variable">match</span>(<span class="regexp">/\.js$/</span>)) {
+ <span class="keyword">var</span> <span class="variable">file</span> = <span class="variable">cov</span>[<span class="variable">name</span>];
+ <span class="variable">print</span>(<span class="string">'\n [bold]{'</span> + <span class="variable">name</span> + <span class="string">'}:'</span>);
+ <span class="variable">print</span>(<span class="variable">file</span>.<span class="variable">source</span>);
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">'\n'</span>);
+ }
+ }
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Populate code coverage data.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Object</em> cov</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">populateCoverage</span>(<span class="variable">cov</span>) {
+ <span class="variable">cov</span>.<span class="class">LOC</span> =
+ <span class="variable">cov</span>.<span class="class">SLOC</span> =
+ <span class="variable">cov</span>.<span class="variable">totalFiles</span> =
+ <span class="variable">cov</span>.<span class="variable">totalHits</span> =
+ <span class="variable">cov</span>.<span class="variable">totalMisses</span> =
+ <span class="variable">cov</span>.<span class="variable">coverage</span> = <span class="number integer">0</span>;
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">name</span> <span class="keyword">in</span> <span class="variable">cov</span>) {
+ <span class="keyword">var</span> <span class="variable">file</span> = <span class="variable">cov</span>[<span class="variable">name</span>];
+ <span class="keyword">if</span> (<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">file</span>)) {
+ <span class="comment">// Stats</span>
+ ++<span class="variable">cov</span>.<span class="variable">totalFiles</span>;
+ <span class="variable">cov</span>.<span class="variable">totalHits</span> += <span class="variable">file</span>.<span class="variable">totalHits</span> = <span class="variable">coverage</span>(<span class="variable">file</span>, <span class="variable">true</span>);
+ <span class="variable">cov</span>.<span class="variable">totalMisses</span> += <span class="variable">file</span>.<span class="variable">totalMisses</span> = <span class="variable">coverage</span>(<span class="variable">file</span>, <span class="variable">false</span>);
+ <span class="variable">file</span>.<span class="variable">totalLines</span> = <span class="variable">file</span>.<span class="variable">totalHits</span> + <span class="variable">file</span>.<span class="variable">totalMisses</span>;
+ <span class="variable">cov</span>.<span class="class">SLOC</span> += <span class="variable">file</span>.<span class="class">SLOC</span> = <span class="variable">file</span>.<span class="variable">totalLines</span>;
+ <span class="keyword">if</span> (!<span class="variable">file</span>.<span class="variable">source</span>) <span class="variable">file</span>.<span class="variable">source</span> = [];
+ <span class="variable">cov</span>.<span class="class">LOC</span> += <span class="variable">file</span>.<span class="class">LOC</span> = <span class="variable">file</span>.<span class="variable">source</span>.<span class="variable">length</span>;
+ <span class="variable">file</span>.<span class="variable">coverage</span> = (<span class="variable">file</span>.<span class="variable">totalHits</span> / <span class="variable">file</span>.<span class="variable">totalLines</span>) * <span class="number integer">100</span>;
+ <span class="comment">// Source</span>
+ <span class="keyword">var</span> <span class="variable">width</span> = <span class="variable">file</span>.<span class="variable">source</span>.<span class="variable">length</span>.<span class="variable">toString</span>().<span class="variable">length</span>;
+ <span class="variable">file</span>.<span class="variable">source</span> = <span class="variable">file</span>.<span class="variable">source</span>.<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">line</span>, <span class="variable">i</span>){
+ ++<span class="variable">i</span>;
+ <span class="keyword">var</span> <span class="variable">hits</span> = <span class="variable">file</span>[<span class="variable">i</span>] === <span class="number integer">0</span> ? <span class="number integer">0</span> : (<span class="variable">file</span>[<span class="variable">i</span>] || <span class="string">' '</span>);
+ <span class="keyword">if</span> (!<span class="variable">boring</span>) {
+ <span class="keyword">if</span> (<span class="variable">hits</span> === <span class="number integer">0</span>) {
+ <span class="variable">hits</span> = <span class="string">'\x1b[31m'</span> + <span class="variable">hits</span> + <span class="string">'\x1b[0m'</span>;
+ <span class="variable">line</span> = <span class="string">'\x1b[41m'</span> + <span class="variable">line</span> + <span class="string">'\x1b[0m'</span>;
+ } <span class="keyword">else</span> {
+ <span class="variable">hits</span> = <span class="string">'\x1b[32m'</span> + <span class="variable">hits</span> + <span class="string">'\x1b[0m'</span>;
+ }
+ }
+ <span class="keyword">return</span> <span class="string">'\n '</span> + <span class="variable">lpad</span>(<span class="variable">i</span>, <span class="variable">width</span>) + <span class="string">' | '</span> + <span class="variable">hits</span> + <span class="string">' | '</span> + <span class="variable">line</span>;
+ }).<span class="variable">join</span>(<span class="string">''</span>);
+ }
+ }
+ <span class="variable">cov</span>.<span class="variable">coverage</span> = (<span class="variable">cov</span>.<span class="variable">totalHits</span> / <span class="variable">cov</span>.<span class="class">SLOC</span>) * <span class="number integer">100</span>;
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Total coverage for the given file data.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Array</em> data</p></li><li><p><strong>return</strong>: <em>Type</em> </p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">coverage</span>(<span class="variable">data</span>, <span class="variable">val</span>) {
+ <span class="keyword">var</span> <span class="variable">n</span> = <span class="number integer">0</span>;
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">data</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {
+ <span class="keyword">if</span> (<span class="variable">data</span>[<span class="variable">i</span>] !== <span class="variable">undefined</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">data</span>[<span class="variable">i</span>] == <span class="variable">val</span>) ++<span class="variable">n</span>;
+ }
+ <span class="keyword">return</span> <span class="variable">n</span>;
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Run the given test <code>files</code>, or try <em>test/*</em>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Array</em> files</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">run</span>(<span class="variable">files</span>) {
+ <span class="keyword">if</span> (!<span class="variable">files</span>.<span class="variable">length</span>) {
+ <span class="keyword">try</span> {
+ <span class="variable">files</span> = <span class="variable">fs</span>.<span class="variable">readdirSync</span>(<span class="string">'test'</span>).<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">file</span>){
+ <span class="keyword">return</span> <span class="string">'test/'</span> + <span class="variable">file</span>;
+ });
+ } <span class="keyword">catch</span> (<span class="variable">err</span>) {
+ <span class="variable">print</span>(<span class="string">'\n failed to load tests in [bold]{./test}\n'</span>);
+ ++<span class="variable">failures</span>;
+ <span class="variable">process</span>.<span class="variable">exit</span>(<span class="number integer">1</span>);
+ }
+ }
+ <span class="keyword">if</span> (<span class="variable">watch</span>) <span class="variable">watchFiles</span>(<span class="variable">files</span>);
+ <span class="variable">runFiles</span>(<span class="variable">files</span>);
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Show the cursor when <code>show</code> is true, otherwise hide it.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Boolean</em> show</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">cursor</span>(<span class="variable">show</span>) {
+ <span class="keyword">if</span> (<span class="variable">show</span>) {
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">'\x1b[?25h'</span>);
+ } <span class="keyword">else</span> {
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">'\x1b[?25l'</span>);
+ }
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Run the given test <code>files</code>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Array</em> files</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">runFiles</span>(<span class="variable">files</span>) {
+ <span class="variable">files</span>.<span class="variable">forEach</span>(<span class="variable">runFile</span>);
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Run tests for the given <code>file</code>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> file</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">runFile</span>(<span class="variable">file</span>) {
+ <span class="keyword">if</span> (<span class="variable">file</span>.<span class="variable">match</span>(<span class="regexp">/\.js$/</span>)) {
+ <span class="keyword">var</span> <span class="variable">title</span> = <span class="variable">path</span>.<span class="variable">basename</span>(<span class="variable">file</span>),
+ <span class="variable">file</span> = <span class="variable">path</span>.<span class="variable">join</span>(<span class="variable">cwd</span>, <span class="variable">file</span>),
+ <span class="variable">mod</span> = <span class="variable">require</span>(<span class="variable">file</span>.<span class="variable">replace</span>(<span class="regexp">/\.js$/</span>, <span class="string">''</span>));
+ (<span class="keyword">function</span> <span class="variable">check</span>(){
+ <span class="keyword">var</span> <span class="variable">len</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">mod</span>).<span class="variable">length</span>;
+ <span class="keyword">if</span> (<span class="variable">len</span>) {
+ <span class="variable">runSuite</span>(<span class="variable">title</span>, <span class="variable">mod</span>);
+ } <span class="keyword">else</span> {
+ <span class="variable">setTimeout</span>(<span class="variable">check</span>, <span class="number integer">20</span>);
+ }
+ })();
+ }
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Clear the module cache for the given <code>file</code>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> file</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">clearCache</span>(<span class="variable">file</span>) {
+ <span class="keyword">var</span> <span class="variable">keys</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">module</span>.<span class="variable">moduleCache</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">keys</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {
+ <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">keys</span>[<span class="variable">i</span>];
+ <span class="keyword">if</span> (<span class="variable">key</span>.<span class="variable">indexOf</span>(<span class="variable">file</span>) === <span class="variable">key</span>.<span class="variable">length</span> - <span class="variable">file</span>.<span class="variable">length</span>) {
+ <span class="keyword">delete</span> <span class="variable">module</span>.<span class="variable">moduleCache</span>[<span class="variable">key</span>];
+ }
+ }
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Watch the given <code>files</code> for changes.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>Array</em> files</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">watchFiles</span>(<span class="variable">files</span>) {
+ <span class="keyword">var</span> <span class="variable">p</span> = <span class="number integer">0</span>,
+ <span class="variable">c</span> = [<span class="string">'â–« '</span>, <span class="string">'â–«â–« '</span>, <span class="string">'â–«â–«â–« '</span>, <span class="string">' â–«â–«â–«'</span>,
+ <span class="string">' â–«â–«'</span>, <span class="string">' â–«'</span>, <span class="string">' â–«'</span>, <span class="string">' â–«â–«'</span>,
+ <span class="string">'â–«â–«â–« '</span>, <span class="string">'â–«â–« '</span>, <span class="string">'â–« '</span>],
+ <span class="variable">l</span> = <span class="variable">c</span>.<span class="variable">length</span>;
+ <span class="variable">cursor</span>(<span class="variable">false</span>);
+ <span class="variable">setInterval</span>(<span class="keyword">function</span>(){
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="variable">colorize</span>(<span class="string">' [green]{'</span> + <span class="variable">c</span>[<span class="variable">p</span>++ % <span class="variable">l</span>] + <span class="string">'} watching\r'</span>));
+ }, <span class="number integer">100</span>);
+ <span class="variable">files</span>.<span class="variable">forEach</span>(<span class="keyword">function</span>(<span class="variable">file</span>){
+ <span class="variable">fs</span>.<span class="variable">watchFile</span>(<span class="variable">file</span>, { <span class="variable">interval</span>: <span class="number integer">100</span> }, <span class="keyword">function</span>(<span class="variable">curr</span>, <span class="variable">prev</span>){
+ <span class="keyword">if</span> (<span class="variable">curr</span>.<span class="variable">mtime</span> &<span class="variable">gt</span>; <span class="variable">prev</span>.<span class="variable">mtime</span>) {
+ <span class="variable">print</span>(<span class="string">' [yellow]{â—¦} '</span> + <span class="variable">file</span>);
+ <span class="variable">clearCache</span>(<span class="variable">file</span>);
+ <span class="variable">runFile</span>(<span class="variable">file</span>);
+ }
+ });
+ });
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Report <code>err</code> for the given <code>test</code> and <code>suite</code>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> suite</p></li><li><p><strong>param</strong>: <em>String</em> test</p></li><li><p><strong>param</strong>: <em>Error</em> err</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">error</span>(<span class="variable">suite</span>, <span class="variable">test</span>, <span class="variable">err</span>) {
+ ++<span class="variable">failures</span>;
+ <span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">err</span>.<span class="variable">name</span>,
+ <span class="variable">stack</span> = <span class="variable">err</span>.<span class="variable">stack</span>.<span class="variable">replace</span>(<span class="variable">err</span>.<span class="variable">name</span>, <span class="string">''</span>),
+ <span class="keyword">label</span> = <span class="variable">test</span> === <span class="string">'uncaught'</span>
+ ? <span class="variable">test</span>
+ : <span class="variable">suite</span> + <span class="string">' '</span> + <span class="variable">test</span>;
+ <span class="variable">print</span>(<span class="string">'\n [bold]{'</span> + <span class="keyword">label</span> + <span class="string">'}: [red]{'</span> + <span class="variable">name</span> + <span class="string">'}'</span> + <span class="variable">stack</span> + <span class="string">'\n'</span>);
+ <span class="keyword">if</span> (<span class="variable">watch</span>) <span class="variable">notify</span>(<span class="keyword">label</span> + <span class="string">' failed'</span>);
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Run the given tests.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> title</p></li><li><p><strong>param</strong>: <em>Object</em> tests</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">dots</span> = <span class="number integer">0</span>;
+<span class="keyword">function</span> <span class="variable">runSuite</span>(<span class="variable">title</span>, <span class="variable">tests</span>) {
+ <span class="comment">// Keys</span>
+ <span class="keyword">var</span> <span class="variable">keys</span> = <span class="variable">only</span>.<span class="variable">length</span>
+ ? <span class="variable">only</span>.<span class="variable">slice</span>(<span class="number integer">0</span>)
+ : <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">tests</span>);
+
+ <span class="comment">// Setup</span>
+ <span class="keyword">var</span> <span class="variable">setup</span> = <span class="variable">tests</span>.<span class="variable">setup</span> || <span class="keyword">function</span>(<span class="variable">fn</span>){ <span class="variable">fn</span>(); };
+
+ <span class="comment">// Iterate tests</span>
+ (<span class="keyword">function</span> <span class="variable">next</span>(){
+ <span class="keyword">if</span> (<span class="variable">keys</span>.<span class="variable">length</span>) {
+ <span class="keyword">var</span> <span class="variable">key</span>,
+ <span class="variable">test</span> = <span class="variable">tests</span>[<span class="variable">key</span> = <span class="variable">keys</span>.<span class="variable">shift</span>()];
+ <span class="comment">// Non-tests</span>
+ <span class="keyword">if</span> (<span class="variable">key</span> === <span class="string">'setup'</span>) <span class="keyword">return</span> <span class="variable">next</span>();
+
+ <span class="comment">// Run test</span>
+ <span class="keyword">if</span> (<span class="variable">test</span>) {
+ <span class="keyword">try</span> {
+ ++<span class="variable">testcount</span>;
+ <span class="variable">assert</span>.<span class="variable">testTitle</span> = <span class="variable">key</span>;
+ <span class="keyword">if</span> (<span class="variable">serial</span>) {
+ <span class="keyword">if</span> (!<span class="variable">watch</span>) {
+ <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">'.'</span>);
+ <span class="keyword">if</span> (++<span class="variable">dots</span> % <span class="number integer">25</span> === <span class="number integer">0</span>) <span class="variable">sys</span>.<span class="variable">print</span>(<span class="string">'\n'</span>);
+ }
+ <span class="variable">setup</span>(<span class="keyword">function</span>(){
+ <span class="keyword">if</span> (<span class="variable">test</span>.<span class="variable">length</span> &<span class="variable">lt</span>; <span class="number integer">2</span>) {
+ <span class="variable">test</span>(<span class="variable">assert</span>);
+ <span class="variable">next</span>();
+ } <span class="keyword">else</span> {
+ <span class="keyword">var</span> <span class="variable">id</span> = <span class="variable">setTimeout</span>(<span class="keyword">function</span>(){
+ <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(&<span class="variable">quot</span>;<span class="string">'" + key + "'</span> <span class="variable">timed</span> <span class="variable">out</span>&<span class="variable">quot</span>;);
+ }, <span class="number integer">2000</span>);
+ <span class="variable">test</span>(<span class="variable">assert</span>, <span class="keyword">function</span>(){
+ <span class="variable">clearTimeout</span>(<span class="variable">id</span>);
+ <span class="variable">next</span>();
+ });
+ }
+ });
+ } <span class="keyword">else</span> {
+ <span class="variable">test</span>(<span class="variable">assert</span>, <span class="keyword">function</span>(<span class="variable">fn</span>){
+ <span class="variable">process</span>.<span class="variable">addListener</span>(<span class="string">'beforeExit'</span>, <span class="keyword">function</span>(){
+ <span class="keyword">try</span> {
+ <span class="variable">fn</span>();
+ } <span class="keyword">catch</span> (<span class="variable">err</span>) {
+ <span class="variable">error</span>(<span class="variable">title</span>, <span class="variable">key</span>, <span class="variable">err</span>);
+ }
+ });
+ });
+ }
+ } <span class="keyword">catch</span> (<span class="variable">err</span>) {
+ <span class="variable">error</span>(<span class="variable">title</span>, <span class="variable">key</span>, <span class="variable">err</span>);
+ }
+ }
+ <span class="keyword">if</span> (!<span class="variable">serial</span>) <span class="variable">next</span>();
+ }
+ })();
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Report exceptions.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">report</span>() {
+ <span class="variable">process</span>.<span class="variable">emit</span>(<span class="string">'beforeExit'</span>);
+ <span class="keyword">if</span> (<span class="variable">failures</span>) {
+ <span class="variable">print</span>(<span class="string">'\n [bold]{Failures}: [red]{'</span> + <span class="variable">failures</span> + <span class="string">'}\n\n'</span>);
+ <span class="variable">notify</span>(<span class="string">'Failures: '</span> + <span class="variable">failures</span>);
+ } <span class="keyword">else</span> {
+ <span class="keyword">if</span> (<span class="variable">serial</span>) <span class="variable">print</span>(<span class="string">''</span>);
+ <span class="variable">print</span>(<span class="string">'\n [green]{100%} '</span> + <span class="variable">testcount</span> + <span class="string">' tests\n'</span>);
+ <span class="variable">notify</span>(<span class="string">'100% ok'</span>);
+ }
+ <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">_</span>$<span class="variable">jscoverage</span> === <span class="string">'object'</span>) {
+ <span class="variable">reportCoverage</span>(<span class="variable">_</span>$<span class="variable">jscoverage</span>);
+ }
+}</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Growl notify the given <code>msg</code>.</p>
+
+<h2></h2>
+
+<ul><li><p><strong>param</strong>: <em>String</em> msg</p></li></ul>
+</td>
+<td class="code">
+<pre><code><span class="keyword">function</span> <span class="variable">notify</span>(<span class="variable">msg</span>) {
+ <span class="keyword">if</span> (<span class="variable">growl</span>) {
+ <span class="variable">childProcess</span>.<span class="variable">exec</span>(<span class="string">'growlnotify -name Expresso -m "'</span> + <span class="variable">msg</span> + <span class="string">'"'</span>);
+ }
+}
+
+<span class="comment">// Report uncaught exceptions</span>
+
+<span class="variable">process</span>.<span class="variable">addListener</span>(<span class="string">'uncaughtException'</span>, <span class="keyword">function</span>(<span class="variable">err</span>){
+ <span class="variable">error</span>(<span class="string">'uncaught'</span>, <span class="string">'uncaught'</span>, <span class="variable">err</span>);
+});
+
+<span class="comment">// Show cursor</span>
+
+[<span class="string">'INT'</span>, <span class="string">'TERM'</span>, <span class="string">'QUIT'</span>].<span class="variable">forEach</span>(<span class="keyword">function</span>(<span class="variable">sig</span>){
+ <span class="variable">process</span>.<span class="variable">addListener</span>(<span class="string">'SIG'</span> + <span class="variable">sig</span>, <span class="keyword">function</span>(){
+ <span class="variable">cursor</span>(<span class="variable">true</span>);
+ <span class="variable">process</span>.<span class="variable">exit</span>(<span class="number integer">1</span>);
+ });
+});
+
+<span class="comment">// Report test coverage when available</span>
+<span class="comment">// and emit "beforeExit" event to perform</span>
+<span class="comment">// final assertions</span>
+
+<span class="keyword">var</span> <span class="variable">orig</span> = <span class="variable">process</span>.<span class="variable">emit</span>;
+<span class="variable">process</span>.<span class="variable">emit</span> = <span class="keyword">function</span>(<span class="variable">event</span>){
+ <span class="keyword">if</span> (<span class="variable">event</span> === <span class="string">'exit'</span>) {
+ <span class="variable">report</span>();
+ <span class="variable">process</span>.<span class="variable">reallyExit</span>(<span class="variable">failures</span>);
+ }
+ <span class="variable">orig</span>.<span class="variable">apply</span>(<span class="this">this</span>, <span class="variable">arguments</span>);
+};
+
+<span class="comment">// Run test files</span>
+
+<span class="keyword">if</span> (!<span class="variable">defer</span>) <span class="variable">run</span>(<span class="variable">files</span>);
+</code></pre>
+</td>
+</tr> </body>
+</html></tbody></table>
\ No newline at end of file
--- /dev/null
+<html>
+ <head>
+ <title>Expresso - TDD Framework For Node</title>
+ <style>
+ body {
+ font: 13px/1.4 "Helvetica", "Lucida Grande", Arial, sans-serif;
+ text-align: center;
+ }
+ #ribbon {
+ position: absolute;
+ top: 0;
+ right: 0;
+ z-index: 10;
+ }
+ #wrapper {
+ margin: 0 auto;
+ padding: 50px 80px;
+ width: 700px;
+ text-align: left;
+ }
+ h1, h2, h3 {
+ margin: 25px 0 15px 0;
+ }
+ h1 {
+ font-size: 35px;
+ }
+ pre {
+ margin: 0 5px;
+ padding: 15px;
+ border: 1px solid #eee;
+ }
+ a {
+ color: #00aaff;
+ }
+ </style>
+ </head>
+ <body>
+ <a href="http://github.com/visionmedia/expresso">
+ <img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" />
+ </a>
+ <div id="wrapper">
+ <h1>Expresso</h1>
+<div class='mp'>
+<p><a href="http://github.com/visionmedia/expresso">Expresso</a> is a JavaScript <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> framework written for <a href="http://nodejs.org">nodejs</a>. Expresso is extremely fast, and is packed with features such as additional assertion methods, code coverage reporting, CI support, and more.</p>
+
+<h2 id="Features">Features</h2>
+
+<ul>
+<li>light-weight</li>
+<li>intuitive async support</li>
+<li>intuitive test runner executable</li>
+<li>test coverage support and reporting via <a href="http://github.com/visionmedia/node-jscoverage">node-jscoverage</a></li>
+<li>uses and extends the core <em>assert</em> module</li>
+<li><code>assert.eql()</code> alias of <code>assert.deepEqual()</code></li>
+<li><code>assert.response()</code> http response utility</li>
+<li><code>assert.includes()</code></li>
+<li><code>assert.isNull()</code></li>
+<li><code>assert.isUndefined()</code></li>
+<li><code>assert.isNotNull()</code></li>
+<li><code>assert.isDefined()</code></li>
+<li><code>assert.match()</code></li>
+<li><code>assert.length()</code></li>
+</ul>
+
+
+<h2 id="Installation">Installation</h2>
+
+<p>To install both expresso <em>and</em> node-jscoverage run
+the command below, which will first compile node-jscoverage:</p>
+
+<pre><code>$ make install
+</code></pre>
+
+<p>To install expresso alone without coverage reporting run:</p>
+
+<pre><code>$ make install-expresso
+</code></pre>
+
+<p>Install via npm:</p>
+
+<pre><code>$ npm install expresso
+</code></pre>
+
+<h2 id="Examples">Examples</h2>
+
+<p>To define tests we simply export several functions:</p>
+
+<pre><code>exports['test String#length'] = function(assert){
+ assert.equal(6, 'foobar'.length);
+};
+</code></pre>
+
+<p>Alternatively for large numbers of tests you may want to
+export your own object containing the tests, however this
+is essentially the as above:</p>
+
+<pre><code>module.exports = {
+ 'test String#length': function(assert){
+ assert.equal(6, 'foobar'.length);
+ }
+};
+</code></pre>
+
+<p>If you prefer not to use quoted keys:</p>
+
+<pre><code>exports.testsStringLength = function(assert){
+ assert.equal(6, 'foobar'.length);
+};
+</code></pre>
+
+<p>The second argument passed to each callback is <em>beforeExit</em>,
+which is typically used to assert that callbacks have been
+invoked.</p>
+
+<pre><code>exports.testAsync = function(assert, beforeExit){
+ var n = 0;
+ setTimeout(function(){
+ ++n;
+ assert.ok(true);
+ }, 200);
+ setTimeout(function(){
+ ++n;
+ assert.ok(true);
+ }, 200);
+ beforeExit(function(){
+ assert.equal(2, n, 'Ensure both timeouts are called');
+ });
+};
+</code></pre>
+
+<h2 id="Assert-Utilities">Assert Utilities</h2>
+
+<h3 id="assert-isNull-val-msg-">assert.isNull(val[, msg])</h3>
+
+<p>Asserts that the given <em>val</em> is <em>null</em>.</p>
+
+<pre><code>assert.isNull(null);
+</code></pre>
+
+<h3 id="assert-isNotNull-val-msg-">assert.isNotNull(val[, msg])</h3>
+
+<p>Asserts that the given <em>val</em> is not <em>null</em>.</p>
+
+<pre><code>assert.isNotNull(undefined);
+assert.isNotNull(false);
+</code></pre>
+
+<h3 id="assert-isUndefined-val-msg-">assert.isUndefined(val[, msg])</h3>
+
+<p>Asserts that the given <em>val</em> is <em>undefined</em>.</p>
+
+<pre><code>assert.isUndefined(undefined);
+</code></pre>
+
+<h3 id="assert-isDefined-val-msg-">assert.isDefined(val[, msg])</h3>
+
+<p>Asserts that the given <em>val</em> is not <em>undefined</em>.</p>
+
+<pre><code>assert.isDefined(null);
+assert.isDefined(false);
+</code></pre>
+
+<h3 id="assert-match-str-regexp-msg-">assert.match(str, regexp[, msg])</h3>
+
+<p>Asserts that the given <em>str</em> matches <em>regexp</em>.</p>
+
+<pre><code>assert.match('foobar', /^foo(bar)?/);
+assert.match('foo', /^foo(bar)?/);
+</code></pre>
+
+<h3 id="assert-length-val-n-msg-">assert.length(val, n[, msg])</h3>
+
+<p>Assert that the given <em>val</em> has a length of <em>n</em>.</p>
+
+<pre><code>assert.length([1,2,3], 3);
+assert.length('foo', 3);
+</code></pre>
+
+<h3 id="assert-type-obj-type-msg-">assert.type(obj, type[, msg])</h3>
+
+<p>Assert that the given <em>obj</em> is typeof <em>type</em>.</p>
+
+<pre><code>assert.type(3, 'number');
+</code></pre>
+
+<h3 id="assert-eql-a-b-msg-">assert.eql(a, b[, msg])</h3>
+
+<p>Assert that object <em>b</em> is equal to object <em>a</em>. This is an
+alias for the core <em>assert.deepEqual()</em> method which does complex
+comparisons, opposed to <em>assert.equal()</em> which uses <em>==</em>.</p>
+
+<pre><code>assert.eql('foo', 'foo');
+assert.eql([1,2], [1,2]);
+assert.eql({ foo: 'bar' }, { foo: 'bar' });
+</code></pre>
+
+<h3 id="assert-includes-obj-val-msg-">assert.includes(obj, val[, msg])</h3>
+
+<p>Assert that <em>obj</em> is within <em>val</em>. This method supports <em>Array_s
+and </em>Strings_s.</p>
+
+<pre><code>assert.includes([1,2,3], 3);
+assert.includes('foobar', 'foo');
+assert.includes('foobar', 'bar');
+</code></pre>
+
+<h3 id="assert-response-server-req-res-fn-msg-fn-">assert.response(server, req, res|fn[, msg|fn])</h3>
+
+<p>Performs assertions on the given <em>server</em>, which should <em>not</em> call
+listen(), as this is handled internally by expresso and the server
+is killed after all responses have completed. This method works with
+any <em>http.Server</em> instance, so <em>Connect</em> and <em>Express</em> servers will work
+as well.</p>
+
+<p>The <em>req</em> object may contain:</p>
+
+<ul>
+<li><em>url</em> request url</li>
+<li><em>timeout</em> timeout in milliseconds</li>
+<li><em>method</em> HTTP method</li>
+<li><em>data</em> request body</li>
+<li><em>headers</em> headers object</li>
+</ul>
+
+
+<p>The <em>res</em> object may be a callback function which
+receives the response for assertions, or an object
+which is then used to perform several assertions
+on the response with the following properties:</p>
+
+<ul>
+<li><em>body</em> assert response body</li>
+<li><em>status</em> assert response status code</li>
+<li><em>header</em> assert that all given headers match (unspecified are ignored)</li>
+</ul>
+
+
+<p>When providing <em>res</em> you may then also pass a callback function
+as the fourth argument for additional assertions.</p>
+
+<p>Below are some examples:</p>
+
+<pre><code>assert.response(server, {
+ url: '/', timeout: 500
+}, {
+ body: 'foobar'
+});
+
+assert.response(server, {
+ url: '/',
+ method: 'GET'
+},{
+ body: '{"name":"tj"}',
+ status: 200,
+ headers: {
+ 'Content-Type': 'application/json; charset=utf8',
+ 'X-Foo': 'bar'
+ }
+});
+
+assert.response(server, {
+ url: '/foo',
+ method: 'POST',
+ data: 'bar baz'
+},{
+ body: '/foo bar baz',
+ status: 200
+}, 'Test POST');
+
+assert.response(server, {
+ url: '/foo',
+ method: 'POST',
+ data: 'bar baz'
+},{
+ body: '/foo bar baz',
+ status: 200
+}, function(res){
+ // All done, do some more tests if needed
+});
+
+assert.response(server, {
+ url: '/'
+}, function(res){
+ assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback');
+});
+</code></pre>
+
+<h2 id="expresso-1-">expresso(1)</h2>
+
+<p>To run a single test suite (file) run:</p>
+
+<pre><code>$ expresso test/a.test.js
+</code></pre>
+
+<p>To run several suites we may simply append another:</p>
+
+<pre><code>$ expresso test/a.test.js test/b.test.js
+</code></pre>
+
+<p>We can also pass a whitelist of tests to run within all suites:</p>
+
+<pre><code>$ expresso --only "foo()" --only "bar()"
+</code></pre>
+
+<p>Or several with one call:</p>
+
+<pre><code>$ expresso --only "foo(), bar()"
+</code></pre>
+
+<p>Globbing is of course possible as well:</p>
+
+<pre><code>$ expresso test/*
+</code></pre>
+
+<p>When expresso is called without any files, <em>test/*</em> is the default,
+so the following is equivalent to the command above:</p>
+
+<pre><code>$ expresso
+</code></pre>
+
+<p>If you wish to unshift a path to <code>require.paths</code> before
+running tests, you may use the <code>-I</code> or <code>--include</code> flag.</p>
+
+<pre><code>$ expresso --include lib test/*
+</code></pre>
+
+<p>The previous example is typically what I would recommend, since expresso
+supports test coverage via <a href="http://github.com/visionmedia/node-jscoverage">node-jscoverage</a> (bundled with expresso),
+so you will need to expose an instrumented version of you library.</p>
+
+<p>To instrument your library, simply run <a href="http://github.com/visionmedia/node-jscoverage">node-jscoverage</a>,
+passing the <em>src</em> and <em>dest</em> directories:</p>
+
+<pre><code>$ node-jscoverage lib lib-cov
+</code></pre>
+
+<p>Now we can run our tests again, using the <em>lib-cov</em> directory that has been
+instrumented with coverage statements:</p>
+
+<pre><code>$ expresso -I lib-cov test/*
+</code></pre>
+
+<p>The output will look similar to below, depending on your test coverage of course :)</p>
+
+<p><img src="http://dl.dropbox.com/u/6396913/cov.png" alt="node coverage" /></p>
+
+<p>To make this process easier expresso has the <em>-c</em> or <em>--cov</em> which essentially
+does the same as the two commands above. The following two commands will
+run the same tests, however one will auto-instrument, and unshift <em>lib-cov</em>,
+and the other will run tests normally:</p>
+
+<pre><code>$ expresso -I lib test/*
+$ expresso -I lib --cov test/*
+</code></pre>
+
+<p>Currently coverage is bound to the <em>lib</em> directory, however in the
+future <code>--cov</code> will most likely accept a path.</p>
+
+<h2 id="Async-Exports">Async Exports</h2>
+
+<p>Sometimes it is useful to postpone running of tests until a callback or event has fired, currently the <em>exports.foo = function(){};</em> syntax is supported for this:</p>
+
+<pre><code>setTimeout(function(){
+ exports['test async exports'] = function(assert){
+ assert.ok('wahoo');
+ };
+}, 100);
+</code></pre>
+
+</div>
+ </div>
+ </body>
+</html>
\ No newline at end of file
--- /dev/null
+
+[Expresso](http://github.com/visionmedia/expresso) is a JavaScript [TDD](http://en.wikipedia.org/wiki/Test-driven_development) framework written for [nodejs](http://nodejs.org). Expresso is extremely fast, and is packed with features such as additional assertion methods, code coverage reporting, CI support, and more.
+
+## Features
+
+ - light-weight
+ - intuitive async support
+ - intuitive test runner executable
+ - test coverage support and reporting via [node-jscoverage](http://github.com/visionmedia/node-jscoverage)
+ - uses and extends the core _assert_ module
+ - `assert.eql()` alias of `assert.deepEqual()`
+ - `assert.response()` http response utility
+ - `assert.includes()`
+ - `assert.isNull()`
+ - `assert.isUndefined()`
+ - `assert.isNotNull()`
+ - `assert.isDefined()`
+ - `assert.match()`
+ - `assert.length()`
+
+## Installation
+
+To install both expresso _and_ node-jscoverage run
+the command below, which will first compile node-jscoverage:
+
+ $ make install
+
+To install expresso alone without coverage reporting run:
+
+ $ make install-expresso
+
+Install via npm:
+
+ $ npm install expresso
+
+## Examples
+
+To define tests we simply export several functions:
+
+ exports['test String#length'] = function(assert){
+ assert.equal(6, 'foobar'.length);
+ };
+
+Alternatively for large numbers of tests you may want to
+export your own object containing the tests, however this
+is essentially the as above:
+
+ module.exports = {
+ 'test String#length': function(assert){
+ assert.equal(6, 'foobar'.length);
+ }
+ };
+
+If you prefer not to use quoted keys:
+
+ exports.testsStringLength = function(assert){
+ assert.equal(6, 'foobar'.length);
+ };
+
+The second argument passed to each callback is _beforeExit_,
+which is typically used to assert that callbacks have been
+invoked.
+
+ exports.testAsync = function(assert, beforeExit){
+ var n = 0;
+ setTimeout(function(){
+ ++n;
+ assert.ok(true);
+ }, 200);
+ setTimeout(function(){
+ ++n;
+ assert.ok(true);
+ }, 200);
+ beforeExit(function(){
+ assert.equal(2, n, 'Ensure both timeouts are called');
+ });
+ };
+
+## Assert Utilities
+
+### assert.isNull(val[, msg])
+
+Asserts that the given _val_ is _null_.
+
+ assert.isNull(null);
+
+### assert.isNotNull(val[, msg])
+
+Asserts that the given _val_ is not _null_.
+
+ assert.isNotNull(undefined);
+ assert.isNotNull(false);
+
+### assert.isUndefined(val[, msg])
+
+Asserts that the given _val_ is _undefined_.
+
+ assert.isUndefined(undefined);
+
+### assert.isDefined(val[, msg])
+
+Asserts that the given _val_ is not _undefined_.
+
+ assert.isDefined(null);
+ assert.isDefined(false);
+
+### assert.match(str, regexp[, msg])
+
+Asserts that the given _str_ matches _regexp_.
+
+ assert.match('foobar', /^foo(bar)?/);
+ assert.match('foo', /^foo(bar)?/);
+
+### assert.length(val, n[, msg])
+
+Assert that the given _val_ has a length of _n_.
+
+ assert.length([1,2,3], 3);
+ assert.length('foo', 3);
+
+### assert.type(obj, type[, msg])
+
+Assert that the given _obj_ is typeof _type_.
+
+ assert.type(3, 'number');
+
+### assert.eql(a, b[, msg])
+
+Assert that object _b_ is equal to object _a_. This is an
+alias for the core _assert.deepEqual()_ method which does complex
+comparisons, opposed to _assert.equal()_ which uses _==_.
+
+ assert.eql('foo', 'foo');
+ assert.eql([1,2], [1,2]);
+ assert.eql({ foo: 'bar' }, { foo: 'bar' });
+
+### assert.includes(obj, val[, msg])
+
+Assert that _obj_ is within _val_. This method supports _Array_s
+and _Strings_s.
+
+ assert.includes([1,2,3], 3);
+ assert.includes('foobar', 'foo');
+ assert.includes('foobar', 'bar');
+
+### assert.response(server, req, res|fn[, msg|fn])
+
+Performs assertions on the given _server_, which should _not_ call
+listen(), as this is handled internally by expresso and the server
+is killed after all responses have completed. This method works with
+any _http.Server_ instance, so _Connect_ and _Express_ servers will work
+as well.
+
+The _req_ object may contain:
+
+ - _url_ request url
+ - _timeout_ timeout in milliseconds
+ - _method_ HTTP method
+ - _data_ request body
+ - _headers_ headers object
+
+The _res_ object may be a callback function which
+receives the response for assertions, or an object
+which is then used to perform several assertions
+on the response with the following properties:
+
+ - _body_ assert response body
+ - _status_ assert response status code
+ - _header_ assert that all given headers match (unspecified are ignored)
+
+When providing _res_ you may then also pass a callback function
+as the fourth argument for additional assertions.
+
+Below are some examples:
+
+ assert.response(server, {
+ url: '/', timeout: 500
+ }, {
+ body: 'foobar'
+ });
+
+ assert.response(server, {
+ url: '/',
+ method: 'GET'
+ },{
+ body: '{"name":"tj"}',
+ status: 200,
+ headers: {
+ 'Content-Type': 'application/json; charset=utf8',
+ 'X-Foo': 'bar'
+ }
+ });
+
+ assert.response(server, {
+ url: '/foo',
+ method: 'POST',
+ data: 'bar baz'
+ },{
+ body: '/foo bar baz',
+ status: 200
+ }, 'Test POST');
+
+ assert.response(server, {
+ url: '/foo',
+ method: 'POST',
+ data: 'bar baz'
+ },{
+ body: '/foo bar baz',
+ status: 200
+ }, function(res){
+ // All done, do some more tests if needed
+ });
+
+ assert.response(server, {
+ url: '/'
+ }, function(res){
+ assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback');
+ });
+
+
+## expresso(1)
+
+To run a single test suite (file) run:
+
+ $ expresso test/a.test.js
+
+To run several suites we may simply append another:
+
+ $ expresso test/a.test.js test/b.test.js
+
+We can also pass a whitelist of tests to run within all suites:
+
+ $ expresso --only "foo()" --only "bar()"
+
+Or several with one call:
+
+ $ expresso --only "foo(), bar()"
+
+Globbing is of course possible as well:
+
+ $ expresso test/*
+
+When expresso is called without any files, _test/*_ is the default,
+so the following is equivalent to the command above:
+
+ $ expresso
+
+If you wish to unshift a path to `require.paths` before
+running tests, you may use the `-I` or `--include` flag.
+
+ $ expresso --include lib test/*
+
+The previous example is typically what I would recommend, since expresso
+supports test coverage via [node-jscoverage](http://github.com/visionmedia/node-jscoverage) (bundled with expresso),
+so you will need to expose an instrumented version of you library.
+
+To instrument your library, simply run [node-jscoverage](http://github.com/visionmedia/node-jscoverage),
+passing the _src_ and _dest_ directories:
+
+ $ node-jscoverage lib lib-cov
+
+Now we can run our tests again, using the _lib-cov_ directory that has been
+instrumented with coverage statements:
+
+ $ expresso -I lib-cov test/*
+
+The output will look similar to below, depending on your test coverage of course :)
+
+![node coverage](http://dl.dropbox.com/u/6396913/cov.png)
+
+To make this process easier expresso has the _-c_ or _--cov_ which essentially
+does the same as the two commands above. The following two commands will
+run the same tests, however one will auto-instrument, and unshift _lib-cov_,
+and the other will run tests normally:
+
+ $ expresso -I lib test/*
+ $ expresso -I lib --cov test/*
+
+Currently coverage is bound to the _lib_ directory, however in the
+future `--cov` will most likely accept a path.
+
+## Async Exports
+
+Sometimes it is useful to postpone running of tests until a callback or event has fired, currently the _exports.foo = function(){};_ syntax is supported for this:
+
+ setTimeout(function(){
+ exports['test async exports'] = function(assert){
+ assert.ok('wahoo');
+ };
+ }, 100);
--- /dev/null
+ </div>
+ </body>
+</html>
\ No newline at end of file
--- /dev/null
+<html>
+ <head>
+ <title>Expresso - TDD Framework For Node</title>
+ <style>
+ body {
+ font: 13px/1.4 "Helvetica", "Lucida Grande", Arial, sans-serif;
+ text-align: center;
+ }
+ #ribbon {
+ position: absolute;
+ top: 0;
+ right: 0;
+ z-index: 10;
+ }
+ #wrapper {
+ margin: 0 auto;
+ padding: 50px 80px;
+ width: 700px;
+ text-align: left;
+ }
+ h1, h2, h3 {
+ margin: 25px 0 15px 0;
+ }
+ h1 {
+ font-size: 35px;
+ }
+ pre {
+ margin: 0 5px;
+ padding: 15px;
+ border: 1px solid #eee;
+ }
+ a {
+ color: #00aaff;
+ }
+ </style>
+ </head>
+ <body>
+ <a href="http://github.com/visionmedia/expresso">
+ <img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" />
+ </a>
+ <div id="wrapper">
+ <h1>Expresso</h1>
--- /dev/null
+
+exports.bar = function(msg){
+ return msg || 'bar';
+};
\ No newline at end of file
--- /dev/null
+
+exports.foo = function(msg){
+ if (msg) {
+ return msg;
+ } else {
+ return generateFoo();
+ }
+};
+
+function generateFoo() {
+ return 'foo';
+}
+
+function Foo(msg){
+ this.msg = msg || 'foo';
+}
--- /dev/null
+{ "name": "expresso",
+ "version": "0.6.2",
+ "description": "TDD framework, light-weight, fast, CI-friendly",
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "bin": {
+ "expresso": "./bin/expresso",
+ "node-jscoverage": "./deps/jscoverage/node-jscoverage"
+ },
+ "scripts": {
+ "preinstall": "make deps/jscoverage/node-jscoverage"
+ }
+}
\ No newline at end of file
--- /dev/null
+module.exports = {
+ 'assert.eql()': function(assert){
+ assert.equal(assert.deepEqual, assert.eql);
+ },
+
+ 'assert.type()': function(assert){
+ assert.type('foobar', 'string');
+ assert.type(2, 'number');
+ assert.throws(function(){
+ assert.type([1,2,3], 'string');
+ });
+ },
+
+ 'assert.includes()': function(assert){
+ assert.includes('some random string', 'dom');
+ assert.throws(function(){
+ assert.include('some random string', 'foobar');
+ });
+
+ assert.includes(['foo', 'bar'], 'bar');
+ assert.includes(['foo', 'bar'], 'foo');
+ assert.includes([1,2,3], 3);
+ assert.includes([1,2,3], 2);
+ assert.includes([1,2,3], 1);
+ assert.throws(function(){
+ assert.includes(['foo', 'bar'], 'baz');
+ });
+
+ assert.throws(function(){
+ assert.includes({ wrong: 'type' }, 'foo');
+ });
+ },
+
+ 'assert.isNull()': function(assert){
+ assert.isNull(null);
+ assert.throws(function(){
+ assert.isNull(undefined);
+ });
+ assert.throws(function(){
+ assert.isNull(false);
+ });
+ },
+
+ 'assert.isUndefined()': function(assert){
+ assert.isUndefined(undefined);
+ assert.throws(function(){
+ assert.isUndefined(null);
+ });
+ assert.throws(function(){
+ assert.isUndefined(false);
+ });
+ },
+
+ 'assert.isNotNull()': function(assert){
+ assert.isNotNull(false);
+ assert.isNotNull(undefined);
+ assert.throws(function(){
+ assert.isNotNull(null);
+ });
+ },
+
+ 'assert.isDefined()': function(assert){
+ assert.isDefined(false);
+ assert.isDefined(null);
+ assert.throws(function(){
+ assert.isDefined(undefined);
+ });
+ },
+
+ 'assert.match()': function(assert){
+ assert.match('foobar', /foo(bar)?/);
+ assert.throws(function(){
+ assert.match('something', /rawr/);
+ });
+ },
+
+ 'assert.length()': function(assert){
+ assert.length('test', 4);
+ assert.length([1,2,3,4], 4);
+ assert.throws(function(){
+ assert.length([1,2,3], 4);
+ });
+ }
+};
\ No newline at end of file
--- /dev/null
+
+setTimeout(function(){
+ exports['test async exports'] = function(assert){
+ assert.ok('wahoo');
+ };
+}, 100);
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var bar = require('bar');
+
+module.exports = {
+ 'bar()': function(assert){
+ assert.equal('bar', bar.bar());
+ }
+};
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var foo = require('foo');
+
+module.exports = {
+ 'foo()': function(assert){
+ assert.equal('foo', foo.foo());
+ assert.equal('foo', foo.foo());
+ }
+};
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var http = require('http');
+
+var server = http.createServer(function(req, res){
+ if (req.method === 'GET') {
+ if (req.url === '/delay') {
+ setTimeout(function(){
+ res.writeHead(200, {});
+ res.end('delayed');
+ }, 200);
+ } else {
+ var body = JSON.stringify({ name: 'tj' });
+ res.writeHead(200, {
+ 'Content-Type': 'application/json; charset=utf8',
+ 'Content-Length': body.length
+ });
+ res.end(body);
+ }
+ } else {
+ var body = '';
+ req.setEncoding('utf8');
+ req.addListener('data', function(chunk){ body += chunk });
+ req.addListener('end', function(){
+ res.writeHead(200, {});
+ res.end(req.url + ' ' + body);
+ });
+ }
+});
+
+module.exports = {
+ 'test assert.response()': function(assert, beforeExit){
+ var called = 0;
+
+ assert.response(server, {
+ url: '/',
+ method: 'GET'
+ },{
+ body: '{"name":"tj"}',
+ status: 200,
+ headers: {
+ 'Content-Type': 'application/json; charset=utf8'
+ }
+ });
+
+ assert.response(server, {
+ url: '/foo',
+ method: 'POST',
+ data: 'bar baz'
+ },{
+ body: '/foo bar baz',
+ status: 200
+ }, function(res){
+ ++called;
+ assert.ok(res);
+ });
+
+ assert.response(server, {
+ url: '/foo'
+ }, function(res){
+ ++called;
+ assert.ok(res.body.indexOf('tj') >= 0, 'Test assert.response() callback');
+ });
+
+ assert.response(server,
+ { url: '/delay', timeout: 300 },
+ { body: 'delayed' });
+
+ beforeExit(function(){
+ assert.equal(2, called);
+ });
+ },
+
+ 'test assert.response() regexp': function(assert){
+ assert.response(server,
+ { url: '/foo', method: 'POST', data: 'foobar' },
+ { body: /^\/foo foo(bar)?/ });
+ }
+};
\ No newline at end of file
--- /dev/null
+
+var setup = 0,
+ order = [];
+
+module.exports = {
+ setup: function(done){
+ ++setup;
+ done();
+ },
+
+ a: function(assert, done){
+ assert.equal(1, setup);
+ order.push('a');
+ setTimeout(function(){
+ done();
+ }, 500);
+ },
+
+ b: function(assert, done){
+ assert.equal(2, setup);
+ order.push('b');
+ setTimeout(function(){
+ done();
+ }, 200);
+ },
+
+ c: function(assert, done){
+ assert.equal(3, setup);
+ order.push('c');
+ setTimeout(function(){
+ done();
+ }, 1000);
+ },
+
+ d: function(assert){
+ assert.eql(order, ['a', 'b', 'c']);
+ }
+};
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var http = require('http');
+
+var server = http.createServer(function(req, res){
+ if (req.method === 'GET') {
+ if (req.url === '/delay') {
+ setTimeout(function(){
+ res.writeHead(200, {});
+ res.end('delayed');
+ }, 200);
+ } else {
+ var body = JSON.stringify({ name: 'tj' });
+ res.writeHead(200, {
+ 'Content-Type': 'application/json; charset=utf8',
+ 'Content-Length': body.length
+ });
+ res.end(body);
+ }
+ } else {
+ var body = '';
+ req.setEncoding('utf8');
+ req.addListener('data', function(chunk){ body += chunk });
+ req.addListener('end', function(){
+ res.writeHead(200, {});
+ res.end(req.url + ' ' + body);
+ });
+ }
+});
+
+module.exports = {
+ 'test assert.response()': function(assert, done){
+ assert.response(server, {
+ url: '/',
+ method: 'GET'
+ },{
+ body: '{"name":"tj"}',
+ status: 200,
+ headers: {
+ 'Content-Type': 'application/json; charset=utf8'
+ }
+ }, done);
+ }
+};
\ No newline at end of file
--- /dev/null
+*.seed
+*.cache
+*.log
+.DS_Store
+pkg
+build
+bin
\ No newline at end of file
--- /dev/null
+
+0.4.2 / 2010-06-21
+==================
+
+ * Added lib directory to package.json for npm to work
+
+0.4.1 / 2010-06-21
+==================
+
+ * Addex index.js for npm support
+
+0.4.0 / 2010-04-02
+==================
+
+ * Added "cache" option
+
+0.3.0 / 2010-02-22
+==================
+
+ * Added mixin support. Closes #1
+
+0.2.0 / 2010-02-05
+==================
+
+ * Added alternate variable syntax back ("var: val")
+ * Added a method to extract variables. Closes #3
+
+0.1.0 / 2010-02-05
+==================
+
+ * Added continuation support. Closes #15
+
+0.0.2 / 2010-02-02
+==================
+
+ * Fixed complex selectors
+ * Removed "var: val" syntax for variables
+
+0.0.1 / 2010-01-12
+==================
+
+ * Initial release
--- /dev/null
+
+all: test
+
+test: spec/node.js
+ @node spec/node.js
+
+benchmark:
+ @node benchmarks/large.js
+
+.PHONY: test benchmark
+
\ No newline at end of file
--- /dev/null
+
+# Sass.js
+
+ JavaScript implementation of Sass. Great for **node.js** and other
+ frameworks supporting the CommonJS module system.
+
+## Installation
+
+ Install the [Kiwi package manager for nodejs](http://github.com/visionmedia/kiwi)
+ and run:
+
+ $ kiwi install sass
+
+Or npm:
+
+ $ npm install sass
+
+## Usage
+
+ var sass = require('sass')
+ sass.render('... string of sass ...')
+ // => '... string of css ...'
+
+ sass.collect('... string of sass ...')
+ // => { selectors: [...], variables: { ... }, mixins: { ... }}
+
+## Comments
+
+ // foo
+ body
+ // bar
+ a
+ :color #fff
+
+compiles to
+
+ body a {
+ color: #fff;}
+
+## Variables
+
+ !red = #ff0000
+ body
+ :color !red
+
+and
+
+ red: #ff0000
+ body
+ :color !red
+
+compile to
+
+ body {
+ color: #ff0000;}
+
+## Selector Continuations
+
+ a
+ :color #fff
+ &:hover
+ :color #000
+ &.active
+ :background #888
+ &:hover
+ :color #fff
+
+compiles to
+
+ a {
+ color: #fff;}
+
+ a:hover {
+ color: #000;}
+
+ a.active {
+ background: #888;}
+
+ a.active:hover {
+ color: #fff;}
+
+## Literal JavaScript
+
+ type: "solid"
+ size: 1
+ input
+ :border { parseInt(size) + 1 }px {type} #000
+
+compiles to
+
+ input {
+ border: 2px "solid" #000;}
+
+## Property Expansion
+
+ div
+ =border-radius 5px
+
+compiles to
+
+ div {
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;}
+
+## Mixins
+
+ +large
+ :font-size 15px
+ +striped
+ tr
+ :background #fff
+ +large
+ &:odd
+ :background #000
+ table
+ +striped
+ :border none
+
+compiles to
+
+ table {
+ border: none;}
+ table tr {
+ background: #fff;}
+ table tr {
+ font-size: 15px;}
+ table tr:odd {
+ background: #000;}
+
+
+## Testing
+
+Update Git submodules and execute:
+ $ make test
+or
+ $ node spec/node.js
+or
+ $ jspec --node
+
+## More Information
+
+* Featured in [Advanced JavaScript e-book](http://www.dev-mag.com/2010/02/18/advanced-javascript/) for only $4
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- /dev/null
+lib/sass.js
\ No newline at end of file
--- /dev/null
+
+// Sass - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+/**
+ * Library version.
+ */
+
+exports.version = '0.4.3'
+
+/**
+ * Compiled sass cache.
+ */
+
+var cache = {}
+
+/**
+ * Sass grammar tokens.
+ */
+
+var tokens = [
+ ['indent', /^\n +/],
+ ['space', /^ +/],
+ ['nl', /^\n/],
+ ['js', /^{(.*?)}/],
+ ['comment', /^\/\/(.*)/],
+ ['string', /^(?:'(.*?)'|"(.*?)")/],
+ ['variable', /^!([\w\-]+) *= *([^\n]+)/],
+ ['variable.alternate', /^([\w\-]+): +([^\n]+)/],
+ ['property.expand', /^=([\w\-]+) *([^\n]+)/],
+ ['property', /^:([\w\-]+) *([^\n]+)/],
+ ['continuation', /^&(.+)/],
+ ['mixin', /^\+([\w\-]+)/],
+ ['selector', /^(.+)/]
+]
+
+/**
+ * Vendor-specific expansion prefixes.
+ */
+
+exports.expansions = ['-moz-', '-webkit-']
+
+/**
+ * Tokenize the given _str_.
+ *
+ * @param {string} str
+ * @return {array}
+ * @api private
+ */
+
+function tokenize(str) {
+ var token, captures, stack = []
+ while (str.length) {
+ for (var i = 0, len = tokens.length; i < len; ++i)
+ if (captures = tokens[i][1].exec(str)) {
+ token = [tokens[i][0], captures],
+ str = str.replace(tokens[i][1], '')
+ break
+ }
+ if (token)
+ stack.push(token),
+ token = null
+ else
+ throw new Error("SyntaxError: near `" + str.slice(0, 25).replace('\n', '\\n') + "'")
+ }
+ return stack
+}
+
+/**
+ * Parse the given _tokens_, returning
+ * and hash containing the properties below:
+ *
+ * selectors: array of top-level selectors
+ * variables: hash of variables defined
+ *
+ * @param {array} tokens
+ * @return {hash}
+ * @api private
+ */
+
+function parse(tokens) {
+ var token, selector,
+ data = { variables: {}, mixins: {}, selectors: [] },
+ line = 1,
+ lastIndents = 0,
+ indents = 0
+
+ /**
+ * Output error _msg_ in context to the current line.
+ */
+
+ function error(msg) {
+ throw new Error('ParseError: on line ' + line + '; ' + msg)
+ }
+
+ /**
+ * Reset parents until the indentation levels match.
+ */
+
+ function reset() {
+ if (indents === 0)
+ return selector = null
+ while (lastIndents-- > indents)
+ selector = selector.parent
+ }
+
+ // Parse tokens
+
+ while (token = tokens.shift())
+ switch (token[0]) {
+ case 'mixin':
+ if (indents) {
+ var mixin = data.mixins[token[1][1]]
+ if (!mixin) error("mixin `" + token[1][1] + "' does not exist")
+ mixin.parent = selector
+ selector.children.push(mixin)
+ }
+ else
+ data.mixins[token[1][1]] = selector = new Selector(token[1][1], null, 'mixin')
+ break
+ case 'continuation':
+ reset()
+ selector = new Selector(token[1][1], selector, 'continuation')
+ break
+ case 'selector':
+ reset()
+ selector = new Selector(token[1][1], selector)
+ if (!selector.parent)
+ data.selectors.push(selector)
+ break
+ case 'property':
+ reset()
+ if (!selector) error('properties must be nested within a selector')
+ var val = token[1][2]
+ .replace(/!([\w\-]+)/g, function(orig, name){
+ return data.variables[name] || orig
+ })
+ .replace(/\{(.*?)\}/g, function(_, js){
+ with (data.variables){ return eval(js) }
+ })
+ selector.properties.push(new Property(token[1][1], val))
+ break
+ case 'property.expand':
+ exports.expansions.forEach(function(prefix){
+ tokens.unshift(['property', [, prefix + token[1][1], token[1][2]]])
+ })
+ break
+ case 'variable':
+ case 'variable.alternate':
+ data.variables[token[1][1]] = token[1][2]
+ break
+ case 'js':
+ with (data.variables){ eval(token[1][1]) }
+ break
+ case 'nl':
+ ++line, indents = 0
+ break
+ case 'comment':
+ break
+ case 'indent':
+ ++line
+ lastIndents = indents,
+ indents = (token[1][0].length - 1) / 2
+ if (indents > lastIndents &&
+ indents - 1 > lastIndents)
+ error('invalid indentation, to much nesting')
+ }
+ return data
+}
+
+/**
+ * Compile _selectors_ to a string of css.
+ *
+ * @param {array} selectors
+ * @return {string}
+ * @api private
+ */
+
+function compile(selectors) {
+ return selectors.join('\n')
+}
+
+/**
+ * Collect data by parsing _sass_.
+ * Returns a hash containing the following properties:
+ *
+ * selectors: array of top-level selectors
+ * variables: hash of variables defined
+ *
+ * @param {string} sass
+ * @return {hash}
+ * @api public
+ */
+
+exports.collect = function(sass) {
+ return parse(tokenize(sass))
+}
+
+/**
+ * Render a string of _sass_.
+ *
+ * Options:
+ *
+ * - filename Optional filename to aid in error reporting
+ * - cache Optional caching of compiled content. Requires "filename" option
+ *
+ * @param {string} sass
+ * @param {object} options
+ * @return {string}
+ * @api public
+ */
+
+exports.render = function(sass, options) {
+ options = options || {}
+ if (options.cache && !options.filename)
+ throw new Error('filename option must be passed when cache is enabled')
+ if (options.cache)
+ return cache[options.filename]
+ ? cache[options.filename]
+ : cache[options.filename] = compile(exports.collect(sass).selectors)
+ return compile(exports.collect(sass).selectors)
+}
+
+// --- Selector
+
+/**
+ * Initialize a selector with _string_ and
+ * optional _parent_.
+ *
+ * @param {string} string
+ * @param {Selector} parent
+ * @param {string} type
+ * @api private
+ */
+
+function Selector(string, parent, type) {
+ this.string = string
+ this.parent = parent
+ this.properties = []
+ this.children = []
+ if (type) this[type] = true
+ if (parent) parent.children.push(this)
+}
+
+/**
+ * Return selector string.
+ *
+ * @return {string}
+ * @api private
+ */
+
+Selector.prototype.selector = function() {
+ var selector = this.string
+ if (this.parent)
+ selector = this.continuation
+ ? this.parent.selector() + selector
+ : this.mixin
+ ? this.parent.selector()
+ : this.parent.selector() + ' ' + selector
+ return selector
+}
+
+/**
+ * Return selector and nested selectors as CSS.
+ *
+ * @return {string}
+ * @api private
+ */
+
+Selector.prototype.toString = function() {
+ return (this.properties.length
+ ? this.selector() + ' {\n' + this.properties.join('\n') + '}\n'
+ : '') + this.children.join('')
+}
+
+// --- Property
+
+/**
+ * Initialize property with _name_ and _val_.
+ *
+ * @param {string} name
+ * @param {string} val
+ * @api private
+ */
+
+function Property(name, val) {
+ this.name = name
+ this.val = val
+}
+
+/**
+ * Return CSS string representing a property.
+ *
+ * @return {string}
+ * @api private
+ */
+
+Property.prototype.toString = function() {
+ return ' ' + this.name + ': ' + this.val + ';'
+}
--- /dev/null
+{
+ "name": "sass",
+ "description": "Syntactically Awesome Stylesheets (compiles to css)",
+ "version": "0.4.3",
+ "keywords": ["sass", "template", "css", "view"],
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "directories": {
+ "lib": "."
+ }
+}
\ No newline at end of file
--- /dev/null
+---
+ name: Sass
+ description: Syntactically Awesome Stylesheets (compiles to css)
+ version: 0.4.3
--- /dev/null
+
+!red = #ff0000
+!black = #000
\ No newline at end of file
--- /dev/null
+body a {
+ color: #fff;}
--- /dev/null
+
+// foo
+body
+ // bar
+ a
+ :color #fff
--- /dev/null
+a {
+ color: #fff;}
+a:hover {
+ color: #000;}
+a.active {
+ background: #888;}
+a.active:hover {
+ color: #fff;}
--- /dev/null
+a
+ :color #fff
+ &:hover
+ :color #000
+ &.active
+ :background #888
+ &:hover
+ :color #fff
\ No newline at end of file
--- /dev/null
+input {
+ border: 2px "solid" #000;}
--- /dev/null
+!type = "solid"
+!size = 1
+input
+ :border { parseInt(size) + 1 }px {type} #000
\ No newline at end of file
--- /dev/null
+table {
+ border: none;}
+table tr {
+ background: #fff;}
+table tr {
+ font-size: 15px;}
+table tr:odd {
+ background: #000;}
--- /dev/null
++large
+ :font-size 15px
++striped
+ tr
+ :background #fff
+ +large
+ &:odd
+ :background #000
+table
+ +striped
+ :border none
\ No newline at end of file
--- /dev/null
+body
+ +large
\ No newline at end of file
--- /dev/null
+body {
+ font-size: 13px;
+ color: #fff;}
--- /dev/null
+div {
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;}
--- /dev/null
+div
+ =border-radius 5px
\ No newline at end of file
--- /dev/null
+:color #fff
+body
\ No newline at end of file
--- /dev/null
+body {
+ padding: 0;}
+body ul {
+ margin: 0;}
+body ul li {
+ list-style: none;}
+body ul li a {
+ color: #fff;}
+body form label {
+ display: none;}
+
+a {
+ color: #cc0000;}
--- /dev/null
+body
+ ul
+ :margin 0
+ li
+ :padding 0
\ No newline at end of file
--- /dev/null
+body
+ ul
+ :margin 0
+ li
+ a
+ :color #fff
+ :list-style none
+ :padding 0
+ form
+ label
+ :display none
+a
+ :color #cc0000
\ No newline at end of file
--- /dev/null
+body
+ :font-size 13px
+ :color #fff
\ No newline at end of file
--- /dev/null
+body input.field#email ~ label {
+ display: none;}
+body form:nth-child(1) legend {
+ font-size: 15px;}
+body ul li:first-child a {
+ display: none;}
--- /dev/null
+body
+ input.field#email ~ label
+ :display none
+ form:nth-child(1)
+ legend
+ :font-size 15px
+ ul
+ li:first-child
+ a
+ :display none
--- /dev/null
+body {
+ background: #ff0000 url('foo.png');}
--- /dev/null
+color: #ff0000
+image: url('foo.png')
+body
+ :background !color !image
\ No newline at end of file
--- /dev/null
+body {
+ color: #ff0000;}
--- /dev/null
+body {
+ color: #ff0000;}
--- /dev/null
+!red = #ff0000
+body
+ :color !red
\ No newline at end of file
--- /dev/null
+
+red: #ff0000
+
+body
+ :color !red
--- /dev/null
+body.jspec {
+ margin: 45px 0;
+ font: 12px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
+ background: #efefef url(images/bg.png) top left repeat-x;
+ text-align: center;
+}
+#jspec {
+ margin: 0 auto;
+ padding-top: 30px;
+ width: 1008px;
+ background: url(images/vr.png) top left repeat-y;
+ text-align: left;
+}
+#jspec-top {
+ position: relative;
+ margin: 0 auto;
+ width: 1008px;
+ height: 40px;
+ background: url(images/sprites.bg.png) top left no-repeat;
+}
+#jspec-bottom {
+ margin: 0 auto;
+ width: 1008px;
+ height: 15px;
+ background: url(images/sprites.bg.png) bottom left no-repeat;
+}
+#jspec .loading {
+ margin-top: -45px;
+ width: 1008px;
+ height: 80px;
+ background: url(images/loading.gif) 50% 50% no-repeat;
+}
+#jspec-title {
+ position: absolute;
+ top: 15px;
+ left: 20px;
+ width: 160px;
+ font-size: 22px;
+ font-weight: normal;
+ background: url(images/sprites.png) 0 -126px no-repeat;
+ text-align: center;
+}
+#jspec-title em {
+ font-size: 10px;
+ font-style: normal;
+ color: #BCC8D1;
+}
+#jspec-report * {
+ margin: 0;
+ padding: 0;
+ background: none;
+ border: none;
+}
+#jspec-report {
+ padding: 15px 40px;
+ font: 11px "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
+ color: #7B8D9B;
+}
+#jspec-report.has-failures {
+ padding-bottom: 30px;
+}
+#jspec-report .hidden {
+ display: none;
+}
+#jspec-report .heading {
+ margin-bottom: 15px;
+}
+#jspec-report .heading span {
+ padding-right: 10px;
+}
+#jspec-report .heading .passes em {
+ color: #0ea0eb;
+}
+#jspec-report .heading .failures em {
+ color: #FA1616;
+}
+#jspec-report table {
+ font-size: 11px;
+ border-collapse: collapse;
+}
+#jspec-report td {
+ padding: 8px;
+ text-indent: 30px;
+ color: #7B8D9B;
+}
+#jspec-report tr.body {
+ display: none;
+}
+#jspec-report tr.body pre {
+ margin: 0;
+ padding: 0 0 5px 25px;
+}
+#jspec-report tr.even:hover + tr.body,
+#jspec-report tr.odd:hover + tr.body {
+ display: block;
+}
+#jspec-report tr td:first-child em {
+ display: block;
+ clear: both;
+ font-style: normal;
+ font-weight: normal;
+ color: #7B8D9B;
+}
+#jspec-report tr.even:hover,
+#jspec-report tr.odd:hover {
+ text-shadow: 1px 1px 1px #fff;
+ background: #F2F5F7;
+}
+#jspec-report td + td {
+ padding-right: 0;
+ width: 15px;
+}
+#jspec-report td.pass {
+ background: url(images/sprites.png) 3px -7px no-repeat;
+}
+#jspec-report td.fail {
+ background: url(images/sprites.png) 3px -158px no-repeat;
+ font-weight: bold;
+ color: #FC0D0D;
+}
+#jspec-report td.requires-implementation {
+ background: url(images/sprites.png) 3px -333px no-repeat;
+}
+#jspec-report tr.description td {
+ margin-top: 25px;
+ padding-top: 25px;
+ font-size: 12px;
+ font-weight: bold;
+ text-indent: 0;
+ color: #1a1a1a;
+}
+#jspec-report tr.description:first-child td {
+ border-top: none;
+}
+#jspec-report .assertion {
+ display: block;
+ float: left;
+ margin: 0 0 0 1px;
+ padding: 0;
+ width: 1px;
+ height: 5px;
+ background: #7B8D9B;
+}
+#jspec-report .assertion.failed {
+ background: red;
+}
+.jspec-sandbox {
+ display: none;
+}
\ No newline at end of file
--- /dev/null
+
+// JSpec - Growl - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+;(function(){
+
+ Growl = {
+
+ // --- Version
+
+ version: '1.0.0',
+
+ /**
+ * Execute the given _cmd_, returning an array of lines from stdout.
+ *
+ * Examples:
+ *
+ * Growl.exec('growlnotify', '-m', msg)
+ *
+ * @param {string ...} cmd
+ * @return {array}
+ * @api public
+ */
+
+ exec: function(cmd) {
+ var lines = [], line
+ with (JavaImporter(java.lang, java.io)) {
+ var proccess = Runtime.getRuntime().exec(Array.prototype.slice.call(arguments))
+ var stream = new DataInputStream(proccess.getInputStream())
+ while (line = stream.readLine())
+ lines.push(line + '')
+ stream.close()
+ }
+ return lines
+ },
+
+ /**
+ * Return the extension of the given _path_ or null.
+ *
+ * @param {string} path
+ * @return {string}
+ * @api private
+ */
+
+ extname: function(path) {
+ return path.lastIndexOf('.') != -1 ?
+ path.slice(path.lastIndexOf('.') + 1, path.length) :
+ null
+ },
+
+ /**
+ * Version of the 'growlnotify' binary.
+ *
+ * @return {string}
+ * @api private
+ */
+
+ binVersion: function() {
+ try { return this.exec('growlnotify', '-v')[0].split(' ')[1] } catch (e) {}
+ },
+
+ /**
+ * Send growl notification _msg_ with _options_.
+ *
+ * Options:
+ *
+ * - title Notification title
+ * - sticky Make the notification stick (defaults to false)
+ * - name Application name (defaults to growlnotify)
+ * - image
+ * - path to an icon sets --iconpath
+ * - path to an image sets --image
+ * - capitalized word sets --appIcon
+ * - filename uses extname as --icon
+ * - otherwise treated as --icon
+ *
+ * Examples:
+ *
+ * Growl.notify('New email')
+ * Growl.notify('5 new emails', { title: 'Thunderbird' })
+ *
+ * @param {string} msg
+ * @param {options} hash
+ * @api public
+ */
+
+ notify: function(msg, options) {
+ options = options || {}
+ var args = ['growlnotify', '-m', msg]
+ if (!this.binVersion()) throw new Error('growlnotify executable is required')
+ if (image = options.image) {
+ var flag, ext = this.extname(image)
+ flag = flag || ext == 'icns' && 'iconpath'
+ flag = flag || /^[A-Z]/.test(image) && 'appIcon'
+ flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
+ flag = flag || ext && (image = ext) && 'icon'
+ flag = flag || 'icon'
+ args.push('--' + flag, image)
+ }
+ if (options.sticky) args.push('--sticky')
+ if (options.name) args.push('--name', options.name)
+ if (options.title) args.push(options.title)
+ this.exec.apply(this, args)
+ }
+ }
+
+ JSpec.include({
+ name: 'Growl',
+ reporting: function(options){
+ var stats = JSpec.stats
+ if (stats.failures) Growl.notify('failed ' + stats.failures + ' assertions', { title: 'JSpec'})
+ else Growl.notify('passed ' + stats.passes + ' assertions', { title: 'JSpec' })
+ }
+ })
+
+})()
\ No newline at end of file
--- /dev/null
+
+// JSpec - jQuery - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+JSpec
+.requires('jQuery', 'when using jspec.jquery.js')
+.include({
+ name: 'jQuery',
+
+ // --- Initialize
+
+ init : function() {
+ jQuery.ajaxSetup({ async: false })
+ },
+
+ // --- Utilities
+
+ utilities : {
+ element: jQuery,
+ elements: jQuery,
+ sandbox : function() {
+ return jQuery('<div class="sandbox"></div>')
+ }
+ },
+
+ // --- Matchers
+
+ matchers : {
+ have_tag : "jQuery(expected, actual).length === 1",
+ have_one : "alias have_tag",
+ have_tags : "jQuery(expected, actual).length > 1",
+ have_many : "alias have_tags",
+ have_any : "alias have_tags",
+ have_child : "jQuery(actual).children(expected).length === 1",
+ have_children : "jQuery(actual).children(expected).length > 1",
+ have_text : "jQuery(actual).text() === expected",
+ have_value : "jQuery(actual).val() === expected",
+ be_enabled : "!jQuery(actual).attr('disabled')",
+ have_class : "jQuery(actual).hasClass(expected)",
+ be_animated : "jQuery(actual).queue().length > 0",
+
+ be_visible : function(actual) {
+ return jQuery(actual).css('display') != 'none' &&
+ jQuery(actual).css('visibility') != 'hidden' &&
+ jQuery(actual).attr('type') != 'hidden'
+ },
+
+ be_hidden : function(actual) {
+ return !JSpec.does(actual, 'be_visible')
+ },
+
+ have_classes : function(actual) {
+ return !JSpec.any(JSpec.toArray(arguments, 1), function(arg){
+ return !JSpec.does(actual, 'have_class', arg)
+ })
+ },
+
+ have_attr : function(actual, attr, value) {
+ return value ? jQuery(actual).attr(attr) == value:
+ jQuery(actual).attr(attr)
+ },
+
+ have_event_handlers : function(actual, expected) {
+ return jQuery(actual).data('events') ?
+ jQuery(actual).data('events').hasOwnProperty(expected) :
+ false
+ },
+
+ 'be disabled selected checked' : function(attr) {
+ return 'jQuery(actual).attr("' + attr + '")'
+ },
+
+ 'have type id title alt href src sel rev name target' : function(attr) {
+ return function(actual, value) {
+ return JSpec.does(actual, 'have_attr', attr, value)
+ }
+ }
+ }
+})
+
--- /dev/null
+
+// JSpec - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+;(function(){
+
+ JSpec = {
+ version : '4.3.2',
+ assert : true,
+ cache : {},
+ suites : [],
+ modules : [],
+ allSuites : [],
+ sharedBehaviors: [],
+ matchers : {},
+ stubbed : [],
+ options : {},
+ request : 'XMLHttpRequest' in this ? XMLHttpRequest : null,
+ stats : { specs: 0, assertions: 0, failures: 0, passes: 0, specsFinished: 0, suitesFinished: 0 },
+
+ /**
+ * Default context in which bodies are evaluated.
+ *
+ * Replace context simply by setting JSpec.context
+ * to your own like below:
+ *
+ * JSpec.context = { foo : 'bar' }
+ *
+ * Contexts can be changed within any body, this can be useful
+ * in order to provide specific helper methods to specific suites.
+ *
+ * To reset (usually in after hook) simply set to null like below:
+ *
+ * JSpec.context = null
+ *
+ */
+
+ defaultContext : {
+
+ /**
+ * Return an object used for proxy assertions.
+ * This object is used to indicate that an object
+ * should be an instance of _object_, not the constructor
+ * itself.
+ *
+ * @param {function} constructor
+ * @return {hash}
+ * @api public
+ */
+
+ an_instance_of : function(constructor) {
+ return { an_instance_of : constructor }
+ },
+
+ /**
+ * Load fixture at _path_.
+ *
+ * Fixtures are resolved as:
+ *
+ * - <path>
+ * - <path>.html
+ *
+ * @param {string} path
+ * @return {string}
+ * @api public
+ */
+
+ fixture : function(path) {
+ if (JSpec.cache[path]) return JSpec.cache[path]
+ return JSpec.cache[path] =
+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path) ||
+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path + '.html')
+ },
+
+ /**
+ * Load json fixture at _path_.
+ *
+ * JSON fixtures are resolved as:
+ *
+ * - <path>
+ * - <path>.json
+ *
+ * @param {string} path
+ * @return {object}
+ * @api public
+ */
+
+ json_fixture: function(path) {
+ if (!JSpec.cache['json:' + path])
+ JSpec.cache['json:' + path] =
+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path) ||
+ JSpec.tryLoading(JSpec.options.fixturePath + '/' + path + '.json')
+ try {
+ return eval('(' + JSpec.cache['json:' + path] + ')')
+ } catch (e) {
+ throw 'json_fixture("' + path + '"): ' + e
+ }
+ }
+ },
+
+ // --- Objects
+
+ reporters : {
+
+ /**
+ * Report to server.
+ *
+ * Options:
+ * - uri specific uri to report to.
+ * - verbose weither or not to output messages
+ * - failuresOnly output failure messages only
+ *
+ * @api public
+ */
+
+ Server : function(results, options) {
+ var uri = options.uri || 'http://' + window.location.host + '/results'
+ JSpec.post(uri, {
+ stats: JSpec.stats,
+ options: options,
+ results: map(results.allSuites, function(suite) {
+ if (suite.isExecutable())
+ return {
+ description: suite.description,
+ specs: map(suite.specs, function(spec) {
+ return {
+ description: spec.description,
+ message: !spec.passed() ? spec.failure().message : null,
+ status: spec.requiresImplementation() ? 'pending' :
+ spec.passed() ? 'pass' :
+ 'fail',
+ assertions: map(spec.assertions, function(assertion){
+ return {
+ passed: assertion.passed
+ }
+ })
+ }
+ })
+ }
+ })
+ })
+ if ('close' in main) main.close()
+ },
+
+ /**
+ * Default reporter, outputting to the DOM.
+ *
+ * Options:
+ * - reportToId id of element to output reports to, defaults to 'jspec'
+ * - failuresOnly displays only suites with failing specs
+ *
+ * @api public
+ */
+
+ DOM : function(results, options) {
+ var id = option('reportToId') || 'jspec',
+ report = document.getElementById(id),
+ failuresOnly = option('failuresOnly'),
+ classes = results.stats.failures ? 'has-failures' : ''
+ if (!report) throw 'JSpec requires the element #' + id + ' to output its reports'
+
+ function bodyContents(body) {
+ return JSpec.
+ escape(JSpec.contentsOf(body)).
+ replace(/^ */gm, function(a){ return (new Array(Math.round(a.length / 3))).join(' ') }).
+ replace(/\r\n|\r|\n/gm, '<br/>')
+ }
+
+ report.innerHTML = '<div id="jspec-report" class="' + classes + '"><div class="heading"> \
+ <span class="passes">Passes: <em>' + results.stats.passes + '</em></span> \
+ <span class="failures">Failures: <em>' + results.stats.failures + '</em></span> \
+ <span class="passes">Duration: <em>' + results.duration + '</em> ms</span> \
+ </div><table class="suites">' + map(results.allSuites, function(suite) {
+ var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran
+ if (displaySuite && suite.isExecutable())
+ return '<tr class="description"><td colspan="2">' + escape(suite.description) + '</td></tr>' +
+ map(suite.specs, function(i, spec) {
+ return '<tr class="' + (i % 2 ? 'odd' : 'even') + '">' +
+ (spec.requiresImplementation() ?
+ '<td class="requires-implementation" colspan="2">' + escape(spec.description) + '</td>' :
+ (spec.passed() && !failuresOnly) ?
+ '<td class="pass">' + escape(spec.description)+ '</td><td>' + spec.assertionsGraph() + '</td>' :
+ !spec.passed() ?
+ '<td class="fail">' + escape(spec.description) +
+ map(spec.failures(), function(a){ return '<em>' + escape(a.message) + '</em>' }).join('') +
+ '</td><td>' + spec.assertionsGraph() + '</td>' :
+ '') +
+ '<tr class="body"><td colspan="2"><pre>' + bodyContents(spec.body) + '</pre></td></tr>'
+ }).join('') + '</tr>'
+ }).join('') + '</table></div>'
+ },
+
+ /**
+ * Terminal reporter.
+ *
+ * @api public
+ */
+
+ Terminal : function(results, options) {
+ var failuresOnly = option('failuresOnly')
+ print(color("\n Passes: ", 'bold') + color(results.stats.passes, 'green') +
+ color(" Failures: ", 'bold') + color(results.stats.failures, 'red') +
+ color(" Duration: ", 'bold') + color(results.duration, 'green') + " ms \n")
+
+ function indent(string) {
+ return string.replace(/^(.)/gm, ' $1')
+ }
+
+ each(results.allSuites, function(suite) {
+ var displaySuite = failuresOnly ? suite.ran && !suite.passed() : suite.ran
+ if (displaySuite && suite.isExecutable()) {
+ print(color(' ' + suite.description, 'bold'))
+ each(suite.specs, function(spec){
+ var assertionsGraph = inject(spec.assertions, '', function(graph, assertion){
+ return graph + color('.', assertion.passed ? 'green' : 'red')
+ })
+ if (spec.requiresImplementation())
+ print(color(' ' + spec.description, 'blue') + assertionsGraph)
+ else if (spec.passed() && !failuresOnly)
+ print(color(' ' + spec.description, 'green') + assertionsGraph)
+ else if (!spec.passed())
+ print(color(' ' + spec.description, 'red') + assertionsGraph +
+ "\n" + indent(map(spec.failures(), function(a){ return a.message }).join("\n")) + "\n")
+ })
+ print("")
+ }
+ })
+
+ quit(results.stats.failures)
+ }
+ },
+
+ Assertion : function(matcher, actual, expected, negate) {
+ extend(this, {
+ message: '',
+ passed: false,
+ actual: actual,
+ negate: negate,
+ matcher: matcher,
+ expected: expected,
+
+ // Report assertion results
+
+ report : function() {
+ if (JSpec.assert)
+ this.passed ? JSpec.stats.passes++ : JSpec.stats.failures++
+ return this
+ },
+
+ // Run the assertion
+
+ run : function() {
+ // TODO: remove unshifting
+ expected.unshift(actual)
+ this.result = matcher.match.apply(this, expected)
+ this.passed = negate ? !this.result : this.result
+ if (!this.passed) this.message = matcher.message.call(this, actual, expected, negate, matcher.name)
+ return this
+ }
+ })
+ },
+
+ ProxyAssertion : function(object, method, times, negate) {
+ var self = this,
+ old = object[method]
+
+ // Proxy
+
+ object[method] = function(){
+ var args = toArray(arguments),
+ result = old.apply(object, args)
+ self.calls.push({ args : args, result : result })
+ return result
+ }
+
+ // Times
+
+ this.times = {
+ once : 1,
+ twice : 2
+ }[times] || times || 1
+
+ extend(this, {
+ calls: [],
+ message: '',
+ defer: true,
+ passed: false,
+ negate: negate,
+ object: object,
+ method: method,
+
+ // Proxy return value
+
+ and_return : function(result) {
+ this.expectedResult = result
+ return this
+ },
+
+ // Proxy arguments passed
+
+ with_args : function() {
+ this.expectedArgs = toArray(arguments)
+ return this
+ },
+
+ // Check if any calls have failing results
+
+ anyResultsFail : function() {
+ return any(this.calls, function(call){
+ return self.expectedResult.an_instance_of ?
+ call.result.constructor != self.expectedResult.an_instance_of:
+ !equal(self.expectedResult, call.result)
+ })
+ },
+
+ // Check if any calls have passing results
+
+ anyResultsPass : function() {
+ return any(this.calls, function(call){
+ return self.expectedResult.an_instance_of ?
+ call.result.constructor == self.expectedResult.an_instance_of:
+ equal(self.expectedResult, call.result)
+ })
+ },
+
+ // Return the passing result
+
+ passingResult : function() {
+ return this.anyResultsPass().result
+ },
+
+ // Return the failing result
+
+ failingResult : function() {
+ return this.anyResultsFail().result
+ },
+
+ // Check if any arguments fail
+
+ anyArgsFail : function() {
+ return any(this.calls, function(call){
+ return any(self.expectedArgs, function(i, arg){
+ if (arg == null) return call.args[i] == null
+ return arg.an_instance_of ?
+ call.args[i].constructor != arg.an_instance_of:
+ !equal(arg, call.args[i])
+
+ })
+ })
+ },
+
+ // Check if any arguments pass
+
+ anyArgsPass : function() {
+ return any(this.calls, function(call){
+ return any(self.expectedArgs, function(i, arg){
+ return arg.an_instance_of ?
+ call.args[i].constructor == arg.an_instance_of:
+ equal(arg, call.args[i])
+
+ })
+ })
+ },
+
+ // Return the passing args
+
+ passingArgs : function() {
+ return this.anyArgsPass().args
+ },
+
+ // Return the failing args
+
+ failingArgs : function() {
+ return this.anyArgsFail().args
+ },
+
+ // Report assertion results
+
+ report : function() {
+ if (JSpec.assert)
+ this.passed ? ++JSpec.stats.passes : ++JSpec.stats.failures
+ return this
+ },
+
+ // Run the assertion
+
+ run : function() {
+ var methodString = 'expected ' + object.toString() + '.' + method + '()' + (negate ? ' not' : '' )
+
+ function times(n) {
+ return n > 2 ? n + ' times' : { 1: 'once', 2: 'twice' }[n]
+ }
+
+ if (this.expectedResult != null && (negate ? this.anyResultsPass() : this.anyResultsFail()))
+ this.message = methodString + ' to return ' + puts(this.expectedResult) +
+ ' but ' + (negate ? 'it did' : 'got ' + puts(this.failingResult()))
+
+ if (this.expectedArgs && (negate ? !this.expectedResult && this.anyArgsPass() : this.anyArgsFail()))
+ this.message = methodString + ' to be called with ' + puts.apply(this, this.expectedArgs) +
+ ' but was' + (negate ? '' : ' called with ' + puts.apply(this, this.failingArgs()))
+
+ if (negate ? !this.expectedResult && !this.expectedArgs && this.calls.length >= this.times : this.calls.length != this.times)
+ this.message = methodString + ' to be called ' + times(this.times) +
+ ', but ' + (this.calls.length == 0 ? ' was not called' : ' was called ' + times(this.calls.length))
+
+ if (!this.message.length)
+ this.passed = true
+
+ return this
+ }
+ })
+ },
+
+ /**
+ * Specification Suite block object.
+ *
+ * @param {string} description
+ * @param {function} body
+ * @api private
+ */
+
+ Suite : function(description, body, isShared) {
+ var self = this
+ extend(this, {
+ body: body,
+ description: description,
+ suites: [],
+ sharedBehaviors: [],
+ specs: [],
+ ran: false,
+ shared: isShared,
+ hooks: { 'before' : [], 'after' : [],
+ 'before_each' : [], 'after_each' : [],
+ 'before_nested' : [], 'after_nested' : []},
+
+ // Add a spec to the suite
+
+ addSpec : function(description, body) {
+ var spec = new JSpec.Spec(description, body)
+ this.specs.push(spec)
+ JSpec.stats.specs++ // TODO: abstract
+ spec.suite = this
+ },
+
+ // Add a before hook to the suite
+
+ addBefore : function(options, body) {
+ body.options = options || {}
+ this.befores.push(body)
+ },
+
+ // Add an after hook to the suite
+
+ addAfter : function(options, body) {
+ body.options = options || {}
+ this.afters.unshift(body)
+ },
+
+ // Add a hook to the suite
+
+ addHook : function(hook, body) {
+ this.hooks[hook].push(body)
+ },
+
+ // Add a nested suite
+
+ addSuite : function(description, body, isShared) {
+ var suite = new JSpec.Suite(description, body, isShared)
+ JSpec.allSuites.push(suite)
+ suite.name = suite.description
+ suite.description = this.description + ' ' + suite.description
+ this.suites.push(suite)
+ suite.suite = this
+ },
+
+ // Invoke a hook in context to this suite
+
+ hook : function(hook) {
+ if (hook != 'before' && hook != 'after')
+ if (this.suite) this.suite.hook(hook)
+
+ each(this.hooks[hook], function(body) {
+ JSpec.evalBody(body, "Error in hook '" + hook + "', suite '" + self.description + "': ")
+ })
+ },
+
+ // Check if nested suites are present
+
+ hasSuites : function() {
+ return this.suites.length
+ },
+
+ // Check if this suite has specs
+
+ hasSpecs : function() {
+ return this.specs.length
+ },
+
+ // Check if the entire suite passed
+
+ passed : function() {
+ return !any(this.specs, function(spec){
+ return !spec.passed()
+ })
+ },
+
+ isShared : function(){
+ return this.shared
+ },
+
+ isExecutable : function() {
+ return !this.isShared() && this.hasSpecs()
+ }
+ })
+ },
+
+ /**
+ * Specification block object.
+ *
+ * @param {string} description
+ * @param {function} body
+ * @api private
+ */
+
+ Spec : function(description, body) {
+ extend(this, {
+ body: body,
+ description: description,
+ assertions: [],
+
+ // Add passing assertion
+
+ pass : function(message) {
+ this.assertions.push({ passed: true, message: message })
+ if (JSpec.assert) ++JSpec.stats.passes
+ },
+
+ // Add failing assertion
+
+ fail : function(message) {
+ this.assertions.push({ passed: false, message: message })
+ if (JSpec.assert) ++JSpec.stats.failures
+ },
+
+ // Run deferred assertions
+
+ runDeferredAssertions : function() {
+ each(this.assertions, function(assertion){
+ if (assertion.defer) assertion.run().report(), hook('afterAssertion', assertion)
+ })
+ },
+
+ // Find first failing assertion
+
+ failure : function() {
+ return find(this.assertions, function(assertion){
+ return !assertion.passed
+ })
+ },
+
+ // Find all failing assertions
+
+ failures : function() {
+ return select(this.assertions, function(assertion){
+ return !assertion.passed
+ })
+ },
+
+ // Weither or not the spec passed
+
+ passed : function() {
+ return !this.failure()
+ },
+
+ // Weither or not the spec requires implementation (no assertions)
+
+ requiresImplementation : function() {
+ return this.assertions.length == 0
+ },
+
+ // Sprite based assertions graph
+
+ assertionsGraph : function() {
+ return map(this.assertions, function(assertion){
+ return '<span class="assertion ' + (assertion.passed ? 'passed' : 'failed') + '"></span>'
+ }).join('')
+ }
+ })
+ },
+
+ Module : function(methods) {
+ extend(this, methods)
+ },
+
+ JSON : {
+
+ /**
+ * Generic sequences.
+ */
+
+ meta : {
+ '\b' : '\\b',
+ '\t' : '\\t',
+ '\n' : '\\n',
+ '\f' : '\\f',
+ '\r' : '\\r',
+ '"' : '\\"',
+ '\\' : '\\\\'
+ },
+
+ /**
+ * Escapable sequences.
+ */
+
+ escapable : /[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
+
+ /**
+ * JSON encode _object_.
+ *
+ * @param {mixed} object
+ * @return {string}
+ * @api private
+ */
+
+ encode : function(object) {
+ var self = this
+ if (object == undefined || object == null) return 'null'
+ if (object === true) return 'true'
+ if (object === false) return 'false'
+ switch (typeof object) {
+ case 'number': return object
+ case 'string': return this.escapable.test(object) ?
+ '"' + object.replace(this.escapable, function (a) {
+ return typeof self.meta[a] === 'string' ? self.meta[a] :
+ '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4)
+ }) + '"' :
+ '"' + object + '"'
+ case 'object':
+ if (object.constructor == Array)
+ return '[' + map(object, function(val){
+ return self.encode(val)
+ }).join(', ') + ']'
+ else if (object)
+ return '{' + map(object, function(key, val){
+ return self.encode(key) + ':' + self.encode(val)
+ }).join(', ') + '}'
+ }
+ return 'null'
+ }
+ },
+
+ // --- DSLs
+
+ DSLs : {
+ snake : {
+ expect : function(actual){
+ return JSpec.expect(actual)
+ },
+
+ describe : function(description, body) {
+ return JSpec.currentSuite.addSuite(description, body, false)
+ },
+
+ it : function(description, body) {
+ return JSpec.currentSuite.addSpec(description, body)
+ },
+
+ before : function(body) {
+ return JSpec.currentSuite.addHook('before', body)
+ },
+
+ after : function(body) {
+ return JSpec.currentSuite.addHook('after', body)
+ },
+
+ before_each : function(body) {
+ return JSpec.currentSuite.addHook('before_each', body)
+ },
+
+ after_each : function(body) {
+ return JSpec.currentSuite.addHook('after_each', body)
+ },
+
+ before_nested : function(body) {
+ return JSpec.currentSuite.addHook('before_nested', body)
+ },
+
+ after_nested : function(body){
+ return JSpec.currentSuite.addhook('after_nested', body)
+ },
+
+ shared_behaviors_for : function(description, body){
+ return JSpec.currentSuite.addSuite(description, body, true)
+ },
+
+ should_behave_like : function(description) {
+ return JSpec.shareBehaviorsOf(description)
+ }
+ }
+ },
+
+ // --- Methods
+
+ /**
+ * Check if _value_ is 'stop'. For use as a
+ * utility callback function.
+ *
+ * @param {mixed} value
+ * @return {bool}
+ * @api public
+ */
+
+ haveStopped : function(value) {
+ return value === 'stop'
+ },
+
+ /**
+ * Include _object_ which may be a hash or Module instance.
+ *
+ * @param {hash, Module} object
+ * @return {JSpec}
+ * @api public
+ */
+
+ include : function(object) {
+ var module = object.constructor == JSpec.Module ? object : new JSpec.Module(object)
+ this.modules.push(module)
+ if ('init' in module) module.init()
+ if ('utilities' in module) extend(this.defaultContext, module.utilities)
+ if ('matchers' in module) this.addMatchers(module.matchers)
+ if ('reporters' in module) extend(this.reporters, module.reporters)
+ if ('DSLs' in module)
+ each(module.DSLs, function(name, methods){
+ JSpec.DSLs[name] = JSpec.DSLs[name] || {}
+ extend(JSpec.DSLs[name], methods)
+ })
+ return this
+ },
+
+ /**
+ * Add a module hook _name_, which is immediately
+ * called per module with the _args_ given. An array of
+ * hook return values is returned.
+ *
+ * @param {name} string
+ * @param {...} args
+ * @return {array}
+ * @api private
+ */
+
+ hook : function(name, args) {
+ args = toArray(arguments, 1)
+ return inject(JSpec.modules, [], function(results, module){
+ if (typeof module[name] == 'function')
+ results.push(JSpec.evalHook(module, name, args))
+ })
+ },
+
+ /**
+ * Eval _module_ hook _name_ with _args_. Evaluates in context
+ * to the module itself, JSpec, and JSpec.context.
+ *
+ * @param {Module} module
+ * @param {string} name
+ * @param {array} args
+ * @return {mixed}
+ * @api private
+ */
+
+ evalHook : function(module, name, args) {
+ hook('evaluatingHookBody', module, name)
+ return module[name].apply(module, args)
+ },
+
+ /**
+ * Same as hook() however accepts only one _arg_ which is
+ * considered immutable. This function passes the arg
+ * to the first module, then passes the return value of the last
+ * module called, to the following module.
+ *
+ * @param {string} name
+ * @param {mixed} arg
+ * @return {mixed}
+ * @api private
+ */
+
+ hookImmutable : function(name, arg) {
+ return inject(JSpec.modules, arg, function(result, module){
+ if (typeof module[name] == 'function')
+ return JSpec.evalHook(module, name, [result])
+ })
+ },
+
+ /**
+ * Find a shared example suite by its description or name.
+ * First searches parent tree of suites for shared behavior
+ * before falling back to global scoped nested behaviors.
+ *
+ * @param {string} description
+ * @return {Suite}
+ * @api private
+ */
+
+ findSharedBehavior : function(description) {
+ var behavior
+ return (behavior = JSpec.findLocalSharedBehavior(description))
+ ? behavior
+ : JSpec.findGlobalSharedBehavior(description)
+ },
+
+ /**
+ * Find a shared example suite within the current suite's
+ * parent tree by its description or name.
+ *
+ * @param {string} description
+ * @return {Suite}
+ * @api private
+ */
+
+ findLocalSharedBehavior : function(description) {
+ var behavior,
+ currentSuite = JSpec.currentSuite.suite
+ while (currentSuite)
+ if (behavior = find(currentSuite.suites, JSpec.suiteDescriptionPredicate(description)))
+ return behavior
+ else
+ currentSuite = currentSuite.suite
+ },
+
+ /**
+ * Find a shared example suite within the global
+ * scope by its description or name.
+ *
+ * @param {string} description
+ * @return {Suite}
+ * @api private
+ */
+
+ findGlobalSharedBehavior : function(description) {
+ return find(JSpec.suites, JSpec.suiteDescriptionPredicate(description))
+ },
+
+ /**
+ * Build a predicate that will match a suite based on name or description
+ *
+ * @param {string} description
+ * @return {function}
+ * @api private
+ */
+
+ suiteDescriptionPredicate : function(description) {
+ return function(suite){
+ return suite.name === description ||
+ suite.description === description
+ }
+ },
+
+ /**
+ * Share behaviors (specs) of the given suite with
+ * the current suite.
+ *
+ * @param {string} description
+ * @api public
+ */
+
+ shareBehaviorsOf : function(description) {
+ var suite = JSpec.findSharedBehavior(description)
+ if (suite)
+ JSpec.evalBody(suite.body)
+ else
+ throw new Error("failed to find shared behaviors named `" + description + "'")
+ },
+
+
+ /**
+ * Convert arguments to an array.
+ *
+ * @param {object} arguments
+ * @param {int} offset
+ * @return {array}
+ * @api public
+ */
+
+ toArray : function(arguments, offset) {
+ return Array.prototype.slice.call(arguments, offset || 0)
+ },
+
+ /**
+ * Return ANSI-escaped colored string.
+ *
+ * @param {string} string
+ * @param {string} color
+ * @return {string}
+ * @api public
+ */
+
+ color : function(string, color) {
+ if (option('disableColors')) {
+ return string
+ } else {
+ return "\u001B[" + {
+ bold : 1,
+ black : 30,
+ red : 31,
+ green : 32,
+ yellow : 33,
+ blue : 34,
+ magenta : 35,
+ cyan : 36,
+ white : 37
+ }[color] + 'm' + string + "\u001B[0m"
+ }
+ },
+
+ /**
+ * Default matcher message callback.
+ *
+ * @api private
+ */
+
+ defaultMatcherMessage : function(actual, expected, negate, name) {
+ return 'expected ' + puts(actual) + ' to ' +
+ (negate ? 'not ' : '') +
+ name.replace(/_/g, ' ') +
+ ' ' + (expected.length > 1 ?
+ puts.apply(this, expected.slice(1)) :
+ '')
+ },
+
+ /**
+ * Normalize a matcher message.
+ *
+ * When no messge callback is present the defaultMatcherMessage
+ * will be assigned, will suffice for most matchers.
+ *
+ * @param {hash} matcher
+ * @return {hash}
+ * @api public
+ */
+
+ normalizeMatcherMessage : function(matcher) {
+ if (typeof matcher.message != 'function')
+ matcher.message = this.defaultMatcherMessage
+ return matcher
+ },
+
+ /**
+ * Normalize a matcher body
+ *
+ * This process allows the following conversions until
+ * the matcher is in its final normalized hash state.
+ *
+ * - '==' becomes 'actual == expected'
+ * - 'actual == expected' becomes 'return actual == expected'
+ * - function(actual, expected) { return actual == expected } becomes
+ * { match : function(actual, expected) { return actual == expected }}
+ *
+ * @param {mixed} body
+ * @return {hash}
+ * @api public
+ */
+
+ normalizeMatcherBody : function(body) {
+ var captures
+ switch (body.constructor) {
+ case String:
+ if (captures = body.match(/^alias (\w+)/)) return JSpec.matchers[last(captures)]
+ if (body.length < 4) body = 'actual ' + body + ' expected'
+ return { match: function(actual, expected) { return eval(body) }}
+
+ case Function:
+ return { match: body }
+
+ default:
+ return body
+ }
+ },
+
+ /**
+ * Get option value. This method first checks if
+ * the option key has been set via the query string,
+ * otherwise returning the options hash value.
+ *
+ * @param {string} key
+ * @return {mixed}
+ * @api public
+ */
+
+ option : function(key) {
+ return (value = query(key)) !== null ? value :
+ JSpec.options[key] || null
+ },
+
+ /**
+ * Check if object _a_, is equal to object _b_.
+ *
+ * @param {object} a
+ * @param {object} b
+ * @return {bool}
+ * @api private
+ */
+
+ equal: function(a, b) {
+ if (typeof a != typeof b) return
+ if (a === b) return true
+ if (a instanceof RegExp)
+ return a.toString() === b.toString()
+ if (a instanceof Date)
+ return Number(a) === Number(b)
+ if (typeof a != 'object') return
+ if (a.length !== undefined)
+ if (a.length !== b.length) return
+ else
+ for (var i = 0, len = a.length; i < len; ++i)
+ if (!equal(a[i], b[i]))
+ return
+ for (var key in a)
+ if (!equal(a[key], b[key]))
+ return
+ return true
+ },
+
+ /**
+ * Return last element of an array.
+ *
+ * @param {array} array
+ * @return {object}
+ * @api public
+ */
+
+ last : function(array) {
+ return array[array.length - 1]
+ },
+
+ /**
+ * Convert object(s) to a print-friend string.
+ *
+ * @param {...} object
+ * @return {string}
+ * @api public
+ */
+
+ puts : function(object) {
+ if (arguments.length > 1)
+ return map(toArray(arguments), function(arg){
+ return puts(arg)
+ }).join(', ')
+ if (object === undefined) return 'undefined'
+ if (object === null) return 'null'
+ if (object === true) return 'true'
+ if (object === false) return 'false'
+ if (object.an_instance_of) return 'an instance of ' + object.an_instance_of.name
+ if (object.jquery && object.selector.length > 0) return 'selector ' + puts(object.selector)
+ if (object.jquery) return object.get(0).outerHTML
+ if (object.nodeName) return object.outerHTML
+ switch (object.constructor) {
+ case Function: return object.name || object
+ case String:
+ return '"' + object
+ .replace(/"/g, '\\"')
+ .replace(/\n/g, '\\n')
+ .replace(/\t/g, '\\t')
+ + '"'
+ case Array:
+ return inject(object, '[', function(b, v){
+ return b + ', ' + puts(v)
+ }).replace('[,', '[') + ' ]'
+ case Object:
+ object.__hit__ = true
+ return inject(object, '{', function(b, k, v) {
+ if (k == '__hit__') return b
+ return b + ', ' + k + ': ' + (v && v.__hit__ ? '<circular reference>' : puts(v))
+ }).replace('{,', '{') + ' }'
+ default:
+ return object.toString()
+ }
+ },
+
+ /**
+ * Parse an XML String and return a 'document'.
+ *
+ * @param {string} text
+ * @return {document}
+ * @api public
+ */
+
+ parseXML : function(text) {
+ var xmlDoc
+ if (window.DOMParser)
+ xmlDoc = (new DOMParser()).parseFromString(text, "text/xml")
+ else {
+ xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
+ xmlDoc.async = "false"
+ xmlDoc.loadXML(text)
+ }
+ return xmlDoc
+ },
+
+ /**
+ * Escape HTML.
+ *
+ * @param {string} html
+ * @return {string}
+ * @api public
+ */
+
+ escape : function(html) {
+ return html.toString()
+ .replace(/&/gmi, '&')
+ .replace(/"/gmi, '"')
+ .replace(/>/gmi, '>')
+ .replace(/</gmi, '<')
+ },
+
+ /**
+ * Perform an assertion without reporting.
+ *
+ * This method is primarily used for internal
+ * matchers in order retain DRYness. May be invoked
+ * like below:
+ *
+ * does('foo', 'eql', 'foo')
+ * does([1,2], 'include', 1, 2)
+ *
+ * External hooks are not run for internal assertions
+ * performed by does().
+ *
+ * @param {mixed} actual
+ * @param {string} matcher
+ * @param {...} expected
+ * @return {mixed}
+ * @api private
+ */
+
+ does : function(actual, matcher, expected) {
+ var assertion = new JSpec.Assertion(JSpec.matchers[matcher], actual, toArray(arguments, 2))
+ return assertion.run().result
+ },
+
+ /**
+ * Perform an assertion.
+ *
+ * expect(true).to('be', true)
+ * expect('foo').not_to('include', 'bar')
+ * expect([1, [2]]).to('include', 1, [2])
+ *
+ * @param {mixed} actual
+ * @return {hash}
+ * @api public
+ */
+
+ expect : function(actual) {
+ function assert(matcher, args, negate) {
+ var expected = toArray(args, 1)
+ matcher.negate = negate
+ var assertion = new JSpec.Assertion(matcher, actual, expected, negate)
+ hook('beforeAssertion', assertion)
+ if (matcher.defer) assertion.run()
+ else JSpec.currentSpec.assertions.push(assertion.run().report()), hook('afterAssertion', assertion)
+ return assertion.result
+ }
+
+ function to(matcher) {
+ return assert(matcher, arguments, false)
+ }
+
+ function not_to(matcher) {
+ return assert(matcher, arguments, true)
+ }
+
+ return {
+ to : to,
+ should : to,
+ not_to: not_to,
+ should_not : not_to
+ }
+ },
+
+ /**
+ * Strim whitespace or chars.
+ *
+ * @param {string} string
+ * @param {string} chars
+ * @return {string}
+ * @api public
+ */
+
+ strip : function(string, chars) {
+ return string.
+ replace(new RegExp('[' + (chars || '\\s') + ']*$'), '').
+ replace(new RegExp('^[' + (chars || '\\s') + ']*'), '')
+ },
+
+ /**
+ * Call an iterator callback with arguments a, or b
+ * depending on the arity of the callback.
+ *
+ * @param {function} callback
+ * @param {mixed} a
+ * @param {mixed} b
+ * @return {mixed}
+ * @api private
+ */
+
+ callIterator : function(callback, a, b) {
+ return callback.length == 1 ? callback(b) : callback(a, b)
+ },
+
+ /**
+ * Extend an object with another.
+ *
+ * @param {object} object
+ * @param {object} other
+ * @api public
+ */
+
+ extend : function(object, other) {
+ each(other, function(property, value){
+ object[property] = value
+ })
+ },
+
+ /**
+ * Iterate an object, invoking the given callback.
+ *
+ * @param {hash, array} object
+ * @param {function} callback
+ * @return {JSpec}
+ * @api public
+ */
+
+ each : function(object, callback) {
+ if (object.constructor == Array)
+ for (var i = 0, len = object.length; i < len; ++i)
+ callIterator(callback, i, object[i])
+ else
+ for (var key in object)
+ if (object.hasOwnProperty(key))
+ callIterator(callback, key, object[key])
+ },
+
+ /**
+ * Iterate with memo.
+ *
+ * @param {hash, array} object
+ * @param {object} memo
+ * @param {function} callback
+ * @return {object}
+ * @api public
+ */
+
+ inject : function(object, memo, callback) {
+ each(object, function(key, value){
+ memo = (callback.length == 2 ?
+ callback(memo, value):
+ callback(memo, key, value)) ||
+ memo
+ })
+ return memo
+ },
+
+ /**
+ * Destub _object_'s _method_. When no _method_ is passed
+ * all stubbed methods are destubbed. When no arguments
+ * are passed every object found in JSpec.stubbed will be
+ * destubbed.
+ *
+ * @param {mixed} object
+ * @param {string} method
+ * @api public
+ */
+
+ destub : function(object, method) {
+ var captures
+ if (method) {
+ if (object['__prototype__' + method])
+ delete object[method]
+ else
+ object[method] = object['__original__' + method]
+ delete object['__prototype__' + method]
+ delete object['__original____' + method]
+ }
+ else if (object) {
+ for (var key in object)
+ if (captures = key.match(/^(?:__prototype__|__original__)(.*)/))
+ destub(object, captures[1])
+ }
+ else
+ while (JSpec.stubbed.length)
+ destub(JSpec.stubbed.shift())
+ },
+
+ /**
+ * Stub _object_'s _method_.
+ *
+ * stub(foo, 'toString').and_return('bar')
+ *
+ * @param {mixed} object
+ * @param {string} method
+ * @return {hash}
+ * @api public
+ */
+
+ stub : function(object, method) {
+ hook('stubbing', object, method)
+ JSpec.stubbed.push(object)
+ var type = object.hasOwnProperty(method) ? '__original__' : '__prototype__'
+ object[type + method] = object[method]
+ object[method] = function(){}
+ return {
+ and_return : function(value) {
+ if (typeof value == 'function') object[method] = value
+ else object[method] = function(){ return value }
+ }
+ }
+ },
+
+ /**
+ * Map callback return values.
+ *
+ * @param {hash, array} object
+ * @param {function} callback
+ * @return {array}
+ * @api public
+ */
+
+ map : function(object, callback) {
+ return inject(object, [], function(memo, key, value){
+ memo.push(callIterator(callback, key, value))
+ })
+ },
+
+ /**
+ * Returns the first matching expression or null.
+ *
+ * @param {hash, array} object
+ * @param {function} callback
+ * @return {mixed}
+ * @api public
+ */
+
+ any : function(object, callback) {
+ return inject(object, null, function(state, key, value){
+ if (state == undefined)
+ return callIterator(callback, key, value) ? value : state
+ })
+ },
+
+ /**
+ * Returns an array of values collected when the callback
+ * given evaluates to true.
+ *
+ * @param {hash, array} object
+ * @return {function} callback
+ * @return {array}
+ * @api public
+ */
+
+ select : function(object, callback) {
+ return inject(object, [], function(selected, key, value){
+ if (callIterator(callback, key, value))
+ selected.push(value)
+ })
+ },
+
+ /**
+ * Define matchers.
+ *
+ * @param {hash} matchers
+ * @api public
+ */
+
+ addMatchers : function(matchers) {
+ each(matchers, function(name, body){
+ JSpec.addMatcher(name, body)
+ })
+ },
+
+ /**
+ * Define a matcher.
+ *
+ * @param {string} name
+ * @param {hash, function, string} body
+ * @api public
+ */
+
+ addMatcher : function(name, body) {
+ hook('addingMatcher', name, body)
+ if (name.indexOf(' ') != -1) {
+ var matchers = name.split(/\s+/)
+ var prefix = matchers.shift()
+ each(matchers, function(name) {
+ JSpec.addMatcher(prefix + '_' + name, body(name))
+ })
+ }
+ this.matchers[name] = this.normalizeMatcherMessage(this.normalizeMatcherBody(body))
+ this.matchers[name].name = name
+ },
+
+ /**
+ * Add a root suite to JSpec.
+ *
+ * @param {string} description
+ * @param {body} function
+ * @api public
+ */
+
+ describe : function(description, body) {
+ var suite = new JSpec.Suite(description, body, false)
+ hook('addingSuite', suite)
+ this.allSuites.push(suite)
+ this.suites.push(suite)
+ },
+
+ /**
+ * Add a shared example suite to JSpec.
+ *
+ * @param {string} description
+ * @param {body} function
+ * @api public
+ */
+
+ shared_behaviors_for : function(description, body) {
+ var suite = new JSpec.Suite(description, body, true)
+ hook('addingSuite', suite)
+ this.allSuites.push(suite)
+ this.suites.push(suite)
+ },
+
+ /**
+ * Return the contents of a function body.
+ *
+ * @param {function} body
+ * @return {string}
+ * @api public
+ */
+
+ contentsOf : function(body) {
+ return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]
+ },
+
+ /**
+ * Evaluate a JSpec capture body.
+ *
+ * @param {function} body
+ * @param {string} errorMessage (optional)
+ * @return {Type}
+ * @api private
+ */
+
+ evalBody : function(body, errorMessage) {
+ var dsl = this.DSL || this.DSLs.snake
+ var matchers = this.matchers
+ var context = this.context || this.defaultContext
+ var contents = this.contentsOf(body)
+ hook('evaluatingBody', dsl, matchers, context, contents)
+ with (dsl){ with (context) { with (matchers) { eval(contents) }}}
+ },
+
+ /**
+ * Pre-process a string of JSpec.
+ *
+ * @param {string} input
+ * @return {string}
+ * @api private
+ */
+
+ preprocess : function(input) {
+ if (typeof input != 'string') return
+ input = hookImmutable('preprocessing', input)
+ return input.
+ replace(/\t/g, ' ').
+ replace(/\r\n|\n|\r/g, '\n').
+ split('__END__')[0].
+ replace(/([\w\.]+)\.(stub|destub)\((.*?)\)$/gm, '$2($1, $3)').
+ replace(/describe\s+(.*?)$/gm, 'describe($1, function(){').
+ replace(/shared_behaviors_for\s+(.*?)$/gm, 'shared_behaviors_for($1, function(){').
+ replace(/^\s+it\s+(.*?)$/gm, ' it($1, function(){').
+ replace(/^ *(before_nested|after_nested|before_each|after_each|before|after)(?= |\n|$)/gm, 'JSpec.currentSuite.addHook("$1", function(){').
+ replace(/^\s*end(?=\s|$)/gm, '});').
+ replace(/-\{/g, 'function(){').
+ replace(/(\d+)\.\.(\d+)/g, function(_, a, b){ return range(a, b) }).
+ replace(/\.should([_\.]not)?[_\.](\w+)(?: |;|$)(.*)$/gm, '.should$1_$2($3)').
+ replace(/([\/\s]*)(.+?)\.(should(?:[_\.]not)?)[_\.](\w+)\((.*)\)\s*;?$/gm, '$1 expect($2).$3($4, $5)').
+ replace(/, \)/g, ')').
+ replace(/should\.not/g, 'should_not')
+ },
+
+ /**
+ * Create a range string which can be evaluated to a native array.
+ *
+ * @param {int} start
+ * @param {int} end
+ * @return {string}
+ * @api public
+ */
+
+ range : function(start, end) {
+ var current = parseInt(start), end = parseInt(end), values = [current]
+ if (end > current) while (++current <= end) values.push(current)
+ else while (--current >= end) values.push(current)
+ return '[' + values + ']'
+ },
+
+ /**
+ * Report on the results.
+ *
+ * @api public
+ */
+
+ report : function() {
+ this.duration = Number(new Date) - this.start
+ hook('reporting', JSpec.options)
+ new (JSpec.options.reporter || JSpec.reporters.DOM)(JSpec, JSpec.options)
+ },
+
+ /**
+ * Run the spec suites. Options are merged
+ * with JSpec options when present.
+ *
+ * @param {hash} options
+ * @return {JSpec}
+ * @api public
+ */
+
+ run : function(options) {
+ if (any(hook('running'), haveStopped)) return this
+ if (options) extend(this.options, options)
+ this.start = Number(new Date)
+ each(this.suites, function(suite) { JSpec.runSuite(suite) })
+ return this
+ },
+
+ /**
+ * Run a suite.
+ *
+ * @param {Suite} suite
+ * @api public
+ */
+
+ runSuite : function(suite) {
+ if (!suite.isShared())
+ {
+ this.currentSuite = suite
+ this.evalBody(suite.body)
+ suite.ran = true
+ hook('beforeSuite', suite), suite.hook('before'), suite.hook('before_nested')
+ each(suite.specs, function(spec) {
+ hook('beforeSpec', spec)
+ suite.hook('before_each')
+ JSpec.runSpec(spec)
+ hook('afterSpec', spec)
+ suite.hook('after_each')
+ })
+ if (suite.hasSuites()) {
+ each(suite.suites, function(suite) {
+ JSpec.runSuite(suite)
+ })
+ }
+ hook('afterSuite', suite), suite.hook('after_nested'), suite.hook('after')
+ this.stats.suitesFinished++
+ }
+ },
+
+ /**
+ * Report a failure for the current spec.
+ *
+ * @param {string} message
+ * @api public
+ */
+
+ fail : function(message) {
+ JSpec.currentSpec.fail(message)
+ },
+
+ /**
+ * Report a passing assertion for the current spec.
+ *
+ * @param {string} message
+ * @api public
+ */
+
+ pass : function(message) {
+ JSpec.currentSpec.pass(message)
+ },
+
+ /**
+ * Run a spec.
+ *
+ * @param {Spec} spec
+ * @api public
+ */
+
+ runSpec : function(spec) {
+ this.currentSpec = spec
+ try { this.evalBody(spec.body) }
+ catch (e) { fail(e) }
+ spec.runDeferredAssertions()
+ destub()
+ this.stats.specsFinished++
+ this.stats.assertions += spec.assertions.length
+ },
+
+ /**
+ * Require a dependency, with optional message.
+ *
+ * @param {string} dependency
+ * @param {string} message (optional)
+ * @return {JSpec}
+ * @api public
+ */
+
+ requires : function(dependency, message) {
+ hook('requiring', dependency, message)
+ try { eval(dependency) }
+ catch (e) { throw 'JSpec depends on ' + dependency + ' ' + message }
+ return this
+ },
+
+ /**
+ * Query against the current query strings keys
+ * or the queryString specified.
+ *
+ * @param {string} key
+ * @param {string} queryString
+ * @return {string, null}
+ * @api private
+ */
+
+ query : function(key, queryString) {
+ var queryString = (queryString || (main.location ? main.location.search : null) || '').substring(1)
+ return inject(queryString.split('&'), null, function(value, pair){
+ parts = pair.split('=')
+ return parts[0] == key ? parts[1].replace(/%20|\+/gmi, ' ') : value
+ })
+ },
+
+ /**
+ * Ad-hoc POST request for JSpec server usage.
+ *
+ * @param {string} uri
+ * @param {string} data
+ * @api private
+ */
+
+ post : function(uri, data) {
+ if (any(hook('posting', uri, data), haveStopped)) return
+ var request = this.xhr()
+ request.open('POST', uri, false)
+ request.setRequestHeader('Content-Type', 'application/json')
+ request.send(JSpec.JSON.encode(data))
+ },
+
+ /**
+ * Instantiate an XMLHttpRequest.
+ *
+ * Here we utilize IE's lame ActiveXObjects first which
+ * allow IE access serve files via the file: protocol, otherwise
+ * we then default to XMLHttpRequest.
+ *
+ * @return {XMLHttpRequest, ActiveXObject}
+ * @api private
+ */
+
+ xhr : function() {
+ return this.ieXhr() || new JSpec.request
+ },
+
+ /**
+ * Return Microsoft piece of crap ActiveXObject.
+ *
+ * @return {ActiveXObject}
+ * @api public
+ */
+
+ ieXhr : function() {
+ function object(str) {
+ try { return new ActiveXObject(str) } catch(e) {}
+ }
+ return object('Msxml2.XMLHTTP.6.0') ||
+ object('Msxml2.XMLHTTP.3.0') ||
+ object('Msxml2.XMLHTTP') ||
+ object('Microsoft.XMLHTTP')
+ },
+
+ /**
+ * Check for HTTP request support.
+ *
+ * @return {bool}
+ * @api private
+ */
+
+ hasXhr : function() {
+ return JSpec.request || 'ActiveXObject' in main
+ },
+
+ /**
+ * Try loading _file_ returning the contents
+ * string or null. Chain to locate / read a file.
+ *
+ * @param {string} file
+ * @return {string}
+ * @api public
+ */
+
+ tryLoading : function(file) {
+ try { return JSpec.load(file) } catch (e) {}
+ },
+
+ /**
+ * Load a _file_'s contents.
+ *
+ * @param {string} file
+ * @param {function} callback
+ * @return {string}
+ * @api public
+ */
+
+ load : function(file, callback) {
+ if (any(hook('loading', file), haveStopped)) return
+ if ('readFile' in main)
+ return readFile(file)
+ else if (this.hasXhr()) {
+ var request = this.xhr()
+ request.open('GET', file, false)
+ request.send(null)
+ if (request.readyState == 4 &&
+ (request.status == 0 ||
+ request.status.toString().charAt(0) == 2))
+ return request.responseText
+ }
+ else
+ throw new Error("failed to load `" + file + "'")
+ },
+
+ /**
+ * Load, pre-process, and evaluate a file.
+ *
+ * @param {string} file
+ * @param {JSpec}
+ * @api public
+ */
+
+ exec : function(file) {
+ if (any(hook('executing', file), haveStopped)) return this
+ eval('with (JSpec){' + this.preprocess(this.load(file)) + '}')
+ return this
+ }
+ }
+
+ // --- Node.js support
+
+ if (typeof GLOBAL === 'object' && typeof exports === 'object') {
+ var fs = require('fs')
+ quit = process.exit
+ print = require('sys').puts
+ readFile = function(file){
+ return fs.readFileSync(file).toString('utf8')
+ }
+ }
+
+ // --- Utility functions
+
+ var main = this,
+ find = JSpec.any,
+ utils = 'haveStopped stub hookImmutable hook destub map any last pass fail range each option inject select \
+ error escape extend puts query strip color does addMatchers callIterator toArray equal'.split(/\s+/)
+ while (utils.length) eval('var ' + utils[0] + ' = JSpec.' + utils.shift())
+ if (!main.setTimeout) main.setTimeout = function(callback){ callback() }
+
+ // --- Matchers
+
+ addMatchers({
+ equal : "===",
+ eql : "equal(actual, expected)",
+ be : "alias equal",
+ be_greater_than : ">",
+ be_less_than : "<",
+ be_at_least : ">=",
+ be_at_most : "<=",
+ be_a : "actual.constructor == expected",
+ be_an : "alias be_a",
+ be_an_instance_of : "actual instanceof expected",
+ be_null : "actual == null",
+ be_true : "actual == true",
+ be_false : "actual == false",
+ be_undefined : "typeof actual == 'undefined'",
+ be_type : "typeof actual == expected",
+ match : "typeof actual == 'string' ? actual.match(expected) : false",
+ respond_to : "typeof actual[expected] == 'function'",
+ have_length : "actual.length == expected",
+ be_within : "actual >= expected[0] && actual <= last(expected)",
+ have_length_within : "actual.length >= expected[0] && actual.length <= last(expected)",
+
+ receive : { defer : true, match : function(actual, method, times) {
+ var proxy = new JSpec.ProxyAssertion(actual, method, times, this.negate)
+ JSpec.currentSpec.assertions.push(proxy)
+ return proxy
+ }},
+
+ be_empty : function(actual) {
+ if (actual.constructor == Object && actual.length == undefined)
+ for (var key in actual)
+ return false;
+ return !actual.length
+ },
+
+ include : function(actual) {
+ for (var state = true, i = 1; i < arguments.length; i++) {
+ var arg = arguments[i]
+ switch (actual.constructor) {
+ case String:
+ case Number:
+ case RegExp:
+ case Function:
+ state = actual.toString().indexOf(arg) !== -1
+ break
+
+ case Object:
+ state = arg in actual
+ break
+
+ case Array:
+ state = any(actual, function(value){ return equal(value, arg) })
+ break
+ }
+ if (!state) return false
+ }
+ return true
+ },
+
+ throw_error : { match : function(actual, expected, message) {
+ try { actual() }
+ catch (e) {
+ this.e = e
+ var assert = function(arg) {
+ switch (arg.constructor) {
+ case RegExp : return arg.test(e.message || e.toString())
+ case String : return arg == (e.message || e.toString())
+ case Function : return e instanceof arg || e.name == arg.name
+ }
+ }
+ return message ? assert(expected) && assert(message) :
+ expected ? assert(expected) :
+ true
+ }
+ }, message : function(actual, expected, negate) {
+ // TODO: refactor when actual is not in expected [0]
+ var message_for = function(i) {
+ if (expected[i] == undefined) return 'exception'
+ switch (expected[i].constructor) {
+ case RegExp : return 'exception matching ' + puts(expected[i])
+ case String : return 'exception of ' + puts(expected[i])
+ case Function : return expected[i].name || 'Error'
+ }
+ }
+ var exception = message_for(1) + (expected[2] ? ' and ' + message_for(2) : '')
+ return 'expected ' + exception + (negate ? ' not ' : '' ) +
+ ' to be thrown, but ' + (this.e ? 'got ' + puts(this.e) : 'nothing was')
+ }},
+
+ have : function(actual, length, property) {
+ return actual[property] == null ? false : actual[property].length == length
+ },
+
+ have_at_least : function(actual, length, property) {
+ return actual[property] == null ? (length === 0) : actual[property].length >= length
+ },
+
+ have_at_most :function(actual, length, property) {
+ return actual[property] == null || actual[property].length <= length
+ },
+
+ have_within : function(actual, range, property) {
+ var length = actual[property] == undefined ? 0 : actual[property].length
+ return length >= range.shift() && length <= range.pop()
+ },
+
+ have_prop : function(actual, property, value) {
+ var actualVal = actual[property], actualType = typeof actualVal
+ return (actualType == 'function' || actualType == 'undefined') ? false :
+ typeof value === 'undefined' ||
+ does(actual[property],'eql',value)
+ },
+
+ have_property : function(actual, property, value) {
+ var actualVal = actual[property], actualType = typeof actualVal
+ return (actualType == 'function' || actualType == 'undefined') ? false :
+ typeof value === 'undefined' ||
+ value === actualVal
+ }
+ })
+
+})()
--- /dev/null
+
+// JSpec - node - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+JSpec
+.include({
+ name: 'node',
+
+ // --- Matchers
+
+ matchers : {
+ have_enumerable_property: 'actual.propertyIsEnumerable(expected)',
+ have_writable_property: 'Object.getOwnPropertyDescriptor(actual, expected).writable === true',
+ have_configurable_property: 'Object.getOwnPropertyDescriptor(actual, expected).configurable === true',
+ have_keys: 'does(Object.keys(actual), "eql", expected)',
+ have_prototype: 'Object.getPrototypeOf(actual) === expected'
+ }
+})
+
--- /dev/null
+
+// JSpec - Shell - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+;(function(){
+
+ var _quit = quit
+
+ Shell = {
+
+ // --- Global
+
+ main: this,
+
+ // --- Commands
+
+ commands: {
+ quit: ['Terminate the shell', function(){ _quit() }],
+ exit: ['Terminate the shell', function(){ _quit() }],
+ p: ['Inspect an object', function(o){ return o.toSource() }]
+ },
+
+ /**
+ * Start the interactive shell.
+ *
+ * @api public
+ */
+
+ start : function() {
+ for (var name in this.commands)
+ if (this.commands.hasOwnProperty(name))
+ this.commands[name][1].length ?
+ this.main[name] = this.commands[name][1] :
+ this.main.__defineGetter__(name, this.commands[name][1])
+ }
+ }
+
+ Shell.start()
+
+})()
\ No newline at end of file
--- /dev/null
+
+// JSpec - Mock Timers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+;(function(){
+
+ /**
+ * Version.
+ */
+
+ mockTimersVersion = '1.0.2'
+
+ /**
+ * Localized timer stack.
+ */
+
+ var timers = []
+
+ /**
+ * Set mock timeout with _callback_ and timeout of _ms_.
+ *
+ * @param {function} callback
+ * @param {int} ms
+ * @return {int}
+ * @api public
+ */
+
+ setTimeout = function(callback, ms) {
+ var id
+ return id = setInterval(function(){
+ callback()
+ clearInterval(id)
+ }, ms)
+ }
+
+ /**
+ * Set mock interval with _callback_ and interval of _ms_.
+ *
+ * @param {function} callback
+ * @param {int} ms
+ * @return {int}
+ * @api public
+ */
+
+ setInterval = function(callback, ms) {
+ callback.step = ms, callback.current = callback.last = 0
+ return timers[timers.length] = callback, timers.length
+ }
+
+ /**
+ * Destroy timer with _id_.
+ *
+ * @param {int} id
+ * @return {bool}
+ * @api public
+ */
+
+ clearInterval = clearTimeout = function(id) {
+ return delete timers[--id]
+ }
+
+ /**
+ * Reset timers.
+ *
+ * @return {array}
+ * @api public
+ */
+
+ resetTimers = function() {
+ return timers = []
+ }
+
+ /**
+ * Increment each timers internal clock by _ms_.
+ *
+ * @param {int} ms
+ * @api public
+ */
+
+ tick = function(ms) {
+ for (var i = 0, len = timers.length; i < len; ++i)
+ if (timers[i] && (timers[i].current += ms))
+ if (timers[i].current - timers[i].last >= timers[i].step) {
+ var times = Math.floor((timers[i].current - timers[i].last) / timers[i].step)
+ var remainder = (timers[i].current - timers[i].last) % timers[i].step
+ timers[i].last = timers[i].current - remainder
+ while (times-- && timers[i]) timers[i]()
+ }
+ }
+
+})()
\ No newline at end of file
--- /dev/null
+
+// JSpec - XHR - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
+
+(function(){
+
+ var lastRequest
+
+ // --- Original XMLHttpRequest
+
+ var OriginalXMLHttpRequest = 'XMLHttpRequest' in this ?
+ XMLHttpRequest :
+ function(){}
+ var OriginalActiveXObject = 'ActiveXObject' in this ?
+ ActiveXObject :
+ undefined
+
+ // --- MockXMLHttpRequest
+
+ var MockXMLHttpRequest = function() {
+ this.requestHeaders = {}
+ }
+
+ MockXMLHttpRequest.prototype = {
+ status: 0,
+ async: true,
+ readyState: 0,
+ responseXML: null,
+ responseText: '',
+ abort: function(){},
+ onreadystatechange: function(){},
+
+ /**
+ * Return response headers hash.
+ */
+
+ getAllResponseHeaders : function(){
+ return JSpec.inject(this.responseHeaders, '', function(buf, key, val){
+ return buf + key + ': ' + val + '\r\n'
+ })
+ },
+
+ /**
+ * Return case-insensitive value for header _name_.
+ */
+
+ getResponseHeader : function(name) {
+ return this.responseHeaders[name.toLowerCase()]
+ },
+
+ /**
+ * Set case-insensitive _value_ for header _name_.
+ */
+
+ setRequestHeader : function(name, value) {
+ this.requestHeaders[name.toLowerCase()] = value
+ },
+
+ /**
+ * Open mock request.
+ */
+
+ open : function(method, url, async, user, password) {
+ this.user = user
+ this.password = password
+ this.url = url
+ this.readyState = 1
+ this.method = method.toUpperCase()
+ if (async != undefined) this.async = async
+ if (this.async) this.onreadystatechange()
+ },
+
+ /**
+ * Send request _data_.
+ */
+
+ send : function(data) {
+ var self = this
+ this.data = data
+ this.readyState = 4
+ if (this.method == 'HEAD') this.responseText = null
+ this.responseHeaders['content-length'] = (this.responseText || '').length
+ if(this.async) this.onreadystatechange()
+ this.populateResponseXML()
+ lastRequest = function(){
+ return self
+ }
+ },
+
+ /**
+ * Parse request body and populate responseXML if response-type is xml
+ * Based on the standard specification : http://www.w3.org/TR/XMLHttpRequest/
+ */
+ populateResponseXML: function() {
+ var type = this.getResponseHeader("content-type")
+ if (!type || !this.responseText || !type.match(/(text\/xml|application\/xml|\+xml$)/g))
+ return
+ this.responseXML = JSpec.parseXML(this.responseText)
+ }
+ }
+
+ // --- Response status codes
+
+ JSpec.statusCodes = {
+ 100: 'Continue',
+ 101: 'Switching Protocols',
+ 200: 'OK',
+ 201: 'Created',
+ 202: 'Accepted',
+ 203: 'Non-Authoritative Information',
+ 204: 'No Content',
+ 205: 'Reset Content',
+ 206: 'Partial Content',
+ 300: 'Multiple Choice',
+ 301: 'Moved Permanently',
+ 302: 'Found',
+ 303: 'See Other',
+ 304: 'Not Modified',
+ 305: 'Use Proxy',
+ 307: 'Temporary Redirect',
+ 400: 'Bad Request',
+ 401: 'Unauthorized',
+ 402: 'Payment Required',
+ 403: 'Forbidden',
+ 404: 'Not Found',
+ 405: 'Method Not Allowed',
+ 406: 'Not Acceptable',
+ 407: 'Proxy Authentication Required',
+ 408: 'Request Timeout',
+ 409: 'Conflict',
+ 410: 'Gone',
+ 411: 'Length Required',
+ 412: 'Precondition Failed',
+ 413: 'Request Entity Too Large',
+ 414: 'Request-URI Too Long',
+ 415: 'Unsupported Media Type',
+ 416: 'Requested Range Not Satisfiable',
+ 417: 'Expectation Failed',
+ 422: 'Unprocessable Entity',
+ 500: 'Internal Server Error',
+ 501: 'Not Implemented',
+ 502: 'Bad Gateway',
+ 503: 'Service Unavailable',
+ 504: 'Gateway Timeout',
+ 505: 'HTTP Version Not Supported'
+ }
+
+ /**
+ * Mock XMLHttpRequest requests.
+ *
+ * mockRequest().and_return('some data', 'text/plain', 200, { 'X-SomeHeader' : 'somevalue' })
+ *
+ * @return {hash}
+ * @api public
+ */
+
+ function mockRequest() {
+ return { and_return : function(body, type, status, headers) {
+ XMLHttpRequest = MockXMLHttpRequest
+ ActiveXObject = false
+ status = status || 200
+ headers = headers || {}
+ headers['content-type'] = type
+ JSpec.extend(XMLHttpRequest.prototype, {
+ responseText: body,
+ responseHeaders: headers,
+ status: status,
+ statusText: JSpec.statusCodes[status]
+ })
+ }}
+ }
+
+ /**
+ * Unmock XMLHttpRequest requests.
+ *
+ * @api public
+ */
+
+ function unmockRequest() {
+ XMLHttpRequest = OriginalXMLHttpRequest
+ ActiveXObject = OriginalActiveXObject
+ }
+
+ JSpec.include({
+ name: 'Mock XHR',
+
+ // --- Utilities
+
+ utilities : {
+ mockRequest: mockRequest,
+ unmockRequest: unmockRequest
+ },
+
+ // --- Hooks
+
+ afterSpec : function() {
+ unmockRequest()
+ },
+
+ // --- DSLs
+
+ DSLs : {
+ snake : {
+ mock_request: mockRequest,
+ unmock_request: unmockRequest,
+ last_request: function(){ return lastRequest() }
+ }
+ }
+
+ })
+})()
--- /dev/null
+
+require.paths.unshift('spec', 'spec/lib', 'lib')
+require('jspec')
+sass = require('sass')
+
+JSpec
+ .exec('spec/spec.core.js')
+ .run({ reporter: JSpec.reporters.Terminal, fixturePath: 'spec/fixtures', failuresOnly: true })
+ .report()
--- /dev/null
+
+describe 'Sass'
+ before
+ render = function(path, options) {
+ return sass.render(fixture(path + '.sass'), options)
+ }
+
+ expected = function(path) {
+ return fixture(path + '.css')
+ }
+
+ assert = function(path, options) {
+ render(path, options).should.eql expected(path)
+ }
+ end
+
+ describe '.version'
+ it 'should be a triplet'
+ sass.version.should.match(/^\d+\.\d+\.\d+$/)
+ end
+ end
+
+ describe '.render()'
+ describe 'with "cache" enabled'
+ describe 'without "filename"'
+ it 'should throw an error'
+ -{ assert('selectors', { cache: true }) }.should.throw_error 'filename option must be passed when cache is enabled'
+ end
+ end
+
+ describe 'with "filename"'
+ it 'should still work'
+ assert('selectors', { cache: true, filename: 'style.sass' })
+ end
+ end
+ end
+
+ it 'should support complex selectors'
+ assert('selectors')
+ end
+
+ describe '// ...'
+ it 'should be a sass-specific comment'
+ assert('comment')
+ end
+ end
+
+ describe '& ...'
+ it 'should continue a selector'
+ assert('continuation')
+ end
+ end
+
+ describe '{...}'
+ it 'should have access to variables'
+ assert('literal')
+ end
+ end
+
+ describe ':key val'
+ it 'should define a property'
+ assert('properties')
+ end
+
+ describe 'when nested'
+ it 'should traverse correctly'
+ assert('properties.nested')
+ end
+
+ describe 'incorrectly'
+ it 'should throw an error'
+ try { assert('properties.nested.invalid') }
+ catch (e) {
+ e.message.should.eql 'ParseError: on line 3; invalid indentation, to much nesting'
+ }
+ end
+ end
+ end
+
+ describe 'when at the top level'
+ it 'should throw an error'
+ try { assert('properties.invalid') }
+ catch (e) {
+ e.message.should.eql 'ParseError: on line 1; properties must be nested within a selector'
+ }
+ end
+ end
+ end
+
+ describe '=:key val'
+ it 'should expand to -{moz, webkit}-border-radius'
+ assert('properties.expand')
+ end
+ end
+
+ describe '!key = val'
+ it 'should define a variable'
+ assert('variables.regular')
+ end
+ end
+
+ describe 'key: val'
+ it 'should define a variable'
+ assert('variables.alternate')
+ end
+ end
+ end
+
+ describe '+mixin'
+ it 'should create a mixin'
+ assert('mixin')
+ end
+
+ describe 'when the mixin does not exist'
+ try { assert('mixin.undefined') }
+ catch (e) {
+ e.message.should.eql 'ParseError: on line 2; mixin `large\' does not exist'
+ }
+ end
+ end
+
+ describe '.collect()'
+ it 'should return variables defined'
+ var collected = sass.collect(fixture('collect.sass'))
+ collected.variables.should.eql { red: '#ff0000', black: '#000' }
+ end
+
+ it 'should return mixins defined'
+ var collected = sass.collect(fixture('mixin.sass'))
+ collected.mixins.should.have_property 'large'
+ collected.mixins.should.have_property 'striped'
+ end
+ end
+end
\ No newline at end of file
--- /dev/null
+css
+lib-cov
+testing
+.DS_Store
--- /dev/null
+[submodule "support/should"]
+ path = support/should
+ url = git://github.com/visionmedia/should.js.git
--- /dev/null
+test
+support
+testing
+docs
+examples
--- /dev/null
+
+0.9.2 / 2011-03-21
+==================
+
+ * Removed a `console.log()` call
+
+0.9.1 / 2011-03-18
+==================
+
+ * Fixed connect middleware `@import` support. Closes #168
+ The middleware is now smart enough to know when imports
+ change, and will re-compile the target file.
+
+ * Changed middleware `compile` function to return the `Renderer` (API change)
+
+0.9.0 / 2011-03-18
+==================
+
+ * Added `-i, --interactive` for the Stylus REPL (eval stylus expressions, tab-completion etc)
+ * Added link to vim syntax
+ * Changed `p()` built-in to display parens
+ * Changed `--compress -C` to `-c`, and `-css -c` is now `-C`
+ * Fixed; preserve rest-arg expressions. Closes #194
+ * Fixed `*=` in selector, ex `[class*="foo"]`
+ * Fixed `--watch` issue with growl, updated to 1.1.0. Closes #188
+ * Fixed negative floats when compressed. Closes #193 [reported by ludicco]
+
+0.8.0 / 2011-03-14
+==================
+
+ * Added postfix `for`-loop support.
+ Ex: `return n if n % 2 == 0 for n in nums`
+ * Added support for several postfix operators
+ Ex: `border-radius: 5px if true unless false;`
+ * Added `last(expr)` built-in function
+ * Added `sum(nums)` built-in function
+ * Added `avg(nums)` built-in function
+ * Added `join(delim, vals)` built-in function
+ * Added `Evaluator#{currentScope,currentBlock}`
+ * Added multi-line function paramter definition support
+ * Changed; `0` is falsey, `0%`, `0em`, `0px` etc truthy. Closes #160
+ * Fixed `for` implicit __return__ value
+ * Fixed `for` explicit __return__ value
+ * Fixed mixin property ordering
+
+0.7.4 / 2011-03-10
+==================
+
+ * Added `RGBA` node
+ * Added `is a "color"` special-case, true for `HSLA` and `RGBA` nodes.
+Closes #180
+ * Performance; 2.5x faster compiles due to removing use of getters in `Parser` and `Lexer` (yes, they are really slow).
+ * Removed `Color` node
+ * Fixed stylus(1) `--watch` support due to dynamic __@import__ support. Closes #176
+
+0.7.3 / 2011-03-09
+==================
+
+ * Fixed; allow semi-colons for non-css syntax for one-liners
+
+0.7.2 / 2011-03-08
+==================
+
+ * Added `isnt` operator, same as `is not`, and `!=`
+ * Added support for dynamic `@import` expressions
+ * Added `@import` index resolution support
+ * Added `light()` / `dark()` BIFs
+ * Added `compress` option for connect middleware [disfated]
+ * Changed; most built-in functions defined in stylus (`./lib/functions/index.styl`)
+ * Fixed dynamic expressions in `url()`. Closes #105
+
+0.7.1 / 2011-03-07
+==================
+
+ * Fixed connect middleware for 0.4.x
+
+0.7.0 / 2011-03-02
+==================
+
+ * Added `is` and `is not` aliases for `==` and `!=`
+ * Added __@keyframes__ dynamic name support
+ * Fixed units in interpolation
+ * Fixed clamping of HSLA degrees / percentages
+
+0.6.7 / 2011-03-01
+==================
+
+ * Fixed __RGBA__ -> __HSLA__ conversion due to typo
+
+0.6.6 / 2011-03-01
+==================
+
+ * Added string -> unit type coercion support aka `5px + "10"` will give `15px`
+ * Added `warn` option Closes #152
+ Currently this only reports on re-definition of functions
+ * Added '$' as a valid identifier character
+ * Added `mixin` local variable for function introspection capabilities. Closes #162
+ * Fixed typo, `Unit#toBoolean()` is now correct
+ * Fixed interpolation function calls. Closes #156
+ * Fixed mixins within Media node. Closes #153
+ * Fixed function call in ret val. Closes #154
+
+0.6.5 / 2011-02-24
+==================
+
+ * Fixed parent ref `&` mid-selector bug. Closes #148 [reported by visnu]
+
+0.6.4 / 2011-02-24
+==================
+
+ * Fixed for within brackets. Closes #146
+
+0.6.3 / 2011-02-22
+==================
+
+ * Fixed single-ident selectors. Closes #142
+ * Fixed cyclic __@import__ with file of the same name. Closes #143
+
+0.6.2 / 2011-02-21
+==================
+
+ * Added stylus(1) growl support when using `--watch`
+ * Added __@import__ watching support to stylus(1). Closes #134
+ * Changed; stylus(1) only throws when `--watch` is not used
+ * Fixed `darken-by()` BIF
+ * Fixed __@import__ literal semi-colon. Closes #140
+
+0.6.1 / 2011-02-18
+==================
+
+ * Fixed evaluation of nodes after a return. Closes #139
+
+0.6.0 / 2011-02-18
+==================
+
+ * Added `stylus(1)` direct css to stylus file conversion [Mario]
+ For example instead of `$ stylus --css < foo.css > foo.styl`
+ you may now either `$ stylus --css foo.css` or provide
+ a destination path `$ stylus --css foo.css /tmp/out.styl`.
+
+ * Added postfix conditionals. Closes #74
+ Expressive ruby-ish syntax, ex: `padding 5px if allow-padding`.
+
+0.5.3 / 2011-02-17
+==================
+
+ * Added `in` operator. `3 in nums`, `padding in props` etc
+ * Added `Expression#hash`, hashing all of the nodes in order
+ * Added tests for conditionals with braces. Closes #136
+ * Fixed ids that are also valid colors. Closes #137
+
+0.5.2 / 2011-02-15
+==================
+
+ * Fixed spaces after "}" with css-style. Closes #131
+ * Fixed single-line css-style support. Closes #130
+
+0.5.1 / 2011-02-11
+==================
+
+ * Fixed mixin property ordering. Closes #125
+
+0.5.0 / 2011-02-09
+==================
+
+ * Added `lighten-by()` BIF
+ * Added `darken-by()` BIF
+
+0.4.1 / 2011-02-09
+==================
+
+ * Added support for function definition braces
+ * Fixed issue with invalid color output. Closes #127
+
+0.4.0 / 2011-02-07
+==================
+
+ * Added css-style syntax support
+ * Fixed support for `*` selector within __@media__ blocks
+
+0.3.1 / 2011-02-04
+==================
+
+ * Fixed property disambiguation logic. Closes #117
+ You no longer need to add a trailing comma when
+ chaining selectors such as 'td:nth-child(2)\ntd:nth-child(3)'
+
+0.3.0 / 2011-02-04
+==================
+
+ * Added more assignment operators. Closes #77
+ +=, -=, *=, /=, and %=
+
+0.2.1 / 2011-02-02
+==================
+
+ * Fixed `--compress` when passing files for stylus(1). Closes #115
+ * Fixed bug preventing absolute paths from being passed to `@import`
+ * Fixed `opposite-position()` with nested expressions, unwrapping
+ * Fixed a couple global var leaks [aheckmann]
+
+0.2.0 / 2011-02-01
+==================
+
+ * Added; `url()` utilizing general lookup paths.
+ This means that `{ paths: [] }` is optional now, as lookups
+ will be relative to the file being rendered by default.
+
+ * Added `-w, --watch` support to stylus(1). Closes #113
+
+0.1.0 / 2011-02-01
+==================
+
+ * Added `opposite-position(positions)` built-in function
+ * Added `image-lookup(path)` built-in function
+ * Added `-o, --out <dir>` support to stylus(1)
+ * Added `stylus [file|dir ...]` support
+ * Added; defaulting paths to `[CWD]` for stylus(1)
+ * Changed; `unquote()` using `Literal` node
+ * Changed; utilizing `Literal` in place of some `Ident`s
+
+0.0.2 / 2011-01-31
+==================
+
+ * Added optional property colon support. Closes #110
+ * Added `--version` to stylus(1)
+
+0.0.1 / 2011-01-31
+==================
+
+ * Initial release
\ No newline at end of file
--- /dev/null
+(The MIT License)
+
+Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- /dev/null
+
+SRC = $(shell find lib -name "*.js")
+TM_BUNDLE = editors/Stylus.tmbundle
+TM_BUNDLE_DEST = ~/Library/Application\ Support/TextMate/Bundles
+
+test: test-integration
+
+test-integration:
+ @node test/run.js
+
+install-bundle:
+ cp -fr $(TM_BUNDLE) $(TM_BUNDLE_DEST)
+
+update-bundle:
+ cp -fr $(TM_BUNDLE_DEST)/Stylus.tmbundle editors
+
+benchmark:
+ @node bm.js
+
+.PHONY: test test-integration install-bundle update-bundle benchmark
\ No newline at end of file
--- /dev/null
+
+# Stylus
+
+ Stylus is a revolutionary new language, providing an efficient, dynamic, and expressive way to generate CSS.
+
+## Installation
+
+ $ npm install stylus
+
+### Example
+
+ border-radius()
+ -webkit-border-radius arguments
+ -moz-border-radius arguments
+ border-radius arguments
+
+ body a
+ font 12px/1.4 "Lucida Grande", Arial, sans-serif
+ background black
+ color #ccc
+
+ form input
+ padding 5px
+ border 1px solid
+ border-radius 5px
+
+compiles to:
+
+ body a {
+ font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
+ background: #000;
+ color: #ccc;
+ }
+ form input {
+ padding: 5px;
+ border: 1px solid;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+ }
+
+### Features
+
+ Stylus has _many_ features, click the links below for detailed documentation.
+
+ - [css syntax](stylus/blob/master/docs/css-style.md) support
+ - [mixins](stylus/blob/master/docs/mixins.md)
+ - [variables](stylus/blob/master/docs/variables.md)
+ - [interpolation](stylus/blob/master/docs/interpolation.md)
+ - arithmetic, logical, and equality [operators](stylus/blob/master/docs/operators.md)
+ - [importing](stylus/blob/master/docs/import.md) of other stylus sheets
+ - [introspection api](stylus/blob/master/docs/introspection.md)
+ - type coercion
+ - [conditionals](stylus/blob/master/docs/conditionals.md)
+ - [iteration](stylus/blob/master/docs/iteration.md)
+ - nested [selectors](stylus/blob/master/docs/selectors.md)
+ - parent reference
+ - in-language [functions](stylus/blob/master/docs/functions.md)
+ - [variable arguments](stylus/blob/master/docs/vargs.md)
+ - built-in [functions](stylus/blob/master/docs/bifs.md) (over 25)
+ - optional [image inlining](stylus/blob/master/docs/functions.url.md)
+ - optional compression
+ - JavaScript [API](stylus/blob/master/docs/js.md)
+ - extremely terse syntax
+ - stylus [executable](stylus/blob/master/docs/executable.md)
+ - [error reporting](stylus/blob/master/docs/error-reporting.md)
+ - single-line and multi-line [comments](stylus/blob/master/docs/comments.md)
+ - css [literal](stylus/blob/master/docs/literal.md)
+ - character [escaping](stylus/blob/master/docs/escape.md)
+ - [@keyframes](stylus/blob/master/docs/keyframes.md) support
+ - [@font-face](stylus/blob/master/docs/font-face.md) support
+ - [@media](stylus/blob/master/docs/media.md) support
+ - Connect [Middleware](stylus/blob/master/docs/middleware.md)
+ - TextMate [bundle](stylus/blob/master/docs/textmates.md)
+ - VIM [Syntax](https://github.com/wavded/vim-stylus)
+
+### Framework Support
+
+ - [Connect](stylus/blob/master/docs/middleware.md)
+ - [Ruby On Rails](https://github.com/lucasmazza/stylus_rails)
+
+### Screencasts
+
+ - [Stylus Intro](http://screenr.com/bNY)
+ - [CSS Syntax & Postfix Conditionals](http://screenr.com/A8v)
+
+### Authors
+
+ - [TJ Holowaychuk (visionmedia)](http://github.com/visionmedia)
+
+### More Information
+
+ - Language [comparisons](stylus/blob/master/docs/compare.md)
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+ , stylus = require('../')
+ , basename = require('path').basename
+ , dirname = require('path').dirname
+ , join = require('path').join
+ , growl = require('growl');
+
+/**
+ * Arguments.
+ */
+
+var args = process.argv.slice(2);
+
+/**
+ * Compare flag.
+ */
+
+var compare = false;
+
+/**
+ * Compress flag.
+ */
+
+var compress = false;
+
+/**
+ * CSS conversion flag.
+ */
+
+var convertCSS = false;
+
+/**
+ * Files to processes.
+ */
+
+var files = [];
+
+/**
+ * Destination directory.
+ */
+
+var dest;
+
+/**
+ * Watcher hash.
+ */
+
+var watchers;
+
+/**
+ * Enable REPL.
+ */
+
+var interactive;
+
+/**
+ * Usage docs.
+ */
+
+var usage = [
+ ''
+ , ' Usage: stylus [options] [command] [< in [> out]]'
+ , ' [file|dir ...]'
+ , ''
+ , ' Commands:'
+ , ''
+ , ' help <prop> Opens help info for <prop> in'
+ , ' your default browser. (osx only)'
+ , ''
+ , ' Options:'
+ , ''
+ , ' -i, --interactive Start interactive REPL'
+ , ' -w, --watch Watch file(s) for changes and re-compile'
+ , ' -o, --out <dir> Output to <dir> when passing files'
+ , ' -C, --css <src> [dest] Convert css input to stylus'
+ , ' -c, --compress Compress css output'
+ , ' -d, --compare Display input along with output'
+ , ' -V, --version Display the version of stylus'
+ , ' -h, --help Display help information'
+ , ''
+].join('\n');
+
+/**
+ * Handle arguments.
+ */
+
+var arg;
+while (args.length) {
+ arg = args.shift();
+ switch (arg) {
+ case '-h':
+ case '--help':
+ console.log(usage);
+ process.exit(1);
+ case '-d':
+ case '--compare':
+ compare = true;
+ break;
+ case '-c':
+ case '--compress':
+ compress = true;
+ break;
+ case '-C':
+ case '--css':
+ convertCSS = true;
+ break;
+ case '-V':
+ case '--version':
+ console.log(stylus.version);
+ process.exit(0);
+ break;
+ case '-o':
+ case '--out':
+ dest = args.shift();
+ if (!dest) throw new Error('--out <dir> required');
+ break;
+ case 'help':
+ var name = args.shift();
+ if (!name) throw new Error('help <property> required');
+ help(name);
+ break;
+ case '-i':
+ case '--repl':
+ case '--interactive':
+ interactive = true;
+ break;
+ case '-w':
+ case '--watch':
+ watchers = {};
+ break;
+ default:
+ files.push(arg);
+ }
+}
+
+// if --watch is used, assume we are
+// not working with stdio
+
+if (watchers && !files.length) {
+ files = fs.readdirSync(process.cwd())
+ .filter(function(file){
+ return file.match(/\.styl$/);
+ });
+}
+
+/**
+ * Open the default browser to the CSS property `name`.
+ *
+ * @param {String} name
+ */
+
+function help(name) {
+ var url = 'https://developer.mozilla.org/en/CSS/' + name
+ , exec = require('child_process').exec;
+ exec('open "' + url + '"', function(){
+ process.exit(0);
+ });
+}
+
+// Compilation options
+
+var options = {
+ filename: 'stdin'
+ , compress: compress
+ , paths: [process.cwd()]
+};
+
+// Buffer stdin
+
+var str = '';
+
+// Convert css to stylus
+
+if (convertCSS) {
+ switch (files.length) {
+ case 2:
+ compileCSSFile(files[0], files[1]);
+ break;
+ case 1:
+ compileCSSFile(files[0], files[0].replace('.css', '.styl'));
+ break;
+ default:
+ var stdin = process.openStdin();
+ stdin.setEncoding('utf8');
+ stdin.on('data', function(chunk){ str += chunk; });
+ stdin.on('end', function(){
+ var out = stylus.convertCSS(str);
+ console.log(out);
+ });
+ }
+} else if (interactive) {
+ repl();
+} else {
+ if (files.length) {
+ compileFiles(files);
+ } else {
+ compileStdio();
+ }
+}
+
+/**
+ * Start stylus REPL.
+ */
+
+function repl() {
+ var options = { filename: 'stdin', imports: [__dirname + '/../lib/functions'] }
+ , parser = new stylus.Parser('', options)
+ , evaluator = new stylus.Evaluator(parser.parse(), options)
+ , rl = require('readline')
+ , repl = rl.createInterface(process.stdin, process.stdout, true)
+ , global = evaluator.global.scope;
+
+ // expose BIFs
+ evaluator.evaluate();
+
+ // readline
+ repl.setPrompt('> ');
+ repl.prompt();
+
+ // HACK: flat-list auto-complete
+ repl._tabComplete = function(){
+ var out = this.output
+ , line = this.line
+ , keys = Object.keys(global.locals)
+ , len = keys.length
+ , words = line.split(/\s+/)
+ , word = words.pop()
+ , names = []
+ , name
+ , obj
+ , key;
+
+ // find words that match
+ for (var i = 0; i < len; ++i) {
+ key = keys[i];
+ if (0 == key.indexOf(word)) {
+ names.push(key);
+ }
+ }
+
+ // several candidates
+ if (names.length > 1) {
+ out.write('\r\n\r\n\033[90m');
+ names.forEach(function(name){
+ var node = global.lookup(name);
+ switch (node.nodeName) {
+ case 'function':
+ out.write(' - ' + node + '\r\n');
+ break;
+ default:
+ out.write(' - ' + name + '\r\n');
+ }
+ });
+ out.write('\r\n\033[0m');
+ this._refreshLine();
+ // single candidate
+ } else if (names.length) {
+ name = names.pop();
+ obj = global.lookup(name);
+ name = name.replace(word, '');
+ switch (obj.nodeName) {
+ case 'function':
+ this._insertString(name + '()');
+ this.cursor--;
+ break;
+ default:
+ this._insertString(name);
+ }
+ this._refreshLine();
+ }
+ };
+
+ repl.on('line', function(line){
+ if (!line.trim().length) return repl.prompt();
+ parser = new stylus.Parser(line, options);
+ parser.state.push('expression');
+ evaluator.return = true;
+ try {
+ var expr = parser.parse();
+ var ret = evaluator.visit(expr);
+ ret = ret.nodes[ret.nodes.length - 1];
+ ret = ret.toString();
+ if ('(' == ret[0]) ret = ret.replace(/^\(|\)$/g, '');
+ console.log('\033[90m=> \033[0m' + highlight(ret));
+ repl.prompt();
+ } catch (err) {
+ console.error('\033[31merror: %s\033[0m', err.message || err.stack);
+ repl.prompt();
+ }
+ });
+
+ repl.on('SIGINT', function(){
+ console.log();
+ process.exit(0);
+ });
+}
+
+/**
+ * Highlight the given string of stylus.
+ */
+
+function highlight(str) {
+ return str
+ .replace(/(#)?(\d+(\.\d+)?)/g, function($0, $1, $2){
+ return $1 ? $0 : '\033[36m' + $2 + '\033[0m';
+ })
+ .replace(/(#[\da-fA-F]+)/g, '\033[33m$1\033[0m')
+ .replace(/('.*?'|".*?")/g, '\033[32m$1\033[0m');
+}
+
+/**
+ * Convert a CSS file to a Styl file
+ */
+
+function compileCSSFile(file, fileOut) {
+ fs.lstat(file, function(err, stat){
+ if (err) throw err;
+ if (stat.isFile()) {
+ fs.readFile(file, 'utf8', function(err, str){
+ if (err) throw err;
+ var styl = stylus.convertCSS(str);
+ fs.writeFile(fileOut, styl, function(err){
+ if (err) throw err;
+ });
+ });
+ }
+ });
+}
+
+/**
+ * Compile with stdio.
+ */
+
+function compileStdio() {
+ var stdin = process.openStdin();
+ stdin.setEncoding('utf8');
+ stdin.on('data', function(chunk){ str += chunk; });
+ stdin.on('end', function(){
+ // Compile to css
+ stylus(str, options).render(function(err, css){
+ if (err) throw err;
+ if (compare) {
+ console.log('\n\x1b[1mInput:\x1b[0m');
+ console.log(str);
+ console.log('\n\x1b[1mOutput:\x1b[0m');
+ }
+ console.log(css);
+ if (compare) console.log();
+ });
+ });
+}
+
+/**
+ * Compile the given files.
+ */
+
+function compileFiles(files) {
+ files.forEach(compileFile);
+}
+
+/**
+ * Compile the given file.
+ */
+
+function compileFile(file) {
+ // ensure file exists
+ fs.lstat(file, function(err, stat){
+ if (err) throw err;
+ // file
+ if (stat.isFile()) {
+ fs.readFile(file, 'utf8', function(err, str){
+ if (err) throw err;
+ options.filename = file;
+ options._imports = [];
+ stylus(str, options).render(function(err, css){
+ watchImports(file, options._imports);
+ if (err) {
+ if (watchers) {
+ console.error(err.stack || err.message);
+ growl.notify(err.message, { title: 'Stylus error' });
+ } else {
+ throw err;
+ }
+ } else {
+ writeFile(file, css);
+ }
+ });
+ });
+ // directory
+ } else if (stat.isDirectory()) {
+ fs.readdir(file, function(err, files){
+ if (err) throw err;
+ files.filter(function(path){
+ return path.match(/\.styl$/);
+ }).map(function(path){
+ return file + '/' + path;
+ }).forEach(compileFile);
+ });
+ }
+ });
+}
+
+/**
+ * Write the given css output.
+ */
+
+function writeFile(file, css) {
+ // --out support
+ var path = dest
+ ? dest + '/' + basename(file, '.styl') + '.css'
+ : file.replace('.styl', '.css');
+ fs.writeFile(path, css, function(err){
+ if (err) throw err;
+ console.log(' \033[90mcompiled\033[0m %s', path);
+ // --watch support
+ watch(file, compileFile);
+ });
+}
+
+/**
+ * Watch the given `file` and invoke `fn` when modified.
+ */
+
+function watch(file, fn) {
+ // not watching
+ if (!watchers) return;
+
+ // already watched
+ if (watchers[file]) return;
+
+ // watch the file itself
+ watchers[file] = true;
+ console.log(' \033[90mwatching\033[0m %s', file);
+ fs.watchFile(file, { interval: 50 }, function(curr, prev){
+ if (curr.mtime > prev.mtime) fn(file);
+ });
+}
+
+/**
+ * Watch `imports`, re-compiling `file` when they change.
+ */
+
+function watchImports(file, imports) {
+ imports.forEach(function(import){
+ if (!import.path) return;
+ watch(import.path, function(){
+ compileFile(file);
+ });
+ });
+}
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env node
+
+/**
+ * Module dependencies.
+ */
+
+try {
+ var stylus = require('stylus');
+} catch (err) {
+ var stylus = require('../lib/stylus');
+}
+
+/**
+ * Banner.
+ */
+
+var banner = '\n\
+ \n\
+ _ _ \n\
+ ___| |_ _ _| |_ _ ___ \n\
+ / __| __| | | | | | | / __| \n\
+ \\__ \\ |_| |_| | | |_| \\__ \\ \n\
+ |___/\\__|\\__, |_|\\__,_|___/ \n\
+ |___/ \n\
+ \n\
+';
+
+/**
+ * Steps.
+ */
+
+var steps = [];
+
+/**
+ * Clear the screen and move the cursor up.
+ */
+
+function clear() {
+ console.log('\x1b[1J\x1b[H');
+}
+
+/**
+ * Output "press enter" message.
+ */
+
+function enter() {
+ process.stdout.write('\x1b[90mpress enter to continue:\x1b[0m ');
+}
+
+/**
+ * Initialize a `Step` with the given data.
+ *
+ * @param {String} title
+ * @param {String} desc
+ * @param {String} src
+ * @param {Function} fn
+ */
+
+function Step(title, desc, src, fn) {
+ var self = this;
+ this.n = steps.length;
+ this.src = src;
+ desc = desc.replace(/\_([^_]+)\_/g, '\x1b[33m$1\x1b[90m');
+
+ this.next = function(){
+ var step = steps[self.n + 1];
+ if (step) {
+ step.display();
+ } else {
+ console.log(' THE END\n');
+ process.exit(0);
+ }
+ };
+
+ this.display = function(retry){
+ if (!retry) {
+ console.log(' %d) \x1b[1m%s\x1b[0m\n', self.n, title);
+ console.log(' \x1b[90m%s\x1b[0m', desc);
+ }
+ console.log('\n%s\n', src);
+ console.log('\x1b[90m--------------------\x1b[0m \n');
+ this.input();
+ };
+
+ this.input = function(){
+ stdin.resume();
+ var buf = '';
+ stdin.on('data', function callback(chunk){
+ if (0 == chunk.indexOf('quit')) process.exit(1);
+ var dot = '.' == chunk[0] && '\n' == chunk[1]
+ , equal = buf.trim() == self.src.trim();
+ if (dot || equal) {
+ stdin.pause();
+ stdin.removeListener('data', callback);
+ stylus.render(buf, { filename: 'stdin' }, function(err, css){
+ if (err) {
+ console.log('\n\x1b[31mError: ' + err.message + '\x1b[0m\n');
+ self.display(true);
+ return;
+ }
+ clear();
+ console.log('\x1b[90m-------------------- stylus\x1b[0m \n');
+ console.log(buf.replace(/^/gm, ' '));
+ console.log('\x1b[90m-------------------- css\x1b[0m \n');
+ console.log(css.replace(/^/gm, ' '));
+ console.log();
+ enter();
+ stdin.resume();
+ stdin.once('data', function(){
+ clear();
+ self.next();
+ });
+ });
+ return;
+ }
+ buf += chunk;
+ });
+ };
+}
+
+/**
+ * Step definitions.
+ */
+
+steps.push(new Step(
+ 'Selector Properties'
+ , 'The Stylus grammar has indentation-based blocks,\n'
+ + ' meaning one does not surround selector properties\n'
+ + ' using braces _{_ _}_, but uses an indent of two \n'
+ + ' spaces, or a single tab.\n'
+ + '\n'
+ + ' To get started, type the stylus you see below\n'
+ + ' and then press return a few times or type _"."_ to render.'
+ , 'body\n color black'));
+
+steps.push(new Step(
+ 'Multiple Selectors'
+ , 'Blocks can be applied to several selectors at once\n'
+ + ' by separating them via comma, or newline.\n'
+ + '\n'
+ + ' Both examples shown below are equivalent.'
+
+ , 'a.button, input[type=button]\n'
+ + ' border 1px solid #eee\n'
+ + ' padding 5px\n\n'
+ + 'a.button\n'
+ + 'input[type=button]\n'
+ + ' border 1px solid #eee\n'
+ + ' padding 5px'
+ ));
+
+steps.push(new Step(
+ 'Nested Selectors'
+ , 'Selectors may also be nested.\n'
+
+ , 'ul\n'
+ + ' li\n'
+ + ' a\n'
+ + ' color black\n'
+ ));
+
+steps.push(new Step(
+ 'Variables'
+ , 'Stylus allows you to define variables by utilizing\n'
+ + ' the _=_ operator, much like you would in any other language.\n'
+ + '\n'
+ + ' These variables may be assigned to _numbers_, _strings_, _booleans_,\n'
+ + ' and virtually everything else you see in css.'
+
+ , 'size = 14px\n\n'
+ + 'body\n'
+ + ' font size Arial, sans-serif'
+ ));
+
+steps.push(new Step(
+ 'Conditional Assignment'
+ , 'The conditional assignment operator _?=_ may be used to\n'
+ + ' define a variable only when previously undefined.'
+
+ , 'size = 14px\n\n'
+ + 'body\n'
+ + ' size ?= 22px\n'
+ + ' font size Arial, sans-serif'
+ ));
+
+steps.push(new Step(
+ 'Arithmetic'
+ , 'A variety of binary arithmetic operators are supported\n'
+ + ' as well as unary operators such as _-_, _+_, and _~_.'
+
+ , 'size = 14px\n'
+ + 'large-size = size * 2\n'
+ + '\n'
+ + 'body\n'
+ + ' font large-size\n'
+ + '\n'
+ + 'p\n'
+ + ' margin-left -(size - 2)'
+ ));
+
+steps.push(new Step(
+ 'Coercion'
+ , 'Arithmetic operations coerce the right-hand operand when\n'
+ + ' applicable, for example converting _2s_ in _1000ms + 2s_\n'
+ + ' into _2000ms_ before evaluating the expression.\n'
+ + '\n'
+ + ' Examples:\n'
+ + ' _15px_ - _5_\n'
+ + ' _#000_ + _#eee_\n'
+ + ' _#fff_ - rgba(_0_,_0_,_0_,_.5_)\n'
+ + ' _#fff_ / _2_\n'
+ + ' _5in_ - _3cm_\n'
+
+ , 'duration = 2s\n\n'
+ + '.fade\n'
+ + ' -webkit-transition opacity duration - 1500ms linear'
+ ));
+
+steps.push(new Step(
+ 'Functions'
+ , 'Stylus functions may act as mixins or have a return value.\n'
+ + 'For example here we use the unit() built-in function to.\n'
+ + 'forcing both unit\'s type to _px_, and then add them.\n'
+ + '\n'
+ + 'Note that we may also use the _return_ keyword, however it\n'
+ + 'is optional in most cases.'
+
+ , 'add(a, b)\n'
+ + ' a = unit(a, "px")\n'
+ + ' b = unit(b, "px")\n'
+ + ' a + b\n'
+ + '\n'
+ + 'body\n'
+ + ' padding add(5px, 10px)\n'
+ + ' margin add(5, 10)'
+ ));
+
+steps.push(new Step(
+ 'Mixins'
+ , 'Mixins are defined in the same manner as functions\n'
+ + 'with return values, however they "mix in" their properties\n'
+ + 'and selectors into the caller.\n'
+ + '\n'
+ + 'Mixin parens are optional in most cases, so we may apply\n'
+ + 'the transparently.'
+
+ , 'border-radius(n)\n'
+ + ' -webkit-border-radius n\n'
+ + ' -moz-border-radius n\n'
+ + ' border-radius n\n'
+ + '\n'
+ + 'body\n'
+ + ' border-radius(5px)\n'
+ + '\n'
+ + 'form input\n'
+ + ' border-radius 5px'
+ ));
+
+/**
+ * Start tutorial.
+ */
+
+clear();
+console.log('\x1b[1m' + banner + '\x1b[0m');
+console.log('\n Welcome to the stylus interactive tutorial.\n');
+console.log(' - To quit at any time type \x1b[1mquit\x1b[0m.');
+console.log(' - To force rendering type "." and press enter,');
+console.log(' however source will be automatically rendered');
+console.log(' when it matches the step\'s source.');
+console.log();
+enter();
+
+var stdin = process.openStdin();
+stdin.setEncoding('utf8');
+
+stdin.once = function(event, fn){
+ this.on(event, function callback(chunk){
+ stdin.removeListener(event, callback);
+ fn(chunk);
+ });
+};
+
+stdin.once('data', function(chunk){
+ stdin.pause();
+ clear();
+ steps[0].display();
+});
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var stylus = require('./');
+
+var times = 200
+ , n = times
+ , start = new Date;
+
+console.log('compiling %d times', times);
+
+while (n--) {
+ stylus('body\n color: white;\n background: url(/images/foo.png)\n a\n &:hover\n text-decoration: underline;')
+ .render(function(err, css){});
+}
+
+var duration = new Date - start;
+console.log(' duration: %dms', duration);
+console.log(' average: %dms', duration / times);
+console.log(' per second: %d', (times / (duration / 1000)).toFixed(1));
--- /dev/null
+
+## Built-in Functions
+
+### red(color)
+
+Return the red component of the given `color`.
+
+ red(#c00)
+ // => 204
+
+### green(color)
+
+Return the green component of the given `color`.
+
+ green(#0c0)
+ // => 204
+
+### blue(color)
+
+Return the blue component of the given `color`.
+
+ red(#00c)
+ // => 204
+
+### alpha(color)
+
+Return the alpha component of the given `color`.
+
+ alpha(#fff)
+ // => 1
+
+ alpha(rgba(0,0,0,0.3))
+ // => 0.3
+
+### dark(color)
+
+Check if `color` is dark:
+
+ dark(black)
+ // => true
+
+ dark(#005716)
+ // => true
+
+ dark(white)
+ // => false
+
+
+### light(color)
+
+Check if `color` is light:
+
+ light(black)
+ // => false
+
+ light(white)
+ // => true
+
+ light(#00FF40)
+ // => true
+
+### hue(color)
+
+Return the hue of the given `color`.
+
+ hue(hsla(50deg, 100%, 80%))
+ // => 50deg
+
+### saturation(color)
+
+Return the saturation of the given `color`.
+
+ hue(hsla(50deg, 100%, 80%))
+ // => 100%
+
+### lightness(color)
+
+Return the lightness of the given `color`.
+
+ hue(hsla(50deg, 100%, 80%))
+ // => 80%
+
+### typeof(node)
+
+Return type of `node` as a string.
+
+ type(12)
+ // => 'unit'
+
+ typeof(12)
+ // => 'unit'
+
+ typeof(#fff)
+ // => 'rgba'
+
+ type-of(#fff)
+ // => 'rgba'
+
+Aliased as `type-of` and `type`.
+
+### unit(unit[, type])
+
+Return a string for the type of `unit` or an empty string,
+or assign the given `type` without unit conversion.
+
+ unit(10)
+ // => ''
+
+ unit(15in)
+ // => 'in'
+
+ unit(15%, 'px')
+ // => 15px
+
+ unit(15%, px)
+ // => 15px
+
+### match(pattern, string)
+
+Test if `string` matches the given `pattern`.
+
+ match('^foo(bar)?', foo)
+ match('^foo(bar)?', foobar)
+ // => true
+
+ match('^foo(bar)?', 'foo')
+ match('^foo(bar)?', 'foobar')
+ // => true
+
+ match('^foo(bar)?', 'bar')
+ // => false
+
+### abs(unit)
+
+ abs(-5px)
+ // => 5px
+
+ abs(5px)
+ // => 5px
+
+### ceil(unit)
+
+ ceil(5.5in)
+ // => 6in
+
+### floor(unit)
+
+ floor(5.6px)
+ // => 5px
+
+### round(unit)
+
+ round(5.5px)
+ // => 6px
+
+ round(5.4px)
+ // => 5px
+
+### min(a, b)
+
+ min(1, 5)
+ // => 1
+
+### max(a, b)
+
+ max(1, 5)
+ // => 5
+
+### even(unit)
+
+ even(6px)
+ // => true
+
+### odd(unit)
+
+ odd(5mm)
+ // => true
+
+### sum(nums)
+
+ sum(1 2 3)
+ // => 6
+
+### avg(nums)
+
+ avg(1 2 3)
+ // => 2
+
+### join(delim, vals...)
+
+ Join the given `vals` with `delim`.
+
+ join(' ', 1 2 3)
+ // => "1 2 3"
+
+ join(',', 1 2 3)
+ // => "1,2,3"
+
+ join(', ', foo bar baz)
+ // => "foo, bar, baz"
+
+ join(', ', foo, bar, baz)
+ // => "foo, bar, baz"
+
+### hsla(color | h[, s, l, a])
+
+Convert the given `color` to an `HSLA` node,
+or h,s,l,a component values.
+
+ hslaa(10deg, 50%, 30%, 0.5)
+ // => HSLA
+
+ hslaa(#ffcc00)
+ // => HSLA
+
+### hsla(color | h[, s, l])
+
+Convert the given `color` to an `HSLA` node,
+or h,s,l component values.
+
+ hsla(10, 50, 30)
+ // => HSLA
+
+ hsla(#ffcc00)
+ // => HSLA
+
+### rgba(color | r[, g, b, a])
+
+Return `RGBA` from the r,g,b,a channels or provide a `color` to tweak the alpha.
+
+ rgba(255,0,0,0.5)
+ // => rgba(255,0,0,0.5)
+
+ rgba(255,0,0,1)
+ // => #ff0000
+
+ rgba(#ffcc00, 0.5)
+ // rgba(255,204,0,0.5)
+
+### rgb(color | r[, g, b])
+
+Return a `RGBA` from the r,g,b channels or cast to an `RGBA` node.
+
+ rgb(255,204,0)
+ // => #ffcc00
+
+ rgb(#fff)
+ // => #fff
+
+### lighten(color, amount)
+
+Lighten the given `color` by `amount`.
+
+ lighten(black, 50%)
+ // => #808080
+
+### darken(color, amount)
+
+Darken the given `color` by `amount`.
+
+ darken(white, 50%)
+ // => #808080
+
+### lighten-by(color, amount)
+
+ Lighten by `amount` of the current lightness value.
+
+ lighten-by(black, 50%)
+ // => #808080
+
+ lighten-by(lighten-by(black, 50%), 50%)
+ // => #bfbfbf
+
+ lighten-by(lighten-by(lighten-by(black, 50%), 50%), 50%)
+ // => #fff
+
+essentially the same as:
+
+ black + hsla(0,0,50%)
+ black + hsla(0,0,75%)
+ black + hsla(0,0,100%)
+
+### darken-by(color, amount)
+
+ Darken by `amount` of the current lightness value.
+
+ darken-by(white, 50%)
+ // => #808080
+
+ darken-by(darken-by(white, 50%), 50%)
+ // => #404040
+
+ darken-by(darken-by(darken-by(white, 50%), 50%), 50%)
+ // => #202020
+
+### desaturate(color, amount)
+
+Desaturate the given `color` by `amount`.
+
+ desaturate(#f00, 40%)
+ // => #c33
+
+### saturate(color, amount)
+
+Saturate the given `color` by `amount`.
+
+ saturate(#c33, 40%)
+ // => #f00
+
+### unquote(str | ident)
+
+ Unquote the given `str` and returned as a `Literal` node.
+
+ unquote("sans-serif")
+ // => sans-serif
+
+ unquote(sans-serif)
+ // => sans-serif
+
+ unquote('1px / 2px')
+ // => 1px / 2px
+
+### operate(op, left, right)
+
+ Perform the given `op` on the `left` and `right` operands:
+
+ op = '+'
+ operate(op, 15, 5)
+ // => 20
+
+### length([expr])
+
+ Parenthesized expressions may act as tuples, the `length()` function returns the length of such expressions.
+
+ length((1 2 3 4))
+ // => 4
+
+ length((1 2))
+ // => 2
+
+ length((1))
+ // => 1
+
+ length(())
+ // => 0
+
+ length(1 2 3)
+ // => 3
+
+ length(1)
+ // => 1
+
+ length()
+ // => 0
+
+### warn(msg)
+
+ Warn with the given error `msg`, does not exit.
+
+ warn("oh noes!")
+
+### error(msg)
+
+ Exits with the given error `msg`.
+
+ add(a, b)
+ unless a is a 'unit' and b is a 'unit'
+ error('add() expects units')
+ a + b
+
+### last(expr)
+
+ Return the _last_ value in the given `expr`:
+
+ nums = 1 2 3
+ last(nums)
+ last(1 2 3)
+ // => 3
+
+ list = (one 1) (two 2) (three 3)
+ last(list)
+ // => (three 3)
+
+### p(expr)
+
+ Inspect the given `expr`:
+
+ fonts = Arial, sans-serif
+ p('test')
+ p(123)
+ p((1 2 3))
+ p(fonts)
+ p(#fff)
+ p(rgba(0,0,0,0.2))
+
+ add(a, b)
+ a + b
+
+ p(add)
+
+stdout:
+
+ inspect: "test"
+ inspect: 123
+ inspect: 1 2 3
+ inspect: Arial, sans-serif
+ inspect: #fff
+ inspect: rgba(0,0,0,0.2)
+ inspect: add(a, b)
+
+### opposite-position(positions)
+
+ Return the opposites of the given `positions`.
+
+ opposite-position(right)
+ // => left
+
+ opposite-position(top left)
+ // => bottom right
+
+ opposite-position('top' 'left')
+ // => bottom right
+
+### image-size(path)
+
+ Returns the `width` and `height` of the image found at `path`. Lookups are performed in the same manner as `@import`, altered by the `paths` setting.
+
+ width(img)
+ return image-size(img)[0]
+
+ height(img)
+ return image-size(img)[1]
+
+ image-size('tux.png')
+ // => 405px 250px
+
+ image-size('tux.png')[0] == width('tux.png')
+ // => true
+
+### Undefined Functions
+
+ Undefined functions will output as literals, so for example
+ we may call `rgba-stop(50%, #fff)` within our css, and it will
+ output as you would expect. We can use this within helpers as well.
+
+ In the example below we simply define the function `stop()` which
+ returns the literal `rgba-stop()` call.
+
+ stop(pos, rgba)
+ rgba-stop(pos, rgba)
+
+ stop(50%, orange)
+ // => rgba-stop(50%, #ffa500)
\ No newline at end of file
--- /dev/null
+
+## Comments
+
+ Stylus supports two kinds of comments, single-line, and multi-line comments, using the same syntax found in JavaScript.
+
+
+ // I'm a comment!
+ body
+ padding 5px // some awesome padding
+
+
+ /*
+ * Adds the given numbers together.
+ */
+
+ add(a, b)
+ a + b
\ No newline at end of file
--- /dev/null
+
+## Implementation Comparisons
+
+Below we go head to head with other implementations.
+
+### Variables
+
+SCSS:
+
+ $main-color: #006;
+ color: $main-color;
+
+Less:
+
+ @main-color: #006;
+ color: @main-color;
+
+Stylus:
+
+ main-color = #006
+ color main-color
+
+### Mixins
+
+SCSS:
+
+ @mixin pad($x, $y) {
+ padding: $y $x;
+ }
+
+ .msg {
+ @include pad(5px, 10px);
+ }
+
+Less:
+
+ .pad(@x, @y) {
+ padding: @y @x;
+ }
+
+ .msg {
+ .pad(5px, 10px);
+ }
+
+Stylus:
+
+ pad(x, y)
+ padding y x
+
+ .msg
+ pad(5px, 10px)
+
+### Larger Example
+
+Less:
+
+ .box-shadow (@x: 0, @y: 0, @blur: 1px, @alpha) {
+ @val: @x @y @blur rgba(0, 0, 0, @alpha);
+ box-shadow: @val;
+ -webkit-box-shadow: @val;
+ -moz-box-shadow: @val;
+ }
+ .box {
+ @base: #f938ab;
+ color: saturate(@base, 5%);
+ border-color: lighten(@base, 30%);
+ div { .box-shadow(0, 0, 5px, 0.4) }
+ }
+
+Stylus:
+ box-shadow()
+ -webkit-box-shadow arguments
+ -moz-box-shadow arguments
+ box-shadow arguments
+
+ .box
+ base = #f938ab
+ color saturate(base, 5%)
+ border-color lighten(base, 30%)
+ div
+ box-shadow 0 0 5px 0.4
\ No newline at end of file
--- /dev/null
+
+## Conditionals
+
+ Conditionals provide control flow to a language which is otherwise static, providing conditional imports, mixins, functions, and more. The examples below are simply examples, and not recommended :)
+
+### if / else if / else
+
+ The `if` conditional works as you would expect, simply accepting an expression, evaluating the following block when `true`. Along with `if` are the typical `else if` and `else` tokens, acting as fallbacks.
+
+ The example below would conditionally overload the `padding` property, swapping it for margin.
+
+ overload-padding = true
+
+ if overload-padding
+ padding(y, x)
+ margin y x
+
+ body
+ padding 5px 10px
+
+Another example:
+
+ box(x, y, margin = false)
+ padding y x
+ if margin
+ margin y x
+
+ body
+ box(5px, 10px, true)
+
+Another `box()` helper:
+
+ box(x, y, margin-only = false)
+ if margin-only
+ margin y x
+ else
+ padding y x
+
+### unless
+
+ For users familiar with the ruby programming language, we have the `unless` conditional, which is essentially the opposite of `if`, essentially `if (!(expr))`.
+
+In the example below, if `disable-padding-override` is undefined or `false` padding will be overridden, displaying `margin` instead. However when `true` padding will remain outputting `padding 5px 10px` as expected.
+
+ disable-padding-override = true
+
+ unless disable-padding-override is defined and disable-padding-override
+ padding(x, y)
+ margin y x
+
+ body
+ padding 5px 10px
+
+### Postfix Conditionals
+
+ Stylus supports postfix conditionals, meaning the `if` and `unless` act as operators, evaluating the left-hand operand, when the right-hand expression is truthy.
+
+
+ For example let's define `negative()`, performing some basic type checking. Below we use block-style conditionals:
+
+ negative(n)
+ unless n is a 'unit'
+ error('invalid number')
+ if n < 0
+ yes
+ else
+ no
+
+ Next we utilize postfix conditionals to keep our function terse.
+
+ negative(n)
+ error('invalid number') unless n is a 'unit'
+ return yes if n < 0
+ no
+
+ Of course we could take this further, and utilize `n < 0 ? yes : no`, or simply stick with booleans, and use only `n < 0`.
+
+ Postfix conditionals may be applied to most single-line statements, for example `@import`, `@charset`, mixins, and of course properties as shown below:
+
+
+ pad(types = margin padding, n = 5px)
+ padding unit(n, px) if padding in types
+ margin unit(n, px) if margin in types
+
+ body
+ pad()
+
+ body
+ pad(margin)
+
+ body
+ apply-mixins = true
+ pad(padding, 10) if apply-mixins
+
+yielding:
+
+ body {
+ padding: 5px;
+ margin: 5px;
+ }
+ body {
+ margin: 5px;
+ }
+ body {
+ padding: 10px;
+ }
+
--- /dev/null
+
+## CSS Style
+
+ Stylus transparently supports a regular css-style syntax, meaning you do not need to use an alternative parser, or specify that a certain file is using a specific style.
+
+### Example
+
+ Below is a small style using the indented approach:
+
+ border-radius()
+ -webkit-border-radius arguments
+ -moz-border-radius arguments
+ border-radius arguments
+
+ body a
+ font 12px/1.4 "Lucida Grande", Arial, sans-serif
+ background black
+ color #ccc
+
+ form input
+ padding 5px
+ border 1px solid
+ border-radius 5px
+
+ Since braces, colons, and semi-colons are optional, we could write this example just as we would with normal css:
+
+ border-radius() {
+ -webkit-border-radius: arguments;
+ -moz-border-radius: arguments;
+ border-radius: arguments;
+ }
+
+ body a {
+ font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
+ background: black;
+ color: #ccc;
+ }
+
+ form input {
+ padding: 5px;
+ border: 1px solid;
+ border-radius: 5px;
+ }
+
+ Since we may mix and match the two variants, the following is valid as well:
+
+ border-radius()
+ -webkit-border-radius: arguments;
+ -moz-border-radius: arguments;
+ border-radius: arguments;
+
+ body a {
+ font: 12px/1.4 "Lucida Grande", Arial, sans-serif;
+ background: black;
+ color: #ccc;
+ }
+
+ form input
+ padding: 5px;
+ border: 1px solid;
+ border-radius: 5px;
+
+ Variables, functions, mixins, and all of the other features that Stylus provides still work as expected:
+
+ main-color = white
+ main-hover-color = black
+
+ body a {
+ color: main-color;
+ &:hover { color: main-hover-color; }
+ }
+
+ body a { color: main-color; &:hover { color: main-hover-color; }}
+
+ There are currently a few exceptions to this rule, since the two styles may be mixed and matched some indentation rules still apply. So although not _every_ plain-css stylesheet will work without modification this feature still allows those who prefer css syntax may still utilize the other powerful features provided by Stylus.
+
+
--- /dev/null
+
+## Error Reporting
+
+ Stylus has fantastic error reporting built in for syntax, parse, and evaluation errors, complete with stack traces, line numbers, and filenames.
+
+### Parse Error
+
+Parse error example:
+
+ body
+ form input
+ == padding 5px
+
+yielding:
+
+ Error: /Users/tj/Projects/stylus/testing/test.styl:4
+ 3: ' form input'
+ 4: ' == padding 5px'
+
+ illegal unary ==
+
+### Evaluation Error
+
+ This "runtime" or evaluation error is caused due to passing a string to `border-radius()` instead of the expected `Unit` by using our helper `ensure(n, 'unit')`.
+
+ ensure(val, type)
+ unless val is a type
+ error('expected a ' + type + ', but got ' + typeof(val))
+
+ border-radius(n)
+ ensure(n, 'unit')
+ -webkit-border-radius n
+ -moz-border-radius n
+ border-radius n
+
+ body
+ border-radius '5px'
+
+yielding:
+
+ Error: /Users/tj/Projects/stylus/examples/error.styl:12
+ 11: ''
+ 12: 'body'
+ 13: ' border-radius \'5px\''
+ 14: ''
+
+ expected a unit, but got string
+ at ensure() (/Users/tj/Projects/stylus/examples/error.styl:2)
+ at border-radius() (/Users/tj/Projects/stylus/examples/error.styl:5)
+ at "body" (/Users/tj/Projects/stylus/examples/error.styl:10)
--- /dev/null
+
+## Escaping
+
+ Stylus allows you to escape characters, effectively turning them into identifiers, so that they can be rendered as literals. For example:
+
+ body
+ padding 1 \+ 2
+
+will compile to:
+
+ body {
+ padding: 1 + 2;
+ }
+
+
+Not that Stylus requires that `/` is parenthesized when used in a property:
+
+ body
+ font 14px/1.4
+ font (14px/1.4)
+
+yields:
+
+ body {
+ font: 14px/1.4;
+ font: 10px;
+ }
\ No newline at end of file
--- /dev/null
+
+## Stylus Executable
+
+Stylus ships with the `stylus` executable for converting stylus to css.
+
+ Usage: stylus [options] [command] [< in [> out]]
+ [file|dir ...]
+
+ Commands:
+
+ help <prop> Opens help info for <prop> in
+ your default browser. (osx only)
+
+ Options:
+
+ -i, --interactive Start interactive REPL
+ -w, --watch Watch file(s) for changes and re-compile
+ -o, --out <dir> Output to <dir> when passing files
+ -C, --css <src> [dest] Convert css input to stylus
+ -c, --compress Compress css output
+ -d, --compare Display input along with output
+ -V, --version Display the version of stylus
+ -h, --help Display help information
+
+### STDIO Compilation Example
+
+ `stylus` reads from _stdin_ and outputs to _stdout_, so for example:
+
+ $ stylus --compress < some.styl > some.css
+
+Try stylus some in the terminal, type below and press CTRL-D for __EOF__:
+
+ $ stylus
+ body
+ color red
+ font 14px Arial, sans-serif
+
+### Compiling Files Example
+
+ `stylus` also accepts files and directories, for example a directory named `css` will compile and output the `.css` files in the same directory.
+
+ $ stylus css
+
+ The following will output to `./public/stylesheets`:
+
+ $ stylus css --out public/stylesheets
+
+ Or a few files:
+
+ $ stylus one.styl two.styl
+
+### Converting CSS
+
+ If we wish to convert css to the terse Stylus syntax, we can utilize the `--css` flag.
+
+ Via stdio:
+
+ $ stylus --css < test.css > test.styl
+
+ Output a `.styl` file of the same basename:
+
+ $ stylus --css test.css
+
+ Output to a specific destination:
+
+ $ stylus --css test.css /tmp/out.styl
+
+### CSS Property Help
+
+ On osx `stylus help <prop>` will open your default browser and display help documentation for the given `<prop>`.
+
+ $ stylus help box-shadow
+
+### Interactive Shell
+
+ The Stylus REPL (Read-Eval-Print-Loop) or "interactive shell" allows you to
+ play around with Stylus expressions directly from your terminal. Note that this works only for expressions, not selectors etc. To use simple add the `-i`, or `--interactive` flag:
+
+ $ stylus -i
+ > color = white
+ => #fff
+ > color - rgb(200,50,0)
+ => #37cdff
+ > color
+ => #fff
+ > color -= rgb(200,50,0)
+ => #37cdff
+ > color
+ => #37cdff
+ > rgba(color, 0.5)
+ => rgba(55,205,255,0.5)
+
\ No newline at end of file
--- /dev/null
+
+## @font-face
+
+ The `@font-face` at-rule expects as you would expect, simply followed by a block of properties:
+
+
+ @font-face
+ font-family Geo
+ font-style normal
+ src url(fonts/geo_sans_light/GensansLight.ttf)
+
+ .ingeo
+ font-family Geo
+
+yielding:
+
+
+ @font-face {
+ font-family: Geo;
+ font-style: normal;
+ src: url("fonts/geo_sans_light/GensansLight.ttf");
+ }
+ .ingeo {
+ font-family: Geo;
+ }
+
--- /dev/null
+
+## Functions
+
+ Stylus features powerful in-language function definition. Function definition appears identical to mixins, however functions may return a value.
+
+### Return Values
+
+ Let's try a trivial example, creating a function that adds two numbers.
+
+ add(a, b)
+ a + b
+
+ We may then utilize this function in conditions, as property values, etc.
+
+ body
+ padding add(10px, 5)
+
+ Rendering
+
+ body {
+ padding: 15px;
+ }
+
+### Argument Defaults
+
+ Optional arguments may default to a given expression. With Stylus we may even default arguments to leading arguments! For example:
+
+
+ add(a, b = a)
+ a + b
+
+ add(10, 5)
+ // => 15
+
+ add(10)
+ // => 20
+
+note that since argument defaults are assignments, we can also utilize function calls for defaults:
+
+ add(a, b = unit(a, px))
+ a + b
+
+### Function Bodies
+
+ We can take our simple `add()` function further, by casting all units passed as `px` via the `unit()` built-in. Re-assigning each argument and providing a unit type string (or identifier), which disregards unit conversion.
+
+ add(a, b = a)
+ a = unit(a, px)
+ b = unit(b, px)
+ a + b
+
+ add(15%, 10deg)
+ // => 25
+
+### Multiple Return Values
+
+ Stylus functions can return several values, just as you can assign several values to a variable. For example the following is a valid assignment:
+
+ sizes = 15px 10px
+
+ sizes[0]
+ // => 15px
+
+Similarly we may return several values:
+
+ sizes()
+ 15px 10px
+
+ sizes()[0]
+ // => 15px
+
+One slight exception is when return values are identifiers, for example the following looks like a property assignment to Stylus since no operators are present.
+
+ swap(a, b)
+ b a
+
+To disambiguate we may either wrap in parens, or utilize the `return` keyword.
+
+ swap(a, b)
+ (b a)
+
+ swap(a, b)
+ return b a
+
+### Conditionals
+
+ Let's say we want to create a function named `stringish()` to see if the value given can be transformed to a string. We check if `val` is a string, or an ident which is string-like. Because undefined identifiers yield themselves as the value, we may compare them to them-selves as shown below, where `yes` and `no` are used in place of `true` and `false`.
+
+
+ stringish(val)
+ if val is a 'string' or val is a 'ident'
+ yes
+ else
+ no
+
+usage:
+
+ stringish('yay') == yes
+ // => true
+
+ stringish(yay) == yes
+ // => true
+
+ stringish(0) == no
+ // => true
+
+__note__: `yes` and `no` are not boolean literals, they are simply undefined identifiers in this case.
+
+Another example:
+
+
+ compare(a, b)
+ if a > b
+ higher
+ else if a < b
+ lower
+ else
+ equal
+
+usage:
+
+ compare(5, 2)
+ // => higher
+
+ compare(1, 5)
+ // => lower
+
+ compare(10, 10)
+ // => equal
+
+### Aliasing
+
+ To alias a function we can simply assign a function's name to a new identifier. For example our previous `add()` function could be exposed as `plus()` as well, simply by:
+
+ plus = add
+
+ plus(1, 2)
+ // => 3
+
+### Variable Functions
+
+ In the same way that we can "alias" a function, we can pass a function as well, here our `invoke()` function accepts a function, so we can pass it `add()` or `sub()`.
+
+ invoke(a, b, fn)
+ fn(a, b)
+
+ add(a, b)
+ a + b
+
+ body
+ padding invoke(5, 10, add)
+ padding invoke(5, 10, sub)
+
+yielding:
+
+ body {
+ padding: 15;
+ padding: -5;
+ }
+
+### arguments
+
+ The `arguments` local is available to all function bodies, and contains all the arguments passed. For example:
+
+ sum()
+ n = 0
+ for num in arguments
+ n = n + num
+
+ sum(1,2,3,4,5)
+ // => 15
+
+### Hash Example
+
+ Below we define the `get(hash, key)` function, which will return the
+ value of `key`, or `null`. We iterate each `pair` in `hash`, returning the pair's second node when the first (the `key`) matches.
+
+ get(hash, key)
+ return pair[1] if pair[0] == key for pair in hash
+
+As you can see below, in-language functions paired with robust stylus expressions can provide great flexibility.
+
+ hash = (one 1) (two 2) (three 3)
+
+ get(hash, two)
+ // => 2
+
+ get(hash, three)
+ // => 3
+
+ get(hash, something)
+ // => null
--- /dev/null
+## Data URI Image Inlining
+
+Stylus is bundled with an optional function named `url()`, which replaces the literal `url()` calls, and conditionally inlines them using base64 [Data URIs](http://en.wikipedia.org/wiki/Data_URI_scheme).
+
+### Example
+
+The function itself is available via `require('stylus').url`, and accepts an options object, returning a function that Stylus calls internally when it sees `url()`.
+
+The `.define(name, callback)` method assigned a JavaScript function that can be called from stylus source. In this case we have our images in `./css/images` then we can ignore the `paths` option, since image lookups are performed relative to the file being rendered (by default), we may alter this with the option.
+
+ stylus(str)
+ .set('filename', __dirname + '/css/test.styl')
+ .define('url', stylus.url())
+ .render(function(err, css){
+
+ });
+
+For example if our images live in `./public/images` and we wish to use `url(images/tobi.png)`, we can pass `paths` with our public directory, which will become part of the lookup process. Like-wise if we wanted `url(tobi.png)` instead, we would pass `paths: [__dirname + '/public/images']`.
+
+ stylus(str)
+ .set('filename', __dirname + '/css/test.styl')
+ .define('url', stylus.url({ paths: [__dirname + '/public'] }))
+ .render(function(err, css){
+
+ });
+
+### Options
+
+ - `limit` bytesize limit defaulting to 30Kb (30000)
+ - `paths` image resolution path(s)
\ No newline at end of file
--- /dev/null
+
+## Import
+
+ Stylus supports both literal __@import__ for CSS, as well as dynamic importing of other Stylus sheets.
+
+### Literal CSS
+
+ Any filename with the extension `.css` will become a literal, for example:
+
+ @import "reset.css"
+
+will render to the literal css __@import__ shown below:
+
+ @import "reset.css"
+
+### Stylus Import
+
+ When using __@import__ without the `.css` extension, it is assumed to be a Stylus sheet, for example `@import "mixins/border-radius"`.
+
+ __@import__ works by iterating an array of directories, and seeing if this file lives in any of them, similar to node's `require.paths`. This array defaults to a single path which is derived from the `filename` option's dirname. So if your filename is `/tmp/testing/stylus/main.styl`, then import will look in `/tmp/testing/stylus/`.
+
+ __@import__ also supports index styles, meaning if you `@import blueprint`, it will resolve either `blueprint.styl` or `blueprint/index.styl`, useful for libraries to expose all of their features, but still allow a subset of the library to be imported. For example a common lib structure might be:
+
+ ./tablet
+ |-- index.styl
+ |-- vendor.styl
+ |-- buttons.styl
+ |-- images.styl
+
+ In the example below we set the `paths` options to provide additional paths to Stylus. Within `./test.styl` we could then `@import "mixins/border-radius"` or `@import "border-radius"` since `./mixins` is exposed to Stylus.
+
+ /**
+ * Module dependencies.
+ */
+
+ var stylus = require('../')
+ , str = require('fs').readFileSync(__dirname + '/test.styl', 'utf8');
+
+ var paths = [
+ __dirname
+ , __dirname + '/mixins'
+ ];
+
+ stylus(str)
+ .set('filename', __dirname + '/test.styl')
+ .set('paths', paths)
+ .render(function(err, css){
+ if (err) throw err;
+ console.log(css);
+ });
+
+### JavaScript Import API
+
+ When using the `.import(path)` method, these imports are deferred until evaluation:
+
+ var stylus = require('../')
+ , str = require('fs').readFileSync(__dirname + '/test.styl', 'utf8');
+
+ stylus(str)
+ .set('filename', __dirname + '/test.styl')
+ .import('mixins/vendor')
+ .render(function(err, css){
+ if (err) throw err;
+ console.log(css);
+ });
+
+ The following are essentially equivalent:
+
+ @import 'mixins/vendor'
+
+and
+ .import('mixins/vendor')
+
\ No newline at end of file
--- /dev/null
+
+## Interpolation
+
+ Stylus supports interpolation by using the `{}` characters to surround an expression, which then becomes part of the identifier. For example `-webkit-{'border' + '-radius'}` would evaluate to `-webkit-border-radius`.
+
+ A great example use-case for this is expanding properties with vendor prefixes.
+
+ vendor(prop, args)
+ -webkit-{prop} args
+ -moz-{prop} args
+ {prop} args
+
+ border-radius()
+ vendor('border-radius', arguments)
+
+ box-shadow()
+ vendor('box-shadow', arguments)
+
+ button
+ border-radius 1px 2px / 3px 4px
+
+yielding:
+
+ button {
+ -webkit-border-radius: 1px 2px / 3px 4px;
+ -moz-border-radius: 1px 2px / 3px 4px;
+ border-radius: 1px 2px / 3px 4px;
+ }
+
+## Property Hacks
+
+Interpolation can be used for property hacks as well, since all string values
+within the delimiters are transformed to literals. For example:
+
+ body
+ {'*foo-bar'} baz
+
+yields:
+
+ body {
+ *foo-bar: baz;
+ }
+
\ No newline at end of file
--- /dev/null
+
+## Introspection API
+
+ Stylus supports an introspection API, allowing mixins and functions to reflect relative to the caller etc.
+
+
+## mixin
+
+ The `mixin` local variable is automatically assigned within function bodies,
+ containing the string "root" indicating the function is called at the root
+ level, or "block" indicating otherwise, and finally `false` if the function
+ is invoked expecting a return value.
+
+ In the following example we define `reset()` altering its behaviour when mixed in to root, another block, or a return value as used in the `foo` property below.
+
+ reset()
+ if mixin == 'root'
+ got
+ root true
+ else if mixin
+ got 'a mixin'
+ else
+ 'not a mixin'
+
+ reset()
+
+ body
+ reset()
+ foo reset()
+
+compiles to:
+
+ got {
+ root: true;
+ }
+ body {
+ foo: "not a mixin";
+ got: "a mixin";
+ }
--- /dev/null
+
+## Iteration
+
+ Stylus allows you to iterate expressions via the `for/in` construct, taking the form of:
+
+ for <val-name> [, <key-name>] in <expression>
+
+For example:
+
+ body
+ for num in 1 2 3
+ foo num
+
+yields:
+
+ body {
+ foo: 1;
+ foo: 2;
+ foo: 3;
+ }
+
+The example below shows how to use the `<key-name>`:
+
+ body
+ fonts = Impact Arial sans-serif
+ for font, i in fonts
+ foo i font
+
+yielding:
+
+ body {
+ foo: 0 Impact;
+ foo: 1 Arial;
+ foo: 2 sans-serif;
+ }
+
+### Mixins
+
+ We may utilize iteration within mixins to produce powerful functionality, for example we can apply expression pairs as properties using interpolation and iteration. Below we define `apply()`, conditionally utilizing all the `arguments` so that comma-delimited _and_ expression lists are supported:
+
+ apply(props)
+ props = arguments if length(arguments) > 1
+ for prop in props
+ {prop[0]} prop[1]
+
+ body
+ apply(one 1, two 2, three 3)
+
+ body
+ list = (one 1) (two 2) (three 3)
+ apply(list)
+
+### Functions
+
+ Stylus functions may also contain for-loops, below are some example use-cases:
+
+sum:
+
+ sum(nums)
+ sum = 0
+ for n in nums
+ sum += n
+
+ sum(1 2 3)
+ // => 6
+
+join:
+
+ join(delim, args)
+ buf = ''
+ for arg, index in args
+ if index
+ buf += delim + arg
+ else
+ buf += arg
+
+ join(', ', foo bar baz)
+ // => "foo, bar, baz"
+
+### Postfix
+
+ Much like `if` / `unless` may be utilized post-statement, the same can be done with `for`. Below are the same examples as above utilizing the postfix syntax:
+
+ sum(nums)
+ sum = 0
+ sum += n for n in nums
+
+
+ join(delim, args)
+ buf = ''
+ buf += i ? delim + arg : arg for arg, i in args
+
+ We can also __return__ from within a loop, below is an example returning the
+ number when `n % 2 == 0` evaluates to __true__.
+
+ first-even(nums)
+ return n if n % 2 == 0 for n in nums
+
+ first-even(1 3 5 5 6 3 2)
+ // => 6
\ No newline at end of file
--- /dev/null
+## JavaScript API
+
+Simply require the module, and call `render()` with the given string of stylus code, and (optional) options object. Frameworks utilizing stylus should pass the `filename` option to provide better error reporting.
+
+ var stylus = require('stylus');
+
+ stylus.render(str, { filename: 'nesting.css' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+ });
+
+We can also do the same thing in a more progressive manner:
+
+ var stylus = require('stylus');
+
+ stylus(str)
+ .set('filename', 'nesting.css')
+ .render(function(err, css){
+ // logic
+ });
+
+### .set(setting, value)
+
+ Apply a setting such as a `filename`, or import `paths`:
+
+ .set('filename', __dirname + '/test.styl')
+ .set('paths', [__dirname, __dirname + '/mixins'])
+
+### .import(path)
+
+Defer importing of the given `path` until evaluation is performed. The example below is essentially the same as doing `@import 'mixins/vendor'` within your Stylus sheet.
+
+ var stylus = require('../')
+ , str = require('fs').readFileSync(__dirname + '/test.styl', 'utf8');
+
+ stylus(str)
+ .set('filename', __dirname + '/test.styl')
+ .import('mixins/vendor')
+ .render(function(err, css){
+ if (err) throw err;
+ console.log(css);
+ });
+
+### .define(name, fn)
+
+ This method allows you to provide a JavaScript-defined function to Stylus, think of these as you would JavaScript to C++ bindings. When you have something you cannot do within Stylus, you define it in JavaScript.
+
+In our example we define four functions `add()`, `sub()`, `image-width()`, and `image-height()`. These functions must return a `Node`, this constructor and the other nodes are available via `stylus.nodes`.
+
+ var stylus = require('../')
+ , nodes = stylus.nodes
+ , utils = stylus.utils
+ , fs = require('fs');
+
+ function add(a, b) {
+ return a.operate('+', b);
+ }
+
+ function sub(a, b) {
+ return a.operate('-', b);
+ }
+
+ function imageDimensions(img) {
+ // assert that the node (img) is a String node, passing
+ // the param name for error reporting
+ utils.assertType(img, nodes.String, 'img');
+ var path = img.val;
+
+ // Grab bytes necessary to retrieve dimensions.
+ // if this was real you would do this per format,
+ // instead of reading the entire image :)
+ var data = fs.readFileSync(__dirname + '/' + path);
+
+ // GIF
+ // of course you would support.. more :)
+ if ('GIF' == data.slice(0, 3).toString()) {
+ var w = data.slice(6, 8)
+ , h = data.slice(8, 10);
+ w = w[1] << 8 | w[0];
+ h = h[1] << 8 | h[0];
+ }
+
+ return [w, h];
+ }
+
+ function imageWidth(img) {
+ return new nodes.Unit(imageDimensions(img)[0]);
+ }
+
+ function imageHeight(img) {
+ return new nodes.Unit(imageDimensions(img)[1]);
+ }
+
+ stylus(str)
+ .set('filename', 'js-functions.styl')
+ .define('add', add)
+ .define('sub', sub)
+ .define('image-width', imageWidth)
+ .define('image-height', imageHeight)
+ .render(function(err, css){
+ if (err) throw err;
+ console.log(css);
+ });
+
+ For further reference until documentation is complete please reference the following files:
+
+ - lib/nodes/*
+ - lib/utils.js
\ No newline at end of file
--- /dev/null
+
+## @keyframes
+
+ Stylus supports the `@keyframes` at-rule, which is converted to `@-webkit-keyframes` when compiled:
+
+
+ @keyframes pulse
+ 0%
+ background-color red
+ opacity 1.0
+ -webkit-transform scale(1.0) rotate(0deg)
+ 33%
+ background-color blue
+ opacity 0.75
+ -webkit-transform scale(1.1) rotate(-5deg)
+ 67%
+ background-color green
+ opacity 0.5
+ -webkit-transform scale(1.1) rotate(5deg)
+ 100%
+ background-color red
+ opacity 1.0
+ -webkit-transform scale(1.0) rotate(0deg)
+
+yielding:
+
+ @-webkit-keyframes pulse {
+ 0% {
+ background-color: red;
+ opacity: 1;
+ -webkit-transform: scale(1) rotate(0deg);
+ }
+
+ 33% {
+ background-color: blue;
+ opacity: 0.75;
+ -webkit-transform: scale(1.1) rotate(-5deg);
+ }
+
+ 67% {
+ background-color: green;
+ opacity: 0.5;
+ -webkit-transform: scale(1.1) rotate(5deg);
+ }
+
+ 100% {
+ background-color: red;
+ opacity: 1;
+ -webkit-transform: scale(1) rotate(0deg);
+ }
+
+ }
--- /dev/null
+## Literal CSS
+
+ If for any reason Stylus cannot accommodate a specific need, you can always resort to literal css via `@css`:
+
+
+ @css {
+ body {
+ font: 14px;
+ }
+ }
+
+compiling to:
+
+ body {
+ font: 14px;
+ }
\ No newline at end of file
--- /dev/null
+
+## @media
+
+ The `@media` works just as it does within regular css, however with Stylus block notation:
+
+ @media print
+ #header
+ #footer
+ display none
+
+yielding:
+
+ @media print {
+ #header,
+ #footer {
+ display: none;
+ }
+ }
--- /dev/null
+
+## Connect Middleware
+
+ Stylus ships with Connect middleware for auto-compiling Stylus sheets when modified.
+
+## stylus.middleware(options)
+
+ Return Connect middleware with the given `options`.
+
+#### Options
+
+ `force` When __true__ styles will always re-compile
+ `src` Source directory used to find .styl files
+ `dest` Destination directory used to output .css files
+ when undefined defaults to `src`.
+ `compress` Whether the output .css files should be compressed
+ `compile` Custom compile function, accepting the arguments
+ `(str, path)` returning the renderer.
+
+#### Examples
+
+ Here we set up the custom compile function so that we may
+ alter the renderer by providing additional settings.
+
+ By default the compile function simply sets the `filename`
+ and renders the CSS.
+
+ function compile(str, path) {
+ return stylus(str)
+ .import(__dirname + '/css/mixins/blueprint')
+ .import(__dirname + '/css/mixins/css3')
+ .set('filename', path)
+ .set('warn', true)
+ .set('compress', true);
+ }
+
+ Pass the middleware to Connect, grabbing .styl files from this directory
+ and saving .css files to _./public_. Also supplying our custom `compile` function.
+
+ Following that we have a `staticProvider` layer setup to serve the .css
+ files generated by Stylus.
+
+ var stylus = require('stylus');
+
+ var server = connect.createServer(
+ stylus.middleware({
+ src: __dirname
+ , dest: __dirname + '/public'
+ , compile: compile
+ })
+ , connect.staticProvider(__dirname + '/public')
+ );
+
+ When `force` is used, the styles will be unconditionally re-compiled, however
+ even without this option the Stylus middleware is smart enough to detect changes in `@import`ed files.
\ No newline at end of file
--- /dev/null
+
+## Mixins
+
+Both mixins and functions are defined in the same manor, however they are applied in different ways. For example we have a `border-radius(n)` function defined below, which is invoked as a _mixin_, aka a statement rather than part of an expression.
+
+When `border-radius()` is invoked within a selector, the properties are expanded and copied into the selector.
+
+ border-radius(n)
+ -webkit-border-radius n
+ -moz-border-radius n
+ border-radius n
+
+ form input[type=button]
+ border-radius(5px)
+
+compiles to:
+
+ form input[type=button] {
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+ }
+
+When utilizing mixins, we can omit the parens all together, providing is with fantastic transparent vendor property support:
+
+ border-radius(n)
+ -webkit-border-radius n
+ -moz-border-radius n
+ border-radius n
+
+ form input[type=button]
+ border-radius 5px
+
+Note that the `border-radius` within our mixin is treated as a property, and not a recursive function invocation. To take this further we we may utilize the automatic `arguments` local variable, containing the expression passed, allowing more than one value to be passed:
+
+ border-radius()
+ -webkit-border-radius arguments
+ -moz-border-radius arguments
+ border-radius arguments
+
+now allowing us to pass values such as `border-radius 1px 2px / 3px 4px`.
+
+Another great example of this, is adding transparent support for vendor specifics such as `opacity` support for IE:
+
+ support-for-ie ?= true
+
+ opacity(n)
+ opacity n
+ if support-for-ie
+ filter unquote('progid:DXImageTransform.Microsoft.Alpha(Opacity=' + round(n * 100) + ')')
+
+ #logo
+ &:hover
+ opacity 0.5
+
+rendering:
+
+ #logo:hover {
+ opacity: 0.5;
+ filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=50);
+ }
+
+### Parent References
+
+ Mixins may utilize the parent reference character `&`, acting on the parent instead of further nesting. For example lets say we wish to create a `stripe(even, odd)` mixin for striping table row, we provide both `even` and `odd` with default color values, and assign the `background-color` property on the row. Nested within the `tr` we use `&` to reference the `tr`, providing the `even` color.
+
+ stripe(even = #fff, odd = #eee)
+ tr
+ background-color odd
+ &.even
+ &:nth-child(even)
+ background-color even
+
+We may then utilize the mixin as shown below:
+
+ table
+ stripe()
+ td
+ padding 4px 10px
+
+ table#users
+ stripe(#303030, #494848)
+ td
+ color white
+
+Another way to define the `stripe()` mixin without parent reference:
+
+ stripe(even = #fff, odd = #eee)
+ tr
+ background-color odd
+ tr.even
+ tr:nth-child(even)
+ background-color even
+
+If we wished, we could invoke `stripe()` as if it were a property:
+
+ stripe #fff #000
+
+### Mixing Mixins in Mixins
+
+ Mixins can of course utilize other mixins, to build up their own selector's and properties. For example, below we create `comma-list()` to inline (via `inline-list()`) and comma-separate an un-ordered list.
+
+
+ inline-list()
+ li
+ display inline
+
+ comma-list()
+ inline-list()
+ li
+ &:after
+ content ', '
+ &:last-child:after
+ content ''
+
+ ul
+ comma-list()
+
+rendering:
+
+ ul li:after {
+ content: ", ";
+ }
+ ul li:last-child:after {
+ content: "";
+ }
+ ul li {
+ display: inline;
+ }
+
--- /dev/null
+
+## Operator Precedence
+
+Below is the operator precedence table, highest to lowest:
+
+ []
+ ! ~ + -
+ is defined
+ ** * / %
+ + -
+ ... ..
+ <= >= < >
+ in
+ == is != is not
+ is a
+ && and || or
+ ?:
+ = ?= += -= *= /= %=
+ not
+ if unless
+
+## Unary Operators
+
+The following unary operators are available, `!`, `not`, `-`, `+`, and `~`.
+
+ !0
+ // => true
+
+ !!0
+ // => false
+
+ !1
+ // => false
+
+ !!5px
+ // => true
+
+ -5px
+ // => -5px
+
+ --5px
+ // => 5px
+
+ not true
+ // => false
+
+ not not true
+ // => true
+
+The logical `not` operator has low precedence, therefore the following example could be replaced with
+
+ a = 0
+ b = 1
+
+ !a and !b
+ // => false
+ // pased as: (!a) and (!b)
+
+with:
+
+ not a or b
+ // => false
+ // parsed as: not (a or b)
+
+## Binary Operators
+
+### Subscript []
+
+ The subscript operator allows us to grab a value in an expression via index. Parenthesized expressions may act as tuples, so for example `(15px 5px)`, `(1 2 3)`.
+
+ Below is an example where we utilize tuples for error handling, showing the versatility of such a construct. As
+
+ add(a, b)
+ if a is a 'unit' and b is a 'unit'
+ a + b
+ else
+ (error 'a and b must be units!')
+
+ body
+ padding add(1,'5')
+ // => padding: error "a and b must be units";
+
+ padding add(1,'5')[0]
+ // => padding: error;
+
+ padding add(1,'5')[0] == error
+ // => padding: true;
+
+ padding add(1,'5')[1]
+ // => padding: "a and b must be units";
+
+ A more complex example, invoking the `error()` built-in function with the error message returned, when the ident (the first value) equals `error`.
+
+
+ if (val = add(1,'5'))[0] == error
+ error(val[1])
+
+## Range .. ...
+
+ Both the inclusive (`..`) and exclusive (`...`) range operators are provided, expanding to expressions:
+
+ 1..5
+ // => 1 2 3 4 5
+
+ 1...5
+ // => 1 2 3 4
+
+### Additive: + -
+
+multiplicative and additive binary operators work as expected, and type conversion is applied within unit type classes, or default to the literal value. For example if we perform `5s - 2px` we will get `3s`.
+
+ 15px - 5px
+ // => 10px
+
+ 5 - 2
+ // => 3
+
+ 5in - 50mm
+ // => 3.031in
+
+ 5s - 1000ms
+ // => 4s
+
+ 20mm + 4in
+ // => 121.6mm
+
+ "foo " + "bar"
+ // => "foo bar"
+
+ "num " + 15
+ // => "num 15"
+
+We can also operator on colors, and values are clamped appropriately.
+
+ #fff - #111
+ => #eee
+
+ #111 + #fco
+ // => #fd1
+
+ #fff - rgba(255,0,0,0.3)
+ // => rgba(0,255,255,0.7)
+
+ #fff / 2
+ // => #808080
+
+ #fff / rgb(2,0,4)
+ // #80ff40
+
+### Multiplicative: / * %
+
+ 2000ms + (1s * 2)
+ // => 4ms
+
+ 5s / 2
+ // => 2.5s
+
+ 4 % 2
+ // => 0
+
+When using `/` within a property value you must wrap with parens. The following for example is taken literally, to support css line-height:
+
+ font: 14px/1.5;
+
+whereas the following is evaluated, dividing `14px` by `1.5`:
+
+ font: (14px/1.5);
+
+this exception is _only_ required for the `/` operator.
+
+### Exponent: **
+
+The Exponent operator:
+
+ 2 ** 8
+ // => 256
+
+### Equality: == != >= <= > <
+
+Equality operators can be used to equate units, colors, strings, and even identifiers. This is a powerful concept, as even arbitrary identifiers such as as `wahoo` can be utilized as atoms, a function could return `yes` or `no` instead of `true` or `false` (although not advised).
+
+ 5 == 5
+ // => true
+
+ 10 < 5
+ // => true
+
+ #fff == #fff
+ // => true
+
+ true == false
+ // => false
+
+ wahoo == yay
+ // => false
+
+ wahoo == wahoo
+ // => true
+
+ "test" == "test"
+ // => true
+
+ true is true
+ // => true
+
+ 'hey' is not 'bye'
+ // => true
+
+ 'hey' isnt 'bye'
+ // => true
+
+Only exact values match, for example `0 == false`, and `null == false` are both `false`.
+
+Aliases:
+
+ == is
+ != is not
+ != isnt
+
+## Truthfulness
+
+ Nearly everything within Stylus resolves to `true`, including units with a suffix, for example even `0%`, `0px`, etc will resolve to `true`, since commonly in Stylus a mixin or function may accept such units as valid, however `0` itself is `false` in terms of arithmetic.
+
+`true` examples:
+
+ 0%
+ 0px
+ 1px
+ -1
+ -1px
+ hey
+ 'hey'
+
+`false` examples:
+
+ 0
+ null
+ false
+ ''
+
+### Logical Operators: && || and or
+
+Logical operators `&&` and `||` are aliased `and` / `or` which apply the same precedence.
+
+ 5 && 3
+ // => 3
+
+ 0 || 5
+ // => 5
+
+ 0 && 5
+ // => 0
+
+ #fff is a 'rgba' and 15 is a 'unit'
+ // => true
+
+### Existence Operator: in
+
+ Checks for the existence of the _left-hand_ operand within the _right-hand_ expression.
+
+Simple examples:
+
+ nums = 1 2 3
+ 1 in nums
+ // => true
+
+ 5 in nums
+ // => false
+
+Some undefined identifiers:
+
+ words = foo bar baz
+ bar in words
+ // => true
+
+ HEY in words
+ // => false
+
+Works with tuples too:
+
+ vals = (error 'one') (error 'two')
+ error in vals
+ // => false
+
+ (error 'one') in vals
+ // => true
+
+ (error 'two') in vals
+ // => true
+
+ (error 'something') in vals
+ // => false
+
+Example usage in mixin:
+
+ pad(types = padding, n = 5px)
+ if padding in types
+ padding n
+ if margin in types
+ margin n
+
+ body
+ pad()
+
+ body
+ pad(margin)
+
+ body
+ pad(padding margin, 10px)
+
+yielding:
+
+ body {
+ padding: 5px;
+ }
+ body {
+ margin: 5px;
+ }
+ body {
+ padding: 10px;
+ margin: 10px;
+ }
+
+### Conditional Assignment: ?=
+
+The conditional assignment operator `?=` lets us define variables without clobbering old values (when present). This operator expands to an `is defined` binary operation within a ternary, for example the following are equivalent:
+
+ color ?= white
+ color = color is defined ? color : white
+
+For example when using `=` we simply re-assign:
+
+ color = white
+ color = black
+
+ color
+ // => black
+
+However when using `?=` our second attempt fails since the variable is already defined:
+
+ color = white
+ color ?= black
+
+ color
+ // => white
+
+### Instance Check: is a
+
+Stylus provides a binary operator named `is a` used to type check.
+
+ 15 is a 'unit'
+ // => true
+
+ #fff is a 'rgba'
+ // => true
+
+ 15 is a 'rgba'
+ // => false
+
+Alternatively we could use the `type()` BIF:
+
+ type(#fff) == 'rgba'
+ // => true
+
+'color' is the one special-case, evaluating to true when the
+left-hand operand is an `RGBA` or `HSLA` node.
+
+### Variable Definition: is defined
+
+This pseudo binary operator does not accept a right-hand operator, and does _not_ evaluate the left. This allows us to check if a variable has a value assigned to it.
+
+ foo is defined
+ // => false
+
+ foo = 15px
+ foo is defined
+ // => true
+
+ #fff is defined
+ // => 'invalid "is defined" check on non-variable #fff'
+
+Alternatively one can use the `lookup(name)` built-in function to do this, or to perform dynamic lookups:
+
+ name = 'blue'
+ lookup('light-' + name)
+ // => null
+
+ light-blue = #80e2e9
+ lookup('light-' + name)
+ // => #80e2e9
+
+This operator is essential, as an undefined identifier is still a truthy value. For example:
+
+ body
+ if ohnoes
+ padding 5px
+
+_will_ yield the following css when undefined:
+
+ body {
+ padding: 5px;
+ }
+
+however this will be safe:
+
+ body
+ if ohnoes is defined
+ padding 5px
+
+## Ternary
+
+The ternary operator works as we would expect in most languages, being the only operator with three operands, the _condition_ expression, the _truth_ expression and the _false_ expression.
+
+ num = 15
+ num ? unit(num, 'px') : 20px
+ // => 15px
+
+
--- /dev/null
+
+## Selectors
+
+### Indentation
+
+Stylus is "pythonic" aka indentation-based. Whitespace is significant, so we substitute { and } with an _indent_, and an _outdent_ as shown below:
+
+ body
+ color white
+
+which compiles to:
+
+ body {
+ color: #fff;
+ }
+
+Optionally if preferred we may utilize colons to separate properties and their values:
+
+ body
+ color: white
+
+### Rule Sets
+
+Stylus, just like css allows you to define properties for several selectors at once through comma separation.
+
+ textarea, input
+ border 1px solid #eee
+
+The same can be done with a newline:
+
+ textarea
+ input
+ border 1px solid #eee
+
+both compiling to:
+
+ textarea,
+ input {
+ border: 1px solid #eee;
+ }
+
+The one exception to this rule, are selectors that look like properties, for example `foo bar baz` in the following may be a property, or a selector:
+
+ foo bar baz
+ > input
+ border 1px solid
+
+so for this reason, or if simply preferred we may trail with a comma:
+
+ foo bar baz,
+ form input,
+ > a
+ border 1px solid
+
+### Parent Reference
+
+The `&` character references the parent selector(s). In the example below our two selectors `textarea`, and `input` both alter the `color` on the `:hover` pseudo selector.
+
+ textarea
+ input
+ color #A7A7A7
+ &:hover
+ color #000
+
+compiles to:
+
+ textarea,
+ input {
+ color: #a7a7a7;
+ }
+ textarea:hover,
+ input:hover {
+ color: #000;
+ }
+
+below is an example providing a simple `2px` border for internet exploder utilizing the parent reference within a mixin:
+
+ box-shadow()
+ -webkit-box-shadow arguments
+ -moz-box-shadow arguments
+ box-shadow arguments
+ html.ie8 &,
+ html.ie7 &,
+ html.ie6 &
+ border 2px solid arguments[length(arguments) - 1]
+
+ body
+ #login
+ box-shadow 1px 1px 3px #eee
+
+yielding:
+
+ body #login {
+ -webkit-box-shadow: 1px 1px 3px #eee;
+ -moz-box-shadow: 1px 1px 3px #eee;
+ box-shadow: 1px 1px 3px #eee;
+ }
+ html.ie8 body #login,
+ html.ie7 body #login,
+ html.ie6 body #login {
+ border: 1px solid #eee;
+ }
+
+### Disambiguation
+
+Expressions such as `padding - n` could be interpreted both as a subtraction operation, as well as a property with an unary minus. To disambiguate we can wrap the expression with parens:
+
+ pad(n)
+ padding (- n)
+
+ body
+ pad(5px)
+
+compiles to:
+
+ body {
+ padding: -5px;
+ }
+
+however this is only true in functions, since functions act both as mixins, or calls with return values. For example this is fine, and will yield the same results as above:
+
+ body
+ padding -5px
+
+Have weird property values that Stylus cannot process? `unquote()` can help you out:
+
+ filter unquote('progid:DXImageTransform.Microsoft.BasicImage(rotation=1)')
+
+yields:
+
+ filter progid:DXImageTransform.Microsoft.BasicImage(rotation=1)
+
\ No newline at end of file
--- /dev/null
+
+## TextMate Bundle
+
+ Stylus ships with a TextMate bundle, located within `./editors`. To install simply execute `make install-bundle`, or place `./editors/Stylus.tmbundle` in the appropriate location.
+
+
+ ![Stylus TextMate Bundle](http://cl.ly/4CA7)
\ No newline at end of file
--- /dev/null
+
+## Rest Parameters
+
+ Stylus supports rest parameters in the form of `name...`. These params consume the remaining arguments passed to a mixin or function. This is useful for example when utilizing the implicit function call support to apply vendor prefixes like `-webkit` or `-moz`.
+
+
+In the example below we consume all the arguments passed and simply apply them to multiple properties.
+
+ box-shadow(args...)
+ -webkit-box-shadow args
+ -moz-box-shadow args
+ box-shadow args
+
+ #login
+ box-shadow 1px 2px 5px #eee
+
+yielding:
+
+ #login {
+ -webkit-box-shadow: 1px 2px 5px #eee;
+ -moz-box-shadow: 1px 2px 5px #eee;
+ box-shadow: 1px 2px 5px #eee;
+ }
+
+If we wanted to peek at a specific argument, for example the x-offset we could simply use `args[0]`, or for example we may wish to re-define the mixin:
+
+ box-shadow(offset-x, args...)
+ got-offset-x offset-x
+ -webkit-box-shadow offset-x args
+ -moz-box-shadow offset-x args
+ box-shadow offset-x args
+
+ #login
+ box-shadow 1px 2px 5px #eee
+
+yielding:
+
+ #login {
+ got-offset-x: 1px;
+ -webkit-box-shadow: 1px 2px 5px #eee;
+ -moz-box-shadow: 1px 2px 5px #eee;
+ box-shadow: 1px 2px 5px #eee;
+ }
+
+### arguments
+
+ The `arguments` variable is injected into mixin and function bodies, containing the exact expression passed. This is useful for several reasons, primarily for vendor support, as you get the _exact_ expression, commas and all.
+
+ For example, if we use a rest param, the comma is simply consumed since it is an expression delimiter:
+
+ box-shadow(args...)
+ -webkit-box-shadow args
+ -moz-box-shadow args
+ box-shadow args
+
+ #login
+ box-shadow #ddd 1px 1px, #eee 2px 2px
+
+yielding slightly unexpected results:
+
+ #login {
+ -webkit-box-shadow: #ddd 1px 1px #eee 2px 2px;
+ -moz-box-shadow: #ddd 1px 1px #eee 2px 2px;
+ box-shadow: #ddd 1px 1px #eee 2px 2px;
+ }
+
+Let's redefine the mixin using `arguments`:
+
+ box-shadow()
+ -webkit-box-shadow arguments
+ -moz-box-shadow arguments
+ box-shadow arguments
+
+ body
+ box-shadow #ddd 1px 1px, #eee 2px 2px
+
+now yielding the desired result:
+
+ body {
+ -webkit-box-shadow: #ddd 1px 1px, #eee 2px 2px;
+ -moz-box-shadow: #ddd 1px 1px, #eee 2px 2px;
+ box-shadow: #ddd 1px 1px, #eee 2px 2px;
+ }
+
--- /dev/null
+
+## Variables
+
+We may assign expressions to variables and use them throughout our stylesheet:
+
+ font-size = 14px
+
+ body
+ font font-size Arial, sans-serif
+
+compiles to:
+
+ body {
+ font: 14px Arial, sans-serif;
+ }
+
+Variables can even consist of an expression list:
+
+ font-size = 14px
+ font = font-size "Lucida Grande", Arial
+
+ body
+ font font sans-serif
+
+compiles to:
+
+ body {
+ font: 14px "Lucida Grande", Arial sans-serif;
+ }
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>fileTypes</key>
+ <array>
+ <string>styl</string>
+ <string>stylus</string>
+ </array>
+ <key>name</key>
+ <string>Stylus</string>
+ <key>patterns</key>
+ <array>
+ <dict>
+ <key>match</key>
+ <string>^ *(&|)</string>
+ <key>name</key>
+ <string>variable.language.stylus</string>
+ </dict>
+ <dict>
+ <key>match</key>
+ <string>(arguments)</string>
+ <key>name</key>
+ <string>variable.language.stylus</string>
+ </dict>
+ <dict>
+ <key>match</key>
+ <string>@([-\w]+)</string>
+ <key>name</key>
+ <string>keyword.stylus</string>
+ </dict>
+ <dict>
+ <key>captures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.entity.stylus</string>
+ </dict>
+ </dict>
+ <key>match</key>
+ <string>(\.)[a-zA-Z0-9_-]+</string>
+ <key>name</key>
+ <string>entity.other.attribute-name.class.stylus</string>
+ </dict>
+ <dict>
+ <key>captures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.entity.stylus</string>
+ </dict>
+ </dict>
+ <key>match</key>
+ <string>(:+)\b(after|before|first-child|first-letter|first-line|selection)\b</string>
+ <key>name</key>
+ <string>entity.other.attribute-name.pseudo-element.stylus</string>
+ </dict>
+ <dict>
+ <key>captures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.entity.stylus</string>
+ </dict>
+ </dict>
+ <key>match</key>
+ <string>(:)\b(active|hover|link|visited|focus)\b</string>
+ <key>name</key>
+ <string>entity.other.attribute-name.pseudo-class.stylus</string>
+ </dict>
+ <dict>
+ <key>captures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.entity.css</string>
+ </dict>
+ </dict>
+ <key>match</key>
+ <string>(#)[a-zA-Z][a-zA-Z0-9_-]*</string>
+ <key>name</key>
+ <string>entity.other.attribute-name.id.stylus</string>
+ </dict>
+ <dict>
+ <key>match</key>
+ <string>\b(!important|for|in|return|true|false|null|if|else|unless|return)\b</string>
+ <key>name</key>
+ <string>keyword.control.stylus</string>
+ </dict>
+ <dict>
+ <key>begin</key>
+ <string>"</string>
+ <key>end</key>
+ <string>"</string>
+ <key>name</key>
+ <string>string.quoted.double.stylus</string>
+ </dict>
+ <dict>
+ <key>begin</key>
+ <string>'</string>
+ <key>end</key>
+ <string>'</string>
+ <key>name</key>
+ <string>string.quoted.single.stylus</string>
+ </dict>
+ <dict>
+ <key>begin</key>
+ <string>/\*</string>
+ <key>captures</key>
+ <dict>
+ <key>0</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.comment.js</string>
+ </dict>
+ </dict>
+ <key>end</key>
+ <string>\*/</string>
+ <key>name</key>
+ <string>comment.block.js</string>
+ </dict>
+ <dict>
+ <key>match</key>
+ <string>(?:\b(\d+))|(#[a-fA-F0-9]+)</string>
+ <key>name</key>
+ <string>constant.numeric.stylus</string>
+ </dict>
+ <dict>
+ <key>captures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>punctuation.definition.comment.stylus</string>
+ </dict>
+ </dict>
+ <key>match</key>
+ <string>(?:^[ \t]+)?(\/\/).*$\n?</string>
+ <key>name</key>
+ <string>comment.line.stylus</string>
+ </dict>
+ <dict>
+ <key>captures</key>
+ <dict>
+ <key>1</key>
+ <dict>
+ <key>name</key>
+ <string>entity.name.function.stylus</string>
+ </dict>
+ </dict>
+ <key>match</key>
+ <string>([-a-zA-Z_][-\w]*)?(\()</string>
+ <key>name</key>
+ <string>meta.function.stylus</string>
+ </dict>
+ </array>
+ <key>scopeName</key>
+ <string>source.stylus</string>
+ <key>uuid</key>
+ <string>60519324-6A3A-4382-9E0B-546993A3869A</string>
+</dict>
+</plist>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>name</key>
+ <string>Stylus</string>
+ <key>uuid</key>
+ <string>DD7889E4-2ACA-4DF5-838F-FC9D7AEAF3F1</string>
+</dict>
+</plist>
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/arithmetic.styl', 'utf8');
+
+css.render(str, { filename: 'arithmetic.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+font-families = "Lucida Grande", Arial, sans-serif
+font-size = 14px
+primary-color = #3a3a3a
+width = 800px
+pad = 20px
+
+body
+ font font-size/1.5 font-families
+ background white
+ color primary-color
+
+h1
+ font-size font-size * (5 - 3)
+ color primary-color + #030303
+
+h2
+ color primary-color - rgba(0,0,0,0.5)
+
+#wrapper
+ width width
+
+.side-bar
+ padding pad
+ width (width / 3) - pad
+ // 6
+ height 3 - - - - 3
+ // 7
+ height 1 + 2 * 3
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/basic.styl', 'utf8');
+
+css.render(str, { filename: 'basic.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+body a
+ font 12px/1.3 "Lucida Grande", Arial, sans-serif
+ background black
+ color #ccc
+
+form input
+ padding 5px
+ border 1px solid
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/builtins.styl', 'utf8');
+
+css.render(str, { filename: 'builtins.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+
+// color manipulation
+
+body
+ color darken(#eee, 50%)
+ color darken-by(#eee, 50%)
+ color #eee - rgba(100,0,0,0.5)
+ color rgba(#eee,.5)
+
+// expression node access
+
+body
+ list = (one 1) (two 2) (three 3)
+ foo last(list)
+
+// pseudo hashes
+
+get(hash, key)
+ return pair[1] if pair[0] == key for pair in hash
+
+body
+ hash = (one 1) (two 2) (three 3)
+ foo get(hash, two)
+ foo get(hash, one)
+ foo get(hash, none) == null
+ foo length(hash)
+
+// color components
+
+body
+ foo red(#c00)
+ foo lightness(#c00)
+
+// units
+
+body
+ foo unit(15%)
+ foo unit(15%, px)
+ foo unit(15px, '%')
+
+// math
+
+body
+ foo abs(-5)
+ foo sum(1 2 3 4)
+ foo avg(1 2 3 4)
+
+// literals
+
+body
+ foo unquote('X::MessedUp::IE.crap(here)')
+
+// inspection
+
+p(1 + 5 / 10)
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/comments.styl', 'utf8');
+
+css.render(str, { filename: 'comments.styl' }, function(err, css){
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+// This is a comment
+body
+ color white
+ // You can nest them as you wish
+ // and have more comments
+ // and more!
+
+/*
+We can also use multi-line comments
+like this, which are native to css
+*/
+
+form
+ /* color black */
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/basic.styl', 'utf8');
+
+css.render(str, { filename: 'basic.styl', compress: true }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/conversions.styl', 'utf8');
+
+css.render(str, { filename: 'conversions.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+seconds(n)
+ 0s + n
+
+body
+ foo 15px - 5px
+ foo 15px - 5
+
+ // 60.8mm
+ foo 5cm - 2mm
+ foo 10mm + 2in
+
+ // 3.54cm
+ foo 1cm + 1in
+
+ // 3in
+ foo 5in - 5.08cm
+
+ // 0.8s
+ foo 1s - 200ms
+
+ // 3500ms
+ foo 1500ms + 2s
+
+ // 3000Hz
+ foo 1000Hz + 2kHz
+
+ // 1kHz
+ foo 3kHz - (1000Hz * 2)
+
+ n = 30%
+ foo unit(n, 'px')
+
+ foo seconds(1500ms)
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/functions.styl', 'utf8');
+
+css.render(str, { filename: 'functions.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+
+// ?= would allow us to define the images global before @importing
+// the file if we were to distribute this
+
+images ?= '/images'
+
+image(path)
+ url(join('/', images path))
+
+// or
+
+image(path)
+ url(images + '/' + path)
+
+body
+ background image('foo.png')
+
+// functions can act as both mixins
+// or have a return value
+
+image(path)
+ if mixin
+ background image(path)
+ else
+ url(images + '/' + path)
+
+body
+ image('something.png')
+ background image('something.png')
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var stylus = require('../')
+ , nodes = stylus.nodes
+ , path = __dirname + '/images.styl'
+ , str = require('fs').readFileSync(path, 'utf8');
+
+// the paths option is merged with the general options
+// so it is completely optional, however this now allows us to use
+// url(sprite.gif) instead of url(images/sprite.gif)
+stylus(str)
+ .set('filename', path)
+ .define('url', stylus.url({ paths: [__dirname + '/images'] }))
+ .render(function(err, css){
+ if (err) throw err;
+ console.log(css);
+ });
\ No newline at end of file
--- /dev/null
+
+body
+ background url("http://foo.com/bar.png")
+
+#wrapper
+ background url(/images/gopher.jpg)
+
+.sprite
+ // both work due to the additional paths option
+ // passed to stylus.url()
+ background url(/images/sprite.gif)
+ background url(sprite.gif)
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/implicit-functions.styl', 'utf8');
+
+css.render(str, { filename: 'implicit-functions.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+border-radius()
+ -webkit-border-radius arguments
+ -moz-border-radius arguments
+ border-radius arguments
+
+form
+ border-radius 5px
+
+a.button
+ border-radius 10px
+
+
+support-for-ie ?= true
+
+opacity(n)
+ opacity n
+ if support-for-ie
+ filter unquote('progid:DXImageTransform.Microsoft.Alpha(Opacity=' + round(n * 100) + ')')
+
+#logo
+ &:hover
+ opacity 0.5
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/import.styl', 'utf8');
+
+css.render(str, { filename: __dirname + '/import.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+@import "mixins/box"
+
+body
+ pad 10px 5px
+
+body
+ pad 5px
+
+body
+ pad-x 5px
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , nodes = css.nodes
+ , str = require('fs').readFileSync(__dirname + '/js-functions.styl', 'utf8')
+ , fs = require('fs');
+
+function add(a, b) {
+ return a.operate('+', b);
+}
+
+function sub(a, b) {
+ return a.operate('-', b);
+}
+
+function imageSize(img) {
+ // assert that the node (img) is a String node, passing
+ // the param name for error reporting
+ css.utils.assertType(img, nodes.String, 'img');
+ var path = img.val;
+
+ // Grab bytes necessary to retrieve dimensions.
+ // if this was real you would do this per format,
+ // instead of reading the entire image :)
+ var data = fs.readFileSync(__dirname + '/' + path);
+
+ // GIF
+ // of course you would support.. more :)
+ if ('GIF' == data.slice(0, 3).toString()) {
+ var w = data.slice(6, 8)
+ , h = data.slice(8, 10);
+ w = w[1] << 8 | w[0];
+ h = h[1] << 8 | h[0];
+ }
+
+ // Return (w h)
+ var expr = new nodes.Expression;
+ expr.push(new nodes.Unit(w));
+ expr.push(new nodes.Unit(h));
+
+ return expr;
+}
+
+css(str)
+ .set('filename', 'js-functions.styl')
+ .define('add', add)
+ .define('sub', sub)
+ .define('image-size', imageSize)
+ .render(function(err, css){
+ if (err) throw err;
+ console.log(css);
+ });
\ No newline at end of file
--- /dev/null
+
+image-width(path)
+ return image-size(path)[0]
+
+image-height(path)
+ return image-size(path)[1]
+
+body
+ font add(5px, 10px)
+ font sub(5px, 10px)
+
+#jesus
+ width image-width('images/jesus.gif')
+ height image-height('images/jesus.gif')
+
+#jesus-2
+ width image-size('images/jesus.gif')[0]
+ height image-size('images/jesus.gif')[1]
+
+#jesus-3
+ size = image-size('images/jesus.gif')
+ width size[0]
+ height size[1]
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/literal.styl', 'utf8');
+
+css.render(str, { filename: 'literal.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+@css {
+ body {
+ font: 14px;
+ }
+
+ a { text-decoration: none; }
+}
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var connect = require('connect')
+ , stylus = require('../');
+
+// Setup server
+// $ curl http://localhost:3000/functions.css
+
+var server = connect.createServer(
+ stylus.middleware({
+ src: __dirname
+ , dest: __dirname + '/public'
+ , compress: true
+ }),
+ connect.static(__dirname + '/public')
+);
+
+server.listen(3000);
+console.log('server listening on port 3000');
\ No newline at end of file
--- /dev/null
+
+pad(x, y = x)
+ if y == x
+ padding y
+ else
+ padding y x y x
+
+pad-x(n)
+ padding-left n
+ padding-right n
+
+pad-y(n)
+ padding-top n
+ padding-bottom n
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/nesting.styl', 'utf8');
+
+css.render(str, { filename: 'nesting.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+body
+ background #ccc
+ color #000
+
+form
+ .buttons
+ margin 10px 0
+ padding 5px
+ [type=submit]
+ padding 5px
+ border none
+ input
+ border 1px solid #ccc
--- /dev/null
+*.css
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var css = require('../')
+ , str = require('fs').readFileSync(__dirname + '/variables.styl', 'utf8');
+
+css.render(str, { filename: 'variables.styl' }, function(err, css){
+ if (err) throw err;
+ console.log(css);
+});
\ No newline at end of file
--- /dev/null
+
+font-families = "Lucida Grande", Arial
+main-width = 80%
+main-color = #fff
+sidebar-width = main-width / 2
+
+// Mixins can use conditionals
+// to supply defaults
+unless font-families is defined
+ font-families = 'WAHOO'
+
+// Alternatively we may use ?=
+font-families ?= 'WAHOO'
+
+body
+ size = 12px
+ font size font-families, sans-serif
+ color main-color
+
+#wrapper
+ width main-width
+
+.sidebar
+ width sidebar-width
\ No newline at end of file
--- /dev/null
+
+module.exports = require('./lib/stylus');
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - colors
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+module.exports = {
+ aliceblue: [240, 248, 255]
+ , antiquewhite: [250, 235, 215]
+ , aqua: [0, 255, 255]
+ , aquamarine: [127, 255, 212]
+ , azure: [240, 255, 255]
+ , beige: [245, 245, 220]
+ , bisque: [255, 228, 196]
+ , black: [0, 0, 0]
+ , blanchedalmond: [255, 235, 205]
+ , blue: [0, 0, 255]
+ , blueviolet: [138, 43, 226]
+ , brown: [165, 42, 42]
+ , burlywood: [222, 184, 135]
+ , cadetblue: [95, 158, 160]
+ , chartreuse: [127, 255, 0]
+ , chocolate: [210, 105, 30]
+ , coral: [255, 127, 80]
+ , cornflowerblue: [100, 149, 237]
+ , cornsilk: [255, 248, 220]
+ , crimson: [220, 20, 60]
+ , cyan: [0, 255, 255]
+ , darkblue: [0, 0, 139]
+ , darkcyan: [0, 139, 139]
+ , darkgoldenrod: [184, 132, 11]
+ , darkgray: [169, 169, 169]
+ , darkgreen: [0, 100, 0]
+ , darkgrey: [169, 169, 169]
+ , darkkhaki: [189, 183, 107]
+ , darkmagenta: [139, 0, 139]
+ , darkolivegreen: [85, 107, 47]
+ , darkorange: [255, 140, 0]
+ , darkorchid: [153, 50, 204]
+ , darkred: [139, 0, 0]
+ , darksalmon: [233, 150, 122]
+ , darkseagreen: [143, 188, 143]
+ , darkslateblue: [72, 61, 139]
+ , darkslategray: [47, 79, 79]
+ , darkslategrey: [47, 79, 79]
+ , darkturquoise: [0, 206, 209]
+ , darkviolet: [148, 0, 211]
+ , deeppink: [255, 20, 147]
+ , deepskyblue: [0, 191, 255]
+ , dimgray: [105, 105, 105]
+ , dimgrey: [105, 105, 105]
+ , dodgerblue: [30, 144, 255]
+ , firebrick: [178, 34, 34]
+ , floralwhite: [255, 255, 240]
+ , forestgreen: [34, 139, 34]
+ , fuchsia: [255, 0, 255]
+ , gainsboro: [220, 220, 220]
+ , ghostwhite: [248, 248, 255]
+ , gold: [255, 215, 0]
+ , goldenrod: [218, 165, 32]
+ , gray: [128, 128, 128]
+ , green: [0, 128, 0]
+ , greenyellow: [173, 255, 47]
+ , grey: [128, 128, 128]
+ , honeydew: [240, 255, 240]
+ , hotpink: [255, 105, 180]
+ , indianred: [205, 92, 92]
+ , indigo: [75, 0, 130]
+ , ivory: [255, 255, 240]
+ , khaki: [240, 230, 140]
+ , lavender: [230, 230, 250]
+ , lavenderblush: [255, 240, 245]
+ , lawngreen: [124, 252, 0]
+ , lemonchiffon: [255, 250, 205]
+ , lightblue: [173, 216, 230]
+ , lightcoral: [240, 128, 128]
+ , lightcyan: [224, 255, 255]
+ , lightgoldenrodyellow: [250, 250, 210]
+ , lightgray: [211, 211, 211]
+ , lightgreen: [144, 238, 144]
+ , lightgrey: [211, 211, 211]
+ , lightpink: [255, 182, 193]
+ , lightsalmon: [255, 160, 122]
+ , lightseagreen: [32, 178, 170]
+ , lightskyblue: [135, 206, 250]
+ , lightslategray: [119, 136, 153]
+ , lightslategrey: [119, 136, 153]
+ , lightsteelblue: [176, 196, 222]
+ , lightyellow: [255, 255, 224]
+ , lime: [0, 255, 0]
+ , limegreen: [50, 205, 50]
+ , linen: [250, 240, 230]
+ , magenta: [255, 0, 255]
+ , maroon: [128, 0, 0]
+ , mediumaquamarine: [102, 205, 170]
+ , mediumblue: [0, 0, 205]
+ , mediumorchid: [186, 85, 211]
+ , mediumpurple: [147, 112, 219]
+ , mediumseagreen: [60, 179, 113]
+ , mediumslateblue: [123, 104, 238]
+ , mediumspringgreen: [0, 250, 154]
+ , mediumturquoise: [72, 209, 204]
+ , mediumvioletred: [199, 21, 133]
+ , midnightblue: [25, 25, 112]
+ , mintcream: [245, 255, 250]
+ , mistyrose: [255, 228, 225]
+ , moccasin: [255, 228, 181]
+ , navajowhite: [255, 222, 173]
+ , navy: [0, 0, 128]
+ , oldlace: [253, 245, 230]
+ , olive: [128, 128, 0]
+ , olivedrab: [107, 142, 35]
+ , orange: [255, 165, 0]
+ , orangered: [255, 69, 0]
+ , orchid: [218, 112, 214]
+ , palegoldenrod: [238, 232, 170]
+ , palegreen: [152, 251, 152]
+ , paleturquoise: [175, 238, 238]
+ , palevioletred: [219, 112, 147]
+ , papayawhip: [255, 239, 213]
+ , peachpuff: [255, 218, 185]
+ , peru: [205, 133, 63]
+ , pink: [255, 192, 203]
+ , plum: [221, 160, 203]
+ , powderblue: [176, 224, 230]
+ , purple: [128, 0, 128]
+ , red: [255, 0, 0]
+ , rosybrown: [188, 143, 143]
+ , royalblue: [65, 105, 225]
+ , saddlebrown: [139, 69, 19]
+ , salmon: [250, 128, 114]
+ , sandybrown: [244, 164, 96]
+ , seagreen: [46, 139, 87]
+ , seashell: [255, 245, 238]
+ , sienna: [160, 82, 45]
+ , silver: [192, 192, 192]
+ , skyblue: [135, 206, 235]
+ , slateblue: [106, 90, 205]
+ , slategray: [119, 128, 144]
+ , slategrey: [119, 128, 144]
+ , snow: [255, 255, 250]
+ , springgreen: [0, 255, 127]
+ , steelblue: [70, 130, 180]
+ , tan: [210, 180, 140]
+ , teal: [0, 128, 128]
+ , thistle: [216, 191, 216]
+ , tomato: [255, 99, 71]
+ , turquoise: [64, 224, 208]
+ , violet: [238, 130, 238]
+ , wheat: [245, 222, 179]
+ , white: [255, 255, 255]
+ , whitesmoke: [245, 245, 245]
+ , yellow: [255, 255, 0]
+ , yellowgreen: [154, 205, 5]
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - css to stylus conversion
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Convert the given `css` to stylus source.
+ *
+ * @param {String} css
+ * @return {String}
+ * @api public
+ */
+
+module.exports = function(css){
+ return new Converter(css).stylus();
+};
+
+/**
+ * Initialize a new `Converter` with the given `css`.
+ *
+ * @param {String} css
+ * @api private
+ */
+
+function Converter(css) {
+ var cssom = require('cssom');
+ this.css = css;
+ this.types = cssom.CSSRule;
+ this.root = cssom.parse(css);
+ this.indents = 0;
+}
+
+/**
+ * Convert to stylus.
+ *
+ * @return {String}
+ * @api private
+ */
+
+Converter.prototype.stylus = function(){
+ return this.visitRules(this.root.cssRules);
+};
+
+/**
+ * Return indent string.
+ *
+ * @return {String}
+ * @api private
+ */
+
+Converter.prototype.__defineGetter__('indent', function(){
+ return Array(this.indents + 1).join(' ');
+});
+
+/**
+ * Visit `node`.
+ *
+ * @param {CSSRule} node
+ * @return {String}
+ * @api private
+ */
+
+Converter.prototype.visit = function(node){
+ switch (node.type) {
+ case this.types.STYLE_RULE:
+ return this.visitStyle(node);
+ case this.types.MEDIA_RULE:
+ return this.visitMedia(node);
+ }
+};
+
+/**
+ * Visit the rules on `node`.
+ *
+ * @param {CSSRule} node
+ * @return {String}
+ * @api private
+ */
+
+Converter.prototype.visitRules = function(node){
+ var buf = '';
+ for (var i = 0, len = node.length; i < len; ++i) {
+ buf += this.visit(node[i]);
+ }
+ return buf;
+};
+
+/**
+ * Visit CSSMediaRule `node`.
+ *
+ * @param {CSSMediaRule} node
+ * @return {String}
+ * @api private
+ */
+
+Converter.prototype.visitMedia = function(node){
+ var buf = this.indent + '@media ';
+ for (var i = 0, len = node.media.length; i < len; ++i) {
+ buf += node.media[i];
+ }
+ buf += '\n';
+ ++this.indents;
+ buf += this.visitRules(node.cssRules);
+ --this.indents;
+ return buf;
+};
+
+/**
+ * Visit CSSStyleRule `node`.`
+ *
+ * @param {CSSStyleRule} node
+ * @return {String}
+ * @api private
+ */
+
+Converter.prototype.visitStyle = function(node){
+ var buf = this.indent + node.selectorText + '\n';
+ ++this.indents;
+ for (var i = 0, len = node.style.length; i < len; ++i) {
+ var prop = node.style[i]
+ , val = node.style[prop];
+ if (prop) {
+ buf += this.indent + prop + ' ' + val + '\n';
+ }
+ }
+ --this.indents;
+ return buf + '\n';
+};
\ No newline at end of file
--- /dev/null
+
+
+/*!
+ * Stylus - plugin - url
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var utils = require('../utils')
+ , nodes = require('../nodes')
+ , fs = require('fs');
+
+/**
+ * Initialize a new `Image` with the given `ctx` and `path.
+ *
+ * @param {Evaluator} ctx
+ * @param {String} path
+ * @api private
+ */
+
+var Image = module.exports = function Image(ctx, path) {
+ this.ctx = ctx;
+ this.path = utils.lookup(path, ctx.paths);
+ if (!this.path) throw new Error('failed to locate file ' + path);
+};
+
+/**
+ * Open the image for reading.
+ *
+ * @api private
+ */
+
+Image.prototype.open = function(){
+ this.fd = fs.openSync(this.path, 'r');
+};
+
+/**
+ * Close the file.
+ *
+ * @api private
+ */
+
+Image.prototype.close = function(){
+ if (this.fd) fs.closeSync(this.fd);
+};
+
+/**
+ * Return the type of image, supports:
+ *
+ * - gif
+ * - png
+ * - jpeg
+ *
+ * @return {String}
+ * @api private
+ */
+
+Image.prototype.type = function(){
+ var type
+ , buf = new Buffer(4);
+
+ fs.readSync(this.fd, buf, 0, 4, 0);
+
+ // GIF
+ if (0x47 == buf[0] && 0x49 == buf[1] && 0x46 == buf[2]) type = 'gif';
+
+ // PNG
+ else if (0x50 == buf[1] && 0x4E == buf[2] && 0x47 == buf[3]) type = 'png';
+
+ // JPEG
+ else if (0xff == buf[0] && 0xd8 == buf[1]) type = 'jpeg';
+
+ return type;
+};
+
+/**
+ * Return image dimensions `[width, height]`.
+ *
+ * @return {Array}
+ * @api private
+ */
+
+Image.prototype.size = function(){
+ var width
+ , height
+ , type = this.type();
+
+ function uint16(b) { return b[1] << 8 | b[0]; }
+ function uint32(b) { return b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3]; }
+
+ // Determine dimensions
+ switch (type) {
+ case 'jpeg':
+ throw new Error('image-size() jpeg support not yet implemented');
+ break;
+ case 'png':
+ var buf = new Buffer(8);
+ // IHDR chunk width / height uint32_t big-endian
+ fs.readSync(this.fd, buf, 0, 8, 16);
+ width = uint32(buf);
+ height = uint32(buf.slice(4, 8));
+ break;
+ case 'gif':
+ var buf = new Buffer(4);
+ // width / height uint16_t little-endian
+ fs.readSync(this.fd, buf, 0, 4, 6);
+ width = uint16(buf);
+ height = uint16(buf.slice(2, 4));
+ break;
+ }
+
+ if ('number' != typeof width) throw new Error('failed to find width of "' + this.path + '"');
+ if ('number' != typeof height) throw new Error('failed to find height of "' + this.path + '"');
+
+ return [width, height];
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Evaluator - built-in functions
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var nodes = require('../nodes')
+ , utils = require('../utils')
+ , Image = require('./image');
+
+/**
+ * Color component name map.
+ */
+
+var componentMap = {
+ red: 'r'
+ , green: 'g'
+ , blue: 'b'
+ , alpha: 'a'
+ , hue: 'h'
+ , saturation: 's'
+ , lightness: 'l'
+};
+
+/**
+ * Color component type map.
+ */
+
+var typeMap = {
+ hue: 'deg'
+ , saturation: '%'
+ , lightness: '%'
+};
+
+/**
+ * Convert the given `color` to an `HSLA` node,
+ * or h,s,l,a component values.
+ *
+ * Examples:
+ *
+ * hsla(10deg, 50%, 30%, 0.5)
+ * // => HSLA
+ *
+ * hsla(#ffcc00)
+ * // => HSLA
+ *
+ * @param {RGBA|HSLA|Unit} h
+ * @param {Unit} s
+ * @param {Unit} l
+ * @param {Unit} a
+ * @return {HSLA}
+ * @api public
+ */
+
+exports.hsla = function(h,s,l,a){
+ switch (arguments.length) {
+ case 1:
+ utils.assertColor(h);
+ return h.hsla;
+ default:
+ utils.assertType(h, nodes.Unit, 'hue');
+ utils.assertType(s, nodes.Unit, 'saturation');
+ utils.assertType(l, nodes.Unit, 'lightness');
+ utils.assertType(a, nodes.Unit, 'alpha');
+ return new nodes.HSLA(h.val,s.val,l.val,a.val);
+ }
+};
+
+/**
+ * Convert the given `color` to an `HSLA` node,
+ * or h,s,l component values.
+ *
+ * Examples:
+ *
+ * hsl(10, 50, 30)
+ * // => HSLA
+ *
+ * hsl(#ffcc00)
+ * // => HSLA
+ *
+ * @param {Unit|HSLA|RGBA} h
+ * @param {Unit} s
+ * @param {Unit} l
+ * @return {HSLA}
+ * @api public
+ */
+
+exports.hsl = function(h,s,l){
+ if (arguments.length > 1) {
+ return exports.hsla(h,s,l,new nodes.Unit(1));
+ }
+ utils.assertColor(h, 'color');
+ return h.hsla;
+};
+
+/**
+ * Return type of `node`.
+ *
+ * Examples:
+ *
+ * type(12)
+ * // => 'unit'
+ *
+ * type(#fff)
+ * // => 'color'
+ *
+ * type(type)
+ * // => 'function'
+ *
+ * type(unbound)
+ * typeof(unbound)
+ * type-of(unbound)
+ * // => 'ident'
+ *
+ * @param {Node} node
+ * @return {String}
+ * @api public
+ */
+
+exports.type =
+exports.typeof =
+exports['type-of'] = function(node){
+ utils.assertPresent(node, 'expression');
+ var type = node.nodeName;
+ return new nodes.String(type);
+};
+
+/**
+ * Return component `name` for the given `color`.
+ *
+ * @param {RGBA|HSLA} color
+ * @param {String} na,e
+ * @return {Unit}
+ * @api public
+ */
+
+exports.component = function(color, name) {
+ utils.assertColor(color, 'color');
+ utils.assertString(name, 'name');
+ var name = name.string
+ , type = typeMap[name]
+ , name = componentMap[name];
+ if (!name) throw new Error('invalid color component "' + name + '"');
+ return new nodes.Unit(color[name], type);
+};
+
+/**
+ * Return the red component of the given `color`.
+ *
+ * Examples:
+ *
+ * red(#c00)
+ * // => 204
+ *
+ * @param {RGBA|HSLA} color
+ * @return {Unit}
+ * @api public
+ */
+
+exports.red = function(color){
+ return exports.component(color, new nodes.String('red'));
+};
+
+/**
+ * Return the green component of the given `color`.
+ *
+ * Examples:
+ *
+ * green(#0c0)
+ * // => 204
+ *
+ * @param {RGBA|HSLA} color
+ * @return {Unit}
+ * @api public
+ */
+
+exports.green = function(color){
+ return exports.component(color, new nodes.String('green'));
+};
+
+/**
+ * Return the blue component of the given `color`.
+ *
+ * Examples:
+ *
+ * blue(#00c)
+ * // => 204
+ *
+ * @param {RGBA|HSLA} color
+ * @return {Unit}
+ * @api public
+ */
+
+exports.blue = function(color){
+ return exports.component(color, new nodes.String('blue'));
+};
+
+/**
+ * Return a `RGBA` from the r,g,b,a channels.
+ *
+ * Examples:
+ *
+ * rgba(255,0,0,0.5)
+ * // => rgba(255,0,0,0.5)
+ *
+ * rgba(255,0,0,1)
+ * // => #ff0000
+ *
+ * rgba(#ffcc00, 0.5)
+ * // rgba(255,204,0,0.5)
+ *
+ * @param {Unit|RGBA|HSLA} r
+ * @param {Unit} g
+ * @param {Unit} b
+ * @param {Unit} a
+ * @return {RGBA}
+ * @api public
+ */
+
+exports.rgba = function(r,g,b,a){
+ switch (arguments.length) {
+ case 1:
+ utils.assertColor(r);
+ var color = r.rgba;
+ return new nodes.RGBA(
+ color.r
+ , color.g
+ , color.b
+ , color.a);
+ case 2:
+ utils.assertColor(r);
+ var color = r.rgba;
+ utils.assertType(g, nodes.Unit);
+ return new nodes.RGBA(
+ color.r
+ , color.g
+ , color.b
+ , g.val);
+ default:
+ utils.assertType(r, nodes.Unit, 'red');
+ utils.assertType(g, nodes.Unit, 'green');
+ utils.assertType(b, nodes.Unit, 'blue');
+ utils.assertType(a, nodes.Unit, 'alpha');
+ return new nodes.RGBA(
+ r.val
+ , g.val
+ , b.val
+ , a.val);
+ }
+};
+
+/**
+ * Return a `RGBA` from the r,g,b channels.
+ *
+ * Examples:
+ *
+ * rgb(255,204,0)
+ * // => #ffcc00
+ *
+ * rgb(#fff)
+ * // => #fff
+ *
+ * @param {Unit|RGBA|HSLA} r
+ * @param {Unit} g
+ * @param {Unit} b
+ * @return {RGBA}
+ * @api public
+ */
+
+exports.rgb = function(r,g,b){
+ switch (arguments.length) {
+ case 1:
+ utils.assertColor(r);
+ var color = r.rgba;
+ return new nodes.RGBA(
+ color.r
+ , color.g
+ , color.b
+ , 1);
+ default:
+ return exports.rgba(r,g,b,new nodes.Unit(1));
+ }
+};
+
+/**
+ * Unquote the given `str`.
+ *
+ * Examples:
+ *
+ * unquote("sans-serif")
+ * // => sans-serif
+ *
+ * unquote(sans-serif)
+ * // => sans-serif
+ *
+ * @param {String|Ident} val
+ * @return {Literal}
+ * @api public
+ */
+
+exports.unquote = function(val){
+ utils.assertString(val, 'string');
+ return new nodes.Literal(val.string);
+};
+
+/**
+ * Assign `type` to the given `unit` or return `unit`'s type.
+ *
+ * @param {Unit} unit
+ * @param {String|Ident} type
+ * @return {Unit}
+ * @api public
+ */
+
+exports.unit = function(unit, type){
+ utils.assertType(unit, nodes.Unit, 'unit');
+
+ // Assign
+ if (type) {
+ utils.assertString(type, 'type');
+ return new nodes.Unit(unit.val, type.string);
+ } else {
+ return new nodes.String(unit.type || '');
+ }
+};
+
+/**
+ * Lookup variable `name` or return Null.
+ *
+ * @param {String} name
+ * @return {Mixed}
+ * @api public
+ */
+
+exports.lookup = function(name){
+ utils.assertType(name, nodes.String, 'name');
+ var node = this.lookup(name.val);
+ if (!node) return nodes.null;
+ return this.visit(node);
+};
+
+/**
+ * Perform `op` on the `left` and `right` operands.
+ *
+ * @param {String} op
+ * @param {Node} left
+ * @param {Node} right
+ * @return {Node}
+ * @api public
+ */
+
+exports.operate = function(op, left, right){
+ utils.assertType(op, nodes.String, 'op');
+ utils.assertPresent(left, 'left');
+ utils.assertPresent(right, 'right');
+ return left.operate(op.val, right);
+};
+
+/**
+ * Test if `val` matches the given `pattern`.
+ *
+ * Examples:
+ *
+ * match('^foo(bar)?', foo)
+ * match('^foo(bar)?', foobar)
+ * match('^foo(bar)?', 'foo')
+ * match('^foo(bar)?', 'foobar')
+ * // => true
+ *
+ * match('^foo(bar)?', 'bar')
+ * // => false
+ *
+ * @param {String} pattern
+ * @param {String|Ident} val
+ * @return {Boolean}
+ * @api public
+ */
+
+exports.match = function(pattern, val){
+ utils.assertType(pattern, nodes.String, 'pattern');
+ utils.assertString(val, 'val');
+ var re = new RegExp(pattern.val);
+ return nodes.Boolean(re.test(val.string));
+};
+
+/**
+ * Return length of the given `expr`.
+ *
+ * @param {Expression} expr
+ * @return {Unit}
+ * @api public
+ */
+
+(exports.length = function(expr){
+ if (expr) {
+ if (expr.nodes) {
+ return new nodes.Unit(utils.unwrap(expr).nodes.length);
+ } else {
+ return new nodes.Unit(1);
+ }
+ }
+ return new nodes.Unit(0);
+}).raw = true;
+
+/**
+ * Inspect the given `expr`.
+ *
+ * @param {Expression} expr
+ * @api public
+ */
+
+(exports.p = function(expr){
+ expr = utils.unwrap(expr);
+ console.log('\033[90minspect:\033[0m %s'
+ , expr.toString().replace(/^\(|\)$/g, ''));
+ return nodes.null;
+}).raw = true;
+
+/**
+ * Throw an error with the given `msg`.
+ *
+ * @param {String} msg
+ * @api public
+ */
+
+exports.error = function(msg){
+ utils.assertType(msg, nodes.String, 'msg');
+ throw new Error(msg.val);
+};
+
+/**
+ * Warn with the given `msg` prefixed by "Warning: ".
+ *
+ * @param {String} msg
+ * @api public
+ */
+
+exports.warn = function(msg){
+ utils.assertType(msg, nodes.String, 'msg');
+ console.warn('Warning: %s', msg.val);
+ return nodes.null;
+};
+
+/**
+ * Output stack trace.
+ *
+ * @api public
+ */
+
+exports.trace = function(){
+ console.log(this.stack);
+ return nodes.null;
+};
+
+/**
+ * Return the opposites of the given `positions`.
+ *
+ * Examples:
+ *
+ * opposite-position(top left)
+ * // => bottom right
+ *
+ * @param {Expression} positions
+ * @return {Expression}
+ * @api public
+ */
+
+(exports['opposite-position'] = function(positions){
+ var expr = new nodes.Expression;
+ utils.unwrap(positions).nodes.forEach(function(pos, i){
+ utils.assertString(pos, 'position ' + i);
+ pos = (function(){ switch (pos.string) {
+ case 'top': return 'bottom';
+ case 'bottom': return 'top';
+ case 'left': return 'right';
+ case 'right': return 'left';
+ default: throw new Error('invalid position ' + pos);
+ }})();
+ expr.push(new nodes.Literal(pos));
+ });
+ return expr;
+}).raw = true;
+
+/**
+ * Return the width and height of the given `img` path.
+ *
+ * Examples:
+ *
+ * image-size('foo.png')
+ * // => 200px 100px
+ *
+ * image-size('foo.png')[0]
+ * // => 200px
+ *
+ * image-size('foo.png')[1]
+ * // => 100px
+ *
+ * @param {String} img
+ * @return {Expression}
+ * @api public
+ */
+
+exports['image-size'] = function(img) {
+ utils.assertType(img, nodes.String, 'img');
+ var img = new Image(this, img.string);
+
+ // Read size
+ img.open();
+ var size = img.size();
+ img.close();
+
+ // Return (w h)
+ var expr = new nodes.Expression;
+ expr.push(new nodes.Unit(size[0], 'px'));
+ expr.push(new nodes.Unit(size[1], 'px'));
+
+ return expr;
+};
+
+/**
+ * Apply Math `fn` to `n`
+ *
+ * @param {Unit} n
+ * @param {String} fn
+ * @return {Unit}
+ * @api private
+ */
+
+exports['-math'] = function(n, fn){
+ return new nodes.Unit(Math[fn.string](n.val), n.type);
+};
+
+/**
+ * Adjust HSL `color` `prop` by `amount`.
+ *
+ * @param {RGBA|HSLA} color
+ * @param {String} prop
+ * @param {Unit} amount
+ * @return {HSLA}
+ * @api private
+ */
+
+exports['-adjust'] = function(color, prop, amount){
+ var hsl = color.hsla;
+ prop = { hue: 'h', saturation: 's', lightness: 'l' }[prop.string];
+ if (!prop) throw new Error('invalid adjustment property');
+ hsl[prop] = hsl[prop] + amount.val;
+ return hsl.clone();
+};
\ No newline at end of file
--- /dev/null
+
+// stringify the given arg
+
+-string(arg)
+ type(arg) + ' ' + arg
+
+// require a color
+
+require-color(color)
+ unless color is a 'color'
+ error('RGB or HSL value expected, got a ' + -string(color))
+
+// require a unit
+
+require-unit(n)
+ unless n is a 'unit'
+ error('unit expected, got a ' + -string(n))
+
+// require a string
+
+require-string(str)
+ unless str is a 'string' or str is a 'ident'
+ error('string expected, got a ' + -string(str))
+
+// apply js Math function
+
+math(n, fn)
+ require-unit(n)
+ require-string(fn)
+ -math(n, fn)
+
+// adjust the given color's property by amount
+
+adjust(color, prop, amount)
+ require-color(color)
+ require-string(prop)
+ require-unit(amount)
+ -adjust(color, prop, amount)
+
+// Math functions
+
+abs(n) { math(n, 'abs') }
+ceil(n) { math(n, 'ceil') }
+floor(n) { math(n, 'floor') }
+round(n) { math(n, 'round') }
+min(a, b) { a < b ? a : b }
+max(a, b) { a > b ? a : b }
+
+// return the sum of the given numbers
+
+sum(nums)
+ sum = 0
+ sum += n for n in nums
+
+// return the average of the given numbers
+
+avg(nums)
+ sum(nums) / length(nums)
+
+// color components
+
+alpha(color) { component(hsl(color), 'alpha') }
+hue(color) { component(hsl(color), 'hue') }
+saturation(color) { component(hsl(color), 'saturation') }
+lightness(color) { component(hsl(color), 'lightness') }
+
+// check if n is an odd number
+
+odd(n)
+ 1 == n % 2
+
+// check if n is an even number
+
+even(n)
+ 0 == n % 2
+
+// check if color is light
+
+light(color)
+ lightness(color) >= 50%
+
+// check if color is dark
+
+dark(color)
+ lightness(color) < 50%
+
+// desaturate color by amount
+
+desaturate(color, amount)
+ adjust(color, 'saturation', - amount)
+
+// saturate color by amount
+
+saturate(color, amount)
+ adjust(color, 'saturation', amount)
+
+// darken by the given amount
+
+darken(color, amount)
+ adjust(color, 'lightness', - amount)
+
+// lighten by the given amount
+
+lighten(color, amount)
+ adjust(color, 'lightness', amount)
+
+// increase the current lightness value by the given amount
+
+lighten-by(color, amount)
+ l = lightness(color)
+ l = 100 if 0 == l
+ adjust(color, 'lightness', l * amount / 100)
+
+// decrease the current lightness value by the given amount
+
+darken-by(color, amount)
+ l = lightness(color)
+ adjust(color, 'lightness', - (l * amount / 100))
+
+// return the last value in the given expr
+
+last(expr)
+ expr[length(expr) - 1]
+
+// join values with the given delimiter
+
+join(delim, vals...)
+ buf = ''
+ vals = vals[0] if length(vals) == 1
+ for val, i in vals
+ buf += i ? delim + val : val
--- /dev/null
+
+/*!
+ * Stylus - plugin - url
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Compiler = require('../visitor/compiler')
+ , nodes = require('../nodes')
+ , parse = require('url').parse
+ , extname = require('path').extname
+ , utils = require('../utils')
+ , fs = require('fs');
+
+/**
+ * Mime table.
+ */
+
+var mimes = {
+ '.gif': 'image/gif'
+ , '.png': 'image/png'
+ , '.jpg': 'image/jpeg'
+ , '.jpeg': 'image/jpeg'
+};
+
+/**
+ * Return a url() function with the given `options`.
+ *
+ * Options:
+ *
+ * - `limit` bytesize limit defaulting to 30Kb
+ * - `paths` image resolution path(s), merged with general lookup paths
+ *
+ * Examples:
+ *
+ * stylus(str)
+ * .set('filename', __dirname + '/css/test.styl')
+ * .define('url', stylus.url({ paths: [__dirname + '/public'] }))
+ * .render(function(err, css){ ... })
+ *
+ * @param {Object} options
+ * @return {Function}
+ * @api public
+ */
+
+module.exports = function(options) {
+ options = options || {};
+
+ var sizeLimit = options.limit || 30000
+ , _paths = options.paths || [];
+
+ function url(url){
+ // Compile the url
+ var compiler = new Compiler(url);
+ compiler.isURL = true;
+ var url = url.nodes.map(function(node){
+ return compiler.visit(node);
+ }).join('');
+
+ // Parse literal
+ var url = parse(url)
+ , ext = extname(url.pathname)
+ , mime = mimes[ext]
+ , literal = new nodes.Literal('url("' + url.href + '")')
+ , paths = _paths.concat(this.paths)
+ , founds
+ , buf;
+
+ // Not supported
+ if (!mime) return literal;
+
+ // Absolute
+ if (url.protocol) return literal;
+
+ // Lookup
+ found = utils.lookup(url.pathname, paths);
+
+ // Failed to lookup
+ if (!found) return literal;
+
+ // Read data
+ buf = fs.readFileSync(found);
+
+ // To large
+ if (buf.length > sizeLimit) return literal;
+
+ // Encode
+ return new nodes.Literal('url("data:' + mime + ';base64,' + buf.toString('base64') + '")');
+ };
+
+ url.raw = true;
+ return url;
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Lexer
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Token = require('./token')
+ , nodes = require('./nodes');
+
+/**
+ * Operator aliases.
+ */
+
+var alias = {
+ 'and': '&&'
+ , 'or': '||'
+ , 'is': '=='
+ , 'isnt': '!='
+ , 'is not': '!='
+};
+
+/**
+ * Units.
+ */
+
+var units = [
+ 'em'
+ , 'ex'
+ , 'px'
+ , 'mm'
+ , 'cm'
+ , 'in'
+ , 'pt'
+ , 'pc'
+ , 'deg'
+ , 'rad'
+ , 'grad'
+ , 'ms'
+ , 's'
+ , 'Hz'
+ , 'kHz'
+ , '%'].join('|');
+
+/**
+ * Unit RegExp.
+ */
+
+var unit = new RegExp('^(-)?(\\d+\\.\\d+|\\d+|\\.\\d+)(' + units + ')? *');
+
+/**
+ * Initialize a new `Lexer` with the given `str` and `options`.
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @api private
+ */
+
+var Lexer = module.exports = function Lexer(str, options) {
+ options = options || {};
+ this.str = str.replace(/\r\n?/g, '\n');
+ this.stash = [];
+ this.indentStack = [];
+ this.indentRe = null;
+ this.lineno = 0;
+};
+
+/**
+ * Lexer prototype.
+ */
+
+Lexer.prototype = {
+
+ /**
+ * Custom inspect.
+ */
+
+ inspect: function(){
+ var tok
+ , tmp = this.str
+ , buf = [];
+ while ('eos' != (tok = this.next()).type) {
+ buf.push(tok.inspect());
+ }
+ this.str = tmp;
+ this.prevIndents = 0;
+ return buf.concat(tok.inspect()).join('\n');
+ },
+
+ /**
+ * Lookahead `n` tokens.
+ *
+ * @param {Number} n
+ * @return {Object}
+ * @api private
+ */
+
+ lookahead: function(n){
+ var fetch = n - this.stash.length;
+ while (fetch-- > 0) this.stash.push(this.advance());
+ return this.stash[--n];
+ },
+
+ /**
+ * Consume the given `len`.
+ *
+ * @param {Number|Array} len
+ * @api private
+ */
+
+ skip: function(len){
+ this.str = this.str.substr(Array.isArray(len)
+ ? len[0].length
+ : len);
+ },
+
+ /**
+ * Fetch next token including those stashed by peek.
+ *
+ * @return {Token}
+ * @api private
+ */
+
+ next: function() {
+ var tok = this.stashed() || this.advance();
+ switch (tok.type) {
+ case 'newline':
+ case 'selector':
+ case 'indent':
+ ++this.lineno;
+ }
+ tok.lineno = this.lineno;
+ return tok;
+ },
+
+ /**
+ * Fetch next token.
+ *
+ * @return {Token}
+ * @api private
+ */
+
+ advance: function() {
+ return this.eos()
+ || this.null()
+ || this.sep()
+ || this.keyword()
+ || this.urlchars()
+ || this.atrule()
+ || this.media()
+ || this.comment()
+ || this.newline()
+ || this.escaped()
+ || this.important()
+ || this.literal()
+ || this.function()
+ || this.brace()
+ || this.paren()
+ || this.color()
+ || this.string()
+ || this.unit()
+ || this.namedop()
+ || this.boolean()
+ || this.ident()
+ || this.op()
+ || this.space()
+ || this.selector();
+ },
+
+ /**
+ * Lookahead a single token.
+ *
+ * @return {Token}
+ * @api private
+ */
+
+ peek: function() {
+ return this.lookahead(1);
+ },
+
+ /**
+ * Return the next possibly stashed token.
+ *
+ * @return {Token}
+ * @api private
+ */
+
+ stashed: function() {
+ return this.stash.shift();
+ },
+
+ /**
+ * EOS | trailing outdents.
+ */
+
+ eos: function() {
+ if (this.str.length) return;
+ if (this.indentStack.length) {
+ this.indentStack.shift();
+ return new Token('outdent');
+ } else {
+ return new Token('eos');
+ }
+ },
+
+ /**
+ * url char
+ */
+
+ urlchars: function() {
+ var captures;
+ if (!this.isURL) return;
+ if (captures = /^[\/:@.;?&=*!,<>#%0-9]+/.exec(this.str)) {
+ this.skip(captures);
+ return new Token('literal', new nodes.Literal(captures[0]));
+ }
+ },
+
+ /**
+ * ';' ' '*
+ */
+
+ sep: function() {
+ var captures;
+ if (captures = /^; */.exec(this.str)) {
+ this.skip(captures);
+ return new Token(';');
+ }
+ },
+
+ /**
+ * ' '+
+ */
+
+ space: function() {
+ var captures;
+ if (captures = /^( +)/.exec(this.str)) {
+ this.skip(captures);
+ return new Token('space');
+ }
+ },
+
+ /**
+ * '\\' . ' '*
+ */
+
+ escaped: function() {
+ var captures;
+ if (captures = /^\\(.) */.exec(this.str)) {
+ var c = captures[1];
+ this.skip(captures);
+ return new Token('ident', new nodes.Literal(c));
+ }
+ },
+
+ /**
+ * '@css' ' '* '{' .* '}' ' '*
+ */
+
+ literal: function() {
+ // HACK attack !!!
+ var captures;
+ if (captures = /^@css *\{/.exec(this.str)) {
+ this.skip(captures);
+ var c
+ , braces = 1
+ , css = '';
+ while (c = this.str[0]) {
+ this.str = this.str.substr(1);
+ switch (c) {
+ case '{': ++braces; break;
+ case '}': --braces; break;
+ }
+ css += c;
+ if (!braces) break;
+ }
+ css = css.replace(/\s*}$/, '');
+ return new Token('literal', new nodes.Literal(css));
+ }
+ },
+
+ /**
+ * '!important' ' '*
+ */
+
+ important: function() {
+ var captures;
+ if (captures = /^!important */.exec(this.str)) {
+ this.skip(captures);
+ return new Token('ident', new nodes.Literal('!important'));
+ }
+ },
+
+ /**
+ * '{' | '}'
+ */
+
+ brace: function() {
+ var captures;
+ if (captures = /^([{}])/.exec(this.str)) {
+ this.skip(1);
+ var brace = captures[1];
+ return new Token(brace, brace);
+ }
+ },
+
+ /**
+ * '(' | ')' ' '*
+ */
+
+ paren: function() {
+ var captures;
+ if (captures = /^([()]) */.exec(this.str)) {
+ var paren = captures[1];
+ this.skip(captures);
+ if (')' == paren) this.isURL = false;
+ return new Token(paren, paren);
+ }
+ },
+
+ /**
+ * 'null'
+ */
+
+ null: function() {
+ var captures;
+ if (captures = /^(null)\b */.exec(this.str)) {
+ this.skip(captures);
+ return new Token('null', nodes.null);
+ }
+ },
+
+ /**
+ * 'if'
+ * | 'else'
+ * | 'unless'
+ * | 'return'
+ * | 'for'
+ * | 'in'
+ */
+
+ keyword: function() {
+ var captures;
+ if (captures = /^(return|if|else|unless|for|in)\b */.exec(this.str)) {
+ var keyword = captures[1];
+ this.skip(captures);
+ return new Token(keyword, keyword);
+ }
+ },
+
+ /**
+ * 'not'
+ * | 'and'
+ * | 'or'
+ * | 'is'
+ * | 'is not'
+ * | 'isnt'
+ * | 'is a'
+ * | 'is defined'
+ */
+
+ namedop: function() {
+ var captures;
+ if (captures = /^(not|and|or|is a|is defined|isnt|is not|is)\b( *)/.exec(this.str)) {
+ var op = captures[1];
+ this.skip(captures);
+ op = alias[op] || op;
+ var tok = new Token(op, op);
+ tok.space = captures[2];
+ return tok;
+ }
+ },
+
+ /**
+ * ','
+ * | '+'
+ * | '+='
+ * | '-'
+ * | '-='
+ * | '*'
+ * | '*='
+ * | '/'
+ * | '/='
+ * | '%'
+ * | '%='
+ * | '**'
+ * | '!'
+ * | '&'
+ * | '&&'
+ * | '||'
+ * | '>'
+ * | '>='
+ * | '<'
+ * | '<='
+ * | '='
+ * | '=='
+ * | '!='
+ * | '!'
+ * | '~'
+ * | '?='
+ * | '?'
+ * | ':'
+ * | '['
+ * | ']'
+ * | '..'
+ * | '...'
+ */
+
+ op: function() {
+ var captures;
+ if (captures = /^([.]{2,3}|&&|\|\||[!<>=?]=|\*\*|[-+*\/%]=?|[,=?:!~<>&\[\]])( *)/.exec(this.str)) {
+ var op = captures[1];
+ this.skip(captures);
+ op = alias[op] || op;
+ var tok = new Token(op, op);
+ tok.space = captures[2];
+ return tok;
+ }
+ },
+
+ /**
+ * '@media' ([^{\n]+)
+ */
+
+ media: function() {
+ var captures;
+ if (captures = /^@media *([^{\n]+)/.exec(this.str)) {
+ this.skip(captures);
+ return new Token('media', captures[1].trim());
+ }
+ },
+
+ /**
+ * '@' ('import' | 'keyframes' | 'charset' | 'page')
+ */
+
+ atrule: function() {
+ var captures;
+ if (captures = /^@(import|keyframes|charset|page) */.exec(this.str)) {
+ this.skip(captures);
+ return new Token(captures[1]);
+ }
+ },
+
+ /**
+ * '//' *
+ */
+
+ comment: function() {
+ // Single line
+ if ('/' == this.str[0] && '/' == this.str[1]) {
+ var end = this.str.indexOf('\n');
+ if (-1 == end) end = this.str.length;
+ this.skip(end);
+ return this.advance();
+ }
+
+ // Multi-line
+ if ('/' == this.str[0] && '*' == this.str[1]) {
+ var end = this.str.indexOf('*/');
+ if (-1 == end) end = this.str.length;
+ var str = this.str.substr(0, end + 2)
+ , lines = str.split('\n').length - 1;
+ this.lineno += lines;
+ this.skip(end + 2);
+ return this.allowComments
+ ? new Token('comment', str)
+ : this.advance();
+ }
+ },
+
+ /**
+ * 'true' | 'false'
+ */
+
+ boolean: function() {
+ var captures;
+ if (captures = /^(true|false)\b( *)/.exec(this.str)) {
+ var val = 'true' == captures[1]
+ ? nodes.true
+ : nodes.false;
+ this.skip(captures);
+ var tok = new Token('boolean', val);
+ tok.space = captures[2];
+ return tok;
+ }
+ },
+
+ /**
+ * -?[a-zA-Z$] [-\w\d$]* '('
+ */
+
+ function: function() {
+ var captures;
+ if (captures = /^(-?[a-zA-Z$][-\w\d$]*)\(( *)/.exec(this.str)) {
+ var name = captures[1];
+ this.skip(captures);
+ this.isURL = 'url' == name;
+ var tok = new Token('function', new nodes.Ident(name));
+ tok.space = captures[2];
+ return tok;
+ }
+ },
+
+ /**
+ * -?[a-zA-Z$] [-\w\d$]*
+ */
+
+ ident: function() {
+ var captures;
+ if (captures = /^(-?[a-zA-Z$][-\w\d$]*)/.exec(this.str)) {
+ var name = captures[1];
+ this.skip(captures);
+ return new Token('ident', new nodes.Ident(name));
+ }
+ },
+
+ /**
+ * '\n' ' '+
+ */
+
+ newline: function() {
+ var captures, re;
+
+ // we have established the indentation regexp
+ if (this.indentRe){
+ captures = this.indentRe.exec(this.str);
+ // figure out if we are using tabs or spaces
+ } else {
+ // try tabs
+ re = /^\n([\t]*) */;
+ captures = re.exec(this.str);
+
+ // nope, try spaces
+ if (captures && !captures[1].length) {
+ re = /^\n( *)/;
+ captures = re.exec(this.str);
+ }
+
+ // established
+ if (captures && captures[1].length) this.indentRe = re;
+ }
+
+
+ if (captures) {
+ var tok
+ , indents = captures[1].length;
+
+ this.skip(captures);
+ if (this.str[0] === ' ' || this.str[0] === '\t') {
+ throw new Error('Invalid indentation, you can use tabs or spaces to indent but not both');
+ }
+
+ // Reset state
+ this.isVariable = false;
+
+ // Blank line
+ if ('\n' == this.str[0]) {
+ ++this.lineno;
+ return this.advance();
+ }
+
+ // Outdent
+ if (this.indentStack.length && indents < this.indentStack[0]) {
+ while (this.indentStack.length && this.indentStack[0] > indents) {
+ this.stash.push(new Token('outdent'));
+ this.indentStack.shift();
+ }
+ tok = this.stash.pop();
+ // Indent
+ } else if (indents && indents != this.indentStack[0]) {
+ this.indentStack.unshift(indents);
+ tok = new Token('indent');
+ // Newline
+ } else {
+ tok = new Token('newline');
+ }
+
+ return tok;
+ }
+ },
+
+ /**
+ * '-'? (digit+ | digit* '.' digit+) unit
+ */
+
+ unit: function() {
+ var captures;
+ if (captures = unit.exec(this.str)) {
+ this.skip(captures);
+ var n = parseFloat(captures[2]);
+ if ('-' == captures[1]) n = -n;
+ var node = new nodes.Unit(n, captures[3]);
+ return new Token('unit', node);
+ }
+ },
+
+ /**
+ * '"' [^"]+ '"' | "'"" [^']+ "'"
+ */
+
+ string: function() {
+ var captures;
+ if (captures = /^("[^"]*"|'[^']*') */.exec(this.str)) {
+ var str = captures[1];
+ this.skip(captures);
+ return new Token('string', new nodes.String(str.slice(1,-1)));
+ }
+ },
+
+ /**
+ * #nnnnnn | #nnn
+ */
+
+ color: function() {
+ return this.hex6()
+ || this.hex3();
+ },
+
+ /**
+ * #nnn
+ */
+
+ hex3: function() {
+ var captures;
+ if (captures = /^#([a-fA-F0-9]{3}) */.exec(this.str)) {
+ this.skip(captures);
+ var rgb = captures[1]
+ , r = parseInt(rgb[0] + rgb[0], 16)
+ , g = parseInt(rgb[1] + rgb[1], 16)
+ , b = parseInt(rgb[2] + rgb[2], 16)
+ , color = new nodes.RGBA(r, g, b, 1);
+ color.raw = captures[0];
+ return new Token('color', color);
+ }
+ },
+
+ /**
+ * #nnnnnn
+ */
+
+ hex6: function() {
+ var captures;
+ if (captures = /^#([a-fA-F0-9]{6}) */.exec(this.str)) {
+ this.skip(captures);
+ var rgb = captures[1]
+ , r = parseInt(rgb.substr(0, 2), 16)
+ , g = parseInt(rgb.substr(2, 2), 16)
+ , b = parseInt(rgb.substr(4, 2), 16)
+ , color = new nodes.RGBA(r, g, b, 1);
+ color.raw = captures[0];
+ return new Token('color', color);
+ }
+ },
+
+ /**
+ * [^\n,;]+
+ */
+
+ selector: function() {
+ var captures;
+ if (captures = /^[^{\n,]+/.exec(this.str)) {
+ var selector = captures[0];
+ this.skip(captures);
+ return new Token('selector', selector);
+ }
+ }
+};
--- /dev/null
+/*!
+ * Stylus - middleware
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var stylus = require('./stylus')
+ , fs = require('fs')
+ , url = require('url')
+ , basename = require('path').basename
+ , join = require('path').join
+ , ENOENT;
+
+// COMPAT:
+
+try {
+ ENOENT = require('constants').ENOENT;
+} catch (err) {
+ ENOENT = process.ENOENT;
+}
+
+/**
+ * Import map.
+ */
+
+var imports = {};
+
+/**
+ * Return Connect middleware with the given `options`.
+ *
+ * Options:
+ *
+ * `force` Always re-compile
+ * `src` Source directory used to find .styl files
+ * `dest` Destination directory used to output .css files
+ * when undefined defaults to `src`.
+ * `compile` Custom compile function, accepting the arguments
+ * `(str, path)`.
+ * `compress` Whether the output .css files should be compressed
+ *
+ * Examples:
+ *
+ * Here we set up the custom compile function so that we may
+ * set the `compress` option, or define additional functions.
+ *
+ * By default the compile function simply sets the `filename`
+ * and renders the CSS.
+ *
+ * function compile(str, path) {
+ * return stylus(str)
+ * .set('filename', path)
+ * .set('compress', true);
+ * }
+ *
+ * Pass the middleware to Connect, grabbing .styl files from this directory
+ * and saving .css files to _./public_. Also supplying our custom `compile` function.
+ *
+ * Following that we have a `staticProvider` layer setup to serve the .css
+ * files generated by Stylus.
+ *
+ * var server = connect.createServer(
+ * stylus.middleware({
+ * src: __dirname
+ * , dest: __dirname + '/public'
+ * , compile: compile
+ * })
+ * , connect.static(__dirname + '/public')
+ * );
+ *
+ * @param {Object} options
+ * @return {Function}
+ * @api public
+ */
+
+module.exports = function(options){
+ options = options || {};
+
+ // Accept src/dest dir
+ if ('string' == typeof options) {
+ options = { src: options };
+ }
+
+ // Force compilation
+ var force = options.force;
+
+ // Source dir required
+ var src = options.src;
+ if (!src) throw new Error('stylus.middleware() requires "src" directory');
+
+ // Default dest dir to source
+ var dest = options.dest
+ ? options.dest
+ : src;
+
+ // Default compile callback
+ options.compile = options.compile || function(str, path){
+ return stylus(str)
+ .set('filename', path)
+ .set('compress', options.compress);
+ };
+
+ // Middleware
+ return function(req, res, next){
+ if ('GET' != req.method && 'HEAD' != req.method) return next();
+ var path = url.parse(req.url).pathname;
+ if (/\.css$/.test(path)) {
+ var cssPath = join(dest, path)
+ , stylusPath = join(src, path.replace('.css', '.styl'));
+
+ // Ignore ENOENT to fall through as 404
+ function error(err) {
+ next(ENOENT == err.errno
+ ? null
+ : err);
+ }
+
+ // Force
+ if (force) return compile();
+
+ // Compile to cssPath
+ function compile() {
+ fs.readFile(stylusPath, 'utf8', function(err, str){
+ if (err) return error(err);
+ var style = options.compile(str, stylusPath);
+ var paths = style.options._imports = [];
+ style.render(function(err, css){
+ imports[stylusPath] = imports[stylusPath] || paths;
+ if (err) return next(err);
+ fs.writeFile(cssPath, css, 'utf8', function(err){
+ next(err);
+ });
+ });
+ });
+ }
+
+ // Compare mtimes
+ fs.stat(stylusPath, function(err, stylusStats){
+ if (err) return error(err);
+ fs.stat(cssPath, function(err, cssStats){
+ // CSS has not been compiled, compile it!
+ if (err) {
+ if (ENOENT == err.errno) {
+ compile();
+ } else {
+ next(err);
+ }
+ } else {
+ // Source has changed, compile it
+ if (stylusStats.mtime > cssStats.mtime) {
+ compile();
+ // Already compiled, check imports
+ } else {
+ checkImports(stylusPath, function(changed){
+ changed ? compile() : next();
+ });
+ }
+ }
+ });
+ });
+ } else {
+ next();
+ }
+ }
+};
+
+/**
+ * Check `path`'s imports to see if they have been altered.
+ *
+ * @param {String} path
+ * @param {Function} fn
+ * @api private
+ */
+
+function checkImports(path, fn) {
+ var nodes = imports[path];
+ if (!nodes) return fn();
+ if (!nodes.length) return fn();
+ var pending = nodes.length
+ , changed = false;
+ nodes.forEach(function(import){
+ fs.stat(import.path, function(err, stat){
+ if (err) {
+ --pending || fn(changed);
+ } else if (import.mtime) {
+ changed = changed || stat.mtime > import.mtime;
+ import.mtime = stat.mtime;
+ --pending || fn(changed);
+ } else {
+ import.mtime = stat.mtime;
+ --pending || fn(changed = true);
+ }
+ });
+ });
+}
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - BinOp
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `BinOp` with `op`, `left` and `right`.
+ *
+ * @param {String} op
+ * @param {Node} left
+ * @param {Node} right
+ * @api public
+ */
+
+var BinOp = module.exports = function BinOp(op, left, right){
+ Node.call(this);
+ this.op = op;
+ this.left = left;
+ this.right = right;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+BinOp.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+BinOp.prototype.clone = function(){
+ var clone = new BinOp(
+ this.op
+ , this.left.clone()
+ , this.right ?
+ this.right.clone()
+ : null);
+ clone.lineno = this.lineno;
+ return clone;
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Block
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Block` node with `parent` Block.
+ *
+ * @param {Block} parent
+ * @api public
+ */
+
+var Block = module.exports = function Block(parent, node){
+ Node.call(this);
+ this.nodes = [];
+ this.parent = parent;
+ this.node = node;
+ this.scope = true;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Block.prototype.__proto__ = Node.prototype;
+
+/**
+ * Check if this block has properties..
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Block.prototype.__defineGetter__('hasProperties', function(){
+ for (var i = 0, len = this.nodes.length; i < len; ++i) {
+ if ('property' == this.nodes[i].nodeName) {
+ return true;
+ }
+ }
+});
+
+/**
+ * Check if this block is empty.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Block.prototype.__defineGetter__('isEmpty', function(){
+ return !this.nodes.length;
+});
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Block.prototype.clone = function(){
+ var clone = new Block(this.parent, this.node);
+ clone.lineno = this.lineno;
+ clone.scope = this.scope;
+ this.nodes.forEach(function(node){
+ node = node.clone();
+ switch (node.nodeName) {
+ case 'each':
+ case 'group':
+ node.block.parent = clone;
+ break;
+ case 'ident':
+ if ('function' == node.val.nodeName) {
+ node.val.block.parent = clone;
+ }
+ }
+ clone.push(node);
+ });
+ return clone;
+};
+
+/**
+ * Push a `node` to this block.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+Block.prototype.push = function(node){
+ this.nodes.push(node);
+};
--- /dev/null
+
+/*!
+ * Stylus - Boolean
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Boolean` node with the given `val`.
+ *
+ * @param {Boolean} val
+ * @api public
+ */
+
+var Boolean = module.exports = function Boolean(val){
+ Node.call(this);
+ if (this instanceof Boolean) {
+ this.val = !!val;
+ } else {
+ return val ? nodes.true : nodes.false;
+ }
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Boolean.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return `this` node.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Boolean.prototype.toBoolean = function(){
+ return this;
+};
+
+/**
+ * Negate the value.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Boolean.prototype.negate = function(){
+ return this.val
+ ? nodes.false
+ : nodes.true;
+};
+
+/**
+ * Return 'Boolean'.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Boolean.prototype.inspect = function(){
+ return '[Boolean ' + this.val + ']';
+};
+
+/**
+ * Return 'true' or 'false'.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Boolean.prototype.toString = function(){
+ return this.val
+ ? 'true'
+ : 'false';
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Call
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Call` with `name` and `args`.
+ *
+ * @param {String} name
+ * @param {Expression} args
+ * @api public
+ */
+
+var Call = module.exports = function Call(name, args){
+ Node.call(this);
+ this.name = name;
+ this.args = args;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Call.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Call.prototype.clone = function(){
+ var clone = new Call(this.name, this.args.clone());
+ clone.lineno = this.lineno;
+ return clone;
+};
+
+/**
+ * Return <name>().
+ *
+ * @return {String}
+ * @api public
+ */
+
+Call.prototype.toString = function(){
+ return this.name + '()';
+};
--- /dev/null
+
+/*!
+ * Stylus - Charset
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Charset` with the given `val`
+ *
+ * @param {String} val
+ * @api public
+ */
+
+var Charset = module.exports = function Charset(val){
+ Node.call(this);
+ this.val = val;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Charset.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return @charset "val".
+ *
+ * @return {String}
+ * @api public
+ */
+
+Charset.prototype.toString = function(){
+ return '@charset ' + this.val;
+};
--- /dev/null
+
+/*!
+ * Stylus - Each
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Each` node with the given `val` name,
+ * `key` name, `expr`, and `block`.
+ *
+ * @param {String} val
+ * @param {String} key
+ * @param {Expression} expr
+ * @param {Block} block
+ * @api public
+ */
+
+var Each = module.exports = function Each(val, key, expr, block){
+ Node.call(this);
+ this.val = val;
+ this.key = key;
+ this.expr = expr;
+ this.block = block;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Each.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Each.prototype.clone = function(){
+ var clone = new Each(
+ this.val
+ , this.key
+ , this.expr.clone()
+ , this.block.clone());
+ clone.lineno = this.lineno;
+ return clone;
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Expression
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('../nodes')
+ , utils = require('../utils');
+
+/**
+ * Initialize a new `Expression`.
+ *
+ * @param {Boolean} isList
+ * @api public
+ */
+
+var Expression = module.exports = function Expression(isList){
+ Node.call(this);
+ this.nodes = [];
+ this.isList = isList;
+};
+
+/**
+ * Check if the variable has a value.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Expression.prototype.__defineGetter__('isEmpty', function(){
+ return !this.nodes.length;
+});
+
+/**
+ * Return the first node in this expression.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Expression.prototype.__defineGetter__('first', function(){
+ return this.nodes[0]
+ ? this.nodes[0].first
+ : nodes.null;
+});
+
+/**
+ * Hash all the nodes in order.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Expression.prototype.__defineGetter__('hash', function(){
+ return this.nodes.map(function(node){
+ return node.hash;
+ }).join('::');
+});
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Expression.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Expression.prototype.clone = function(){
+ var clone = new Expression(this.isList);
+ clone.preserve = this.preserve;
+ clone.lineno = this.lineno;
+ for (var i = 0; i < this.nodes.length; ++i) {
+ clone.push(this.nodes[i].clone());
+ }
+ return clone;
+};
+
+/**
+ * Push the given `node`.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+Expression.prototype.push = function(node){
+ this.nodes.push(node);
+};
+
+/**
+ * Operate on `right` with the given `op`.
+ *
+ * @param {String} op
+ * @param {Node} right
+ * @return {Node}
+ * @api public
+ */
+
+Expression.prototype.operate = function(op, right){
+ switch (op) {
+ case '[]':
+ var expr = new nodes.Expression
+ , vals = utils.unwrap(this).nodes
+ , range = utils.unwrap(right).nodes;
+ range.forEach(function(unit){
+ if ('unit' == unit.nodeName) {
+ var node = vals[unit.val];
+ if (node) expr.push(node);
+ }
+ });
+ return expr.isEmpty
+ ? nodes.null
+ : expr;
+ default:
+ return Node.prototype.operate.call(this, op, right);
+ }
+};
+
+/**
+ * Return "<a> <b> <c>" or "<a>, <b>, <c>" if
+ * the expression represents a list.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Expression.prototype.toString = function(){
+ return '(' + this.nodes.map(function(node){
+ return node.toString();
+ }).join(this.isList ? ', ' : ' ') + ')';
+};
+
+
--- /dev/null
+
+/*!
+ * Stylus - Function
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Function` with `name`, `params`, and `body`.
+ *
+ * @param {String} name
+ * @param {Params|Function} params
+ * @param {Block} body
+ * @api public
+ */
+
+var Function = module.exports = function Function(name, params, body){
+ Node.call(this);
+ this.name = name;
+ this.params = params;
+ this.block = body;
+ if ('function' == typeof params) this.fn = params;
+};
+
+/**
+ * Check function arity.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Function.prototype.__defineGetter__('arity', function(){
+ return this.params.length;
+});
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Function.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Function.prototype.clone = function(){
+ if (this.fn) {
+ var clone = new Function(
+ this.name
+ , this.fn);
+ } else {
+ var clone = new Function(
+ this.name
+ , this.params.clone()
+ , this.block.clone());
+ }
+ clone.lineno = this.lineno;
+ return clone;
+};
+
+/**
+ * Return <name>(param1, param2, ...).
+ *
+ * @return {String}
+ * @api public
+ */
+
+Function.prototype.toString = function(){
+ if (this.fn) {
+ return this.name
+ + '('
+ + this.fn.toString()
+ .match(/^function *\((.*?)\)/)
+ .slice(1)
+ .join(', ')
+ + ')';
+ } else {
+ return this.name
+ + '('
+ + this.params.nodes.join(', ')
+ + ')';
+ }
+};
--- /dev/null
+
+/*!
+ * Stylus - Group
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Group`.
+ *
+ * @api public
+ */
+
+var Group = module.exports = function Group(){
+ Node.call(this);
+ this.nodes = [];
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Group.prototype.__proto__ = Node.prototype;
+
+/**
+ * Push the given `selector` node.
+ *
+ * @param {Selector} selector
+ * @api public
+ */
+
+Group.prototype.push = function(selector){
+ this.nodes.push(selector);
+};
+
+/**
+ * Return this set's `Block`.
+ */
+
+Group.prototype.__defineGetter__('block', function(){
+ return this.nodes[0].block;
+});
+
+/**
+ * Assign `block` to each selector in this set.
+ *
+ * @param {Block} block
+ * @api public
+ */
+
+Group.prototype.__defineSetter__('block', function(block){
+ for (var i = 0, len = this.nodes.length; i < len; ++i) {
+ this.nodes[i].block = block;
+ }
+});
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Group.prototype.clone = function(){
+ var clone = new Group;
+ clone.lineno = this.lineno;
+ this.nodes.forEach(function(node){
+ clone.push(node.clone());
+ });
+ clone.block = this.block.clone();
+ return clone;
+};
--- /dev/null
+
+/*!
+ * Stylus - HSLA
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `HSLA` with the given h,s,l,a component values.
+ *
+ * @param {Number} h
+ * @param {Number} s
+ * @param {Number} l
+ * @param {Number} a
+ * @api public
+ */
+
+var HSLA = exports = module.exports = function HSLA(h,s,l,a){
+ Node.call(this);
+ this.h = clampDegrees(h);
+ this.s = clampPercentage(s);
+ this.l = clampPercentage(l);
+ this.a = clampAlpha(a);
+ this.hsla = this;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+HSLA.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return hsla(n,n,n,n).
+ *
+ * @return {String}
+ * @api public
+ */
+
+HSLA.prototype.toString = function(){
+ return 'hsla('
+ + this.h + ','
+ + this.s + ','
+ + this.l + ','
+ + this.a + ')';
+};
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+HSLA.prototype.clone = function(){
+ var clone = new HSLA(
+ this.h
+ , this.s
+ , this.l
+ , this.a);
+ clone.lineno = this.lineno;
+ return clone;
+};
+
+/**
+ * Return rgba `RGBA` representation.
+ *
+ * @return {RGBA}
+ * @api public
+ */
+
+HSLA.prototype.__defineGetter__('rgba', function(){
+ return nodes.RGBA.fromHSLA(this);
+});
+
+/**
+ * Return hash.
+ *
+ * @return {String}
+ * @api public
+ */
+
+HSLA.prototype.__defineGetter__('hash', function(){
+ return this.rgba.toString();
+});
+
+/**
+ * Coerce RGBA to HSLA.
+ *
+ * @param {Node} other
+ * @return {Node}
+ * @api public
+ */
+
+HSLA.prototype.coerce = function(other){
+ if (other instanceof nodes.RGBA) {
+ return other.hsla;
+ } else {
+ return Node.prototype.coerce.call(this, other);
+ }
+};
+
+/**
+ * Operate on `right` with the given `op`.
+ *
+ * @param {String} op
+ * @param {Node} right
+ * @return {Node}
+ * @api public
+ */
+
+HSLA.prototype.operate = function(op, right){
+ switch (op) {
+ case '+':
+ return new HSLA(
+ this.h + right.h
+ , this.s + right.s
+ , this.l + right.l
+ , 1 == right.a ? this.a : (this.a + right.a)
+ );
+ case '-':
+ return new HSLA(
+ this.h - right.h
+ , this.s - right.s
+ , this.l - right.l
+ , 1 == right.a ? this.a : (this.a - right.a)
+ );
+ case '*':
+ return new HSLA(
+ this.h * right.h
+ , this.s * right.s
+ , this.l * right.l
+ , this.a * right.a
+ );
+ case '/':
+ return new HSLA(
+ this.h / right.h
+ , this.s / right.s
+ , this.l / right.l
+ , this.a / right.a
+ );
+ default:
+ return Node.prototype.operate.call(this, op, right);
+ }
+};
+
+/**
+ * Return `HSLA` representation of the given `color`.
+ *
+ * @param {RGBA} color
+ * @return {HSLA}
+ * @api public
+ */
+
+exports.fromRGBA = function(rgba){
+ var r = rgba.r / 255
+ , g = rgba.g / 255
+ , b = rgba.b / 255
+ , a = rgba.a;
+
+ var min = Math.min(r,g,b)
+ , max = Math.max(r,g,b)
+ , l = (max + min) / 2
+ , d = max - min
+ , h, s;
+
+ switch (max) {
+ case min: h = 0; break;
+ case r: h = 60 * (g-b) / d; break;
+ case g: h = 60 * (b-r) / d + 120; break;
+ case b: h = 60 * (r-g) / d + 240; break;
+ }
+
+ if (max == min) {
+ s = 0;
+ } else if (l < .5) {
+ s = d / (2 * l);
+ } else {
+ s = d / (2 - 2 * l);
+ }
+
+ h %= 360;
+ s *= 100;
+ l *= 100;
+
+ return new HSLA(h,s,l,a);
+};
+
+/**
+ * Clamp degree `n` >= 0 and <= 360.
+ *
+ * @param {Number} n
+ * @return {Number}
+ * @api private
+ */
+
+function clampDegrees(n) {
+ return Math.max(0, Math.min(n, 360));
+}
+
+/**
+ * Clamp percentage `n` >= 0 and <= 100.
+ *
+ * @param {Number} n
+ * @return {Number}
+ * @api private
+ */
+
+function clampPercentage(n) {
+ return Math.max(0, Math.min(n, 100));
+}
+
+/**
+ * Clamp alpha `n` >= 0 and <= 1.
+ *
+ * @param {Number} n
+ * @return {Number}
+ * @api private
+ */
+
+function clampAlpha(n) {
+ return Math.max(0, Math.min(n, 1));
+}
--- /dev/null
+
+/*!
+ * Stylus - Ident
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Ident` by `name` with the given `val` node.
+ *
+ * @param {String} name
+ * @param {Node} val
+ * @api public
+ */
+
+var Ident = module.exports = function Ident(name, val){
+ Node.call(this);
+ this.name = name;
+ this.string = name;
+ this.val = val || nodes.null;
+};
+
+/**
+ * Check if the variable has a value.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Ident.prototype.__defineGetter__('isEmpty', function(){
+ return undefined == this.val;
+});
+
+/**
+ * Return hash.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Ident.prototype.__defineGetter__('hash', function(){
+ return this.name;
+});
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Ident.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Ident.prototype.clone = function(){
+ var clone = new Ident(this.name, this.val.clone());
+ clone.lineno = this.lineno;
+ return clone;
+};
+
+/**
+ * Return <name>.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Ident.prototype.toString = function(){
+ return this.name;
+};
+
+/**
+ * Coerce `other` to an ident.
+ *
+ * @param {Node} other
+ * @return {String}
+ * @api public
+ */
+
+Ident.prototype.coerce = function(other){
+ if (other instanceof nodes.Literal ||
+ other instanceof Ident) {
+ return other;
+ } else {
+ return Node.prototype.coerce.call(this, other);
+ }
+};
--- /dev/null
+
+/*!
+ * Stylus - If
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `If` with the given `cond`.
+ *
+ * @param {Expression} cond
+ * @param {Boolean|Block} negate, block
+ * @api public
+ */
+
+var If = module.exports = function If(cond, negate){
+ Node.call(this);
+ this.cond = cond;
+ this.elses = [];
+ if (negate instanceof Node) {
+ this.block = negate;
+ } else {
+ this.negate = negate;
+ }
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+If.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+If.prototype.clone = function(){
+ var cond = this.cond.clone()
+ , block = this.block.clone();
+ var clone = new If(cond, block);
+ clone.elses = this.elses.map(function(node){ return node.clone(); });
+ clone.negate = this.negate;
+ clone.lineno = this.lineno;
+ return clone;
+};
--- /dev/null
+
+/*!
+ * Stylus - Import
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Import` with the given `expr`.
+ *
+ * @param {Expression} expr
+ * @api public
+ */
+
+var Import = module.exports = function Import(expr){
+ Node.call(this);
+ this.path = expr;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Import.prototype.__proto__ = Node.prototype;
--- /dev/null
+
+/*!
+ * Stylus - nodes
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Constructors
+ */
+
+exports.Node = require('./node');
+exports.Root = require('./root');
+exports.Null = require('./null');
+exports.Each = require('./each');
+exports.If = require('./if');
+exports.Call = require('./call');
+exports.Page = require('./page');
+exports.UnaryOp = require('./unaryop');
+exports.BinOp = require('./binop');
+exports.Ternary = require('./ternary');
+exports.Block = require('./block');
+exports.Unit = require('./unit');
+exports.String = require('./string');
+exports.HSLA = require('./hsla');
+exports.RGBA = require('./rgba');
+exports.Ident = require('./ident');
+exports.Group = require('./group');
+exports.Literal = require('./literal');
+exports.Boolean = require('./boolean');
+exports.Return = require('./return');
+exports.Media = require('./media');
+exports.Params = require('./params');
+exports.Keyframes = require('./keyframes');
+exports.Charset = require('./charset');
+exports.Import = require('./import');
+exports.Function = require('./function');
+exports.Property = require('./property');
+exports.Selector = require('./selector');
+exports.Expression = require('./expression');
+
+/**
+ * Singletons.
+ */
+
+exports.true = new exports.Boolean(true);
+exports.false = new exports.Boolean(false);
+exports.null = new exports.Null;
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Keyframes
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Keyframes` with the given `name`.
+ *
+ * @param {String} name
+ * @api public
+ */
+
+var Keyframes = module.exports = function Keyframes(name){
+ Node.call(this);
+ this.name = name;
+ this.frames = [];
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Keyframes.prototype.__proto__ = Node.prototype;
+
+/**
+ * Push the given `block` at `pos`.
+ *
+ * @param {Unit} pos
+ * @param {Block} block
+ * @api public
+ */
+
+Keyframes.prototype.push = function(pos, block){
+ this.frames.push({
+ pos: pos
+ , block: block
+ });
+};
+
+/**
+ * Return `@keyframes name`.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Keyframes.prototype.toString = function(){
+ return '@keyframes ' + this.name;
+};
--- /dev/null
+
+/*!
+ * Stylus - Literal
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Literal` with the given `str`.
+ *
+ * @param {String} str
+ * @api public
+ */
+
+var Literal = module.exports = function Literal(str){
+ Node.call(this);
+ this.val = str;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Literal.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return hash.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Literal.prototype.__defineGetter__('hash', function(){
+ return this.val;
+});
+
+/**
+ * Return literal value.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Literal.prototype.toString = function(){
+ return this.val;
+};
+
+/**
+ * Coerce `other` to a literal.
+ *
+ * @param {Node} other
+ * @return {String}
+ * @api public
+ */
+
+Literal.prototype.coerce = function(other){
+ if (other instanceof Literal ||
+ other instanceof nodes.Ident) {
+ return other;
+ } else {
+ return Node.prototype.coerce.call(this, other);
+ }
+};
--- /dev/null
+
+/*!
+ * Stylus - Media
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Media` with the given `val`
+ *
+ * @param {String} val
+ * @api public
+ */
+
+var Media = module.exports = function Media(val){
+ Node.call(this);
+ this.val = val;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Media.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return @media "val".
+ *
+ * @return {String}
+ * @api public
+ */
+
+Media.prototype.toString = function(){
+ return '@media ' + this.val;
+};
--- /dev/null
+
+/*!
+ * Stylus - Node
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Evaluator = require('../visitor/evaluator')
+ , utils = require('../utils')
+ , nodes = require('./');
+
+/**
+ * Node constructor.
+ *
+ * @api public
+ */
+
+var Node = module.exports = function Node(){
+ this.lineno = nodes.lineno;
+ Object.defineProperty(this, 'filename', { value: nodes.filename });
+ Object.defineProperty(this, 'source', { value: nodes.source });
+};
+
+/**
+ * Return this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Node.prototype.__defineGetter__('first', function(){
+ return this;
+});
+
+/**
+ * Return hash.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Node.prototype.__defineGetter__('hash', function(){
+ return this.val;
+});
+
+/**
+ * Return node name.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Node.prototype.__defineGetter__('nodeName', function(){
+ return this.constructor.name.toLowerCase();
+});
+
+/**
+ * Return this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Node.prototype.clone = function(){
+ return this;
+};
+
+/**
+ * Nodes by default evaluate to themselves.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Node.prototype.eval = function(){
+ return new Evaluator(this).evaluate();
+};
+
+/**
+ * Return true.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Node.prototype.toBoolean = function(){
+ return nodes.true;
+};
+
+/**
+ * Operate on `right` with the given `op`.
+ *
+ * @param {String} op
+ * @param {Node} right
+ * @return {Node}
+ * @api public
+ */
+
+Node.prototype.operate = function(op, right){
+ switch (op) {
+ case 'is a':
+ if ('string' == right.nodeName) {
+ if ('color' == right.string) {
+ return nodes.Boolean('rgba' == this.nodeName || 'hsla' == this.nodeName);
+ } else {
+ return nodes.Boolean(this.nodeName == right.val);
+ }
+ } else {
+ throw new Error('"is a" expects a string, got ' + right.nodeName);
+ }
+ case '==':
+ return nodes.Boolean(this.hash == right.hash);
+ case '!=':
+ return nodes.Boolean(this.hash != right.hash);
+ case '>=':
+ return nodes.Boolean(this.hash >= right.hash);
+ case '<=':
+ return nodes.Boolean(this.hash <= right.hash);
+ case '>':
+ return nodes.Boolean(this.hash > right.hash);
+ case '<':
+ return nodes.Boolean(this.hash < right.hash);
+ case '||':
+ return nodes.true == this.toBoolean()
+ ? this
+ : right;
+ case 'in':
+ var vals = utils.unwrap(right).nodes
+ , hash = this.hash;
+ if (!vals) throw new Error('"in" given invalid right-hand operand, expecting an expression');
+ for (var i = 0, len = vals.length; i < len; ++i) {
+ if (hash == vals[i].hash) {
+ return nodes.true;
+ }
+ }
+ return nodes.false;
+ case '&&':
+ var a = this.toBoolean()
+ , b = right.toBoolean();
+ return nodes.true == a && nodes.true == b
+ ? right
+ : nodes.false == a
+ ? this
+ : right;
+ default:
+ if ('[]' == op) {
+ var msg = 'cannot perform '
+ + this
+ + '[' + right + ']';
+ } else {
+ var msg = 'cannot perform'
+ + ' ' + this
+ + ' ' + op
+ + ' ' + right;
+ }
+ throw new Error(msg);
+ }
+};
+
+/**
+ * Default coercion throws.
+ *
+ * @param {Node} other
+ * @return {Node}
+ * @api public
+ */
+
+Node.prototype.coerce = function(other){
+ if (other.nodeName == this.nodeName) return other;
+ throw new Error('cannot coerce ' + other + ' to ' + this.nodeName);
+};
--- /dev/null
+
+/*!
+ * Stylus - Null
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Null` node.
+ *
+ * @api public
+ */
+
+var Null = module.exports = function Null(){};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Null.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return 'Null'.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Null.prototype.inspect =
+Null.prototype.toString = function(){
+ return '[Null]';
+};
+
+/**
+ * Return false.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Null.prototype.toBoolean = function(){
+ return nodes.false;
+};
+
+/**
+ * Return hash.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Null.prototype.__defineGetter__('hash', function(){
+ return null;
+});
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Page
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Page` with the given `selector` and `block`.
+ *
+ * @param {Selector} selector
+ * @param {Block} block
+ * @api public
+ */
+
+var Page = module.exports = function Page(selector, block){
+ Node.call(this);
+ this.selector = selector;
+ this.block = block;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Page.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return `@oage name`.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Page.prototype.toString = function(){
+ return '@page ' + this.selector;
+};
--- /dev/null
+
+/*!
+ * Stylus - Params
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Params` with `name`, `params`, and `body`.
+ *
+ * @param {String} name
+ * @param {Params} params
+ * @param {Expression} body
+ * @api public
+ */
+
+var Params = module.exports = function Params(){
+ Node.call(this);
+ this.nodes = [];
+};
+
+/**
+ * Check function arity.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Params.prototype.__defineGetter__('length', function(){
+ return this.nodes.length;
+});
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Params.prototype.__proto__ = Node.prototype;
+
+/**
+ * Push the given `node`.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+Params.prototype.push = function(node){
+ this.nodes.push(node);
+};
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Params.prototype.clone = function(){
+ var clone = new Params;
+ clone.lineno = this.lineno;
+ this.nodes.forEach(function(node){
+ clone.push(node.clone());
+ });
+ return clone;
+};
+
--- /dev/null
+
+/*!
+ * Stylus - Property
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Property` with the given `segs` and optional `expr`.
+ *
+ * @param {Array} segs
+ * @param {Expression} expr
+ * @api public
+ */
+
+var Property = module.exports = function Property(segs, expr){
+ Node.call(this);
+ this.segments = segs;
+ this.expr = expr;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Property.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Property.prototype.clone = function(){
+ var clone = new Property(this.segments);
+ clone.lineno = this.lineno;
+ this.segments = this.segments.map(function(node){ return node.clone(); });
+ if (this.expr) clone.expr = this.expr.clone();
+ return clone;
+};
--- /dev/null
+
+/*!
+ * Stylus - Return
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Return` node with the given `expr`.
+ *
+ * @param {Expression} expr
+ * @api public
+ */
+
+var Return = module.exports = function Return(expr){
+ this.expr = expr || nodes.null;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Return.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Return.prototype.clone = function(){
+ var clone = new Return(this.expr.clone());
+ clone.lineno = this.lineno;
+ return clone;
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - RGBA
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , HSLA = require('./hsla')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `RGBA` with the given r,g,b,a component values.
+ *
+ * @param {Number} r
+ * @param {Number} g
+ * @param {Number} b
+ * @param {Number} a
+ * @api public
+ */
+
+var RGBA = exports = module.exports = function RGBA(r,g,b,a){
+ Node.call(this);
+ this.r = clamp(r);
+ this.g = clamp(g);
+ this.b = clamp(b);
+ this.a = clampAlpha(a);
+ this.rgba = this;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+RGBA.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+RGBA.prototype.clone = function(){
+ var clone = new RGBA(
+ this.r
+ , this.g
+ , this.b
+ , this.a);
+ clone.lineno = this.lineno;
+ return clone;
+};
+
+/**
+ * Return true.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+RGBA.prototype.toBoolean = function(){
+ return nodes.true;
+};
+
+/**
+ * Return `HSLA` representation.
+ *
+ * @return {HSLA}
+ * @api public
+ */
+
+RGBA.prototype.__defineGetter__('hsla', function(){
+ return HSLA.fromRGBA(this);
+});
+
+/**
+ * Return hash.
+ *
+ * @return {String}
+ * @api public
+ */
+
+RGBA.prototype.__defineGetter__('hash', function(){
+ return this.toString();
+});
+
+/**
+ * Coerce HSLA and Unit to RGBA.
+ *
+ * @param {Node} other
+ * @return {Node}
+ * @api public
+ */
+
+RGBA.prototype.coerce = function(other){
+ if (other instanceof nodes.HSLA) {
+ return other.rgba;
+ } else if (other instanceof nodes.Unit) {
+ var n = other.val;
+ return new RGBA(n,n,n,1);
+ } else {
+ return Node.prototype.coerce.call(this, other);
+ }
+};
+
+/**
+ * Operate on `right` with the given `op`.
+ *
+ * @param {String} op
+ * @param {Node} right
+ * @return {Node}
+ * @api public
+ */
+
+RGBA.prototype.operate = function(op, right){
+ switch (op) {
+ case '+':
+ return new RGBA(
+ this.r + right.r
+ , this.g + right.g
+ , this.b + right.b
+ , 1 == right.a ? this.a : (this.a + right.a)
+ );
+ case '-':
+ return new RGBA(
+ this.r - right.r
+ , this.g - right.g
+ , this.b - right.b
+ , 1 == right.a ? this.a : (this.a - right.a)
+ );
+ case '*':
+ return new RGBA(
+ this.r * right.r
+ , this.g * right.g
+ , this.b * right.b
+ , this.a * right.a
+ );
+ case '/':
+ return new RGBA(
+ this.r / right.r
+ , this.g / right.g
+ , this.b / right.b
+ , this.a / right.a
+ );
+ default:
+ return Node.prototype.operate.call(this, op, right);
+ }
+};
+
+/**
+ * Return #nnnnnn, #nnn, or rgba(n,n,n,n) string representation of the color.
+ *
+ * @return {String}
+ * @api public
+ */
+
+RGBA.prototype.toString = function(){
+ function pad(n) {
+ return n < 16
+ ? '0' + n.toString(16)
+ : n.toString(16);
+ }
+
+ if (1 == this.a) {
+ var r = pad(this.r)
+ , g = pad(this.g)
+ , b = pad(this.b);
+
+ // Compress
+ if (r[0] == r[1] && g[0] == g[1] && b[0] == b[1]) {
+ return '#' + r[0] + g[0] + b[0];
+ } else {
+ return '#' + r + g + b;
+ }
+ } else {
+ return 'rgba('
+ + this.r + ','
+ + this.g + ','
+ + this.b + ','
+ + this.a + ')';
+ }
+};
+
+/**
+ * Return a `RGBA` from the given `hsla`.
+ *
+ * @param {HSLA} hsla
+ * @return {RGBA}
+ * @api public
+ */
+
+exports.fromHSLA = function(hsla){
+ var h = hsla.h / 360
+ , s = hsla.s / 100
+ , l = hsla.l / 100
+ , a = hsla.a;
+
+ var m2 = l <= .5 ? l * (s + 1) : l + s - l * s
+ , m1 = l * 2 - m2;
+
+ var r = hue(h + 1/3) * 0xff
+ , g = hue(h) * 0xff
+ , b = hue(h - 1/3) * 0xff;
+
+ function hue(h) {
+ if (h < 0) ++h;
+ if (h > 1) --h;
+ if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
+ if (h * 2 < 1) return m2;
+ if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
+ return m1;
+ }
+
+ return new RGBA(r,g,b,a);
+};
+
+/**
+ * Clamp `n` >= 0 and <= 255.
+ *
+ * @param {Number} n
+ * @return {Number}
+ * @api private
+ */
+
+function clamp(n) {
+ return Math.max(0, Math.min(n.toFixed(0), 255));
+}
+
+/**
+ * Clamp alpha `n` >= 0 and <= 1.
+ *
+ * @param {Number} n
+ * @return {Number}
+ * @api private
+ */
+
+function clampAlpha(n) {
+ return Math.max(0, Math.min(n, 1));
+}
--- /dev/null
+
+/*!
+ * Stylus - Root
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Root` node.
+ *
+ * @api public
+ */
+
+var Root = module.exports = function Root(){
+ this.nodes = [];
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Root.prototype.__proto__ = Node.prototype;
+
+/**
+ * Push a `node` to this block.
+ *
+ * @param {Node} node
+ * @api public
+ */
+
+Root.prototype.push = function(node){
+ this.nodes.push(node);
+};
+
+/**
+ * Return "root".
+ *
+ * @return {String}
+ * @api public
+ */
+
+Root.prototype.toString = function(){
+ return '[Root]';
+};
--- /dev/null
+
+/*!
+ * Stylus - Selector
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Block = require('./block')
+ , Node = require('./node');
+
+/**
+ * Initialize a new `Selector` with the given `val`.
+ *
+ * @param {String} val
+ * @api public
+ */
+
+var Selector = module.exports = function Selector(val){
+ Node.call(this);
+ this.val = val.replace(/ +$/, '');
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Selector.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return the selector string.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Selector.prototype.toString = function(){
+ return this.val;
+};
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Selector.prototype.clone = function(){
+ var clone = new Selector(this.val);
+ clone.lineno = this.lineno;
+ return clone;
+};
--- /dev/null
+
+/*!
+ * Stylus - String
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `String` with the given `val`.
+ *
+ * @param {String} val
+ * @api public
+ */
+
+var String = module.exports = function String(val){
+ Node.call(this);
+ this.val = val;
+ this.string = val;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+String.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return quoted string.
+ *
+ * @return {String}
+ * @api public
+ */
+
+String.prototype.toString = function(){
+ return '"' + this.val + '"';
+};
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+String.prototype.clone = function(){
+ var clone = new String(this.val);
+ clone.lineno = this.lineno;
+ return clone;
+};
+
+/**
+ * Return Boolean based on the length of this string.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+String.prototype.toBoolean = function(){
+ return nodes.Boolean(this.val.length);
+};
+
+/**
+ * Coerce `other` to a string.
+ *
+ * @param {Node} other
+ * @return {String}
+ * @api public
+ */
+
+String.prototype.coerce = function(other){
+ if (other instanceof String) {
+ return other;
+ } else {
+ return new String(other.toString());
+ }
+};
+
+/**
+ * Operate on `right` with the given `op`.
+ *
+ * @param {String} op
+ * @param {Node} right
+ * @return {Node}
+ * @api public
+ */
+
+String.prototype.operate = function(op, right){
+ switch (op) {
+ case '+':
+ return new String(this.val + right.val);
+ default:
+ return Node.prototype.operate.call(this, op, right);
+ }
+};
--- /dev/null
+
+/*!
+ * Stylus - Ternary
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `Ternary` with `cond`, `trueExpr` and `falseExpr`.
+ *
+ * @param {Expression} cond
+ * @param {Expression} trueExpr
+ * @param {Expression} falseExpr
+ * @api public
+ */
+
+var Ternary = module.exports = function Ternary(cond, trueExpr, falseExpr){
+ Node.call(this);
+ this.cond = cond;
+ this.trueExpr = trueExpr;
+ this.falseExpr = falseExpr;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Ternary.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Ternary.prototype.clone = function(){
+ var clone = new Ternary(
+ this.cond.clone()
+ , this.trueExpr.clone()
+ , this.falseExpr.clone());
+ clone.lineno = this.lineno;
+ return clone;
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - UnaryOp
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node');
+
+/**
+ * Initialize a new `UnaryOp` with `op`, and `expr`.
+ *
+ * @param {String} op
+ * @param {Node} expr
+ * @api public
+ */
+
+var UnaryOp = module.exports = function UnaryOp(op, expr){
+ Node.call(this);
+ this.op = op;
+ this.expr = expr;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+UnaryOp.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+UnaryOp.prototype.clone = function(){
+ var clone = new UnaryOp(this.op, this.expr.clone());
+ clone.lineno = this.lineno;
+ return clone;
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Unit
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Node = require('./node')
+ , nodes = require('./');
+
+/**
+ * Initialize a new `Unit` with the given `val` and unit `type`
+ * such as "px", "pt", "in", etc.
+ *
+ * @param {String} val
+ * @param {String} type
+ * @api public
+ */
+
+var Unit = module.exports = function Unit(val, type){
+ Node.call(this);
+ this.val = val;
+ this.type = type;
+};
+
+/**
+ * Inherit from `Node.prototype`.
+ */
+
+Unit.prototype.__proto__ = Node.prototype;
+
+/**
+ * Return Boolean based on the unit value.
+ *
+ * @return {Boolean}
+ * @api public
+ */
+
+Unit.prototype.toBoolean = function(){
+ return nodes.Boolean(this.type
+ ? true
+ : this.val);
+};
+
+/**
+ * Return unit string.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Unit.prototype.toString = function(){
+ var n = this.val;
+ if ('px' == this.type) n = n.toFixed(0);
+ return n + (this.type || '');
+};
+
+/**
+ * Return a clone of this node.
+ *
+ * @return {Node}
+ * @api public
+ */
+
+Unit.prototype.clone = function(){
+ var clone = new Unit(this.val, this.type);
+ clone.lineno = this.lineno;
+ return clone;
+};
+
+/**
+ * Operate on `right` with the given `op`.
+ *
+ * @param {String} op
+ * @param {Node} right
+ * @return {Node}
+ * @api public
+ */
+
+Unit.prototype.operate = function(op, right){
+ switch (op) {
+ case '-':
+ return new Unit(this.val - right.val, this.type);
+ case '+':
+ return new Unit(this.val + right.val, this.type);
+ case '/':
+ return new Unit(this.val / right.val, this.type);
+ case '*':
+ return new Unit(this.val * right.val, this.type);
+ case '%':
+ return new Unit(this.val % right.val, this.type);
+ case '**':
+ return new Unit(Math.pow(this.val, right.val), this.type);
+ case '..':
+ case '...':
+ var start = this.val
+ , end = right.val
+ , expr = new nodes.Expression
+ , inclusive = '..' == op;
+ do {
+ expr.push(new nodes.Unit(start));
+ } while (inclusive ? ++start <= end : ++start < end);
+ return expr;
+ default:
+ return Node.prototype.operate.call(this, op, right);
+ }
+};
+
+/**
+ * Coerce `other` unit to the same type as `this` unit.
+ *
+ * Supports:
+ *
+ * mm -> cm | in
+ * cm -> mm | in
+ * in -> mm | cm
+ *
+ * ms -> s
+ * s -> ms
+ *
+ * Hz -> kHz
+ * kHz -> Hz
+ *
+ * @param {Unit} other
+ * @return {Unit}
+ * @api public
+ */
+
+Unit.prototype.coerce = function(other){
+ if (other instanceof Unit) {
+ var a = this
+ , b = other;
+ switch (a.type) {
+ case 'mm':
+ switch (b.type) {
+ case 'cm':
+ return new nodes.Unit(b.val * 2.54, 'mm');
+ case 'in':
+ return new nodes.Unit(b.val * 25.4, 'mm');
+ }
+ case 'cm':
+ switch (b.type) {
+ case 'mm':
+ return new nodes.Unit(b.val / 10, 'cm');
+ case 'in':
+ return new nodes.Unit(b.val * 2.54, 'cm');
+ }
+ case 'in':
+ switch (b.type) {
+ case 'mm':
+ return new nodes.Unit(b.val / 25.4, 'in');
+ case 'cm':
+ return new nodes.Unit(b.val / 2.54, 'in');
+ }
+ case 'ms':
+ switch (b.type) {
+ case 's':
+ return new nodes.Unit(b.val * 1000, 'ms');
+ }
+ case 's':
+ switch (b.type) {
+ case 'ms':
+ return new nodes.Unit(b.val / 1000, 's');
+ }
+ case 'Hz':
+ switch (b.type) {
+ case 'kHz':
+ return new nodes.Unit(b.val * 1000, 'Hz');
+ }
+ case 'kHz':
+ switch (b.type) {
+ case 'Hz':
+ return new nodes.Unit(b.val / 1000, 'kHz');
+ }
+ }
+ return new nodes.Unit(b.val, a.type);
+ } else if (other instanceof nodes.String) {
+ var val = parseInt(other.val, 10);
+ if (isNaN(val)) Node.prototype.coerce.call(this, other);
+ return new nodes.Unit(val);
+ } else {
+ return Node.prototype.coerce.call(this, other);
+ }
+};
--- /dev/null
+
+/*!
+ * Stylus - Parser
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Lexer = require('./lexer')
+ , nodes = require('./nodes')
+ , inspect = require('sys').inspect;
+
+/**
+ * Selector composite tokens.
+ */
+
+var selectorTokens = [
+ 'ident'
+ , 'string'
+ , 'selector'
+ , 'function'
+ , 'comment'
+ , 'space'
+ , 'color'
+ , 'unit'
+ , 'for'
+ , '['
+ , ']'
+ , '('
+ , ')'
+ , '+'
+ , '-'
+ , '*'
+ , '*='
+ , '<'
+ , '>'
+ , '='
+ , ':'
+ , '&'
+ , '~'
+];
+
+/**
+ * CSS3 pseudo-selectors.
+ */
+
+var pseudoSelectors = [
+ 'root'
+ , 'nth-child'
+ , 'nth-last-child'
+ , 'nth-of-type'
+ , 'nth-last-of-type'
+ , 'first-child'
+ , 'last-child'
+ , 'first-of-type'
+ , 'last-of-type'
+ , 'only-child'
+ , 'only-of-type'
+ , 'empty'
+ , 'link'
+ , 'visited'
+ , 'active'
+ , 'hover'
+ , 'focus'
+ , 'target'
+ , 'lang'
+ , 'enabled'
+ , 'disabled'
+ , 'checked'
+ , 'not'
+];
+
+/**
+ * Initialize a new `Parser` with the given `str` and `options`.
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @api private
+ */
+
+var Parser = module.exports = function Parser(str, options) {
+ var self = this;
+ options = options || {};
+ this.str = nodes.source = str;
+ this.lexer = new Lexer(str, options);
+ this.root = options.root || new nodes.Root;
+ this.state = ['root'];
+ this.state.pop = function(){
+ self.prevState = [].pop.call(this);
+ };
+};
+
+/**
+ * Parser prototype.
+ */
+
+Parser.prototype = {
+
+ /**
+ * Constructor.
+ */
+
+ constructor: Parser,
+
+ /**
+ * Return current state.
+ *
+ * @return {String}
+ * @api private
+ */
+
+ currentState: function() {
+ return this.state[this.state.length - 1];
+ },
+
+ /**
+ * Parse the input, then return the root node.
+ *
+ * @return {Node}
+ * @api private
+ */
+
+ parse: function(){
+ var block = this.parent = this.root;
+ while ('eos' != this.peek().type) {
+ if (this.accept('newline')) continue;
+ var stmt = this.statement();
+ this.accept(';');
+ if (!stmt) this.error('unexpected token {peek}, not allowed at the root level');
+ block.push(stmt);
+ }
+ return block;
+ },
+
+ /**
+ * Throw an `Error` with the given `msg`.
+ *
+ * @param {String} msg
+ * @api private
+ */
+
+ error: function(msg){
+ var type = this.peek().type
+ , val = undefined == this.peek().val
+ ? ''
+ : ' ' + this.peek().toString();
+ if (val.trim() == type.trim()) val = '';
+ throw new Error(msg.replace('{peek}', type + val));
+ },
+
+ /**
+ * Accept the given token `type`, and return it,
+ * otherwise return `undefined`.
+ *
+ * @param {String} type
+ * @return {Token}
+ * @api private
+ */
+
+ accept: function(type){
+ if (type == this.peek().type) {
+ return this.next();
+ }
+ },
+
+ /**
+ * Expect token `type` and return it, throw otherwise.
+ *
+ * @param {String} type
+ * @return {Token}
+ * @api private
+ */
+
+ expect: function(type){
+ if (type != this.peek().type) {
+ throw new Error('expected ' + type + ', got ' + this.peek());
+ }
+ return this.next();
+ },
+
+ /**
+ * Get the next token.
+ *
+ * @return {Token}
+ * @api private
+ */
+
+ next: function() {
+ var tok = this.lexer.next();
+ nodes.lineno = tok.lineno;
+ return tok;
+ },
+
+ /**
+ * Peek with lookahead(1).
+ *
+ * @return {Token}
+ * @api private
+ */
+
+ peek: function() {
+ return this.lexer.peek();
+ },
+
+ /**
+ * Lookahead `n` tokens.
+ *
+ * @param {Number} n
+ * @return {Token}
+ * @api private
+ */
+
+ lookahead: function(n){
+ return this.lexer.lookahead(n);
+ },
+
+ /**
+ * Check if the token at `n` is a valid selector token.
+ *
+ * @param {Number} n
+ * @return {Boolean}
+ * @api private
+ */
+
+ isSelectorToken: function(n) {
+ var la = this.lookahead(n).type;
+ switch (la) {
+ case 'for':
+ return this.bracketed;
+ case '[':
+ this.bracketed = true;
+ return true;
+ case ']':
+ this.bracketed = false;
+ return true;
+ default:
+ return ~selectorTokens.indexOf(la);
+ }
+ },
+
+ /**
+ * Check if the token at `n` is a pseudo selector.
+ *
+ * @param {Number} n
+ * @return {Boolean}
+ * @api private
+ */
+
+ isPseudoSelector: function(n){
+ return ~pseudoSelectors.indexOf(this.lookahead(n).val.name);
+ },
+
+ /**
+ * Valid selector tokens.
+ */
+
+ selectorToken: function() {
+ if (this.isSelectorToken(1)) return this.next();
+ },
+
+ /**
+ * Consume whitespace.
+ */
+
+ skipWhitespace: function() {
+ while (~['space', 'indent', 'outdent', 'newline'].indexOf(this.peek().type))
+ this.next();
+ },
+
+ /**
+ * Consume spaces.
+ */
+
+ skipSpaces: function() {
+ while ('space' == this.peek().type)
+ this.next();
+ },
+
+ /**
+ * Check if the following sequence of tokens
+ * forms a function definition, ie trailing
+ * `{` or indentation.
+ */
+
+ looksLikeFunctionDefinition: function(i) {
+ return 'indent' == this.lookahead(i).type
+ || '{' == this.lookahead(i).type;
+ },
+
+ /**
+ * Check if the following sequence of tokens
+ * forms a selector.
+ */
+
+ looksLikeSelector: function() {
+ var i = 1;
+
+ // Assume selector when an ident is
+ // followed by a selector
+ while ('ident' == this.lookahead(i).type
+ && 'newline' == this.lookahead(i + 1).type) i += 2;
+
+ // Assume pseudo selectors are NOT properties
+ // as 'td:th-child(1)' may look like a property
+ // and function call to the parser otherwise
+ while (this.isSelectorToken(i)) {
+ if (':' == this.lookahead(i++).type
+ && this.isPseudoSelector(i))
+ return true;
+ }
+
+ // Trailing comma
+ if (',' == this.lookahead(i).type
+ && 'newline' == this.lookahead(i + 1).type)
+ return true;
+
+ // Trailing brace
+ if ('{' == this.lookahead(i).type
+ && 'newline' == this.lookahead(i + 1).type)
+ return true;
+
+ // css-style mode, false on ; }
+ if (this.css) {
+ if (';' == this.lookahead(i) ||
+ '}' == this.lookahead(i))
+ return false;
+ }
+
+ // Trailing separators
+ while (!~[
+ 'newline'
+ , 'indent'
+ , 'outdent'
+ , 'for'
+ , 'if'
+ , ';'
+ , '}'].indexOf(this.lookahead(i).type))
+ ++i;
+
+ if ('indent' == this.lookahead(i).type)
+ return true;
+ },
+
+ /**
+ * statement
+ * | statement 'if' expression
+ * | statement 'unless' expression
+ */
+
+ statement: function() {
+ var stmt = this.stmt()
+ , state = this.prevState
+ , block
+ , op;
+
+ // special-case statements since it
+ // is not an expression. We could
+ // implement postfix conditionals at
+ // the expression level, however they
+ // would then fail to enclose properties
+ if (this.allowPostfix) {
+ delete this.allowPostfix;
+ state = 'expression';
+ }
+
+ switch (state) {
+ case 'assignment':
+ case 'expression':
+ case 'function arguments':
+ while (op =
+ this.accept('if')
+ || this.accept('unless')
+ || this.accept('for')) {
+ switch (op.type) {
+ case 'if':
+ case 'unless':
+ stmt = new nodes.If(this.expression(), stmt);
+ stmt.postfix = true;
+ stmt.negate = 'unless' == op.type;
+ this.accept(';');
+ break;
+ case 'for':
+ var key
+ , val = this.id().name;
+ if (this.accept(',')) key = this.id().name;
+ this.expect('in');
+ var each = new nodes.Each(val, key, this.expression());
+ block = new nodes.Block;
+ block.push(stmt);
+ each.block = block;
+ stmt = each;
+ }
+ }
+ }
+
+ return stmt;
+ },
+
+ /**
+ * ident
+ * | selector
+ * | literal
+ * | charset
+ * | import
+ * | media
+ * | keyframes
+ * | page
+ * | for
+ * | if
+ * | unless
+ * | expression
+ * | 'return' expression
+ */
+
+ stmt: function() {
+ var type = this.peek().type;
+ switch (type) {
+ case 'selector':
+ case 'literal':
+ case 'keyframes':
+ case 'charset':
+ case 'import':
+ case 'media':
+ case 'page':
+ case 'ident':
+ case 'unless':
+ case 'function':
+ case 'for':
+ case 'if':
+ return this[type]();
+ case 'return':
+ return this.return();
+ case '{':
+ return this.property();
+ default:
+ // Contextual selectors
+ switch (this.currentState()) {
+ case 'root':
+ case 'selector':
+ case 'conditional':
+ case 'keyframe':
+ case 'function':
+ case 'media':
+ case 'for':
+ switch (type) {
+ case 'color':
+ case '~':
+ case '+':
+ case '>':
+ case '<':
+ case '*':
+ case ':':
+ case '&':
+ case '[':
+ return this.selector();
+ }
+ }
+
+ // Expression fallback
+ var expr = this.expression();
+ if (expr.isEmpty) this.error('unexpected {peek}');
+ return expr;
+ }
+ },
+
+ /**
+ * indent (!outdent)+ outdent
+ */
+
+ block: function(node, scope) {
+ var delim
+ , stmt
+ , _ = this.css
+ , block = this.parent = new nodes.Block(this.parent, node);
+
+ if (false === scope) block.scope = false;
+
+ // css-style
+ if (this.css = this.accept('{')) {
+ delim = '}';
+ this.skipWhitespace();
+ } else {
+ delim = 'outdent';
+ this.expect('indent');
+ }
+
+ while (delim != this.peek().type) {
+ // css-style
+ if (this.css) {
+ if (this.accept('newline')) continue;
+ stmt = this.statement();
+ this.accept(';');
+ this.skipWhitespace();
+ } else {
+ if (this.accept('newline')) continue;
+ stmt = this.statement();
+ this.accept(';');
+ }
+ if (!stmt) this.error('unexpected token {peek} in block');
+ block.push(stmt);
+ }
+
+ // css-style
+ if (this.css) {
+ this.skipWhitespace();
+ this.expect('}');
+ this.skipSpaces();
+ this.css = _;
+ } else {
+ this.expect('outdent');
+ }
+
+ this.parent = block.parent;
+ return block;
+ },
+
+ /**
+ * for val (',' key) in expr
+ */
+
+ for: function() {
+ this.expect('for');
+ var key
+ , val = this.id().name;
+ if (this.accept(',')) key = this.id().name;
+ this.expect('in');
+ var each = new nodes.Each(val, key, this.expression());
+ this.state.push('for');
+ each.block = this.block(each, false);
+ this.state.pop();
+ return each;
+ },
+
+ /**
+ * return expression
+ */
+
+ return: function() {
+ this.expect('return');
+ var expr = this.expression();
+ return expr.isEmpty
+ ? new nodes.Return
+ : new nodes.Return(expr);
+ },
+
+ /**
+ * unless expression block
+ */
+
+ unless: function() {
+ this.expect('unless');
+ var node = new nodes.If(this.expression(), true);
+ this.state.push('conditional');
+ node.block = this.block(node, false);
+ this.state.pop();
+ return node;
+ },
+
+ /**
+ * if expression block (else block)?
+ */
+
+ if: function() {
+ this.expect('if');
+ var node = new nodes.If(this.expression());
+ this.state.push('conditional');
+ node.block = this.block(node, false);
+ while (this.accept('else')) {
+ if (this.accept('if')) {
+ var cond = this.expression()
+ , block = this.block(node, false);
+ node.elses.push(new nodes.If(cond, block));
+ } else {
+ node.elses.push(this.block(node, false));
+ break;
+ }
+ }
+ this.state.pop();
+ return node;
+ },
+
+ /**
+ * media
+ */
+
+ media: function() {
+ var val = this.expect('media').val
+ , media = new nodes.Media(val);
+ this.state.push('media');
+ media.block = this.block(media);
+ this.state.pop();
+ return media;
+ },
+
+ /**
+ * import expression
+ */
+
+ import: function() {
+ this.expect('import');
+ this.allowPostfix = true;
+ return new nodes.Import(this.expression());
+ },
+
+ /**
+ * charset string
+ */
+
+ charset: function() {
+ this.expect('charset');
+ var str = this.expect('string').val;
+ this.allowPostfix = true;
+ return new nodes.Charset(str);
+ },
+
+ /**
+ * page selector? block
+ */
+
+ page: function() {
+ var selector;
+ this.expect('page');
+ if (this.accept(':')) {
+ var str = this.expect('ident').val.name;
+ selector = new nodes.Literal(':' + str);
+ }
+ var page = new nodes.Page(selector);
+ this.state.push('page');
+ page.block = this.block(page);
+ this.state.pop();
+ return page;
+ },
+
+ /**
+ * keyframes name ((unit | from | to) block)+
+ */
+
+ keyframes: function() {
+ this.expect('keyframes');
+ var pos
+ , _ = this.css
+ , keyframes = new nodes.Keyframes(this.id());
+
+ // css-sty;e
+ if (this.css = this.accept('{')) {
+ this.skipWhitespace();
+ } else {
+ this.expect('indent');
+ }
+
+ while (pos = this.accept('unit') || this.accept('ident')) {
+ // from | to
+ if ('ident' == pos.type) {
+ this.accept('space');
+ switch (pos.val.name) {
+ case 'from':
+ pos = new nodes.Unit(0, '%');
+ break;
+ case 'to':
+ pos = new nodes.Unit(100, '%');
+ break;
+ default:
+ throw new Error('invalid ident "' + pos.val.name + '" in selector');
+ }
+ } else {
+ pos = pos.val;
+ }
+
+ // block
+ this.state.push('keyframe');
+ var block = this.block(keyframes);
+ keyframes.push(pos, block);
+ this.state.pop();
+ if (this.css) this.skipWhitespace();
+ }
+
+ // css-style
+ if (this.css) {
+ this.skipWhitespace();
+ this.expect('}');
+ this.css = _;
+ } else {
+ this.expect('outdent');
+ }
+
+ return keyframes;
+ },
+
+ /**
+ * literal
+ */
+
+ literal: function() {
+ return this.expect('literal').val;
+ },
+
+ /**
+ * ident space?
+ */
+
+ id: function() {
+ var tok = this.expect('ident');
+ this.accept('space');
+ return tok.val;
+ },
+
+ /**
+ * ident
+ * | assignment
+ * | property
+ * | selector
+ */
+
+ ident: function() {
+ var i = 2
+ , la = this.lookahead(i).type;
+
+ while ('space' == la) la = this.lookahead(++i).type;
+
+ switch (la) {
+ // Assignment
+ case '=':
+ case '?=':
+ case '-=':
+ case '+=':
+ case '*=':
+ case '/=':
+ case '%=':
+ return this.assignment();
+ // Operation
+ case '-':
+ case '+':
+ case '/':
+ case '*':
+ case '%':
+ case '**':
+ case 'and':
+ case 'or':
+ case '&&':
+ case '||':
+ case '>':
+ case '<':
+ case '>=':
+ case '<=':
+ case '!=':
+ case '==':
+ case '[':
+ case '?':
+ case 'in':
+ case 'is a':
+ case 'is defined':
+ // Prevent cyclic .ident, return literal
+ if (this._ident == this.peek()) {
+ return this.id();
+ } else {
+ this._ident = this.peek();
+ switch (this.currentState()) {
+ // unary op or selector in property / for
+ case 'for':
+ case 'selector':
+ return this.property();
+ // Part of a selector
+ case 'root':
+ return this.selector();
+ // Do not disrupt the ident when an operand
+ default:
+ return this.operand
+ ? this.id()
+ : this.expression();
+ }
+ }
+ // Selector or property
+ default:
+ switch (this.currentState()) {
+ case 'root':
+ return this.selector();
+ case 'for':
+ case 'page':
+ case 'media':
+ case 'selector':
+ case 'function':
+ case 'keyframe':
+ case 'conditional':
+ return this.property();
+ default:
+ return this.id();
+ }
+ }
+ },
+
+ /**
+ * (ident | '{' expression '}')+
+ */
+
+ interpolate: function() {
+ var node
+ , segs = [];
+ while (true) {
+ if (this.accept('{')) {
+ this.state.push('interpolation');
+ segs.push(this.expression());
+ this.expect('}');
+ this.state.pop();
+ } else if (node = this.accept('ident')){
+ segs.push(node.val);
+ } else {
+ break;
+ }
+ }
+ if (!segs.length) this.expect('ident');
+ return segs;
+ },
+
+ /**
+ * property ':'? expression
+ * | ident
+ */
+
+ property: function() {
+ if (this.looksLikeSelector()) return this.selector();
+
+ // property
+ var ident = this.interpolate()
+ , ret = prop = new nodes.Property(ident);
+
+ // optional ':'
+ this.accept('space');
+ if (this.accept(':')) this.accept('space');
+
+ this.state.push('property');
+ this.inProperty = true;
+ prop.expr = this.list();
+ if (prop.expr.isEmpty) ret = ident[0];
+ this.inProperty = false;
+ this.allowPostfix = true;
+ this.state.pop();
+
+ // optional ';'
+ this.accept(';');
+
+ return ret;
+ },
+
+ /**
+ * selector ',' selector
+ * | selector newline selector
+ * | selector block
+ */
+
+ selector: function() {
+ var tok
+ , arr
+ , val
+ , prev
+ , parent
+ , group = new nodes.Group;
+
+ // Allow comments in selectors
+ // for hacks
+ this.lexer.allowComments = true;
+
+ do {
+ val = prev = null;
+ arr = [];
+
+ // Clobber newline after ,
+ this.accept('newline');
+
+ // Selector candidates,
+ // stitched together to
+ // form a selector.
+ while (tok = this.selectorToken()) {
+ // Selector component
+ switch (tok.type) {
+ case 'unit': val = tok.val.val; break;
+ case 'ident': val = tok.val.name; break;
+ case 'function': val = tok.val.name + '('; break;
+ case 'string': val = tok.val.toString(); break;
+ case 'color': val = tok.val.raw; break;
+ case 'space': val = ' '; break;
+ default: val = tok.val;
+ }
+
+ // Whitespace support
+ if (!prev || prev.space) {
+ arr.push(val);
+ } else {
+ arr[arr.length-1] += val;
+ }
+ prev = tok;
+ }
+
+ // Push the selector
+ group.push(new nodes.Selector(arr.join(' '), parent));
+ } while (this.accept(',') || this.accept('newline'));
+
+ this.lexer.allowComments = false;
+ this.state.push('selector');
+ group.block = this.block(group);
+ this.state.pop();
+
+
+ return group;
+ },
+
+ /**
+ * ident ('=' | '?=') expression
+ */
+
+ assignment: function() {
+ var op
+ , node
+ , name = this.id().name;
+
+ if (op =
+ this.accept('=')
+ || this.accept('?=')
+ || this.accept('+=')
+ || this.accept('-=')
+ || this.accept('*=')
+ || this.accept('/=')
+ || this.accept('%=')) {
+ this.state.push('assignment');
+ var expr = this.list();
+ if (expr.isEmpty) this.error('invalid right-hand side operand in assignment, got {peek}')
+ node = new nodes.Ident(name, expr);
+ this.state.pop();
+
+ switch (op.type) {
+ case '?=':
+ var defined = new nodes.BinOp('is defined', node)
+ , lookup = new nodes.Ident(name);
+ node = new nodes.Ternary(defined, lookup, node);
+ break;
+ case '+=':
+ case '-=':
+ case '*=':
+ case '/=':
+ case '%=':
+ node.val = new nodes.BinOp(op.type[0], new nodes.Ident(name), expr);
+ break;
+ }
+ }
+
+ return node;
+ },
+
+ /**
+ * definition
+ * | call
+ */
+
+ function: function() {
+ var parens = 1
+ , i = 2
+ , tok;
+
+ // Lookahead and determine if we are dealing
+ // with a function call or definition. Here
+ // we pair parens to prevent false negatives
+ out:
+ while (tok = this.lookahead(i++)) {
+ switch (tok.type) {
+ case 'function': case '(': ++parens; break;
+ case ')': if (!--parens) break out;
+ }
+ }
+
+ // Definition or call
+ switch (this.currentState()) {
+ case 'expression':
+ return this.functionCall();
+ default:
+ return this.looksLikeFunctionDefinition(i)
+ ? this.functionDefinition()
+ : this.expression();
+ }
+ },
+
+ /**
+ * url '(' (expression | urlchars)+ ')'
+ */
+
+ url: function() {
+ this.expect('function');
+ this.state.push('function arguments');
+ var args = this.args();
+ this.expect(')');
+ this.state.pop();
+ return new nodes.Call('url', args);
+ },
+
+ /**
+ * ident '(' expression ')'
+ */
+
+ functionCall: function() {
+ if ('url' == this.peek().val.name) return this.url();
+ var name = this.expect('function').val.name;
+ this.state.push('function arguments');
+ var args = this.args();
+ this.expect(')');
+ this.state.pop();
+ return new nodes.Call(name, args);
+ },
+
+ /**
+ * ident '(' params ')' block
+ */
+
+ functionDefinition: function() {
+ var name = this.expect('function').val.name;
+
+ // params
+ this.state.push('function params');
+ this.skipWhitespace();
+ var params = this.params();
+ this.skipWhitespace();
+ this.expect(')');
+ this.state.pop();
+
+ // Body
+ this.state.push('function');
+ var fn = new nodes.Function(name, params);
+ fn.block = this.block(fn);
+ this.state.pop();
+ return new nodes.Ident(name, fn);
+ },
+
+ /**
+ * ident
+ * | ident '...'
+ * | ident '=' expression
+ * | ident ',' ident
+ */
+
+ params: function() {
+ var tok
+ , node
+ , params = new nodes.Params;
+ while (tok = this.accept('ident')) {
+ this.accept('space');
+ params.push(node = tok.val);
+ if (this.accept('...')) {
+ node.rest = true;
+ } else if (this.accept('=')) {
+ node.val = this.expression();
+ }
+ this.skipWhitespace();
+ this.accept(',');
+ this.skipWhitespace();
+ }
+ return params;
+ },
+
+ /**
+ * expression (',' expression)*
+ */
+
+ args: function() {
+ var args = new nodes.Expression;
+ do {
+ args.push(this.expression());
+ } while (this.accept(','));
+ return args;
+ },
+
+ /**
+ * expression (',' expression)*
+ */
+
+ list: function() {
+ var node = this.expression();
+ while (this.accept(',')) {
+ if (node.isList) {
+ list.push(this.expression());
+ } else {
+ var list = new nodes.Expression(true);
+ list.push(node);
+ list.push(this.expression());
+ node = list;
+ }
+ }
+ return node;
+ },
+
+ /**
+ * negation+
+ */
+
+ expression: function() {
+ var node
+ , expr = new nodes.Expression;
+ this.state.push('expression');
+ while (node = this.negation()) {
+ if (!node) this.error('unexpected token {peek} in expression');
+ expr.push(node);
+ }
+ this.state.pop();
+ return expr;
+ },
+
+ /**
+ * 'not' ternary
+ * | ternary
+ */
+
+ negation: function() {
+ if (this.accept('not')) {
+ return new nodes.UnaryOp('!', this.negation());
+ }
+ return this.ternary();
+ },
+
+ /**
+ * logical ('?' expression ':' expression)?
+ */
+
+ ternary: function() {
+ var node = this.logical();
+ if (this.accept('?')) {
+ var trueExpr = this.expression();
+ this.expect(':');
+ var falseExpr = this.expression();
+ node = new nodes.Ternary(node, trueExpr, falseExpr);
+ }
+ return node;
+ },
+
+ /**
+ * typecheck (('&&' | '||') typecheck)*
+ */
+
+ logical: function() {
+ var op
+ , node = this.typecheck();
+ while (op = this.accept('&&') || this.accept('||')) {
+ node = new nodes.BinOp(op.type, node, this.typecheck());
+ }
+ return node;
+ },
+
+ /**
+ * equality ('is a' equality)*
+ */
+
+ typecheck: function() {
+ var op
+ , node = this.equality();
+ while (op = this.accept('is a')) {
+ this.operand = true;
+ if (!node) throw new Error('illegal unary ' + op);
+ node = new nodes.BinOp(op.type, node, this.equality());
+ this.operand = false;
+ }
+ return node;
+ },
+
+ /**
+ * in (('==' | '!=') in)*
+ */
+
+ equality: function() {
+ var op
+ , node = this.in();
+ while (op = this.accept('==') || this.accept('!=')) {
+ this.operand = true;
+ if (!node) throw new Error('illegal unary ' + op);
+ node = new nodes.BinOp(op.type, node, this.in());
+ this.operand = false;
+ }
+ return node;
+ },
+
+ /**
+ * relational ('in' relational)*
+ */
+
+ in: function() {
+ var node = this.relational();
+ while (this.accept('in')) {
+ this.operand = true;
+ if (!node) throw new Error('illegal unary in');
+ node = new nodes.BinOp('in', node, this.relational());
+ this.operand = false;
+ }
+ return node;
+ },
+
+ /**
+ * range (('>=' | '<=' | '>' | '<') range)*
+ */
+
+ relational: function() {
+ var op
+ , node = this.range();
+ while (op =
+ this.accept('>=')
+ || this.accept('<=')
+ || this.accept('<')
+ || this.accept('>')
+ ) {
+ this.operand = true;
+ if (!node) throw new Error('illegal unary ' + op);
+ node = new nodes.BinOp(op.type, node, this.range());
+ this.operand = false;
+ }
+ return node;
+ },
+
+ /**
+ * additive (('..' | '...') additive)*
+ */
+
+ range: function() {
+ var op
+ , node = this.additive();
+ if (op = this.accept('...') || this.accept('..')) {
+ this.operand = true;
+ if (!node) throw new Error('illegal unary ' + op);
+ node = new nodes.BinOp(op.val, node, this.additive());
+ this.operand = false;
+ }
+ return node;
+ },
+
+ /**
+ * multiplicative (('+' | '-') multiplicative)*
+ */
+
+ additive: function() {
+ var op
+ , node = this.multiplicative();
+ while (op = this.accept('+') || this.accept('-')) {
+ this.operand = true;
+ node = new nodes.BinOp(op.type, node, this.multiplicative());
+ this.operand = false;
+ }
+ return node;
+ },
+
+ /**
+ * defined (('**' | '*' | '/' | '%') defined)*
+ */
+
+ multiplicative: function() {
+ var op
+ , node = this.defined();
+ while (op =
+ this.accept('**')
+ || this.accept('*')
+ || this.accept('/')
+ || this.accept('%')) {
+ this.operand = true;
+ if ('/' == op && this.inProperty && !this.parens) {
+ var expr = new nodes.Expression;
+ expr.push(node);
+ expr.push(new nodes.Literal('/'));
+ return expr;
+ } else {
+ if (!node) throw new Error('illegal unary ' + op);
+ node = new nodes.BinOp(op.type, node, this.defined());
+ this.operand = false;
+ }
+ }
+ return node;
+ },
+
+ /**
+ * unary 'is defined'
+ * | unary
+ */
+
+ defined: function() {
+ var node = this.unary();
+ if (this.accept('is defined')) {
+ if (!node) throw new Error('illegal use of "is defined"');
+ node = new nodes.BinOp('is defined', node);
+ }
+ return node;
+ },
+
+ /**
+ * ('!' | '~' | '+' | '-') unary
+ * | subscript
+ */
+
+ unary: function() {
+ var op
+ , node;
+ if (op =
+ this.accept('!')
+ || this.accept('~')
+ || this.accept('+')
+ || this.accept('-')) {
+ this.operand = true;
+ node = new nodes.UnaryOp(op.type, this.unary());
+ this.operand = false;
+ return node;
+ }
+ return this.subscript();
+ },
+
+ /**
+ * primary ('[' expression ']')+
+ * | primary
+ */
+
+ subscript: function() {
+ var node = this.primary();
+ while (this.accept('[')) {
+ node = new nodes.BinOp('[]', node, this.expression());
+ this.expect(']');
+ }
+ return node;
+ },
+
+ /**
+ * unit
+ * | null
+ * | color
+ * | string
+ * | ident
+ * | boolean
+ * | literal
+ * | '(' expression ')'
+ */
+
+ primary: function() {
+ var op
+ , node;
+
+ // Parenthesis
+ if (this.accept('(')) {
+ this.parens = true;
+ var expr = this.expression();
+ this.expect(')');
+ this.parens = false;
+ return expr;
+ }
+
+ // Primitive
+ switch (this.peek().type) {
+ case 'null':
+ case 'unit':
+ case 'color':
+ case 'string':
+ case 'literal':
+ case 'boolean':
+ return this.next().val;
+ case 'ident':
+ return this.ident();
+ case 'function':
+ return this.functionCall();
+ }
+ }
+};
--- /dev/null
+
+/*!
+ * Stylus - Renderer
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Parser = require('./parser')
+ , Compiler = require('./visitor/compiler')
+ , Evaluator = require('./visitor/evaluator')
+ , utils = require('./utils')
+ , nodes = require('./nodes');
+
+/**
+ * Initialize a new `Renderer` with the given `str` and `options`.
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @api public
+ */
+
+var Renderer = module.exports = function Renderer(str, options) {
+ options = options || {};
+ options.functions = {};
+ options.imports = [__dirname + '/functions'];
+ options.filename = options.filename || 'stylus';
+ this.str = str;
+ this.options = options;
+ this.parser = new Parser(str, options);
+};
+
+/**
+ * Parse and evaluate AST, then callback `fn(err, css)`.
+ *
+ * @param {Function} fn
+ * @api public
+ */
+
+Renderer.prototype.render = function(fn){
+ try {
+ var ast = this.parser.parse()
+ , expr;
+ this.evaluator = new Evaluator(ast, this.options);
+ ast = this.evaluator.evaluate();
+ new Compiler(ast, this.options).compile(fn);
+ } catch (err) {
+ fn(utils.formatException(
+ this
+ , err
+ , this.options));
+ }
+ nodes.source = null;
+};
+
+/**
+ * Set option `key` to `val`.
+ *
+ * @param {String} key
+ * @param {Mixed} val
+ * @return {Renderer} for chaining
+ * @api public
+ */
+
+Renderer.prototype.set = function(key, val){
+ this.options[key] = val;
+ return this;
+};
+
+/**
+ * Define function with the given `name`. Optionally
+ * the function may accept full expressions, by setting `raw`
+ * to `true`.
+ *
+ * @param {String} name
+ * @param {Function} fn
+ * @return {Renderer} for chaining
+ * @api public
+ */
+
+Renderer.prototype.define = function(name, fn, raw){
+ this.options.functions[name] = fn;
+ if (undefined != raw) fn.raw = raw;
+ return this;
+};
+
+/**
+ * Import the given `file`.
+ *
+ * @param {String} file
+ * @return {Renderer} for chaining
+ * @api public
+ */
+
+Renderer.prototype.import = function(file){
+ this.options.imports.push(file);
+ return this;
+};
+
+
--- /dev/null
+
+/*!
+ * Stylus - stack - Frame
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Scope = require('./scope')
+ , blocks = require('../nodes');
+
+/**
+ * Initialize a new `Frame` with the given `block`.
+ *
+ * @param {Block} block
+ * @api private
+ */
+
+var Frame = module.exports = function Frame(block) {
+ this._scope = false === block.scope
+ ? null
+ : new Scope;
+ this.block = block;
+};
+
+/**
+ * Return this frame's scope or the parent scope
+ * for scope-less blocks.
+ *
+ * @return {Scope}
+ * @api public
+ */
+
+Frame.prototype.__defineGetter__('scope', function(){
+ return this._scope || this.parent.scope;
+});
+
+/**
+ * Lookup the given local variable `name`.
+ *
+ * @param {String} name
+ * @return {Node}
+ * @api private
+ */
+
+Frame.prototype.lookup = function(name){
+ return this.scope.lookup(name)
+};
+
+/**
+ * Custom inspect.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Frame.prototype.inspect = function(){
+ return '[Frame '
+ + (false === this.block.scope
+ ? 'scope-less'
+ : this.scope.inspect())
+ + ']';
+};
--- /dev/null
+
+/*!
+ * Stylus - Stack
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Frame = require('./frame');
+
+/**
+ * Initialize a new `Stack`.
+ *
+ * @api private
+ */
+
+var Stack = module.exports = function Stack() {
+ Array.apply(this, arguments);
+};
+
+/**
+ * Inherit from `Array.prototype`.
+ */
+
+Stack.prototype.__proto__ = Array.prototype;
+
+/**
+ * Push the given `frame`.
+ *
+ * @param {Frame} frame
+ * @api public
+ */
+
+Stack.prototype.push = function(frame){
+ frame.stack = this;
+ frame.parent = this.currentFrame;
+ return [].push.apply(this, arguments);
+};
+
+/**
+ * Return the current stack `Frame`.
+ *
+ * @return {Frame}
+ * @api private
+ */
+
+Stack.prototype.__defineGetter__('currentFrame', function(){
+ return this[this.length - 1];
+});
+
+/**
+ * Lookup stack frame for the given `block`.
+ *
+ * @param {Block} block
+ * @return {Frame}
+ * @api private
+ */
+
+Stack.prototype.getBlockFrame = function(block){
+ for (var i = 0; i < this.length; ++i) {
+ if (block == this[i].block) {
+ return this[i];
+ }
+ }
+};
+
+/**
+ * Lookup the given local variable `name`, relative
+ * to the lexical scope of the current frame's `Block`.
+ *
+ * When the result of a lookup is an identifier
+ * a recursive lookup is performed, defaulting to
+ * returning the identifier itself.
+ *
+ * @param {String} name
+ * @return {Node}
+ * @api private
+ */
+
+Stack.prototype.lookup = function(name){
+ var block = this.currentFrame.block
+ , val
+ , ret;
+
+ do {
+ var frame = this.getBlockFrame(block);
+ if (frame && (val = frame.lookup(name))) {
+ switch (val.first.nodeName) {
+ case 'ident':
+ return this.lookup(val.first.name) || val;
+ default:
+ return val;
+ }
+ }
+ } while (block = block.parent);
+};
+
+/**
+ * Custom inspect.
+ *
+ * @return {String}
+ * @api private
+ */
+
+Stack.prototype.inspect = function(){
+ return this.reverse().map(function(frame){
+ return frame.inspect();
+ }).join('\n');
+};
+
+/**
+ * Return stack string formatted as:
+ *
+ * at <context> (<filename>:<lineno>)
+ *
+ * @return {String}
+ * @api private
+ */
+
+Stack.prototype.toString = function(){
+ var block
+ , node
+ , buf = []
+ , location
+ , len = this.length;
+
+ while (len--) {
+ block = this[len].block;
+ if (node = block.node) {
+ location = '(' + node.filename + ':' + node.lineno + ')';
+ switch (node.nodeName) {
+ case 'function':
+ buf.push(' at ' + node.name + '() ' + location);
+ break;
+ case 'group':
+ buf.push(' at "' + node.nodes[0].val + '" ' + location);
+ break;
+ }
+ }
+ }
+
+ return buf.join('\n');
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - stack - Scope
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Initialize a new `Scope`.
+ *
+ * @api private
+ */
+
+var Scope = module.exports = function Scope() {
+ this.locals = {};
+};
+
+/**
+ * Add `ident` node to the current scope.
+ *
+ * @param {Ident} ident
+ * @api private
+ */
+
+Scope.prototype.add = function(ident){
+ this.locals[ident.name] = ident.val;
+};
+
+/**
+ * Lookup the given local variable `name`.
+ *
+ * @param {String} name
+ * @return {Node}
+ * @api private
+ */
+
+Scope.prototype.lookup = function(name){
+ return this.locals[name];
+};
+
+/**
+ * Custom inspect.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Scope.prototype.inspect = function(){
+ var keys = Object.keys(this.locals).map(function(key){ return '@' + key; });
+ return '[Scope'
+ + (keys.length ? ' ' + keys.join(', ') : '')
+ + ']';
+};
--- /dev/null
+
+/*!
+ * Stylus
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Renderer = require('./renderer')
+ , nodes = require('./nodes')
+ , utils = require('./utils');
+
+/**
+ * Export render as the module.
+ */
+
+exports = module.exports = render;
+
+/**
+ * Library version.
+ */
+
+exports.version = '0.9.2';
+
+/**
+ * Expose nodes.
+ */
+
+exports.nodes = nodes;
+
+/**
+ * Expose BIFs.
+ */
+
+exports.functions = require('./functions');
+
+/**
+ * Expose utils.
+ */
+
+exports.utils = require('./utils');
+
+/**
+ * Expose middleware.
+ */
+
+exports.middleware = require('./middleware');
+
+/**
+ * Expose constructors.
+ */
+
+exports.Parser = require('./parser');
+exports.Evaluator = require('./visitor/evaluator');
+
+/**
+ * Convert the given `css` to `stylus` source.
+ *
+ * @param {String} css
+ * @return {String}
+ * @api public
+ */
+
+exports.convertCSS = require('./convert/css');
+
+/**
+ * Parse the given `str` with `options` and return the AST.
+ *
+ * Examples:
+ *
+ * css.parse(str);
+ * // raw ast comprised of nodes
+ *
+ * css.parse(str).toObject();
+ * // plain object representation
+ *
+ * css.parse(str).toJSON();
+ * // JSON representation
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @return {Object}
+ * @api public
+ */
+
+exports.parse = function(str, options){
+ var renderer = new Renderer(str, options);
+ try {
+ return renderer.parser.parse();
+ } catch (err) {
+ throw utils.formatException(
+ renderer
+ , err
+ , options);
+ }
+};
+
+/**
+ * Render the given `str` with `options` and callback `fn(err, css)`.
+ *
+ * @param {String} str
+ * @param {Object|Function} options
+ * @param {Function} fn
+ * @api public
+ */
+
+exports.render = function(str, options, fn){
+ if ('function' == typeof options) fn = options, options = {};
+ new Renderer(str, options).render(fn);
+};
+
+/**
+ * Return a new `Renderer` for the given `str` and `options`.
+ *
+ * @param {String} str
+ * @param {Object} options
+ * @return {Renderer}
+ * @api public
+ */
+
+function render(str, options) {
+ return new Renderer(str, options);
+}
+
+/**
+ * Expose optional functions.
+ */
+
+exports.url = require('./functions/url');
--- /dev/null
+
+/*!
+ * Stylus - Token
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var inspect = require('sys').inspect;
+
+/**
+ * Initialize a new `Token` with the given `type` and `val`.
+ *
+ * @param {String} type
+ * @param {Mixed} val
+ * @api private
+ */
+
+var Token = exports = module.exports = function Token(type, val) {
+ this.type = type;
+ this.val = val;
+};
+
+/**
+ * Custom inspect.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Token.prototype.inspect = function(){
+ var val = ' ' + inspect(this.val);
+ return '[Token:' + this.lineno + ' '
+ + '\x1b[32m' + this.type + '\x1b[0m'
+ + '\x1b[33m' + (this.val ? val : '') + '\x1b[0m'
+ + ']';
+};
+
+/**
+ * Return type or val.
+ *
+ * @return {String}
+ * @api public
+ */
+
+Token.prototype.toString = function(){
+ return (undefined === this.val
+ ? this.type
+ : this.val).toString();
+};
--- /dev/null
+
+/*!
+ * Stylus - utils
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var nodes = require('./nodes')
+ , inspect = require('sys').inspect
+ , fs = require('fs');
+
+/**
+ * Attempt to lookup `path` within `paths` from tail to head.
+ * Optionally a path to `ignore` may be passed.
+ *
+ * @param {String} path
+ * @param {String} paths
+ * @param {String} ignore
+ * @return {String}
+ * @api private
+ */
+
+exports.lookup = function(path, paths, ignore){
+ var lookup
+ , i = paths.length;
+
+ // Absolute
+ if ('/' == path[0]) {
+ try {
+ fs.statSync(path);
+ return path;
+ } catch (err) {
+ // Ignore, continue on
+ // to trying relative lookup.
+ // Needed for url(/images/foo.png)
+ // for example
+ }
+ }
+
+ // Relative
+ while (i--) {
+ try {
+ lookup = paths[i] + '/' + path;
+ if (ignore == lookup) continue;
+ fs.statSync(lookup);
+ return lookup;
+ } catch (err) {
+ // Ignore
+ }
+ }
+};
+
+/**
+ * Format the given `err` in context to `renderer`.
+ *
+ * @param {Renderer} renderer
+ * @param {Error} err
+ * @param {Object} options
+ * @return {Error}
+ * @api private
+ */
+
+exports.formatException = function(renderer, err, options){
+ var lineno = renderer.evaluator
+ ? renderer.evaluator.lineno
+ : renderer.parser.lexer.lineno
+ , contextLineno = lineno - 2
+ , contextLines = options.context || 8
+ , lastWidth = (contextLineno + contextLines).toString().length;
+
+ var src = (err.str || renderer.str).split('\n')
+ .slice(contextLineno, contextLineno + contextLines)
+ .map(function(line){
+ var n = ++contextLineno
+ , width = n.toString().length
+ , pad = Array(lastWidth - width + 1).join(' ');
+ return ' ' + pad + n + ': ' + inspect(line);
+ }).join('\n');
+
+ err.message = renderer.options.filename
+ + ':' + lineno
+ + '\n' + src
+ + '\n\n' + err.message + '\n'
+ + (err.stylusStack ? err.stylusStack + '\n' : '');
+
+ return err;
+};
+
+/**
+ * Assert that `node` is of the given `type`, or throw.
+ *
+ * @param {Node} node
+ * @param {Function} type
+ * @param {String} param
+ * @api public
+ */
+
+exports.assertType = function(node, type, param){
+ exports.assertPresent(node, param);
+ if (node instanceof type) return;
+ var actual = node.constructor.name
+ , msg = 'expected ' + type.name + ', but got ' + actual + ':' + node;
+ throw new Error('TypeError: ' + msg);
+};
+
+/**
+ * Assert that `node` is a `String` or `Ident`.
+ *
+ * @param {Node} node
+ * @param {String} param
+ * @api public
+ */
+
+exports.assertString = function(node, param){
+ exports.assertPresent(node, param);
+ if (node instanceof nodes.String) return;
+ if (node instanceof nodes.Ident) return;
+ var actual = node.constructor.name
+ , msg = 'expected String or Ident, but got ' + actual + ':' + node;
+ throw new Error('TypeError: ' + msg);
+};
+
+/**
+ * Assert that `node` is a `RGBA` or `HSLA`.
+ *
+ * @param {Node} node
+ * @param {String} param
+ * @api public
+ */
+
+exports.assertColor = function(node, param){
+ exports.assertPresent(node, param);
+ if (node instanceof nodes.RGBA) return;
+ if (node instanceof nodes.HSLA) return;
+ var actual = node.constructor.name
+ , msg = 'expected RGBA or HSLA, but got ' + actual + ':' + node;
+ throw new Error('TypeError: ' + msg);
+};
+
+/**
+ * Assert that param `name` is given, aka the `node` is passed.
+ *
+ * @param {Node} node
+ * @param {String} name
+ * @api public
+ */
+
+exports.assertPresent = function(node, name){
+ if (node) return;
+ if (name) throw new Error('ArgumentError: argument ' + name + ' required');
+ throw new Error('ArgumentError: argument missing');
+};
+
+/**
+ * Unwrap `expr`.
+ *
+ * Takes an expressions with length of 1
+ * such as `((1 2 3))` and unwraps it to `(1 2 3)`.
+ *
+ * @param {Expression} expr
+ * @return {Node}
+ * @api public
+ */
+
+exports.unwrap = function(expr){
+ if (expr.preserve) return expr;
+ if ('expression' != expr.nodeName) return expr;
+ if (1 != expr.nodes.length) return expr;
+ if ('expression' != expr.nodes[0].nodeName) return expr;
+ return exports.unwrap(expr.nodes[0]);
+};
\ No newline at end of file
--- /dev/null
+
+/*!
+ * Stylus - Compiler
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Visitor = require('./')
+ , nodes = require('../nodes');
+
+/**
+ * Initialize a new `Compiler` with the given `root` Node
+ * and the following `options`.
+ *
+ * Options:
+ *
+ * - `compress` Compress the css output, defaults to false
+ *
+ * @param {Node} root
+ * @api public
+ */
+
+var Compiler = module.exports = function Compiler(root, options) {
+ options = options || {};
+ this.compress = options.compress;
+ this.indents = 1;
+ Visitor.call(this, root);
+ this.tree = [];
+};
+
+/**
+ * Inherit from `Visitor.prototype`.
+ */
+
+Compiler.prototype.__proto__ = Visitor.prototype;
+
+/**
+ * Compile to css, and callback `fn(err, css)`.
+ *
+ * @param {Function} fn
+ * @api public
+ */
+
+Compiler.prototype.compile = function(fn){
+ this.callback = fn;
+ this.css = this.visit(this.root);
+ fn(null, this.css);
+};
+
+/**
+ * Return indentation string.
+ *
+ * @return {String}
+ * @api private
+ */
+
+Compiler.prototype.__defineGetter__('indent', function(){
+ return this.compress
+ ? ''
+ : new Array(this.indents).join(' ');
+});
+
+/**
+ * Visit Root.
+ */
+
+Compiler.prototype.visitRoot = function(block){
+ this.buf = '';
+ for (var i = 0, len = block.nodes.length; i < len; ++i) {
+ var node = block.nodes[i];
+ if (node instanceof nodes.Null
+ || node instanceof nodes.Expression
+ || node instanceof nodes.Function
+ || node instanceof nodes.Unit) continue;
+ var ret = this.visit(node);
+ if (ret) this.buf += ret + '\n';
+ }
+ return this.buf;
+};
+
+/**
+ * Visit Block.
+ */
+
+Compiler.prototype.visitBlock = function(block){
+ if (block.hasProperties) {
+ var arr = [this.compress ? '{' : ' {'];
+ ++this.indents;
+ for (var i = 0, len = block.nodes.length; i < len; ++i) {
+ this.last = len - 1 == i;
+ var node = block.nodes[i];
+ if (node instanceof nodes.Null
+ || node instanceof nodes.Expression
+ || node instanceof nodes.Function
+ || node instanceof nodes.Group
+ || node instanceof nodes.Unit) continue;
+ arr.push(this.visit(node));
+ }
+ --this.indents;
+ arr.push(this.indent + '}');
+ this.buf += arr.join(this.compress ? '' : '\n');
+ this.buf += '\n';
+ }
+
+ // Nesting
+ for (var i = 0, len = block.nodes.length; i < len; ++i) {
+ this.visit(block.nodes[i]);
+ }
+};
+
+/**
+ * Visit Keyframes.
+ */
+
+Compiler.prototype.visitKeyframes = function(node){
+ this.buf += '@-webkit-keyframes '
+ + this.visit(node.name)
+ + (this.compress ? '{' : ' {');
+ ++this.indents;
+ node.frames.forEach(function(frame){
+ if (!this.compress) this.buf += '\n ';
+ this.buf += this.visit(frame.pos);
+ this.visit(frame.block);
+ }, this);
+ --this.indents;
+ this.buf += '}' + (this.compress ? '' : '\n');
+};
+
+/**
+ * Visit Media.
+ */
+
+Compiler.prototype.visitMedia = function(media){
+ this.buf += '@media ' + media.val;
+ this.buf += this.compress ? '{' : ' {\n';
+ ++this.indents;
+ this.visit(media.block);
+ --this.indents;
+ this.buf += '}' + (this.compress ? '' : '\n');
+};
+
+/**
+ * Visit Page.
+ */
+
+Compiler.prototype.visitPage = function(page){
+ this.buf += this.indent + '@page';
+ this.buf += page.selector ? ' ' + page.selector : '';
+ this.visit(page.block);
+};
+
+/**
+ * Visit Function.
+ */
+
+Compiler.prototype.visitFunction = function(fn){
+ return fn.name;
+};
+
+/**
+ * Visit Variable.
+ */
+
+Compiler.prototype.visitVariable = function(variable){
+ return '';
+};
+
+/**
+ * Visit Charset.
+ */
+
+Compiler.prototype.visitCharset = function(charset){
+ return '@charset ' + this.visit(charset.val);
+};
+
+/**
+ * Visit Literal.
+ */
+
+Compiler.prototype.visitLiteral = function(lit){
+ return lit.val.trim().replace(/^ /gm, '');
+};
+
+/**
+ * Visit Boolean.
+ */
+
+Compiler.prototype.visitBoolean = function(bool){
+ return bool.toString();
+};
+
+/**
+ * Visit RGBA.
+ */
+
+Compiler.prototype.visitRGBA = function(rgba){
+ return rgba.toString();
+};
+
+/**
+ * Visit HSLA.
+ */
+
+Compiler.prototype.visitHSLA = function(hsla){
+ return hsla.rgba.toString();
+};
+
+/**
+ * Visit Unit.
+ */
+
+Compiler.prototype.visitUnit = function(unit){
+ var type = unit.type || ''
+ , n = unit.val
+ , float = n != (n | 0);
+
+ // Int
+ if ('px' == type) n = n.toFixed(0);
+ // Compress
+ if (this.compress) {
+ // Zero is always '0'
+ if (0 == n) return '0';
+ // Omit leading '0' on floats
+ if (float && n < 1 && n > -1) {
+ return n.toString().replace('0.', '.') + type;
+ }
+ }
+
+ return n.toString() + type;
+};
+
+/**
+ * Visit Group.
+ */
+
+Compiler.prototype.visitGroup = function(group){
+ var self = this
+ , tree = this.tree
+ , prev = tree[tree.length - 1]
+ , curr = [];
+
+ // Construct an array of arrays
+ // representing the selector hierarchy
+ group.nodes.forEach(function(node){
+ curr.push(node.parent
+ ? node
+ : node.val);
+ });
+
+ tree.push(curr);
+
+ // Reverse recurse the
+ // hierarchy array to build
+ // up the selector permutations.
+ // When we reach root, we have our
+ // selector string built
+ var selectors = []
+ , buf = [];
+ function join(arr, i) {
+ if (i) {
+ arr[i].forEach(function(str){
+ buf.unshift(str);
+ join(arr, i - 1);
+ buf.shift();
+ });
+ } else {
+ arr[0].forEach(function(selector){
+ var str = selector;
+ if (buf.length) {
+ for (var i = 0, len = buf.length; i < len; ++i) {
+ if (~buf[i].indexOf('&')) {
+ str = buf[i].replace('&', str);
+ } else {
+ str += ' ' + buf[i];
+ }
+ }
+ }
+ selectors.push(self.indent + str);
+ });
+ }
+ }
+
+ // Join selectors
+ if (group.block.hasProperties) {
+ join(tree, tree.length - 1);
+ this.buf += selectors.join(this.compress ? ',' : ',\n');
+ }
+
+ // Output blocks
+ this.visit(group.block);
+ tree.pop();
+};
+
+/**
+ * Visit Ident.
+ */
+
+Compiler.prototype.visitIdent = function(ident){
+ return ident.name;
+};
+
+/**
+ * Visit String.
+ */
+
+Compiler.prototype.visitString = function(string){
+ return this.isURL
+ ? string.val
+ : string.toString();
+};
+
+/**
+ * Visit Null.
+ */
+
+Compiler.prototype.visitNull = function(node){
+ return '';
+};
+
+/**
+ * Visit Call.
+ */
+
+Compiler.prototype.visitCall = function(call){
+ this.isURL = 'url' == call.name;
+ var args = call.args.nodes.map(function(arg){
+ return this.visit(arg);
+ }, this).join(this.compress ? ',' : ', ');
+ if (this.isURL) args = '"' + args + '"';
+ delete this.isURL;
+ return call.name + '(' + args + ')';
+};
+
+/**
+ * Visit Import.
+ */
+
+Compiler.prototype.visitImport = function(import){
+ return '@import ' + this.visit(import.path) + ';';
+};
+
+/**
+ * Visit Expression.
+ */
+
+Compiler.prototype.visitExpression = function(expr){
+ return expr.nodes.map(function(node){
+ return this.visit(node);
+ }, this).join(expr.isList
+ ? (this.compress ? ',' : ', ')
+ : (this.isURL ? '' : ' '));
+};
+
+/**
+ * Visit Property.
+ */
+
+Compiler.prototype.visitProperty = function(prop){
+ var self = this
+ , val = this.visit(prop.expr);
+ return this.indent + (prop.name || prop.segments.join(''))
+ + (this.compress ? ':' + val : ': ' + val)
+ + (this.compress
+ ? (this.last ? '' : ';')
+ : ';');
+};
--- /dev/null
+
+/*!
+ * Stylus - Evaluator
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Module dependencies.
+ */
+
+var Visitor = require('./')
+ , nodes = require('../nodes')
+ , Stack = require('../stack')
+ , Frame = require('../stack/frame')
+ , Scope = require('../stack/scope')
+ , utils = require('../utils')
+ , bifs = require('../functions')
+ , dirname = require('path').dirname
+ , colors = require('../colors')
+ , fs = require('fs');
+
+/**
+ * Initialize a new `Evaluator` with the given `root` Node
+ * and the following `options`.
+ *
+ * Options:
+ *
+ * - `compress` Compress the css output, defaults to false
+ * - `warn` Warn the user of duplicate function definitions etc
+ *
+ * @param {Node} root
+ * @api private
+ */
+
+var Evaluator = module.exports = function Evaluator(root, options) {
+ options = options || {};
+ Visitor.call(this, root);
+ this.stack = new Stack;
+ this.imports = options.imports || [];
+ this.functions = options.functions || {};
+ this.paths = options.paths || [];
+ this.filename = options.filename;
+ this.paths.push(dirname(options.filename || '.'));
+ this.stack.push(this.global = new Frame(root));
+ this.warnings = options.warn;
+ this.options = options;
+ this.calling = []; // TODO: remove, use stack
+};
+
+/**
+ * Inherit from `Visitor.prototype`.
+ */
+
+Evaluator.prototype.__proto__ = Visitor.prototype;
+
+/**
+ * Proxy visit to expose node line numbers.
+ *
+ * @param {Node} node
+ * @return {Node}
+ * @api private
+ */
+
+var visit = Visitor.prototype.visit;
+Evaluator.prototype.visit = function(node){
+ try {
+ return visit.call(this, node);
+ } catch (err) {
+ // TODO: less-lame hack to reference
+ // the origin node source input
+ this.lineno = this.lineno || node.lineno;
+ err.str = err.str || node.source;
+ err.stylusStack = err.stylusStack || this.stack.toString();
+ throw err;
+ }
+};
+
+/**
+ * Perform evaluation setup:
+ *
+ * - populate global scope
+ * - iterate imports
+ *
+ * @api private
+ */
+
+Evaluator.prototype.setup = function(){
+ this.populateGlobalScope();
+ this.imports.forEach(function(file){
+ var expr = new nodes.Expression;
+ expr.push(new nodes.String(file));
+ this.visit(new nodes.Import(expr));
+ }, this);
+};
+
+/**
+ * Populate the global scope with:
+ *
+ * - css colors
+ *
+ * @api private
+ */
+
+Evaluator.prototype.populateGlobalScope = function(){
+ var scope = this.global.scope;
+ Object.keys(colors).forEach(function(name){
+ var rgb = colors[name]
+ , rgba = new nodes.RGBA(rgb[0], rgb[1], rgb[2], 1)
+ , node = new nodes.Ident(name, rgba);
+ scope.add(node);
+ });
+};
+
+/**
+ * Evaluate the tree.
+ *
+ * @return {Node}
+ * @api private
+ */
+
+Evaluator.prototype.evaluate = function(){
+ this.setup();
+ return this.visit(this.root);
+};
+
+/**
+ * Visit Group.
+ */
+
+Evaluator.prototype.visitGroup = function(group){
+ group.block = this.visit(group.block);
+ return group;
+};
+
+/**
+ * Visit Charset.
+ */
+
+Evaluator.prototype.visitCharset = function(charset){
+ return charset;
+};
+
+/**
+ * Visit Return.
+ */
+
+Evaluator.prototype.visitReturn = function(ret){
+ ret.expr = this.visit(ret.expr);
+ throw ret;
+};
+
+/**
+ * Visit Media.
+ */
+
+Evaluator.prototype.visitMedia = function(media){
+ media.block = this.visit(media.block);
+ return media;
+};
+
+/**
+ * Visit Keyframes.
+ */
+
+Evaluator.prototype.visitKeyframes = function(keyframes){
+ keyframes.name = this.visit(keyframes.name).first.name;
+ return keyframes;
+};
+
+/**
+ * Visit Function.
+ */
+
+Evaluator.prototype.visitFunction = function(fn){
+ // check local
+ var local = this.stack.currentFrame.scope.lookup(fn.name);
+ if (local) this.warn('local ' + local.nodeName + ' "' + fn.name + '" previously defined in this scope');
+
+ // user-defined
+ var user = this.functions[fn.name];
+ if (user) this.warn('user-defined function "' + fn.name + '" is already defined');
+
+ // BIF
+ var bif = bifs[fn.name];
+ if (bif) this.warn('built-in function "' + fn.name + '" is already defined');
+
+ return fn;
+};
+
+/**
+ * Visit Each.
+ */
+
+Evaluator.prototype.visitEach = function(each){
+ var expr = utils.unwrap(this.visit(utils.unwrap(each.expr)))
+ , len = expr.nodes.length
+ , val = new nodes.Ident(each.val)
+ , key = new nodes.Ident(each.key || '__index__')
+ , scope = this.currentScope
+ , block = this.currentBlock
+ , vals = []
+ , body;
+
+ each.block.scope = false;
+ for (var i = 0; i < len; ++i) {
+ val.val = expr.nodes[i];
+ key.val = new nodes.Unit(i);
+ scope.add(val);
+ scope.add(key);
+ body = this.visit(each.block.clone());
+ vals = vals.concat(body.nodes);
+ }
+
+ this.mixin(vals, block);
+ return vals[vals.length - 1] || nodes.null;
+};
+
+/**
+ * Visit Call.
+ */
+
+Evaluator.prototype.visitCall = function(call){
+ var fn = this.lookup(call.name)
+ , ret;
+
+ // Variable function
+ if (fn && 'expression' == fn.nodeName) {
+ fn = fn.nodes[0];
+ }
+
+ // Not a function? try user-defined or built-ins
+ if (fn && 'function' != fn.nodeName) {
+ fn = this.lookupFunction(call.name);
+ }
+
+ // Undefined function, render literal css
+ if (!fn || fn.nodeName != 'function') return this.literalCall(call);
+ this.calling.push(call.name);
+
+ // Massive stack
+ if (this.calling.length > 200) {
+ throw new RangeError('Maximum call stack size exceeded');
+ }
+
+ // First node in expression
+ if (fn instanceof nodes.Expression) fn = fn.first;
+
+ // Evaluate arguments
+ var _ = this.return;
+ this.return = true;
+ var args = this.visit(call.args);
+ this.return = _;
+
+ // Built-in
+ if (fn.fn) {
+ ret = this.invokeBuiltin(fn.fn, args);
+ // User-defined
+ } else if (fn instanceof nodes.Function) {
+ ret = this.invokeFunction(fn, args);
+ }
+
+ this.calling.pop();
+ return ret;
+};
+
+/**
+ * Visit Ident.
+ */
+
+Evaluator.prototype.visitIdent = function(ident){
+ // Lookup
+ if (nodes.null == ident.val) {
+ var val = this.lookup(ident.name);
+ return val ? this.visit(val) : ident;
+ // Assign
+ } else {
+ var _ = this.return;
+ this.return = true;
+ ident.val = this.visit(ident.val);
+ this.return = _;
+ this.currentScope.add(ident);
+ return ident.val;
+ }
+};
+
+/**
+ * Visit BinOp.
+ */
+
+Evaluator.prototype.visitBinOp = function(binop){
+ // Special-case "is defined" pseudo binop
+ if ('is defined' == binop.op) return this.isDefined(binop.left);
+
+ var _ = this.return;
+ this.return = true;
+ // Visit operands
+ var op = binop.op
+ , ident = 'ident' == binop.left.nodeName
+ , left = this.visit(binop.left)
+ , right = this.visit(binop.right);
+ this.return = _;
+
+ // First node in expression
+ if (!~['[]', 'in'].indexOf(op)) {
+ left = left.first;
+ right = right.first;
+ }
+
+ // Coercion
+ switch (op) {
+ case '[]':
+ case 'in':
+ case '||':
+ case '&&':
+ case 'is a':
+ break;
+ default:
+ // Special-case '-' against ident
+ if ('-' == op
+ && 'ident' == left.nodeName
+ && 'unit' == right.nodeName) {
+ var expr = new nodes.Expression;
+ right.val = -right.val;
+ expr.push(left);
+ expr.push(right);
+ return expr;
+ }
+
+ // Attempt coercion
+ try {
+ right = left.coerce(right);
+ } catch (err) {
+ // Disgregard coercion issues
+ // and simply return false
+ if ('==' == op || '!=' == op) {
+ return nodes.false;
+ } else {
+ throw err;
+ }
+ }
+ }
+
+ // Operate
+ return this.visit(left.operate(op, right));
+};
+
+/**
+ * Visit UnaryOp.
+ */
+
+Evaluator.prototype.visitUnaryOp = function(unary){
+ var op = unary.op
+ , node = this.visit(unary.expr).first;
+
+ if ('!' != op) utils.assertType(node, nodes.Unit);
+
+ switch (op) {
+ case '-':
+ node.val = -node.val;
+ break;
+ case '+':
+ node.val = +node.val;
+ break;
+ case '~':
+ node.val = ~node.val;
+ break;
+ case '!':
+ return node.toBoolean().negate();
+ }
+
+ return node;
+};
+
+/**
+ * Visit TernaryOp.
+ */
+
+Evaluator.prototype.visitTernary = function(ternary){
+ var ok = this.visit(ternary.cond).toBoolean();
+ return nodes.true == ok
+ ? this.visit(ternary.trueExpr)
+ : this.visit(ternary.falseExpr);
+};
+
+/**
+ * Visit Expression.
+ */
+
+Evaluator.prototype.visitExpression = function(expr){
+ for (var i = 0, len = expr.nodes.length; i < len; ++i) {
+ expr.nodes[i] = this.visit(expr.nodes[i]);
+ }
+ return expr;
+};
+
+/**
+ * Visit Property.
+ */
+
+Evaluator.prototype.visitProperty = function(prop){
+ var name = this.interpolate(prop)
+ , fn = this.lookup(name)
+ , call = fn instanceof nodes.Function
+ , literal = ~this.calling.indexOf(name);
+
+ // Function of the same name
+ if (call && !literal && !prop.literal) {
+ this.calling.push(name);
+ var ret = this.visit(new nodes.Call(name, prop.expr));
+ this.calling.pop();
+ return ret;
+ // Regular property
+ } else {
+ var _ = this.return;
+ this.return = true;
+ prop.expr = this.visit(prop.expr);
+ prop.name = name;
+ prop.literal = true;
+ this.return = _;
+ return prop;
+ }
+};
+
+/**
+ * Visit Root.
+ */
+
+Evaluator.prototype.visitRoot = function(block){
+ for (var i = 0; i < block.nodes.length; ++i) {
+ block.index = this.rootIndex = i;
+ block.nodes[i] = this.visit(block.nodes[i]);
+ }
+ return block;
+};
+
+/**
+ * Visit Block.
+ */
+
+Evaluator.prototype.visitBlock = function(block){
+ this.stack.push(new Frame(block));
+ for (var i = 0; i < block.nodes.length; ++i) {
+ block.index = i;
+ try {
+ block.nodes[i] = this.visit(block.nodes[i]);
+ } catch (err) {
+ if (err instanceof nodes.Return) {
+ if (this.return) {
+ this.stack.pop();
+ throw err;
+ } else {
+ block.nodes[i] = err;
+ break;
+ }
+ } else {
+ throw err;
+ }
+ }
+ }
+ this.stack.pop();
+ return block;
+};
+
+/**
+ * Visit If.
+ */
+
+Evaluator.prototype.visitIf = function(node){
+ var ret
+ , _ = this.return
+ , block = this.currentBlock
+ , negate = node.negate;
+
+ this.return = true;
+ var ok = this.visit(node.cond).first.toBoolean();
+ this.return = _;
+
+ // Evaluate body
+ if (negate) {
+ // unless
+ if (nodes.false == ok) {
+ ret = this.visit(node.block);
+ }
+ } else {
+ // if
+ if (nodes.true == ok) {
+ ret = this.visit(node.block);
+ // else
+ } else if (node.elses.length) {
+ var elses = node.elses
+ , len = elses.length;
+ for (var i = 0; i < len; ++i) {
+ // else if
+ if (elses[i].cond) {
+ if (nodes.true == this.visit(elses[i].cond).first.toBoolean()) {
+ ret = this.visit(elses[i].block);
+ break;
+ }
+ // else
+ } else {
+ ret = this.visit(elses[i]);
+ }
+ }
+ }
+ }
+
+ // mixin conditional statements within a selector group
+ if (ret && !node.postfix && block.node && 'group' == block.node.nodeName) {
+ this.mixin(ret.nodes, block);
+ return nodes.null;
+ }
+
+ return ret || nodes.null;
+};
+
+/**
+ * Visit Import.
+ */
+
+Evaluator.prototype.visitImport = function(import){
+ var found
+ , root = this.root
+ , i = this.rootIndex
+ , stylus = require('../stylus')
+ , path = this.visit(import.path).first
+ , relative = this.importPath;
+
+ // Enusre string
+ if (!path.string) throw new Error('@import string expected');
+ var name = path = path.string;
+
+ // Literal
+ if (/\.css$/.test(path)) return import;
+ path += '.styl';
+
+ // Lookup
+ if (relative) this.paths.push(relative);
+ found = utils.lookup(path, this.paths, this.filename);
+ found = found || utils.lookup(name + '/index.styl', this.paths, this.filename);
+ if (relative) this.paths.pop();
+
+ // Expose imports
+ import.path = found;
+ if (this.options._imports) this.options._imports.push(import);
+
+ // Throw if import failed
+ if (!found) throw new Error('failed to locate @import file ' + path);
+ this.importPath = dirname(found);
+
+ // Parse the file
+ var str = fs.readFileSync(found, 'utf8')
+ , rest = root.nodes.splice(++i, root.nodes.length);
+
+ stylus.parse(str, {
+ filename: found
+ , root: root
+ });
+
+ rest.forEach(function(node){
+ root.push(node);
+ });
+
+ return nodes.null;
+};
+
+/**
+ * Invoke `fn` with `args`.
+ *
+ * @param {Function} fn
+ * @param {Array} args
+ * @return {Node}
+ * @api private
+ */
+
+Evaluator.prototype.invokeFunction = function(fn, args){
+ var block = new nodes.Block(fn.block.parent);
+ fn.block.parent = block;
+
+ // Clone the function body
+ // to prevent mutation of subsequent calls
+ // inject argument scope
+ var body = fn.block.clone();
+
+ // mixin block
+ var mixinBlock = this.stack.currentFrame.block;
+
+ // new block scope
+ this.stack.push(new Frame(block));
+ var scope = this.currentScope;
+
+ // arguments local
+ scope.add(new nodes.Ident('arguments', args));
+
+ // mixin scope introspection
+ scope.add(new nodes.Ident('mixin', this.return
+ ? nodes.false
+ : new nodes.String(mixinBlock.nodeName)));
+
+ // inject arguments as locals
+ fn.params.nodes.forEach(function(node, i){
+ // rest param support
+ if (node.rest) {
+ node.val = new nodes.Expression;
+ for (var len = args.nodes.length; i < len; ++i) {
+ node.val.push(args.nodes[i]);
+ }
+ node.val.preserve = true;
+ // argument default support
+ } else {
+ var arg = args.nodes[i];
+ var val = arg && !arg.isEmpty
+ ? args.nodes[i]
+ : node.val;
+ node = node.clone();
+ node.val = val;
+ // required argument not satisfied
+ if (node.val instanceof nodes.Null) {
+ throw new Error('argument ' + node + ' required for ' + fn);
+ }
+ }
+
+ scope.add(node);
+ });
+
+ // invoke
+ return this.invoke(body, true);
+};
+
+/**
+ * Invoke built-in `fn` with `args`.
+ *
+ * @param {Function} fn
+ * @param {Array} args
+ * @return {Node}
+ * @api private
+ */
+
+Evaluator.prototype.invokeBuiltin = function(fn, args){
+ // Map arguments to first node
+ // providing a nicer js api for
+ // BIFs. Functions may specify that
+ // they wish to accept full expressions
+ // via .raw
+ if (fn.raw) {
+ args = args.nodes;
+ } else {
+ args = args.nodes.map(function(node){
+ return node.first;
+ });
+ }
+
+ // Invoke the BIF
+ var body = fn.apply(this, args);
+
+ // Always wrapping allows js functions
+ // to return several values with a single
+ // Expression node
+ var expr = new nodes.Expression;
+ expr.push(body);
+ body = expr;
+
+ // Invoke
+ return this.invoke(body);
+};
+
+/**
+ * Invoke the given function `body`.
+ *
+ * @param {Block} body
+ * @return {Node}
+ * @api private
+ */
+
+Evaluator.prototype.invoke = function(body, stack){
+ var self = this
+ , ret;
+
+ // Return
+ if (this.return) {
+ ret = this.eval(body.nodes);
+ if (stack) this.stack.pop();
+ // Mixin
+ } else {
+ body = this.visit(body);
+ if (stack) this.stack.pop();
+ this.mixin(body.nodes, this.currentBlock);
+ ret = nodes.null;
+ }
+
+ return ret;
+};
+
+/**
+ * Mixin the given `nodes` to the given `block`.
+ *
+ * @param {Array} nodes
+ * @param {Block} block
+ * @api private
+ */
+
+Evaluator.prototype.mixin = function(nodes, block){
+ var len = block.nodes.length
+ , head = block.nodes.slice(0, block.index)
+ , tail = block.nodes.slice(block.index + 1, len);
+ this._mixin(nodes, head);
+ block.nodes = head.concat(tail);
+};
+
+/**
+ * Mixin the given `nodes` to the `dest` array.
+ *
+ * @param {Array} nodes
+ * @param {Array} dest
+ * @api private
+ */
+
+Evaluator.prototype._mixin = function(nodes, dest){
+ var node
+ , len = nodes.length;
+ for (var i = 0; i < len; ++i) {
+ switch ((node = nodes[i]).nodeName) {
+ case 'return':
+ return;
+ case 'block':
+ this._mixin(node.nodes, dest);
+ break;
+ default:
+ dest.push(node);
+ }
+ }
+};
+
+/**
+ * Evaluate the given `vals`.
+ *
+ * @param {Array} vals
+ * @return {Node}
+ * @api private
+ */
+
+Evaluator.prototype.eval = function(vals){
+ if (!vals) return nodes.null;
+ var len = vals.length
+ , node = nodes.null;
+
+ try {
+ for (var i = 0; i < len; ++i) {
+ node = vals[i];
+ switch (node.nodeName) {
+ case 'if':
+ if ('block' != node.block.nodeName) {
+ node = this.visit(node);
+ break;
+ }
+ case 'each':
+ case 'block':
+ node = this.visit(node);
+ if (node.nodes) node = this.eval(node.nodes);
+ break;
+ default:
+ node = this.visit(node);
+ }
+ }
+ } catch (err) {
+ if (err instanceof nodes.Return) {
+ return err.expr;
+ } else {
+ throw err;
+ }
+ }
+
+ return node;
+};
+
+/**
+ * Literal function `call`.
+ *
+ * @param {Call} call
+ * @return {call}
+ * @api private
+ */
+
+Evaluator.prototype.literalCall = function(call){
+ call.args = this.visit(call.args);
+ return call;
+};
+
+/**
+ * Lookup `name`, with support for JavaScript
+ * functions, and BIFs.
+ *
+ * @param {String} name
+ * @return {Node}
+ * @api private
+ */
+
+Evaluator.prototype.lookup = function(name){
+ var val;
+ if (val = this.stack.lookup(name)) {
+ return utils.unwrap(val);
+ } else {
+ return this.lookupFunction(name);
+ }
+};
+
+/**
+ * Map segments in `node` returning a string.
+ *
+ * @param {Node} node
+ * @return {String}
+ * @api private
+ */
+
+Evaluator.prototype.interpolate = function(node){
+ var self = this;
+ return node.segments.map(function(node){
+ function toString(node) {
+ switch (node.nodeName) {
+ case 'function':
+ case 'ident':
+ return node.name;
+ case 'literal':
+ case 'string':
+ case 'unit':
+ return node.val;
+ case 'expression':
+ var _ = self.return;
+ self.return = true;
+ var ret = toString(self.visit(node).first);
+ self.return = _;
+ return ret;
+ }
+ }
+ return toString(node);
+ }).join('');
+};
+
+/**
+ * Lookup JavaScript user-defined or built-in function.
+ *
+ * @param {String} name
+ * @return {Function}
+ * @api private
+ */
+
+Evaluator.prototype.lookupFunction = function(name){
+ var fn = this.functions[name] || bifs[name];
+ if (fn) return new nodes.Function(name, fn);
+};
+
+/**
+ * Check if the given `node` is an ident, and if it is defined.
+ *
+ * @param {Node} node
+ * @return {Boolean}
+ * @api private
+ */
+
+Evaluator.prototype.isDefined = function(node){
+ if (node instanceof nodes.Ident) {
+ return nodes.Boolean(this.lookup(node.name));
+ } else {
+ throw new Error('invalid "is defined" check on non-variable ' + node);
+ }
+};
+
+/**
+ * Warn with the given `msg`.
+ *
+ * @param {String} msg
+ * @api private
+ */
+
+Evaluator.prototype.warn = function(msg){
+ if (!this.warnings) return;
+ console.warn('\033[33mWarning:\033[0m ' + msg);
+};
+
+/**
+ * Return the current `Block`.
+ *
+ * @return {Block}
+ * @api private
+ */
+
+Evaluator.prototype.__defineGetter__('currentBlock', function(){
+ return this.stack.currentFrame.block;
+});
+
+/**
+ * Return the current frame `Scope`.
+ *
+ * @return {Scope}
+ * @api private
+ */
+
+Evaluator.prototype.__defineGetter__('currentScope', function(){
+ return this.stack.currentFrame.scope;
+});
+
+/**
+ * Return the current `Frame`.
+ *
+ * @return {Frame}
+ * @api private
+ */
+
+Evaluator.prototype.__defineGetter__('currentFrame', function(){
+ return this.stack.currentFrame;
+});
--- /dev/null
+
+/*!
+ * Stylus - Visitor
+ * Copyright(c) 2010 LearnBoost <dev@learnboost.com>
+ * MIT Licensed
+ */
+
+/**
+ * Initialize a new `Visitor` with the given `root` Node.
+ *
+ * @param {Node} root
+ * @api private
+ */
+
+var Visitor = module.exports = function Visitor(root) {
+ this.root = root;
+};
+
+/**
+ * Visit the given `node`.
+ *
+ * @param {Node|Array} node
+ * @api public
+ */
+
+Visitor.prototype.visit = function(node, fn){
+ var method = 'visit' + node.constructor.name
+ , cons = this.constructor.name;
+ if (this[method]) return this[method](node);
+ return node;
+};
+
--- /dev/null
+{ "name": "stylus"
+ , "description": "Robust, expressive language which compiles to CSS"
+ , "version": "0.9.2"
+ , "author": "TJ Holowaychuk <tj@vision-media.ca>"
+ , "keywords": ["css", "parser", "style", "stylesheets", "jade", "language"]
+ , "main": "./index.js"
+ , "engines": { "node": ">= 0.2.4" }
+ , "bin": {
+ "stylus": "./bin/stylus"
+ , "stylus-tutorial": "./bin/stylus-tutorial"
+ }
+ , "dependencies": {
+ "cssom": "0.2.0"
+ , "growl": "1.1.0"
+ }
+}
\ No newline at end of file
--- /dev/null
+body {
+ background: rgba(0,255,255,0.5);
+ color: #0c0;
+}
+a {
+ color: #808080;
+}
\ No newline at end of file
--- /dev/null
+
+body
+ background #fff - (rgba(250,0,0,0.5) + rgba(5,0,0,0))
+ color #ffcc00 - #f00
+
+a
+ color (#fff / 2)
\ No newline at end of file
--- /dev/null
+body {
+ font-size: 12px;
+}
+h1 {
+ font-size: 36px;
+}
+h2 {
+ font-size: 24px;
+ font: 2px;
+ font: 0px;
+ font: 16px;
+}
\ No newline at end of file
--- /dev/null
+
+size = 12px
+large = size * (3 - 1)
+huge = size * 3
+
+body
+ font-size size
+
+h1
+ font-size huge
+
+h2
+ font-size large
+ font 5px % 3
+ font 5px % 5
+ font 2px ** 4
+ y = 10
+ x = 15
\ No newline at end of file
--- /dev/null
+h1#logo {
+ margin-top: -15px;
+ margin-left: 3px;
+ foo: false;
+ foo: false;
+ foo: false;
+ foo: false;
+ foo: false;
+ foo: false;
+ foo: 0px -2px -3px;
+ foo: 1px;
+}
+body {
+ text-indent: -99999px;
+ background: #fff url("/some/image.png") no-repeat -29px 1px;
+}
\ No newline at end of file
--- /dev/null
+
+h1#logo
+ margin-top - - - 15px
+ margin-left ~ - 4px
+ foo !true
+ foo !!0
+ foo !-1
+ foo !99
+ foo !((99))
+ foo not not 0
+ foo 0px -2px -3px
+ foo -2px --3px
+
+body
+ text-indent -99999px
+ background #fff url('/some/image.png') no-repeat -29px 1px
--- /dev/null
+body {
+ background: 255;
+ background: 204;
+ background: 0;
+ background: 0.4;
+ background: 15deg;
+ background: 100%;
+ background: 60%;
+}
\ No newline at end of file
--- /dev/null
+body
+ background red(#fc0)
+ background green(#fc0)
+ background blue(#fc0)
+ background alpha(#fff - rgba(0,0,0,.6))
+
+ background hue(hsl(15deg,100%,60%))
+ background saturation(hsl(15deg,100%,60%))
+ background lightness(hsl(15deg,100%,60%))
\ No newline at end of file
--- /dev/null
+body {
+ foo: true;
+ foo: true;
+ foo: true;
+}
\ No newline at end of file
--- /dev/null
+body
+ foo dark(black) == true
+ foo dark(#005716) == true
+ foo dark(white) == false
--- /dev/null
+body {
+ background: #808080;
+ background: #404040;
+ background: #202020;
+}
\ No newline at end of file
--- /dev/null
+body
+ background: darken-by(white, 50%)
+ background: darken-by(darken-by(white, 50%), 50%)
+ background: darken-by(darken-by(darken-by(white, 50%), 50%), 50%)
\ No newline at end of file
--- /dev/null
+body {
+ foo: 315px 450px;
+ foo: true;
+ foo: true;
+}
+body {
+ foo: 400px 479px;
+ foo: 400px 479px;
+}
\ No newline at end of file
--- /dev/null
+
+width(img)
+ return image-size(img)[0]
+
+height(img)
+ return image-size(img)[1]
+
+body
+ foo image-size('gif')
+ foo image-size('gif')[0] == width('gif')
+ foo image-size('gif')[1] == height('gif')
+
+body
+ foo image-size('tux.png')
+ foo image-size('tux.png')
+/*
+body
+ foo image-size('jpeg')
+
--- /dev/null
+body {
+ foo: "1 2 3";
+ foo: "1, 2, 3";
+ foo: "1,2,3";
+ foo: "1";
+ foo: true;
+}
+body {
+ foo: "1, 2, 3";
+ foo: "one, two, three";
+}
\ No newline at end of file
--- /dev/null
+
+body
+ foo join(' ', 1 2 3)
+ foo join(', ', 1 2 3)
+ foo join(',', 1 2 3)
+ foo join(',', 1)
+ foo join(',') == null
+
+body
+ foo join(', ', 1, 2, 3)
+ foo join(', ', one 1, two 2, three 3)
\ No newline at end of file
--- /dev/null
+body {
+ foo: true;
+ foo: true;
+ foo: true;
+}
\ No newline at end of file
--- /dev/null
+
+body
+ nums = 1 2 3 4
+ foo last(nums) == 4
+ foo last(foo bar baz) == baz
+ foo last(()) == null
\ No newline at end of file
--- /dev/null
+body {
+ foo: 0;
+ foo: 1;
+ foo: 1;
+ foo: 2;
+ foo: 3;
+ foo: 4;
+ foo: 5;
+ foo: 6;
+}
\ No newline at end of file
--- /dev/null
+args(n = null)
+ length(n)
+
+vargs(args...)
+ length(args)
+
+arguments()
+ length(arguments)
+
+body
+ foo length()
+ foo length(args())
+ foo length(1)
+ foo length((1 2) (3 4))
+ foo length(1 2 3)
+ foo vargs(1, 2, 3, 4)
+ foo args(1 2 3 4 5)
+ foo arguments(1,2,3,4,5,6)
\ No newline at end of file
--- /dev/null
+body {
+ foo: true;
+ foo: true;
+ foo: true;
+}
\ No newline at end of file
--- /dev/null
+body
+ foo light(black) == false
+ foo light(white) == true
+ foo light(#00FF40) == true
\ No newline at end of file
--- /dev/null
+body {
+ background: #808080;
+ background: #bfbfbf;
+ background: #fff;
+ foo: #7fbfee;
+}
\ No newline at end of file
--- /dev/null
+body
+ background: lighten-by(black, 50%)
+ background: lighten-by(lighten-by(black, 50%), 50%)
+ background: lighten-by(lighten-by(lighten-by(black, 50%), 50%), 50%)
+ foo lighten(#52a8e8, 10%)
+ // => #7fbfee
--- /dev/null
+body {
+ color: #80e2e9;
+ border: 1px solid #f00;
+}
\ No newline at end of file
--- /dev/null
+
+border-type = solid
+dark-blue = #006269
+light-blue = dark-blue + hsl(0,0,50%)
+
+light(color-name)
+ lookup('light-' + color-name)
+
+body
+ color light('blue')
+ border 1px lookup('border-type') red
\ No newline at end of file
--- /dev/null
+body {
+ color: #006269;
+}
\ No newline at end of file
--- /dev/null
+
+dark-blue = #006269
+
+dark(color-name)
+ lookup('dark-' + color-name)
+
+body
+ color dark('blue')
\ No newline at end of file
--- /dev/null
+body {
+ margin: 5px;
+ padding: 5px;
+}
\ No newline at end of file
--- /dev/null
+pad(type = padding)
+ if match('^pad', type)
+ padding 5px
+ else
+ margin 5px
+
+body
+ pad(margin)
+ pad(padding)
--- /dev/null
+body {
+ foo: ;
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: bottom right;
+}
\ No newline at end of file
--- /dev/null
+
+body
+ foo opposite-position()
+ foo opposite-position(top) == bottom
+ foo opposite-position(left) == right
+ foo opposite-position(top left)[0] == bottom
+ foo opposite-position(top left)[1] == right
+ val = top left
+ foo opposite-position(val)
\ No newline at end of file
--- /dev/null
+body {
+ background: #ff0800;
+ background: rgba(255,255,0,0.2);
+ background: rgba(255,204,0,0.5);
+}
\ No newline at end of file
--- /dev/null
+body
+ background rgba(255,8,0,1)
+ background rgba(255,255,0,0.2)
+ background rgba(#fc0, 0.5)
\ No newline at end of file
--- /dev/null
+body {
+ background: "string";
+ background: "unit";
+ background: "unit";
+ background: "hsla";
+ background: "rgba";
+ background: "ident";
+ background: "unit";
+ background: "function";
+ background: "ident";
+}
\ No newline at end of file
--- /dev/null
+body
+ border-type = solid
+ size = 15px
+ background type('test')
+ background type(12px)
+ background type(12)
+ background type(hsl(100deg, 50%, 50%))
+ background type(#fff)
+ background type(something)
+ background type(size)
+ background type(type)
+ background type(border-type)
\ No newline at end of file
--- /dev/null
+body {
+ foo: 20px;
+ foo: 20px;
+ foo: 20px;
+ foo: 20%;
+}
\ No newline at end of file
--- /dev/null
+body
+ foo unit(20, 'px')
+ foo unit(20, px)
+ foo unit(20%, px)
+ foo unit(20, '%')
\ No newline at end of file
--- /dev/null
+body {
+ background: testing;
+ background: testing;
+ font: 14px / 1.5;
+}
\ No newline at end of file
--- /dev/null
+
+line-height(n)
+ unquote('/ ' + n)
+
+body
+ background unquote(testing)
+ background unquote('testing')
+ font 14px line-height(1.5)
--- /dev/null
+body {
+ background: url("/images/foo.png");
+ background: url("/images/foo.png");
+ background: url("/images/foo.png");
+ background: url("/images/foo.png");
+ background: url("/images/foo.png");
+ background: url("/images/foo.png");
+ background: url("/images/foo.png");
+ background: url("/images/foo.png");
+ background: url("http://foo.com/images/bar.png");
+}
\ No newline at end of file
--- /dev/null
+body
+ background url("/images/foo.png")
+ background url(/images/foo.png)
+
+ dir = '/images'
+ img = 'foo.png'
+ background url(dir/foo.png)
+ background url(dir/img)
+
+ background url('/images/' + img)
+ background url(dir'/foo.png')
+ background url(dir + '/foo.png')
+ background url(dir + '/' + img)
+
+ background url(http://foo.com/images/bar.png)
\ No newline at end of file
--- /dev/null
+body {
+ foo: 10px;
+ foo: 6px;
+ foo: "foo bar";
+ foo: "value: 5px";
+}
\ No newline at end of file
--- /dev/null
+body
+ foo 5px + '5'
+ foo 5px + '1 23'
+ foo 'foo ' + 'bar'
+ foo 'value: ' + 5px
\ No newline at end of file
--- /dev/null
+body {
+ color: #f00;
+}
+form {
+ background: #fff;
+}
+html>/**/body select,
+x:-moz-any-link,
+x:default select {
+ font-weight: bold !important;
+}
\ No newline at end of file
--- /dev/null
+
+// foo = 'bar'
+
+body
+ color red
+ // lots of stuff
+ // wahoo
+
+ // super cool
+
+ // background green
+
+form
+ background white
+
+/*
+
+body
+ a
+ color blue
+
+*/
+// rawr
+
+html>/**/body select
+x:-moz-any-link
+x:default select
+ font-weight bold !important
\ No newline at end of file
--- /dev/null
+body{foo:0;foo:0;foo:15;foo:-15;foo:15px;foo:-15px}
+body{foo:.1;foo:-.1;foo:1.1;foo:-1.1;foo:.1;foo:-.1;foo:10.1;foo:-10.1}
\ No newline at end of file
--- /dev/null
+body
+ foo 0
+ foo 0px
+ foo 15
+ foo -15
+ foo 15px
+ foo -15px
+
+body
+ foo 0.1
+ foo -0.1
+ foo 1.1
+ foo -1.1
+ foo 0.1
+ foo -0.1
+ foo 10.1
+ foo -10.1
+
\ No newline at end of file
--- /dev/null
+a.button {
+ font: 14px;
+ background: #fff;
+}
\ No newline at end of file
--- /dev/null
+
+color ?= white
+color ?= black
+
+font-size ?= 14px
+
+a.button
+ font font-size
+ background color
--- /dev/null
+body {
+ foo: false;
+ foo: true;
+}
+body {
+ foo: false;
+ foo: true;
+ foo: ;
+}
\ No newline at end of file
--- /dev/null
+
+large(n){ n > 100 }
+
+body
+ foo large(5)
+ foo large(300)
+
+large(n){ n > 100 if n is a 'unit' }
+
+body
+ foo large(5)
+ foo large(300)
+ foo large('test')
\ No newline at end of file
--- /dev/null
+body {
+ color: #fff;
+ color: #fff;
+}
+body {
+ padding: 5px;
+ margin: 5px;
+}
\ No newline at end of file
--- /dev/null
+
+body
+ if true {
+ color: white;
+ }
+ unless (false) {
+ color: white;
+ }
+
+mixin(pad, margin) {
+ if (pad) {
+ padding: 5px;
+ }
+ if (margin) {
+ margin: 5px;
+ }
+}
+
+body
+ mixin(true, true)
+
--- /dev/null
+@-webkit-keyframes bouce {
+ 0% {
+ foo: bar;
+ }
+
+ 50% {
+ foo: bar;
+ }
+
+ 100% {
+ foo: bar;
+ }
+}
+@-webkit-keyframes bouce {
+ 0% {
+ foo: bar;
+ }
+
+ 50% {
+ foo: bar;
+ }
+
+ 100% {
+ foo: bar;
+ }
+}
+@-webkit-keyframes bouce {
+ 0% {
+ foo: bar;
+ }
+
+ 50% {
+ foo: bar;
+ }
+
+ 100% {
+ foo: bar;
+ }
+}
+@-webkit-keyframes something {
+ 0% {
+ color: red;
+ }
+
+ 100% {
+ color: blue;
+ }
+}
\ No newline at end of file
--- /dev/null
+
+@keyframes bouce {
+ from {
+ foo: bar;
+ }
+
+ 50% {
+ foo: bar;
+ }
+
+ to {
+ foo: bar;
+ }
+}
+
+@keyframes bouce {
+ from { foo: bar; }
+ 50% { foo: bar; }
+ to { foo: bar; }
+}
+
+
+@keyframes bouce {
+ from { foo: bar; }
+
+
+ 50% { foo: bar; }
+
+ to { foo: bar; }
+}
+
+animate(name) {
+ @keyframes name {
+ from { color: red; }
+ to { color: blue; }
+ }
+}
+
+animate(something)
\ No newline at end of file
--- /dev/null
+html {
+ background: #dadada;
+ background: -moz-linear-gradient(-90deg, #fff, #dadada) fixed;
+ background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dadada)) fixed;
+}
+body {
+ padding: 120px 150px;
+ font: 14px / 1.4 "helvetica neue", helvetica, arial, sans-serif;
+ color: #484848;
+}
+h1,
+h2,
+h3 {
+ color: #222;
+}
+h1 a,
+h2 a,
+h3 a {
+ color: #222;
+}
+h1 a:hover,
+h2 a:hover,
+h3 a:hover {
+ text-decoration: none;
+}
+h1 {
+ margin: 10px 0 15px 0;
+ font-weight: bold;
+ font-size: 60px;
+}
+h2 {
+ margin: 0;
+ font-size: 18px;
+}
+h3 {
+ font-size: 14px;
+}
+a {
+ text-decoration: none;
+ color: #b90101;
+}
+a:hover {
+ text-decoration: underline;
+}
+strong {
+ color: #a00;
+}
+ul {
+ margin: 0;
+ padding: 0 25px;
+}
+ul li {
+ list-style: square;
+}
+.tagline {
+ margin: 0;
+ padding: 0;
+}
+.tagline em {
+ font-style: normal;
+}
+.tagline em.expressive {
+ color: #222;
+}
+.tagline em.dynamic {
+ color: #555;
+}
+.tagline em.robust {
+ color: #888;
+}
+.tagline em.css {
+ color: #bbb;
+}
+#container {
+ text-align: center;
+}
+#container #content {
+ margin: 0 auto;
+ padding-top: 40px;
+ width: 300px;
+ text-align: left;
+}
+#menu {
+ position: fixed;
+ top: -5px;
+ right: 60px;
+ margin: 0;
+ padding: 15px 0 10px 5px;
+ background: rgba(255,255,255,0.3);
+ border: 1px solid #ddd;
+ text-align: left;
+ -moz-box-shadow: inset rgba(34,34,34,0.1) 0 4px 4px;
+ -webkit-box-shadow: inset rgba(34,34,34,0.1) 0 4px 4px;
+ box-shadow: inset rgba(34,34,34,0.1) 0 4px 4px;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+}
+#menu li {
+ list-style: none;
+}
+#menu li a {
+ display: block;
+ width: 150px;
+ padding: 1px 10px;
+ color: #7b7b7b;
+ font-size: 13px;
+}
+#menu li a:hover {
+ color: #000;
+ text-decoration: none;
+}
+.example {
+ margin-top: 25px;
+}
+pre {
+ width: 300px;
+ padding: 30px;
+ color: #8d8d8d;
+ font: 12px / 1.4 monaco, "helvetica neue", helvetica;
+ overflow-x: auto;
+ background: #fff;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+ -moz-box-shadow: rgba(34,34,34,0.1) -1px -1px;
+ -webkit-box-shadow: rgba(34,34,34,0.1) -1px -1px;
+ box-shadow: rgba(34,34,34,0.1) -1px -1px;
+}
+pre.terminal {
+ width: 340px;
+ padding: 10px;
+ background: #2b2b2b;
+ color: #dadada;
+ -moz-box-shadow: #fff -1px -1px;
+ -webkit-box-shadow: #fff -1px -1px;
+ box-shadow: #fff -1px -1px;
+}
+p code {
+ padding: 2px 4px;
+ color: #626262;
+ font-size: 85%;
+ background: #fff;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+ -moz-box-shadow: rgba(34,34,34,0.1) -1px -1px;
+ -webkit-box-shadow: rgba(34,34,34,0.1) -1px -1px;
+ box-shadow: rgba(34,34,34,0.1) -1px -1px;
+}
+#ribbon {
+ position: absolute;
+ top: 2.5em;
+ left: -3.75em;
+ background-color: #a00;
+ padding: 1px 0;
+ overflow: hidden;
+ -webkit-transform: rotate(-45deg);
+ -moz-transform: rotate(-45deg);
+ -moz-box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
+ -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
+ box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
+}
+#ribbon a {
+ color: #fff;
+ border: 1px solid #f18585;
+ display: block;
+ margin: 0.05em 0;
+ padding: 0.5em 3.5em;
+ text-align: center;
+ text-decoration: none;
+}
\ No newline at end of file
--- /dev/null
+html {
+ background: #dadada;
+ background: -moz-linear-gradient(-90deg, #fff, #dadada) fixed;
+ background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dadada)) fixed;
+}
+body {
+ padding: 120px 150px;
+ font: 14px / 1.4 "helvetica neue", helvetica, arial, sans-serif;
+ color: #484848;
+}
+h1,
+h2,
+h3 {
+ color: #222;
+}
+h1 a,
+h2 a,
+h3 a {
+ color: #222;
+}
+h1 a:hover,
+h2 a:hover,
+h3 a:hover {
+ text-decoration: none;
+}
+h1 {
+ margin: 10px 0 15px 0;
+ font-weight: bold;
+ font-size: 60px;
+}
+h2 {
+ margin: 0;
+ font-size: 18px;
+}
+h3 {
+ font-size: 14px;
+}
+a {
+ text-decoration: none;
+ color: #b90101;
+}
+a:hover {
+ text-decoration: underline;
+}
+strong {
+ color: #a00;
+}
+ul {
+ margin: 0;
+ padding: 0 25px;
+}
+ul li {
+ list-style: square;
+}
+.tagline {
+ margin: 0;
+ padding: 0;
+}
+.tagline em {
+ font-style: normal;
+}
+.tagline em.expressive {
+ color: #222;
+}
+.tagline em.dynamic {
+ color: #555;
+}
+.tagline em.robust {
+ color: #888;
+}
+.tagline em.css {
+ color: #bbb;
+}
+#container {
+ text-align: center;
+}
+#container #content {
+ margin: 0 auto;
+ padding-top: 40px;
+ width: 300px;
+ text-align: left;
+}
+#menu {
+ position: fixed;
+ top: -5px;
+ right: 60px;
+ margin: 0;
+ padding: 15px 0 10px 5px;
+ background: rgba(255,255,255,0.3);
+ border: 1px solid #ddd;
+ text-align: left;
+ -moz-box-shadow: inset rgba(34,34,34,0.1) 0 4px 4px;
+ -webkit-box-shadow: inset rgba(34,34,34,0.1) 0 4px 4px;
+ box-shadow: inset rgba(34,34,34,0.1) 0 4px 4px;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+}
+#menu li {
+ list-style: none;
+}
+#menu li a {
+ display: block;
+ width: 150px;
+ padding: 1px 10px;
+ color: #7b7b7b;
+ font-size: 13px;
+}
+#menu li a:hover {
+ color: #000;
+ text-decoration: none;
+}
+.example {
+ margin-top: 25px;
+}
+pre {
+ width: 300px;
+ padding: 30px;
+ color: #8d8d8d;
+ font: 12px / 1.4 monaco, "helvetica neue", helvetica;
+ overflow-x: auto;
+ background: #fff;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+ -moz-box-shadow: rgba(34,34,34,0.1) -1px -1px;
+ -webkit-box-shadow: rgba(34,34,34,0.1) -1px -1px;
+ box-shadow: rgba(34,34,34,0.1) -1px -1px;
+}
+pre.terminal {
+ width: 340px;
+ padding: 10px;
+ background: #2b2b2b;
+ color: #dadada;
+ -moz-box-shadow: #fff -1px -1px;
+ -webkit-box-shadow: #fff -1px -1px;
+ box-shadow: #fff -1px -1px;
+}
+p code {
+ padding: 2px 4px;
+ color: #626262;
+ font-size: 85%;
+ background: #fff;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+ -moz-box-shadow: rgba(34,34,34,0.1) -1px -1px;
+ -webkit-box-shadow: rgba(34,34,34,0.1) -1px -1px;
+ box-shadow: rgba(34,34,34,0.1) -1px -1px;
+}
+#ribbon {
+ position: absolute;
+ top: 2.5em;
+ left: -3.75em;
+ background-color: #a00;
+ padding: 1px 0;
+ overflow: hidden;
+ -webkit-transform: rotate(-45deg);
+ -moz-transform: rotate(-45deg);
+ -moz-box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
+ -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
+ box-shadow: 1px 1px 3px rgba(0,0,0,0.3);
+}
+#ribbon a {
+ color: #fff;
+ border: 1px solid #f18585;
+ display: block;
+ margin: 0.05em 0;
+ padding: 0.5em 3.5em;
+ text-align: center;
+ text-decoration: none;
+}
--- /dev/null
+@media print {
+ body {
+ margin: 5px;
+ padding: 5px;
+ }
+}
+@media print {
+ body {
+ margin: 5px;
+ padding: 5px;
+ }
+ .no-print {
+ display: none;
+ }
+}
\ No newline at end of file
--- /dev/null
+
+@media print {
+ body {
+ margin: 5px;
+ padding: 5px;
+ }
+}
+
+@media print {
+ body {
+ margin: 5px;
+ padding: 5px;
+ }
+ .no-print {
+ display: none;
+ }
+}
\ No newline at end of file
--- /dev/null
+button,
+a.button {
+ display: block;
+ text-decoration: none;
+ background: #e3e3e3;
+ border: 1px solid #bdbdbd;
+ border-radius: 3px;
+ box-shadow: inset 0 0 1px 1px rgba(255,255,255,0.8);
+ color: #333;
+ font-family: "helvetica neue", helvetica, arial, sans-serif;
+ font-size: 12px;
+ font-weight: bold;
+ line-height: 1;
+ padding: 8px 0 9px;
+ text-align: center;
+ text-shadow: 0 1px 0 #fff;
+ width: 150px;
+}
+button:hover,
+a.button:hover {
+ background: #dbdbdb;
+ box-shadow: inset 0 0 1px 1px rgba(255,255,255,0.5);
+ color: #222;
+ cursor: pointer;
+}
+button:active,
+a.button:active {
+ background: #d6d6d6;
+ box-shadow: inset 0 0 1px 1px rgba(255,255,255,0.2);
+ color: #000;
+}
\ No newline at end of file
--- /dev/null
+
+/*
+ * Reset button related properties so that
+ * a, button, and input's are supported.
+ */
+
+-reset() {
+ display: block;
+ text-decoration: none;
+}
+
+// just testing stuff
+
+get-width() { 150px; }
+
+/*
+ * Minimalistic flat button with white inset.
+ */
+
+minimal-button(bg = #e3e3e3, intensity = 1) {
+ -reset();
+ background: bg;
+ border: 1px solid darken(bg, 15% * intensity);
+ border-radius: 3px;
+ box-shadow: inset 0 0 1px 1px rgba(white, 0.8 * intensity);
+ color: #333;
+ font-family: 'helvetica neue', helvetica, arial, sans-serif;
+ font-size: 12px;
+ font-weight: bold;
+ line-height: 1;
+ padding: 8px 0 9px;
+ text-align: center;
+ text-shadow: 0 1px 0 rgba(white, 1 * intensity);
+ width: get-width();
+
+ &:hover {
+ background: darken(bg, 3%);
+ box-shadow: inset 0 0 1px 1px rgba(white, 0.5 * intensity);
+ color: #222;
+ cursor: pointer;
+ }
+
+ &:active {
+ background: darken(bg, 5%);
+ box-shadow: inset 0 0 1px 1px rgba(white, 0.2 * intensity);
+ color: #000;
+ }
+}
+
+button,
+a.button {
+ minimal-button();
+}
\ No newline at end of file
--- /dev/null
+button,
+a.button {
+ display: block;
+ text-decoration: none;
+ background: #e3e3e3;
+ border: 1px solid #bdbdbd;
+ border-radius: 3px;
+ box-shadow: inset 0 0 1px 1px rgba(255,255,255,0.8);
+ color: #333;
+ font-family: "helvetica neue", helvetica, arial, sans-serif;
+ font-size: 12px;
+ font-weight: bold;
+ line-height: 1;
+ padding: 8px 0 9px;
+ text-align: center;
+ text-shadow: 0 1px 0 #fff;
+ width: 150px;
+}
+button:hover,
+a.button:hover {
+ background: #dbdbdb;
+ box-shadow: inset 0 0 1px 1px rgba(255,255,255,0.5);
+ color: #222;
+ cursor: pointer;
+}
+button:active,
+a.button:active {
+ background: #d6d6d6;
+ box-shadow: inset 0 0 1px 1px rgba(255,255,255,0.2);
+ color: #000;
+}
\ No newline at end of file
--- /dev/null
+button,
+a.button,
+input[type=submit],
+input[type=button] {
+ padding: 5px 10px;
+}
+button:hover,
+a.button:hover,
+input[type=submit]:hover,
+input[type=button]:hover {
+ color: #fff;
+ background: #000;
+}
+button:hover em,
+a.button:hover em,
+input[type=submit]:hover em,
+input[type=button]:hover em {
+ color: #808080;
+}
+button:active,
+a.button:active,
+input[type=submit]:active,
+input[type=button]:active {
+ color: #000;
+ background: #fff;
+}
\ No newline at end of file
--- /dev/null
+
+hover()
+ &:hover {
+ color: white;
+ background: black;
+ em {
+ color: gray;
+ }
+ }
+ &:active {
+ color: black;
+ background: white;
+ }
+
+
+button(pad)
+ button,
+ a.button,
+ input[type=submit],
+ input[type=button] {
+ padding: pad;
+ hover();
+ }
+
+button(5px 10px);
\ No newline at end of file
--- /dev/null
+button,
+a.button,
+input[type=submit],
+input[type=button] {
+ padding: 5px 10px;
+}
+button:hover,
+a.button:hover,
+input[type=submit]:hover,
+input[type=button]:hover {
+ color: #fff;
+ background: #000;
+}
+button:hover em,
+a.button:hover em,
+input[type=submit]:hover em,
+input[type=button]:hover em {
+ color: #808080;
+}
+button:active,
+a.button:active,
+input[type=submit]:active,
+input[type=button]:active {
+ color: #000;
+ background: #fff;
+}
\ No newline at end of file
--- /dev/null
+
+hover()
+ &:hover { color: white; background: black;
+ em {
+ color: gray;
+ }
+ }
+ &:active { color: black; background: white; }
+
+
+button(pad)
+ button,
+ a.button,
+ input[type=submit],
+ input[type=button] { padding: pad; hover(); }
+
+button(5px 10px);
\ No newline at end of file
--- /dev/null
+
+/*
+ * Reset button related properties so that
+ * a, button, and input's are supported.
+ */
+
+-reset()
+ display: block;
+ text-decoration: none;
+
+/*
+ * Minimalistic flat button with white inset.
+ */
+
+minimal-button(bg = #e3e3e3, intensity = 1)
+ -reset()
+ background: bg;
+ border: 1px solid darken(bg, 15% * intensity);
+ border-radius: 3px;
+ box-shadow: inset 0 0 1px 1px rgba(white, 0.8 * intensity);
+ color: #333;
+ font-family: 'helvetica neue', helvetica, arial, sans-serif;
+ font-size: 12px;
+ font-weight: bold;
+ line-height: 1;
+ padding: 8px 0 9px;
+ text-align: center;
+ text-shadow: 0 1px 0 rgba(white, 1 * intensity);
+ width: 150px;
+
+ &:hover {
+ background: darken(bg, 3%);
+ box-shadow: inset 0 0 1px 1px rgba(white, 0.5 * intensity);
+ color: #222;
+ cursor: pointer;
+ }
+
+ &:active {
+ background: darken(bg, 5%);
+ box-shadow: inset 0 0 1px 1px rgba(white, 0.2 * intensity);
+ color: #000;
+ }
+
+button,
+a.button {
+ minimal-button();
+}
\ No newline at end of file
--- /dev/null
+body {
+ margin: 0;
+ padding: 5px;
+}
+body ul {
+ margin: 0;
+}
+body ul li:first-child {
+ border-top: none;
+}
+body ul li:last-child {
+ border-bottom: none;
+}
+ul li:first-child,
+ul li:last-child {
+ display: none;
+}
+foo {
+ border-radius: 5px;
+}
+foo bar baz {
+ border-radius: 5px;
+}
+foo,
+bar,
+baz {
+ border-radius: 5px;
+}
+input[type=button] {
+ border-radius: 5px;
+}
+button,
+input[type=button],
+input[type=submit],
+a.button {
+ border-radius: 5px;
+}
\ No newline at end of file
--- /dev/null
+
+body {
+ margin: 0;
+ padding: 5px;
+ ul {
+ /* test */
+ margin: 0;
+ li:first-child {
+ border-top: none;
+ // test
+ }
+ // test
+ li:last-child {
+ border-bottom: none;
+ }
+ }
+}
+
+ul {
+ li {
+ &:first-child,
+ &:last-child {
+ display: none;
+ }
+ }
+}
+
+
+foo {
+ border-radius: 5px;
+}
+
+foo bar baz {
+ border-radius: 5px;
+}
+
+foo
+bar
+baz {
+ border-radius: 5px;
+}
+
+input[type=button] {
+ border-radius: 5px;
+}
+
+
+button
+input[type=button]
+input[type=submit]
+a.button {
+ border-radius: 5px;
+}
\ No newline at end of file
--- /dev/null
+body {
+ padding: 5px;
+}
+body {
+ padding: 5px;
+}
+body {
+ padding: 5px;
+ margin: 0;
+}
+body {
+ padding: 5px;
+ margin: 0;
+}
+body {
+ padding: 5px;
+ margin: 0;
+}
+body {
+ padding: 5px;
+ margin: 0;
+}
+body {
+ padding: 5px;
+}
+ul li {
+ padding: 5px;
+}
+body {
+ padding: 5px;
+}
+body {
+ padding: 5px;
+}
+input {
+ foo: "bar";
+}
\ No newline at end of file
--- /dev/null
+
+body
+ padding 5px
+
+body
+ padding 5px
+
+body
+ padding: 5px; margin: 0;
+
+body
+ padding: 5px;
+ margin: 0;
+
+body {
+ padding: 5px;
+ margin: 0;
+}
+
+body {
+ padding: 5px; margin: 0;
+}
+
+body {
+padding: 5px;
+}
+
+ul {
+ li {
+ padding: 5px;
+}
+}
+
+
+body{padding: 5px;}
+body{padding: 5px}input{foo:'bar'}
--- /dev/null
+body {
+ font: 14px + 1.2;
+ border-radius: 5px 2px ( 5px 1px;
+}
\ No newline at end of file
--- /dev/null
+
+body
+ font 14px \+ 1.2
+ border-radius 5px 2px \( 5px 1px
--- /dev/null
+body {
+ foo: a;
+ foo: b;
+ foo: c;
+ foo: d;
+ foo: e;
+ foo: f;
+ foo: g;
+}
+body {
+ foo: a;
+}
+body {
+ foo: 0 : b;
+ foo: 1 : c;
+ foo: 2 : d;
+}
+body {
+ foo: error test "test";
+ foo: error test "foo";
+}
+body {
+ foo: 0 a;
+ foo: 1 a;
+ foo: 2 a;
+ foo: 3 a;
+ foo: 0 b;
+ foo: 1 b;
+ foo: 2 b;
+ foo: 3 b;
+ foo: 0 c;
+ foo: 1 c;
+ foo: 2 c;
+ foo: 3 c;
+ foo: 0 d;
+ foo: 1 d;
+ foo: 2 d;
+ foo: 3 d;
+}
+body {
+ foo: helvetica;
+ foo: arial;
+ foo: sans-serif;
+}
\ No newline at end of file
--- /dev/null
+vals = a b c d e f g
+
+body
+ for val in vals
+ foo val
+
+body
+ for val in vals[0]
+ foo val
+
+body
+ for val, i in vals[1..3]
+ foo i unquote(':') val
+
+body
+ for msg in (error 'test') (error 'foo')
+ foo msg[0] test msg[1]
+
+body
+ for char in a b c d
+ for num in 0 1 2 3
+ foo num char
+
+fonts = helvetica, arial, sans-serif
+
+body
+ for font in fonts
+ foo font
--- /dev/null
+body {
+ test-args: 1 2 3;
+ foo: 1;
+ foo: 2;
+ foo: 3;
+ test-args: 1 2 3 4 5;
+ foo: 1 2;
+ foo: 3 4;
+ foo: 5;
+ test-args: 1 2 3 4;
+ foo: 1 2;
+ foo: 3 4;
+}
+body {
+ foo: 1 2;
+ foo: 3 4;
+}
+body {
+ foo: 1;
+ foo: 2;
+ foo: 3;
+ foo: 4;
+ foo: 5;
+}
+body {
+ foo: 1;
+ foo: 2;
+ foo: 3;
+}
+body foo {
+ bar: 1;
+}
+body foo {
+ bar: 2;
+}
+body foo {
+ bar: 3;
+}
+body foo bar {
+ baz: 1;
+}
+body foo bar {
+ baz: 2;
+}
+body foo bar {
+ baz: 3;
+}
+body {
+ foo: 0 foo;
+ foo: 1 bar;
+ foo: 2 baz;
+}
\ No newline at end of file
--- /dev/null
+body {
+ foo: 10;
+ foo: 20;
+ foo: 10;
+}
+body {
+ foo: "foo bar baz";
+ foo: "foo, bar, baz";
+ foo: "1 2 3";
+ foo: "1, 2, 3";
+}
+body {
+ foo: 0 Impact;
+ foo: 1 Arial;
+ foo: 2 sans-serif;
+}
+body {
+ foo: 24;
+ foo: 30;
+}
\ No newline at end of file
--- /dev/null
+
+sum(nums...)
+ sum = 0
+ for n in nums
+ sum += n
+
+sum2(nums...)
+ sum = 0
+ for n in nums
+ sum += n
+ sum * 2
+
+sum3(nums...)
+ sum = 0
+ sum += n for n in nums
+
+body
+ foo sum(1,2,3,4)
+ foo sum2(1,2,3,4)
+ foo sum3(1,2,3,4)
+
+join(delim, args)
+ buf = ''
+ for arg, i in args
+ buf += i ? delim + arg : arg
+
+join2(delim, args)
+ buf = ''
+ buf += i ? delim + arg : arg for arg, i in args
+
+body
+ foo join(' ', foo bar baz)
+ foo join(', ', foo bar baz)
+ foo join2(' ', 1 2 3)
+ foo join2(', ', 1 2 3)
+
+body
+ fonts = Impact Arial sans-serif
+ for font, i in fonts
+ foo i font
+
+last-even(nums...)
+ ret = n if n % 2 == 0 for n in nums
+ ret
+
+first-even(nums...)
+ return n if n % 2 == 0 for n in nums
+
+body
+ foo last-even(1,3,30,5,6,12,2,24,3)
+ foo first-even(1,3,30,5,6,12,2,24,3)
\ No newline at end of file
--- /dev/null
+
+test(args...)
+ test-args args
+ for arg in args
+ foo arg
+
+size(a, b)
+ return a b
+
+body
+ test 1 2 3
+ test (1 2) (3 4) 5
+ test size(1, 2) size(3, 4)
+
+body
+ sizes = size(1, 2) size(3, 4)
+ for size in sizes
+ foo size
+
+body
+ for n in 1..5
+ foo n
+
+body
+ for n in 1 2 3
+ foo n
+
+body
+ for n in 1 2 3
+ foo
+ bar n
+
+test(args...)
+ foo
+ for arg in args
+ bar
+ baz arg
+
+body
+ test 1 2 3
+
+body
+ for val, index in foo bar baz
+ foo index val
\ No newline at end of file
--- /dev/null
+body {
+ padding: 15;
+ padding: 1 2;
+}
\ No newline at end of file
--- /dev/null
+
+sum()
+ n = 0
+ for num in arguments
+ n = n + num
+ n
+
+test(a, b)
+ a = b
+ (arguments[0] a)
+
+body
+ padding sum(1,2,3,4,5)
+ padding test(1,2)
\ No newline at end of file
--- /dev/null
+body {
+ foo: bar(1px, baz(5px));
+ bar: baz(5px) baz(5px);
+ foo: recurse;
+ foo: recurse;
+}
\ No newline at end of file
--- /dev/null
+
+something(arg)
+ bar arg arg
+
+recurse()
+ foo recurse
+ foo recurse
+
+body
+ foo bar(1px, baz(5px))
+ something(baz(5px))
+ recurse()
\ No newline at end of file
--- /dev/null
+form input {
+ padding: 10px 5px 10px 5px;
+}
\ No newline at end of file
--- /dev/null
+add(a, b)
+ a + b
+
+pad(x, y = x)
+ padding y x y x
+
+form input
+ n = 5
+ pad(5px, unit(add(n, n), 'px'))
\ No newline at end of file
--- /dev/null
+body {
+ foo: 15;
+ foo: 7;
+}
\ No newline at end of file
--- /dev/null
+
+add(a, b)
+ a + b
+
+body
+ foo add(5, 10)
+ foo add(5, 2)
--- /dev/null
+body {
+ padding: 10px 5px 10px 5px;
+}
+form .button {
+ padding-left: 15px;
+}
+body {
+ foo: bottom;
+ foo: right;
+ foo: bottom right;
+}
\ No newline at end of file
--- /dev/null
+body {
+ padding: 15px 5px 15px 5px;
+}
+a.button {
+ padding: 10px 10px 10px 10px;
+}
+a.button-2 {
+ padding: 2px 10px 2px 10px;
+}
+body {
+ padding: 10px;
+}
+.button {
+ padding: 5px;
+}
\ No newline at end of file
--- /dev/null
+
+size = 15px
+small = 5
+
+pad-var(x, y = size)
+ padding y x y x
+
+pad-arg(x, y = x)
+ padding y x y x
+
+body
+ pad-var(5px)
+
+a.button
+ pad-arg(10px)
+
+a.button-2
+ pad-arg(10px, 2px)
+
+add(a, b)
+ a + b
+
+pad-call(n = unit(add(small, small), 'px'))
+ padding n
+
+body
+ pad-call()
+
+.button
+ pad-call(5px)
\ No newline at end of file
--- /dev/null
+body {
+ padding: 2 1;
+}
+body {
+ padding: 2 1;
+}
+body {
+ padding: 3 2;
+}
\ No newline at end of file
--- /dev/null
+
+pad(
+ x = 5
+, y = 10
+)
+ padding y x
+
+body
+ pad 1 2
+
+pad(
+ x = 5
+ , y = 10
+)
+ padding y x
+
+body
+ pad 1 2
+
+body
+ pad(x
+ , y
+ )
+ padding y x
+ pad 2 3
\ No newline at end of file
--- /dev/null
+body {
+ padding: 5px;
+ padding: 100px;
+ padding: 10px;
+ padding: 1px;
+ padding: 100px;
+}
+form {
+ padding-left: 5px;
+ padding-right: 5px;
+ padding-top: 10px;
+ padding-bottom: 10px;
+}
\ No newline at end of file
--- /dev/null
+
+pad(y = 100px)
+ padding unit(y, 'px')
+
+body
+ pad(5px)
+ pad()
+ pad(10px)
+ pad(1)
+ pad()
+
+pad-x(n)
+ n = unit(n, 'px')
+ padding-left n
+ padding-right n
+
+pad-y(y)
+ padding-top n = unit(y, 'px')
+ padding-bottom n
+
+pad(x, y)
+ pad-x(x)
+ pad-y(y)
+
+form
+ pad(5, 10)
\ No newline at end of file
--- /dev/null
+body {
+ foo: 13;
+}
\ No newline at end of file
--- /dev/null
+
+sub(a, b)
+ a - b
+
+add(a, b)
+ a + b
+
+body
+ foo add(5, add(5, sub(5, 2)))
--- /dev/null
+body {
+ padding: 3.5;
+}
+body {
+ padding: 3.5;
+}
+body {
+ padding: 10;
+ padding: 0;
+}
\ No newline at end of file
--- /dev/null
+
+add(a, b)
+ div(a, b)
+ a / b
+ a + div(b, 2)
+
+body
+ padding add(1,5)
+ // => 3.5
+
+add(a, b)
+ half()
+ b / 2
+ a + half()
+
+body
+ padding add(1,5)
+ // => 3.5
+
+getFunction(name)
+ if name == 'add'
+ add(a, b)
+ a + b
+ else
+ sub(a, b)
+ a - b
+
+body
+ fn = getFunction('add')
+ padding fn(5, 5)
+ // => 10
+
+ fn = getFunction('sub')
+ fn2 = fn
+ fn3 = fn2
+ padding fn3(5, 5)
+ // => 0
\ No newline at end of file
--- /dev/null
+form {
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+}
+a.button {
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+}
\ No newline at end of file
--- /dev/null
+
+border-radius(size)
+ -webkit-border-radius size
+ -moz-border-radius size
+ border-radius size
+
+form
+ border-radius 5px
+
+a.button
+ border-radius 5px
\ No newline at end of file
--- /dev/null
+body {
+ foo: no;
+ foo: yes;
+ foo: false;
+ foo: yes;
+ foo: "a is not a unit";
+ foo: 2;
+}
+body {
+ foo: five;
+ foo: something;
+}
+body {
+ foo: 3;
+}
\ No newline at end of file
--- /dev/null
+body {
+ foo: "1 2 3";
+ foo: "1, 2, 3";
+ foo: "1,2,3";
+}
+body {
+ foo: "1 2 3";
+ foo: "1, 2, 3";
+ foo: "1,2,3";
+}
\ No newline at end of file
--- /dev/null
+
+join1(delim, vals)
+ buf = ''
+ for val, i in vals
+ if i
+ buf += delim + val
+ else
+ buf += val
+
+join2(delim, vals)
+ buf = ''
+ for val, i in vals
+ buf += i ? delim + val : val
+
+body
+ foo join1(' ', 1 2 3)
+ foo join1(', ', 1 2 3)
+ foo join1(',', 1 2 3)
+
+body
+ foo join2(' ', 1 2 3)
+ foo join2(', ', 1 2 3)
+ foo join2(',', 1 2 3)
\ No newline at end of file
--- /dev/null
+
+large(n)
+ unless n is a 'unit'
+ return false
+ if n > 100
+ yes
+ else
+ no
+
+awesome()
+ yes
+
+nested(a = 5)
+ if a is a 'unit'
+ b = 10
+ if a
+ c = 100
+ c = 100
+ c = 100
+ c = 100
+ awesome()
+ else
+ 'b is not a unit'
+ else
+ 'a is not a unit'
+
+set()
+ 1
+ return 2
+ 3
+
+body
+ // no
+ foo large(15)
+
+ // yes
+ foo large(150)
+
+ // false
+ foo large('string')
+
+ // yes
+ foo nested()
+
+ // 'a is not a unit'
+ foo nested('wahoo')
+
+ // 2
+ foo set()
+
+deep-implicit()
+ one
+ if false
+ two
+ else
+ if true
+ something
+ three
+ else
+ four
+ five
+
+deep-explicit()
+ one
+ if false
+ two
+ else
+ if true
+ return something
+ three
+ else
+ four
+ five
+
+body
+ foo deep-implicit()
+ foo deep-explicit()
+
+test()
+ return 1 if false
+ return 2 if false
+ return 3 if true
+ return 4
+
+body
+ foo test()
\ No newline at end of file
--- /dev/null
+
+add(a, b)
+ a + b
+
+pad(x, y)
+ padding y x y x
+
+body
+ pad(5px, 10px)
+
+form .button
+ padding-left add(10px, 5px)
+
+-opposite-position(pos)
+ if pos == top
+ bottom
+ else if pos == bottom
+ top
+ else if pos == left
+ right
+ else if pos == right
+ left
+ else
+ error('Invalid position ' + pos)
+
+opposite(positions)
+ for pos in positions
+ pos = -opposite-position(pos)
+ ret = ret is defined ? ret pos : pos
+
+body
+ foo opposite(top)
+ foo opposite(left)
+ foo opposite(top left)
--- /dev/null
+body {
+ font: 28px;
+ padding-left: 5px;
+ padding-right: 5px;
+}
+form {
+ padding-top: 10px;
+ padding-bottom: 10px;
+}
\ No newline at end of file
--- /dev/null
+body {
+ font: 28px;
+}
\ No newline at end of file
--- /dev/null
+
+add(a, b)
+ a + b
+
+size-function = add
+
+size(n)
+ size-function(n, n)
+
+body
+ font size(14px)
\ No newline at end of file
--- /dev/null
+
+add(a, b)
+ a + b
+
+size-function = add
+
+size(n)
+ size-function(n, n)
+
+padding-x(n)
+ padding-left n
+ padding-right n
+
+padding-y(n)
+ padding-top n
+ padding-bottom n
+
+mixin(name, n)
+ name(n)
+
+body
+ fn = padding-x
+ font size(14px)
+ fn(5px)
+
+form
+ mixin(padding-y, 10px)
\ No newline at end of file
--- /dev/null
+body {
+ padding: 100;
+}
+body {
+ padding: false;
+}
+body {
+ padding: 150;
+}
+body {
+ padding: 75;
+}
+body {
+ padding: -1;
+}
+body {
+ padding: 1;
+}
+body {
+ foo: yes;
+ foo: no;
+ foo: zero;
+ foo: invalid;
+}
+body .input {
+ padding: 5px;
+ no: margin;
+}
+body form input {
+ foo: no;
+ foo: bar;
+ bar: baz;
+}
+body something {
+ foo: bar;
+ bar: baz;
+}
+body .nested {
+ foo: bar;
+}
+body .nested .hidden {
+ display: none;
+}
\ No newline at end of file
--- /dev/null
+body {
+ foo: string;
+ foo: unit;
+ foo: color;
+ foo: unknown;
+}
\ No newline at end of file
--- /dev/null
+
+naive-type(val = null)
+ if val is a 'unit'
+ unit
+ else if val is a 'color'
+ color
+ else if val is a 'string'
+ string
+ else
+ unknown
+
+body
+ foo naive-type('test')
+ foo naive-type(12)
+ foo naive-type(#fff)
+ foo naive-type()
--- /dev/null
+body {
+ got: above;
+ got: below;
+ got: empty;
+ yup: just lots of empty;
+ padding: 10px;
+}
\ No newline at end of file
--- /dev/null
+
+test(n)
+ if n < 0
+ got below
+ else
+ got above
+
+test-nested(a, b)
+ if a > 1
+ if unit(-5) == ''
+ got empty
+ yup just lots of empty
+ else
+ got unit(-5px)
+
+test-unless(n = 0)
+ unless n
+ padding 10px
+
+body
+ test(5px)
+ test(-5px)
+ test-nested(5px, -5)
+ test-unless()
--- /dev/null
+body {
+ foo: 1;
+ foo: 2;
+ foo: 3;
+ foo: 4;
+ foo: 5;
+ foo: 6;
+ foo: 7;
+}
+body {
+ foo: 3;
+}
+body {
+ foo: true;
+ foo: true;
+}
+body {
+ foo: true;
+ foo: true;
+}
+body {
+ foo: 5;
+}
+body {
+ foo: bar;
+ foo: baz;
+}
+body {
+ foo: bar;
+ foo: baz;
+}
+@import "foo.css";
+body {
+ foo: 5;
+}
+body {
+ foo: string;
+ foo: number;
+ foo: unknown;
+}
+body {
+ foo: true;
+ foo: true;
+ foo: false;
+}
+body {
+ fonts: arial, sans-serif;
+}
+body {
+ foo: yes;
+ foo: yes;
+ foo: yes;
+ foo: ;
+ foo: ;
+}
+body {
+ foo: yes;
+ foo: no;
+ foo: zero;
+ foo: invalid;
+}
\ No newline at end of file
--- /dev/null
+
+mixin()
+ if true
+ foo 6
+ foo 7 if true
+ foo 8 unless true
+
+body
+ foo 1
+ foo 2 if true
+ foo 3 unless false
+ if true
+ foo 4
+ foo 5
+ mixin()
+
+body
+ foo 1 if false
+ foo 2 unless true
+ foo 3
+
+above-5(n)
+ true if n > 5
+
+body
+ foo above-5(2) == null
+ foo above-5(6) == true
+
+below-5(n)
+ return true unless n > 5
+ false
+
+body
+ foo below-5(3) == true
+ foo below-5(7) == false
+
+body
+ foo 5 unless 5 + 5 == 10
+
+body
+ foo 5 if 5 + 5 == 10 and true
+
+mixin()
+ foo bar
+ foo baz
+
+body
+ mixin() if true
+ mixin() unless true
+
+body
+ mixin test if true
+
+
+@import 'foo.css' if true
+@charset 'foo' if false
+
+num = 5 unless num is defined
+
+body
+ foo num
+
+type(arg = null)
+ return string if arg is a 'string'
+ return number if arg is a 'unit'
+ unknown
+
+body
+ foo type('test')
+ foo type(12)
+ foo type()
+
+is-a-string(arg = null)
+ arg is a 'string' unless arg == null
+
+body
+ foo is-a-string() == null
+ foo is-a-string('test')
+ foo is-a-string(12) if true
+
+empty(expr)
+ 0 == length(expr)
+
+font-list = arial, sans-serif
+body
+ fonts font-list unless empty(font-list)
+ font-list = ()
+ fonts font-list unless empty(font-list)
+
+truthy(val)
+ yes if 1 == val or 'yes' == val or 'y' == val
+
+body
+ foo truthy(1)
+ foo truthy('yes')
+ foo truthy('y')
+ foo truthy(0)
+ foo truthy('no')
+
+negative(n)
+ return invalid unless n is a 'unit'
+ return yes if n < 0
+ return no if n > 0
+ zero
+
+body
+ foo negative(-5)
+ foo negative(5)
+ foo negative(0)
+ foo negative('asdf')
\ No newline at end of file
--- /dev/null
+form input {
+ border: 1px solid #eee;
+}
+body {
+ font: 12px;
+}
\ No newline at end of file
--- /dev/null
+
+if false
+ something
+ with a-prop
+
+if true
+ form
+ input
+ border 1px solid #eee
+ if true
+ body
+ font 12px
\ No newline at end of file
--- /dev/null
+n = false
+
+if !n
+ n = 100
+
+body
+ padding n
+
+n = false
+
+if not not n
+ n = 50
+
+body
+ padding n
+
+if not n
+ n = 150
+
+body
+ padding n
+
+if n
+ n = n / 2
+else
+ n = 10000
+
+body
+ padding n
+
+if n > 100
+ n = n * 2
+else
+ n = -1
+
+body
+ padding n
+
+n = 75
+
+if n < 50
+ n = n
+else
+ if n > 50 and n < 100
+ n = 1
+ else
+ n = -1
+
+body
+ padding n
+
+negative(n)
+ unless n is a 'unit'
+ return invalid
+ if n < 0
+ yes
+ else if n > 0
+ no
+ else
+ zero
+
+body
+ foo negative(-5)
+ foo negative(5)
+ foo negative(0)
+ foo negative('asdf')
+
+body
+ .input
+ pad = true
+ margin = false
+ if pad
+ padding 5px
+ if margin
+ margin 5px
+ else
+ no unquote('margin')
+
+mixin()
+ foo bar
+ bar baz
+
+body
+ form input
+ if true
+ foo negative(5)
+ mixin()
+ something
+ mixin()
+
+body
+ .nested
+ if true
+ if true
+ if true
+ foo bar
+ .hidden
+ if true
+ display none
\ No newline at end of file
--- /dev/null
+.a {
+ color: #f00;
+}
+.b {
+ color: #008000;
+}
+.c {
+ color: #00f;
+}
\ No newline at end of file
--- /dev/null
+
+@import "a"
--- /dev/null
+
+.a
+ color red
+
+@import "b"
\ No newline at end of file
--- /dev/null
+
+.b
+ color green
+
+@import "c"
\ No newline at end of file
--- /dev/null
+
+.c
+ color blue
\ No newline at end of file
--- /dev/null
+one {
+ foo: bar;
+}
+two {
+ foo: bar;
+}
+three {
+ foo: bar;
+}
\ No newline at end of file
--- /dev/null
+@import "./import.complex/a"
\ No newline at end of file
--- /dev/null
+one
+ foo bar
+
+@import "./nested/b"
\ No newline at end of file
--- /dev/null
+three
+ foo bar
\ No newline at end of file
--- /dev/null
+two
+ foo bar
+
+@import "../c"
\ No newline at end of file
--- /dev/null
+body {
+ one: 1;
+}
+body {
+ two: 2;
+}
+body {
+ three: 3;
+}
\ No newline at end of file
--- /dev/null
+
+@import 'import.index/vendor'
\ No newline at end of file
--- /dev/null
+body
+ one 1
\ No newline at end of file
--- /dev/null
+body
+ two 2
\ No newline at end of file
--- /dev/null
+body
+ three 3
\ No newline at end of file
--- /dev/null
+
+@import 'a'
+@import 'b'
+@import 'c'
\ No newline at end of file
--- /dev/null
+@import "foo/bar.css";
+@import "bar/baz.css";
\ No newline at end of file
--- /dev/null
+
+@import "foo/bar.css"
+@import 'bar/baz.css'
\ No newline at end of file
--- /dev/null
+body {
+ padding: 10px 5px 10px 5px;
+}
+form {
+ padding-left: 5px;
+ padding-right: 5px;
+}
\ No newline at end of file
--- /dev/null
+
+if true
+ @import "mixins/box"
+
+body
+ pad 5px 10px
+
+form
+ pad-x 5px
\ No newline at end of file
--- /dev/null
+one {
+ foo: bar;
+}
+two {
+ foo: bar;
+}
+three {
+ foo: bar;
+}
+four {
+ foo: bar;
+}
+five {
+ foo: bar;
+}
\ No newline at end of file
--- /dev/null
+
+dir = 'import.ordering'
+
+one
+ foo bar
+
+@import dir + "/two"
+
+three
+ foo bar
+
+@import dir + '/four'
--- /dev/null
+five
+ foo bar
\ No newline at end of file
--- /dev/null
+four
+ foo bar
+
+@import "import.ordering/five"
\ No newline at end of file
--- /dev/null
+two
+ foo bar
\ No newline at end of file
--- /dev/null
+a {
+ color: #f00 !important;
+}
+a.button {
+ color: #00f;
+}
\ No newline at end of file
--- /dev/null
+
+a
+ color red !important
+
+a.button
+ color blue
\ No newline at end of file
--- /dev/null
+#login {
+ -webkit-border-radius: 1px 2px / 3px 4px;
+ -moz-border-radius: 1px 2px / 3px 4px;
+ border-radius: 1px 2px / 3px 4px;
+}
+body {
+ foo: bar;
+ foo-something: foo;
+ foo-something-bar: foo;
+ something-foo: foo;
+ something: foo;
+}
+body {
+ test-stuff-yup: awesome;
+ -webkit-border-radius: awesome;
+ -webkit-box-shadow: awesome;
+}
+body {
+ foo: "one";
+ foo: "two";
+}
+body {
+ -webkit-something: foo;
+ something: foo;
+}
+body form input {
+ -webkit-something: foo;
+ something: foo;
+}
+body form input p {
+ something: foo;
+}
+body {
+ foo-test-baz: bar;
+ foo-test: bar;
+ test: bar;
+ position: absolute;
+ top: 0;
+ right: 0;
+}
\ No newline at end of file
--- /dev/null
+
+vendor(prop, args)
+ -webkit-{prop} args
+ -moz-{prop} args
+ {prop} args
+
+border-radius()
+ vendor('border-radius', arguments)
+
+#login
+ border-radius 1px 2px / 3px 4px
+
+body
+ prop = 'something'
+ foo bar
+ foo-{prop} foo
+ foo-{prop}-bar foo
+ {prop}-foo foo
+ {prop} foo
+
+body
+ {'test' + '-stuff'}-yup awesome
+ -webkit-{border-radius} awesome
+ -webkit-{box-shadow} awesome
+
+testing(var, one, two)
+ {var}
+
+body
+ foo testing('one', 1, 2)
+ foo testing('two', 1, 2)
+
+body
+ nested(prop)
+ -webkit-{prop} foo
+ {prop} foo
+ form input
+ -webkit-{prop} foo
+ {prop} foo
+ p
+ {prop} foo
+ nested('something')
+
+top-right()
+ position absolute
+ top 0
+ right 0
+
+foo(ret)
+ ret
+
+body
+ foo-{foo('test')}-baz bar
+ foo-{foo('test')} bar
+ {foo('test')} bar
+ {foo('top')}-right bar
--- /dev/null
+got {
+ root: true;
+}
+body {
+ got: "a mixin";
+ foo: "not a mixin";
+}
\ No newline at end of file
--- /dev/null
+reset()
+ if mixin == 'root'
+ got
+ root true
+ else if mixin
+ got 'a mixin'
+ else
+ 'not a mixin'
+
+reset()
+
+body
+ reset()
+ foo reset()
\ No newline at end of file
--- /dev/null
+body {
+ padding: 10px 10px;
+}
\ No newline at end of file
--- /dev/null
+pad( x , y = x )
+ padding x y
+
+body
+ pad( 10px )
\ No newline at end of file
--- /dev/null
+body {
+ font: 12px "Lucida Grande", Arial, sans-serif;
+}
\ No newline at end of file
--- /dev/null
+
+body
+ font 12px "Lucida Grande", Arial, sans-serif
\ No newline at end of file
--- /dev/null
+body {
+ font: 14px;
+}
+
+a { text-decoration: none; }
\ No newline at end of file
--- /dev/null
+@css {
+ body {
+ font: 14px;
+ }
+
+ a { text-decoration: none; }
+}
\ No newline at end of file
--- /dev/null
+@media print and (width: 21cm) and (height: 29cm) {
+ body {
+ margin: 3cm;
+ padding: 0;
+ }
+}
+@media print {
+ @page :left {
+ margin-left: 5px;
+ }
+ @page :right {
+ margin-right: 5px;
+ }
+}
\ No newline at end of file
--- /dev/null
+
+@media print and (width: 21cm) and (height: 29cm)
+ body
+ margin 3cm
+ padding 0
+
+@media print
+ @page :left
+ margin-left 5px
+ @page :right
+ margin-right 5px
\ No newline at end of file
--- /dev/null
+body {
+ padding: 20px;
+ padding: 10px;
+ padding: 3px;
+}
+form input {
+ foo: bar;
+ bar: baz;
+}
+form input .two {
+ level: two;
+}
+form input .two:hover {
+ level: three;
+}
+body {
+ foo: bar;
+ bar: baz;
+}
\ No newline at end of file
--- /dev/null
+
+pad(size = small)
+ if large == size
+ padding 20px
+ if medium == size
+ padding 10px
+ if small == size
+ padding 3px
+
+body
+ pad(large)
+ pad(medium)
+ pad()
+ pad(invalid)
+
+nested(val)
+ if val
+ foo bar
+ bar baz
+ .two
+ level two
+ &:hover
+ level three
+
+form input
+ nested(true)
+ nested(false)
+
+break()
+ foo bar
+ bar baz
+ return
+ baz raz
+
+body
+ break()
\ No newline at end of file
--- /dev/null
+body {
+ one: 1;
+ two: 2;
+ three: 3;
+ four: 4;
+ five: 5;
+ six: 6;
+ seven: 7;
+ eight: 8;
+ nine: 9;
+}
\ No newline at end of file
--- /dev/null
+mixin2()
+ four 4
+ if true
+ five 5
+
+mixin()
+ mixin2()
+ if true
+ six 6
+ if true
+ seven 7
+ eight 8 if true
+
+body
+ one 1
+ two 2
+ three 3
+ if true
+ mixin()
+ nine 9
\ No newline at end of file
--- /dev/null
+body {
+ one: 1;
+ two: 2;
+ three: 3;
+ four: 4;
+ five: 5;
+ six: 6;
+ seven: 7;
+}
\ No newline at end of file
--- /dev/null
+body {
+ one: 1;
+ two: 2;
+ three: 3;
+ four: 4;
+ five: 5;
+ six: 6;
+ seven: 7;
+}
\ No newline at end of file
--- /dev/null
+
+mixin2()
+ three 3
+
+mixin3()
+ four 4
+ mixin4()
+
+mixin4()
+ five 5
+
+mixin()
+ two 2
+ mixin2()
+ mixin3()
+ six 6
+
+body
+ one 1
+ mixin()
+ seven 7
\ No newline at end of file
--- /dev/null
+mixin2()
+ three 3
+
+mixin3()
+ four 4
+ mixin4()
+
+mixin4()
+ five 5
+
+mixin()
+ two 2
+ mixin2()
+ mixin3()
+ six 6
+
+body
+ one 1
+ mixin()
+ seven 7
\ No newline at end of file
--- /dev/null
+ul li {
+ list-style-image: none;
+ list-style-type: none;
+ margin-left: 0;
+ display: -moz-inline-box;
+ -moz-box-orient: vertical;
+ display: inline-block;
+ vertical-align: middle;
+}
+ul li:first-child {
+ list-style-image: none;
+ list-style-type: none;
+ margin-left: 0;
+ display: -moz-inline-box;
+ -moz-box-orient: vertical;
+ display: inline-block;
+ vertical-align: middle;
+ padding-left: 5px;
+ padding-right: 5px;
+}
+body {
+ did: nothing;
+}
+body {
+ padding: 5px;
+}
+body {
+ padding: 5px;
+ margin: 5px;
+}
\ No newline at end of file
--- /dev/null
+.button {
+ position: fixed;
+ bottom: 0;
+ left: 0;
+}
+.button {
+ position: fixed;
+ bottom: 0;
+ left: 0;
+}
+.button {
+ position: fixed;
+ bottom: 5px;
+ left: 5px;
+}
\ No newline at end of file
--- /dev/null
+
+fix-to(a, b)
+ position fixed
+ {a} 0
+ {b} 0
+
+.button
+ fix-to bottom left
+
+
+fix-to(pos...)
+ position fixed
+ if length(pos) == 2
+ {pos[0]} 0
+ {pos[1]} 0
+ else if length(pos) == 4
+ a = pos[0..1]
+ b = pos[2..3]
+ {a[0]} a[1]
+ {b[0]} b[1]
+ else
+ error('invalid arguments. fix-to: <pos> [n] <pos> [n];')
+
+.button
+ fix-to bottom left
+
+.button
+ fix-to bottom 5px left 5px
\ No newline at end of file
--- /dev/null
+no-bullet()
+ list-style-image none
+ list-style-type none
+ margin-left 0
+
+inline-block()
+ display -moz-inline-box
+ -moz-box-orient vertical
+ display inline-block
+ vertical-align middle
+
+inline-block-list-item(padding = false)
+ no-bullet()
+ inline-block()
+ if padding
+ padding-left 5px
+ padding-right 5px
+
+ul
+ li
+ inline-block-list-item()
+
+ul li:first-child
+ inline-block-list-item(true)
+
+pad(pad = false, margin = false)
+ if pad
+ padding 5px
+ if margin
+ margin 5px
+ unless pad or margin
+ did nothing
+
+body
+ pad()
+
+body
+ pad(true)
+
+body
+ pad(true, true)
\ No newline at end of file
--- /dev/null
+body {
+ margin: 5px 10px;
+}
\ No newline at end of file
--- /dev/null
+overload-padding = true
+
+if overload-padding
+ padding(y, x)
+ margin y x
+
+body
+ padding 5px 10px
\ No newline at end of file
--- /dev/null
+body {
+ one: 1;
+ two: 1 2;
+ three: 1 2 3;
+ -three: 1 2 c;
+ -two: 1 b c;
+}
\ No newline at end of file
--- /dev/null
+body {
+ padding: 5px;
+ color: "bar";
+}
+body .foo {
+ color: "bar";
+}
+body .foo .bar {
+ color: "bar";
+}
+body {
+ one: 1;
+ two: 2;
+ three: 3;
+}
+body with some nesting {
+ four: 4;
+}
+body with some nesting even more {
+ five: 5;
+}
\ No newline at end of file
--- /dev/null
+
+mixin(n)
+ padding n
+ var = 'bar'
+ color var
+ .foo
+ color var
+ .bar
+ color var
+
+body
+ foo = 'foo'
+ mixin(5px)
+
+three(n)
+ three n
+ with some nesting
+ four n = n + 1
+ even more
+ five n + 1
+
+two(n)
+ two n
+ three(n + 1)
+
+one(n)
+ one n
+ two(n + 1)
+
+body
+ one(1)
\ No newline at end of file
--- /dev/null
+
+one(a)
+ one a
+ two(b)
+ two a b
+ three(c)
+ three a b c
+ three(3)
+ -three a b c
+ two(2)
+ -two a b c
+
+body
+ one(1)
--- /dev/null
+body {
+ one: 1;
+ two: 2;
+ three: 3;
+ four: 4;
+ five: 5;
+ six: 6;
+ seven: 7;
+ eight: 8;
+ nine: 9;
+}
\ No newline at end of file
--- /dev/null
+test-nested()
+ two 2
+ if true
+ three 3
+ if true
+ four 4
+ if true
+ five 5
+ six 6
+ seven 7
+ eight 8
+
+body
+ one 1
+ test-nested()
+ nine 9
--- /dev/null
+body {
+ foo: bar;
+ bar: baz;
+}
\ No newline at end of file
--- /dev/null
+another()
+ foo bar
+ bar baz
+ return
+ baz raz
+
+body
+ another()
\ No newline at end of file
--- /dev/null
+body {
+ padding: 5px;
+}
\ No newline at end of file
--- /dev/null
+foo()
+ body
+ padding 5px
+
+foo()
\ No newline at end of file
--- /dev/null
+
+pad(x, y = x)
+ padding y x y x
+
+pad-x(n)
+ padding-left n
+ padding-right n
+
+pad-y(n)
+ padding-top n
+ padding-bottom n
--- /dev/null
+body {
+ foo: 1 2 3 4 5;
+ foo: 1 2 3 4 5 6 7 8 9 10;
+ foo: 1;
+ foo: 1 2 3 4 5;
+ foo: 5;
+ foo: 2;
+ foo: 5;
+ foo: 6 7 8 9 10;
+ foo: true;
+ foo: true;
+}
+body {
+ foo: 1 2 3;
+}
\ No newline at end of file
--- /dev/null
+body
+ small = 1..5
+ large = (1..5) (6..10)
+
+ foo small
+ foo large
+
+ foo small[0]
+ foo large[0]
+
+ foo length(small)
+ foo length(large)
+
+ foo small[length(small) - 1]
+ foo large[length(large) - 1]
+
+ foo small[-1] == null
+ foo small[123123] == null
+
+body
+ start = 1
+ end = 3
+ foo start..end
\ No newline at end of file
--- /dev/null
+body {
+ foo: 20;
+}
+body {
+ foo: 5;
+}
+body {
+ foo: 20;
+}
+body {
+ foo: 2.5;
+}
+body {
+ foo: 1;
+}
\ No newline at end of file
--- /dev/null
+
+test(n)
+ n += 5
+ n += 5
+
+body
+ foo test(10)
+
+test(n)
+ n -= 2
+ n -= 3
+
+body
+ foo test(10)
+
+test(n)
+ n *= 2
+ n *= 2
+
+body
+ foo test(5)
+
+test(n)
+ n /= 2
+ n /= 4
+
+body
+ foo test(20)
+
+test(n)
+ n %= 2
+
+body
+ foo test(5)
\ No newline at end of file
--- /dev/null
+body {
+ foo: 20;
+}
+body {
+ foo: 5;
+}
+body {
+ foo: 20;
+}
+body {
+ foo: 2.5;
+}
+body {
+ foo: 1;
+}
\ No newline at end of file
--- /dev/null
+
+test(n)
+ n += 5
+ n += 5
+ foo n
+
+body
+ test(10)
+
+test(n)
+ n -= 2
+ n -= 3
+ foo n
+
+body
+ test(10)
+
+test(n)
+ n *= 2
+ n *= 2
+ foo n
+
+body
+ test(5)
+
+test(n)
+ n /= 2
+ n /= 4
+ foo n
+
+body
+ test(20)
+
+test(n)
+ n %= 2
+ foo n
+
+body
+ test(5)
\ No newline at end of file
--- /dev/null
+body {
+ foo: 20;
+ foo: 21;
+}
+body {
+ foo: 20;
+}
+body {
+ foo: 5;
+}
+body {
+ foo: 20;
+}
+body {
+ foo: 2.5;
+}
+body {
+ foo: 1;
+}
\ No newline at end of file
--- /dev/null
+
+
+n = 10
+a = n = n + 10
+a += 1
+
+body
+ foo n
+ foo a
+
+n = 10
+n += 5
+n += 5
+
+body
+ foo n
+
+n = 10
+n -= 2
+n -= 3
+
+body
+ foo n
+
+n = 5
+n *= 2
+n *= 2
+
+body
+ foo n
+
+n = 20
+n /= 2
+n /= 4
+
+body
+ foo n
+
+n = 5
+n %= 2
+
+body
+ foo n
\ No newline at end of file
--- /dev/null
+body {
+ foo: yes;
+ foo: true;
+ foo: yay;
+ foo: nah;
+ foo: nah;
+ foo: true;
+ foo: false;
+}
\ No newline at end of file
--- /dev/null
+
+ensure-unit(n)
+ foo bar
+ foo bar
+ foo bar
+ n is a 'unit'
+
+body
+ a = 15
+ b = 15
+
+ // yes
+ foo a == b and (b == 15 ? 1 : 0) ? yes : no
+
+ // true
+ foo a == b and b == a
+
+ // yay
+ foo 15px is a 'unit' and #fff is a 'color'?yay:nah
+
+ // nah
+ foo 15px is a 'color' and #fff is a 'color'?yay:nah
+
+ // nah
+ foo 15px is a 'unit' and #fff is a 'unit'? yay : nah
+
+ // true
+ foo ensure-unit(15)
+
+ // false
+ foo ensure-unit(#fff)
+
--- /dev/null
+body {
+ foo: 5px;
+ foo: 0px;
+ foo: 0px;
+ foo: false;
+ foo: true;
+ foo: 5px;
+ foo: 1px;
+ foo: 0;
+ foo: false;
+ foo: 10;
+ foo: #fff;
+ foo: 1;
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: wahoo;
+ foo: nope;
+ foo: "got 15px";
+ foo: 1;
+ foo: 5;
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: false;
+ foo: false;
+}
\ No newline at end of file
--- /dev/null
+body {
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: true;
+}
\ No newline at end of file
--- /dev/null
+body
+
+ // true
+ foo 1 != 5
+
+ // true
+ foo wahoo == wahoo
+
+ // false
+ foo wahoo == something
+
+ // true
+ foo wahoo != something
+ foo wahoo is not something
+
+ // true
+ foo = yay
+ foo yes == (foo is defined ? yes : nope)
+
+ // true
+ rawr = 'asdfasdf'
+ foo yes == (rawr is defined ? yes : nope)
+
+ // true
+ foo 1000ms == 1s
+
+ // false
+ foo 1ms == 1s
+
+ // true
+ foo 5 < 10 and 10 > 5
\ No newline at end of file
--- /dev/null
+body {
+ foo: true;
+ foo: true;
+ foo: false;
+}
+body {
+ foo: true;
+}
+body {
+ foo: true;
+ foo: true;
+ foo: false;
+}
+body {
+ foo: false;
+ foo: true;
+ foo: true;
+ foo: false;
+}
+body {
+ foo: false;
+ foo: false;
+ foo: true;
+ foo: false;
+ foo: true;
+}
+body {
+ foo: true;
+ foo: false;
+}
+body {
+ foo: true;
+ foo: false;
+ foo: true;
+ foo: true;
+}
\ No newline at end of file
--- /dev/null
+
+
+body
+ nums = 1 2 3
+ foo 1 in nums
+ foo 3 in nums
+ foo 5 in nums
+
+body
+ nums = 1
+ foo 1 in nums == true
+
+body
+ words = foo bar baz
+ foo bar in words
+ foo baz in words
+ foo HEY in words
+
+body
+ tuples = (error 'one') (error 'two')
+ foo error in tuples
+ foo (error 'one') in tuples
+ foo (error 'two') in tuples
+ foo (error 'something') in tuples
+
+fn(args...)
+ 2 in args
+
+body
+ foo fn()
+ foo fn(1)
+ foo fn(2)
+ foo fn(3 2)
+ foo fn(1,2,3)
+
+fn(args...)
+ (3 2) in args
+
+body
+ foo fn(3 2)
+ foo fn(3,2)
+
+fn()
+ test in arguments
+
+body
+ foo fn(test)
+ foo fn(a, b, c)
+ foo fn(a, test, c)
+ foo fn(a test c)
\ No newline at end of file
--- /dev/null
+body {
+ foo: false;
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: false;
+ foo: "something";
+ foo: "something";
+ foo: "12";
+}
\ No newline at end of file
--- /dev/null
+
+stringish(val = false)
+ 'string' == type(val) or 'ident' == type(val)
+
+string(val)
+ '' + val
+
+body
+ // false
+ foo stringish(12)
+
+ // true
+ foo stringish('12')
+
+ // true
+ foo stringish(wahoo)
+
+ // false
+ num = 12
+ foo stringish(num)
+ foo stringish()
+
+ foo string(something)
+ foo string('something')
+ foo string(12)
\ No newline at end of file
--- /dev/null
+body {
+ foo: 4;
+ foo: 4;
+ foo: -5px;
+ foo: 2;
+ foo: 2;
+}
+body {
+ foo: true;
+ foo: true;
+}
+body {
+ foo: 5;
+ foo: 5;
+}
+body {
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: true;
+ foo: 2;
+}
+body {
+ foo: true;
+ foo: true;
+}
+body {
+ foo: 2.5;
+ foo: 2.5;
+}
+body {
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: wahoo;
+ foo: fail;
+}
+body {
+ foo: true;
+ foo: true;
+}
+body {
+ foo: true;
+ foo: 1;
+}
+body {
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: true;
+}
\ No newline at end of file
--- /dev/null
+body
+ // 4
+ foo (--- 0) or 4
+ // 4
+ foo --- 0 or 4
+ // -5px
+ foo ---5px
+ // 2
+ foo (!!!5) or 2
+ foo !!!5 or 2
+
+
+body
+ // true
+ foo !(! 5)
+ foo !!5
+
+body
+ // 5
+ foo (! false) and (! false) and 5
+ foo ! false and ! false and 5
+
+body
+ // true
+ foo (!!5 == true) or (!!0 == false)
+ foo !!5 == true or !!0 == false
+ foo (!!5 == false) or (!!0 == false)
+ foo !!5 == false or !!0 == false
+ // 2
+ foo 5 < 10 and !!5 and 2
+
+body
+ // true
+ foo (!!true) and (!!true)
+ foo !!true and !!true
+
+body
+ test()
+ 5 * 2 - 15 / 2
+ // 2.5
+ foo test()
+ foo (5 * 2) - (15 / 2)
+
+body
+ // true
+ foo not 5 < 10 ? 0 : 1
+ // true
+ foo !(5 < 10 ? 0 : 1)
+ // false
+ foo !(5 > 10 ? 0 : 1)
+ // wahoo
+ foo !! 1 ? wahoo : fail
+ // fail
+ foo !1 ? wahoo : fail
+
+body
+ foo = 'test'
+ bar = 'test'
+ // true
+ foo (foo is defined) and (bar is defined)
+ foo foo is defined and bar is defined
+
+body
+ // true
+ foo 5 > 4 is a 'boolean'
+
+ foo = type is a 'unit' ? type : 1
+ // 1
+ foo foo
+
+body
+ padding = false
+ margin = false
+
+ // true
+ foo !padding or !margin
+ foo not padding or margin
+
+ // false
+ foo not padding or margin == !padding or !margin
+ // true
+ foo (not padding or margin) == !padding or !margin
--- /dev/null
+body
+ // 5px
+ foo 0 || 5px
+
+ // 0px
+ foo 0px || 5px
+
+ // 0px
+ foo 0px || 0px
+
+ // false
+ foo 0 or false
+
+ // true
+ foo 0 || 0 || true
+
+ // 5px
+ foo 1px && 5px
+
+ // 1px
+ foo 0px && 1px
+
+ // 0
+ foo 1px && 0
+
+ // false
+ foo 1px and false
+
+ // 10
+ foo 5px && 5px && 10
+
+ // #fff
+ foo #000 && #fff
+
+ // 1
+ foo 8 && (4 && 1)
+
+ // true
+ type = "color"
+ foo #fff is a type
+ foo #fff is a 'color'
+
+ // false
+ foo 15px is a 'color'
+ // true
+ foo 15px is a 'unit'
+
+ // true
+ foo 15px is a 'unit' and #fff is a 'color'
+
+ // true
+ foo = 'bar'
+
+ // true
+ bar = 'baz'
+ foo foo is defined and bar is defined
+
+ // false
+ foo baz is defined
+
+ // wahoo
+ foo bar is defined ? wahoo : nope
+
+ // nope
+ foo rawr is defined ? yes : nope
+
+ // "got 15px"
+ foo "got " + 15px
+
+ // 1
+ foo true and 1 or 5
+
+ // 5
+ foo !false and !false and 5
+
+ // true
+ foo !!5 is true or !!0 is false
+ foo !!5 == false or !!0 == false
+
+ // true
+ foo wahoo == wahoo
+
+ // false
+ foo 0 == true
+ foo true == 0
+ foo #fff == undefined
--- /dev/null
+body {
+ foo: true;
+ foo: 3 4 5;
+ foo: true;
+ foo: true;
+ foo: false;
+ foo: -5;
+}
+body {
+ foo: 1 2 3 4;
+ foo: 1;
+ foo: 2 3 4;
+ foo: 2;
+ foo: 3 4;
+ foo: 3;
+ foo: 4;
+ foo: ;
+}
+body {
+ foo: error;
+ foo: "message";
+}
+body {
+ foo: 5;
+ foo: 10;
+}
+body {
+ foo: 5;
+ foo: 10;
+}
+body {
+ foo: 1 2;
+ foo: 3 4;
+ foo: 4;
+}
+body {
+ foo: 100 200;
+ foo: 100;
+ foo: 200;
+ foo: 2;
+}
+body {
+ foo: 100 200;
+ foo: 100;
+ foo: 200;
+ foo: 2;
+}
+body {
+ foo: 100 200;
+ foo: 100;
+ foo: 200;
+ foo: 2;
+}
+body {
+ foo: 100 200;
+ foo: 100;
+ foo: 200;
+ foo: 2;
+}
\ No newline at end of file
--- /dev/null
+body {
+ foo: a b;
+ foo: a b c;
+ foo: d e f;
+ foo: c d e;
+}
+body {
+ foo: 1 2 3 4;
+}
+body {
+ foo: ;
+ foo: ;
+ foo: ;
+}
\ No newline at end of file
--- /dev/null
+body
+ vals = a b c d e f g
+ foo vals[0...2]
+ foo vals[0..2]
+ foo vals[3..5]
+ foo vals[2 3 4]
+
+body
+ vals = (1 2) (3 4)
+ foo vals[0..1]
+
+body
+ foo ()[]
+ foo ()[1]
+ foo ()[1..3]
\ No newline at end of file
--- /dev/null
+body
+ foo ()[0] == null
+ foo (1(2(3 4 5)))[1][1]
+ foo (1 2 3)['test'] == null
+ foo !(1 0)[1]
+ foo !(1 0)[0]
+ foo - - -(1 2 3 4 5)[4]
+
+body
+ foo (1 (2 (3 4)))
+ foo (1 (2 (3 4)))[0]
+ foo (1 (2 (3 4)))[1]
+ foo (1 (2 (3 4)))[1][0]
+ foo (1 (2 (3 4)))[1][1]
+ foo (1 (2 (3 4)))[1][1][0]
+ foo (1 (2 (3 4)))[1][1][1]
+ foo (1 (2 (3 4)))[1][1][3]
+
+body
+ foo (error 'message')[0]
+ foo (error 'message')[1]
+
+size(a, b)
+ return a b
+
+body
+ foo size(5, 10)[0]
+ foo size(5, 10)[1]
+
+size(a, b)
+ (a b)
+
+body
+ foo size(5, 10)[0]
+ foo size(5, 10)[1]
+
+size()
+ (1 2) (3 4)
+
+body
+ foo size()[0]
+ foo size()[1]
+ foo size()[1][1]
+
+image-size(path)
+ w = 100
+ h = 200
+ return w h
+
+body
+ size = image-size('test.png')
+ foo size
+ foo size[0]
+ foo size[1]
+ foo length(size)
+
+image-size(path)
+ 100 200
+
+body
+ size = image-size('test.png')
+ foo size
+ foo size[0]
+ foo size[1]
+ foo length(size)
+
+size = 100 200
+
+body
+ foo size
+ foo size[0]
+ foo size[1]
+ foo length(size)
+
+size = (100 200)
+
+body
+ foo size
+ foo size[0]
+ foo size[1]
+ foo length(size)
--- /dev/null
+@page {
+ margin: 2.5cm;
+}
+@page :left {
+ margin-left: 5cm;
+}
+@page :right {
+ margin-right: 5cm;
+}
+@page :first {
+ margin-top: 8cm;
+ background: white;
+}
\ No newline at end of file
--- /dev/null
+
+@page
+ margin 2.5cm
+
+@page :left
+ margin-left 5cm
+
+@page :right
+ margin-right 5cm
+
+@page :first
+ margin-top 8cm
+ background white
--- /dev/null
+.button {
+ padding: 5px;
+ -webkit-transition: opacity 1s ease-out;
+}
+.button:hover {
+ opacity: 2;
+}
+textarea,
+input {
+ color: #a7a7a7;
+}
+textarea:hover,
+input:hover {
+ color: #000;
+}
+.dim {
+ opacity: 0.2;
+}
+.dim:hover,
+.dim.show {
+ opacity: 1;
+}
+body #login {
+ -webkit-box-shadow: 1px 1px 3px #eee;
+ -moz-box-shadow: 1px 1px 3px #eee;
+ box-shadow: 1px 1px 3px #eee;
+}
+html.ie8 body #login,
+html.ie7 body #login foo,
+html.ie6 body #login {
+ border: solid 1px #eee;
+}
\ No newline at end of file
--- /dev/null
+dim-on-hover()
+ -webkit-transition opacity 1s ease-out
+ &:hover
+ opacity 2
+
+.button
+ padding 5px
+ dim-on-hover()
+
+textarea
+input
+ color #A7A7A7
+ &:hover
+ color #000
+
+.dim
+ opacity .2
+ &:hover
+ &.show
+ opacity 1
+
+box-shadow()
+ -webkit-box-shadow arguments
+ -moz-box-shadow arguments
+ box-shadow arguments
+ html.ie8 &,
+ html.ie7 & foo,
+ html.ie6 &
+ border solid 1px arguments[length(arguments) - 1]
+
+body
+ #login
+ box-shadow 1px 1px 3px #eee
\ No newline at end of file
--- /dev/null
+body {
+ margin: 5px;
+ padding: 5px;
+ foo: 5px;
+}
+body something {
+ here: whoop;
+}
\ No newline at end of file
--- /dev/null
+
+mixin()
+ foo: 5px
+ something
+ here: whoop
+
+body
+ margin: 5px
+ padding: 5px
+ mixin()
\ No newline at end of file
--- /dev/null
+#wrapper {
+ padding: 5px;
+ white-space: nowrap;
+}
\ No newline at end of file
--- /dev/null
+body {
+ background: #00f;
+ width: 100px;
+ height: 50px;
+}
+body {
+ background: #00f;
+ width: 100px;
+ height: 50px;
+}
\ No newline at end of file
--- /dev/null
+bg()
+ background: blue;
+
+body {
+ bg(); width: 100px;
+ height: 50px;
+}
+
+body
+ bg(); width 100px;
+ height 50px
\ No newline at end of file
--- /dev/null
+
+#wrapper
+ padding 5px
+ white-space nowrap
\ No newline at end of file
--- /dev/null
+button {
+ background: #e3e3e3;
+}
+button:hover {
+ background: #dbdbdb;
+}
+button:active {
+ background: #d6d6d6;
+}
+button nested really-nested with-even-more-nesting {
+ background: #e3e3e3;
+}
\ No newline at end of file
--- /dev/null
+minimal-button(bg = #e3e3e3)
+ background bg
+ &:hover
+ background darken(bg, 3%)
+ &:active
+ background darken(bg, 5%)
+ nested
+ really-nested
+ with-even-more-nesting
+ background bg
+
+button
+ minimal-button()
\ No newline at end of file
--- /dev/null
+body {
+ background: #c3210d;
+}
\ No newline at end of file
--- /dev/null
+body
+ background #c3210d
\ No newline at end of file
--- /dev/null
+body {
+ font: 13px / 1.231;
+}
+body {
+ font: 13px / 1.231;
+}
+body {
+ font: 13px / 1.231;
+}
+body {
+ font: 13px / 1.231;
+}
+body {
+ font: 13px / 1.231;
+ background: #fff;
+}
\ No newline at end of file
--- /dev/null
+
+body { font: 13px / 1.231; }
+body {font: 13px / 1.231;}
+body {font: 13px / 1.231}
+body { font : 13px / 1.231 }
+body { font : 13px / 1.231; background: white }
\ No newline at end of file
--- /dev/null
+body {
+ font-weight: normal;
+}
+body {
+ color: #fff;
+}
\ No newline at end of file
--- /dev/null
+body { font-weight: normal; } /* foo */
+body { color: #fff; } // foo
\ No newline at end of file
--- /dev/null
+#fea-ca {
+ padding: 5px;
+}
+#ffffff {
+ padding: 5px;
+ foo: #fea -ca;
+}
\ No newline at end of file
--- /dev/null
+
+#fea-ca
+ padding 5px
+
+#ffffff
+ padding 5px
+ foo #fea-ca
\ No newline at end of file
--- /dev/null
+body {
+ foo: bottom;
+ foo: right;
+ foo: bottom right;
+}
\ No newline at end of file
--- /dev/null
+
+opposite-position(pos) {
+ return bottom if pos == top;
+ return top if pos == bottom;
+ return right if pos == left;
+ return left if pos == right;
+ error('Invalid position ' + pos)
+}
+
+opposite(positions) {
+ for pos in positions {
+ pos = opposite-position(pos);
+ ret = ret is defined ? ret pos : pos;
+ }
+}
+
+body {
+ foo: opposite(top);
+ foo: opposite(left);
+ foo: opposite(top left);
+}
--- /dev/null
+foo,
+bar,
+baz {
+ display: none;
+}
+foo,
+bar,
+baz {
+ display: none;
+}
+body :nth-child(2),
+body foo bar,
+body bar,
+body baz {
+ display: none;
+}
+body {
+ foo: bar;
+}
+body bar,
+body baz {
+ display: none;
+}
+body foo,
+body bar,
+body baz {
+ display: none;
+}
+body foo,
+body :nth-child(2),
+body bar {
+ display: none;
+}
+body {
+ foo: bar;
+}
+body {
+ foo: 3;
+}
\ No newline at end of file
--- /dev/null
+
+foo, bar, baz
+ display none
+
+foo
+bar
+baz
+ display none
+
+body
+ :nth-child(2)
+ foo bar
+ bar
+ baz
+ display none
+
+body
+ foo bar
+ bar
+ baz
+ display none
+
+body
+ foo
+ bar
+ baz
+ display none
+
+body
+ foo
+ :nth-child(2)
+ bar
+ display none
+
+fn()
+ bar if true;
+
+something()
+ one
+ two
+ fn()
+
+body
+ foo something()
+
+something()
+ nums = 1 2 3
+ one
+ two
+ for n in nums
+ n
+
+body
+ foo something()
\ No newline at end of file
--- /dev/null
+input[for=name] {
+ width: 200px;
+}
+body {
+ foo: 1;
+}
+body {
+ foo: 2;
+}
+body {
+ foo: 3;
+}
+body foo {
+ bar: 1;
+ bar: 2;
+ bar: 3;
+}
+#login foo,
+#login input[for=name] {
+ foo: bar;
+}
+#login foo input[for=name] {
+ bar: 1;
+}
+#login foo input[for=name] {
+ bar: 2;
+}
+#login foo input[for=name] {
+ bar: 3;
+}
\ No newline at end of file
--- /dev/null
+input[for=name]
+ width 200px
+
+nums = 1 2 3
+for n in nums
+ body
+ foo n
+
+body
+ foo
+ for n in nums
+ bar n
+
+something()
+ nums = 1 2 3
+ foo
+ input[for=name]
+ foo bar
+
+#login
+ something()
+
+something()
+ nums = 1 2 3
+ foo
+ for n in nums
+ input[for=name]
+ bar n
+
+#login
+ something()
\ No newline at end of file
--- /dev/null
+#content {
+ width: 960px;
+}
+@media screen {
+ #content {
+ width: 640px;
+ }
+}
\ No newline at end of file
--- /dev/null
+cols(n)
+ width 160px * n
+
+#content
+ cols 6
+
+@media screen
+ #content
+ cols 4
\ No newline at end of file
--- /dev/null
+body {
+ foo: true;
+ foo: false;
+}
+body {
+ foo: false;
+ foo: true;
+}
\ No newline at end of file
--- /dev/null
+
+light(color)
+ lightness(color) >= 50%
+
+dark(color)
+ lightness(color) < 50%
+
+body
+ foo light(white)
+ foo light(black)
+
+body
+ foo dark(white)
+ foo dark(black)
\ No newline at end of file
--- /dev/null
+body {
+ padding-right: 0;
+ float: right;
+}
\ No newline at end of file
--- /dev/null
+body
+ mixin()
+
+body
+ padding-{opposite-position(left)} 0
+ float opposite-position(left)
\ No newline at end of file
--- /dev/null
+@charset "utf-8"
\ No newline at end of file
--- /dev/null
+
+@charset "utf-8"
\ No newline at end of file
--- /dev/null
+textarea,
+input {
+ border: 1px solid #eee;
+}
\ No newline at end of file
--- /dev/null
+textarea,
+input,
+.text {
+ border: 1px solid #eee;
+}
\ No newline at end of file
--- /dev/null
+
+textarea
+input
+.text
+ border 1px solid #eee
\ No newline at end of file
--- /dev/null
+
+textarea, input
+ border 1px solid #eee
\ No newline at end of file
--- /dev/null
+body {
+ margin: 24px;
+ padding: 12px 5px 12px 5px;
+ font-size: 50px;
+}
+form input {
+ border: 3px solid #000;
+ margin: 24px;
+ padding: 2px 1px 2px 1px;
+}
\ No newline at end of file
--- /dev/null
+
+size = 12px
+size-large = size * 2
+
+pad(x, y = size)
+ margin size-large
+ padding y x y x
+
+body
+ size = 50px
+ pad(5px)
+ font-size size
+
+form input
+ border (size / 4) solid black
+ pad(1px, 2px)
\ No newline at end of file
--- /dev/null
+body {
+ margin: 24px;
+ padding: 12px 5px 12px 5px;
+ font-size: 50px;
+}
\ No newline at end of file
--- /dev/null
+body {
+ font: 5;
+}
+body .large {
+ font: 10;
+}
+body .other {
+ font: 15;
+}
\ No newline at end of file
--- /dev/null
+
+body
+ size = 5
+ font size
+ .large
+ large = size * 2
+ font large
+ .other
+ large ?= size * 3
+ font large
\ No newline at end of file
--- /dev/null
+
+size = 12px
+size-large = size * 2
+
+pad(x, y = size)
+ margin size-large
+ padding y x y x
+
+body
+ size = 50px
+ pad(5px)
+ font-size size
--- /dev/null
+body form input.hide,
+body foo bar,
+body .hidden,
+body:hover,
+body:focus {
+ display: none;
+}
+body form input,
+body .hidden {
+ display: none;
+}
+ul > li {
+ padding: 5px;
+ border: 1px solid #eee;
+}
+ul > li:first-child,
+ul > li:last-child {
+ border: none;
+}
+ul > li:first-child {
+ padding-top: 0;
+}
+ul > li:last-child {
+ padding-bottom: 0;
+}
+body form > input:nth-child(2) {
+ border: 1px solid #eee;
+}
\ No newline at end of file
--- /dev/null
+body
+ form input.hide,
+ foo bar,
+ .hidden
+ &:hover
+ &:focus
+ display none
+
+body
+ form input, .hidden
+ display none
+
+ul
+ > li
+ padding 5px
+ border 1px solid #eee
+ &:first-child,
+ &:last-child
+ border none
+ &:first-child
+ padding-top 0
+ &:last-child
+ padding-bottom 0
+
+body
+ form > input:nth-child(2)
+ border 1px solid #eee
\ No newline at end of file
--- /dev/null
+foo bar baz {
+ foo: bar;
+}
+foo > bar {
+ foo: bar;
+}
+input[type=text] {
+ foo: bar;
+}
+input[type="text"] {
+ foo: bar;
+}
+* {
+ foo: bar;
+}
+* .foo-bar {
+ foo: bar;
+}
+body > #container * {
+ foo: bar;
+}
+#foo > #bar + .baz {
+ foo: bar;
+}
+#foo>#bar {
+ foo: bar;
+}
+p + p ~ p {
+ foo: bar;
+}
+ul :odd {
+ foo: bar;
+}
+ul > li:last-child {
+ foo: bar;
+}
+ul > li:nth-child(2n) {
+ foo: bar;
+}
+*,
+p + p,
+ul > li {
+ foo: bar;
+}
\ No newline at end of file
--- /dev/null
+#container .hide,
+#footer .hide {
+ display: none;
+}
+#foo .hide .stuff,
+#bar .hide .stuff,
+#baz .hide .stuff {
+ display: none;
+}
\ No newline at end of file
--- /dev/null
+#container, #footer
+ .hide
+ display none
+
+#foo, #bar, #baz
+ .hide
+ .stuff
+ display none
--- /dev/null
+form .foo {
+ color: #000;
+}
+form .foo .bar {
+ padding: 5px;
+ color: #f00;
+}
+body .foo .bar {
+ display: none;
+}
+body .foo .baz,
+body .bar .baz,
+body .foo .sdf,
+body .bar .sdf {
+ display: none;
+}
+.foo .baz,
+.bar .baz,
+.foo .raz,
+.bar .raz {
+ something: "else";
+}
+.foo .baz,
+.bar .baz,
+.foo .raz,
+.bar .raz {
+ background: #f00;
+}
+.foo .baz .ASDF,
+.bar .baz .ASDF,
+.foo .raz .ASDF,
+.bar .raz .ASDF {
+ background: #fff;
+}
\ No newline at end of file
--- /dev/null
+
+form
+ .foo
+ color black
+ .bar
+ padding 5px
+ color red
+
+body
+ .foo
+ .bar
+ display none
+
+body
+ .foo
+ .bar
+ .baz
+ .sdf
+ display none
+
+.foo
+.bar
+ .baz
+ .raz
+ something 'else'
+
+.foo
+.bar
+ .baz
+ .raz
+ background red
+ .ASDF
+ background white
\ No newline at end of file
--- /dev/null
+ul td:nth-of-type(2),
+ul td:nth-of-type(3) {
+ background: #000;
+}
+table td:nth-child(2),
+table td:nth-child(3),
+table td:nth-child(4),
+table td:nth-child(5),
+table td::first-letter {
+ background: #000;
+}
+table td:nth-child(2) li:first-child,
+table td:nth-child(3) li:first-child,
+table td:nth-child(4) li:first-child,
+table td:nth-child(5) li:first-child,
+table td::first-letter li:first-child,
+table td:nth-child(2) li:last-child,
+table td:nth-child(3) li:last-child,
+table td:nth-child(4) li:last-child,
+table td:nth-child(5) li:last-child,
+table td::first-letter li:last-child {
+ background: #fff;
+}
+table :nth-child(2),
+table :nth-child(3) {
+ background: #000;
+}
\ No newline at end of file
--- /dev/null
+
+mixin()
+ td:nth-of-type(2)
+ td:nth-of-type(3)
+ background black
+
+ul
+ mixin()
+
+table
+ td:nth-child(2)
+ td:nth-child(3)
+ td:nth-child(4)
+ td:nth-child(5)
+ td::first-letter
+ background black
+ li:first-child
+ li:last-child
+ background white
+
+table
+ :nth-child(2)
+ :nth-child(3)
+ background black
\ No newline at end of file
--- /dev/null
+
+foo bar baz
+ foo bar
+
+foo > bar
+ foo bar
+
+input[type=text]
+ foo bar
+
+input[type="text"]
+ foo bar
+
+*
+ foo bar
+
+* .foo-bar
+ foo bar
+
+body > #container *
+ foo bar
+
+#foo > #bar + .baz
+ foo bar
+#foo>#bar
+ foo bar
+
+p + p ~ p
+ foo bar
+
+ul :odd
+ foo bar
+
+ul > li:last-child
+ foo bar
+
+ul > li:nth-child(2n)
+ foo bar
+
+*, p + p, ul > li
+ foo bar
\ No newline at end of file
--- /dev/null
+body {
+ background: #fff;
+}
\ No newline at end of file
--- /dev/null
+color = white
+color = color is defined ? color : black
+body
+ background color
\ No newline at end of file
--- /dev/null
+body {
+ padding: 5px;
+ padding: 5px 10px;
+}
+body {
+ padding: 5px ;
+ padding: 5px 10px;
+}
+body {
+ padding: 5px;
+ padding: 5px 10px;
+ padding: 5px 10px 0 2px;
+}
+body {
+ test-y: 1px;
+ test-y: 1px;
+ padding: 2px 3px;
+}
+body {
+ test-y: 1px;
+ test-x: ;
+ test-y: 1px;
+ test-x: 2px;
+}
\ No newline at end of file
--- /dev/null
+
+padding(n)
+ padding n
+
+body
+ padding(5px)
+ padding(5px 10px)
+
+padding(y, x = null)
+ padding y x
+
+body
+ padding(5px)
+ padding(5px, 10px)
+
+padding(args...)
+ padding args
+
+body
+ padding(5px)
+ padding(5px, 10px)
+ padding(5px, 10px, 0 2px)
+
+padding(y, rest...)
+ test-y y
+ if rest
+ padding rest
+
+body
+ padding(1px)
+ padding(1px, 2px, 3px)
+
+padding(args...)
+ if args
+ test-y args[0]
+ test-x args[1]
+
+body
+ padding(1px)
+ padding(1px, 2px)
\ No newline at end of file
--- /dev/null
+body {
+ padding: 5px;
+ padding: 5px;
+}
+body {
+ padding: 5px ;
+ padding: 5px 10px;
+}
+body {
+ padding: 5px;
+ padding: 5px 10px;
+ padding: 5px 10px 0 2px;
+}
+body {
+ test-y: 1px;
+ test-y: 1px;
+ padding: 2px 3px;
+}
+body {
+ test-y: 1px;
+ test-x: ;
+ test-y: 1px;
+ test-x: 2px;
+}
+body {
+ pad: 1;
+ pad: 2;
+ pad: 3 4 5;
+ len: 3;
+}
\ No newline at end of file
--- /dev/null
+
+padding(n)
+ padding n
+
+body
+ padding 5px
+ padding 5px 10px
+
+padding(y, x = null)
+ padding y x
+
+body
+ padding 5px
+ padding 5px 10px
+
+padding(args...)
+ padding args
+
+body
+ padding 5px
+ padding 5px 10px
+ padding 5px 10px 0 2px
+
+padding(y, rest...)
+ test-y y
+ if rest
+ padding rest
+
+body
+ padding 1px
+ padding 1px 2px 3px
+
+padding(args...)
+ if args
+ test-y args[0]
+ test-x args[1]
+
+body
+ padding 1px
+ padding 1px 2px
+
+padding(args...)
+ pad args[0]
+ pad args[1]
+ pad args[2]
+ len length(args)
+
+body
+ padding 1 2 (3 4 5)
\ No newline at end of file
--- /dev/null
+body {
+ font: 12px;
+}
\ No newline at end of file
--- /dev/null
+size = 12px
+
+body
+ font size
\ No newline at end of file
--- /dev/null
+body {
+ color: 204;
+}
+body {
+ font: 14px "Lucida Grande", Arial, sans-serif;
+ padding: 5px;
+ margin: 5px;
+}
+a {
+ font: 11px Impact, "Lucida Grande", Arial, sans-serif, serif;
+ border: 1px solid #fff;
+}
\ No newline at end of file
--- /dev/null
+
+size = 14px
+font-family = 'Lucida Grande', Arial, sans-serif
+$type = solid
+blue = #00c
+
+body
+ color blue(blue)
+
+body
+ font size font-family
+ padding pad = 5px
+ margin pad
+
+a
+ font 11px Impact, font-family, serif
+ border 1px $type #fff
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var stylus = require('../')
+ , should = require('../support/should')
+ , basename = require('path').basename
+ , fs = require('fs');
+
+/**
+ * Test count.
+ */
+
+var count = 0;
+
+/**
+ * Tests pending.
+ */
+
+var pending = 0;
+
+/**
+ * Test the given `test`.
+ *
+ * @param {String} test
+ */
+
+function test(test) {
+ var base = __dirname + '/cases/' + test
+ , path = base + '.styl'
+ , csspath = base + '.css';
+ fs.readFile(path, 'utf8', function(err, str){
+ if (err) throw err;
+ var paths = [__dirname + '/images', __dirname + '/cases/import.basic'];
+ var options = { filename: path, paths: paths };
+ if (~test.indexOf('compress')) options.compress = true;
+ stylus.render(str, options, function(err, actual){
+ if (err) throw err;
+ fs.readFile(csspath, 'utf8', function(err, expected){
+ if (err) throw err;
+ expected += '\n';
+ if (actual == expected) {
+ --pending || done();
+ } else {
+ var msg = '"' + basename(path, '.in') + '" failed\n\n'
+ + '\033[33mexpected:\033[0m \n' + expected + '\n\n'
+ + '\033[33mactual:\033[0m \n' + actual + '\n';
+ throw new Error(msg);
+ }
+ });
+ });
+ });
+ return test;
+};
+
+/**
+ * Auto-load and run tests.
+ */
+
+fs.readdir(__dirname + '/cases', function(err, files){
+ if (err) throw err;
+ files.forEach(function(file){
+ if (/\.styl$/.test(file)) {
+ ++pending;
+ ++count;
+ test(basename(file, '.styl'));
+ }
+ });
+});
+
+/**
+ * Done!!!
+ */
+
+function done() {
+ console.log(
+ '\n \033[90mcompleted\033[0m'
+ + ' \033[32m%d\033[0m'
+ + ' \033[90mtests\033[0m\n', count);
+}
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('../'),
+ Compiler = jade.Compiler,
+ render = jade.render,
+ nodes = jade.nodes;
+
+jade.filters.conditionals = function(block, compiler){
+ return new Visitor(block).compile();
+};
+
+function Visitor(node) {
+ this.node = node;
+}
+
+Visitor.prototype.__proto__ = Compiler.prototype;
+
+Visitor.prototype.visit = function(node){
+ if (node.name != 'else') this.line(node);
+ this.visitNode(node);
+};
+
+Visitor.prototype.visitTag = function(node){
+ switch (node.name) {
+ case 'if':
+ // First text -> line
+ var condition = node.text[0]
+ , block = node.block;
+ node = new nodes.Code('if (' + condition + ')');
+ node.block = block;
+ this.visit(node);
+ break;
+ case 'else':
+ var block = node.block;
+ node = new nodes.Code('else');
+ node.block = block;
+ node.instrumentLineNumber = false;
+ this.visit(node);
+ break;
+ default:
+ Compiler.prototype.visitTag.call(this, node);
+ }
+};
+
+module.exports = {
+ 'test :cdata filter': function(assert){
+ assert.equal('<![CDATA[\nfoo\n]]>', render(':cdata\n foo'));
+ assert.equal('<![CDATA[\nfoo\nbar\n]]>', render(':cdata\n foo\n bar'));
+ assert.equal('<![CDATA[\nfoo\nbar\n]]><p>something else</p>', render(':cdata\n foo\n bar\np something else'));
+ },
+
+ 'test :markdown filter': function(assert){
+ assert.equal(
+ '<h1>foo</h1>\n\n<ul><li>bar</li><li>baz</li></ul>',
+ render(':markdown\n #foo\n - bar\n - baz\n'))
+ },
+
+ 'test :stylus filter': function(assert){
+ assert.equal(
+ '<style>body {\n color: #c00;\n}\n</style>',
+ render(':stylus\n body\n color #c00'));
+ },
+
+ 'test :stylus filter with options': function(assert){
+ assert.equal(
+ '<style>body{color:#c00}\n</style>',
+ render(':stylus(compress=true)\n body\n color #c00'));
+ },
+
+ 'test :less filter': function(assert){
+ assert.equal(
+ '<style>.class {\n width: 20px;\n}\n</style>',
+ render(':less\n .class { width: 10px * 2 }\n'));
+ },
+
+ 'test :coffeescript filter': function(assert){
+ var coffee, js;
+ coffee = [
+ ':coffeescript',
+ ' square = (x) ->',
+ ' x * x'
+ ].join('\n');
+ js = [
+ '<script type="text/javascript">',
+ '(function() {',
+ ' var square;',
+ ' square = function(x) {',
+ ' return x * x;',
+ ' };',
+ '}).call(this);',
+ '</script>'
+ ].join('\n');
+
+ assert.equal(js, render(coffee));
+
+ coffee = [
+ ':coffeescript',
+ ' $ ->',
+ ' $("#flash").fadeIn ->',
+ ' console.log("first line")',
+ ' console.log("second line")'
+ ].join('\n');
+ js = [
+ '<script type="text/javascript">',
+ '(function() {',
+ ' $(function() {',
+ ' return $("#flash").fadeIn(function() {',
+ ' console.log("first line");',
+ ' return console.log("second line");',
+ ' });',
+ ' });',
+ '}).call(this);',
+ '</script>'
+ ].join('\n');
+
+ assert.equal(js, render(coffee));
+ },
+
+ 'test parse tree': function(assert){
+ var str = [
+ 'conditionals:',
+ ' if false',
+ ' | oh noes',
+ ' else',
+ ' if null == false',
+ ' p doh',
+ ' else',
+ ' p amazing!'
+ ].join('\n');
+
+ var html = [
+ '<p>amazing!</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ },
+
+ 'test filter attrs': function(assert){
+ jade.filters.testing = function(str, attrs){
+ return str + ' ' + attrs.stuff;
+ };
+
+ var str = [
+ ':testing(stuff)',
+ ' foo bar',
+ ].join('\n');
+
+ assert.equal('foo bar true', render(str));
+ }
+};
\ No newline at end of file
--- /dev/null
+ul
+ li= foo
+ li bar
\ No newline at end of file
--- /dev/null
+html
+ body
+ h1 Jade
\ No newline at end of file
--- /dev/null
+
+/**
+ * Module dependencies.
+ */
+
+var jade = require('../')
+ , ENOENT;
+
+// COMPAT:
+
+try {
+ ENOENT = require('constants').ENOENT;
+} catch (err) {
+ ENOENT = process.ENOENT;
+}
+
+// Shortcut
+
+var render = jade.render;
+
+module.exports = {
+ 'test .version': function(assert){
+ assert.ok(/^\d+\.\d+\.\d+$/.test(jade.version), "Invalid version format");
+ },
+
+ 'test exports': function(assert){
+ assert.equal('object', typeof jade.selfClosing, 'exports.selfClosing missing');
+ assert.equal('object', typeof jade.doctypes, 'exports.doctypes missing');
+ assert.equal('object', typeof jade.filters, 'exports.filters missing');
+ assert.equal('object', typeof jade.utils, 'exports.utils missing');
+ assert.equal('function', typeof jade.Compiler, 'exports.Compiler missing');
+ },
+
+ 'test doctypes': function(assert){
+ assert.equal('<?xml version="1.0" encoding="utf-8" ?>', render('!!! xml'));
+ assert.equal('<!DOCTYPE html>', render('doctype html'));
+ assert.equal('<!DOCTYPE html>', render('doctype HTML'));
+ assert.equal('<!DOCTYPE html>', render('!!! 5'));
+ assert.equal('<!DOCTYPE html>', render('!!!', { doctype:'html' }));
+ assert.equal('<!DOCTYPE html>', render('!!! html', { doctype:'xml' }));
+ assert.equal('<html></html>', render('html'));
+ assert.equal('<!DOCTYPE html><html></html>', render('html', { doctype:'html' }));
+ },
+
+ 'test Buffers': function(assert){
+ assert.equal('<p>foo</p>', render(new Buffer('p foo')));
+ },
+
+ 'test line endings': function(assert){
+ var str = [
+ 'p',
+ 'div',
+ 'img'
+ ].join('\r\n');
+
+ var html = [
+ '<p></p>',
+ '<div></div>',
+ '<img/>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'p',
+ 'div',
+ 'img'
+ ].join('\r');
+
+ var html = [
+ '<p></p>',
+ '<div></div>',
+ '<img/>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'p',
+ 'div',
+ 'img'
+ ].join('\r\n');
+
+ var html = [
+ '<p></p>',
+ '<div></div>',
+ '<img>'
+ ].join('');
+
+ assert.equal(html, render(str, { doctype:'html' }));
+ },
+
+ 'test single quotes': function(assert){
+ assert.equal("<p>'foo'</p>", render("p 'foo'"));
+ assert.equal("<p>'foo'\n</p>", render("p\n | 'foo'"));
+ assert.equal('<a href="/foo"></a>', render("- var path = 'foo';\na(href='/' + path)"));
+ },
+
+ 'test block-expansion': function(assert){
+ assert.equal("<li><a>foo</a></li><li><a>bar</a></li><li><a>baz</a></li>", render("li: a foo\nli: a bar\nli: a baz"));
+ assert.equal("<li class=\"first\"><a>foo</a></li><li><a>bar</a></li><li><a>baz</a></li>", render("li.first: a foo\nli: a bar\nli: a baz"));
+ },
+
+ 'test tags': function(assert){
+ var str = [
+ 'p',
+ 'div',
+ 'img'
+ ].join('\n');
+
+ var html = [
+ '<p></p>',
+ '<div></div>',
+ '<img/>'
+ ].join('');
+
+ assert.equal(html, render(str), 'Test basic tags');
+ assert.equal('<fb:foo-bar></fb:foo-bar>', render('fb:foo-bar'), 'Test hyphens');
+ assert.equal('<div class="something"></div>', render('div.something'), 'Test classes');
+ assert.equal('<div id="something"></div>', render('div#something'), 'Test ids');
+ assert.equal('<div class="something"></div>', render('.something'), 'Test stand-alone classes');
+ assert.equal('<div id="something"></div>', render('#something'), 'Test stand-alone ids');
+ assert.equal('<div id="foo" class="bar"></div>', render('#foo.bar'));
+ assert.equal('<div id="foo" class="bar"></div>', render('.bar#foo'));
+ assert.equal('<div id="foo" class="bar"></div>', render('div#foo(class="bar")'));
+ assert.equal('<div id="foo" class="bar"></div>', render('div(class="bar")#foo'));
+ assert.equal('<div id="bar" class="foo"></div>', render('div(id="bar").foo'));
+ assert.equal('<div class="foo bar baz"></div>', render('div.foo.bar.baz'));
+ assert.equal('<div class="foo bar baz"></div>', render('div(class="foo").bar.baz'));
+ assert.equal('<div class="foo bar baz"></div>', render('div.foo(class="bar").baz'));
+ assert.equal('<div class="foo bar baz"></div>', render('div.foo.bar(class="baz")'));
+ assert.equal('<div class="a-b2"></div>', render('div.a-b2'));
+ assert.equal('<div class="a_b2"></div>', render('div.a_b2'));
+ assert.equal('<fb:user></fb:user>', render('fb:user'));
+ assert.equal('<fb:user:role></fb:user:role>', render('fb:user:role'));
+ assert.equal('<colgroup><col class="test"/></colgroup>', render('colgroup\n col.test'));
+ },
+
+ 'test nested tags': function(assert){
+ var str = [
+ 'ul',
+ ' li a',
+ ' li b',
+ ' li',
+ ' ul',
+ ' li c',
+ ' li d',
+ ' li e',
+ ].join('\n');
+
+ var html = [
+ '<ul>',
+ '<li>a</li>',
+ '<li>b</li>',
+ '<li><ul><li>c</li><li>d</li></ul></li>',
+ '<li>e</li>',
+ '</ul>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'a(href="#")',
+ ' | foo ',
+ ' | bar ',
+ ' | baz'
+ ].join('\n');
+
+ assert.equal('<a href="#">foo \nbar \nbaz\n</a>', render(str));
+
+ var str = [
+ 'ul',
+ ' li one',
+ ' ul',
+ ' | two',
+ ' li three'
+ ].join('\n');
+
+ var html = [
+ '<ul>',
+ '<li>one</li>',
+ '<ul>two\n',
+ '<li>three</li>',
+ '</ul>',
+ '</ul>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ },
+
+ 'test variable length newlines': function(assert){
+ var str = [
+ 'ul',
+ ' li a',
+ ' ',
+ ' li b',
+ ' ',
+ ' ',
+ ' li',
+ ' ul',
+ ' li c',
+ '',
+ ' li d',
+ ' li e',
+ ].join('\n');
+
+ var html = [
+ '<ul>',
+ '<li>a</li>',
+ '<li>b</li>',
+ '<li><ul><li>c</li><li>d</li></ul></li>',
+ '<li>e</li>',
+ '</ul>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ },
+
+ 'test tab conversion': function(assert){
+ var str = [
+ 'ul',
+ '\tli a',
+ '\t',
+ '\tli b',
+ '\t\t',
+ '\t\t\t\t\t\t',
+ '\tli',
+ '\t\tul',
+ '\t\t\tli c',
+ '',
+ '\t\t\tli d',
+ '\tli e',
+ ].join('\n');
+
+ var html = [
+ '<ul>',
+ '<li>a</li>',
+ '<li>b</li>',
+ '<li><ul><li>c</li><li>d</li></ul></li>',
+ '<li>e</li>',
+ '</ul>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ },
+
+ 'test newlines': function(assert){
+ var str = [
+ 'ul',
+ ' li a',
+ ' ',
+ ' ',
+ '',
+ ' ',
+ ' li b',
+ ' li',
+ ' ',
+ ' ',
+ ' ',
+ ' ul',
+ ' ',
+ ' li c',
+ ' li d',
+ ' li e',
+ ].join('\n');
+
+ var html = [
+ '<ul>',
+ '<li>a</li>',
+ '<li>b</li>',
+ '<li><ul><li>c</li><li>d</li></ul></li>',
+ '<li>e</li>',
+ '</ul>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'html',
+ ' ',
+ ' head',
+ ' != "test"',
+ ' ',
+ ' ',
+ ' ',
+ ' body'
+ ].join('\n');
+
+ var html = [
+ '<html>',
+ '<head>',
+ 'test',
+ '</head>',
+ '<body></body>',
+ '</html>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ assert.equal('<foo></foo>something<bar></bar>', render('foo\n= "something"\nbar'));
+ assert.equal('<foo></foo>something<bar></bar>else', render('foo\n= "something"\nbar\n= "else"'));
+ },
+
+ 'test cache': function(assert){
+ var err;
+ try {
+ render('foo', { cache: true });
+ } catch (e) {
+ err = e;
+ }
+ assert.equal('filename is required when using the cache option', err.message);
+
+ assert.equal('<p></p>', render('p', { cache: true, filename: 'foo.jade' }));
+ assert.equal('<p></p>', render('p', { cache: true, filename: 'foo.jade' }));
+ assert.ok(typeof jade.cache['foo.jade'] === 'function', 'Test cache');
+ },
+
+ 'test text': function(assert){
+ assert.equal('foo\nbar\nbaz\n', render('| foo\n| bar\n| baz'));
+ assert.equal('foo \nbar \nbaz\n', render('| foo \n| bar \n| baz'));
+ assert.equal('(hey)\n', render('| (hey)'));
+ assert.equal('some random text\n', render('| some random text'));
+ assert.equal(' foo\n', render('| foo'));
+ assert.equal(' foo \n', render('| foo '));
+ assert.equal(' foo \n bar \n', render('| foo \n| bar '));
+ },
+
+ 'test pipe-less text': function(assert){
+ assert.equal('<pre><code>foo\n\nbar\n</code></pre>', render('pre\n code\n foo\n\n bar'));
+ assert.equal('<p>foo\n\nbar\n</p>', render('p.\n foo\n\n bar'));
+ assert.equal('<p>foo\n\n\n\nbar\n</p>', render('p.\n foo\n\n\n\n bar'));
+ assert.equal('<p>foo\n bar\nfoo\n</p>', render('p.\n foo\n bar\n foo'));
+ assert.equal('<script>s.parentNode.insertBefore(g,s)\n</script>', render('script\n s.parentNode.insertBefore(g,s)\n'));
+ assert.equal('<script>s.parentNode.insertBefore(g,s)\n</script>', render('script\n s.parentNode.insertBefore(g,s)'));
+ },
+
+ 'test tag text': function(assert){
+ assert.equal('<p>some random text</p>', render('p some random text'));
+ assert.equal('<p>click\n<a>Google</a>.\n</p>', render('p\n | click\n a Google\n | .'));
+ assert.equal('<p>(parens)</p>', render('p (parens)'));
+ assert.equal('<p foo="bar">(parens)</p>', render('p(foo="bar") (parens)'));
+ assert.equal('<option value="">-- (optional) foo --</option>', render('option(value="") -- (optional) foo --'));
+ },
+
+ 'test tag text block': function(assert){
+ assert.equal('<p>foo \nbar \nbaz\n</p>', render('p\n | foo \n | bar \n | baz'));
+ assert.equal('<label>Password:\n<input/></label>', render('label\n | Password:\n input'));
+ assert.equal('<label>Password:<input/></label>', render('label Password:\n input'));
+ },
+
+ 'test tag text interpolation': function(assert){
+ assert.equal('yo, jade is cool\n', render('| yo, #{name} is cool\n', { locals: { name: 'jade' }}));
+ assert.equal('<p>yo, jade is cool</p>', render('p yo, #{name} is cool', { locals: { name: 'jade' }}));
+ assert.equal('yo, jade is cool\n', render('| yo, #{name || "jade"} is cool', { locals: { name: null }}));
+ assert.equal('yo, \'jade\' is cool\n', render('| yo, #{name || "\'jade\'"} is cool', { locals: { name: null }}));
+ assert.equal('foo <script> bar\n', render('| foo #{code} bar', { locals: { code: '<script>' }}));
+ assert.equal('foo <script> bar\n', render('| foo !{code} bar', { locals: { code: '<script>' }}));
+ },
+
+ 'test flexible indentation': function(assert){
+ assert.equal('<html><body><h1>Wahoo</h1><p>test</p></body></html>', render('html\n body\n h1 Wahoo\n p test'));
+ },
+
+ 'test interpolation values': function(assert){
+ assert.equal('<p>Users: 15</p>', render('p Users: #{15}'));
+ assert.equal('<p>Users: </p>', render('p Users: #{null}'));
+ assert.equal('<p>Users: </p>', render('p Users: #{undefined}'));
+ assert.equal('<p>Users: none</p>', render('p Users: #{undefined || "none"}'));
+ assert.equal('<p>Users: 0</p>', render('p Users: #{0}'));
+ assert.equal('<p>Users: false</p>', render('p Users: #{false}'));
+ },
+
+ 'test html 5 mode': function(assert){
+ assert.equal('<!DOCTYPE html><input type="checkbox" checked>', render('!!! 5\ninput(type="checkbox", checked)'));
+ assert.equal('<!DOCTYPE html><input type="checkbox" checked>', render('!!! 5\ninput(type="checkbox", checked=true)'));
+ assert.equal('<!DOCTYPE html><input type="checkbox">', render('!!! 5\ninput(type="checkbox", checked= false)'));
+ },
+
+ 'test multi-line attrs': function(assert){
+ assert.equal('<a foo="bar" bar="baz" checked="checked">foo</a>', render('a(foo="bar"\n bar="baz"\n checked) foo'));
+ assert.equal('<a foo="bar" bar="baz" checked="checked">foo</a>', render('a(foo="bar"\nbar="baz"\nchecked) foo'));
+ assert.equal('<a foo="bar" bar="baz" checked="checked">foo</a>', render('a(foo="bar"\n,bar="baz"\n,checked) foo'));
+ assert.equal('<a foo="bar" bar="baz" checked="checked">foo</a>', render('a(foo="bar",\nbar="baz",\nchecked) foo'));
+ },
+
+ 'test attrs': function(assert){
+ assert.equal('<img src="<script>"/>', render('img(src="<script>")'), 'Test attr escaping');
+
+ assert.equal('<a data-attr="bar"></a>', render('a(data-attr="bar")'));
+ assert.equal('<a data-attr="bar" data-attr-2="baz"></a>', render('a(data-attr="bar", data-attr-2="baz")'));
+
+ assert.equal('<a title="foo,bar"></a>', render('a(title= "foo,bar")'));
+ assert.equal('<a title="foo,bar" href="#"></a>', render('a(title= "foo,bar", href="#")'));
+
+ assert.equal('<p class="foo"></p>', render("p(class='foo')"), 'Test single quoted attrs');
+ assert.equal('<input type="checkbox" checked="checked"/>', render('input( type="checkbox", checked )'));
+ assert.equal('<input type="checkbox" checked="checked"/>', render('input( type="checkbox", checked = true )'));
+ assert.equal('<input type="checkbox"/>', render('input(type="checkbox", checked= false)'));
+ assert.equal('<input type="checkbox"/>', render('input(type="checkbox", checked= null)'));
+ assert.equal('<input type="checkbox"/>', render('input(type="checkbox", checked= undefined)'));
+
+ assert.equal('<img src="/foo.png"/>', render('img(src="/foo.png")'), 'Test attr =');
+ assert.equal('<img src="/foo.png"/>', render('img(src = "/foo.png")'), 'Test attr = whitespace');
+ assert.equal('<img src="/foo.png"/>', render('img(src="/foo.png")'), 'Test attr :');
+ assert.equal('<img src="/foo.png"/>', render('img(src = "/foo.png")'), 'Test attr : whitespace');
+
+ assert.equal('<img src="/foo.png" alt="just some foo"/>', render('img(src="/foo.png", alt="just some foo")'));
+ assert.equal('<img src="/foo.png" alt="just some foo"/>', render('img(src = "/foo.png", alt = "just some foo")'));
+
+ assert.equal('<p class="foo,bar,baz"></p>', render('p(class="foo,bar,baz")'));
+ assert.equal('<a href="http://google.com" title="Some : weird = title"></a>', render('a(href= "http://google.com", title= "Some : weird = title")'));
+ assert.equal('<label for="name"></label>', render('label(for="name")'));
+ assert.equal('<meta name="viewport" content="width=device-width"/>', render("meta(name= 'viewport', content='width=device-width')"), 'Test attrs that contain attr separators');
+ assert.equal('<div style="color= white"></div>', render("div(style='color= white')"));
+ assert.equal('<div style="color: white"></div>', render("div(style='color: white')"));
+ assert.equal('<p class="foo"></p>', render("p('class'='foo')"), 'Test keys with single quotes');
+ assert.equal('<p class="foo"></p>', render("p(\"class\"= 'foo')"), 'Test keys with double quotes');
+
+ assert.equal('<p data-lang="en"></p>', render('p(data-lang = "en")'));
+ assert.equal('<p data-dynamic="true"></p>', render('p("data-dynamic"= "true")'));
+ assert.equal('<p data-dynamic="true" class="name"></p>', render('p("class"= "name", "data-dynamic"= "true")'));
+ assert.equal('<p data-dynamic="true"></p>', render('p(\'data-dynamic\'= "true")'));
+ assert.equal('<p data-dynamic="true" class="name"></p>', render('p(\'class\'= "name", \'data-dynamic\'= "true")'));
+ assert.equal('<p data-dynamic="true" yay="yay" class="name"></p>', render('p(\'class\'= "name", \'data-dynamic\'= "true", yay)'));
+
+ assert.equal('<input checked="checked" type="checkbox"/>', render('input(checked, type="checkbox")'));
+
+ assert.equal('<a data-foo="{ foo: \'bar\', bar= \'baz\' }"></a>', render('a(data-foo = "{ foo: \'bar\', bar= \'baz\' }")'));
+
+ assert.equal('<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>', render('meta(http-equiv="X-UA-Compatible", content="IE=edge,chrome=1")'));
+
+ assert.equal('<div style="background: url(/images/test.png)">Foo</div>', render("div(style= 'background: url(/images/test.png)') Foo"));
+ assert.equal('<div style="background = url(/images/test.png)">Foo</div>', render("div(style= 'background = url(/images/test.png)') Foo"));
+ assert.equal('<div style="foo">Foo</div>', render("div(style= ['foo', 'bar'][0]) Foo"));
+ assert.equal('<div style="bar">Foo</div>', render("div(style= { foo: 'bar', baz: 'raz' }['foo']) Foo"));
+ assert.equal('<a href="def">Foo</a>', render("a(href='abcdefg'.substr(3,3)) Foo"));
+ assert.equal('<a href="def">Foo</a>', render("a(href={test: 'abcdefg'}.test.substr(3,3)) Foo"));
+ assert.equal('<a href="def">Foo</a>', render("a(href={test: 'abcdefg'}.test.substr(3,[0,3][1])) Foo"));
+
+ assert.equal('<rss xmlns:atom="atom"></rss>', render("rss(xmlns:atom=\"atom\")"));
+ assert.equal('<rss xmlns:atom="atom"></rss>', render("rss('xmlns:atom'=\"atom\")"));
+ assert.equal('<rss xmlns:atom="atom"></rss>', render("rss(\"xmlns:atom\"='atom')"));
+ assert.equal('<rss xmlns:atom="atom" foo="bar"></rss>', render("rss('xmlns:atom'=\"atom\", 'foo'= 'bar')"));
+ assert.equal('<a data-obj="{ foo: \'bar\' }"></a>', render("a(data-obj= \"{ foo: 'bar' }\")"));
+
+ assert.equal('<meta content="what\'s up? \'weee\'"/>', render('meta(content="what\'s up? \'weee\'")'));
+ },
+
+ 'test class attr array': function(assert){
+ assert.equal('<body class="foo bar baz"></body>', render('body(class=["foo", "bar", "baz"])'));
+ },
+
+ 'test attr interpolation': function(assert){
+ // Test single quote interpolation
+ assert.equal('<a href="/user/12">tj</a>'
+ , render("a(href='/user/#{id}') #{name}", { locals: { name: 'tj', id: 12 }}));
+
+ assert.equal('<a href="/user/12-tj">tj</a>'
+ , render("a(href='/user/#{id}-#{name}') #{name}", { locals: { name: 'tj', id: 12 }}));
+
+ assert.equal('<a href="/user/<script>">tj</a>'
+ , render("a(href='/user/#{id}') #{name}", { locals: { name: 'tj', id: '<script>' }}));
+
+ // Test double quote interpolation
+ assert.equal('<a href="/user/13">ds</a>'
+ , render('a(href="/user/#{id}") #{name}', { locals: { name: 'ds', id: 13 }}));
+
+ assert.equal('<a href="/user/13-ds">ds</a>'
+ , render('a(href="/user/#{id}-#{name}") #{name}', { locals: { name: 'ds', id: 13 }}));
+
+ assert.equal('<a href="/user/<script>">ds</a>'
+ , render('a(href="/user/#{id}") #{name}', { locals: { name: 'ds', id: '<script>' }}));
+ },
+
+ 'test attr parens': function(assert){
+ assert.equal('<p foo="bar">baz</p>', render('p(foo=((("bar"))))= ((("baz")))'));
+ },
+
+ 'test code attrs': function(assert){
+ assert.equal('<p></p>', render('p(id= name)', { locals: { name: undefined }}));
+ assert.equal('<p></p>', render('p(id= name)', { locals: { name: null }}));
+ assert.equal('<p></p>', render('p(id= name)', { locals: { name: false }}));
+ assert.equal('<p id=""></p>', render('p(id= name)', { locals: { name: '' }}));
+ assert.equal('<p id="tj"></p>', render('p(id= name)', { locals: { name: 'tj' }}));
+ assert.equal('<p id="default"></p>', render('p(id= name || "default")', { locals: { name: null }}));
+ assert.equal('<p id="something"></p>', render("p(id= 'something')", { locals: { name: null }}));
+ assert.equal('<p id="something"></p>', render("p(id = 'something')", { locals: { name: null }}));
+ assert.equal('<p id="foo"></p>', render("p(id= (true ? 'foo' : 'bar'))"));
+ assert.equal('<option value="">Foo</option>', render("option(value='') Foo"));
+ },
+
+ 'test code attrs class': function(assert){
+ assert.equal('<p class="tj"></p>', render('p(class= name)', { locals: { name: 'tj' }}));
+ assert.equal('<p class="tj"></p>', render('p( class= name )', { locals: { name: 'tj' }}));
+ assert.equal('<p class="default"></p>', render('p(class= name || "default")', { locals: { name: null }}));
+ assert.equal('<p class="foo default"></p>', render('p.foo(class= name || "default")', { locals: { name: null }}));
+ assert.equal('<p class="default foo"></p>', render('p(class= name || "default").foo', { locals: { name: null }}));
+ assert.equal('<p id="default"></p>', render('p(id = name || "default")', { locals: { name: null }}));
+ assert.equal('<p id="user-1"></p>', render('p(id = "user-" + 1)'));
+ assert.equal('<p class="user-1"></p>', render('p(class = "user-" + 1)'));
+ },
+
+ 'test code buffering': function(assert){
+ assert.equal('<p></p>', render('p= null'));
+ assert.equal('<p></p>', render('p= undefined'));
+ assert.equal('<p>0</p>', render('p= 0'));
+ assert.equal('<p>false</p>', render('p= false'));
+ },
+
+ 'test comments': function(assert){
+ // Regular
+ var str = [
+ '//foo',
+ 'p bar'
+ ].join('\n');
+
+ var html = [
+ '<!--foo-->',
+ '<p>bar</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ // Arbitrary indentation
+
+ var str = [
+ ' //foo',
+ 'p bar'
+ ].join('\n');
+
+ var html = [
+ '<!--foo-->',
+ '<p>bar</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ // Between tags
+
+ var str = [
+ 'p foo',
+ '// bar ',
+ 'p baz'
+ ].join('\n');
+
+ var html = [
+ '<p>foo</p>',
+ '<!-- bar -->',
+ '<p>baz</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ // Quotes
+
+ var str = "<!-- script(src: '/js/validate.js') -->",
+ js = "// script(src: '/js/validate.js') ";
+ assert.equal(str, render(js));
+ },
+
+ 'test unbuffered comments': function(assert){
+ var str = [
+ '//- foo',
+ 'p bar'
+ ].join('\n');
+
+ var html = [
+ '<p>bar</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'p foo',
+ '//- bar ',
+ 'p baz'
+ ].join('\n');
+
+ var html = [
+ '<p>foo</p>',
+ '<p>baz</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ },
+
+ 'test literal html': function(assert){
+ assert.equal('<!--[if IE lt 9]>weeee<![endif]-->\n', render('<!--[if IE lt 9]>weeee<![endif]-->'));
+ },
+
+ 'test code': function(assert){
+ assert.equal('test', render('!= "test"'));
+ assert.equal('test', render('= "test"'));
+ assert.equal('test', render('- var foo = "test"\n=foo'));
+ assert.equal('foo\n<em>test</em>bar\n', render('- var foo = "test"\n| foo\nem= foo\n| bar'));
+ assert.equal('test<h2>something</h2>', render('!= "test"\nh2 something'));
+
+ var str = [
+ '- var foo = "<script>";',
+ '= foo',
+ '!= foo'
+ ].join('\n');
+
+ var html = [
+ '<script>',
+ '<script>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ '- var foo = "<script>";',
+ '- if (foo)',
+ ' p= foo'
+ ].join('\n');
+
+ var html = [
+ '<p><script></p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ '- var foo = "<script>";',
+ '- if (foo)',
+ ' p!= foo'
+ ].join('\n');
+
+ var html = [
+ '<p><script></p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ '- var foo;',
+ '- if (foo)',
+ ' p.hasFoo= foo',
+ '- else',
+ ' p.noFoo no foo'
+ ].join('\n');
+
+ var html = [
+ '<p class="noFoo">no foo</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ '- var foo;',
+ '- if (foo)',
+ ' p.hasFoo= foo',
+ '- else if (true)',
+ ' p kinda foo',
+ '- else',
+ ' p.noFoo no foo'
+ ].join('\n');
+
+ var html = [
+ '<p>kinda foo</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'p foo',
+ '= "bar"',
+ ].join('\n');
+
+ var html = [
+ '<p>foo</p>bar'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'title foo',
+ '- if (true)',
+ ' p something',
+ ].join('\n');
+
+ var html = [
+ '<title>foo</title><p>something</p>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ var str = [
+ 'foo',
+ ' bar= "bar"',
+ ' baz= "baz"',
+ ].join('\n');
+
+ var html = [
+ '<foo>',
+ '<bar>bar',
+ '<baz>baz</baz>',
+ '</bar>',
+ '</foo>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ },
+
+ 'test - each': function(assert){
+ // Array
+ var str = [
+ '- var items = ["one", "two", "three"];',
+ '- each item in items',
+ ' li= item'
+ ].join('\n');
+
+ var html = [
+ '<li>one</li>',
+ '<li>two</li>',
+ '<li>three</li>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ // Any enumerable (length property)
+ var str = [
+ '- var jQuery = { length: 3, 0: 1, 1: 2, 2: 3 };',
+ '- each item in jQuery',
+ ' li= item'
+ ].join('\n');
+
+ var html = [
+ '<li>1</li>',
+ '<li>2</li>',
+ '<li>3</li>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ // Empty array
+ var str = [
+ '- var items = [];',
+ '- each item in items',
+ ' li= item'
+ ].join('\n');
+
+ assert.equal('', render(str));
+
+ // Object
+ var str = [
+ '- var obj = { foo: "bar", baz: "raz" };',
+ '- each val in obj',
+ ' li= val'
+ ].join('\n');
+
+ var html = [
+ '<li>bar</li>',
+ '<li>raz</li>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ // Complex
+ var str = [
+ '- var obj = { foo: "bar", baz: "raz" };',
+ '- each key in Object.keys(obj)',
+ ' li= key'
+ ].join('\n');
+
+ var html = [
+ '<li>foo</li>',
+ '<li>baz</li>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ // Keys
+ var str = [
+ '- var obj = { foo: "bar", baz: "raz" };',
+ '- each val, key in obj',
+ ' li #{key}: #{val}'
+ ].join('\n');
+
+ var html = [
+ '<li>foo: bar</li>',
+ '<li>baz: raz</li>'
+ ].join('');
+
+ assert.equal(html, render(str));
+
+ // Nested
+ var str = [
+ '- var users = [{ name: "tj" }]',
+ '- each user in users',
+ ' - each val, key in user',
+ ' li #{key} #{val}',
+ ].join('\n');
+
+ var html = [
+ '<li>name tj</li>'
+ ].join('');
+
+ assert.equal(html, render(str));
+ },
+
+ 'test renderFile() fs exception': function(assert, beforeExit){
+ var called;
+ jade.renderFile('foo', function(err, str){
+ called = true;
+ assert.equal(ENOENT, err.errno);
+ assert.equal(undefined, str);
+ });
+ beforeExit(function(){
+ assert.ok(called);
+ });
+ },
+
+ 'test renderFile() with valid path': function(assert, beforeExit){
+ var called;
+ jade.renderFile(__dirname + '/fixtures/layout.jade', function(err, str){
+ called = true;
+ assert.equal(null, err);
+ assert.equal('<html><body><h1>Jade</h1></body></html>', str);
+ });
+ beforeExit(function(){
+ assert.ok(called);
+ });
+ },
+
+ 'test renderFile() with options': function(assert, beforeExit){
+ var called = 0;
+ jade.renderFile(__dirname + '/fixtures/layout.jade', { cache: true }, function(err, str){
+ ++called;
+ assert.equal(null, err);
+ assert.equal('<html><body><h1>Jade</h1></body></html>', str);
+
+ jade.renderFile(__dirname + '/fixtures/layout.jade', { cache: true }, function(err, str){
+ ++called;
+ assert.equal(null, err);
+ assert.equal('<html><body><h1>Jade</h1></body></html>', str);
+ });
+ });
+ beforeExit(function(){
+ assert.equal(2, called);
+ });
+ },
+
+ 'test renderFile() passing of exceptions': function(assert, beforeExit){
+ var called = 0;
+ jade.renderFile(__dirname + '/fixtures/invalid.jade', { cache: true }, function(err, str){
+ ++called;
+ assert.ok(typeof err.message === 'string', 'Test passing of exceptions to renderFile() callback');
+ assert.equal(undefined, str);
+ });
+ beforeExit(function(){
+ assert.equal(1, called);
+ });
+ },
+
+ 'test .compile()': function(assert){
+ var fn = jade.compile('p foo');
+ assert.equal('<p>foo</p>', fn());
+ },
+
+ 'test .compile() locals': function(assert){
+ var fn = jade.compile('p= foo');
+ assert.equal('<p>bar</p>', fn({ foo: 'bar' }));
+ },
+
+ 'test .compile() scope': function(assert){
+ var fn = jade.compile('p= this.foo');
+ assert.equal('<p>bar</p>', fn.call({ foo: 'bar' }));
+ },
+
+ 'test null attrs on tag': function(assert){
+ var tag = new jade.nodes.Tag('a'),
+ name = 'href',
+ val = '"/"';
+ tag.setAttribute(name, val)
+ assert.equal(tag.getAttribute(name), val)
+ tag.removeAttribute(name)
+ assert.isUndefined(tag.getAttribute(name))
+ }
+};