3054e35b0fac4ecfb6dbb7dfe968069518ed97e7
[myslice.git] / third-party / codemirror-3.15 / mode / livescript / index.html
1 <!doctype html>
2 <html>
3   <head>
4     <title>CodeMirror: LiveScript mode</title>
5     <link rel="stylesheet" href="../../lib/codemirror.css">
6     <script src="../../lib/codemirror.js"></script>
7     <script src="livescript.js"></script>
8     <style>.CodeMirror {font-size: 80%;border-top: 1px solid silver; border-bottom: 1px solid silver;}</style>
9     <link rel="stylesheet" href="../../doc/docs.css">
10     <link rel="stylesheet" href="../../theme/solarized.css">
11   </head>
12   <body>
13     <h1>CodeMirror: LiveScript mode</h1>
14     <form><textarea id="code" name="code">
15 # LiveScript mode for CodeMirror
16 # The following script, prelude.ls, is used to
17 # demonstrate LiveScript mode for CodeMirror.
18 #   https://github.com/gkz/prelude-ls
19
20 export objToFunc = objToFunc = (obj) ->
21   (key) -> obj[key]
22
23 export each = (f, xs) -->
24   if typeof! xs is \Object
25     for , x of xs then f x
26   else
27     for x in xs then f x
28   xs
29
30 export map = (f, xs) -->
31   f = objToFunc f if typeof! f isnt \Function
32   type = typeof! xs
33   if type is \Object
34     {[key, f x] for key, x of xs}
35   else
36     result = [f x for x in xs]
37     if type is \String then result * '' else result
38
39 export filter = (f, xs) -->
40   f = objToFunc f if typeof! f isnt \Function
41   type = typeof! xs
42   if type is \Object
43     {[key, x] for key, x of xs when f x}
44   else
45     result = [x for x in xs when f x]
46     if type is \String then result * '' else result
47
48 export reject = (f, xs) -->
49   f = objToFunc f if typeof! f isnt \Function
50   type = typeof! xs
51   if type is \Object
52     {[key, x] for key, x of xs when not f x}
53   else
54     result = [x for x in xs when not f x]
55     if type is \String then result * '' else result
56
57 export partition = (f, xs) -->
58   f = objToFunc f if typeof! f isnt \Function
59   type = typeof! xs
60   if type is \Object
61     passed = {}
62     failed = {}
63     for key, x of xs
64       (if f x then passed else failed)[key] = x
65   else
66     passed = []
67     failed = []
68     for x in xs
69       (if f x then passed else failed)push x
70     if type is \String
71       passed *= ''
72       failed *= ''
73   [passed, failed]
74
75 export find = (f, xs) -->
76   f = objToFunc f if typeof! f isnt \Function
77   if typeof! xs is \Object
78     for , x of xs when f x then return x
79   else
80     for x in xs when f x then return x
81   void
82
83 export head = export first = (xs) ->
84   return void if not xs.length
85   xs.0
86
87 export tail = (xs) ->
88   return void if not xs.length
89   xs.slice 1
90
91 export last = (xs) ->
92   return void if not xs.length
93   xs[*-1]
94
95 export initial = (xs) ->
96   return void if not xs.length
97   xs.slice 0 xs.length - 1
98
99 export empty = (xs) ->
100   if typeof! xs is \Object
101     for x of xs then return false
102     return yes
103   not xs.length
104
105 export values = (obj) ->
106   [x for , x of obj]
107
108 export keys = (obj) ->
109   [x for x of obj]
110
111 export len = (xs) ->
112   xs = values xs if typeof! xs is \Object
113   xs.length
114
115 export cons = (x, xs) -->
116   if typeof! xs is \String then x + xs else [x] ++ xs
117
118 export append = (xs, ys) -->
119   if typeof! ys is \String then xs + ys else xs ++ ys
120
121 export join = (sep, xs) -->
122   xs = values xs if typeof! xs is \Object
123   xs.join sep
124
125 export reverse = (xs) ->
126   if typeof! xs is \String
127   then (xs / '')reverse! * ''
128   else xs.slice!reverse!
129
130 export fold = export foldl = (f, memo, xs) -->
131   if typeof! xs is \Object
132     for , x of xs then memo = f memo, x
133   else
134     for x in xs then memo = f memo, x
135   memo
136
137 export fold1 = export foldl1 = (f, xs) --> fold f, xs.0, xs.slice 1
138
139 export foldr = (f, memo, xs) --> fold f, memo, xs.slice!reverse!
140
141 export foldr1 = (f, xs) -->
142   xs.=slice!reverse!
143   fold f, xs.0, xs.slice 1
144
145 export unfoldr = export unfold = (f, b) -->
146   if (f b)?
147     [that.0] ++ unfoldr f, that.1
148   else
149     []
150
151 export andList = (xs) ->
152   for x in xs when not x
153     return false
154   true
155
156 export orList = (xs) ->
157   for x in xs when x
158     return true
159   false
160
161 export any = (f, xs) -->
162   f = objToFunc f if typeof! f isnt \Function
163   for x in xs when f x
164     return yes
165   no
166
167 export all = (f, xs) -->
168   f = objToFunc f if typeof! f isnt \Function
169   for x in xs when not f x
170     return no
171   yes
172
173 export unique = (xs) ->
174   result = []
175   if typeof! xs is \Object
176     for , x of xs when x not in result then result.push x
177   else
178     for x   in xs when x not in result then result.push x
179   if typeof! xs is \String then result * '' else result
180
181 export sort = (xs) ->
182   xs.concat!sort (x, y) ->
183     | x > y =>  1
184     | x < y => -1
185     | _     =>  0
186
187 export sortBy = (f, xs) -->
188   return [] unless xs.length
189   xs.concat!sort f
190
191 export compare = (f, x, y) -->
192   | (f x) > (f y) =>  1
193   | (f x) < (f y) => -1
194   | otherwise     =>  0
195
196 export sum = (xs) ->
197   result = 0
198   if typeof! xs is \Object
199     for , x of xs then result += x
200   else
201     for x   in xs then result += x
202   result
203
204 export product = (xs) ->
205   result = 1
206   if typeof! xs is \Object
207     for , x of xs then result *= x
208   else
209     for x   in xs then result *= x
210   result
211
212 export mean = export average = (xs) -> (sum xs) / len xs
213
214 export concat = (xss) -> fold append, [], xss
215
216 export concatMap = (f, xs) --> fold ((memo, x) -> append memo, f x), [], xs
217
218 export listToObj = (xs) ->
219   {[x.0, x.1] for x in xs}
220
221 export maximum = (xs) -> fold1 (>?), xs
222
223 export minimum = (xs) -> fold1 (<?), xs
224
225 export scan = export scanl = (f, memo, xs) -->
226   last = memo
227   if typeof! xs is \Object
228   then [memo] ++ [last = f last, x for , x of xs]
229   else [memo] ++ [last = f last, x for x in xs]
230
231 export scan1 = export scanl1 = (f, xs) --> scan f, xs.0, xs.slice 1
232
233 export scanr = (f, memo, xs) -->
234   xs.=slice!reverse!
235   scan f, memo, xs .reverse!
236
237 export scanr1 = (f, xs) -->
238   xs.=slice!reverse!
239   scan f, xs.0, xs.slice 1 .reverse!
240
241 export replicate = (n, x) -->
242   result = []
243   i = 0
244   while i < n, ++i then result.push x
245   result
246
247 export take = (n, xs) -->
248   | n <= 0
249     if typeof! xs is \String then '' else []
250   | not xs.length => xs
251   | otherwise     => xs.slice 0, n
252
253 export drop = (n, xs) -->
254   | n <= 0        => xs
255   | not xs.length => xs
256   | otherwise     => xs.slice n
257
258 export splitAt = (n, xs) --> [(take n, xs), (drop n, xs)]
259
260 export takeWhile = (p, xs) -->
261   return xs if not xs.length
262   p = objToFunc p if typeof! p isnt \Function
263   result = []
264   for x in xs
265     break if not p x
266     result.push x
267   if typeof! xs is \String then result * '' else result
268
269 export dropWhile = (p, xs) -->
270   return xs if not xs.length
271   p = objToFunc p if typeof! p isnt \Function
272   i = 0
273   for x in xs
274     break if not p x
275     ++i
276   drop i, xs
277
278 export span = (p, xs) --> [(takeWhile p, xs), (dropWhile p, xs)]
279
280 export breakIt = (p, xs) --> span (not) << p, xs
281
282 export zip = (xs, ys) -->
283   result = []
284   for zs, i in [xs, ys]
285     for z, j in zs
286       result.push [] if i is 0
287       result[j]?push z
288   result
289
290 export zipWith = (f,xs, ys) -->
291   f = objToFunc f if typeof! f isnt \Function
292   if not xs.length or not ys.length
293     []
294   else
295     [f.apply this, zs for zs in zip.call this, xs, ys]
296
297 export zipAll = (...xss) ->
298   result = []
299   for xs, i in xss
300     for x, j in xs
301       result.push [] if i is 0
302       result[j]?push x
303   result
304
305 export zipAllWith = (f, ...xss) ->
306   f = objToFunc f if typeof! f isnt \Function
307   if not xss.0.length or not xss.1.length
308     []
309   else
310     [f.apply this, xs for xs in zipAll.apply this, xss]
311
312 export compose = (...funcs) ->
313   ->
314     args = arguments
315     for f in funcs
316       args = [f.apply this, args]
317     args.0
318
319 export curry = (f) ->
320   curry$ f # using util method curry$ from livescript
321
322 export id = (x) -> x
323
324 export flip = (f, x, y) --> f y, x
325
326 export fix = (f) ->
327   ( (g, x) -> -> f(g g) ...arguments ) do
328     (g, x) -> -> f(g g) ...arguments
329
330 export lines = (str) ->
331   return [] if not str.length
332   str / \\n
333
334 export unlines = (strs) -> strs * \\n
335
336 export words = (str) ->
337   return [] if not str.length
338   str / /[ ]+/
339
340 export unwords = (strs) -> strs * ' '
341
342 export max = (>?)
343
344 export min = (<?)
345
346 export negate = (x) -> -x
347
348 export abs = Math.abs
349
350 export signum = (x) ->
351   | x < 0     => -1
352   | x > 0     =>  1
353   | otherwise =>  0
354
355 export quot = (x, y) --> ~~(x / y)
356
357 export rem = (%)
358
359 export div = (x, y) --> Math.floor x / y
360
361 export mod = (%%)
362
363 export recip = (1 /)
364
365 export pi = Math.PI
366
367 export tau = pi * 2
368
369 export exp = Math.exp
370
371 export sqrt = Math.sqrt
372
373 # changed from log as log is a
374 # common function for logging things
375 export ln = Math.log
376
377 export pow = (^)
378
379 export sin = Math.sin
380
381 export tan = Math.tan
382
383 export cos = Math.cos
384
385 export asin = Math.asin
386
387 export acos = Math.acos
388
389 export atan = Math.atan
390
391 export atan2 = (x, y) --> Math.atan2 x, y
392
393 # sinh
394 # tanh
395 # cosh
396 # asinh
397 # atanh
398 # acosh
399
400 export truncate = (x) -> ~~x
401
402 export round = Math.round
403
404 export ceiling = Math.ceil
405
406 export floor = Math.floor
407
408 export isItNaN = (x) -> x isnt x
409
410 export even = (x) -> x % 2 == 0
411
412 export odd = (x) -> x % 2 != 0
413
414 export gcd = (x, y) -->
415   x = Math.abs x
416   y = Math.abs y
417   until y is 0
418     z = x % y
419     x = y
420     y = z
421   x
422
423 export lcm = (x, y) -->
424   Math.abs Math.floor (x / (gcd x, y) * y)
425
426 # meta
427 export installPrelude = !(target) ->
428   unless target.prelude?isInstalled
429     target <<< out$ # using out$ generated by livescript
430     target <<< target.prelude.isInstalled = true
431
432 export prelude = out$
433 </textarea></form>
434     <script>
435       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
436         theme: "solarized light",
437         lineNumbers: true
438       });
439     </script>
440
441     <p><strong>MIME types defined:</strong> <code>text/x-livescript</code>.</p>
442
443     <p>The LiveScript mode was written by Kenneth Bentley (<a href="LICENSE">license</a>).</p>
444
445   </body>
446 </html>