PageRenderTime 56ms CodeModel.GetById 23ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/documentation/docs/helpers.html

http://github.com/jashkenas/coffee-script
HTML | 612 lines | 417 code | 195 blank | 0 comment | 0 complexity | 35377504448519f52ecb29dcb4a7ee9e MD5 | raw file
  1<!DOCTYPE html>
  2
  3<html>
  4<head>
  5  <title>helpers.coffee</title>
  6  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  7  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  8  <link rel="stylesheet" media="all" href="docco.css" />
  9</head>
 10<body>
 11  <div id="container">
 12    <div id="background"></div>
 13    
 14      <ul id="jump_to">
 15        <li>
 16          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
 17          <a class="small" href="javascript:void(0);">+</a>
 18          <div id="jump_wrapper">
 19          <div id="jump_page_wrapper">
 20            <div id="jump_page">
 21              
 22                
 23                <a class="source" href="browser.html">
 24                  browser.coffee
 25                </a>
 26              
 27                
 28                <a class="source" href="cake.html">
 29                  cake.coffee
 30                </a>
 31              
 32                
 33                <a class="source" href="coffee-script.html">
 34                  coffee-script.coffee
 35                </a>
 36              
 37                
 38                <a class="source" href="command.html">
 39                  command.coffee
 40                </a>
 41              
 42                
 43                <a class="source" href="grammar.html">
 44                  grammar.coffee
 45                </a>
 46              
 47                
 48                <a class="source" href="helpers.html">
 49                  helpers.coffee
 50                </a>
 51              
 52                
 53                <a class="source" href="index.html">
 54                  index.coffee
 55                </a>
 56              
 57                
 58                <a class="source" href="lexer.html">
 59                  lexer.coffee
 60                </a>
 61              
 62                
 63                <a class="source" href="nodes.html">
 64                  nodes.coffee
 65                </a>
 66              
 67                
 68                <a class="source" href="optparse.html">
 69                  optparse.coffee
 70                </a>
 71              
 72                
 73                <a class="source" href="register.html">
 74                  register.coffee
 75                </a>
 76              
 77                
 78                <a class="source" href="repl.html">
 79                  repl.coffee
 80                </a>
 81              
 82                
 83                <a class="source" href="rewriter.html">
 84                  rewriter.coffee
 85                </a>
 86              
 87                
 88                <a class="source" href="scope.html">
 89                  scope.litcoffee
 90                </a>
 91              
 92                
 93                <a class="source" href="sourcemap.html">
 94                  sourcemap.litcoffee
 95                </a>
 96              
 97            </div>
 98          </div>
 99        </li>
100      </ul>
101    
102    <ul class="sections">
103        
104          <li id="title">
105              <div class="annotation">
106                  <h1>helpers.coffee</h1>
107              </div>
108          </li>
109        
110        
111        
112        <li id="section-1">
113            <div class="annotation">
114              
115              <div class="pilwrap ">
116                <a class="pilcrow" href="#section-1">&#182;</a>
117              </div>
118              <p>This file contains the common helper functions that we’d like to share among
119the <strong>Lexer</strong>, <strong>Rewriter</strong>, and the <strong>Nodes</strong>. Merge objects, flatten
120arrays, count characters, that sort of thing.</p>
121
122            </div>
123            
124        </li>
125        
126        
127        <li id="section-2">
128            <div class="annotation">
129              
130              <div class="pilwrap ">
131                <a class="pilcrow" href="#section-2">&#182;</a>
132              </div>
133              <p>Peek at the beginning of a given string to see if it matches a sequence.</p>
134
135            </div>
136            
137            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">starts</span> = <span class="hljs-params">(string, literal, start)</span> -&gt;</span>
138  literal <span class="hljs-keyword">is</span> string.substr start, literal.length</pre></div></div>
139            
140        </li>
141        
142        
143        <li id="section-3">
144            <div class="annotation">
145              
146              <div class="pilwrap ">
147                <a class="pilcrow" href="#section-3">&#182;</a>
148              </div>
149              <p>Peek at the end of a given string to see if it matches a sequence.</p>
150
151            </div>
152            
153            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">ends</span> = <span class="hljs-params">(string, literal, back)</span> -&gt;</span>
154  len = literal.length
155  literal <span class="hljs-keyword">is</span> string.substr string.length - len - (back <span class="hljs-keyword">or</span> <span class="hljs-number">0</span>), len</pre></div></div>
156            
157        </li>
158        
159        
160        <li id="section-4">
161            <div class="annotation">
162              
163              <div class="pilwrap ">
164                <a class="pilcrow" href="#section-4">&#182;</a>
165              </div>
166              <p>Repeat a string <code>n</code> times.</p>
167
168            </div>
169            
170            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.repeat = <span class="hljs-function"><span class="hljs-title">repeat</span> = <span class="hljs-params">(str, n)</span> -&gt;</span></pre></div></div>
171            
172        </li>
173        
174        
175        <li id="section-5">
176            <div class="annotation">
177              
178              <div class="pilwrap ">
179                <a class="pilcrow" href="#section-5">&#182;</a>
180              </div>
181              <p>Use clever algorithm to have O(log(n)) string concatenation operations.</p>
182
183            </div>
184            
185            <div class="content"><div class='highlight'><pre>  res = <span class="hljs-string">''</span>
186  <span class="hljs-keyword">while</span> n &gt; <span class="hljs-number">0</span>
187    res += str <span class="hljs-keyword">if</span> n &amp; <span class="hljs-number">1</span>
188    n &gt;&gt;&gt;= <span class="hljs-number">1</span>
189    str += str
190  res</pre></div></div>
191            
192        </li>
193        
194        
195        <li id="section-6">
196            <div class="annotation">
197              
198              <div class="pilwrap ">
199                <a class="pilcrow" href="#section-6">&#182;</a>
200              </div>
201              <p>Trim out all falsy values from an array.</p>
202
203            </div>
204            
205            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">compact</span> = <span class="hljs-params">(array)</span> -&gt;</span>
206  item <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> array <span class="hljs-keyword">when</span> item</pre></div></div>
207            
208        </li>
209        
210        
211        <li id="section-7">
212            <div class="annotation">
213              
214              <div class="pilwrap ">
215                <a class="pilcrow" href="#section-7">&#182;</a>
216              </div>
217              <p>Count the number of occurrences of a string in a string.</p>
218
219            </div>
220            
221            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">count</span> = <span class="hljs-params">(string, substr)</span> -&gt;</span>
222  num = pos = <span class="hljs-number">0</span>
223  <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>/<span class="hljs-number">0</span> <span class="hljs-keyword">unless</span> substr.length
224  num++ <span class="hljs-keyword">while</span> pos = <span class="hljs-number">1</span> + string.indexOf substr, pos
225  num</pre></div></div>
226            
227        </li>
228        
229        
230        <li id="section-8">
231            <div class="annotation">
232              
233              <div class="pilwrap ">
234                <a class="pilcrow" href="#section-8">&#182;</a>
235              </div>
236              <p>Merge objects, returning a fresh copy with attributes from both sides.
237Used every time <code>Base#compile</code> is called, to allow properties in the
238options hash to propagate down the tree without polluting other branches.</p>
239
240            </div>
241            
242            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">merge</span> = <span class="hljs-params">(options, overrides)</span> -&gt;</span>
243  extend (extend {}, options), overrides</pre></div></div>
244            
245        </li>
246        
247        
248        <li id="section-9">
249            <div class="annotation">
250              
251              <div class="pilwrap ">
252                <a class="pilcrow" href="#section-9">&#182;</a>
253              </div>
254              <p>Extend a source object with the properties of another object (shallow copy).</p>
255
256            </div>
257            
258            <div class="content"><div class='highlight'><pre>extend = <span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">extend</span> = <span class="hljs-params">(object, properties)</span> -&gt;</span>
259  <span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> properties
260    object[key] = val
261  object</pre></div></div>
262            
263        </li>
264        
265        
266        <li id="section-10">
267            <div class="annotation">
268              
269              <div class="pilwrap ">
270                <a class="pilcrow" href="#section-10">&#182;</a>
271              </div>
272              <p>Return a flattened version of an array.
273Handy for getting a list of <code>children</code> from the nodes.</p>
274
275            </div>
276            
277            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.flatten = <span class="hljs-function"><span class="hljs-title">flatten</span> = <span class="hljs-params">(array)</span> -&gt;</span>
278  flattened = []
279  <span class="hljs-keyword">for</span> element <span class="hljs-keyword">in</span> array
280    <span class="hljs-keyword">if</span> <span class="hljs-string">'[object Array]'</span> <span class="hljs-keyword">is</span> <span class="hljs-attribute">Object</span>::toString.call element
281      flattened = flattened.concat flatten element
282    <span class="hljs-keyword">else</span>
283      flattened.push element
284  flattened</pre></div></div>
285            
286        </li>
287        
288        
289        <li id="section-11">
290            <div class="annotation">
291              
292              <div class="pilwrap ">
293                <a class="pilcrow" href="#section-11">&#182;</a>
294              </div>
295              <p>Delete a key from an object, returning the value. Useful when a node is
296looking for a particular method in an options hash.</p>
297
298            </div>
299            
300            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">del</span> = <span class="hljs-params">(obj, key)</span> -&gt;</span>
301  val =  obj[key]
302  <span class="hljs-keyword">delete</span> obj[key]
303  val</pre></div></div>
304            
305        </li>
306        
307        
308        <li id="section-12">
309            <div class="annotation">
310              
311              <div class="pilwrap ">
312                <a class="pilcrow" href="#section-12">&#182;</a>
313              </div>
314              <p>Typical Array::some</p>
315
316            </div>
317            
318            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.some = <span class="hljs-attribute">Array</span>::some ? <span class="hljs-function"><span class="hljs-params">(fn)</span> -&gt;</span>
319  <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> <span class="hljs-keyword">this</span> <span class="hljs-keyword">when</span> fn e
320  <span class="hljs-literal">false</span></pre></div></div>
321            
322        </li>
323        
324        
325        <li id="section-13">
326            <div class="annotation">
327              
328              <div class="pilwrap ">
329                <a class="pilcrow" href="#section-13">&#182;</a>
330              </div>
331              <p>Simple function for inverting Literate CoffeeScript code by putting the
332documentation in comments, producing a string of CoffeeScript code that
333can be compiled “normally”.</p>
334
335            </div>
336            
337            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">invertLiterate</span> = <span class="hljs-params">(code)</span> -&gt;</span>
338  maybe_code = <span class="hljs-literal">true</span>
339  lines = <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> code.split(<span class="hljs-string">'\n'</span>)
340    <span class="hljs-keyword">if</span> maybe_code <span class="hljs-keyword">and</span> <span class="hljs-regexp">/^([ ]{4}|[ ]{0,3}\t)/</span>.test line
341      line
342    <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> maybe_code = <span class="hljs-regexp">/^\s*$/</span>.test line
343      line
344    <span class="hljs-keyword">else</span>
345      <span class="hljs-string">'# '</span> + line
346  lines.join <span class="hljs-string">'\n'</span></pre></div></div>
347            
348        </li>
349        
350        
351        <li id="section-14">
352            <div class="annotation">
353              
354              <div class="pilwrap ">
355                <a class="pilcrow" href="#section-14">&#182;</a>
356              </div>
357              <p>Merge two jison-style location data objects together.
358If <code>last</code> is not provided, this will simply return <code>first</code>.</p>
359
360            </div>
361            
362            <div class="content"><div class='highlight'><pre><span class="hljs-function"><span class="hljs-title">buildLocationData</span> = <span class="hljs-params">(first, last)</span> -&gt;</span>
363  <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> last
364    first
365  <span class="hljs-keyword">else</span>
366    <span class="hljs-attribute">first_line</span>: first.first_line
367    <span class="hljs-attribute">first_column</span>: first.first_column
368    <span class="hljs-attribute">last_line</span>: last.last_line
369    <span class="hljs-attribute">last_column</span>: last.last_column</pre></div></div>
370            
371        </li>
372        
373        
374        <li id="section-15">
375            <div class="annotation">
376              
377              <div class="pilwrap ">
378                <a class="pilcrow" href="#section-15">&#182;</a>
379              </div>
380              <p>This returns a function which takes an object as a parameter, and if that
381object is an AST node, updates that object’s locationData.
382The object is returned either way.</p>
383
384            </div>
385            
386            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">addLocationDataFn</span> = <span class="hljs-params">(first, last)</span> -&gt;</span>
387  <span class="hljs-function"><span class="hljs-params">(obj)</span> -&gt;</span>
388    <span class="hljs-keyword">if</span> ((<span class="hljs-keyword">typeof</span> obj) <span class="hljs-keyword">is</span> <span class="hljs-string">'object'</span>) <span class="hljs-keyword">and</span> (!!obj[<span class="hljs-string">'updateLocationDataIfMissing'</span>])
389      obj.updateLocationDataIfMissing buildLocationData(first, last)
390
391    <span class="hljs-keyword">return</span> obj</pre></div></div>
392            
393        </li>
394        
395        
396        <li id="section-16">
397            <div class="annotation">
398              
399              <div class="pilwrap ">
400                <a class="pilcrow" href="#section-16">&#182;</a>
401              </div>
402              <p>Convert jison location data to a string.
403<code>obj</code> can be a token, or a locationData.</p>
404
405            </div>
406            
407            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">locationDataToString</span> = <span class="hljs-params">(obj)</span> -&gt;</span>
408  <span class="hljs-keyword">if</span> (<span class="hljs-string">"2"</span> <span class="hljs-keyword">of</span> obj) <span class="hljs-keyword">and</span> (<span class="hljs-string">"first_line"</span> <span class="hljs-keyword">of</span> obj[<span class="hljs-number">2</span>]) <span class="hljs-keyword">then</span> locationData = obj[<span class="hljs-number">2</span>]
409  <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> <span class="hljs-string">"first_line"</span> <span class="hljs-keyword">of</span> obj <span class="hljs-keyword">then</span> locationData = obj
410
411  <span class="hljs-keyword">if</span> locationData
412    <span class="hljs-string">"<span class="hljs-subst">#{locationData.first_line + <span class="hljs-number">1</span>}</span>:<span class="hljs-subst">#{locationData.first_column + <span class="hljs-number">1</span>}</span>-"</span> +
413    <span class="hljs-string">"<span class="hljs-subst">#{locationData.last_line + <span class="hljs-number">1</span>}</span>:<span class="hljs-subst">#{locationData.last_column + <span class="hljs-number">1</span>}</span>"</span>
414  <span class="hljs-keyword">else</span>
415    <span class="hljs-string">"No location data"</span></pre></div></div>
416            
417        </li>
418        
419        
420        <li id="section-17">
421            <div class="annotation">
422              
423              <div class="pilwrap ">
424                <a class="pilcrow" href="#section-17">&#182;</a>
425              </div>
426              <p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.</p>
427
428            </div>
429            
430            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">baseFileName</span> = <span class="hljs-params">(file, stripExt = <span class="hljs-literal">no</span>, useWinPathSep = <span class="hljs-literal">no</span>)</span> -&gt;</span>
431  pathSep = <span class="hljs-keyword">if</span> useWinPathSep <span class="hljs-keyword">then</span> <span class="hljs-regexp">/\\|\//</span> <span class="hljs-keyword">else</span> <span class="hljs-regexp">/\/</span>/
432  parts = file.split(pathSep)
433  file = parts[parts.length - <span class="hljs-number">1</span>]
434  <span class="hljs-keyword">return</span> file <span class="hljs-keyword">unless</span> stripExt <span class="hljs-keyword">and</span> file.indexOf(<span class="hljs-string">'.'</span>) &gt;= <span class="hljs-number">0</span>
435  parts = file.split(<span class="hljs-string">'.'</span>)
436  parts.pop()
437  parts.pop() <span class="hljs-keyword">if</span> parts[parts.length - <span class="hljs-number">1</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">'coffee'</span> <span class="hljs-keyword">and</span> parts.length &gt; <span class="hljs-number">1</span>
438  parts.join(<span class="hljs-string">'.'</span>)</pre></div></div>
439            
440        </li>
441        
442        
443        <li id="section-18">
444            <div class="annotation">
445              
446              <div class="pilwrap ">
447                <a class="pilcrow" href="#section-18">&#182;</a>
448              </div>
449              <p>Determine if a filename represents a CoffeeScript file.</p>
450
451            </div>
452            
453            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">isCoffee</span> = <span class="hljs-params">(file)</span> -&gt;</span> <span class="hljs-regexp">/\.((lit)?coffee|coffee\.md)$/</span>.test file</pre></div></div>
454            
455        </li>
456        
457        
458        <li id="section-19">
459            <div class="annotation">
460              
461              <div class="pilwrap ">
462                <a class="pilcrow" href="#section-19">&#182;</a>
463              </div>
464              <p>Determine if a filename represents a Literate CoffeeScript file.</p>
465
466            </div>
467            
468            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">isLiterate</span> = <span class="hljs-params">(file)</span> -&gt;</span> <span class="hljs-regexp">/\.(litcoffee|coffee\.md)$/</span>.test file</pre></div></div>
469            
470        </li>
471        
472        
473        <li id="section-20">
474            <div class="annotation">
475              
476              <div class="pilwrap ">
477                <a class="pilcrow" href="#section-20">&#182;</a>
478              </div>
479              <p>Throws a SyntaxError from a given location.
480The error’s <code>toString</code> will return an error message following the “standard”
481format <filename>:<line>:<col>: <message> plus the line with the error and a
482marker showing where the error is.</p>
483
484            </div>
485            
486            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">throwSyntaxError</span> = <span class="hljs-params">(message, location)</span> -&gt;</span>
487  error = <span class="hljs-keyword">new</span> SyntaxError message
488  error.location = location
489  error.toString = syntaxErrorToString</pre></div></div>
490            
491        </li>
492        
493        
494        <li id="section-21">
495            <div class="annotation">
496              
497              <div class="pilwrap ">
498                <a class="pilcrow" href="#section-21">&#182;</a>
499              </div>
500              <p>Instead of showing the compiler’s stacktrace, show our custom error message
501(this is useful when the error bubbles up in Node.js applications that
502compile CoffeeScript for example).</p>
503
504            </div>
505            
506            <div class="content"><div class='highlight'><pre>  error.stack = error.toString()
507
508  <span class="hljs-keyword">throw</span> error</pre></div></div>
509            
510        </li>
511        
512        
513        <li id="section-22">
514            <div class="annotation">
515              
516              <div class="pilwrap ">
517                <a class="pilcrow" href="#section-22">&#182;</a>
518              </div>
519              <p>Update a compiler SyntaxError with source code information if it didn’t have
520it already.</p>
521
522            </div>
523            
524            <div class="content"><div class='highlight'><pre><span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">updateSyntaxError</span> = <span class="hljs-params">(error, code, filename)</span> -&gt;</span></pre></div></div>
525            
526        </li>
527        
528        
529        <li id="section-23">
530            <div class="annotation">
531              
532              <div class="pilwrap ">
533                <a class="pilcrow" href="#section-23">&#182;</a>
534              </div>
535              <p>Avoid screwing up the <code>stack</code> property of other errors (i.e. possible bugs).</p>
536
537            </div>
538            
539            <div class="content"><div class='highlight'><pre>  <span class="hljs-keyword">if</span> error.toString <span class="hljs-keyword">is</span> syntaxErrorToString
540    error.code <span class="hljs-keyword">or</span>= code
541    error.filename <span class="hljs-keyword">or</span>= filename
542    error.stack = error.toString()
543  error
544
545<span class="hljs-function"><span class="hljs-title">syntaxErrorToString</span> = -&gt;</span>
546  <span class="hljs-keyword">return</span> <span class="hljs-attribute">Error</span>::toString.call @ <span class="hljs-keyword">unless</span> <span class="hljs-property">@code</span> <span class="hljs-keyword">and</span> <span class="hljs-property">@location</span>
547
548  {first_line, first_column, last_line, last_column} = <span class="hljs-property">@location</span>
549  last_line ?= first_line
550  last_column ?= first_column
551
552  filename = <span class="hljs-property">@filename</span> <span class="hljs-keyword">or</span> <span class="hljs-string">'[stdin]'</span>
553  codeLine = <span class="hljs-property">@code</span>.split(<span class="hljs-string">'\n'</span>)[first_line]
554  start    = first_column</pre></div></div>
555            
556        </li>
557        
558        
559        <li id="section-24">
560            <div class="annotation">
561              
562              <div class="pilwrap ">
563                <a class="pilcrow" href="#section-24">&#182;</a>
564              </div>
565              <p>Show only the first line on multi-line errors.</p>
566
567            </div>
568            
569            <div class="content"><div class='highlight'><pre>  end      = <span class="hljs-keyword">if</span> first_line <span class="hljs-keyword">is</span> last_line <span class="hljs-keyword">then</span> last_column + <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> codeLine.length
570  marker   = codeLine[...start].replace(<span class="hljs-regexp">/[^\s]/g</span>, <span class="hljs-string">' '</span>) + repeat(<span class="hljs-string">'^'</span>, end - start)</pre></div></div>
571            
572        </li>
573        
574        
575        <li id="section-25">
576            <div class="annotation">
577              
578              <div class="pilwrap ">
579                <a class="pilcrow" href="#section-25">&#182;</a>
580              </div>
581              <p>Check to see if we’re running on a color-enabled TTY.</p>
582
583            </div>
584            
585            <div class="content"><div class='highlight'><pre>  <span class="hljs-keyword">if</span> process?
586    colorsEnabled = process.stdout?.isTTY <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> process.env?.NODE_DISABLE_COLORS
587
588  <span class="hljs-keyword">if</span> <span class="hljs-property">@colorful</span> ? colorsEnabled
589    <span class="hljs-function"><span class="hljs-title">colorize</span> = <span class="hljs-params">(str)</span> -&gt;</span> <span class="hljs-string">"\x1B[1;31m<span class="hljs-subst">#{str}</span>\x1B[0m"</span>
590    codeLine = codeLine[...start] + colorize(codeLine[start...end]) + codeLine[end..]
591    marker   = colorize marker
592
593  <span class="hljs-string">"""
594    <span class="hljs-subst">#{filename}</span>:<span class="hljs-subst">#{first_line + <span class="hljs-number">1</span>}</span>:<span class="hljs-subst">#{first_column + <span class="hljs-number">1</span>}</span>: error: <span class="hljs-subst">#{<span class="hljs-property">@message</span>}</span>
595    <span class="hljs-subst">#{codeLine}</span>
596    <span class="hljs-subst">#{marker}</span>
597  """</span>
598
599<span class="hljs-built_in">exports</span>.<span class="hljs-function"><span class="hljs-title">nameWhitespaceCharacter</span> = <span class="hljs-params">(string)</span> -&gt;</span>
600  <span class="hljs-keyword">switch</span> string
601    <span class="hljs-keyword">when</span> <span class="hljs-string">' '</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'space'</span>
602    <span class="hljs-keyword">when</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'newline'</span>
603    <span class="hljs-keyword">when</span> <span class="hljs-string">'\r'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'carriage return'</span>
604    <span class="hljs-keyword">when</span> <span class="hljs-string">'\t'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'tab'</span>
605    <span class="hljs-keyword">else</span> string</pre></div></div>
606            
607        </li>
608        
609    </ul>
610  </div>
611</body>
612</html>