/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. <html>
  3. <head>
  4. <title>helpers.coffee</title>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  7. <link rel="stylesheet" media="all" href="docco.css" />
  8. </head>
  9. <body>
  10. <div id="container">
  11. <div id="background"></div>
  12. <ul id="jump_to">
  13. <li>
  14. <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
  15. <a class="small" href="javascript:void(0);">+</a>
  16. <div id="jump_wrapper">
  17. <div id="jump_page_wrapper">
  18. <div id="jump_page">
  19. <a class="source" href="browser.html">
  20. browser.coffee
  21. </a>
  22. <a class="source" href="cake.html">
  23. cake.coffee
  24. </a>
  25. <a class="source" href="coffee-script.html">
  26. coffee-script.coffee
  27. </a>
  28. <a class="source" href="command.html">
  29. command.coffee
  30. </a>
  31. <a class="source" href="grammar.html">
  32. grammar.coffee
  33. </a>
  34. <a class="source" href="helpers.html">
  35. helpers.coffee
  36. </a>
  37. <a class="source" href="index.html">
  38. index.coffee
  39. </a>
  40. <a class="source" href="lexer.html">
  41. lexer.coffee
  42. </a>
  43. <a class="source" href="nodes.html">
  44. nodes.coffee
  45. </a>
  46. <a class="source" href="optparse.html">
  47. optparse.coffee
  48. </a>
  49. <a class="source" href="register.html">
  50. register.coffee
  51. </a>
  52. <a class="source" href="repl.html">
  53. repl.coffee
  54. </a>
  55. <a class="source" href="rewriter.html">
  56. rewriter.coffee
  57. </a>
  58. <a class="source" href="scope.html">
  59. scope.litcoffee
  60. </a>
  61. <a class="source" href="sourcemap.html">
  62. sourcemap.litcoffee
  63. </a>
  64. </div>
  65. </div>
  66. </li>
  67. </ul>
  68. <ul class="sections">
  69. <li id="title">
  70. <div class="annotation">
  71. <h1>helpers.coffee</h1>
  72. </div>
  73. </li>
  74. <li id="section-1">
  75. <div class="annotation">
  76. <div class="pilwrap ">
  77. <a class="pilcrow" href="#section-1">&#182;</a>
  78. </div>
  79. <p>This file contains the common helper functions that wed like to share among
  80. the <strong>Lexer</strong>, <strong>Rewriter</strong>, and the <strong>Nodes</strong>. Merge objects, flatten
  81. arrays, count characters, that sort of thing.</p>
  82. </div>
  83. </li>
  84. <li id="section-2">
  85. <div class="annotation">
  86. <div class="pilwrap ">
  87. <a class="pilcrow" href="#section-2">&#182;</a>
  88. </div>
  89. <p>Peek at the beginning of a given string to see if it matches a sequence.</p>
  90. </div>
  91. <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>
  92. literal <span class="hljs-keyword">is</span> string.substr start, literal.length</pre></div></div>
  93. </li>
  94. <li id="section-3">
  95. <div class="annotation">
  96. <div class="pilwrap ">
  97. <a class="pilcrow" href="#section-3">&#182;</a>
  98. </div>
  99. <p>Peek at the end of a given string to see if it matches a sequence.</p>
  100. </div>
  101. <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>
  102. len = literal.length
  103. 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>
  104. </li>
  105. <li id="section-4">
  106. <div class="annotation">
  107. <div class="pilwrap ">
  108. <a class="pilcrow" href="#section-4">&#182;</a>
  109. </div>
  110. <p>Repeat a string <code>n</code> times.</p>
  111. </div>
  112. <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>
  113. </li>
  114. <li id="section-5">
  115. <div class="annotation">
  116. <div class="pilwrap ">
  117. <a class="pilcrow" href="#section-5">&#182;</a>
  118. </div>
  119. <p>Use clever algorithm to have O(log(n)) string concatenation operations.</p>
  120. </div>
  121. <div class="content"><div class='highlight'><pre> res = <span class="hljs-string">''</span>
  122. <span class="hljs-keyword">while</span> n &gt; <span class="hljs-number">0</span>
  123. res += str <span class="hljs-keyword">if</span> n &amp; <span class="hljs-number">1</span>
  124. n &gt;&gt;&gt;= <span class="hljs-number">1</span>
  125. str += str
  126. res</pre></div></div>
  127. </li>
  128. <li id="section-6">
  129. <div class="annotation">
  130. <div class="pilwrap ">
  131. <a class="pilcrow" href="#section-6">&#182;</a>
  132. </div>
  133. <p>Trim out all falsy values from an array.</p>
  134. </div>
  135. <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>
  136. 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>
  137. </li>
  138. <li id="section-7">
  139. <div class="annotation">
  140. <div class="pilwrap ">
  141. <a class="pilcrow" href="#section-7">&#182;</a>
  142. </div>
  143. <p>Count the number of occurrences of a string in a string.</p>
  144. </div>
  145. <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>
  146. num = pos = <span class="hljs-number">0</span>
  147. <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
  148. num++ <span class="hljs-keyword">while</span> pos = <span class="hljs-number">1</span> + string.indexOf substr, pos
  149. num</pre></div></div>
  150. </li>
  151. <li id="section-8">
  152. <div class="annotation">
  153. <div class="pilwrap ">
  154. <a class="pilcrow" href="#section-8">&#182;</a>
  155. </div>
  156. <p>Merge objects, returning a fresh copy with attributes from both sides.
  157. Used every time <code>Base#compile</code> is called, to allow properties in the
  158. options hash to propagate down the tree without polluting other branches.</p>
  159. </div>
  160. <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>
  161. extend (extend {}, options), overrides</pre></div></div>
  162. </li>
  163. <li id="section-9">
  164. <div class="annotation">
  165. <div class="pilwrap ">
  166. <a class="pilcrow" href="#section-9">&#182;</a>
  167. </div>
  168. <p>Extend a source object with the properties of another object (shallow copy).</p>
  169. </div>
  170. <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>
  171. <span class="hljs-keyword">for</span> key, val <span class="hljs-keyword">of</span> properties
  172. object[key] = val
  173. object</pre></div></div>
  174. </li>
  175. <li id="section-10">
  176. <div class="annotation">
  177. <div class="pilwrap ">
  178. <a class="pilcrow" href="#section-10">&#182;</a>
  179. </div>
  180. <p>Return a flattened version of an array.
  181. Handy for getting a list of <code>children</code> from the nodes.</p>
  182. </div>
  183. <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>
  184. flattened = []
  185. <span class="hljs-keyword">for</span> element <span class="hljs-keyword">in</span> array
  186. <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
  187. flattened = flattened.concat flatten element
  188. <span class="hljs-keyword">else</span>
  189. flattened.push element
  190. flattened</pre></div></div>
  191. </li>
  192. <li id="section-11">
  193. <div class="annotation">
  194. <div class="pilwrap ">
  195. <a class="pilcrow" href="#section-11">&#182;</a>
  196. </div>
  197. <p>Delete a key from an object, returning the value. Useful when a node is
  198. looking for a particular method in an options hash.</p>
  199. </div>
  200. <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>
  201. val = obj[key]
  202. <span class="hljs-keyword">delete</span> obj[key]
  203. val</pre></div></div>
  204. </li>
  205. <li id="section-12">
  206. <div class="annotation">
  207. <div class="pilwrap ">
  208. <a class="pilcrow" href="#section-12">&#182;</a>
  209. </div>
  210. <p>Typical Array::some</p>
  211. </div>
  212. <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>
  213. <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
  214. <span class="hljs-literal">false</span></pre></div></div>
  215. </li>
  216. <li id="section-13">
  217. <div class="annotation">
  218. <div class="pilwrap ">
  219. <a class="pilcrow" href="#section-13">&#182;</a>
  220. </div>
  221. <p>Simple function for inverting Literate CoffeeScript code by putting the
  222. documentation in comments, producing a string of CoffeeScript code that
  223. can be compiled normally.</p>
  224. </div>
  225. <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>
  226. maybe_code = <span class="hljs-literal">true</span>
  227. lines = <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> code.split(<span class="hljs-string">'\n'</span>)
  228. <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
  229. line
  230. <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> maybe_code = <span class="hljs-regexp">/^\s*$/</span>.test line
  231. line
  232. <span class="hljs-keyword">else</span>
  233. <span class="hljs-string">'# '</span> + line
  234. lines.join <span class="hljs-string">'\n'</span></pre></div></div>
  235. </li>
  236. <li id="section-14">
  237. <div class="annotation">
  238. <div class="pilwrap ">
  239. <a class="pilcrow" href="#section-14">&#182;</a>
  240. </div>
  241. <p>Merge two jison-style location data objects together.
  242. If <code>last</code> is not provided, this will simply return <code>first</code>.</p>
  243. </div>
  244. <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>
  245. <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> last
  246. first
  247. <span class="hljs-keyword">else</span>
  248. <span class="hljs-attribute">first_line</span>: first.first_line
  249. <span class="hljs-attribute">first_column</span>: first.first_column
  250. <span class="hljs-attribute">last_line</span>: last.last_line
  251. <span class="hljs-attribute">last_column</span>: last.last_column</pre></div></div>
  252. </li>
  253. <li id="section-15">
  254. <div class="annotation">
  255. <div class="pilwrap ">
  256. <a class="pilcrow" href="#section-15">&#182;</a>
  257. </div>
  258. <p>This returns a function which takes an object as a parameter, and if that
  259. object is an AST node, updates that objects locationData.
  260. The object is returned either way.</p>
  261. </div>
  262. <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>
  263. <span class="hljs-function"><span class="hljs-params">(obj)</span> -&gt;</span>
  264. <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>])
  265. obj.updateLocationDataIfMissing buildLocationData(first, last)
  266. <span class="hljs-keyword">return</span> obj</pre></div></div>
  267. </li>
  268. <li id="section-16">
  269. <div class="annotation">
  270. <div class="pilwrap ">
  271. <a class="pilcrow" href="#section-16">&#182;</a>
  272. </div>
  273. <p>Convert jison location data to a string.
  274. <code>obj</code> can be a token, or a locationData.</p>
  275. </div>
  276. <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>
  277. <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>]
  278. <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
  279. <span class="hljs-keyword">if</span> locationData
  280. <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> +
  281. <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>
  282. <span class="hljs-keyword">else</span>
  283. <span class="hljs-string">"No location data"</span></pre></div></div>
  284. </li>
  285. <li id="section-17">
  286. <div class="annotation">
  287. <div class="pilwrap ">
  288. <a class="pilcrow" href="#section-17">&#182;</a>
  289. </div>
  290. <p>A <code>.coffee.md</code> compatible version of <code>basename</code>, that returns the file sans-extension.</p>
  291. </div>
  292. <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>
  293. 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>/
  294. parts = file.split(pathSep)
  295. file = parts[parts.length - <span class="hljs-number">1</span>]
  296. <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>
  297. parts = file.split(<span class="hljs-string">'.'</span>)
  298. parts.pop()
  299. 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>
  300. parts.join(<span class="hljs-string">'.'</span>)</pre></div></div>
  301. </li>
  302. <li id="section-18">
  303. <div class="annotation">
  304. <div class="pilwrap ">
  305. <a class="pilcrow" href="#section-18">&#182;</a>
  306. </div>
  307. <p>Determine if a filename represents a CoffeeScript file.</p>
  308. </div>
  309. <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>
  310. </li>
  311. <li id="section-19">
  312. <div class="annotation">
  313. <div class="pilwrap ">
  314. <a class="pilcrow" href="#section-19">&#182;</a>
  315. </div>
  316. <p>Determine if a filename represents a Literate CoffeeScript file.</p>
  317. </div>
  318. <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>
  319. </li>
  320. <li id="section-20">
  321. <div class="annotation">
  322. <div class="pilwrap ">
  323. <a class="pilcrow" href="#section-20">&#182;</a>
  324. </div>
  325. <p>Throws a SyntaxError from a given location.
  326. The errors <code>toString</code> will return an error message following the standard
  327. format <filename>:<line>:<col>: <message> plus the line with the error and a
  328. marker showing where the error is.</p>
  329. </div>
  330. <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>
  331. error = <span class="hljs-keyword">new</span> SyntaxError message
  332. error.location = location
  333. error.toString = syntaxErrorToString</pre></div></div>
  334. </li>
  335. <li id="section-21">
  336. <div class="annotation">
  337. <div class="pilwrap ">
  338. <a class="pilcrow" href="#section-21">&#182;</a>
  339. </div>
  340. <p>Instead of showing the compilers stacktrace, show our custom error message
  341. (this is useful when the error bubbles up in Node.js applications that
  342. compile CoffeeScript for example).</p>
  343. </div>
  344. <div class="content"><div class='highlight'><pre> error.stack = error.toString()
  345. <span class="hljs-keyword">throw</span> error</pre></div></div>
  346. </li>
  347. <li id="section-22">
  348. <div class="annotation">
  349. <div class="pilwrap ">
  350. <a class="pilcrow" href="#section-22">&#182;</a>
  351. </div>
  352. <p>Update a compiler SyntaxError with source code information if it didnt have
  353. it already.</p>
  354. </div>
  355. <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>
  356. </li>
  357. <li id="section-23">
  358. <div class="annotation">
  359. <div class="pilwrap ">
  360. <a class="pilcrow" href="#section-23">&#182;</a>
  361. </div>
  362. <p>Avoid screwing up the <code>stack</code> property of other errors (i.e. possible bugs).</p>
  363. </div>
  364. <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> error.toString <span class="hljs-keyword">is</span> syntaxErrorToString
  365. error.code <span class="hljs-keyword">or</span>= code
  366. error.filename <span class="hljs-keyword">or</span>= filename
  367. error.stack = error.toString()
  368. error
  369. <span class="hljs-function"><span class="hljs-title">syntaxErrorToString</span> = -&gt;</span>
  370. <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>
  371. {first_line, first_column, last_line, last_column} = <span class="hljs-property">@location</span>
  372. last_line ?= first_line
  373. last_column ?= first_column
  374. filename = <span class="hljs-property">@filename</span> <span class="hljs-keyword">or</span> <span class="hljs-string">'[stdin]'</span>
  375. codeLine = <span class="hljs-property">@code</span>.split(<span class="hljs-string">'\n'</span>)[first_line]
  376. start = first_column</pre></div></div>
  377. </li>
  378. <li id="section-24">
  379. <div class="annotation">
  380. <div class="pilwrap ">
  381. <a class="pilcrow" href="#section-24">&#182;</a>
  382. </div>
  383. <p>Show only the first line on multi-line errors.</p>
  384. </div>
  385. <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
  386. 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>
  387. </li>
  388. <li id="section-25">
  389. <div class="annotation">
  390. <div class="pilwrap ">
  391. <a class="pilcrow" href="#section-25">&#182;</a>
  392. </div>
  393. <p>Check to see if were running on a color-enabled TTY.</p>
  394. </div>
  395. <div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> process?
  396. colorsEnabled = process.stdout?.isTTY <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> process.env?.NODE_DISABLE_COLORS
  397. <span class="hljs-keyword">if</span> <span class="hljs-property">@colorful</span> ? colorsEnabled
  398. <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>
  399. codeLine = codeLine[...start] + colorize(codeLine[start...end]) + codeLine[end..]
  400. marker = colorize marker
  401. <span class="hljs-string">"""
  402. <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>
  403. <span class="hljs-subst">#{codeLine}</span>
  404. <span class="hljs-subst">#{marker}</span>
  405. """</span>
  406. <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>
  407. <span class="hljs-keyword">switch</span> string
  408. <span class="hljs-keyword">when</span> <span class="hljs-string">' '</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'space'</span>
  409. <span class="hljs-keyword">when</span> <span class="hljs-string">'\n'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'newline'</span>
  410. <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>
  411. <span class="hljs-keyword">when</span> <span class="hljs-string">'\t'</span> <span class="hljs-keyword">then</span> <span class="hljs-string">'tab'</span>
  412. <span class="hljs-keyword">else</span> string</pre></div></div>
  413. </li>
  414. </ul>
  415. </div>
  416. </body>
  417. </html>