]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/livescript.js
Initial commit.
[flow-web.git] / static / highlight / languages / livescript.js
1 /*! `livescript` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 const KEYWORDS = [
7 "as", // for exports
8 "in",
9 "of",
10 "if",
11 "for",
12 "while",
13 "finally",
14 "var",
15 "new",
16 "function",
17 "do",
18 "return",
19 "void",
20 "else",
21 "break",
22 "catch",
23 "instanceof",
24 "with",
25 "throw",
26 "case",
27 "default",
28 "try",
29 "switch",
30 "continue",
31 "typeof",
32 "delete",
33 "let",
34 "yield",
35 "const",
36 "class",
37 // JS handles these with a special rule
38 // "get",
39 // "set",
40 "debugger",
41 "async",
42 "await",
43 "static",
44 "import",
45 "from",
46 "export",
47 "extends",
48 // It's reached stage 3, which is "recommended for implementation":
49 "using"
50 ];
51 const LITERALS = [
52 "true",
53 "false",
54 "null",
55 "undefined",
56 "NaN",
57 "Infinity"
58 ];
59
60 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
61 const TYPES = [
62 // Fundamental objects
63 "Object",
64 "Function",
65 "Boolean",
66 "Symbol",
67 // numbers and dates
68 "Math",
69 "Date",
70 "Number",
71 "BigInt",
72 // text
73 "String",
74 "RegExp",
75 // Indexed collections
76 "Array",
77 "Float32Array",
78 "Float64Array",
79 "Int8Array",
80 "Uint8Array",
81 "Uint8ClampedArray",
82 "Int16Array",
83 "Int32Array",
84 "Uint16Array",
85 "Uint32Array",
86 "BigInt64Array",
87 "BigUint64Array",
88 // Keyed collections
89 "Set",
90 "Map",
91 "WeakSet",
92 "WeakMap",
93 // Structured data
94 "ArrayBuffer",
95 "SharedArrayBuffer",
96 "Atomics",
97 "DataView",
98 "JSON",
99 // Control abstraction objects
100 "Promise",
101 "Generator",
102 "GeneratorFunction",
103 "AsyncFunction",
104 // Reflection
105 "Reflect",
106 "Proxy",
107 // Internationalization
108 "Intl",
109 // WebAssembly
110 "WebAssembly"
111 ];
112
113 const ERROR_TYPES = [
114 "Error",
115 "EvalError",
116 "InternalError",
117 "RangeError",
118 "ReferenceError",
119 "SyntaxError",
120 "TypeError",
121 "URIError"
122 ];
123
124 const BUILT_IN_GLOBALS = [
125 "setInterval",
126 "setTimeout",
127 "clearInterval",
128 "clearTimeout",
129
130 "require",
131 "exports",
132
133 "eval",
134 "isFinite",
135 "isNaN",
136 "parseFloat",
137 "parseInt",
138 "decodeURI",
139 "decodeURIComponent",
140 "encodeURI",
141 "encodeURIComponent",
142 "escape",
143 "unescape"
144 ];
145
146 const BUILT_INS = [].concat(
147 BUILT_IN_GLOBALS,
148 TYPES,
149 ERROR_TYPES
150 );
151
152 /*
153 Language: LiveScript
154 Author: Taneli Vatanen <taneli.vatanen@gmail.com>
155 Contributors: Jen Evers-Corvina <jen@sevvie.net>
156 Origin: coffeescript.js
157 Description: LiveScript is a programming language that transcompiles to JavaScript. For info about language see http://livescript.net/
158 Website: https://livescript.net
159 Category: scripting
160 */
161
162
163 function livescript(hljs) {
164 const LIVESCRIPT_BUILT_INS = [
165 'npm',
166 'print'
167 ];
168 const LIVESCRIPT_LITERALS = [
169 'yes',
170 'no',
171 'on',
172 'off',
173 'it',
174 'that',
175 'void'
176 ];
177 const LIVESCRIPT_KEYWORDS = [
178 'then',
179 'unless',
180 'until',
181 'loop',
182 'of',
183 'by',
184 'when',
185 'and',
186 'or',
187 'is',
188 'isnt',
189 'not',
190 'it',
191 'that',
192 'otherwise',
193 'from',
194 'to',
195 'til',
196 'fallthrough',
197 'case',
198 'enum',
199 'native',
200 'list',
201 'map',
202 '__hasProp',
203 '__extends',
204 '__slice',
205 '__bind',
206 '__indexOf'
207 ];
208 const KEYWORDS$1 = {
209 keyword: KEYWORDS.concat(LIVESCRIPT_KEYWORDS),
210 literal: LITERALS.concat(LIVESCRIPT_LITERALS),
211 built_in: BUILT_INS.concat(LIVESCRIPT_BUILT_INS)
212 };
213 const JS_IDENT_RE = '[A-Za-z$_](?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*';
214 const TITLE = hljs.inherit(hljs.TITLE_MODE, { begin: JS_IDENT_RE });
215 const SUBST = {
216 className: 'subst',
217 begin: /#\{/,
218 end: /\}/,
219 keywords: KEYWORDS$1
220 };
221 const SUBST_SIMPLE = {
222 className: 'subst',
223 begin: /#[A-Za-z$_]/,
224 end: /(?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*/,
225 keywords: KEYWORDS$1
226 };
227 const EXPRESSIONS = [
228 hljs.BINARY_NUMBER_MODE,
229 {
230 className: 'number',
231 begin: '(\\b0[xX][a-fA-F0-9_]+)|(\\b\\d(\\d|_\\d)*(\\.(\\d(\\d|_\\d)*)?)?(_*[eE]([-+]\\d(_\\d|\\d)*)?)?[_a-z]*)',
232 relevance: 0,
233 starts: {
234 end: '(\\s*/)?',
235 relevance: 0
236 } // a number tries to eat the following slash to prevent treating it as a regexp
237 },
238 {
239 className: 'string',
240 variants: [
241 {
242 begin: /'''/,
243 end: /'''/,
244 contains: [ hljs.BACKSLASH_ESCAPE ]
245 },
246 {
247 begin: /'/,
248 end: /'/,
249 contains: [ hljs.BACKSLASH_ESCAPE ]
250 },
251 {
252 begin: /"""/,
253 end: /"""/,
254 contains: [
255 hljs.BACKSLASH_ESCAPE,
256 SUBST,
257 SUBST_SIMPLE
258 ]
259 },
260 {
261 begin: /"/,
262 end: /"/,
263 contains: [
264 hljs.BACKSLASH_ESCAPE,
265 SUBST,
266 SUBST_SIMPLE
267 ]
268 },
269 {
270 begin: /\\/,
271 end: /(\s|$)/,
272 excludeEnd: true
273 }
274 ]
275 },
276 {
277 className: 'regexp',
278 variants: [
279 {
280 begin: '//',
281 end: '//[gim]*',
282 contains: [
283 SUBST,
284 hljs.HASH_COMMENT_MODE
285 ]
286 },
287 {
288 // regex can't start with space to parse x / 2 / 3 as two divisions
289 // regex can't start with *, and it supports an "illegal" in the main mode
290 begin: /\/(?![ *])(\\.|[^\\\n])*?\/[gim]*(?=\W)/ }
291 ]
292 },
293 { begin: '@' + JS_IDENT_RE },
294 {
295 begin: '``',
296 end: '``',
297 excludeBegin: true,
298 excludeEnd: true,
299 subLanguage: 'javascript'
300 }
301 ];
302 SUBST.contains = EXPRESSIONS;
303
304 const PARAMS = {
305 className: 'params',
306 begin: '\\(',
307 returnBegin: true,
308 /* We need another contained nameless mode to not have every nested
309 pair of parens to be called "params" */
310 contains: [
311 {
312 begin: /\(/,
313 end: /\)/,
314 keywords: KEYWORDS$1,
315 contains: [ 'self' ].concat(EXPRESSIONS)
316 }
317 ]
318 };
319
320 const SYMBOLS = { begin: '(#=>|=>|\\|>>|-?->|!->)' };
321
322 const CLASS_DEFINITION = {
323 variants: [
324 { match: [
325 /class\s+/,
326 JS_IDENT_RE,
327 /\s+extends\s+/,
328 JS_IDENT_RE
329 ] },
330 { match: [
331 /class\s+/,
332 JS_IDENT_RE
333 ] }
334 ],
335 scope: {
336 2: "title.class",
337 4: "title.class.inherited"
338 },
339 keywords: KEYWORDS$1
340 };
341
342 return {
343 name: 'LiveScript',
344 aliases: [ 'ls' ],
345 keywords: KEYWORDS$1,
346 illegal: /\/\*/,
347 contains: EXPRESSIONS.concat([
348 hljs.COMMENT('\\/\\*', '\\*\\/'),
349 hljs.HASH_COMMENT_MODE,
350 SYMBOLS, // relevance booster
351 {
352 className: 'function',
353 contains: [
354 TITLE,
355 PARAMS
356 ],
357 returnBegin: true,
358 variants: [
359 {
360 begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B->\\*?',
361 end: '->\\*?'
362 },
363 {
364 begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?!?(\\(.*\\)\\s*)?\\B[-~]{1,2}>\\*?',
365 end: '[-~]{1,2}>\\*?'
366 },
367 {
368 begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B!?[-~]{1,2}>\\*?',
369 end: '!?[-~]{1,2}>\\*?'
370 }
371 ]
372 },
373 CLASS_DEFINITION,
374 {
375 begin: JS_IDENT_RE + ':',
376 end: ':',
377 returnBegin: true,
378 returnEnd: true,
379 relevance: 0
380 }
381 ])
382 };
383 }
384
385 return livescript;
386
387 })();
388
389 hljs.registerLanguage('livescript', hljsGrammar);
390 })();