Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

7972 lines (7332 sloc) 512.929 kb
<a href="http://github.com/learnboost/stylus"><img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a><html>
<head>
<title>Stylus</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>Stylus</h1><p>Expressive, dynamic, robust CSS for nodejs</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/colors.js"><a href="#">colors</a></h2></td><td>lib/colors.js</td></tr><tr class="code">
<td class="docs">
<p>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]
};</p>
</td>
<td class="code">
</td>
</tr><tr class="filename"><td><h2 id="lib/convert/css.js"><a href="#">css</a></h2></td><td>lib/convert/css.js</td></tr><tr class="code">
<td class="docs">
<p>Convert the given <code>css</code> to stylus source.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> css</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span>(<span class="variable">css</span>){
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Converter</span>(<span class="variable">css</span>).<span class="variable">stylus</span>();
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a new <code>Converter</code> with the given <code>css</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> css</p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">function</span> <span class="class">Converter</span>(<span class="variable">css</span>) {
<span class="keyword">var</span> <span class="variable">cssom</span> = <span class="variable">require</span>(<span class="string">'cssom'</span>);
<span class="this">this</span>.<span class="variable">css</span> = <span class="variable">css</span>;
<span class="this">this</span>.<span class="variable">types</span> = <span class="variable">cssom</span>.<span class="class">CSSRule</span>;
<span class="this">this</span>.<span class="variable">root</span> = <span class="variable">cssom</span>.<span class="variable">parse</span>(<span class="variable">css</span>);
<span class="this">this</span>.<span class="variable">indents</span> = <span class="number integer">0</span>;
}</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Convert to stylus.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Converter</span>.<span class="variable">prototype</span>.<span class="variable">stylus</span> = <span class="keyword">function</span>(){
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">visitRules</span>(<span class="this">this</span>.<span class="variable">root</span>.<span class="variable">cssRules</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return indent string.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Converter</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'indent'</span>, <span class="keyword">function</span>(){
<span class="keyword">return</span> <span class="class">Array</span>(<span class="this">this</span>.<span class="variable">indents</span> + <span class="number integer">1</span>).<span class="variable">join</span>(<span class="string">' '</span>);
});</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Visit <code>node</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>CSSRule</em> node</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Converter</span>.<span class="variable">prototype</span>.<span class="variable">visit</span> = <span class="keyword">function</span>(<span class="variable">node</span>){
<span class="keyword">switch</span> (<span class="variable">node</span>.<span class="variable">type</span>) {
<span class="keyword">case</span> <span class="this">this</span>.<span class="variable">types</span>.<span class="class">STYLE_RULE</span>:
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">visitStyle</span>(<span class="variable">node</span>);
<span class="keyword">case</span> <span class="this">this</span>.<span class="variable">types</span>.<span class="class">MEDIA_RULE</span>:
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">visitMedia</span>(<span class="variable">node</span>);
}
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Visit the rules on <code>node</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>CSSRule</em> node</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Converter</span>.<span class="variable">prototype</span>.<span class="variable">visitRules</span> = <span class="keyword">function</span>(<span class="variable">node</span>){
<span class="keyword">var</span> <span class="variable">buf</span> = <span class="string">''</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">node</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="variable">buf</span> += <span class="this">this</span>.<span class="variable">visit</span>(<span class="variable">node</span>[<span class="variable">i</span>]);
}
<span class="keyword">return</span> <span class="variable">buf</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Visit CSSMediaRule <code>node</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>CSSMediaRule</em> node</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Converter</span>.<span class="variable">prototype</span>.<span class="variable">visitMedia</span> = <span class="keyword">function</span>(<span class="variable">node</span>){
<span class="keyword">var</span> <span class="variable">buf</span> = <span class="this">this</span>.<span class="variable">indent</span> + <span class="string">'@media '</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">node</span>.<span class="variable">media</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="variable">buf</span> += <span class="variable">node</span>.<span class="variable">media</span>[<span class="variable">i</span>];
}
<span class="variable">buf</span> += <span class="string">'\n'</span>;
++<span class="this">this</span>.<span class="variable">indents</span>;
<span class="variable">buf</span> += <span class="this">this</span>.<span class="variable">visitRules</span>(<span class="variable">node</span>.<span class="variable">cssRules</span>);
--<span class="this">this</span>.<span class="variable">indents</span>;
<span class="keyword">return</span> <span class="variable">buf</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Visit CSSStyleRule <code>node</code>.`</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>CSSStyleRule</em> node</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="class">Converter</span>.<span class="variable">prototype</span>.<span class="variable">visitStyle</span> = <span class="keyword">function</span>(<span class="variable">node</span>){
<span class="keyword">var</span> <span class="variable">buf</span> = <span class="this">this</span>.<span class="variable">indent</span> + <span class="variable">node</span>.<span class="variable">selectorText</span> + <span class="string">'\n'</span>;
++<span class="this">this</span>.<span class="variable">indents</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">node</span>.<span class="variable">style</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">prop</span> = <span class="variable">node</span>.<span class="variable">style</span>[<span class="variable">i</span>]
, <span class="variable">val</span> = <span class="variable">node</span>.<span class="variable">style</span>[<span class="variable">prop</span>];
<span class="keyword">if</span> (<span class="variable">prop</span>) {
<span class="variable">buf</span> += <span class="this">this</span>.<span class="variable">indent</span> + <span class="variable">prop</span> + <span class="string">' '</span> + <span class="variable">val</span> + <span class="string">'\n'</span>;
}
}
--<span class="this">this</span>.<span class="variable">indents</span>;
<span class="keyword">return</span> <span class="variable">buf</span> + <span class="string">'\n'</span>;
};</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/functions/index.js"><a href="#">index</a></h2></td><td>lib/functions/index.js</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">nodes</span> = <span class="variable">require</span>(<span class="string">'../nodes'</span>)
, <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'../utils'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Convert the given <code>color</code> to an <code>HSLA</code> node,
or h,s,l,a component values.</p>
<h2>Examples</h2>
<p> hsla(10deg, 50%, 30%, 0.5)
// =&gt; HSLA</p>
<p> hsla(#ffcc00)
// =&gt; HSLA</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | Unit</em> h</p></li><li><p><strong>param</strong>: <em>Unit</em> s</p></li><li><p><strong>param</strong>: <em>Unit</em> l</p></li><li><p><strong>param</strong>: <em>Unit</em> a</p></li><li><p><strong>return</strong>: <em>HSLA</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">hsla</span> = <span class="keyword">function</span>(<span class="variable">h</span>,<span class="variable">s</span>,<span class="variable">l</span>,<span class="variable">a</span>){
<span class="keyword">switch</span> (<span class="variable">arguments</span>.<span class="variable">length</span>) {
<span class="keyword">case</span> <span class="number integer">1</span>:
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">h</span>);
<span class="keyword">return</span> <span class="variable">h</span>.<span class="variable">hsl</span>;
<span class="keyword">default</span>:
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">h</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'hue'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">s</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'saturation'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">l</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'lightness'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">a</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'alpha'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">HSLA</span>(<span class="variable">h</span>.<span class="variable">val</span>,<span class="variable">s</span>.<span class="variable">val</span>,<span class="variable">l</span>.<span class="variable">val</span>,<span class="variable">a</span>.<span class="variable">val</span>);
}
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Convert the given <code>color</code> to an <code>HSLA</code> node,
or h,s,l component values.</p>
<h2>Examples</h2>
<p> hsl(10, 50, 30)
// =&gt; HSLA</p>
<p> hsl(#ffcc00)
// =&gt; HSLA</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | Unit | HSLA</em> h</p></li><li><p><strong>param</strong>: <em>Unit</em> s</p></li><li><p><strong>param</strong>: <em>Unit</em> l</p></li><li><p><strong>return</strong>: <em>HSLA</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">hsl</span> = <span class="keyword">function</span>(<span class="variable">h</span>,<span class="variable">s</span>,<span class="variable">l</span>){
<span class="keyword">if</span> (<span class="variable">arguments</span>.<span class="variable">length</span> &<span class="variable">gt</span>; <span class="number integer">1</span>) {
<span class="keyword">return</span> <span class="variable">exports</span>.<span class="variable">hsla</span>(<span class="variable">h</span>,<span class="variable">s</span>,<span class="variable">l</span>,<span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="number integer">1</span>));
}
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">h</span>, <span class="string">'color'</span>);
<span class="keyword">return</span> <span class="variable">h</span>.<span class="variable">hsl</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return type of <code>node</code>.</p>
<h2>Examples</h2>
<p> type(12)
// =&gt; 'unit'</p>
<p> type(#fff)
// =&gt; 'color'</p>
<p> type(type)
// =&gt; 'function'</p>
<p> type(unbound)
typeof(unbound)
type-of(unbound)
// =&gt; 'ident'</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Node</em> node</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">type</span> =
<span class="variable">exports</span>.<span class="keyword">typeof</span> =
<span class="variable">exports</span>[<span class="string">'type-of'</span>] = <span class="keyword">function</span>(<span class="variable">node</span>){
<span class="variable">utils</span>.<span class="variable">assertPresent</span>(<span class="variable">node</span>, <span class="string">'expression'</span>);
<span class="keyword">var</span> <span class="variable">type</span> = <span class="variable">node</span>.<span class="variable">nodeName</span>;
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">String</span>(<span class="variable">type</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the hue of the given <code>color</code>.</p>
<h2>Examples</h2>
<p> hue(hsl(50deg, 100%, 80%))
// =&gt; 50deg</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>HSLA | Color</em> color</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">hue</span> = <span class="keyword">function</span>(<span class="variable">color</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'hue'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="class">Math</span>.<span class="variable">round</span>(<span class="variable">color</span>.<span class="variable">hsl</span>.<span class="variable">h</span>), <span class="string">'deg'</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the saturation of the given <code>color</code>.</p>
<h2>Examples</h2>
<p> saturation(hsl(50deg, 100%, 80%))
// =&gt; 100%</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>HSLA | Color</em> color</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">saturation</span> = <span class="keyword">function</span>(<span class="variable">color</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'saturation'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="class">Math</span>.<span class="variable">round</span>(<span class="variable">color</span>.<span class="variable">hsl</span>.<span class="variable">s</span>), <span class="string">'%'</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the lightness of the given <code>color</code>.</p>
<h2>Examples</h2>
<p> lightness(hsl(50def, 100%, 80%))
// =&gt; 80%</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>HSLA | Color</em> color</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">lightness</span> = <span class="keyword">function</span>(<span class="variable">color</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'lightness'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="class">Math</span>.<span class="variable">round</span>(<span class="variable">color</span>.<span class="variable">hsl</span>.<span class="variable">l</span>), <span class="string">'%'</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the alpha component of the given <code>color</code>.</p>
<h2>Examples</h2>
<p> alpha(#fff)
// =&gt; 1</p>
<p> alpha(rgba(0,0,0,0.3))
// =&gt; 0.3</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | HSLA</em> color</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">alpha</span> = <span class="keyword">function</span>(<span class="variable">color</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'alpha'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="variable">color</span>.<span class="variable">rgba</span>.<span class="variable">a</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the red component of the given <code>color</code>.</p>
<h2>Examples</h2>
<p> red(#c00)
// =&gt; 204</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | HSLA</em> color</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">red</span> = <span class="keyword">function</span>(<span class="variable">color</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'red'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="variable">color</span>.<span class="variable">rgba</span>.<span class="variable">r</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the green component of the given <code>color</code>.</p>
<h2>Examples</h2>
<p> green(#0c0)
// =&gt; 204</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | HSLA</em> color</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">green</span> = <span class="keyword">function</span>(<span class="variable">color</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'green'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="variable">color</span>.<span class="variable">rgba</span>.<span class="variable">g</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the blue component of the given <code>color</code>.</p>
<h2>Examples</h2>
<p> blue(#00c)
// =&gt; 204</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | HSLA</em> color</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">blue</span> = <span class="keyword">function</span>(<span class="variable">color</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'blue'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="variable">color</span>.<span class="variable">rgba</span>.<span class="variable">b</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return a <code>Color</code> from the r,g,b,a channels.</p>
<h2>Examples</h2>
<p> rgba(255,0,0,0.5)
// =&gt; rgba(255,0,0,0.5)</p>
<p> rgba(255,0,0,1)
// =&gt; #ff0000</p>
<p> rgba(#ffcc00, 0.5)
// rgba(255,204,0,0.5)</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit | Color | HSLA</em> r</p></li><li><p><strong>param</strong>: <em>Unit</em> g</p></li><li><p><strong>param</strong>: <em>Unit</em> b</p></li><li><p><strong>param</strong>: <em>Unit</em> a</p></li><li><p><strong>return</strong>: <em>Color</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">rgba</span> = <span class="keyword">function</span>(<span class="variable">r</span>,<span class="variable">g</span>,<span class="variable">b</span>,<span class="variable">a</span>){
<span class="keyword">switch</span> (<span class="variable">arguments</span>.<span class="variable">length</span>) {
<span class="keyword">case</span> <span class="number integer">1</span>:
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">r</span>);
<span class="keyword">var</span> <span class="variable">color</span> = <span class="variable">r</span>.<span class="variable">rgba</span>;
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Color</span>(
<span class="variable">color</span>.<span class="variable">r</span>
, <span class="variable">color</span>.<span class="variable">g</span>
, <span class="variable">color</span>.<span class="variable">b</span>
, <span class="variable">color</span>.<span class="variable">a</span>);
<span class="keyword">case</span> <span class="number integer">2</span>:
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">r</span>);
<span class="keyword">var</span> <span class="variable">color</span> = <span class="variable">r</span>.<span class="variable">rgba</span>;
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">g</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Color</span>(
<span class="variable">color</span>.<span class="variable">r</span>
, <span class="variable">color</span>.<span class="variable">g</span>
, <span class="variable">color</span>.<span class="variable">b</span>
, <span class="variable">g</span>.<span class="variable">val</span>);
<span class="keyword">default</span>:
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">r</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'red'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">g</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'green'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">b</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'blue'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">a</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'alpha'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Color</span>(
<span class="variable">r</span>.<span class="variable">val</span>
, <span class="variable">g</span>.<span class="variable">val</span>
, <span class="variable">b</span>.<span class="variable">val</span>
, <span class="variable">a</span>.<span class="variable">val</span>);
}
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return a <code>Color</code> from the r,g,b channels.</p>
<h2>Examples</h2>
<p> rgb(255,204,0)
// =&gt; #ffcc00</p>
<p> rgb(#fff)
// =&gt; #fff</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit | Color | HSLA</em> r</p></li><li><p><strong>param</strong>: <em>Unit</em> g</p></li><li><p><strong>param</strong>: <em>Unit</em> b</p></li><li><p><strong>return</strong>: <em>Color</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">rgb</span> = <span class="keyword">function</span>(<span class="variable">r</span>,<span class="variable">g</span>,<span class="variable">b</span>){
<span class="keyword">switch</span> (<span class="variable">arguments</span>.<span class="variable">length</span>) {
<span class="keyword">case</span> <span class="number integer">1</span>:
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">r</span>);
<span class="keyword">var</span> <span class="variable">color</span> = <span class="variable">r</span>.<span class="variable">rgba</span>;
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Color</span>(
<span class="variable">color</span>.<span class="variable">r</span>
, <span class="variable">color</span>.<span class="variable">g</span>
, <span class="variable">color</span>.<span class="variable">b</span>
, <span class="number integer">1</span>);
<span class="keyword">default</span>:
<span class="keyword">return</span> <span class="variable">exports</span>.<span class="variable">rgba</span>(<span class="variable">r</span>,<span class="variable">g</span>,<span class="variable">b</span>,<span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="number integer">1</span>));
}
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Unquote the given <code>str</code>.</p>
<h2>Examples</h2>
<p> unquote("sans-serif")
// =&gt; sans-serif</p>
<p> unquote(sans-serif)
// =&gt; sans-serif</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String | Ident</em> val</p></li><li><p><strong>return</strong>: <em>Ident</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">unquote</span> = <span class="keyword">function</span>(<span class="variable">val</span>){
<span class="variable">utils</span>.<span class="variable">assertString</span>(<span class="variable">val</span>, <span class="string">'string'</span>);
<span class="keyword">return</span> <span class="variable">val</span>.<span class="variable">string</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Absolute value of <code>n</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> n</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">abs</span> = <span class="keyword">function</span>(<span class="variable">n</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">n</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'unit'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="class">Math</span>.<span class="variable">abs</span>(<span class="variable">n</span>.<span class="variable">val</span>), <span class="variable">n</span>.<span class="variable">type</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Nearest integer above <code>n</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> n</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">ceil</span> = <span class="keyword">function</span>(<span class="variable">n</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">n</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'unit'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="class">Math</span>.<span class="variable">ceil</span>(<span class="variable">n</span>.<span class="variable">val</span>), <span class="variable">n</span>.<span class="variable">type</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Nearest integer below <code>n</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> n</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">floor</span> = <span class="keyword">function</span>(<span class="variable">n</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">n</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'unit'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="class">Math</span>.<span class="variable">floor</span>(<span class="variable">n</span>.<span class="variable">val</span>), <span class="variable">n</span>.<span class="variable">type</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Round <code>n</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> n</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">round</span> = <span class="keyword">function</span>(<span class="variable">n</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">n</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'unit'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="class">Math</span>.<span class="variable">round</span>(<span class="variable">n</span>.<span class="variable">val</span>), <span class="variable">n</span>.<span class="variable">type</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Min of <code>a</code> and <code>b</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> a</p></li><li><p><strong>param</strong>: <em>Unit</em> b</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">min</span> = <span class="keyword">function</span>(<span class="variable">a</span>, <span class="variable">b</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">a</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'a'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">b</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'b'</span>);
<span class="keyword">return</span> <span class="variable">a</span>.<span class="variable">val</span> &<span class="variable">lt</span>; <span class="variable">b</span>.<span class="variable">val</span> ? <span class="variable">a</span> : <span class="variable">b</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Max of <code>a</code> and <code>b</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> a</p></li><li><p><strong>param</strong>: <em>Unit</em> b</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">max</span> = <span class="keyword">function</span>(<span class="variable">a</span>, <span class="variable">b</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">a</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'a'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">b</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'b'</span>);
<span class="keyword">return</span> <span class="variable">a</span>.<span class="variable">val</span> &<span class="variable">gt</span>; <span class="variable">b</span>.<span class="variable">val</span> ? <span class="variable">a</span> : <span class="variable">b</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Check if <code>n</code> is even.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> n</p></li><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">even</span> = <span class="keyword">function</span>(<span class="variable">n</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">n</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'unit'</span>);
<span class="keyword">return</span> <span class="variable">nodes</span>.<span class="class">Boolean</span>(<span class="number integer">0</span> == <span class="variable">n</span> % <span class="number integer">2</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Check if <code>n</code> is odd.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> n</p></li><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">odd</span> = <span class="keyword">function</span>(<span class="variable">n</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">n</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'unit'</span>);
<span class="keyword">return</span> <span class="variable">nodes</span>.<span class="class">Boolean</span>(<span class="number integer">1</span> == <span class="variable">n</span> % <span class="number integer">2</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Saturate <code>color</code> by <code>amount</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | HSLA</em> color</p></li><li><p><strong>param</strong>: <em>Unit</em> amount</p></li><li><p><strong>return</strong>: <em>HSLA</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">saturate</span> = <span class="keyword">function</span>(<span class="variable">color</span>, <span class="variable">amount</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'color'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">amount</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'amount'</span>);
<span class="keyword">var</span> <span class="variable">hsl</span> = <span class="variable">color</span>.<span class="variable">hsl</span>;
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">HSLA</span>(
<span class="variable">hsl</span>.<span class="variable">h</span>
, <span class="variable">hsl</span>.<span class="variable">s</span> + <span class="variable">amount</span>.<span class="variable">val</span>
, <span class="variable">hsl</span>.<span class="variable">l</span>
, <span class="variable">hsl</span>.<span class="variable">a</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Desaturate <code>color</code> by <code>amount</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | HSLA</em> color</p></li><li><p><strong>param</strong>: <em>Unit</em> amount</p></li><li><p><strong>return</strong>: <em>HSLA</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">desaturate</span> = <span class="keyword">function</span>(<span class="variable">color</span>, <span class="variable">amount</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'color'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">amount</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'amount'</span>);
<span class="keyword">var</span> <span class="variable">hsl</span> = <span class="variable">color</span>.<span class="variable">hsl</span>;
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">HSLA</span>(
<span class="variable">hsl</span>.<span class="variable">h</span>
, <span class="variable">hsl</span>.<span class="variable">s</span> - <span class="variable">amount</span>.<span class="variable">val</span>
, <span class="variable">hsl</span>.<span class="variable">l</span>
, <span class="variable">hsl</span>.<span class="variable">a</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Lighten <code>color</code> by <code>amount</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | HSLA</em> color</p></li><li><p><strong>param</strong>: <em>Unit</em> amount</p></li><li><p><strong>return</strong>: <em>HSLA</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">lighten</span> = <span class="keyword">function</span>(<span class="variable">color</span>, <span class="variable">amount</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'color'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">amount</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'amount'</span>);
<span class="keyword">var</span> <span class="variable">hsl</span> = <span class="variable">color</span>.<span class="variable">hsl</span>;
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">HSLA</span>(
<span class="variable">hsl</span>.<span class="variable">h</span>
, <span class="variable">hsl</span>.<span class="variable">s</span>
, <span class="variable">hsl</span>.<span class="variable">l</span> + <span class="variable">amount</span>.<span class="variable">val</span>
, <span class="variable">hsl</span>.<span class="variable">a</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Darken <code>color</code> by <code>amount</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Color | HSLA</em> color</p></li><li><p><strong>param</strong>: <em>Unit</em> amount</p></li><li><p><strong>return</strong>: <em>HSLA</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">darken</span> = <span class="keyword">function</span>(<span class="variable">color</span>, <span class="variable">amount</span>){
<span class="variable">utils</span>.<span class="variable">assertColor</span>(<span class="variable">color</span>, <span class="string">'color'</span>);
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">amount</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'amount'</span>);
<span class="keyword">var</span> <span class="variable">hsl</span> = <span class="variable">color</span>.<span class="variable">hsl</span>;
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">HSLA</span>(
<span class="variable">hsl</span>.<span class="variable">h</span>
, <span class="variable">hsl</span>.<span class="variable">s</span>
, <span class="variable">hsl</span>.<span class="variable">l</span> - <span class="variable">amount</span>.<span class="variable">val</span>
, <span class="variable">hsl</span>.<span class="variable">a</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Assign <code>type</code> to the given <code>unit</code> or return <code>unit</code>'s type.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Unit</em> unit</p></li><li><p><strong>param</strong>: <em>String | Ident</em> type</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">unit</span> = <span class="keyword">function</span>(<span class="variable">unit</span>, <span class="variable">type</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">unit</span>, <span class="variable">nodes</span>.<span class="class">Unit</span>, <span class="string">'unit'</span>);
<span class="comment">// Assign</span>
<span class="keyword">if</span> (<span class="variable">type</span>) {
<span class="variable">utils</span>.<span class="variable">assertString</span>(<span class="variable">type</span>, <span class="string">'type'</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="variable">unit</span>.<span class="variable">val</span>, <span class="variable">type</span>.<span class="variable">string</span>);
} <span class="keyword">else</span> {
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">String</span>(<span class="variable">unit</span>.<span class="variable">type</span> || <span class="string">''</span>);
}
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Lookup variable <code>name</code> or return Null.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>Mixed</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">lookup</span> = <span class="keyword">function</span>(<span class="variable">name</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">name</span>, <span class="variable">nodes</span>.<span class="class">String</span>, <span class="string">'name'</span>);
<span class="keyword">var</span> <span class="variable">node</span> = <span class="this">this</span>.<span class="variable">lookup</span>(<span class="variable">name</span>.<span class="variable">val</span>);
<span class="keyword">if</span> (!<span class="variable">node</span>) <span class="keyword">return</span> <span class="variable">nodes</span>.<span class="keyword">null</span>;
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">visit</span>(<span class="variable">node</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Perform <code>op</code> on the <code>left</code> and <code>right</code> operands.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> op</p></li><li><p><strong>param</strong>: <em>Node</em> left</p></li><li><p><strong>param</strong>: <em>Node</em> right</p></li><li><p><strong>return</strong>: <em>Node</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">operate</span> = <span class="keyword">function</span>(<span class="variable">op</span>, <span class="variable">left</span>, <span class="variable">right</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">op</span>, <span class="variable">nodes</span>.<span class="class">String</span>, <span class="string">'op'</span>);
<span class="variable">utils</span>.<span class="variable">assertPresent</span>(<span class="variable">left</span>, <span class="string">'left'</span>);
<span class="variable">utils</span>.<span class="variable">assertPresent</span>(<span class="variable">right</span>, <span class="string">'right'</span>);
<span class="keyword">return</span> <span class="variable">left</span>.<span class="variable">operate</span>(<span class="variable">op</span>.<span class="variable">val</span>, <span class="variable">right</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Test if <code>val</code> matches the given <code>pattern</code>.</p>
<h2>Examples</h2>
<pre><code>match('^foo(bar)?', foo)
match('^foo(bar)?', foobar)
match('^foo(bar)?', 'foo')
match('^foo(bar)?', 'foobar')
// =&gt; true
match('^foo(bar)?', 'bar')
// =&gt; false</code></pre>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> pattern</p></li><li><p><strong>param</strong>: <em>String | Ident</em> val</p></li><li><p><strong>return</strong>: <em>Boolean</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">match</span> = <span class="keyword">function</span>(<span class="variable">pattern</span>, <span class="variable">val</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">pattern</span>, <span class="variable">nodes</span>.<span class="class">String</span>, <span class="string">'pattern'</span>);
<span class="variable">utils</span>.<span class="variable">assertString</span>(<span class="variable">val</span>, <span class="string">'val'</span>);
<span class="keyword">var</span> <span class="variable">re</span> = <span class="keyword">new</span> <span class="class">RegExp</span>(<span class="variable">pattern</span>.<span class="variable">val</span>);
<span class="keyword">return</span> <span class="variable">nodes</span>.<span class="class">Boolean</span>(<span class="variable">re</span>.<span class="variable">test</span>(<span class="variable">val</span>.<span class="variable">string</span>));
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return length of the given <code>expr</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Expression</em> expr</p></li><li><p><strong>return</strong>: <em>Unit</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code>(<span class="variable">exports</span>.<span class="variable">length</span> = <span class="keyword">function</span>(<span class="variable">expr</span>){
<span class="keyword">if</span> (<span class="variable">expr</span>) {
<span class="keyword">if</span> (<span class="variable">expr</span>.<span class="variable">nodes</span>) {
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="variable">utils</span>.<span class="variable">unwrap</span>(<span class="variable">expr</span>).<span class="variable">nodes</span>.<span class="variable">length</span>);
} <span class="keyword">else</span> {
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="number integer">1</span>);
}
}
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="number integer">0</span>);
}).<span class="variable">tuple</span> = <span class="variable">true</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Inspect the given <code>node</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Node</em> node</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code>(<span class="variable">exports</span>.<span class="variable">p</span> = <span class="keyword">function</span>(<span class="variable">node</span>){
<span class="variable">console</span>.<span class="variable">log</span>(<span class="string">'\033[90minspect:\033[0m %s'</span>, <span class="variable">node</span>);
<span class="keyword">return</span> <span class="variable">nodes</span>.<span class="keyword">null</span>;
}).<span class="variable">tuple</span> = <span class="variable">true</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Throw an error with the given <code>msg</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> msg</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">error</span> = <span class="keyword">function</span>(<span class="variable">msg</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">msg</span>, <span class="variable">nodes</span>.<span class="class">String</span>, <span class="string">'msg'</span>);
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="variable">msg</span>.<span class="variable">val</span>);
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Warn with the given <code>msg</code> prefixed by "Warning: ".</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> msg</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">warn</span> = <span class="keyword">function</span>(<span class="variable">msg</span>){
<span class="variable">utils</span>.<span class="variable">assertType</span>(<span class="variable">msg</span>, <span class="variable">nodes</span>.<span class="class">String</span>, <span class="string">'msg'</span>);
<span class="variable">console</span>.<span class="variable">warn</span>(<span class="string">'Warning: %s'</span>, <span class="variable">msg</span>.<span class="variable">val</span>);
<span class="keyword">return</span> <span class="variable">nodes</span>.<span class="keyword">null</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Output stack trace.</p>
<ul><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">trace</span> = <span class="keyword">function</span>(){
<span class="variable">console</span>.<span class="variable">log</span>(<span class="this">this</span>.<span class="variable">stack</span>);
<span class="keyword">return</span> <span class="variable">nodes</span>.<span class="keyword">null</span>;
};</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/functions/url.js"><a href="#">url</a></h2></td><td>lib/functions/url.js</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">nodes</span> = <span class="variable">require</span>(<span class="string">'../nodes'</span>)
, <span class="variable">parse</span> = <span class="variable">require</span>(<span class="string">'url'</span>).<span class="variable">parse</span>
, <span class="variable">extname</span> = <span class="variable">require</span>(<span class="string">'path'</span>).<span class="variable">extname</span>
, <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Mime table.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">mimes</span> = {
<span class="string">'.gif'</span>: <span class="string">'image/gif'</span>
, <span class="string">'.png'</span>: <span class="string">'image/png'</span>
, <span class="string">'.jpg'</span>: <span class="string">'image/jpeg'</span>
, <span class="string">'.jpeg'</span>: <span class="string">'image/jpeg'</span>
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return a url() function with the given <code>options</code>.</p>
<h2>Options</h2>
<ul><li><code>limit</code> bytesize limit defaulting to 30Kb</li><li><code>paths</code> image resolution path(s), defaults to CWD</li></ul>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>return</strong>: <em>Function</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span>(<span class="variable">options</span>) {
<span class="variable">options</span> = <span class="variable">options</span> || {};
<span class="keyword">var</span> <span class="variable">sizeLimit</span> = <span class="variable">options</span>.<span class="variable">limit</span> || <span class="number integer">30000</span>
, <span class="variable">paths</span> = <span class="variable">options</span>.<span class="variable">paths</span> || [<span class="variable">process</span>.<span class="variable">cwd</span>()];
<span class="keyword">return</span> <span class="keyword">function</span>(<span class="variable">url</span>){
<span class="keyword">var</span> <span class="variable">buf</span>
, <span class="variable">url</span> = <span class="variable">parse</span>(<span class="variable">url</span>.<span class="variable">val</span>)
, <span class="variable">ext</span> = <span class="variable">extname</span>(<span class="variable">url</span>.<span class="variable">pathname</span>)
, <span class="variable">mime</span> = <span class="variable">mimes</span>[<span class="variable">ext</span>]
, <span class="variable">literal</span> = <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Ident</span>(<span class="string">'url(&quot;'</span> + <span class="variable">url</span>.<span class="variable">href</span> + <span class="string">'&quot;)'</span>);
<span class="comment">// Not supported</span>
<span class="keyword">if</span> (!<span class="variable">mime</span>) <span class="keyword">return</span> <span class="variable">literal</span>;
<span class="comment">// Absolute</span>
<span class="keyword">if</span> (<span class="variable">url</span>.<span class="variable">protocol</span>) <span class="keyword">return</span> <span class="variable">literal</span>;
<span class="comment">// Lookup</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">i</span> &<span class="variable">lt</span>; <span class="variable">paths</span>.<span class="variable">length</span>; ++<span class="variable">i</span>) {
<span class="keyword">try</span> {
<span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">paths</span>[<span class="variable">i</span>] + <span class="string">'/'</span> + <span class="variable">url</span>.<span class="variable">pathname</span>;
<span class="variable">buf</span> = <span class="variable">fs</span>.<span class="variable">readFileSync</span>(<span class="variable">path</span>);
<span class="keyword">break</span>;
} <span class="keyword">catch</span> (<span class="variable">err</span>) {
<span class="comment">// Ignore</span>
}
}
<span class="comment">// Failed to lookup</span>
<span class="keyword">if</span> (!<span class="variable">buf</span>) <span class="keyword">return</span> <span class="variable">literal</span>;
<span class="comment">// To large</span>
<span class="keyword">if</span> (<span class="variable">buf</span>.<span class="variable">length</span> &<span class="variable">gt</span>; <span class="variable">sizeLimit</span>) <span class="keyword">return</span> <span class="variable">literal</span>;
<span class="comment">// Encode</span>
<span class="keyword">var</span> <span class="variable">str</span> = <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">String</span>(<span class="string">'data:'</span> + <span class="variable">mime</span> + <span class="string">';base64,'</span> + <span class="variable">buf</span>.<span class="variable">toString</span>(<span class="string">'base64'</span>))
, <span class="variable">args</span> = <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Expression</span>;
<span class="variable">args</span>.<span class="variable">push</span>(<span class="variable">str</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Call</span>(<span class="string">'url'</span>, <span class="variable">args</span>);
}
};</code></pre>
</td>
</tr><tr class="filename"><td><h2 id="lib/lexer.js"><a href="#">lexer</a></h2></td><td>lib/lexer.js</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="class">Token</span> = <span class="variable">require</span>(<span class="string">'./token'</span>)
, <span class="variable">nodes</span> = <span class="variable">require</span>(<span class="string">'./nodes'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Operator aliases.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">alias</span> = {
<span class="variable">and</span>: <span class="string">'&amp;&amp;'</span>
, <span class="variable">or</span>: <span class="string">'||'</span>
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Numeric strings used for exceptions.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">numberString</span> = [, <span class="string">'one'</span>, <span class="string">'two'</span>];</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Units.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">units</span> = [
<span class="string">'em'</span>
, <span class="string">'ex'</span>
, <span class="string">'px'</span>
, <span class="string">'mm'</span>
, <span class="string">'cm'</span>
, <span class="string">'in'</span>
, <span class="string">'pt'</span>
, <span class="string">'pc'</span>
, <span class="string">'deg'</span>
, <span class="string">'rad'</span>
, <span class="string">'grad'</span>
, <span class="string">'ms'</span>
, <span class="string">'s'</span>
, <span class="string">'Hz'</span>
, <span class="string">'kHz'</span>
, <span class="string">'%'</span>].<span class="variable">join</span>(<span class="string">'|'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Unit RegExp.
</p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">unit</span> = <span class="keyword">new</span> <span class="class">RegExp</span>(<span class="string">'^(-)?(\\d+\\.\\d+|\\d+|\\.\\d+)('</span> + <span class="variable">units</span> + <span class="string">')? *'</span>);</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Initialize a new <code>Lexer</code> with the given <code>str</code> and <code>options</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="class">Lexer</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">Lexer</span>(<span class="variable">str</span>, <span class="variable">options</span>) {
<span class="variable">options</span> = <span class="variable">options</span> || {};
<span class="this">this</span>.<span class="variable">str</span> = <span class="variable">str</span>.<span class="variable">replace</span>(<span class="regexp">/\r\n?/g</span>, <span class="string">'\n'</span>).<span class="variable">replace</span>(<span class="regexp">/\t/g</span>, <span class="string">' '</span>);
<span class="this">this</span>.<span class="variable">stash</span> = [];
<span class="this">this</span>.<span class="variable">prevIndents</span> = <span class="number integer">0</span>;
<span class="this">this</span>.<span class="variable">lineno</span> = <span class="number integer">0</span>;
};</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Lexer prototype.
</p>
</td>
<td class="code">
<pre><code><span class="class">Lexer</span>.<span class="variable">prototype</span> = {</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Custom inspect.
</p>
</td>
<td class="code">
<pre><code><span class="variable">inspect</span>: <span class="keyword">function</span>(){
<span class="keyword">var</span> <span class="variable">tok</span>
, <span class="variable">tmp</span> = <span class="this">this</span>.<span class="variable">str</span>
, <span class="variable">buf</span> = [];
<span class="keyword">while</span> (<span class="string">'eos'</span> != (<span class="variable">tok</span> = <span class="this">this</span>.<span class="variable">next</span>).<span class="variable">type</span>) {
<span class="variable">buf</span>.<span class="variable">push</span>(<span class="variable">tok</span>.<span class="variable">inspect</span>());
}
<span class="this">this</span>.<span class="variable">str</span> = <span class="variable">tmp</span>;
<span class="this">this</span>.<span class="variable">prevIndents</span> = <span class="number integer">0</span>;
<span class="keyword">return</span> <span class="variable">buf</span>.<span class="variable">concat</span>(<span class="variable">tok</span>.<span class="variable">inspect</span>()).<span class="variable">join</span>(<span class="string">'\n'</span>);
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Lookahead <code>n</code> tokens.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Number</em> n</p></li><li><p><strong>return</strong>: <em>Object</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">lookahead</span>: <span class="keyword">function</span>(<span class="variable">n</span>){
<span class="keyword">var</span> <span class="variable">fetch</span> = <span class="variable">n</span> - <span class="this">this</span>.<span class="variable">stash</span>.<span class="variable">length</span>;
<span class="keyword">while</span> (<span class="variable">fetch</span>-- &<span class="variable">gt</span>; <span class="number integer">0</span>) <span class="this">this</span>.<span class="variable">stash</span>.<span class="variable">push</span>(<span class="this">this</span>.<span class="variable">advance</span>);
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">stash</span>[--<span class="variable">n</span>];
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Consume the given <code>len</code>.</p>
<h2></h2>
<ul><li><p><strong>param</strong>: <em>Number | Array</em> len</p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">skip</span>: <span class="keyword">function</span>(<span class="variable">len</span>){
<span class="this">this</span>.<span class="variable">str</span> = <span class="this">this</span>.<span class="variable">str</span>.<span class="variable">substr</span>(<span class="class">Array</span>.<span class="variable">isArray</span>(<span class="variable">len</span>)
? <span class="variable">len</span>[<span class="number integer">0</span>].<span class="variable">length</span>
: <span class="variable">len</span>);
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Fetch next token including those stashed by peek.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>Token</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">next</span>() {
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="this">this</span>.<span class="variable">stashed</span> || <span class="this">this</span>.<span class="variable">advance</span>;
<span class="keyword">switch</span> (<span class="variable">tok</span>.<span class="variable">type</span>) {
<span class="keyword">case</span> <span class="string">'newline'</span>:
<span class="keyword">case</span> <span class="string">'selector'</span>:
<span class="keyword">case</span> <span class="string">'indent'</span>:
++<span class="this">this</span>.<span class="variable">lineno</span>;
}
<span class="variable">tok</span>.<span class="variable">lineno</span> = <span class="this">this</span>.<span class="variable">lineno</span>;
<span class="keyword">return</span> <span class="variable">tok</span>;
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Fetch next token.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>Token</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">advance</span>() {
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">eos</span>
|| <span class="this">this</span>.<span class="keyword">null</span>
|| <span class="this">this</span>.<span class="variable">keyword</span>
|| <span class="this">this</span>.<span class="variable">atrule</span>
|| <span class="this">this</span>.<span class="variable">media</span>
|| <span class="this">this</span>.<span class="variable">comment</span>
|| <span class="this">this</span>.<span class="variable">newline</span>
|| <span class="this">this</span>.<span class="variable">escaped</span>
|| <span class="this">this</span>.<span class="variable">important</span>
|| <span class="this">this</span>.<span class="variable">literal</span>
|| <span class="this">this</span>.<span class="keyword">function</span>
|| <span class="this">this</span>.<span class="variable">brace</span>
|| <span class="this">this</span>.<span class="variable">paren</span>
|| <span class="this">this</span>.<span class="variable">color</span>
|| <span class="this">this</span>.<span class="variable">string</span>
|| <span class="this">this</span>.<span class="variable">unit</span>
|| <span class="this">this</span>.<span class="variable">namedop</span>
|| <span class="this">this</span>.<span class="variable">boolean</span>
|| <span class="this">this</span>.<span class="variable">ident</span>
|| <span class="this">this</span>.<span class="variable">op</span>
|| <span class="this">this</span>.<span class="variable">space</span>
|| <span class="this">this</span>.<span class="variable">selector</span>;
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Lookahead a single token.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>Token</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">peek</span>() {
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">lookahead</span>(<span class="number integer">1</span>);
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>Return the next possibly stashed token.</p>
<h2></h2>
<ul><li><p><strong>return</strong>: <em>Token</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">stashed</span>() {
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">stash</span>.<span class="variable">shift</span>();
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>EOS | trailing outdents.
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">eos</span>() {
<span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">str</span>.<span class="variable">length</span>) <span class="keyword">return</span>;
<span class="keyword">return</span> --<span class="this">this</span>.<span class="variable">prevIndents</span> &<span class="variable">lt</span>; <span class="number integer">0</span>
? <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'eos'</span>)
: <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'outdent'</span>);
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>' '+
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">space</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^( +)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'space'</span>);
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'\' . ' '*
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">escaped</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^\\(.) */</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">c</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'ident'</span>, <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Ident</span>(<span class="variable">c</span>));
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'@css' ' '<em> '{' .</em> '}' ' '*
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">literal</span>() {
<span class="comment">// HACK attack !!!</span>
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^@css *\{/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">var</span> <span class="variable">c</span>
, <span class="variable">braces</span> = <span class="number integer">1</span>
, <span class="variable">css</span> = <span class="string">''</span>;
<span class="keyword">while</span> (<span class="variable">c</span> = <span class="this">this</span>.<span class="variable">str</span>[<span class="number integer">0</span>]) {
<span class="this">this</span>.<span class="variable">str</span> = <span class="this">this</span>.<span class="variable">str</span>.<span class="variable">substr</span>(<span class="number integer">1</span>);
<span class="keyword">switch</span> (<span class="variable">c</span>) {
<span class="keyword">case</span> <span class="string">'{'</span>: ++<span class="variable">braces</span>; <span class="keyword">break</span>;
<span class="keyword">case</span> <span class="string">'}'</span>: --<span class="variable">braces</span>; <span class="keyword">break</span>;
}
<span class="variable">css</span> += <span class="variable">c</span>;
<span class="keyword">if</span> (!<span class="variable">braces</span>) <span class="keyword">break</span>;
}
<span class="variable">css</span> = <span class="variable">css</span>.<span class="variable">replace</span>(<span class="regexp">/\s*}$/</span>, <span class="string">''</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'literal'</span>, <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Literal</span>(<span class="variable">css</span>));
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'!important' ' '*
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">important</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^!important */</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'ident'</span>, <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Ident</span>(<span class="string">'!important'</span>));
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'{' | '}'
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">brace</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^([{}])/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="this">this</span>.<span class="variable">skip</span>(<span class="number integer">1</span>);
<span class="keyword">var</span> <span class="variable">brace</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="variable">brace</span>, <span class="variable">brace</span>);
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'(' | ')' ' '*
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">paren</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^([()]) */</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">paren</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">if</span> (<span class="string">')'</span> == <span class="variable">paren</span>) <span class="this">this</span>.<span class="variable">isURL</span> = <span class="variable">false</span>;
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="variable">paren</span>, <span class="variable">paren</span>);
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'null'
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="keyword">null</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^(null)\b */</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'null'</span>, <span class="variable">nodes</span>.<span class="keyword">null</span>);
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p> 'if'
| 'else'
| 'unless'
| 'return'
| 'for'
| 'in'
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">keyword</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^(return|if|else|unless|for|in)\b */</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">keyword</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="variable">keyword</span>, <span class="variable">keyword</span>);
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p> 'not'
| 'and'
| 'or'
| 'is a'
| 'is defined'
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">namedop</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^(not|and|or|is a|is defined)\b( *)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">op</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="variable">op</span> = <span class="variable">alias</span>[<span class="variable">op</span>] || <span class="variable">op</span>;
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="keyword">new</span> <span class="class">Token</span>(<span class="variable">op</span>, <span class="variable">op</span>);
<span class="variable">tok</span>.<span class="variable">space</span> = <span class="variable">captures</span>[<span class="number integer">2</span>];
<span class="keyword">return</span> <span class="variable">tok</span>;
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p> ','
| '+'
| '-'
| '*'
| '/'
| '%'
| '**'
| '!'
| '&amp;'
| '&amp;&amp;'
| '||'
| '&gt;'
| '&gt;='
| '&lt;'
| '&lt;='
| '='
| '=='
| '!='
| '!'
| '~'
| '?='
| '?'
| ':'
| '['
| ']'
| '..'
| '...'
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">op</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^([.]{2,3}|&amp;&amp;|\|\||[!&lt;&gt;=?]=|\*\*|[-,=?:!~+&lt;&gt;*\/</span>%&<span class="variable">amp</span>;\[\]])( *)/.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">op</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="variable">op</span> = <span class="variable">alias</span>[<span class="variable">op</span>] || <span class="variable">op</span>;
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="keyword">new</span> <span class="class">Token</span>(<span class="variable">op</span>, <span class="variable">op</span>);
<span class="variable">tok</span>.<span class="variable">space</span> = <span class="variable">captures</span>[<span class="number integer">2</span>];
<span class="keyword">return</span> <span class="variable">tok</span>;
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'@media' ([^\n]+)
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">media</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^@media *([^\n]+)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'media'</span>, <span class="variable">captures</span>[<span class="number integer">1</span>]);
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'@' ('import' | 'keyframes' | 'charset' | 'page')
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">atrule</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^@(import|keyframes|charset|page) */</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="variable">captures</span>[<span class="number integer">1</span>]);
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'//' *
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">comment</span>() {
<span class="comment">// Single line</span>
<span class="keyword">if</span> (<span class="string">'/'</span> == <span class="this">this</span>.<span class="variable">str</span>[<span class="number integer">0</span>] &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="string">'/'</span> == <span class="this">this</span>.<span class="variable">str</span>[<span class="number integer">1</span>]) {
<span class="keyword">var</span> <span class="variable">end</span> = <span class="this">this</span>.<span class="variable">str</span>.<span class="variable">indexOf</span>(<span class="string">'\n'</span>);
<span class="keyword">if</span> (-<span class="number integer">1</span> == <span class="variable">end</span>) <span class="variable">end</span> = <span class="this">this</span>.<span class="variable">str</span>.<span class="variable">length</span>;
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">end</span>);
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">advance</span>;
}
<span class="comment">// Multi-line</span>
<span class="keyword">if</span> (<span class="string">'/'</span> == <span class="this">this</span>.<span class="variable">str</span>[<span class="number integer">0</span>] &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="string">'*'</span> == <span class="this">this</span>.<span class="variable">str</span>[<span class="number integer">1</span>]) {
<span class="keyword">var</span> <span class="variable">end</span> = <span class="this">this</span>.<span class="variable">str</span>.<span class="variable">indexOf</span>(<span class="string">'*/'</span>);
<span class="keyword">if</span> (-<span class="number integer">1</span> == <span class="variable">end</span>) <span class="variable">end</span> = <span class="this">this</span>.<span class="variable">str</span>.<span class="variable">length</span>;
<span class="keyword">var</span> <span class="variable">str</span> = <span class="this">this</span>.<span class="variable">str</span>.<span class="variable">substr</span>(<span class="number integer">0</span>, <span class="variable">end</span> + <span class="number integer">2</span>)
, <span class="variable">lines</span> = <span class="variable">str</span>.<span class="variable">split</span>(<span class="string">'\n'</span>).<span class="variable">length</span> - <span class="number integer">1</span>;
<span class="this">this</span>.<span class="variable">lineno</span> += <span class="variable">lines</span>;
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">end</span> + <span class="number integer">2</span>);
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">allowComments</span>
? <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'comment'</span>, <span class="variable">str</span>)
: <span class="this">this</span>.<span class="variable">advance</span>;
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'true' | 'false'
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">boolean</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^(true|false)\b( *)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">val</span> = <span class="string">'true'</span> == <span class="variable">captures</span>[<span class="number integer">1</span>]
? <span class="variable">nodes</span>.<span class="variable">true</span>
: <span class="variable">nodes</span>.<span class="variable">false</span>;
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'boolean'</span>, <span class="variable">val</span>);
<span class="variable">tok</span>.<span class="variable">space</span> = <span class="variable">captures</span>[<span class="number integer">2</span>];
<span class="keyword">return</span> <span class="variable">tok</span>;
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>-?[a-zA-Z] [-\w\d]* '('
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="keyword">function</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^(-?[a-zA-Z][-\w\d]*)\(( *)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="this">this</span>.<span class="variable">isURL</span> = <span class="string">'url'</span> == <span class="variable">name</span>;
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'function'</span>, <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Ident</span>(<span class="variable">name</span>));
<span class="variable">tok</span>.<span class="variable">space</span> = <span class="variable">captures</span>[<span class="number integer">2</span>];
<span class="keyword">return</span> <span class="variable">tok</span>;
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>-?[a-zA-Z] [-\w\d]*
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">ident</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^(-?[a-zA-Z][-\w\d]*)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">name</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'ident'</span>, <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Ident</span>(<span class="variable">name</span>));
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'\n' ' '+
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">newline</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^\n( *)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="keyword">var</span> <span class="variable">tok</span>
, <span class="variable">spaces</span> = <span class="variable">captures</span>[<span class="number integer">1</span>].<span class="variable">length</span>
, <span class="variable">indents</span> = <span class="variable">spaces</span> / <span class="number integer">2</span>;
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="comment">// Reset state</span>
<span class="this">this</span>.<span class="variable">isVariable</span> = <span class="variable">false</span>;
<span class="comment">// Blank line</span>
<span class="keyword">if</span> (<span class="string">'\n'</span> == <span class="this">this</span>.<span class="variable">str</span>[<span class="number integer">0</span>]) {
++<span class="this">this</span>.<span class="variable">lineno</span>;
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">advance</span>;
}
<span class="comment">// To few spaces</span>
<span class="keyword">if</span> (<span class="number integer">0</span> != <span class="variable">spaces</span> % <span class="number integer">2</span>) {
<span class="keyword">var</span> <span class="variable">str</span> = <span class="number integer">1</span> == <span class="variable">spaces</span> ? <span class="string">'space'</span> : <span class="string">'spaces'</span>
, <span class="variable">spaces</span> = <span class="variable">numberString</span>[<span class="variable">spaces</span>] || <span class="variable">spaces</span>;
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'Invalid indentation, got '</span> + <span class="variable">spaces</span> + <span class="string">' '</span> + <span class="variable">str</span> + <span class="string">' and expected multiple of two'</span>);
<span class="comment">// To many spaces</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">indents</span> &<span class="variable">gt</span>; <span class="this">this</span>.<span class="variable">prevIndents</span> + <span class="number integer">1</span>) {
<span class="keyword">var</span> <span class="variable">str</span> = <span class="number integer">1</span> == <span class="variable">spaces</span> ? <span class="string">'space'</span> : <span class="string">'spaces'</span>
, <span class="variable">expected</span> = <span class="number integer">2</span> * (<span class="this">this</span>.<span class="variable">prevIndents</span> * <span class="number integer">2</span>) || <span class="number integer">2</span>
, <span class="variable">expected</span> = <span class="variable">numberString</span>[<span class="variable">expected</span>] || <span class="variable">expected</span>
, <span class="variable">spaces</span> = <span class="variable">numberString</span>[<span class="variable">spaces</span>] || <span class="variable">spaces</span>;
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'Invalid indentation, got '</span> + <span class="variable">spaces</span> + <span class="string">' '</span> + <span class="variable">str</span> + <span class="string">' and expected '</span> + <span class="variable">expected</span>);
<span class="comment">// Outdent</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">indents</span> &<span class="variable">lt</span>; <span class="this">this</span>.<span class="variable">prevIndents</span>) {
<span class="keyword">var</span> <span class="variable">n</span> = <span class="this">this</span>.<span class="variable">prevIndents</span> - <span class="variable">indents</span>;
<span class="keyword">while</span> (--<span class="variable">n</span>) <span class="this">this</span>.<span class="variable">stash</span>.<span class="variable">push</span>(<span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'outdent'</span>));
<span class="this">this</span>.<span class="variable">prevIndents</span> = <span class="variable">indents</span>;
<span class="variable">tok</span> = <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'outdent'</span>);
<span class="comment">// Indent</span>
} <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">indents</span> != <span class="this">this</span>.<span class="variable">prevIndents</span>) {
<span class="this">this</span>.<span class="variable">prevIndents</span> = <span class="variable">indents</span>;
<span class="variable">tok</span> = <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'indent'</span>);
<span class="comment">// Newline</span>
} <span class="keyword">else</span> {
<span class="variable">tok</span> = <span class="keyword">new</span> <span class="class">Token</span>(<span class="string">'newline'</span>);
}
<span class="keyword">return</span> <span class="variable">tok</span>;
}
},</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
<p>'-'? (digit+ | digit* '.' digit+) unit
</p>
</td>
<td class="code">
<pre><code><span class="variable">get</span> <span class="variable">unit</span>() {
<span class="keyword">var</span> <span class="variable">captures</span>;
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="variable">unit</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">str</span>)) {
<span class="this">this</span>.<span class="variable">skip</span>(<span class="variable">captures</span>);
<span class="keyword">var</span> <span class="variable">n</span> = <span class="variable">parseFloat</span>(<span class="variable">captures</span>[<span class="number integer">2</span>]);
<span class="keyword">if</span> (<span class="string">'-'</span> == <span class="variable">captures</span>[<span class="number integer">1</span>]) <span class="variable">n</span> = -<span class="variable">n</span>;
<span class="keyword">var</span> <span class="variable">node</span> = <span class="keyword">new</span> <span class="variable">nodes</span>.<span class="class">Unit</span>(<span class="variable">n</span>, <span class="variable">captures</span>[<span class="number integer">3</span>]);
<span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Token</span>(<span class